Added Intent Subscriber and Module
Module is used to drive plan computation and installation
Also, added support for ADD/REMOVE in plan computation
Change-Id: Ib88eae8b13a1f5ed1503c5ff7762980f8ed032ac
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java
new file mode 100644
index 0000000..df4c762
--- /dev/null
+++ b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java
@@ -0,0 +1,116 @@
+package net.onrc.onos.intent.runtime;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import net.floodlightcontroller.core.IFloodlightProviderService;
+import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.core.module.FloodlightModuleException;
+import net.floodlightcontroller.core.module.IFloodlightModule;
+import net.floodlightcontroller.core.module.IFloodlightService;
+import net.onrc.onos.datagrid.IDatagridService;
+import net.onrc.onos.datagrid.IEventChannelListener;
+import net.onrc.onos.intent.FlowEntry;
+import net.onrc.onos.intent.IntentOperationList;
+import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
+import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
+
+public class PlanInstallModule implements IFloodlightModule {
+ protected volatile IFloodlightProviderService floodlightProvider;
+ protected volatile NetworkGraph networkGraph;
+ protected volatile IDatagridService datagridService;
+ protected volatile IFlowPusherService flowPusher;
+ private PlanCalcRuntime planCalc;
+ private PlanInstallRuntime planInstall;
+ private EventListener eventListener;
+
+ private static final String PATH_INTENT_CHANNEL_NAME = "onos.pathintent";
+
+ @Override
+ public void init(FloodlightModuleContext context)
+ throws FloodlightModuleException {
+ floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+ //networkGraph = context.getServiceImpl(INetworkGraphService.class);
+ datagridService = context.getServiceImpl(IDatagridService.class);
+ flowPusher = context.getServiceImpl(IFlowPusherService.class);
+ planCalc = new PlanCalcRuntime(networkGraph);
+ planInstall = new PlanInstallRuntime(networkGraph, floodlightProvider, flowPusher);
+ eventListener = new EventListener();
+ }
+
+ class EventListener extends Thread
+ implements IEventChannelListener<Long, IntentOperationList> {
+
+ private BlockingQueue<IntentOperationList> intentQueue = new LinkedBlockingQueue<>();
+
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ IntentOperationList intents = intentQueue.take();
+ //TODO: drain the remaining intent lists
+ processIntents(intents);
+ } catch (InterruptedException e) {
+ //TODO: log the exception
+ }
+ }
+ }
+
+ private void processIntents(IntentOperationList intents) {
+ List<Set<FlowEntry>> plan = planCalc.computePlan(intents);
+ planInstall.installPlan(plan);
+ }
+
+ @Override
+ public void entryAdded(IntentOperationList value) {
+ intentQueue.add(value);
+ }
+
+ @Override
+ public void entryRemoved(IntentOperationList value) {
+ // This channel is a queue, so this method is not needed
+ }
+
+ @Override
+ public void entryUpdated(IntentOperationList value) {
+ // This channel is a queue, so this method is not needed
+ }
+ }
+ @Override
+ public void startUp(FloodlightModuleContext context) {
+ eventListener.start();
+ datagridService.addListener(PATH_INTENT_CHANNEL_NAME,
+ new EventListener(),
+ Long.class,
+ IntentOperationList.class);
+ }
+
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
+ Collection<Class<? extends IFloodlightService>> l =
+ new ArrayList<Class<? extends IFloodlightService>>();
+ l.add(IFloodlightProviderService.class);
+// l.add(INetworkGraphService.class);
+ l.add(IDatagridService.class);
+ l.add(IFlowPusherService.class);
+ return l;
+ }
+
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleServices() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}