use of org.onosproject.cluster.DefaultControllerNode in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandlerTest method testShouldHandleRoutingCase3.
/*
* Node 1 is the leader of switch 1A, 1B
* Node 3 is the leader of switch 2
*/
@Test
public void testShouldHandleRoutingCase3() {
expect(mockWps.leadershipService.getLeadership(DEV1A_PARTITION_ID)).andReturn(new Leadership(DEV1A_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
expect(mockWps.leadershipService.getLeadership(DEV1B_PARTITION_ID)).andReturn(new Leadership(DEV1B_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
expect(mockWps.leadershipService.getLeadership(DEV2_PARTITION_ID)).andReturn(new Leadership(DEV2_PARTITION_ID, new Leader(NODE3, 0, 0), List.of(NODE2, NODE3))).anyTimes();
replay(mockWps.leadershipService);
expect(srManager.getPairDeviceId(DEV1A)).andReturn(Optional.of(DEV1B)).anyTimes();
expect(srManager.getPairDeviceId(DEV1B)).andReturn(Optional.of(DEV1A)).anyTimes();
expect(srManager.getPairDeviceId(DEV2)).andReturn(Optional.empty()).anyTimes();
replay(srManager);
// Node 1 should program 1A, 1B
expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE1, IP1)).anyTimes();
replay(srManager.clusterService);
assertNull(dfh.shouldProgram.get(DEV1A));
assertNull(dfh.shouldProgram.get(DEV1B));
assertNull(dfh.shouldProgram.get(DEV2));
assertTrue(dfh.shouldProgram(DEV1A));
assertTrue(dfh.shouldProgram(DEV1B));
assertFalse(dfh.shouldProgram(DEV2));
assertEquals(NODE1, dfh.shouldProgram.get(DEV1A));
assertEquals(NODE1, dfh.shouldProgram.get(DEV1B));
assertNotEquals(NODE1, dfh.shouldProgram.get(DEV2));
reset(srManager.clusterService);
clearShouldProgram();
// Node 2 should program no device
expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE2, IP2)).anyTimes();
replay(srManager.clusterService);
assertNull(dfh.shouldProgram.get(DEV1A));
assertNull(dfh.shouldProgram.get(DEV1B));
assertNull(dfh.shouldProgram.get(DEV2));
assertFalse(dfh.shouldProgram(DEV1A));
assertFalse(dfh.shouldProgram(DEV1B));
assertFalse(dfh.shouldProgram(DEV2));
assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1A));
assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1B));
assertNotEquals(NODE2, dfh.shouldProgram.get(DEV2));
reset(srManager.clusterService);
clearShouldProgram();
// Node 3 should program 2
expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE3, IP3)).anyTimes();
replay(srManager.clusterService);
assertNull(dfh.shouldProgram.get(DEV1A));
assertNull(dfh.shouldProgram.get(DEV1B));
assertNull(dfh.shouldProgram.get(DEV2));
assertFalse(dfh.shouldProgram(DEV1A));
assertFalse(dfh.shouldProgram(DEV1B));
assertTrue(dfh.shouldProgram(DEV2));
assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1A));
assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1B));
assertEquals(NODE3, dfh.shouldProgram.get(DEV2));
}
Aggregations