WIP: Adding PathInstallRuntime for installing flow entries using FlowPusher
I also had to add several methods to our base classes to do type conversion,
which is a bit messy. Also, do to naming overlaps, we need to have some fully
specified class names.
Adding IntentRuntime service to drive the runtimes.
Change-Id: I675fbfe243b0bf18536425dfd9f9e6e5ca795845
diff --git a/src/main/java/net/onrc/onos/intent/runtime/IntentRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/IntentRuntime.java
new file mode 100644
index 0000000..567986e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/intent/runtime/IntentRuntime.java
@@ -0,0 +1,55 @@
+package net.onrc.onos.intent.runtime;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+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.floodlightcontroller.restserver.IRestApiService;
+import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService;
+
+public class IntentRuntime implements IFloodlightModule {
+ protected volatile IFloodlightProviderService floodlightProvider;
+ protected volatile INetworkGraphService networkGraph;
+ protected volatile IRestApiService restApi;
+
+ @Override
+ public void init(FloodlightModuleContext context)
+ throws FloodlightModuleException {
+ floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+ networkGraph = context.getServiceImpl(INetworkGraphService.class);
+ restApi = context.getServiceImpl(IRestApiService.class);
+ }
+
+ @Override
+ public void startUp(FloodlightModuleContext context) {
+ restApi.addRestletRoutable(new IntentWebRoutable());
+ }
+
+ @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(IRestApiService.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;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/intent/runtime/IntentWebRoutable.java b/src/main/java/net/onrc/onos/intent/runtime/IntentWebRoutable.java
new file mode 100644
index 0000000..533b55b
--- /dev/null
+++ b/src/main/java/net/onrc/onos/intent/runtime/IntentWebRoutable.java
@@ -0,0 +1,23 @@
+package net.onrc.onos.intent.runtime;
+
+import org.restlet.Context;
+import org.restlet.Restlet;
+import org.restlet.routing.Router;
+
+import net.floodlightcontroller.restserver.RestletRoutable;
+
+public class IntentWebRoutable implements RestletRoutable {
+
+ @Override
+ public Restlet getRestlet(Context context) {
+ Router router = new Router(context);
+ // TODO: add routes
+ return router;
+ }
+
+ @Override
+ public String basePath() {
+ return "/wm/onos/intent";
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathInstallRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PathInstallRuntime.java
new file mode 100644
index 0000000..0b74cfc
--- /dev/null
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathInstallRuntime.java
@@ -0,0 +1,48 @@
+package net.onrc.onos.intent.runtime;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.floodlightcontroller.core.IFloodlightProviderService;
+import net.floodlightcontroller.core.IOFSwitch;
+import net.onrc.onos.intent.FlowEntry;
+import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
+import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
+import net.onrc.onos.ofcontroller.util.Pair;
+
+/**
+ *
+ * @author Brian O'Connor <bocon@onlab.us>
+ *
+ */
+
+public class PathInstallRuntime {
+ NetworkGraph graph;
+ IFlowPusherService pusher;
+ IFloodlightProviderService provider;
+ protected List<Set<FlowEntry>> plan;
+
+ public PathInstallRuntime(NetworkGraph graph) {
+ this.graph = graph;
+ }
+
+ public void installPlan(List<Set<FlowEntry>> plan) {
+ this.plan = plan;
+ Map<Long,IOFSwitch> switches = provider.getSwitches();
+ for(Set<FlowEntry> phase : plan) {
+ Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries
+ = new HashSet<>();
+ // convert flow entries and create pairs
+ for(FlowEntry entry : phase) {
+ entries.add(new Pair<>(switches.get(entry.getSwitch().getDpid()),
+ entry.getFlowEntry()));
+ }
+ // push flow entries to switches
+ pusher.pushFlowEntries(entries);
+ // TODO: wait for confirmation messages before proceeding
+ }
+ }
+
+}