Fix for bug ONOS-897:
Add support for specifying flow entry priority.
Now the default priority is 32768 (same as NOX)
The priority can be specified by add_flow.py script with the
"priority <flowPriority>" keyword.
Conflicts:
src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowPusher.java
src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
src/test/java/net/onrc/onos/ofcontroller/util/FlowPathTest.java
NOTE: The conflicts in file FlowDatabaseOperation.java and FlowPusher.java
have been resolved by hand.
The rest of the conflicts are because of missing test files and have been
ignored.
Change-Id: Ia8291fa321d250675850942ea6763f3770af711f
Fix the formatting of the help string.
Change-Id: I95f4c64d6960f7d66db3821210277fc91c2239e1
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 65750e2..f237376 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
@@ -268,6 +268,13 @@
@Property("hard_timeout")
public void setHardTimeout(Integer hardTimeout);
+ @JsonProperty("priority")
+ @Property("priority")
+ public Integer getPriority();
+
+ @Property("priority")
+ public void setPriority(Integer priority);
+
@JsonProperty("srcDpid")
@Property("src_switch")
public String getSrcSwitch();
@@ -436,6 +443,13 @@
@Property("hard_timeout")
public void setHardTimeout(Integer hardTimeout);
+ @JsonProperty("priority")
+ @Property("priority")
+ public Integer getPriority();
+
+ @Property("priority")
+ public void setPriority(Integer priority);
+
@Property("switch_dpid")
public String getSwitchDpid();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
index cedfdfd..ec3064e 100755
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
@@ -5,6 +5,7 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.Map;
import net.floodlightcontroller.core.IOFSwitch;
@@ -100,6 +101,9 @@
flowPathEntity.setProperty("hard_timeout", flowPath.hardTimeout());
flowProp.setHardTimeout(flowPath.hardTimeout());
+ flowPathEntity.setProperty("priority", flowPath.priority());
+ flowProp.setPriority(flowPath.priority());
+
flowPathEntity.setProperty("src_switch", flowPath.dataPath().srcPort().dpid().toString());
flowProp.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString());
@@ -208,6 +212,8 @@
flowEntryEntity.setProperty("hard_timeout", flowEntry.hardTimeout());
+ flowEntryEntity.setProperty("priority", flowEntry.priority());
+
flowEntryEntity.setProperty("switch_dpid", flowEntry.dpid().toString());
flowEntryEntity.addEdge(sw, Direction.OUT, "switch");
@@ -400,6 +406,7 @@
//
// - flowEntry.idleTimeout()
// - flowEntry.hardTimeout()
+ // - flowEntry.priority()
// - flowEntry.dpid()
// - flowEntry.flowEntryUserState()
// - flowEntry.flowEntrySwitchState()
@@ -429,6 +436,7 @@
flowProp.setIdleTimeout(flowEntry.idleTimeout());
flowProp.setHardTimeout(flowEntry.hardTimeout());
+ flowProp.setPriority(flowEntry.priority());
flowProp.setSwitchDpid(flowEntry.dpid().toString());
if (measureONOSFlowEntryTimeProp) {
numProperties += 3;
@@ -961,6 +969,7 @@
Long flowPathFlags;
Integer idleTimeout;
Integer hardTimeout;
+ Integer priority;
String srcSwitchStr;
Short srcPortShort;
String dstSwitchStr;
@@ -977,6 +986,7 @@
flowPathFlags = (Long)propMap.get("flow_path_flags");
idleTimeout = (Integer) propMap.get("idle_timeout");
hardTimeout = (Integer) propMap.get("hard_timeout");
+ priority = (Integer) propMap.get("priority");
srcSwitchStr = (String) propMap.get("src_switch");
srcPortShort = (Short)propMap.get("src_port");
dstSwitchStr = (String) propMap.get("dst_switch");
@@ -989,6 +999,7 @@
flowPathFlags = flowObj.getFlowPathFlags();
idleTimeout = flowObj.getIdleTimeout();
hardTimeout = flowObj.getHardTimeout();
+ priority = flowObj.getPriority();
srcSwitchStr = flowObj.getSrcSwitch();
srcPortShort = flowObj.getSrcPort();
dstSwitchStr = flowObj.getDstSwitch();
@@ -1002,6 +1013,7 @@
(flowPathFlags == null) ||
(idleTimeout == null) ||
(hardTimeout == null) ||
+ (priority == null) ||
(srcSwitchStr == null) ||
(srcPortShort == null) ||
(dstSwitchStr == null) ||
@@ -1019,6 +1031,7 @@
flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags));
flowPath.setIdleTimeout(idleTimeout);
flowPath.setHardTimeout(hardTimeout);
+ flowPath.setPriority(priority);
flowPath.dataPath().srcPort().setDpid(new Dpid(srcSwitchStr));
flowPath.dataPath().srcPort().setPort(new Port(srcPortShort));
flowPath.dataPath().dstPort().setDpid(new Dpid(dstSwitchStr));
@@ -1076,6 +1089,7 @@
String flowEntryIdStr;
Integer idleTimeout;
Integer hardTimeout;
+ Integer priority;
String switchDpidStr;
String userState;
String switchState;
@@ -1086,6 +1100,7 @@
flowEntryIdStr = (String) propMap.get("flow_entry_id");
idleTimeout = (Integer) propMap.get("idle_timeout");
hardTimeout = (Integer) propMap.get("hard_timeout");
+ priority = (Integer) propMap.get("priority");
switchDpidStr = (String) propMap.get("switch_dpid");
userState = (String) propMap.get("user_state");
switchState = (String) propMap.get("switch_state");
@@ -1093,6 +1108,7 @@
flowEntryIdStr = flowEntryObj.getFlowEntryId();
idleTimeout = flowEntryObj.getIdleTimeout();
hardTimeout = flowEntryObj.getHardTimeout();
+ priority = flowEntryObj.getPriority();
switchDpidStr = flowEntryObj.getSwitchDpid();
userState = flowEntryObj.getUserState();
switchState = flowEntryObj.getSwitchState();
@@ -1102,6 +1118,7 @@
(flowEntryIdStr == null) ||
(idleTimeout == null) ||
(hardTimeout == null) ||
+ (priority == null) ||
(switchDpidStr == null) ||
(userState == null) ||
(switchState == null)) {
@@ -1116,6 +1133,7 @@
flowEntry.setDpid(new Dpid(switchDpidStr));
flowEntry.setIdleTimeout(idleTimeout);
flowEntry.setHardTimeout(hardTimeout);
+ flowEntry.setPriority(priority);
//
// Extract the match conditions
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
index b45f8ff..f893ac1 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
@@ -48,6 +48,10 @@
public void setHardTimeout(Integer value) {
map.put("hard_timeout", value);
}
+
+ public void setPriority(Integer value) {
+ map.put("priority", value);
+ }
public void setSwitchDpid(String value) {
map.put("switch_dpid", value);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
index 5ff1dc5..1a2563d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
@@ -1318,6 +1318,7 @@
//
newFlowEntry.setIdleTimeout(flowPath.idleTimeout());
newFlowEntry.setHardTimeout(flowPath.hardTimeout());
+ newFlowEntry.setPriority(flowPath.priority());
//
// Allocate the FlowEntryMatch by copying the default one
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
index 21db7bc..50bbcc8 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
@@ -41,6 +41,10 @@
map.put("hard_timeout", hardTimeout);
}
+ public void setPriority(Integer priority) {
+ map.put("priority", priority);
+ }
+
public void setSrcSwitch(String srcSwitch) {
map.put("src_switch", srcSwitch);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowPusher.java b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowPusher.java
index f2a1828..21be62c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowPusher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowPusher.java
@@ -66,9 +66,7 @@
// Number of messages sent to switch at once
protected static final int MAX_MESSAGE_SEND = 100;
- public static final short PRIORITY_DEFAULT = 100;
-
- public enum QueueState {
+ public enum QueueState {
READY,
SUSPENDED,
}
@@ -723,7 +721,7 @@
fm.setIdleTimeout((short)flowEntry.idleTimeout())
.setHardTimeout((short)flowEntry.hardTimeout())
- .setPriority(PRIORITY_DEFAULT)
+ .setPriority((short)flowEntry.priority())
.setBufferId(OFPacketOut.BUFFER_ID_NONE).setCookie(cookie)
.setCommand(flowModCommand).setMatch(match)
.setActions(openFlowActions)
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
index c8b206f..c6d6726 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
@@ -15,6 +15,7 @@
private FlowEntryId flowEntryId; // The Flow Entry ID
private int idleTimeout; // The Flow idle timeout
private int hardTimeout; // The Flow hard timeout
+ private int priority; // The Flow priority
private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
private FlowEntryActions flowEntryActions; // The Flow Entry Actions
private Dpid dpid; // The Switch DPID
@@ -111,6 +112,7 @@
setFlowEntryActions(actions);
*/
+ priority = FlowPath.PRIORITY_DEFAULT;
flowEntryActions = new FlowEntryActions();
flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
@@ -224,6 +226,28 @@
}
/**
+ * Get the flow priority.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ *
+ * @return the flow priority.
+ */
+ @JsonProperty("priority")
+ public int priority() { return priority; }
+
+ /**
+ * Set the flow priority.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ *
+ * @param priority the flow priority to set.
+ */
+ @JsonProperty("priority")
+ public void setPriority(int priority) {
+ this.priority = 0xffff & priority;
+ }
+
+ /**
* Get the Flow Entry Match.
*
* @return the Flow Entry Match.
@@ -393,7 +417,7 @@
* Convert the flow entry to a string.
*
* The string has the following form:
- * [flowEntryId=XXX idleTimeout=XXX hardTimeout=XXX
+ * [flowEntryId=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
* flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX
* inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
* flowEntryErrorState=XXX]
@@ -412,6 +436,7 @@
}
ret.append(" idleTimeout=" + this.idleTimeout);
ret.append(" hardTimeout=" + this.hardTimeout);
+ ret.append(" priority=" + this.priority);
if ( flowEntryMatch != null ) {
ret.append(" flowEntryMatch=" + this.flowEntryMatch.toString());
}
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 7c87a10..0371046 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPath.java
@@ -13,6 +13,8 @@
* The class representing the Flow Path.
*/
public class FlowPath implements Comparable<FlowPath> {
+ public static final int PRIORITY_DEFAULT = 32768; // Default Flow Priority
+
private FlowId flowId; // The Flow ID
private CallerId installerId; // The Caller ID of the path installer
private FlowPathType flowPathType; // The Flow Path type
@@ -20,6 +22,7 @@
private FlowPathFlags flowPathFlags; // The Flow Path flags
private int idleTimeout; // The Flow idle timeout
private int hardTimeout; // The Flow hard timeout
+ private int priority; // The Flow priority
private DataPath dataPath; // The data path
private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
// Flow Entries
@@ -33,6 +36,7 @@
flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
flowPathFlags = new FlowPathFlags();
+ priority = FlowPath.PRIORITY_DEFAULT;
dataPath = new DataPath();
flowEntryActions = new FlowEntryActions();
}
@@ -49,6 +53,7 @@
this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
this.setIdleTimeout(flowObj.getIdleTimeout());
this.setHardTimeout(flowObj.getHardTimeout());
+ this.setPriority(flowObj.getPriority());
this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
@@ -347,6 +352,28 @@
}
/**
+ * Get the flow priority.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ *
+ * @return the flow priority.
+ */
+ @JsonProperty("priority")
+ public int priority() { return priority; }
+
+ /**
+ * Set the flow priority.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ *
+ * @param priority the flow priority to set.
+ */
+ @JsonProperty("priority")
+ public void setPriority(int priority) {
+ this.priority = 0xffff & priority;
+ }
+
+ /**
* Get the flow path's data path.
*
* @return the flow path's data path.
@@ -418,8 +445,8 @@
*
* The string has the following form:
* [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
- * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX dataPath=XXX
- * flowEntryMatch=XXX flowEntryActions=XXX]
+ * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
+ * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
*
* @return the flow path as a string.
*/
@@ -432,6 +459,7 @@
ret += " flowPathFlags=" + this.flowPathFlags.toString();
ret += " idleTimeout=" + this.idleTimeout;
ret += " hardTimeout=" + this.hardTimeout;
+ ret += " priority=" + this.priority;
if (dataPath != null)
ret += " dataPath=" + this.dataPath.toString();
if (flowEntryMatch != null)