Search in sources :

Example 46 with NetconfSession

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());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 47 with NetconfSession

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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NetconfController(org.onosproject.netconf.NetconfController) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) XPath(javax.xml.xpath.XPath) Pattern(java.util.regex.Pattern) Device(org.onosproject.net.Device) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) HashMap(java.util.HashMap) Map(java.util.Map)

Example 48 with NetconfSession

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);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) NetconfController(org.onosproject.netconf.NetconfController) NetconfException(org.onosproject.netconf.NetconfException)

Example 49 with NetconfSession

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))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Example 50 with NetconfSession

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))));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

NetconfSession (org.onosproject.netconf.NetconfSession)87 NetconfException (org.onosproject.netconf.NetconfException)72 NetconfController (org.onosproject.netconf.NetconfController)44 DeviceId (org.onosproject.net.DeviceId)32 XPath (javax.xml.xpath.XPath)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)18 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)18 Node (org.w3c.dom.Node)18 ArrayList (java.util.ArrayList)16 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 DeviceService (org.onosproject.net.device.DeviceService)13 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)11 ChassisId (org.onlab.packet.ChassisId)10 FlowRule (org.onosproject.net.flow.FlowRule)10 HashMap (java.util.HashMap)9 PortDescription (org.onosproject.net.device.PortDescription)9 NodeList (org.w3c.dom.NodeList)9 ConnectPoint (org.onosproject.net.ConnectPoint)8