use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CienaWaveserverAiDeviceDescription method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
log.debug("Adding description for Waveserver Ai device");
NetconfSession session = getNetconfSession();
Device device = getDevice(handler().data().deviceId());
try {
XPath xp = XPathFactory.newInstance().newXPath();
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverDeviceDetails");
String chassisId = xp.evaluate("waveserver-chassis/mac-addresses/chassis/base/text()", node);
chassisId = chassisId.replace(":", "");
SparseAnnotations annotationDevice = DefaultAnnotations.builder().set("name", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)).build();
return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(Long.valueOf(chassisId, 16)), (SparseAnnotations) annotationDevice);
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve device information for device {}, {}", device.chassisId(), e);
}
return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "unknown", "unknown", device.chassisId());
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CienaWaveserverAiLinkDiscovery method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<>();
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<>();
for (Device d : devices) {
lookup.put(d.chassisId().toString(), d);
}
log.debug("MAP: {}", lookup);
XPath xp = XPathFactory.newInstance().newXPath();
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortDetails");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
int count = nodeList.getLength();
Node nodeListItem;
for (int i = 0; i < count; i += 1) {
Long portAsLong;
Long destPortAsLong;
String destChassis = null;
String destPort = null;
nodeListItem = nodeList.item(i);
String port = xp.evaluate("port-id/text()", nodeListItem);
portAsLong = portIdConvert(port);
log.debug("CHECKING: {}", port);
if (xp.evaluate("id/type/text()", nodeListItem).equals("otn")) {
String label = xp.evaluate("id/label/text()", nodeListItem);
final String r1 = "\\$\\{remote_mac:(.*?)\\}";
final Pattern p1 = Pattern.compile(r1);
final Matcher m1 = p1.matcher(label);
if (m1.find()) {
destChassis = m1.group(1).replaceFirst("^0+(?!$)", "");
}
final String r2 = "\\$\\{remote_port:(.*?)\\}";
final Pattern p2 = Pattern.compile(r2);
final Matcher m2 = p2.matcher(label);
if (m2.find()) {
destPort = m2.group(1);
}
destPortAsLong = portIdConvert(destPort);
if (destChassis != null && destPort != null) {
log.debug("LOOKING FOR OTN neighbor chassis: {}", destChassis);
Device dest = lookup.get(destChassis);
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), Link.Type.TUNNEL, true));
} else {
log.error("DEST OTN CHASSIS is NULL for {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else {
log.error("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else if (xp.evaluate("id/type/text()", nodeListItem).equals("ethernet")) {
Map<String, Object> templateContext = new HashMap<>();
templateContext.put("port-number", port);
node = TEMPLATE_MANAGER.doRequest(session, "getLinks", templateContext);
String chassisIdSubtype = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node);
if (chassisIdSubtype.equals("mac-address")) {
destChassis = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id/text()", node).trim().toLowerCase();
if (destChassis.startsWith("0x")) {
destChassis = destChassis.substring(2);
}
} else {
log.error("Unknown Chassis-id-subtype {}", xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node));
}
destPort = xp.evaluate("waveserver-lldp/port/remote/port/id/id/text()", node);
destPortAsLong = Long.valueOf(destPort);
if (destChassis != null && !destPort.equals("")) {
log.debug("LOOKING FOR ethernet neighbor chassisId: {}", destChassis);
Device dest = lookup.get(destChassis);
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), Link.Type.TUNNEL, true));
} else {
log.debug("DEST CHASSIS is NULL for port {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
}
}
}
} 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 CienaWaveserverAiPortStatisticsDiscovery method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
log.debug("Calculating port stats for Waveserver Ai device");
Collection<PortStatistics> portStats = new ArrayList<>();
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 portStats;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
XPath xp = XPathFactory.newInstance().newXPath();
String tx = "current-bin/statistics/interface-counts/tx/";
String rx = "current-bin/statistics/interface-counts/rx/";
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortStatistics");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-pm/ethernet-performance-instances", node, XPathConstants.NODESET);
Node nodeListItem;
int count = nodeList.getLength();
for (int i = 0; i < count; ++i) {
nodeListItem = nodeList.item(i);
portStats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(portIdConvert(xp.evaluate("instance-name/text()", nodeListItem)))).setPacketsReceived(Long.parseLong(xp.evaluate(rx + "packets/value/text()", nodeListItem))).setPacketsSent(Long.parseLong(xp.evaluate(tx + "packets/value/text()", nodeListItem))).setBytesReceived(Long.parseLong(xp.evaluate(rx + "bytes/value/text()", nodeListItem))).setBytesSent(Long.parseLong(xp.evaluate(tx + "bytes/value/text()", nodeListItem))).build());
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port stats information for device {}, {}", deviceId, e);
}
return ImmutableList.copyOf(portStats);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method removeAccessMode.
/**
* Removes an access interface to a VLAN.
*
* @param intf the name of the interface
* @return the result of operation
*/
@Override
public boolean removeAccessMode(String intf) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeAccessModeBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove access mode from device {} interface {}.", handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method getInterfaces.
/**
* Provides the interfaces configured on a device.
*
* @return the list of the configured interfaces
*/
@Override
public List<DeviceInterfaceDescription> getInterfaces() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(getConfigBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve configuration from device {}.", handler().data().deviceId(), e);
return null;
}
return XmlParserCisco.getInterfacesFromConfig(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
Aggregations