Search in sources :

Example 36 with PortDescription

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

the class OpenFlowDeviceProviderTest method switchChanged.

// test receiving features reply
@Test
public void switchChanged() {
    controller.listener.switchChanged(DPID1);
    Collection<PortDescription> updatedDescr = registry.ports.values();
    for (PortDescription pd : updatedDescr) {
        assertNotNull("Switch change not handled by the provider service", pd);
    }
}
Also used : PortDescription(org.onosproject.net.device.PortDescription) Test(org.junit.Test)

Example 37 with PortDescription

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

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for Polatis Snmp device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    List<PortDescription> ports = Lists.newArrayList();
    List<TableEvent> events;
    DeviceId deviceId = handler().data().deviceId();
    try {
        OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
        events = getTable(handler(), columnOIDs);
    } catch (IOException e) {
        log.error("Error reading ports table for device {} exception {}", deviceId, e);
        return ports;
    }
    if (events == null) {
        log.error("Error reading ports table for device {}", deviceId);
        return ports;
    }
    for (TableEvent event : events) {
        if (event == null) {
            log.error("Error reading event for device {}", deviceId);
            continue;
        }
        VariableBinding[] columns = event.getColumns();
        if (columns == null) {
            log.error("Error reading columns for device {} event {}", deviceId, event);
            continue;
        }
        VariableBinding portColumn = columns[0];
        if (portColumn == null) {
            continue;
        }
        int port = event.getIndex().last();
        boolean enabled = (portColumn.getVariable().toInt() == 1);
        PortNumber portNumber = PortNumber.portNumber(port);
        DefaultAnnotations annotations = DefaultAnnotations.builder().build();
        double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
        Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
        PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
        ports.add(p);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) TableEvent(org.snmp4j.util.TableEvent) Frequency(org.onlab.util.Frequency) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 38 with PortDescription

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

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for polatis device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    log.debug("Discovering ports on Polatis switch...");
    DeviceService deviceService = handler().get(DeviceService.class);
    DeviceId deviceID = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceID);
    int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
    int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
    String reply = netconfGet(handler(), getPortsFilter());
    List<PortDescription> descriptions = parsePorts(reply, numInputPorts, numOutputPorts);
    return ImmutableList.copyOf(descriptions);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription)

Example 39 with PortDescription

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

the class GossipDeviceStoreTest method testUpdatePortStatus.

@Test
public final void testUpdatePortStatus() {
    putDevice(DID1, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
    deviceStore.updatePorts(PID, DID1, pds);
    Capture<InternalPortStatusEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalPortStatusEvent, byte[]>> encoder = Capture.newInstance();
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    final DefaultPortDescription desc = DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build();
    DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, desc);
    assertEquals(PORT_UPDATED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(P1, event.port().number());
    assertFalse("Port is disabled", event.port().isEnabled());
    verify(clusterCommunicator);
    assertInternalPortStatusEvent(NID1, DID1, PID, desc, 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 40 with PortDescription

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

the class GossipDeviceStoreTest method testRemoveDevice.

@Test
public final void testRemoveDevice() {
    putDevice(DID1, SW1, A1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).annotations(A2).build());
    deviceStore.updatePorts(PID, DID1, pds);
    putDevice(DID2, SW1);
    assertEquals(2, deviceStore.getDeviceCount());
    assertEquals(1, deviceStore.getPorts(DID1).size());
    assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations(), A1);
    assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations(), A2);
    Capture<InternalDeviceEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event = deviceStore.removeDevice(DID1);
    assertEquals(DEVICE_REMOVED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(1, deviceStore.getDeviceCount());
    assertEquals(0, deviceStore.getPorts(DID1).size());
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());
    // putBack Device, Port w/o annotation
    putDevice(DID1, SW1);
    List<PortDescription> pds2 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
    deviceStore.updatePorts(PID, DID1, pds2);
    // annotations should not survive
    assertEquals(2, deviceStore.getDeviceCount());
    assertEquals(1, deviceStore.getPorts(DID1).size());
    assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations());
    assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations());
}
Also used : 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)

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