* Add FlowPathFlags to the FlowPath header.
* Implement DISCARD_FIRST_HOP_ENTRY and KEEP_ONLY_FIRST_HOP_ENTRY flags:
- DISCARD_FIRST_HOP_ENTRY : After computing the shortest-path, the
first-hop entry is discarded
- KEEP_ONLY_FIRST_HOP_ENTRY : After computing the shortest-path,
only the the first hop entry is kept, and the rest are discarded.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
index 04f9384..2672a6b 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
@@ -200,6 +200,13 @@
@Property("installer_id")
public void setInstallerId(String installerId);
+ @JsonProperty("flowPathFlags")
+ @Property("flow_path_flags")
+ public Long getFlowPathFlags();
+
+ @Property("flow_path_flags")
+ public void setFlowPathFlags(Long flowPathFlags);
+
@JsonProperty("srcDpid")
@Property("src_switch")
public String getSrcSwitch();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index ebef1f4..969d41e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -48,6 +48,7 @@
import net.onrc.onos.ofcontroller.util.FlowEntryUserState;
import net.onrc.onos.ofcontroller.util.FlowId;
import net.onrc.onos.ofcontroller.util.FlowPath;
+import net.onrc.onos.ofcontroller.util.FlowPathFlags;
import net.onrc.onos.ofcontroller.util.IPv4Net;
import net.onrc.onos.ofcontroller.util.Port;
import net.onrc.onos.ofcontroller.util.SwitchPort;
@@ -330,9 +331,11 @@
Short srcPortShort = flowPathObj.getSrcPort();
String dstDpidStr = flowPathObj.getDstSwitch();
Short dstPortShort = flowPathObj.getDstPort();
+ Long flowPathFlagsLong = flowPathObj.getFlowPathFlags();
if ((srcPortShort == null) ||
(dstDpidStr == null) ||
- (dstPortShort == null)) {
+ (dstPortShort == null) ||
+ (flowPathFlagsLong == null)) {
continue;
}
@@ -341,6 +344,7 @@
Port dstPort = new Port(dstPortShort);
SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
+ FlowPathFlags flowPathFlags = new FlowPathFlags(flowPathFlagsLong);
counterMyFlowPaths++;
@@ -363,6 +367,7 @@
dataPath.setSrcPort(srcSwitchPort);
dataPath.setDstPort(dstSwitchPort);
}
+ dataPath.applyFlowPathFlags(flowPathFlags);
String newDataPathSummaryStr = dataPath.dataPathSummary();
if (dataPathSummaryStr.equals(newDataPathSummaryStr))
@@ -568,6 +573,7 @@
//
// Set the Flow attributes:
// - flowPath.installerId()
+ // - flowPath.flowPathFlags()
// - flowPath.dataPath().srcPort()
// - flowPath.dataPath().dstPort()
// - flowPath.matchSrcMac()
@@ -583,6 +589,7 @@
// - flowPath.matchDstTcpUdpPort()
//
flowObj.setInstallerId(flowPath.installerId().toString());
+ flowObj.setFlowPathFlags(flowPath.flowPathFlags().flags());
flowObj.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString());
flowObj.setSrcPort(flowPath.dataPath().srcPort().port().value());
flowObj.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString());
@@ -1314,6 +1321,7 @@
//
String flowIdStr = flowObj.getFlowId();
String installerIdStr = flowObj.getInstallerId();
+ Long flowPathFlags = flowObj.getFlowPathFlags();
String srcSwitchStr = flowObj.getSrcSwitch();
Short srcPortShort = flowObj.getSrcPort();
String dstSwitchStr = flowObj.getDstSwitch();
@@ -1321,6 +1329,7 @@
if ((flowIdStr == null) ||
(installerIdStr == null) ||
+ (flowPathFlags == null) ||
(srcSwitchStr == null) ||
(srcPortShort == null) ||
(dstSwitchStr == null) ||
@@ -1332,6 +1341,7 @@
FlowPath flowPath = new FlowPath();
flowPath.setFlowId(new FlowId(flowIdStr));
flowPath.setInstallerId(new CallerId(installerIdStr));
+ flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags));
flowPath.dataPath().srcPort().setDpid(new Dpid(srcSwitchStr));
flowPath.dataPath().srcPort().setPort(new Port(srcPortShort));
flowPath.dataPath().dstPort().setDpid(new Dpid(dstSwitchStr));
@@ -1505,6 +1515,7 @@
FlowPath computedFlowPath = new FlowPath();
computedFlowPath.setFlowId(new FlowId(flowPath.flowId().value()));
computedFlowPath.setInstallerId(new CallerId(flowPath.installerId().value()));
+ computedFlowPath.setFlowPathFlags(new FlowPathFlags(flowPath.flowPathFlags().flags()));
computedFlowPath.setDataPath(dataPath);
computedFlowPath.setFlowEntryMatch(new FlowEntryMatch(flowPath.flowEntryMatch()));
@@ -2107,6 +2118,7 @@
dataPath.setSrcPort(flowPath.dataPath().srcPort());
dataPath.setDstPort(flowPath.dataPath().dstPort());
}
+ dataPath.applyFlowPathFlags(flowPath.flowPathFlags());
//
// Set the incoming port matching and the outgoing port output
@@ -2135,6 +2147,7 @@
FlowPath computedFlowPath = new FlowPath();
computedFlowPath.setFlowId(new FlowId(flowPath.flowId().value()));
computedFlowPath.setInstallerId(new CallerId(flowPath.installerId().value()));
+ computedFlowPath.setFlowPathFlags(new FlowPathFlags(flowPath.flowPathFlags().flags()));
computedFlowPath.setDataPath(dataPath);
computedFlowPath.setFlowEntryMatch(new FlowEntryMatch(flowPath.flowEntryMatch()));
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/AddShortestPathFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/AddShortestPathFlowResource.java
index 9d2e0c9..2a75c6a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/AddShortestPathFlowResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/AddShortestPathFlowResource.java
@@ -53,10 +53,11 @@
if (flowPath != null) {
FlowPath addedFlowPath =
flowService.addAndMaintainShortestPathFlow(flowPath);
- if (addedFlowPath == null)
+ if (addedFlowPath == null) {
result = new FlowId(); // Error: Return empty Flow Id
- else
+ } else {
result = addedFlowPath.flowId();
+ }
}
return result;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java b/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
index 5f96414..9b06743 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
@@ -76,6 +76,31 @@
}
/**
+ * Apply Flow Path Flags to the pre-computed Data Path.
+ *
+ * @param flowPathFlags the Flow Path Flags to apply.
+ */
+ public void applyFlowPathFlags(FlowPathFlags flowPathFlags) {
+ if (flowPathFlags == null)
+ return; // Nothing to do
+
+ // Discard the first Flow Entry
+ if (flowPathFlags.isDiscardFirstHopEntry()) {
+ if (flowEntries.size() > 0)
+ flowEntries.remove(0);
+ }
+
+ // Keep only the first Flow Entry
+ if (flowPathFlags.isKeepOnlyFirstHopEntry()) {
+ if (flowEntries.size() > 1) {
+ FlowEntry flowEntry = flowEntries.get(0);
+ flowEntries.clear();
+ flowEntries.add(flowEntry);
+ }
+ }
+ }
+
+ /**
* Get a string with the summary of the shortest-path data path
* computation.
*
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java
index 4a8fc7b..2f4d421 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java
@@ -5,6 +5,7 @@
import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.util.FlowPathFlags;
import org.codehaus.jackson.annotate.JsonProperty;
@@ -14,6 +15,7 @@
public class FlowPath implements Comparable<FlowPath> {
private FlowId flowId; // The Flow ID
private CallerId installerId; // The Caller ID of the path installer
+ private FlowPathFlags flowPathFlags; // The Flow Path flags
private DataPath dataPath; // The data path
private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
// Flow Entries
@@ -22,6 +24,7 @@
* Default constructor.
*/
public FlowPath() {
+ flowPathFlags = new FlowPathFlags();
dataPath = new DataPath();
}
@@ -32,6 +35,7 @@
dataPath = new DataPath();
this.setFlowId(new FlowId(flowObj.getFlowId()));
this.setInstallerId(new CallerId(flowObj.getInstallerId()));
+ this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
@@ -190,6 +194,24 @@
}
/**
+ * Get the flow path flags.
+ *
+ * @return the flow path flags.
+ */
+ @JsonProperty("flowPathFlags")
+ public FlowPathFlags flowPathFlags() { return flowPathFlags; }
+
+ /**
+ * Set the flow path flags.
+ *
+ * @param flowPathFlags the flow path flags to set.
+ */
+ @JsonProperty("flowPathFlags")
+ public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
+ this.flowPathFlags = flowPathFlags;
+ }
+
+ /**
* Get the flow path's data path.
*
* @return the flow path's data path.
@@ -230,7 +252,7 @@
* Convert the flow path to a string.
*
* The string has the following form:
- * [flowId=XXX installerId=XXX dataPath=XXX]
+ * [flowId=XXX installerId=XXX flowPathFlags=XXX dataPath=XXX]
*
* @return the flow path as a string.
*/
@@ -238,6 +260,7 @@
public String toString() {
String ret = "[flowId=" + this.flowId.toString();
ret += " installerId=" + this.installerId.toString();
+ ret += " flowPathFlags=" + this.flowPathFlags.toString();
if (dataPath != null)
ret += " dataPath=" + this.dataPath.toString();
if (flowEntryMatch != null)
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java
new file mode 100644
index 0000000..63241f0
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java
@@ -0,0 +1,128 @@
+package net.onrc.onos.ofcontroller.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing the Flow Path flags.
+ */
+public class FlowPathFlags {
+ private long flags;
+
+ // Discard the first-hop Flow Entry
+ private final long DISCARD_FIRST_HOP_ENTRY = (1 << 0);
+
+ // Keep only the first-hop Flow Entry
+ private final long KEEP_ONLY_FIRST_HOP_ENTRY = (1 << 1);
+
+ /**
+ * Default constructor.
+ */
+ public FlowPathFlags() {
+ this.flags = 0;
+ }
+
+ /**
+ * Constructor for given flags.
+ *
+ * @param flags the flags value to set.
+ */
+ public FlowPathFlags(long flags) {
+ this.flags = flags;
+ }
+
+ /**
+ * Constructor for given flags as a string.
+ *
+ * The string value should contain the name of each flags to set. E.g.:
+ * "DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY"
+ * @param flagsStr the string value of the flags to set.
+ */
+ public FlowPathFlags(String flagsStr) {
+ this.setFlagsStr(flagsStr);
+ }
+
+ /**
+ * Get the flags.
+ *
+ * @return the flags.
+ */
+ @JsonProperty("flags")
+ public long flags() { return flags; }
+
+ /**
+ * Set the flags.
+ *
+ * @param flags the flags value to set.
+ */
+ @JsonProperty("flags")
+ public void setFlags(long flags) {
+ this.flags = flags;
+ }
+
+ /**
+ * Set the flags as a string.
+ *
+ * The string value should contain the name of each flags to set. E.g.:
+ * "DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY"
+ * @param flagsStr the string value of the flags to set.
+ */
+ @JsonProperty("flagsStr")
+ public void setFlagsStr(String flagsStr) {
+ this.flags = 0L;
+
+ // Test all flags
+ if (flagsStr.contains("DISCARD_FIRST_HOP_ENTRY"))
+ this.flags |= DISCARD_FIRST_HOP_ENTRY;
+ if (flagsStr.contains("KEEP_ONLY_FIRST_HOP_ENTRY"))
+ this.flags |= KEEP_ONLY_FIRST_HOP_ENTRY;
+ }
+
+ /**
+ * Test whether the DISCARD_FIRST_HOP_ENTRY flag is set.
+ *
+ * @return true if the DISCARD_FIRST_HOP_ENTRY flag is set,
+ * otherwise false.
+ */
+ public boolean isDiscardFirstHopEntry() {
+ return ((flags & DISCARD_FIRST_HOP_ENTRY) != 0);
+ }
+
+ /**
+ * Test whether the KEEP_ONLY_FIRST_HOP_ENTRY flag is set.
+ *
+ * @return true if the KEEP_ONLY_FIRST_HOP_ENTRY flag is set,
+ * otherwise false.
+ */
+ public boolean isKeepOnlyFirstHopEntry() {
+ return ((flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0);
+ }
+
+ /**
+ * Convert the Flow Path Flags to a string.
+ *
+ * The string has the following form:
+ * [flags=DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY]
+ *
+ * @return the Flow Path flags as a string.
+ */
+ @Override
+ public String toString() {
+ String flagsStr = null;
+ String ret = "[flags=";
+
+ // Test all flags
+ if ((this.flags & DISCARD_FIRST_HOP_ENTRY) != 0) {
+ if (flagsStr != null)
+ flagsStr += ",";
+ flagsStr += "DISCARD_FIRST_HOP_ENTRY";
+ }
+ if ((this.flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0) {
+ if (flagsStr != null)
+ flagsStr += ",";
+ flagsStr += "KEEP_ONLY_FIRST_HOP_ENTRY";
+ }
+ ret += "]";
+
+ return ret;
+ }
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
index 85072e3..bb0dbbf 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
@@ -104,6 +104,24 @@
/**
* Desc:
+ * Test method for get and set FlowPathFlags method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the Flow Path Flags.
+ * 2. Should get the Flow Path Flags.
+ */
+ @Test
+ public void testSetGetFlowPathFlags() {
+ String flowId = "xx";
+ Long flowPathFlags = new Long(0x3);
+ flowPath.setFlowId(flowId);
+ flowPath.setFlowPathFlags(flowPathFlags);
+ assertEquals(flowPath.getFlowPathFlags(), flowPathFlags);
+ }
+
+ /**
+ * Desc:
* Test method for get and set SourceSwitch method.
* Condition:
* N/A
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
index fb5227f..f746060 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
@@ -415,6 +415,7 @@
public static class TestFlowPath implements IFlowPath {
private String state,type,flowId,installerId,srcSw,dstSw;
+ private Long flowPathFlags;
private String dataPathSummary,userState;
private Short srcPort,dstPort;
private String matchSrcMac,matchDstMac;
@@ -429,6 +430,7 @@
private List<ISwitchObject> switches;
private String stateToUpdate,typeToUpdate,flowIdToUpdate,installerIdToUpdate,srcSwToUpdate,dstSwToUpdate;
+ private Long flowPathFlagsToUpdate;
private String dataPathSummaryToUpdate,userStateToUpdate;
private Short srcPortToUpdate,dstPortToUpdate;
private String matchSrcMacToUpdate,matchDstMacToUpdate;
@@ -465,6 +467,7 @@
if(typeToUpdate != null) { type = typeToUpdate; }
if(flowIdToUpdate != null) { flowId = flowIdToUpdate; }
if(installerIdToUpdate != null) { installerId = installerIdToUpdate; }
+ if(flowPathFlagsToUpdate != null) { flowPathFlags = flowPathFlagsToUpdate; }
if(srcSwToUpdate != null) { srcSw = srcSwToUpdate; }
if(dstSwToUpdate != null) { dstSw = dstSwToUpdate; }
if(dataPathSummaryToUpdate != null) { dataPathSummary = dataPathSummaryToUpdate; }
@@ -493,6 +496,7 @@
flowsToRemove.clear();
stateToUpdate = typeToUpdate = flowIdToUpdate = installerIdToUpdate = null;
+ flowPathFlagsToUpdate = null;
srcSwToUpdate = dstSwToUpdate = dataPathSummaryToUpdate = userStateToUpdate = null;
srcPortToUpdate = dstPortToUpdate = null;
matchSrcMacToUpdate = matchDstMacToUpdate = null;
@@ -509,6 +513,7 @@
public void setTypeForTest(String type) { this.type = type; }
public void setFlowIdForTest(String flowId) { this.flowId = flowId; }
public void setInstallerIdForTest(String installerId) { this.installerId = installerId; }
+ public void setFlowPathFlagsForTest(Long flowPathFlags) { this.flowPathFlags = flowPathFlags; }
public void setSrcSwForTest(String srcSw) { this.srcSw = srcSw; }
public void setDstSwForTest(String dstSw) { this.dstSw = dstSw; }
public void setDataPathSummaryForTest(String dataPathSummary) { this.dataPathSummary = dataPathSummary; }
@@ -560,6 +565,12 @@
public void setInstallerId(String installerId) { installerIdToUpdate = installerId; }
@Override
+ public Long getFlowPathFlags() { return flowPathFlags; }
+
+ @Override
+ public void setFlowPathFlags(Long flowPathFlags) { flowPathFlagsToUpdate = flowPathFlags; }
+
+ @Override
public String getSrcSwitch() { return srcSw; }
@Override
diff --git a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
index 750bfba..cacedd2 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -80,10 +80,12 @@
}
private IFlowPath createIFlowPathMock(long flowId, String installerID,
+ long flowPathFlags,
long srcDpid, int srcPort, long dstDpid, int dstPort) {
IFlowPath iFlowPath = createNiceMock(IFlowPath.class);
expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes();
expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes();
+ expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes();
expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes();
expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes();
expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes();
@@ -92,12 +94,14 @@
}
private FlowPath createTestFlowPath(long flowId, String installerId,
+ final long flowPathFlags,
final long srcDpid, final int srcPort,
final long dstDpid, final int dstPort
) {
FlowPath flowPath = new FlowPath();
flowPath.setFlowId(new FlowId(flowId));
flowPath.setInstallerId(new CallerId(installerId));
+ flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags));
flowPath.setDataPath(new DataPath() {{
setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort)));
setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort)));
@@ -107,9 +111,9 @@
}
private ArrayList<FlowPath> createTestFlowPaths() {
- FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", 1, 1, 2, 2);
- FlowPath flowPath2 = createTestFlowPath(2, "caller id", 1, 1, 2, 2);
- FlowPath flowPath3 = createTestFlowPath(3, "caller id", 1, 5, 2, 2);
+ FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", 0, 1, 1, 2, 2);
+ FlowPath flowPath2 = createTestFlowPath(2, "caller id", 0, 1, 1, 2, 2);
+ FlowPath flowPath3 = createTestFlowPath(3, "caller id", 0, 1, 5, 2, 2);
ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
flowPaths.add(flowPath1);
@@ -182,6 +186,7 @@
FlowPath flowPath = new FlowPath();
flowPath.setFlowId(new FlowId(0x100));
flowPath.setInstallerId(new CallerId("installer id"));
+ flowPath.setFlowPathFlags(new FlowPathFlags(0));
flowPath.setDataPath(dataPath);
flowPath.setFlowEntryMatch(match);
@@ -192,6 +197,7 @@
createdFlowPath.setFlowId("0x100");
createdFlowPath.setType("flow");
createdFlowPath.setInstallerId("installer id");
+ createdFlowPath.setFlowPathFlags(new Long((long)0));
createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34");
createdFlowPath.setSrcPort(new Short((short)1));
createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78");
@@ -339,7 +345,7 @@
public final void testGetFlowSuccessNormally() throws Exception {
// instantiate required objects
FlowManager fm = new FlowManager();
- IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
+ IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
// setup expectations
expectInitWithContext();
@@ -351,11 +357,14 @@
replayAll();
fm.init(context);
- String result = fm.getFlow(new FlowId(1)).installerId().toString();
+ FlowPath flowPath = fm.getFlow(new FlowId(1));
+ String installerId = flowPath.installerId().toString();
+ long flowPathFlags = flowPath.flowPathFlags().flags();
//verify the test
verifyAll();
- assertEquals("caller id", result);
+ assertEquals("caller id", installerId);
+ assertEquals(0L, flowPathFlags);
}
/**
@@ -437,9 +446,9 @@
final String getAllFlowsWithoutFlowEntries = "getAllFlowsWithoutFlowEntries";
// create mock objects
FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithoutFlowEntries);
- IFlowPath flowPath1 = createIFlowPathMock(1, "", 1, 2, 3, 4);
- IFlowPath flowPath2 = createIFlowPathMock(5, "", 2, 3, 4, 5);
- IFlowPath flowPath3 = createIFlowPathMock(10, "", 3, 4, 5, 6);
+ IFlowPath flowPath1 = createIFlowPathMock(1, "", 0, 1, 2, 3, 4);
+ IFlowPath flowPath2 = createIFlowPathMock(5, "", 0, 2, 3, 4, 5);
+ IFlowPath flowPath3 = createIFlowPathMock(10, "", 0, 3, 4, 5, 6);
// instantiate required objects
ArrayList<IFlowPath> flows = new ArrayList<IFlowPath>();
@@ -472,8 +481,8 @@
@Test
public final void testGetAllFlowsSuccessNormally() throws Exception {
// create mock objects
- IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
- IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
+ IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5);
// instantiate required objects
ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
@@ -524,6 +533,7 @@
FlowPath paramFlow = new FlowPath();
paramFlow.setFlowId(new FlowId(100));
paramFlow.setInstallerId(new CallerId("installer id"));
+ paramFlow.setFlowPathFlags(new FlowPathFlags(0));
paramFlow.setDataPath(dataPath);
paramFlow.setFlowEntryMatch(match);
@@ -538,6 +548,7 @@
FlowPath flowPath = (FlowPath)EasyMock.getCurrentArguments()[0];
assertEquals(flowPath.flowId().value(), 100);
assertEquals(flowPath.installerId().toString(), "installer id");
+ assertEquals(flowPath.flowPathFlags().flags(), 0);
assertEquals(flowPath.dataPath().srcPort().toString(),
new SwitchPort(new Dpid(1), new Port((short)3)).toString());
@@ -558,6 +569,7 @@
verifyAll();
assertEquals(paramFlow.flowId().value(), resultFlow.flowId().value());
assertEquals(paramFlow.installerId().toString(), resultFlow.installerId().toString());
+ assertEquals(paramFlow.flowPathFlags().flags(), resultFlow.flowPathFlags().flags());
assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString());
assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString());
}
@@ -569,7 +581,7 @@
@Test
public final void testMeasurementStorePathFlowSuccessNormally() throws Exception {
// instantiate required objects
- FlowPath paramFlow = createTestFlowPath(100, "installer id", 1, 3, 2, 4);
+ FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
FlowManager fm = new FlowManager();
@@ -592,6 +604,7 @@
verifyAll();
assertEquals(paramFlow.flowId().value(), resultFlowPath.flowId().value());
assertEquals(paramFlow.installerId().toString(), resultFlowPath.installerId().toString());
+ assertEquals(paramFlow.flowPathFlags().flags(), resultFlowPath.flowPathFlags().flags());
assertEquals(paramFlow.dataPath().toString(), resultFlowPath.dataPath().toString());
assertEquals(paramFlow.flowEntryMatch().toString(), resultFlowPath.flowEntryMatch().toString());
}
@@ -608,9 +621,9 @@
FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
// instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
- FlowPath flow2 = createTestFlowPath(2, "installer id", 2, 3, 4, 5);
- FlowPath flow3 = createTestFlowPath(3, "installer id", 3, 4, 5, 6);
+ FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
+ FlowPath flow2 = createTestFlowPath(2, "installer id", 0, 2, 3, 4, 5);
+ FlowPath flow3 = createTestFlowPath(3, "installer id", 0, 3, 4, 5, 6);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
// setup expectations
@@ -675,7 +688,7 @@
mockStaticPartial(System.class, "nanoTime");
// instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
+ FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
// setup expectations
@@ -718,7 +731,7 @@
FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
// instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
+ FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
// setup expectations
@@ -757,7 +770,7 @@
@Test
public final void testMeasurementClearAllPathsSuccessNormally() throws Exception {
// instantiate required objects
- FlowPath paramFlow = createTestFlowPath(100, "installer id", 1, 3, 2, 4);
+ FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
FlowManager fm = new FlowManager();
@@ -980,7 +993,7 @@
@Test
public final void testClearFlowSuccessNormally() throws Exception {
// create mock objects
- IFlowPath flowPath = createIFlowPathMock(123, "id", 1, 2, 3, 4);
+ IFlowPath flowPath = createIFlowPathMock(123, "id", 0, 1, 2, 3, 4);
IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
@@ -1023,8 +1036,8 @@
@Test
public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception {
// create mock objects
- IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
- IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
+ IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5);
// instantiate required objects
ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
@@ -1060,7 +1073,7 @@
final String addFlowEntry = "addFlowEntry";
// create mock objects
- IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class);
IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class);
FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
@@ -1127,7 +1140,7 @@
public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception {
// create mock object
IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class);
- IFlowPath iFlowPath = createIFlowPathMock(1, "id", 1, 2, 3, 4);
+ IFlowPath iFlowPath = createIFlowPathMock(1, "id", 0, 1, 2, 3, 4);
IFlowEntry iFlowEntry = createMock(IFlowEntry.class);
BasicFactory basicFactory = createMock(BasicFactory.class);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
index e6d7d16..ba23a01 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
@@ -41,6 +41,7 @@
import net.onrc.onos.ofcontroller.routing.TopoRouteService;
import net.onrc.onos.ofcontroller.util.DataPath;
import net.onrc.onos.ofcontroller.util.Dpid;
+import net.onrc.onos.ofcontroller.util.FlowPathFlags;
import net.onrc.onos.ofcontroller.util.Port;
import net.onrc.onos.ofcontroller.util.SwitchPort;
@@ -132,6 +133,20 @@
String expectedResult = "1/00:00:00:00:00:00:0a:01/2;1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
assertEquals(dataPathSummaryStr, expectedResult);
+ // Test if we apply various Flow Path Flags
+ String expectedResult2 = "1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
+ String expectedResult3 = "1/00:00:00:00:00:00:0a:03/2;";
+ FlowPathFlags flowPathFlags2 = new FlowPathFlags("DISCARD_FIRST_HOP_ENTRY");
+ FlowPathFlags flowPathFlags3 = new FlowPathFlags("KEEP_ONLY_FIRST_HOP_ENTRY");
+ //
+ dataPath.applyFlowPathFlags(flowPathFlags2);
+ dataPathSummaryStr = dataPath.dataPathSummary();
+ assertEquals(dataPathSummaryStr, expectedResult2);
+ //
+ dataPath.applyFlowPathFlags(flowPathFlags3);
+ dataPathSummaryStr = dataPath.dataPathSummary();
+ assertEquals(dataPathSummaryStr, expectedResult3);
+
//
// Test Shortest-Path computation to non-existing destination
//
@@ -180,6 +195,20 @@
String expectedResult = "1/00:00:00:00:00:00:0a:01/2;1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
assertEquals(dataPathSummaryStr, expectedResult);
+ // Test if we apply various Flow Path Flags
+ String expectedResult2 = "1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
+ String expectedResult3 = "1/00:00:00:00:00:00:0a:03/2;";
+ FlowPathFlags flowPathFlags2 = new FlowPathFlags("DISCARD_FIRST_HOP_ENTRY");
+ FlowPathFlags flowPathFlags3 = new FlowPathFlags("KEEP_ONLY_FIRST_HOP_ENTRY");
+ //
+ dataPath.applyFlowPathFlags(flowPathFlags2);
+ dataPathSummaryStr = dataPath.dataPathSummary();
+ assertEquals(dataPathSummaryStr, expectedResult2);
+ //
+ dataPath.applyFlowPathFlags(flowPathFlags3);
+ dataPathSummaryStr = dataPath.dataPathSummary();
+ assertEquals(dataPathSummaryStr, expectedResult3);
+
//
// Test Shortest-Path computation to non-existing destination
//
diff --git a/web/add_flow.py b/web/add_flow.py
index ec84744..f61e926 100755
--- a/web/add_flow.py
+++ b/web/add_flow.py
@@ -129,8 +129,9 @@
my_dst_port = my_args[5]
#
- # Extract the "match" and "action" arguments
+ # Extract the "flowPathFlags", "match" and "action" arguments
#
+ flowPathFlags = 0L
match = {}
matchInPortEnabled = True # NOTE: Enabled by default
actions = []
@@ -149,7 +150,12 @@
arg2 = my_args[idx]
idx = idx + 1
- if arg1 == "matchInPort":
+ if arg1 == "flowPathFlags":
+ if "DISCARD_FIRST_HOP_ENTRY" in arg2:
+ flowPathFlags = flowPathFlags + 0x1
+ if "KEEP_ONLY_FIRST_HOP_ENTRY" in arg2:
+ flowPathFlags = flowPathFlags + 0x2
+ elif arg1 == "matchInPort":
# Just mark whether inPort matching is enabled
matchInPortEnabled = arg2 in ['True', 'true']
# inPort = {}
@@ -302,6 +308,7 @@
'my_src_port' : my_src_port,
'my_dst_dpid' : my_dst_dpid,
'my_dst_port' : my_dst_port,
+ 'flowPathFlags' : flowPathFlags,
'match' : match,
'matchInPortEnabled' : matchInPortEnabled,
'actions' : actions,
@@ -325,6 +332,7 @@
my_flow_id = parsed_args['my_flow_id']
my_installer_id = parsed_args['my_installer_id']
+ myFlowPathFlags = parsed_args['flowPathFlags']
match = parsed_args['match']
matchInPortEnabled = parsed_args['matchInPortEnabled']
actions = parsed_args['actions']
@@ -335,10 +343,13 @@
flow_id['value'] = my_flow_id
installer_id = {}
installer_id['value'] = my_installer_id
+ flowPathFlags = {}
+ flowPathFlags['flags'] = myFlowPathFlags
flow_path = {}
flow_path['flowId'] = flow_id
flow_path['installerId'] = installer_id
+ flow_path['flowPathFlags'] = flowPathFlags
if (len(match) > 0):
flow_path['flowEntryMatch'] = copy.deepcopy(match)
@@ -461,7 +472,7 @@
if __name__ == "__main__":
- usage_msg = "Usage: %s [Flags] <flow-id> <installer-id> <src-dpid> <src-port> <dest-dpid> <dest-port> [Match Conditions] [Actions]\n" % (sys.argv[0])
+ usage_msg = "Usage: %s [Flags] <flow-id> <installer-id> <src-dpid> <src-port> <dest-dpid> <dest-port> [Flow Path Flags] [Match Conditions] [Actions]\n" % (sys.argv[0])
usage_msg = usage_msg + "\n"
usage_msg = usage_msg + " Flags:\n"
usage_msg = usage_msg + " -m [monitorname] Monitor and maintain the installed shortest path(s)\n"
@@ -472,6 +483,13 @@
usage_msg = usage_msg + " -f <filename> Read the flow(s) to install from a file\n"
usage_msg = usage_msg + " File format: one line per flow starting with <flow-id>\n"
usage_msg = usage_msg + "\n"
+ usage_msg = usage_msg + " Flow Path Flags:\n"
+ usage_msg = usage_msg + " flowPathFlags <Flags> (flag names separated by ',')\n"
+ usage_msg = usage_msg + "\n"
+ usage_msg = usage_msg + " Known flags:\n"
+ usage_msg = usage_msg + " DISCARD_FIRST_HOP_ENTRY : Discard the first-hop flow entry\n"
+ usage_msg = usage_msg + " KEEP_ONLY_FIRST_HOP_ENTRY : Keep only the first-hop flow entry\n"
+ usage_msg = usage_msg + "\n"
usage_msg = usage_msg + " Match Conditions:\n"
usage_msg = usage_msg + " matchInPort <True|False> (default to True)\n"
usage_msg = usage_msg + " matchSrcMac <source MAC address>\n"
diff --git a/web/get_flow.py b/web/get_flow.py
index 9e954fe..6599360 100755
--- a/web/get_flow.py
+++ b/web/get_flow.py
@@ -36,12 +36,23 @@
def print_flow_path(parsedResult):
flowId = parsedResult['flowId']['value']
installerId = parsedResult['installerId']['value']
+ flowPathFlags = parsedResult['flowPathFlags']['flags']
srcSwitch = parsedResult['dataPath']['srcPort']['dpid']['value']
srcPort = parsedResult['dataPath']['srcPort']['port']['value']
dstSwitch = parsedResult['dataPath']['dstPort']['dpid']['value']
dstPort = parsedResult['dataPath']['dstPort']['port']['value']
- print "FlowPath: (flowId = %s installerId = %s src = %s/%s dst = %s/%s)" % (flowId, installerId, srcSwitch, srcPort, dstSwitch, dstPort)
+ flowPathFlagsStr = ""
+ if (flowPathFlags & 0x1):
+ if flowPathFlagsStr:
+ flowPathFlagsStr += ","
+ flowPathFlagsStr += "DISCARD_FIRST_HOP_ENTRY"
+ if (flowPathFlags & 0x2):
+ if flowPathFlagsStr:
+ flowPathFlagsStr += ","
+ flowPathFlagsStr += "KEEP_ONLY_FIRST_HOP_ENTRY"
+
+ print "FlowPath: (flowId = %s installerId = %s flowPathFlags = 0x%x(%s) src = %s/%s dst = %s/%s)" % (flowId, installerId, flowPathFlags, flowPathFlagsStr, srcSwitch, srcPort, dstSwitch, dstPort)
match = parsedResult['flowEntryMatch'];
#
# Print the common conditions
diff --git a/web/measurement_store_flow.py b/web/measurement_store_flow.py
index dda7fbd..8f6bd73 100755
--- a/web/measurement_store_flow.py
+++ b/web/measurement_store_flow.py
@@ -60,8 +60,9 @@
my_dst_port = my_args[5]
#
- # Extract the "match" and "action" arguments
+ # Extract the "flowPathFlags", "match" and "action" arguments
#
+ flowPathFlags = 0L
match = {}
matchInPortEnabled = True # NOTE: Enabled by default
actions = []
@@ -80,7 +81,12 @@
arg2 = my_args[idx]
idx = idx + 1
- if arg1 == "matchInPort":
+ if arg1 == "flowPathFlags":
+ if "DISCARD_FIRST_HOP_ENTRY" in arg2:
+ flowPathFlags = flowPathFlags + 0x1
+ if "KEEP_ONLY_FIRST_HOP_ENTRY" in arg2:
+ flowPathFlags = flowPathFlags + 0x2
+ elif arg1 == "matchInPort":
# Just mark whether inPort matching is enabled
matchInPortEnabled = arg2 in ['True', 'true']
# inPort = {}
@@ -233,6 +239,7 @@
'my_src_port' : my_src_port,
'my_dst_dpid' : my_dst_dpid,
'my_dst_port' : my_dst_port,
+ 'flowPathFlags' : flowPathFlags,
'match' : match,
'matchInPortEnabled' : matchInPortEnabled,
'actions' : actions,
@@ -243,6 +250,7 @@
my_flow_id = parsed_args['my_flow_id']
my_installer_id = parsed_args['my_installer_id']
+ myFlowPathFlags = parsed_args['flowPathFlags']
match = parsed_args['match']
matchInPortEnabled = parsed_args['matchInPortEnabled']
actions = parsed_args['actions']
@@ -253,10 +261,13 @@
flow_id['value'] = my_flow_id
installer_id = {}
installer_id['value'] = my_installer_id
+ flowPathFlags = {}
+ flowPathFlags['flags'] = myFlowPathFlags
flow_path = {}
flow_path['flowId'] = flow_id
flow_path['installerId'] = installer_id
+ flow_path['flowPathFlags'] = flowPathFlags
if (len(match) > 0):
flow_path['flowEntryMatch'] = copy.deepcopy(match)
@@ -346,12 +357,19 @@
if __name__ == "__main__":
usage_msg = "Store Flow Paths into ONOS for measurement purpose.\n"
usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + "Usage: %s [Flags] <flow-id> <installer-id> <src-dpid> <src-port> <dest-dpid> <dest-port> [Match Conditions] [Actions]\n" % (sys.argv[0])
+ usage_msg = usage_msg + "Usage: %s [Flags] <flow-id> <installer-id> <src-dpid> <src-port> <dest-dpid> <dest-port> [Flow Path Flags] [Match Conditions] [Actions]\n" % (sys.argv[0])
usage_msg = usage_msg + "\n"
usage_msg = usage_msg + " Flags:\n"
usage_msg = usage_msg + " -f <filename> Read the flow(s) to install from a file\n"
usage_msg = usage_msg + " File format: one line per flow starting with <flow-id>\n"
usage_msg = usage_msg + "\n"
+ usage_msg = usage_msg + " Flow Path Flags:\n"
+ usage_msg = usage_msg + " flowPathFlags <Flags> (flag names separated by ',')\n"
+ usage_msg = usage_msg + "\n"
+ usage_msg = usage_msg + " Known flags:\n"
+ usage_msg = usage_msg + " DISCARD_FIRST_HOP_ENTRY : Discard the first-hop flow entry\n"
+ usage_msg = usage_msg + " KEEP_ONLY_FIRST_HOP_ENTRY : Keep only the first-hop flow entry\n"
+ usage_msg = usage_msg + "\n"
usage_msg = usage_msg + " Match Conditions:\n"
usage_msg = usage_msg + " matchInPort <True|False> (default to True)\n"
usage_msg = usage_msg + " matchSrcMac <source MAC address>\n"
@@ -361,7 +379,6 @@
usage_msg = usage_msg + " matchVlanPriority <VLAN priority>\n"
usage_msg = usage_msg + " matchSrcIPv4Net <source IPv4 network address>\n"
usage_msg = usage_msg + " matchDstIPv4Net <destination IPv4 network address>\n"
- usage_msg = usage_msg + "\n"
usage_msg = usage_msg + " matchIpProto <IP protocol>\n"
usage_msg = usage_msg + " matchIpToS <IP ToS (DSCP field, 6 bits)>\n"
usage_msg = usage_msg + " matchSrcTcpUdpPort <source TCP/UDP port>\n"