Pavlin Radoslavov

Moved the BGP Route Intent synchronization mechanism from the Router class

to the new class IntentSynchronizer.

Also, minor cleanup in some of the method names and access scope.

Change-Id: I38257cd1d9516ef3b3dd50f23c28015054c73d70
......@@ -96,6 +96,13 @@ public class PeerConnectivityManager {
}
/**
* Stops the peer connectivity manager.
*/
public void stop() {
// TODO: Implement it
}
/**
* Sets up paths to establish connectivity between all internal
* {@link BgpSpeaker}s and all external {@link BgpPeer}s.
*/
......
......@@ -55,6 +55,7 @@ public class SdnIp implements SdnIpService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
private IntentSynchronizer intentSynchronizer;
private SdnIpConfigReader config;
private PeerConnectivityManager peerConnectivity;
private Router router;
......@@ -64,35 +65,41 @@ public class SdnIp implements SdnIpService {
protected void activate() {
log.debug("SDN-IP started");
ApplicationId appId = coreService.registerApplication(SDN_IP_APP);
config = new SdnIpConfigReader();
config.init();
InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService);
InterfaceService interfaceService =
new HostToInterfaceAdaptor(hostService);
ApplicationId appId = coreService.registerApplication(SDN_IP_APP);
intentSynchronizer = new IntentSynchronizer(appId, intentService);
intentSynchronizer.start();
peerConnectivity = new PeerConnectivityManager(appId, config,
interfaceService, intentService);
peerConnectivity.start();
router = new Router(appId, intentService, hostService, config, interfaceService);
router = new Router(appId, intentSynchronizer, hostService, config,
interfaceService);
router.start();
// Manually set the router as the leader to allow testing
// Manually set the instance as the leader to allow testing
// TODO change this when we get a leader election
router.leaderChanged(true);
intentSynchronizer.leaderChanged(true);
bgpSessionManager = new BgpSessionManager(router);
bgpSessionManager.startUp(2000); // TODO
// TODO: the local BGP listen port number should be configurable
bgpSessionManager.start(2000);
// TODO need to disable link discovery on external ports
}
@Deactivate
protected void deactivate() {
bgpSessionManager.shutDown();
router.shutdown();
bgpSessionManager.stop();
router.stop();
peerConnectivity.stop();
intentSynchronizer.stop();
log.info("Stopped");
}
......@@ -114,7 +121,7 @@ public class SdnIp implements SdnIpService {
@Override
public void modifyPrimary(boolean isPrimary) {
router.leaderChanged(isPrimary);
intentSynchronizer.leaderChanged(isPrimary);
}
static String dpidToUri(String dpid) {
......
......@@ -181,8 +181,8 @@ public class BgpSessionManager {
* @param listenPortNumber the port number to listen on. By default
* it should be BgpConstants.BGP_PORT (179)
*/
public void startUp(int listenPortNumber) {
log.debug("BGP Session Manager startUp()");
public void start(int listenPortNumber) {
log.debug("BGP Session Manager start.");
isShutdown = false;
ChannelFactory channelFactory =
......@@ -222,9 +222,9 @@ public class BgpSessionManager {
}
/**
* Shuts down the BGP Session Manager operation.
* Stops the BGP Session Manager operation.
*/
public void shutDown() {
public void stop() {
isShutdown = true;
allChannels.close().awaitUninterruptibly();
serverBootstrap.releaseExternalResources();
......
......@@ -54,7 +54,8 @@ import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
/**
* This class tests the intent synchronization function in Router class.
* This class tests the intent synchronization function in the
* IntentSynchronizer class.
*/
public class IntentSyncTest {
......@@ -74,6 +75,7 @@ public class IntentSyncTest {
DeviceId.deviceId("of:0000000000000003"),
PortNumber.portNumber(1));
private IntentSynchronizer intentSynchronizer;
private Router router;
private static final ApplicationId APPID = new ApplicationId() {
......@@ -94,7 +96,8 @@ public class IntentSyncTest {
setUpHostService();
intentService = createMock(IntentService.class);
router = new Router(APPID, intentService,
intentSynchronizer = new IntentSynchronizer(APPID, intentService);
router = new Router(APPID, intentSynchronizer,
hostService, null, interfaceService);
}
......@@ -260,7 +263,7 @@ public class IntentSyncTest {
// Compose a intent, which is equal to intent5 but the id is different.
MultiPointToSinglePointIntent intent5New =
staticIntentBuilder(intent5, routeEntry5, "00:00:00:00:00:01");
assertTrue(TestUtils.callMethod(router,
assertTrue(TestUtils.callMethod(intentSynchronizer,
"compareMultiPointToSinglePointIntents",
new Class<?>[] {MultiPointToSinglePointIntent.class,
MultiPointToSinglePointIntent.class},
......@@ -296,7 +299,8 @@ public class IntentSyncTest {
pushedRouteIntents.put(routeEntry5.prefix(), intent5New);
pushedRouteIntents.put(routeEntry6.prefix(), intent6);
pushedRouteIntents.put(routeEntry7.prefix(), intent7);
TestUtils.setField(router, "pushedRouteIntents", pushedRouteIntents);
TestUtils.setField(intentSynchronizer, "pushedRouteIntents",
pushedRouteIntents);
// Set up expectation
reset(intentService);
......@@ -327,8 +331,9 @@ public class IntentSyncTest {
replay(intentService);
// Start the test
router.leaderChanged(true);
TestUtils.callMethod(router, "syncIntents", new Class<?>[] {});
intentSynchronizer.leaderChanged(true);
TestUtils.callMethod(intentSynchronizer, "syncIntents",
new Class<?>[] {});
// Verify
assertEquals(router.getRoutes().size(), 6);
......@@ -338,12 +343,12 @@ public class IntentSyncTest {
assertTrue(router.getRoutes().contains(routeEntry5));
assertTrue(router.getRoutes().contains(routeEntry6));
assertEquals(router.getPushedRouteIntents().size(), 6);
assertTrue(router.getPushedRouteIntents().contains(intent1));
assertTrue(router.getPushedRouteIntents().contains(intent3));
assertTrue(router.getPushedRouteIntents().contains(intent4Update));
assertTrue(router.getPushedRouteIntents().contains(intent5));
assertTrue(router.getPushedRouteIntents().contains(intent6));
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 6);
assertTrue(intentSynchronizer.getPushedRouteIntents().contains(intent1));
assertTrue(intentSynchronizer.getPushedRouteIntents().contains(intent3));
assertTrue(intentSynchronizer.getPushedRouteIntents().contains(intent4Update));
assertTrue(intentSynchronizer.getPushedRouteIntents().contains(intent5));
assertTrue(intentSynchronizer.getPushedRouteIntents().contains(intent6));
verify(intentService);
}
......
......@@ -102,6 +102,7 @@ public class RouterTest {
}
};
private IntentSynchronizer intentSynchronizer;
private Router router;
@Before
......@@ -113,7 +114,8 @@ public class RouterTest {
intentService = createMock(IntentService.class);
router = new Router(APPID, intentService,
intentSynchronizer = new IntentSynchronizer(APPID, intentService);
router = new Router(APPID, intentSynchronizer,
hostService, sdnIpConfigService, interfaceService);
}
......@@ -258,15 +260,15 @@ public class RouterTest {
replay(intentService);
// Call the processRouteAdd() method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteAdd(routeEntry);
// Verify
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntry));
assertEquals(router.getPushedRouteIntents().size(), 1);
assertEquals(router.getPushedRouteIntents().iterator().next(),
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
intent);
verify(intentService);
}
......@@ -338,15 +340,15 @@ public class RouterTest {
replay(intentService);
// Call the processRouteAdd() method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteAdd(routeEntryUpdate);
// Verify
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntryUpdate));
assertEquals(router.getPushedRouteIntents().size(), 1);
assertEquals(router.getPushedRouteIntents().iterator().next(),
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
intentNew);
verify(intentService);
}
......@@ -389,13 +391,13 @@ public class RouterTest {
replay(intentService);
// Call route deleting method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteDelete(routeEntry);
// Verify
assertEquals(router.getRoutes().size(), 0);
assertEquals(router.getPushedRouteIntents().size(), 0);
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 0);
verify(intentService);
}
......@@ -416,14 +418,14 @@ public class RouterTest {
replay(intentService);
// Call the processRouteAdd() method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteAdd(routeEntry);
// Verify
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntry));
assertEquals(router.getPushedRouteIntents().size(), 0);
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 0);
verify(intentService);
}
}
......
......@@ -92,6 +92,7 @@ public class RouterTestWithAsyncArp {
DeviceId.deviceId("of:0000000000000003"),
PortNumber.portNumber(1));
private IntentSynchronizer intentSynchronizer;
private Router router;
private InternalHostListener internalHostListener;
......@@ -114,7 +115,8 @@ public class RouterTestWithAsyncArp {
hostService = createMock(HostService.class);
intentService = createMock(IntentService.class);
router = new Router(APPID, intentService,
intentSynchronizer = new IntentSynchronizer(APPID, intentService);
router = new Router(APPID, intentSynchronizer,
hostService, sdnIpConfigService, interfaceService);
internalHostListener = router.new InternalHostListener();
}
......@@ -211,8 +213,8 @@ public class RouterTestWithAsyncArp {
replay(intentService);
// Call the processRouteAdd() method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteAdd(routeEntry);
Host host = new DefaultHost(ProviderId.NONE, HostId.NONE,
......@@ -227,8 +229,8 @@ public class RouterTestWithAsyncArp {
// Verify
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntry));
assertEquals(router.getPushedRouteIntents().size(), 1);
assertEquals(router.getPushedRouteIntents().iterator().next(),
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
intent);
verify(intentService);
verify(hostService);
......@@ -294,8 +296,8 @@ public class RouterTestWithAsyncArp {
replay(intentService);
// Call the processRouteAdd() method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteAdd(routeEntryUpdate);
Host host = new DefaultHost(ProviderId.NONE, HostId.NONE,
......@@ -310,8 +312,8 @@ public class RouterTestWithAsyncArp {
// Verify
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntryUpdate));
assertEquals(router.getPushedRouteIntents().size(), 1);
assertEquals(router.getPushedRouteIntents().iterator().next(),
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
intentNew);
verify(intentService);
verify(hostService);
......@@ -342,13 +344,13 @@ public class RouterTestWithAsyncArp {
replay(intentService);
// Call route deleting method in Router class
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
router.processRouteDelete(routeEntry);
// Verify
assertEquals(router.getRoutes().size(), 0);
assertEquals(router.getPushedRouteIntents().size(), 0);
assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 0);
verify(intentService);
}
......
......@@ -66,6 +66,7 @@ public class SdnIpTest {
private static final int MIN_PREFIX_LENGTH = 1;
private static final int MAX_PREFIX_LENGTH = 32;
private IntentSynchronizer intentSynchronizer;
static Router router;
private SdnIpConfigService sdnIpConfigService;
......@@ -111,7 +112,8 @@ public class SdnIpTest {
intentService = createMock(IntentService.class);
random = new Random();
router = new Router(APPID, intentService, hostService,
intentSynchronizer = new IntentSynchronizer(APPID, intentService);
router = new Router(APPID, intentSynchronizer, hostService,
sdnIpConfigService, interfaceService);
}
......@@ -228,8 +230,8 @@ public class SdnIpTest {
replay(intentService);
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
// Add route updates
for (RouteUpdate update : routeUpdates) {
......@@ -239,7 +241,8 @@ public class SdnIpTest {
latch.await(5000, TimeUnit.MILLISECONDS);
assertEquals(router.getRoutes().size(), numRoutes);
assertEquals(router.getPushedRouteIntents().size(), numRoutes);
assertEquals(intentSynchronizer.getPushedRouteIntents().size(),
numRoutes);
verify(intentService);
}
......@@ -295,8 +298,8 @@ public class SdnIpTest {
replay(intentService);
router.leaderChanged(true);
TestUtils.setField(router, "isActivatedLeader", true);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
// Send the add updates first
for (RouteUpdate update : routeUpdates) {
......@@ -314,7 +317,7 @@ public class SdnIpTest {
deleteCount.await(5000, TimeUnit.MILLISECONDS);
assertEquals(0, router.getRoutes().size());
assertEquals(0, router.getPushedRouteIntents().size());
assertEquals(0, intentSynchronizer.getPushedRouteIntents().size());
verify(intentService);
}
......
......@@ -95,7 +95,7 @@ public class BgpSessionManagerTest {
//
bgpSessionManager = new BgpSessionManager(dummyRouteListener);
// NOTE: We use port 0 to bind on any available port
bgpSessionManager.startUp(0);
bgpSessionManager.start(0);
// Get the port number the BGP Session Manager is listening on
Channel serverChannel = TestUtils.getField(bgpSessionManager,
......@@ -136,7 +136,7 @@ public class BgpSessionManagerTest {
@After
public void tearDown() throws Exception {
bgpSessionManager.shutDown();
bgpSessionManager.stop();
bgpSessionManager = null;
}
......