[Falcon] Componentize IntentSynchronizer and SdnIpFib.
Change-Id: Ic384ce00572ae1e4bbf94b4de814cea3499d3828
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
index 1265cc1..37c50d3 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
@@ -29,7 +29,9 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
+import org.onosproject.cluster.LeadershipServiceAdapter;
import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
@@ -43,14 +45,15 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
+import org.onosproject.net.intent.IntentUtils;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
-import org.onosproject.net.intent.IntentUtils;
import org.onosproject.routing.RouteEntry;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.ExecutorService;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
@@ -88,7 +91,8 @@
private IntentSynchronizer intentSynchronizer;
private final Set<Interface> interfaces = Sets.newHashSet();
- private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
+ private static final ApplicationId APPID =
+ TestApplicationId.create("intent-sync-test");
@Before
public void setUp() throws Exception {
@@ -98,8 +102,13 @@
intentService = createMock(IntentService.class);
- intentSynchronizer = new IntentSynchronizer(APPID, intentService,
- MoreExecutors.newDirectExecutorService());
+ intentSynchronizer = new TestIntentSynchronizer();
+
+ intentSynchronizer.coreService = new TestCoreService();
+ intentSynchronizer.leadershipService = new TestLeadershipService();
+ intentSynchronizer.intentService = intentService;
+
+ intentSynchronizer.activate();
}
/**
@@ -268,7 +277,7 @@
// Give the leadership to the intent synchronizer. It will now attempt
// to synchronize the intents in the store with the intents it has
// recorded based on the earlier user input.
- intentSynchronizer.leaderChanged(true);
+ intentSynchronizer.modifyPrimary(true);
verify(intentService);
}
@@ -290,7 +299,7 @@
// Give the intent synchronizer leadership so it will submit intents
// to the intent service
- intentSynchronizer.leaderChanged(true);
+ intentSynchronizer.modifyPrimary(true);
// Test the submit
intentSynchronizer.submit(intent);
@@ -303,7 +312,7 @@
reset(intentService);
replay(intentService);
- intentSynchronizer.leaderChanged(false);
+ intentSynchronizer.modifyPrimary(false);
intentSynchronizer.submit(intent);
@@ -328,7 +337,7 @@
// Give the intent synchronizer leadership so it will submit intents
// to the intent service
- intentSynchronizer.leaderChanged(true);
+ intentSynchronizer.modifyPrimary(true);
// Test the submit then withdraw
intentSynchronizer.submit(intent);
@@ -342,7 +351,7 @@
reset(intentService);
replay(intentService);
- intentSynchronizer.leaderChanged(false);
+ intentSynchronizer.modifyPrimary(false);
intentSynchronizer.submit(intent);
intentSynchronizer.withdraw(intent);
@@ -418,4 +427,22 @@
"ingressPoints", intent.ingressPoints());
return intentNew;
}
+
+ private class TestIntentSynchronizer extends IntentSynchronizer {
+ @Override
+ protected ExecutorService createExecutor() {
+ return MoreExecutors.newDirectExecutorService();
+ }
+ }
+
+ private class TestCoreService extends CoreServiceAdapter {
+ @Override
+ public ApplicationId registerApplication(String name) {
+ return APPID;
+ }
+ }
+
+ private class TestLeadershipService extends LeadershipServiceAdapter {
+
+ }
}
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
index 5466d52..5c3243f 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
@@ -28,6 +28,7 @@
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
@@ -42,8 +43,10 @@
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.routing.FibEntry;
+import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.IntentSynchronizationService;
+import org.onosproject.routing.RoutingServiceAdapter;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.RoutingConfigurationService;
@@ -90,6 +93,8 @@
private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
+ private FibListener fibListener;
+
@Before
public void setUp() throws Exception {
super.setUp();
@@ -106,7 +111,13 @@
intentSynchronizer = createMock(IntentSynchronizationService.class);
- sdnipFib = new SdnIpFib(APPID, interfaceService, intentSynchronizer);
+ sdnipFib = new SdnIpFib();
+ sdnipFib.routingService = new TestRoutingService();
+ sdnipFib.coreService = new TestCoreService();
+ sdnipFib.interfaceService = interfaceService;
+ sdnipFib.intentSynchronizer = intentSynchronizer;
+
+ sdnipFib.activate();
}
/**
@@ -242,7 +253,7 @@
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
- sdnipFib.update(Collections.singleton(fibUpdate), Collections.emptyList());
+ fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
verify(intentSynchronizer);
}
@@ -295,7 +306,7 @@
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
- sdnipFib.update(Collections.singleton(fibUpdate), Collections.emptyList());
+ fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
verify(intentSynchronizer);
}
@@ -354,7 +365,7 @@
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE,
fibEntryUpdate);
- sdnipFib.update(Collections.singletonList(fibUpdate),
+ fibListener.update(Collections.singletonList(fibUpdate),
Collections.emptyList());
verify(intentSynchronizer);
@@ -410,8 +421,23 @@
// Send in the DELETE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
- sdnipFib.update(Collections.emptyList(), Collections.singletonList(fibUpdate));
+ fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate));
verify(intentSynchronizer);
}
+
+ private class TestCoreService extends CoreServiceAdapter {
+ @Override
+ public ApplicationId getAppId(String name) {
+ return APPID;
+ }
+ }
+
+ private class TestRoutingService extends RoutingServiceAdapter {
+
+ @Override
+ public void addFibListener(FibListener fibListener) {
+ SdnIpFibTest.this.fibListener = fibListener;
+ }
+ }
}