Search in sources :

Example 31 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations 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)

Example 32 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.

the class CienaWaveserverAiDeviceDescriptionTest method testDiscoverPortDetails.

@Test
public void testDiscoverPortDetails() {
    List<PortDescription> result = new ArrayList<>();
    List<PortDescription> expectResult = getExpectedPorts();
    try {
        XPath xp = XPathFactory.newInstance().newXPath();
        Node nodeListItem;
        Node node = doRequest("/response/discoverPortDetails.xml", "/rpc-reply/data");
        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);
            result.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 (XPathExpressionException e) {
        e.printStackTrace();
    }
    assertEquals(expectResult, result);
}
Also used : XPath(javax.xml.xpath.XPath) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) 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) Test(org.junit.Test)

Example 33 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.

the class GnmiDeviceStateSubscriber method handleOperStatusUpdate.

private void handleOperStatusUpdate(DeviceId deviceId, Update update, long timestamp) {
    Path path = update.getPath();
    // first element should be "interface"
    String interfaceName = path.getElem(1).getKeyOrDefault("name", null);
    if (interfaceName == null) {
        log.error("No interface present in gNMI update, abort");
        log.debug("gNMI update:\n{}", update);
        return;
    }
    List<Port> portsFromDevice = deviceService.getPorts(deviceId);
    portsFromDevice.forEach(port -> {
        if (!port.number().name().equals(interfaceName)) {
            return;
        }
        DefaultAnnotations portAnnotations = DefaultAnnotations.builder().putAll(port.annotations()).set(LAST_CHANGE, String.valueOf(timestamp)).build();
        // Port/Interface name is identical in OpenConfig model, but not in ONOS
        // This might cause some problem if we use one name to different port
        PortDescription portDescription = DefaultPortDescription.builder().portSpeed(port.portSpeed()).withPortNumber(port.number()).isEnabled(update.getVal().getStringVal().equals("UP")).type(port.type()).annotations(portAnnotations).build();
        providerService.portStatusChanged(deviceId, portDescription);
    });
}
Also used : Path(gnmi.Gnmi.Path) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Aggregations

DefaultAnnotations (org.onosproject.net.DefaultAnnotations)33 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortDescription (org.onosproject.net.device.PortDescription)9 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)6 LinkDescription (org.onosproject.net.link.LinkDescription)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 Device (org.onosproject.net.Device)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 ArrayList (java.util.ArrayList)3 ChassisId (org.onlab.packet.ChassisId)3 DefaultDevice (org.onosproject.net.DefaultDevice)3 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceService (org.onosproject.net.device.DeviceService)3 XPath (javax.xml.xpath.XPath)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2