use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CzechLightDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("Cannot request NETCONF session for {}", data().deviceId());
return null;
}
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
try {
Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
if (!data.containsKey(YANGLIB_KEY_REVISION)) {
log.error("Not talking to a supported CzechLight device, is that a teapot?");
return noDevice;
}
final var revision = data.getString(YANGLIB_KEY_REVISION);
if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
return noDevice;
}
final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
if (!isLineDegree && !isAddDrop) {
log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
return noDevice;
}
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
return noDevice;
}
isCoherentAddDrop = true;
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
if (!revision.equals(MOD_INLINE_AMP_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
return noDevice;
}
isInlineAmp = true;
}
if (isLineDegree) {
log.info("Talking to a Line/Degree ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
} else if (isAddDrop) {
log.info("Talking to an Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
} else if (isCoherentAddDrop) {
log.info("Talking to a Coherent Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
} else if (isInlineAmp) {
log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
} else {
log.error("Device type not recognized");
return noDevice;
}
} catch (NetconfException e) {
log.error("Cannot request ietf-yang-library data", e);
return noDevice;
}
// FIXME: initialize these
String vendor = "CzechLight";
String hwVersion = "n/a";
String swVersion = "n/a";
String serialNumber = "n/a";
ChassisId chassisId = null;
return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5170DeviceDescription 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;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5170DeviceDescription method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo");
Node chassisMac = TEMPLATE_MANAGER.doRequest(session, "chassis-mac");
Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion");
XPath xp = XPathFactory.newInstance().newXPath();
String mac = xp.evaluate("lldp-global-operational/chassis-id/text()", chassisMac).toUpperCase();
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", xp.evaluate("components/component/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), mac, new ChassisId(Long.valueOf(mac, 16)));
} catch (XPathExpressionException | NetconfException ne) {
log.error("failed to query system info from device {} : {}", handler().data().deviceId(), ne.getMessage(), ne);
}
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5170", "Unknown", "Unknown", new ChassisId());
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CiscoIosDeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
interfaces = session.get(showInterfacesRequestBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve Interfaces");
return ImmutableList.of();
}
return ImmutableList.copyOf(TextBlockParserCisco.parseCiscoIosPorts(interfaces));
}
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;
}
Aggregations