Search in sources :

Example 41 with NetconfSession

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

the class DeviceDiscoveryJuniperImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId devId = handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(devId);
    String sysInfo;
    String chassisMacAddresses;
    try {
        sysInfo = session.get(requestBuilder(REQ_SYS_INFO));
        chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve device details for {}", devId);
        return null;
    }
    log.trace("Device {} system-information {}", devId, sysInfo);
    DeviceDescription description = JuniperUtils.parseJuniperDescription(devId, loadXmlString(sysInfo), chassisMacAddresses);
    log.debug("Device {} description {}", devId, description);
    return description;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceDescription(org.onosproject.net.device.DeviceDescription) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

Example 42 with NetconfSession

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

the class ZteDeviceDiscoveryImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    log.info("Discovering ZTE device {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    String hwVersion = "ZTE hw";
    String swVersion = "ZTE sw";
    String serialNumber = "000000000000";
    try {
        String reply = session.requestSync(buildDeviceInfoRequest());
        XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
        hwVersion = cfg.getString("components.component.state.hardware-version");
        swVersion = cfg.getString("components.component.state.software-version");
        serialNumber = cfg.getString("components.component.state.serial-no");
    } catch (NetconfException e) {
        log.error("ZTE device discovery error.", e);
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, "ZTE", hwVersion, swVersion, serialNumber, new ChassisId(1));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) NetconfController(org.onosproject.netconf.NetconfController)

Example 43 with NetconfSession

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

the class ZtePortStatisticsDiscovery method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceId deviceId = handler().data().deviceId();
    LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    if (null == controller) {
        LOG.error("Cannot find NetconfController");
        return null;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    if (null == session) {
        LOG.error("No session available for device {}", deviceId);
        return null;
    }
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortStatistics> portStatistics = Lists.newArrayList();
    ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
    return portStatistics;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) NetconfController(org.onosproject.netconf.NetconfController) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 44 with NetconfSession

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

the class NetconfSessionMinaImpl method startSubscriptionStream.

@Beta
protected void startSubscriptionStream(String filterSchema) throws NetconfException {
    boolean openNewSession = false;
    if (!deviceCapabilities.contains(INTERLEAVE_CAPABILITY_STRING)) {
        log.info("Device {} doesn't support interleave, creating child session", deviceInfo);
        openNewSession = true;
    } else if (subscriptionConnected && notificationFilterSchema != null && !Objects.equal(filterSchema, notificationFilterSchema)) {
        // interleave supported and existing filter is NOT "no filtering"
        // and was requested with different filtering schema
        log.info("Cannot use existing session for subscription {} ({})", deviceInfo, filterSchema);
        openNewSession = true;
    }
    if (openNewSession) {
        log.info("Creating notification session to {} with filter {}", deviceInfo, filterSchema);
        NetconfSession child = new NotificationSession(deviceInfo);
        child.addDeviceOutputListener(new NotificationForwarder());
        child.startSubscription(filterSchema);
        children.add(child);
        return;
    }
    // request to start interleaved notification session
    String reply = sendRequest(createSubscriptionString(filterSchema));
    if (!checkReply(reply)) {
        throw new NetconfException("Subscription not successful with device " + deviceInfo + " with reply " + reply);
    }
    subscriptionConnected = true;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) AbstractNetconfSession(org.onosproject.netconf.AbstractNetconfSession) NetconfException(org.onosproject.netconf.NetconfException) Beta(com.google.common.annotations.Beta)

Example 45 with NetconfSession

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

the class CienaWaveserverAiDeviceDescription method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    log.info("Adding ports for Waveserver Ai device");
    List<PortDescription> ports = new ArrayList<>();
    Device device = getDevice(handler().data().deviceId());
    NetconfSession session = getNetconfSession();
    try {
        XPath xp = XPathFactory.newInstance().newXPath();
        Node nodeListItem;
        Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortDetails");
        NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
        int count = nodeList.getLength();
        for (int i = 0; i < count; ++i) {
            nodeListItem = nodeList.item(i);
            DefaultAnnotations annotationPort = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, xp.evaluate("port-id/text()", nodeListItem)).set(AnnotationKeys.PROTOCOL, xp.evaluate("id/type/text()", nodeListItem)).build();
            String port = xp.evaluate("port-id/text()", nodeListItem);
            ports.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(portIdConvert(port), port)).isEnabled(portStateConvert(xp.evaluate("state/operational-state/text()", nodeListItem))).portSpeed(portSpeedToLong(xp.evaluate("id/speed/text()", nodeListItem))).type(Port.Type.PACKET).annotations(annotationPort).build());
        }
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve port information for device {}, {}", device.chassisId(), e);
    }
    return ImmutableList.copyOf(ports);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) 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) NetconfException(org.onosproject.netconf.NetconfException)

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