Listen to edge removal and invoke flow reconciliation
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
index 640c7e3..be56ec2 100644
--- a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
@@ -302,5 +302,7 @@
@Adjacency(label="switch")
public void setOutPort(IPortObject port);
+ @Adjacency(label="flow")
+ public IFlowPath getFlowPath();
}
}
diff --git a/src/main/java/net/floodlightcontroller/util/FlowPath.java b/src/main/java/net/floodlightcontroller/util/FlowPath.java
index 7fcb2e6..f4c25c2 100644
--- a/src/main/java/net/floodlightcontroller/util/FlowPath.java
+++ b/src/main/java/net/floodlightcontroller/util/FlowPath.java
@@ -1,5 +1,9 @@
package net.floodlightcontroller.util;
+import java.util.ArrayList;
+
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.floodlightcontroller.util.CallerId;
import net.floodlightcontroller.util.DataPath;
import net.floodlightcontroller.util.FlowId;
@@ -20,6 +24,75 @@
public FlowPath() {
dataPath = new DataPath();
}
+
+ /**
+ * Constructor to instantiate from object in Network Map
+ */
+ public FlowPath(IFlowPath flowObj) {
+ dataPath = new DataPath();
+ this.setFlowId(new FlowId(flowObj.getFlowId()));
+ this.setInstallerId(new CallerId(flowObj.getInstallerId()));
+ this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
+ this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
+ this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
+ this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
+
+ //
+ // Extract all Flow Entries
+ //
+ Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
+ for (IFlowEntry flowEntryObj : flowEntries) {
+ FlowEntry flowEntry = new FlowEntry();
+ flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
+ flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
+
+ //
+ // Extract the match conditions
+ //
+ FlowEntryMatch match = new FlowEntryMatch();
+ Short matchInPort = flowEntryObj.getMatchInPort();
+ if (matchInPort != null)
+ match.enableInPort(new Port(matchInPort));
+ Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
+ if (matchEthernetFrameType != null)
+ match.enableEthernetFrameType(matchEthernetFrameType);
+ String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
+ if (matchSrcIPv4Net != null)
+ match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
+ String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
+ if (matchDstIPv4Net != null)
+ match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
+ String matchSrcMac = flowEntryObj.getMatchSrcMac();
+ if (matchSrcMac != null)
+ match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
+ String matchDstMac = flowEntryObj.getMatchDstMac();
+ if (matchDstMac != null)
+ match.enableDstMac(MACAddress.valueOf(matchDstMac));
+ flowEntry.setFlowEntryMatch(match);
+
+ //
+ // Extract the actions
+ //
+ ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
+ Short actionOutputPort = flowEntryObj.getActionOutput();
+ if (actionOutputPort != null) {
+ FlowEntryAction action = new FlowEntryAction();
+ action.setActionOutput(new Port(actionOutputPort));
+ actions.add(action);
+ }
+ flowEntry.setFlowEntryActions(actions);
+
+ String userState = flowEntryObj.getUserState();
+ flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
+ String switchState = flowEntryObj.getSwitchState();
+ flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
+ //
+ // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
+ // and FlowEntryErrorState.
+ //
+ this.dataPath().flowEntries().add(flowEntry);
+ }
+ }
/**
* Get the flow path Flow ID.
diff --git a/src/main/java/net/onrc/onos/flow/IFlowManager.java b/src/main/java/net/onrc/onos/flow/IFlowManager.java
index f2f9d49..1c90e56 100644
--- a/src/main/java/net/onrc/onos/flow/IFlowManager.java
+++ b/src/main/java/net/onrc/onos/flow/IFlowManager.java
@@ -38,7 +38,7 @@
* @param port the port to match.
* @return the list of flows that are going out from the port.
*/
- public Iterable<FlowPath> getFlows(IPortObject port);
+ public Iterable<FlowPath> getOutFlows(IPortObject port);
/**
* Reconcile all flows on inactive port (src port of link which might be
diff --git a/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java b/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java
new file mode 100644
index 0000000..186ba58
--- /dev/null
+++ b/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java
@@ -0,0 +1,92 @@
+package net.onrc.onos.util;
+
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.floodlightcontroller.linkdiscovery.internal.TopoLinkServiceImpl;
+import net.floodlightcontroller.util.FlowPath;
+import net.onrc.onos.flow.FlowManagerImpl;
+import net.onrc.onos.flow.IFlowManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.thinkaurelius.titan.core.TitanEdge;
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener;
+
+public class LocalTopologyEventListener implements GraphChangedListener {
+
+ protected static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
+ protected static GraphDBConnection conn = GraphDBConnection.getInstance("");
+
+ @Override
+ public void edgeAdded(Edge arg0) {
+ // TODO Auto-generated method stub
+ // Convert this Event into NetMapEvent (LinkAdded, FlowEntryEnabled, HostAttached, PortEnabled)
+ }
+
+ @Override
+ public void edgePropertyChanged(Edge arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ // Generate State change events on edges too
+ }
+
+ @Override
+ public void edgePropertyRemoved(Edge arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ // Currently not needed
+
+ }
+
+ @Override
+ public void edgeRemoved(Edge e) {
+ // TODO Auto-generated method stub
+ // Fire NetMapEvents (LinkRemoved, FlowEntryRemoved, HostRemoved, PortRemoved)
+ TitanEdge edge = (TitanEdge) e;
+ log.debug("TopologyEvents: Received edge removed event: {}",edge.toString());
+ String label = edge.getLabel();
+ if (label.equals("link")) {
+ Vertex v = edge.getVertex(Direction.IN);
+ IPortObject src_port = conn.getFramedGraph().frame(v, IPortObject.class);
+ v = edge.getVertex(Direction.OUT);
+ IPortObject dest_port = conn.getFramedGraph().frame(v, IPortObject.class);
+
+ log.debug("TopologyEvents: link broken {}", new Object []{src_port.getSwitch().getDPID(),
+ src_port.getNumber(),
+ dest_port.getSwitch().getDPID(),
+ dest_port.getNumber()});
+ IFlowManager manager = new FlowManagerImpl();
+ // TODO: Find the flows and add to reconcile queue
+ manager.reconcileFlows(src_port);
+ }
+ }
+
+ @Override
+ public void vertexAdded(Vertex arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+
+
+ }
+
+ @Override
+ public void vertexPropertyRemoved(Vertex arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void vertexRemoved(Vertex arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}