Search in sources :

Example 41 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class GossipDeviceStoreTest method testGetPort.

@Test
public final void testGetPort() {
    putDevice(DID1, SW1);
    putDevice(DID2, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(false).build());
    deviceStore.updatePorts(PID, DID1, pds);
    Port port1 = deviceStore.getPort(DID1, P1);
    assertEquals(P1, port1.number());
    assertTrue("Port is enabled", port1.isEnabled());
    Port port2 = deviceStore.getPort(DID1, P2);
    assertEquals(P2, port2.number());
    assertFalse("Port is disabled", port2.isEnabled());
    Port port3 = deviceStore.getPort(DID1, P3);
    assertNull("P3 not expected", port3);
}
Also used : Port(org.onosproject.net.Port) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Test(org.junit.Test)

Example 42 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class GossipDeviceStoreTest method testUpdatePortStatusAncillary.

@Test
public final void testUpdatePortStatusAncillary() throws IOException {
    putDeviceAncillary(DID1, SW1);
    putDevice(DID1, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).annotations(A1).build());
    deviceStore.updatePorts(PID, DID1, pds);
    Capture<InternalPortStatusEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalPortStatusEvent, byte[]>> encoder = Capture.newInstance();
    // update port from primary
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    final DefaultPortDescription desc1 = DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).annotations(A1_2).build();
    DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, desc1);
    assertEquals(PORT_UPDATED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(P1, event.port().number());
    assertAnnotationsEquals(event.port().annotations(), A1, A1_2);
    assertFalse("Port is disabled", event.port().isEnabled());
    verify(clusterCommunicator);
    assertInternalPortStatusEvent(NID1, DID1, PID, desc1, asList(A1, A1_2), message, subject, encoder);
    assertTrue(message.hasCaptured());
    // update port from ancillary with no attributes
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    final DefaultPortDescription desc2 = DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build();
    DeviceEvent event2 = deviceStore.updatePortStatus(PIDA, DID1, desc2);
    assertNull("Ancillary is ignored if primary exists", event2);
    verify(clusterCommunicator);
    assertFalse(message.hasCaptured());
    // but, Ancillary annotation update will be notified
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    final DefaultPortDescription desc3 = DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).annotations(A2).build();
    DeviceEvent event3 = deviceStore.updatePortStatus(PIDA, DID1, desc3);
    assertEquals(PORT_UPDATED, event3.type());
    assertDevice(DID1, SW1, event3.subject());
    assertEquals(P1, event3.port().number());
    assertAnnotationsEquals(event3.port().annotations(), A1, A1_2, A2);
    assertFalse("Port is disabled", event3.port().isEnabled());
    verify(clusterCommunicator);
    assertInternalPortStatusEvent(NID1, DID1, PIDA, desc3, asList(A2), message, subject, encoder);
    assertTrue(message.hasCaptured());
    // port only reported from Ancillary will be notified as down
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    final DefaultPortDescription desc4 = DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build();
    DeviceEvent event4 = deviceStore.updatePortStatus(PIDA, DID1, desc4);
    assertEquals(PORT_ADDED, event4.type());
    assertDevice(DID1, SW1, event4.subject());
    assertEquals(P2, event4.port().number());
    assertAnnotationsEquals(event4.port().annotations());
    assertFalse("Port is disabled if not given from primary provider", event4.port().isEnabled());
    verify(clusterCommunicator);
    // TODO: verify broadcast message content
    assertInternalPortStatusEvent(NID1, DID1, PIDA, desc4, NO_ANNOTATION, message, subject, encoder);
    assertTrue(message.hasCaptured());
}
Also used : DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DeviceEvent(org.onosproject.net.device.DeviceEvent) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Test(org.junit.Test)

Example 43 with PortDescription

use of org.onosproject.net.device.PortDescription 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 44 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class LumentumRoadmDiscovery method getPorts.

private List<PortDescription> getPorts() {
    try {
        snmp = new LumentumSnmpDevice(handler().data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);
        return Collections.emptyList();
    }
    List<PortDescription> ports = Lists.newLinkedList();
    OID[] oids = { new OID(CTRL_PORT_STATE + "1"), new OID(CTRL_PORT_STATE + "2") };
    for (OID oid : oids) {
        for (TreeEvent event : snmp.get(oid)) {
            if (event != null) {
                VariableBinding[] varBindings = event.getVariableBindings();
                for (VariableBinding varBinding : varBindings) {
                    if (varBinding.getVariable().toInt() == 1) {
                        int portNumber = varBinding.getOid().removeLast();
                        int portDirection = varBinding.getOid().removeLast();
                        SparseAnnotations ann = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portDirection + "-" + portNumber).build();
                        PortDescription p = omsPortDescription(PortNumber.portNumber(ports.size() + 1L), true, LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ, LumentumSnmpDevice.CHANNEL_SPACING.frequency(), ann);
                        ports.add(p);
                    }
                }
            }
        }
    }
    // Create LINE IN and LINE OUT ports as these are not reported through SNMP
    SparseAnnotations annLineIn = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "LINE IN").build();
    ports.add(omsPortDescription(PortNumber.portNumber(ports.size() + 1L), true, LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ, LumentumSnmpDevice.CHANNEL_SPACING.frequency(), annLineIn));
    SparseAnnotations annLineOut = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "LINE OUT").build();
    ports.add(omsPortDescription(PortNumber.portNumber(ports.size() + 1L), true, LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ, LumentumSnmpDevice.CHANNEL_SPACING.frequency(), annLineOut));
    return ports;
}
Also used : TreeEvent(org.snmp4j.util.TreeEvent) SparseAnnotations(org.onosproject.net.SparseAnnotations) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) IOException(java.io.IOException) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 45 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class DeviceDiscoveryJuniperImpl method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId devId = handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(devId);
    String reply;
    try {
        reply = session.get(requestBuilder(REQ_IF_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve interface-information for device {}", devId);
        return ImmutableList.of();
    }
    log.trace("Device {} interface-information {}", devId, reply);
    List<PortDescription> descriptions = JuniperUtils.parseJuniperPorts(loadXmlString(reply));
    log.debug("Device {} Discovered ports {}", devId, descriptions);
    return descriptions;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) PortDescription(org.onosproject.net.device.PortDescription) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)82 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)42 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)25 DeviceId (org.onosproject.net.DeviceId)24 Port (org.onosproject.net.Port)23 ArrayList (java.util.ArrayList)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)15 ProviderId (org.onosproject.net.provider.ProviderId)14 Device (org.onosproject.net.Device)13 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)10 DefaultPort (org.onosproject.net.DefaultPort)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 ConnectPoint (org.onosproject.net.ConnectPoint)6