Began integration with ONOS discovery code by implementing add switch and add link
Change-Id: I21426ea7031df20701d186cb2840a380fa334728
Made NetworkGraphModule to provide access to the global NetworkGraph instance
Change-Id: Ie2293b97f9fb6bdeaa5140c244a21c107d5e1ca7
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java
new file mode 100644
index 0000000..71a5d53
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java
@@ -0,0 +1,23 @@
+package net.onrc.onos.ofcontroller.networkgraph;
+
+import net.floodlightcontroller.core.module.IFloodlightService;
+
+/**
+ * Interface for providing the Network Graph Service to other modules.
+ */
+public interface INetworkGraphService extends IFloodlightService {
+ /**
+ * Allows a module to get a reference to the global network graph object.
+ * @return
+ */
+ public NetworkGraph getNetworkGraph();
+
+ /**
+ * Allows a module to get a reference to the southbound interface to
+ * the network graph.
+ * TODO Figure out how to hide the southbound interface from
+ * applications/modules that shouldn't touch it
+ * @return
+ */
+ public SouthboundNetworkGraph getSouthboundNetworkGraph();
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java
new file mode 100644
index 0000000..490f30f
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java
@@ -0,0 +1,68 @@
+package net.onrc.onos.ofcontroller.networkgraph;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.core.module.FloodlightModuleException;
+import net.floodlightcontroller.core.module.IFloodlightModule;
+import net.floodlightcontroller.core.module.IFloodlightService;
+
+public class NetworkGraphModule implements IFloodlightModule, INetworkGraphService {
+
+ // This is initialized as a module for now
+ // private RCNetworkGraphPublisher eventListener;
+
+ private NetworkGraphImpl networkGraph;
+ private SouthboundNetworkGraph southboundNetworkGraph;
+
+
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleServices() {
+ List<Class<? extends IFloodlightService>> services =
+ new ArrayList<Class<? extends IFloodlightService>>();
+ services.add(INetworkGraphService.class);
+ return services;
+ }
+
+ @Override
+ public Map<Class<? extends IFloodlightService>, IFloodlightService>
+ getServiceImpls() {
+ Map<Class<? extends IFloodlightService>, IFloodlightService> impls =
+ new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
+ impls.put(INetworkGraphService.class, this);
+ return impls;
+ }
+
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
+ return null;
+ }
+
+ @Override
+ public void init(FloodlightModuleContext context)
+ throws FloodlightModuleException {
+ networkGraph = new NetworkGraphImpl();
+ southboundNetworkGraph = new SouthboundNetworkGraph(networkGraph);
+ }
+
+ @Override
+ public void startUp(FloodlightModuleContext context) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public NetworkGraph getNetworkGraph() {
+ return networkGraph;
+ }
+
+ @Override
+ public SouthboundNetworkGraph getSouthboundNetworkGraph() {
+ return southboundNetworkGraph;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
index b1f4213..e9de665 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
@@ -36,10 +36,15 @@
private static final Logger log = LoggerFactory.getLogger(SouthboundNetworkGraph.class);
private static final int NUM_RETRIES = 10;
+
+ private final NetworkGraphImpl graph;
+ public SouthboundNetworkGraph(NetworkGraphImpl graph) {
+ this.graph = graph;
+ }
public void addSwitch(Switch sw) {
-
+ log.debug("Adding switch {}", sw);
ArrayList<WriteOp> groupOp = new ArrayList<>();
RCSwitch rcSwitch = new RCSwitch(sw.getDpid());
@@ -61,7 +66,7 @@
boolean failed = RCObject.multiWrite( groupOp );
if ( failed ) {
- log.error("Adding Switch {} and it's ports failed.", sw.getDpid());
+ log.error("Adding Switch {} and its ports failed.", sw.getDpid());
for ( WriteOp op : groupOp ) {
log.debug("Operation:{} for {} - Result:{}", op.getOp(), op.getObject(), op.getStatus() );
@@ -69,10 +74,15 @@
// Conditional operation (Create/Update) then we should retry here.
}
}
+ else {
+ // Publish event to the in-memory cache
+ graph.addSwitch(sw);
+ }
}
public void deactivateSwitch(Switch sw) {
+ log.debug("Deactivating switch {}", sw);
RCSwitch rcSwitch = new RCSwitch(sw.getDpid());
List<RCObject> objectsToDeactive = new ArrayList<RCObject>();
@@ -111,6 +121,7 @@
}
public void addPort(Switch sw, Port port) {
+ log.debug("Adding port {}", port);
RCSwitch rcSwitch = new RCSwitch(sw.getDpid());
try {
@@ -129,6 +140,7 @@
}
public void deactivatePort(Port port) {
+ log.debug("Deactivating port {}", port);
RCPort rcPort = new RCPort(port.getSwitch().getDpid(), (long)port.getNumber());
for (int i = 0; i < NUM_RETRIES; i++) {
@@ -152,6 +164,7 @@
}
public void addLink(Link link) {
+ log.debug("Adding link {}", link);
RCLink rcLink = new RCLink(link.getSourceSwitchDpid(), (long)link.getSourcePortNumber(),
link.getDestinationSwitchDpid(), (long)link.getDestinationPortNumber());
@@ -187,9 +200,13 @@
// retry
}
}
+
+ // Publish event to in-memory cache
+ graph.addLink(link);
}
public void removeLink(Link link) {
+ log.debug("Removing link {}", link);
RCLink rcLink = new RCLink(link.getSourceSwitchDpid(), (long)link.getSourcePortNumber(),
link.getDestinationSwitchDpid(), (long)link.getDestinationPortNumber());