First sketch of instance local topology event handler.
TODO:
* Not sure if INetworkGraphListener should pass SelfContained Event Object or In-memory Object
Change-Id: If44b70a54f087357b7e830cebcf5dba985cf7797
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphListener.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphListener.java
new file mode 100644
index 0000000..88806ef
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphListener.java
@@ -0,0 +1,22 @@
+package net.onrc.onos.ofcontroller.networkgraph;
+
+/**
+ * Interface which needs to be implemented to receive Topology events from
+ * NetworkGraph
+ *
+ * TODO Should these interface hand over Event object or Object in NetworkGraph.
+ */
+public interface INetworkGraphListener {
+ public void putSwitchEvent(SwitchEvent switchEvent);
+ public void removeSwitchEvent(SwitchEvent switchEvent);
+
+ public void putPortEvent(PortEvent portEvent);
+ public void removePortEvent(PortEvent portEvent);
+
+ public void putLinkEvent(LinkEvent linkEvent);
+ public void removeLinkEvent(LinkEvent linkEvent);
+
+ public void putDeviceEvent(DeviceEvent deviceEvent);
+ public void removeDeviceEvent(DeviceEvent deviceEvent);
+
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java
index 318c0f7..5d94f65 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/INetworkGraphService.java
@@ -11,11 +11,14 @@
* @return
*/
public NetworkGraph getNetworkGraph();
-
+
+ public void registerNetworkGraphListener(INetworkGraphListener listener);
+ public void deregisterNetworkGraphListener(INetworkGraphListener listener);
+
/**
* 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
+ * TODO Figure out how to hide the southbound interface from
* applications/modules that shouldn't touch it
* @return
*/
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
index 8b6faeb..ae71633 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -8,6 +8,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import net.onrc.onos.datagrid.IDatagridService;
@@ -50,11 +51,13 @@
private final NetworkGraphDatastore datastore;
private final IControllerRegistryService registryService;
+ private CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners;
- public NetworkGraphImpl(IControllerRegistryService registryService) {
+ public NetworkGraphImpl(IControllerRegistryService registryService, CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners) {
super();
datastore = new NetworkGraphDatastore(this);
this.registryService = registryService;
+ this.networkGraphListeners = networkGraphListeners;
}
/**
@@ -571,7 +574,8 @@
putSwitch(switchEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchPutSwitchEvent(switchEvent);
}
@Override
@@ -580,7 +584,8 @@
removeSwitch(switchEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchRemoveSwitchEvent(switchEvent);
}
@Override
@@ -589,7 +594,8 @@
putPort(portEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchPutPortEvent(portEvent);
}
@Override
@@ -598,7 +604,8 @@
removePort(portEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchRemovePortEvent(portEvent);
}
@Override
@@ -607,7 +614,8 @@
putLink(linkEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchPutLinkEvent(linkEvent);
}
@Override
@@ -616,7 +624,8 @@
removeLink(linkEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchRemoveLinkEvent(linkEvent);
}
@Override
@@ -625,7 +634,8 @@
putDevice(deviceEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchPutDeviceEvent(deviceEvent);
}
@Override
@@ -634,7 +644,8 @@
removeDevice(deviceEvent);
}
// TODO handle invariant violation
- // TODO trigger instance local topology event handler
+ // trigger instance local topology event handler
+ dispatchRemoveDeviceEvent(deviceEvent);
}
/* ************************************************
@@ -1052,6 +1063,62 @@
}
}
+ private void dispatchPutSwitchEvent(SwitchEvent switchEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.putSwitchEvent(switchEvent);
+ }
+ }
+
+ private void dispatchRemoveSwitchEvent(SwitchEvent switchEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.removeSwitchEvent(switchEvent);
+ }
+ }
+
+ private void dispatchPutPortEvent(PortEvent portEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.putPortEvent(portEvent);
+ }
+ }
+
+ private void dispatchRemovePortEvent(PortEvent portEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.removePortEvent(portEvent);
+ }
+ }
+
+ private void dispatchPutLinkEvent(LinkEvent linkEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.putLinkEvent(linkEvent);
+ }
+ }
+
+ private void dispatchRemoveLinkEvent(LinkEvent linkEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.removeLinkEvent(linkEvent);
+ }
+ }
+
+ private void dispatchPutDeviceEvent(DeviceEvent deviceEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.putDeviceEvent(deviceEvent);;
+ }
+ }
+
+ private void dispatchRemoveDeviceEvent(DeviceEvent deviceEvent) {
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO Should copy before handing them over to listener
+ listener.removeDeviceEvent(deviceEvent);
+ }
+ }
+
private SwitchImpl getSwitchImpl(Switch sw) {
if (sw instanceof SwitchImpl) {
return (SwitchImpl) sw;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java
index 97fa4b5..80f0d0b 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphModule.java
@@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
@@ -25,6 +26,7 @@
private IDatagridService datagridService;
private IControllerRegistryService registryService;
+ private CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners;
private IRestApiService restApi;
@@ -61,7 +63,8 @@
datagridService = context.getServiceImpl(IDatagridService.class);
registryService = context.getServiceImpl(IControllerRegistryService.class);
- networkGraph = new NetworkGraphImpl(registryService);
+ networkGraphListeners = new CopyOnWriteArrayList<>();
+ networkGraph = new NetworkGraphImpl(registryService, networkGraphListeners);
//southboundNetworkGraph = new NetworkGraphDatastore(networkGraph);
}
@@ -81,4 +84,14 @@
return networkGraph;
}
+ @Override
+ public void registerNetworkGraphListener(INetworkGraphListener listener) {
+ networkGraphListeners.addIfAbsent(listener);
+ }
+
+ @Override
+ public void deregisterNetworkGraphListener(INetworkGraphListener listener) {
+ networkGraphListeners.remove(listener);
+ }
+
}