use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class PolatisNetconfUtility method opticalRevision.
public static String opticalRevision(DriverHandler handler) {
NetconfSession session = getNetconfSession(handler);
Set<String> capabilities = session.getDeviceCapabilitiesSet();
for (String c : capabilities) {
if (c.startsWith(OPTICAL_CAPABILITY_PREFIX)) {
return c.substring(OPTICAL_CAPABILITY_PREFIX.length());
}
}
return null;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162PortAdmin method setAdminState.
/**
* Sets the administrative state of the given port to the given value.
*
* @param number
* port number
* @param value
* state, true for enabled, false for disabled
* @return true if successfully set
*/
private CompletableFuture<Boolean> setAdminState(PortNumber number, Boolean value) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toLong());
templateContext.put("admin-state", value.toString());
Node req = (Node) TEMPLATE_MANAGER.doRequest(session, "port-admin-state", templateContext, "/", XPathConstants.NODE);
XPath xp = XPathFactory.newInstance().newXPath();
// If OK element exists then it worked.
Node ok = (Node) xp.evaluate("/rpc-reply/ok", req, XPathConstants.NODE);
return CompletableFuture.completedFuture(ok != null);
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to set port admin state for port {} to {}", number, handler().data().deviceId(), value, e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5170PortAdmin method isEnabled.
@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toString());
Node port = TEMPLATE_MANAGER.doRequest(session, "logicalPort", templateContext);
XPath xp = XPathFactory.newInstance().newXPath();
return CompletableFuture.completedFuture(Boolean.valueOf(xp.evaluate("admin-status/text()", port)));
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to query port state for port {} from device {}", number, handler().data().deviceId(), e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class FujitsuT100DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.get(requestBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
return ImmutableList.of();
}
List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
return ImmutableList.copyOf(descriptions);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenRoadmFlowRuleProgrammable method getDeviceConnections.
/**
* Fetches list of connections from device.
*
* @return list of connections as XML hierarchy
*/
private List<HierarchicalConfiguration> getDeviceConnections() {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("OPENROADM {}: session not found", did());
return ImmutableList.of();
}
try {
StringBuilder rb = new StringBuilder();
rb.append(ORG_OPENROADM_DEVICE_OPEN_TAG);
rb.append(" <roadm-connections/>");
rb.append(ORG_OPENROADM_DEVICE_CLOSE_TAG);
String reply = session.getConfig(DatastoreId.RUNNING, rb.toString());
log.debug("REPLY to getDeviceConnections {}", reply);
HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
return cfg.configurationsAt("data.org-openroadm-device.roadm-connections");
} catch (NetconfException e) {
return ImmutableList.of();
}
}
Aggregations