Search in sources :

Example 71 with DeviceEvent

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

the class NetworkConfigLinksProviderTest method testAddDevice.

/**
 * Tests adding a new device via an event.
 */
@Test
public void testAddDevice() {
    deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, dev3));
    assertThat(provider.discoverers.entrySet(), hasSize(3));
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Test(org.junit.Test)

Example 72 with DeviceEvent

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

the class DeviceManager method removeDevicePorts.

@Override
public void removeDevicePorts(DeviceId deviceId) {
    checkNotNull(deviceId, DEVICE_ID_NULL);
    if (isAvailable(deviceId)) {
        log.debug("Cannot remove ports of device {} while it is available.", deviceId);
        return;
    }
    List<PortDescription> portDescriptions = ImmutableList.of();
    List<DeviceEvent> events = store.updatePorts(getProvider(deviceId).id(), deviceId, portDescriptions);
    if (events != null) {
        for (DeviceEvent event : events) {
            post(event);
        }
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Example 73 with DeviceEvent

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

Example 74 with DeviceEvent

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

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

Aggregations

DeviceEvent (org.onosproject.net.device.DeviceEvent)77 Test (org.junit.Test)42 Device (org.onosproject.net.Device)26 DefaultDevice (org.onosproject.net.DefaultDevice)17 DefaultPort (org.onosproject.net.DefaultPort)17 PortDescription (org.onosproject.net.device.PortDescription)14 PortNumber (org.onosproject.net.PortNumber)11 Port (org.onosproject.net.Port)10 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)10 ProviderId (org.onosproject.net.provider.ProviderId)10 ArrayList (java.util.ArrayList)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 Timestamp (org.onosproject.store.Timestamp)8 MessageSubject (org.onosproject.store.cluster.messaging.MessageSubject)8 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)8 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)8 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)8 BiFunction (java.util.function.BiFunction)7 Function (java.util.function.Function)7 DeviceDescription (org.onosproject.net.device.DeviceDescription)7