use of org.onosproject.net.device.DefaultPortDescription 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());
}
use of org.onosproject.net.device.DefaultPortDescription 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());
}
Aggregations