Search in sources :

Example 6 with MessageSubject

use of org.onosproject.store.cluster.messaging.MessageSubject 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 7 with MessageSubject

use of org.onosproject.store.cluster.messaging.MessageSubject 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 8 with MessageSubject

use of org.onosproject.store.cluster.messaging.MessageSubject 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 9 with MessageSubject

use of org.onosproject.store.cluster.messaging.MessageSubject in project onos by opennetworkinglab.

the class GossipDeviceStoreTest method testMarkOffline.

@Test
public final void testMarkOffline() {
    putDevice(DID1, SW1);
    assertTrue(deviceStore.isAvailable(DID1));
    Capture<InternalDeviceEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event = deviceStore.markOffline(DID1);
    assertEquals(DEVICE_AVAILABILITY_CHANGED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertFalse(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    DeviceEvent event2 = deviceStore.markOffline(DID1);
    assertNull("No change, no event", event2);
    verify(clusterCommunicator);
    assertFalse(message.hasCaptured());
}
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) Test(org.junit.Test)

Aggregations

MessageSubject (org.onosproject.store.cluster.messaging.MessageSubject)9 BiFunction (java.util.function.BiFunction)7 Function (java.util.function.Function)7 Test (org.junit.Test)7 DeviceEvent (org.onosproject.net.device.DeviceEvent)7 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)4 PortDescription (org.onosproject.net.device.PortDescription)4 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)2 DeviceDescription (org.onosproject.net.device.DeviceDescription)2 PortNumber (org.onosproject.net.PortNumber)1 ClusterMessage (org.onosproject.store.cluster.messaging.ClusterMessage)1