Search in sources :

Example 1 with ClusterMessage

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

the class GossipDeviceStoreTest method testCreateOrUpdateDeviceAncillary.

@Test
public final void testCreateOrUpdateDeviceAncillary() throws IOException {
    // add
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2);
    Capture<ClusterMessage> bcast = Capture.newInstance();
    Capture<InternalDeviceEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PIDA, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(PIDA, event.subject().providerId());
    assertAnnotationsEquals(event.subject().annotations(), A2);
    assertFalse("Ancillary will not bring device up", deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    assertInternalDeviceEvent(NID1, DID1, PIDA, description, message, subject, encoder);
    // update from primary
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID, A1);
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertEquals(PID, event2.subject().providerId());
    assertAnnotationsEquals(event2.subject().annotations(), A1, A2);
    assertTrue(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    assertInternalDeviceEvent(NID1, DID1, PID, description2, message, subject, encoder);
    // no-op update from primary
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
    verify(clusterCommunicator);
    assertFalse("no broadcast expected", bcast.hasCaptured());
    // For now, Ancillary is ignored once primary appears
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PIDA, DID1, description));
    verify(clusterCommunicator);
    assertFalse("no broadcast expected", bcast.hasCaptured());
    // But, Ancillary annotations will be in effect
    DeviceDescription description3 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2_2);
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event3 = deviceStore.createOrUpdateDevice(PIDA, DID1, description3);
    assertEquals(DEVICE_UPDATED, event3.type());
    // basic information will be the one from Primary
    assertDevice(DID1, SW2, event3.subject());
    assertEquals(PID, event3.subject().providerId());
    // but annotation from Ancillary will be merged
    assertAnnotationsEquals(event3.subject().annotations(), A1, A2, A2_2);
    assertTrue(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    // note: only annotation from PIDA is sent over the wire
    assertInternalDeviceEvent(NID1, DID1, PIDA, description3, asList(union(A2, A2_2)), message, subject, encoder);
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DeviceEvent(org.onosproject.net.device.DeviceEvent) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) ClusterMessage(org.onosproject.store.cluster.messaging.ClusterMessage) Test(org.junit.Test)

Example 2 with ClusterMessage

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

the class ClusterCommunicationManager method multicast.

@Override
public <M> void multicast(M message, MessageSubject subject, Function<M, byte[]> encoder, Set<NodeId> nodes) {
    checkPermission(CLUSTER_WRITE);
    byte[] payload = new ClusterMessage(localNodeId, subject, timeFunction(encoder, subjectMeteringAgent, SERIALIZING).apply(message)).getBytes();
    nodes.forEach(nodeId -> doUnicast(subject, payload, nodeId));
}
Also used : ClusterMessage(org.onosproject.store.cluster.messaging.ClusterMessage)

Aggregations

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