Search in sources :

Example 56 with NetconfSession

use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.

the class LumentumNetconfRoadmDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId deviceId = handler().data().deviceId();
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    // Get the configuration from the device
    if (device == null) {
        log.error("Lumentum NETCONF - device object not found for {}", deviceId);
        return ImmutableList.of();
    }
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Lumentum NETCONF - session not found for {}", deviceId);
        return ImmutableList.of();
    }
    StringBuilder requestBuilder = new StringBuilder();
    requestBuilder.append("<physical-ports xmlns=\"http://www.lumentum.com/lumentum-ote-port\" ");
    requestBuilder.append("xmlns:lotep=\"http://www.lumentum.com/lumentum-ote-port\" ");
    requestBuilder.append("xmlns:lotepopt=\"http://www.lumentum.com/lumentum-ote-port-optical\" ");
    requestBuilder.append("xmlns:loteeth=\"http://www.lumentum.com/lumentum-ote-port-ethernet\">");
    requestBuilder.append("</physical-ports>");
    String reply;
    try {
        reply = session.get(requestBuilder.toString(), null);
    } catch (NetconfException e) {
        log.error("Lumentum NETCONF - " + "discoverPortDetails failed to retrieve port details {}", handler().data().deviceId(), e);
        return ImmutableList.of();
    }
    List<PortDescription> descriptions = parseLumentumRoadmPorts(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
    return ImmutableList.copyOf(descriptions);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Example 57 with NetconfSession

use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.

the class ZteDeviceDiscoveryImpl method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId deviceId = handler().data().deviceId();
    log.info("Discovering ZTE device ports {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    XMLConfiguration cfg = new XMLConfiguration();
    try {
        String reply = session.requestSync(buildPortDetailRequest(), 30);
        String data = getDataOfRpcReply(reply);
        if (data == null) {
            log.error("No valid response found from {}:\n{}", deviceId, reply);
            return ImmutableList.of();
        }
        cfg.load(CharSource.wrap(data).openStream());
        return discoverPorts(cfg);
    } catch (Exception e) {
        log.error("ZTE device port discovery error.", e);
    }
    return ImmutableList.of();
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) DeviceId(org.onosproject.net.DeviceId) NetconfController(org.onosproject.netconf.NetconfController) NetconfException(org.onosproject.netconf.NetconfException)

Example 58 with NetconfSession

use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.

the class Ciena5170DeviceDescription 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;
}
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) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException)

Example 59 with NetconfSession

use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.

the class Ciena5170DeviceDescription 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;
}
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) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException)

Example 60 with NetconfSession

use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.

the class Ciena5170PortAdmin 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);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) NetconfException(org.onosproject.netconf.NetconfException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) 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