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 Ciena5162DeviceDescription method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
List<PortStatistics> stats = new ArrayList<PortStatistics>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, will be retried", deviceId);
return stats;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
Node data = TEMPLATE_MANAGER.doRequest(session, "port-stats");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList interfaces = (NodeList) xp.evaluate("interfaces/interface", data, XPathConstants.NODESET);
int count = interfaces.getLength();
for (int i = 0; i < count; i += 1) {
Node iface = interfaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
stats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(xp.evaluate("name/text()", iface))).setBytesReceived(Long.valueOf(xp.evaluate("state/counters/in-octets/text()", iface))).setBytesSent(Long.valueOf(xp.evaluate("state/counters/out-octets/text()", iface))).setPacketsReceived(Long.valueOf(xp.evaluate("state/counters/in-pkts/text()", iface))).setPacketsSent(Long.valueOf(xp.evaluate("state/counters/out-pkts/text()", iface))).setPacketsTxErrors(Long.valueOf(xp.evaluate("state/counters/out-errors/text()", iface))).setPacketsRxErrors(Long.valueOf(xp.evaluate("state/counters/in-errors/text()", iface))).build());
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port statistics for device {}, {}", deviceId, e);
}
return stats;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = new ArrayList<PortDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, will be retried", deviceId);
return ports;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "logicalPorts");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList) xp.evaluate("interfaces/interface/config", logicalPorts, XPathConstants.NODESET);
int count = nl.getLength();
Node node;
for (int i = 0; i < count; i += 1) {
node = nl.item(i);
if (xp.evaluate("type/text()", node).equals("ettp")) {
ports.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(xp.evaluate("name/text()", node))).isEnabled(Boolean.valueOf(xp.evaluate("admin-status/text()", node))).portSpeed(portSpeedToLong(xp.evaluate("port-speed/text()", node))).type(Port.Type.PACKET).build());
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port information for device {}, {}", deviceId, e);
}
return ports;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<LinkDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
return links;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
DeviceService deviceService = this.handler().get(DeviceService.class);
Iterable<Device> devices = deviceService.getAvailableDevices();
Map<String, Device> lookup = new HashMap<String, Device>();
for (Device d : devices) {
lookup.put(d.chassisId().toString().toUpperCase(), d);
}
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
int count = ifaces.getLength();
Node iface;
Node destChassis;
for (int i = 0; i < count; i += 1) {
iface = ifaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
if (destChassis != null) {
Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
} else {
log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
}
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve links for device {}, {}", deviceId, e);
}
return links;
}
Aggregations