Renamed devicemanager, flowprogrammer, linkdiscovery and util packages
net.onrc.onos.ofcontroller.devicemanager.* => net.onrc.onos.core.devicemanager.*
net.onrc.onos.ofcontroller.flowprogrammer.* => net.onrc.onos.core.flowprogrammer.*
net.onrc.onos.ofcontroller.linkdiscovery.* => net.onrc.onos.core.linkdiscovery.*
net.onrc.onos.ofcontroller.util.* => net.onrc.onos.core.util.*
Change-Id: Iaa865af552e8fb3a589e73d006569ac79f5a0f08
diff --git a/src/main/java/net/onrc/onos/core/util/CallerId.java b/src/main/java/net/onrc/onos/core/util/CallerId.java
new file mode 100644
index 0000000..bcd9704
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/CallerId.java
@@ -0,0 +1,77 @@
+package net.onrc.onos.core.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing a Caller ID for an ONOS component.
+ */
+public class CallerId {
+ private String value;
+
+ /**
+ * Default constructor.
+ */
+ public CallerId() {}
+
+ /**
+ * Copy constructor
+ * @param otherCallerId
+ */
+ public CallerId(CallerId otherCallerId) {
+ // Note: make a full copy if we change value to a mutable type
+ value = otherCallerId.value;
+ }
+
+ /**
+ * Constructor from a string value.
+ *
+ * @param value the value to use.
+ */
+ public CallerId(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the value of the Caller ID.
+ *
+ * @return the value of the Caller ID.
+ */
+ @JsonProperty("value")
+ public String value() { return value; }
+
+ /**
+ * Set the value of the Caller ID.
+ *
+ * @param value the value to set.
+ */
+ @JsonProperty("value")
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Convert the Caller ID value to a string.
+ *
+ * @return the Caller ID value to a string.
+ */
+ @Override
+ public String toString() {
+ return value;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof CallerId)) {
+ return false;
+ }
+
+ CallerId otherCallerId = (CallerId) other;
+
+ return value.equals(otherCallerId.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/DataPath.java b/src/main/java/net/onrc/onos/core/util/DataPath.java
new file mode 100644
index 0000000..7dd1f51
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/DataPath.java
@@ -0,0 +1,157 @@
+package net.onrc.onos.core.util;
+
+import java.util.ArrayList;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The data forwarding path state from a source to a destination.
+ */
+public class DataPath {
+ private SwitchPort srcPort; // The source port
+ private SwitchPort dstPort; // The destination port
+ private ArrayList<FlowEntry> flowEntries; // The Flow Entries
+
+ /**
+ * Default constructor.
+ */
+ public DataPath() {
+ srcPort = new SwitchPort();
+ dstPort = new SwitchPort();
+ flowEntries = new ArrayList<FlowEntry>();
+ }
+
+ /**
+ * Get the data path source port.
+ *
+ * @return the data path source port.
+ */
+ @JsonProperty("srcPort")
+ public SwitchPort srcPort() { return srcPort; }
+
+ /**
+ * Set the data path source port.
+ *
+ * @param srcPort the data path source port to set.
+ */
+ @JsonProperty("srcPort")
+ public void setSrcPort(SwitchPort srcPort) {
+ this.srcPort = srcPort;
+ }
+
+ /**
+ * Get the data path destination port.
+ *
+ * @return the data path destination port.
+ */
+ @JsonProperty("dstPort")
+ public SwitchPort dstPort() { return dstPort; }
+
+ /**
+ * Set the data path destination port.
+ *
+ * @param dstPort the data path destination port to set.
+ */
+ @JsonProperty("dstPort")
+ public void setDstPort(SwitchPort dstPort) {
+ this.dstPort = dstPort;
+ }
+
+ /**
+ * Get the data path flow entries.
+ *
+ * @return the data path flow entries.
+ */
+ @JsonProperty("flowEntries")
+ public ArrayList<FlowEntry> flowEntries() { return flowEntries; }
+
+ /**
+ * Set the data path flow entries.
+ *
+ * @param flowEntries the data path flow entries to set.
+ */
+ @JsonProperty("flowEntries")
+ public void setFlowEntries(ArrayList<FlowEntry> flowEntries) {
+ this.flowEntries = flowEntries;
+ }
+
+ /**
+ * 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);
+ }
+ }
+ }
+
+ /**
+ * Remove Flow Entries that were deleted.
+ */
+ public void removeDeletedFlowEntries() {
+ //
+ // NOTE: We create a new ArrayList, and add only the Flow Entries
+ // that are NOT FE_USER_DELETE.
+ // This is sub-optimal: if it adds notable processing cost,
+ // the Flow Entries container should be changed to LinkedList
+ // or some other container that has O(1) cost of removing an entry.
+ //
+
+ // Test first whether any Flow Entry was deleted
+ boolean foundDeletedFlowEntry = false;
+ for (FlowEntry flowEntry : this.flowEntries) {
+ if (flowEntry.flowEntryUserState() ==
+ FlowEntryUserState.FE_USER_DELETE) {
+ foundDeletedFlowEntry = true;
+ break;
+ }
+ }
+ if (! foundDeletedFlowEntry)
+ return; // Nothing to do
+
+ // Create a new collection and exclude the deleted flow entries
+ ArrayList<FlowEntry> newFlowEntries = new ArrayList<FlowEntry>();
+ for (FlowEntry flowEntry : this.flowEntries()) {
+ if (flowEntry.flowEntryUserState() !=
+ FlowEntryUserState.FE_USER_DELETE) {
+ newFlowEntries.add(flowEntry);
+ }
+ }
+ setFlowEntries(newFlowEntries);
+ }
+
+ /**
+ * Convert the data path to a string.
+ *
+ * The string has the following form:
+ * [src=01:01:01:01:01:01:01:01/1111 flowEntry=<entry1> flowEntry=<entry2> flowEntry=<entry3> dst=02:02:02:02:02:02:02:02/2222]
+ *
+ * @return the data path as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[src=" + this.srcPort.toString();
+
+ for (FlowEntry fe : flowEntries) {
+ ret += " flowEntry=" + fe.toString();
+ }
+ ret += " dst=" + this.dstPort.toString() + "]";
+
+ return ret;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/DataPathEndpoints.java b/src/main/java/net/onrc/onos/core/util/DataPathEndpoints.java
new file mode 100644
index 0000000..eeb5aaa
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/DataPathEndpoints.java
@@ -0,0 +1,80 @@
+package net.onrc.onos.core.util;
+
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing the Data Path Endpoints.
+ */
+public class DataPathEndpoints {
+ private SwitchPort srcPort; // The source port
+ private SwitchPort dstPort; // The destination port
+
+ /**
+ * Default constructor.
+ */
+ public DataPathEndpoints() {
+ }
+
+ /**
+ * Constructor for given source and destination ports.
+ *
+ * @param srcPort the source port to use.
+ * @param dstPort the destination port to use.
+ */
+ public DataPathEndpoints(SwitchPort srcPort, SwitchPort dstPort) {
+ this.srcPort = srcPort;
+ this.dstPort = dstPort;
+ }
+
+ /**
+ * Get the data path source port.
+ *
+ * @return the data path source port.
+ */
+ @JsonProperty("srcPort")
+ public SwitchPort srcPort() { return srcPort; }
+
+ /**
+ * Set the data path source port.
+ *
+ * @param srcPort the data path source port to set.
+ */
+ @JsonProperty("srcPort")
+ public void setSrcPort(SwitchPort srcPort) {
+ this.srcPort = srcPort;
+ }
+
+ /**
+ * Get the data path destination port.
+ *
+ * @return the data path destination port.
+ */
+ @JsonProperty("dstPort")
+ public SwitchPort dstPort() { return dstPort; }
+
+ /**
+ * Set the data path destination port.
+ *
+ * @param dstPort the data path destination port to set.
+ */
+ @JsonProperty("dstPort")
+ public void setDstPort(SwitchPort dstPort) {
+ this.dstPort = dstPort;
+ }
+
+ /**
+ * Convert the data path endpoints to a string.
+ *
+ * The string has the following form:
+ * [src=01:01:01:01:01:01:01:01/1111 dst=02:02:02:02:02:02:02:02/2222]
+ *
+ * @return the data path endpoints as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[src=" + this.srcPort.toString() +
+ " dst=" + this.dstPort.toString() + "]";
+ return ret;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/Dpid.java b/src/main/java/net/onrc/onos/core/util/Dpid.java
new file mode 100644
index 0000000..dcc3a7c
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/Dpid.java
@@ -0,0 +1,88 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.DpidDeserializer;
+import net.onrc.onos.core.util.serializers.DpidSerializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.openflow.util.HexString;
+
+/**
+ * The class representing a network switch DPID.
+ */
+@JsonDeserialize(using=DpidDeserializer.class)
+@JsonSerialize(using=DpidSerializer.class)
+public class Dpid {
+ static public final long UNKNOWN = 0;
+
+ private long value;
+
+ /**
+ * Default constructor.
+ */
+ public Dpid() {
+ this.value = Dpid.UNKNOWN;
+ }
+
+ /**
+ * Constructor from a long value.
+ *
+ * @param value the value to use.
+ */
+ public Dpid(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public Dpid(String value) {
+ this.value = HexString.toLong(value);
+ }
+
+ /**
+ * Get the value of the DPID.
+ *
+ * @return the value of the DPID.
+ */
+ public long value() { return value; }
+
+ /**
+ * Set the value of the DPID.
+ *
+ * @param value the value to set.
+ */
+ public void setValue(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Convert the DPID value to a ':' separated hexadecimal string.
+ *
+ * @return the DPID value as a ':' separated hexadecimal string.
+ */
+ @Override
+ public String toString() {
+ return HexString.toHexString(this.value);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Dpid)) {
+ return false;
+ }
+
+ Dpid otherDpid = (Dpid) other;
+
+ return value == otherDpid.value;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash += 31 * hash + (int)(value ^ value >>> 32);
+ return hash;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/EventEntry.java b/src/main/java/net/onrc/onos/core/util/EventEntry.java
new file mode 100644
index 0000000..fe4c3ac
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/EventEntry.java
@@ -0,0 +1,64 @@
+package net.onrc.onos.core.util;
+
+/**
+ * Class for encapsulating events with event-related data entry.
+ */
+public class EventEntry<T> {
+ /**
+ * The event types.
+ */
+ public enum Type {
+ ENTRY_ADD, // Add or update an entry
+ ENTRY_REMOVE // Remove an entry
+ }
+
+ private Type eventType; // The event type
+ private T eventData; // The relevant event data entry
+
+ /**
+ * Constructor for a given event type and event-related data entry.
+ *
+ * @param eventType the event type.
+ * @param eventData the event data entry.
+ */
+ public EventEntry(EventEntry.Type eventType, T eventData) {
+ this.eventType = eventType;
+ this.eventData = eventData;
+ }
+
+ /**
+ * Test whether the event type is ENTRY_ADD.
+ *
+ * @return true if the event type is ENTRY_ADD, otherwise false.
+ */
+ public boolean isAdd() {
+ return (this.eventType == Type.ENTRY_ADD);
+ }
+
+ /**
+ * Test whether the event type is ENTRY_REMOVE.
+ *
+ * @return true if the event type is ENTRY_REMOVE, otherwise false.
+ */
+ public boolean isRemove() {
+ return (this.eventType == Type.ENTRY_REMOVE);
+ }
+
+ /**
+ * Get the event type.
+ *
+ * @return the event type.
+ */
+ public EventEntry.Type eventType() {
+ return this.eventType;
+ }
+
+ /**
+ * Get the event-related data entry.
+ *
+ * @return the event-related data entry.
+ */
+ public T eventData() {
+ return this.eventData;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntry.java b/src/main/java/net/onrc/onos/core/util/FlowEntry.java
new file mode 100644
index 0000000..fb5e3a3
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntry.java
@@ -0,0 +1,462 @@
+package net.onrc.onos.core.util;
+
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing the Flow Entry.
+ *
+ * NOTE: The specification is incomplete. E.g., the entry needs to
+ * support multiple in-ports and multiple out-ports.
+ */
+public class FlowEntry {
+ private FlowId flowId; // FlowID of the Flow Entry
+ 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
+ private Port inPort; // The Switch incoming port. Used only
+ // when the entry is used to return
+ // Shortest Path computation.
+ private Port outPort; // The Switch outgoing port. Used only
+ // when the entry is used to return
+ // Shortest Path computation.
+ private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
+ private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
+ // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
+ private FlowEntryErrorState flowEntryErrorState;
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntry() {
+ // TODO: Test code
+ /*
+ MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
+ IPv4 ipv4 = new IPv4("1.2.3.4");
+ IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
+
+ flowEntryMatch = new FlowEntryMatch();
+ flowEntryMatch.enableInPort(new Port((short)10));
+ flowEntryMatch.enableSrcMac(mac);
+ flowEntryMatch.enableDstMac(mac);
+ flowEntryMatch.enableVlanId((short)20);
+ flowEntryMatch.enableVlanPriority((byte)30);
+ flowEntryMatch.enableEthernetFrameType((short)40);
+ flowEntryMatch.enableIpToS((byte)50);
+ flowEntryMatch.enableIpProto((byte)60);
+ flowEntryMatch.enableSrcIPv4Net(ipv4net);
+ flowEntryMatch.enableDstIPv4Net(ipv4net);
+ flowEntryMatch.enableSrcTcpUdpPort((short)70);
+ flowEntryMatch.enableDstTcpUdpPort((short)80);
+
+ FlowEntryAction action = null;
+ FlowEntryActions actions = new FlowEntryActions();
+
+ action = new FlowEntryAction();
+ action.setActionOutput(new Port((short)12));
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionOutputToController((short)13);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetVlanId((short)14);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetVlanPriority((byte)15);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionStripVlan(true);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetEthernetSrcAddr(mac);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetEthernetDstAddr(mac);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetIPv4SrcAddr(ipv4);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetIPv4DstAddr(ipv4);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetIpToS((byte)16);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetTcpUdpSrcPort((short)17);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionSetTcpUdpDstPort((short)18);
+ actions.addAction(action);
+
+ action = new FlowEntryAction();
+ action.setActionEnqueue(new Port((short)19), 20);
+ actions.addAction(action);
+
+ setFlowEntryActions(actions);
+ */
+
+ priority = FlowPath.PRIORITY_DEFAULT;
+ flowEntryActions = new FlowEntryActions();
+ flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
+ flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
+ }
+
+ /**
+ * Get the Flow ID.
+ *
+ * @return the Flow ID.
+ */
+ @JsonIgnore
+ public FlowId flowId() { return flowId; }
+
+ /**
+ * Set the Flow ID.
+ *
+ * @param flowId the Flow ID to set.
+ */
+ public void setFlowId(FlowId flowId) {
+ this.flowId = flowId;
+ }
+
+ /**
+ * Test whether the Flow ID is valid.
+ *
+ * @return true if the Flow ID is valid, otherwise false.
+ */
+ @JsonIgnore
+ public boolean isValidFlowId() {
+ if (this.flowId == null)
+ return false;
+ return (this.flowId.isValid());
+ }
+
+ /**
+ * Get the Flow Entry ID.
+ *
+ * @return the Flow Entry ID.
+ */
+ @JsonProperty("flowEntryId")
+ public FlowEntryId flowEntryId() { return flowEntryId; }
+
+ /**
+ * Set the Flow Entry ID.
+ *
+ * @param flowEntryId the Flow Entry ID to set.
+ */
+ @JsonProperty("flowEntryId")
+ public void setFlowEntryId(FlowEntryId flowEntryId) {
+ this.flowEntryId = flowEntryId;
+ }
+
+ /**
+ * Test whether the Flow Entry ID is valid.
+ *
+ * @return true if the Flow Entry ID is valid, otherwise false.
+ */
+ @JsonIgnore
+ public boolean isValidFlowEntryId() {
+ if (this.flowEntryId == null)
+ return false;
+ return (this.flowEntryId.isValid());
+ }
+
+ /**
+ * Get the flow idle timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @return the flow idle timeout.
+ */
+ @JsonProperty("idleTimeout")
+ public int idleTimeout() { return idleTimeout; }
+
+ /**
+ * Set the flow idle timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @param idleTimeout the flow idle timeout to set.
+ */
+ @JsonProperty("idleTimeout")
+ public void setIdleTimeout(int idleTimeout) {
+ this.idleTimeout = 0xffff & idleTimeout;
+ }
+
+ /**
+ * Get the flow hard timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @return the flow hard timeout.
+ */
+ @JsonProperty("hardTimeout")
+ public int hardTimeout() { return hardTimeout; }
+
+ /**
+ * Set the flow hard timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @param hardTimeout the flow hard timeout to set.
+ */
+ @JsonProperty("hardTimeout")
+ public void setHardTimeout(int hardTimeout) {
+ this.hardTimeout = 0xffff & hardTimeout;
+ }
+
+ /**
+ * 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.
+ */
+ @JsonProperty("flowEntryMatch")
+ public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
+
+ /**
+ * Set the Flow Entry Match.
+ *
+ * @param flowEntryMatch the Flow Entry Match to set.
+ */
+ @JsonProperty("flowEntryMatch")
+ public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
+ this.flowEntryMatch = flowEntryMatch;
+ }
+
+ /**
+ * Get the Flow Entry Actions.
+ *
+ * @return the Flow Entry Actions.
+ */
+ @JsonProperty("flowEntryActions")
+ public FlowEntryActions flowEntryActions() {
+ return flowEntryActions;
+ }
+
+ /**
+ * Set the Flow Entry Actions.
+ *
+ * @param flowEntryActions the Flow Entry Actions to set.
+ */
+ @JsonProperty("flowEntryActions")
+ public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
+ this.flowEntryActions = flowEntryActions;
+ }
+
+ /**
+ * Get the Switch DPID.
+ *
+ * @return the Switch DPID.
+ */
+ @JsonProperty("dpid")
+ public Dpid dpid() { return dpid; }
+
+ /**
+ * Set the Switch DPID.
+ *
+ * @param dpid the Switch DPID to set.
+ */
+ @JsonProperty("dpid")
+ public void setDpid(Dpid dpid) {
+ this.dpid = dpid;
+ }
+
+ /**
+ * Get the Switch incoming port.
+ *
+ * Used only when the entry is used to return Shortest Path computation.
+ *
+ * @return the Switch incoming port.
+ */
+ @JsonProperty("inPort")
+ public Port inPort() { return inPort; }
+
+ /**
+ * Set the Switch incoming port.
+ *
+ * Used only when the entry is used to return Shortest Path computation.
+ *
+ * @param inPort the Switch incoming port to set.
+ */
+ @JsonProperty("inPort")
+ public void setInPort(Port inPort) {
+ this.inPort = inPort;
+ }
+
+ /**
+ * Get the Switch outgoing port.
+ *
+ * Used only when the entry is used to return Shortest Path computation.
+ *
+ * @return the Switch outgoing port.
+ */
+ @JsonProperty("outPort")
+ public Port outPort() { return outPort; }
+
+ /**
+ * Set the Switch outgoing port.
+ *
+ * Used only when the entry is used to return Shortest Path computation.
+ *
+ * @param outPort the Switch outgoing port to set.
+ */
+ @JsonProperty("outPort")
+ public void setOutPort(Port outPort) {
+ this.outPort = outPort;
+ }
+
+ /**
+ * Get the Flow Entry User state.
+ *
+ * @return the Flow Entry User state.
+ */
+ @JsonProperty("flowEntryUserState")
+ public FlowEntryUserState flowEntryUserState() {
+ return flowEntryUserState;
+ }
+
+ /**
+ * Set the Flow Entry User state.
+ *
+ * @param flowEntryUserState the Flow Entry User state to set.
+ */
+ @JsonProperty("flowEntryUserState")
+ public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
+ this.flowEntryUserState = flowEntryUserState;
+ }
+
+ /**
+ * Get the Flow Entry Switch state.
+ *
+ * The Flow Entry Error state is used if FlowEntrySwitchState is
+ * FE_SWITCH_FAILED.
+ *
+ * @return the Flow Entry Switch state.
+ */
+ @JsonProperty("flowEntrySwitchState")
+ public FlowEntrySwitchState flowEntrySwitchState() {
+ return flowEntrySwitchState;
+ }
+
+ /**
+ * Set the Flow Entry Switch state.
+ *
+ * The Flow Entry Error state is used if FlowEntrySwitchState is
+ * FE_SWITCH_FAILED.
+ *
+ * @param flowEntrySwitchState the Flow Entry Switch state to set.
+ */
+ @JsonProperty("flowEntrySwitchState")
+ public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
+ this.flowEntrySwitchState = flowEntrySwitchState;
+ }
+
+ /**
+ * Get the Flow Entry Error state.
+ *
+ * @return the Flow Entry Error state.
+ */
+ @JsonProperty("flowEntryErrorState")
+ public FlowEntryErrorState flowEntryErrorState() {
+ return flowEntryErrorState;
+ }
+
+ /**
+ * Set the Flow Entry Error state.
+ *
+ * @param flowEntryErrorState the Flow Entry Error state to set.
+ */
+ @JsonProperty("flowEntryErrorState")
+ public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
+ this.flowEntryErrorState = flowEntryErrorState;
+ }
+
+ /**
+ * Convert the flow entry to a string.
+ *
+ * The string has the following form:
+ * [flowEntryId=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
+ * flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX
+ * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
+ * flowEntryErrorState=XXX]
+ * @return the flow entry as a string.
+ */
+ @Override
+ public String toString() {
+ StringBuilder ret = new StringBuilder();
+ if ( flowEntryId != null ) {
+ ret.append("[flowEntryId=" + this.flowEntryId.toString());
+ } else {
+ ret.append("[");
+ }
+ if ( flowId != null ) {
+ ret.append(" flowId=" + this.flowId.toString());
+ }
+ ret.append(" idleTimeout=" + this.idleTimeout);
+ ret.append(" hardTimeout=" + this.hardTimeout);
+ ret.append(" priority=" + this.priority);
+ if ( flowEntryMatch != null ) {
+ ret.append(" flowEntryMatch=" + this.flowEntryMatch.toString());
+ }
+ ret.append(" flowEntryActions=" + this.flowEntryActions.toString() );
+ if ( dpid != null ) {
+ ret.append(" dpid=" + this.dpid.toString());
+ }
+ if ( inPort != null ) {
+ ret.append(" inPort=" + this.inPort.toString());
+ }
+ if ( outPort != null ) {
+ ret.append(" outPort=" + this.outPort.toString());
+ }
+ ret.append(" flowEntryUserState=" + this.flowEntryUserState);
+ ret.append(" flowEntrySwitchState=" + this.flowEntrySwitchState);
+ if ( flowEntryErrorState != null ) {
+ ret.append(" flowEntryErrorState=" + this.flowEntryErrorState.toString());
+ }
+ ret.append("]");
+
+ return ret.toString();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java b/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java
new file mode 100644
index 0000000..da86ed3
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java
@@ -0,0 +1,1677 @@
+package net.onrc.onos.core.util;
+
+import net.floodlightcontroller.util.MACAddress;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing a single Flow Entry action.
+ *
+ * A Flow Entry action that needs to be applied to each packet.
+ * Note that it contains only a single action. Multiple actions are
+ * listed in a list inside @ref FlowEntryActions.
+ */
+public class FlowEntryAction {
+ /**
+ * Special action values.
+ *
+ * Those values are taken as-is from the OpenFlow-v1.0.0 specification
+ * (pp 21-22).
+ */
+ public enum ActionValues {
+ ACTION_OUTPUT ((short)0x0), // Output to switch port
+ ACTION_SET_VLAN_VID ((short)0x1), // Set the 802.1q VLAN id
+ ACTION_SET_VLAN_PCP ((short)0x2), // Set the 802.1q priority
+ ACTION_STRIP_VLAN ((short)0x3), // Strip the 802.1q header
+ ACTION_SET_DL_SRC ((short)0x4), // Ethernet source address
+ ACTION_SET_DL_DST ((short)0x5), // Ethernet destination address
+ ACTION_SET_NW_SRC ((short)0x6), // IP source address
+ ACTION_SET_NW_DST ((short)0x7), // IP destination address
+ ACTION_SET_NW_TOS ((short)0x8), // IP ToS (DSCP field, 6 bits)
+ ACTION_SET_TP_SRC ((short)0x9), // TCP/UDP source port
+ ACTION_SET_TP_DST ((short)0xa), // TCP/UDP destination port
+ ACTION_ENQUEUE ((short)0xb), // Output to queue on port
+ ACTION_VENDOR ((short)0xffff); // Vendor-specific
+
+ private final short value; // The value
+
+ /**
+ * Constructor for a given value.
+ *
+ * @param value the value to use for the initialization.
+ */
+ private ActionValues(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the value.
+ *
+ * @return the value.
+ */
+ public short getValue() { return value; }
+ }
+
+ /**
+ * Action structure for ACTION_OUTPUT: Output to switch port.
+ */
+ public static class ActionOutput {
+ private Port port; // Output port
+ private short maxLen; // Max. length (in bytes) to send to controller
+ // if the port is set to PORT_CONTROLLER
+
+ /**
+ * Default constructor.
+ */
+ public ActionOutput() {
+ this.port = null;
+ this.maxLen = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionOutput(ActionOutput other) {
+ if (other.port != null)
+ this.port = new Port(other.port);
+ this.maxLen = other.maxLen;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [port=XXX maxLen=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionOutput(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given output port and maximum length.
+ *
+ * @param port the output port to set.
+ * @param maxLen the maximum length (in bytes) to send to controller
+ * if the port is set to PORT_CONTROLLER.
+ */
+ public ActionOutput(Port port, short maxLen) {
+ this.port = port;
+ this.maxLen = maxLen;
+ }
+
+ /**
+ * Constructor for a given output port.
+ *
+ * @param port the output port to set.
+ */
+ public ActionOutput(Port port) {
+ this.port = port;
+ this.maxLen = 0;
+ }
+
+ /**
+ * Get the output port.
+ *
+ * @return the output port.
+ */
+ @JsonProperty("port")
+ public Port port() {
+ return this.port;
+ }
+
+ /**
+ * Get the maximum length (in bytes) to send to controller if the
+ * port is set to PORT_CONTROLLER.
+ *
+ * @return the maximum length (in bytes) to send to controller if the
+ * port is set to PORT_CONTROLLER.
+ */
+ @JsonProperty("maxLen")
+ public short maxLen() {
+ return this.maxLen;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [port=XXX maxLen=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "port=" + port.toString();
+ ret += " maxLen=" + maxLen;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [port=XXX maxLen=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split(" ");
+ String decode = null;
+
+ // Decode the "port=XXX" part
+ if (parts.length > 0)
+ decode = parts[0];
+ if (decode != null) {
+ String[] tokens = decode.split("port=");
+ if (tokens.length > 1 && tokens[1] != null) {
+ try {
+ Short valueShort = Short.valueOf(tokens[1]);
+ port = new Port(valueShort);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+
+ // Decode the "maxLen=XXX" part
+ decode = null;
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ String[] tokens = decode.split("maxLen=");
+ if (tokens.length > 1 && tokens[1] != null) {
+ try {
+ maxLen = Short.valueOf(tokens[1]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id
+ */
+ public static class ActionSetVlanId {
+ private short vlanId; // The VLAN ID to set
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetVlanId() {
+ this.vlanId = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetVlanId(ActionSetVlanId other) {
+ this.vlanId = other.vlanId;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [vlanId=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetVlanId(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given VLAN ID.
+ *
+ * @param vlanId the VLAN ID to set.
+ */
+ public ActionSetVlanId(short vlanId) {
+ this.vlanId = vlanId;
+ }
+
+ /**
+ * Get the VLAN ID.
+ *
+ * @return the VLAN ID.
+ */
+ @JsonProperty("vlanId")
+ public short vlanId() {
+ return this.vlanId;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [vlanId=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "vlanId=" + this.vlanId;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [vlanId=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("vlanId=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ vlanId = Short.valueOf(decode);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority
+ */
+ public static class ActionSetVlanPriority {
+ private byte vlanPriority; // The VLAN priority to set
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetVlanPriority() {
+ this.vlanPriority = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetVlanPriority(ActionSetVlanPriority other) {
+ this.vlanPriority = other.vlanPriority;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [vlanPriority=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetVlanPriority(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given VLAN priority.
+ *
+ * @param vlanPriority the VLAN priority to set.
+ */
+ public ActionSetVlanPriority(byte vlanPriority) {
+ this.vlanPriority = vlanPriority;
+ }
+
+ /**
+ * Get the VLAN priority.
+ *
+ * @return the VLAN priority.
+ */
+ @JsonProperty("vlanPriority")
+ public byte vlanPriority() {
+ return this.vlanPriority;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [vlanPriority=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "vlanPriority=" + this.vlanPriority;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [vlanPriority=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("vlanPriority=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ vlanPriority = Byte.valueOf(decode);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header
+ */
+ public static class ActionStripVlan {
+ private boolean stripVlan; // If true, strip the VLAN header
+
+ /**
+ * Default constructor.
+ */
+ public ActionStripVlan() {
+ this.stripVlan = false;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionStripVlan(ActionStripVlan other) {
+ this.stripVlan = other.stripVlan;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [stripVlan=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionStripVlan(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given boolean flag.
+ *
+ * @param stripVlan if true, strip the VLAN header.
+ */
+ public ActionStripVlan(boolean stripVlan) {
+ this.stripVlan = stripVlan;
+ }
+
+ /**
+ * Get the boolean flag whether the VLAN header should be stripped.
+ *
+ * @return the boolean flag whether the VLAN header should be stripped.
+ */
+ @JsonProperty("stripVlan")
+ public boolean stripVlan() {
+ return this.stripVlan;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [stripVlan=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "stripVlan=" + this.stripVlan;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [stripVlan=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("stripVlan=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ stripVlan = Boolean.valueOf(decode);
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST:
+ * Set the Ethernet source/destination address.
+ */
+ public static class ActionSetEthernetAddr {
+ private MACAddress addr; // The MAC address to set
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetEthernetAddr() {
+ this.addr = null;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetEthernetAddr(ActionSetEthernetAddr other) {
+ if (other.addr != null)
+ this.addr = MACAddress.valueOf(other.addr.toLong());
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetEthernetAddr(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given MAC address.
+ *
+ * @param addr the MAC address to set.
+ */
+ public ActionSetEthernetAddr(MACAddress addr) {
+ this.addr = addr;
+ }
+
+ /**
+ * Get the MAC address.
+ *
+ * @return the MAC address.
+ */
+ @JsonProperty("addr")
+ public MACAddress addr() {
+ return this.addr;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "addr=" + addr.toString();
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("addr=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ addr = MACAddress.valueOf(decode);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST:
+ * Set the IPv4 source/destination address.
+ */
+ public static class ActionSetIPv4Addr {
+ private IPv4 addr; // The IPv4 address to set
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetIPv4Addr() {
+ this.addr = null;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetIPv4Addr(ActionSetIPv4Addr other) {
+ if (other.addr != null)
+ this.addr = new IPv4(other.addr);
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetIPv4Addr(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given IPv4 address.
+ *
+ * @param addr the IPv4 address to set.
+ */
+ public ActionSetIPv4Addr(IPv4 addr) {
+ this.addr = addr;
+ }
+
+ /**
+ * Get the IPv4 address.
+ *
+ * @return the IPv4 address.
+ */
+ @JsonProperty("addr")
+ public IPv4 addr() {
+ return this.addr;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "addr=" + addr.toString();
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [addr=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("addr=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ addr = new IPv4(decode);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_NW_TOS:
+ * Set the IP ToS (DSCP field, 6 bits).
+ */
+ public static class ActionSetIpToS {
+ private byte ipToS; // The IP ToS to set DSCP field, 6 bits)
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetIpToS() {
+ this.ipToS = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetIpToS(ActionSetIpToS other) {
+ this.ipToS = other.ipToS;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [ipToS=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetIpToS(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given IP ToS (DSCP field, 6 bits).
+ *
+ * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
+ */
+ public ActionSetIpToS(byte ipToS) {
+ this.ipToS = ipToS;
+ }
+
+ /**
+ * Get the IP ToS (DSCP field, 6 bits).
+ *
+ * @return the IP ToS (DSCP field, 6 bits).
+ */
+ @JsonProperty("ipToS")
+ public byte ipToS() {
+ return this.ipToS;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [ipToS=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "ipToS=" + ipToS;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [ipToS=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("ipToS=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ ipToS = Byte.valueOf(decode);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST:
+ * Set the TCP/UDP source/destination port.
+ */
+ public static class ActionSetTcpUdpPort {
+ private short port; // The TCP/UDP port to set
+
+ /**
+ * Default constructor.
+ */
+ public ActionSetTcpUdpPort() {
+ this.port = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionSetTcpUdpPort(ActionSetTcpUdpPort other) {
+ this.port = other.port;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [port=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionSetTcpUdpPort(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given TCP/UDP port.
+ *
+ * @param port the TCP/UDP port to set.
+ */
+ public ActionSetTcpUdpPort(short port) {
+ this.port = port;
+ }
+
+ /**
+ * Get the TCP/UDP port.
+ *
+ * @return the TCP/UDP port.
+ */
+ @JsonProperty("port")
+ public short port() {
+ return this.port;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [port=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "port=" + port;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [port=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("port=");
+ String decode = null;
+
+ // Decode the value
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ try {
+ port = Short.valueOf(decode);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ /**
+ * Action structure for ACTION_ENQUEUE: Output to queue on port.
+ */
+ public static class ActionEnqueue {
+ private Port port; // Port that queue belongs. Should
+ // refer to a valid physical port
+ // (i.e. < PORT_MAX) or PORT_IN_PORT
+ private int queueId; // Where to enqueue the packets
+
+ /**
+ * Default constructor.
+ */
+ public ActionEnqueue() {
+ this.port = null;
+ this.queueId = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public ActionEnqueue(ActionEnqueue other) {
+ if (other.port != null)
+ this.port = new Port(other.port);
+ this.queueId = other.queueId;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [port=XXX queueId=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public ActionEnqueue(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Constructor for a given port and queue ID.
+ *
+ * @param port the port to set.
+ * @param queueId the queue ID on the port.
+ */
+ public ActionEnqueue(Port port, int queueId) {
+ this.port = port;
+ this.queueId = queueId;
+ }
+
+ /**
+ * Get the port.
+ *
+ * @return the port.
+ */
+ @JsonProperty("port")
+ public Port port() {
+ return this.port;
+ }
+
+ /**
+ * Get the queue ID.
+ *
+ * @return the queue ID.
+ */
+ @JsonProperty("queueId")
+ public int queueId() {
+ return this.queueId;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [port=XXX queueId=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "port=" + port.toString();
+ ret += " queueId=" + queueId;
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [port=XXX queueId=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split(" ");
+ String decode = null;
+
+ // Decode the "port=XXX" part
+ if (parts.length > 0)
+ decode = parts[0];
+ if (decode != null) {
+ String[] tokens = decode.split("port=");
+ if (tokens.length > 1 && tokens[1] != null) {
+ try {
+ Short valueShort = Short.valueOf(tokens[1]);
+ port = new Port(valueShort);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+
+ // Decode the "queueId=XXX" part
+ decode = null;
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode != null) {
+ decode = decode.replace("]", "");
+ String[] tokens = decode.split("queueId=");
+ if (tokens.length > 1 && tokens[1] != null) {
+ try {
+ queueId = Short.valueOf(tokens[1]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+ }
+
+ private ActionValues actionType; // The action type
+
+ //
+ // The actions.
+ // NOTE: Only one action should be set.
+ //
+ private ActionOutput actionOutput;
+ private ActionSetVlanId actionSetVlanId;
+ private ActionSetVlanPriority actionSetVlanPriority;
+ private ActionStripVlan actionStripVlan;
+ private ActionSetEthernetAddr actionSetEthernetSrcAddr;
+ private ActionSetEthernetAddr actionSetEthernetDstAddr;
+ private ActionSetIPv4Addr actionSetIPv4SrcAddr;
+ private ActionSetIPv4Addr actionSetIPv4DstAddr;
+ private ActionSetIpToS actionSetIpToS;
+ private ActionSetTcpUdpPort actionSetTcpUdpSrcPort;
+ private ActionSetTcpUdpPort actionSetTcpUdpDstPort;
+ private ActionEnqueue actionEnqueue;
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntryAction() {
+ actionType = ActionValues.ACTION_VENDOR; // XXX: Initial value
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public FlowEntryAction(FlowEntryAction other) {
+ this.actionType = other.actionType;
+
+ //
+ if (other.actionOutput != null)
+ this.actionOutput = new ActionOutput(other.actionOutput);
+ else
+ this.actionOutput = null;
+ //
+ if (other.actionSetVlanId != null)
+ this.actionSetVlanId = new ActionSetVlanId(other.actionSetVlanId);
+ else
+ this.actionSetVlanId = null;
+ //
+ if (other.actionSetVlanPriority != null)
+ this.actionSetVlanPriority = new ActionSetVlanPriority(other.actionSetVlanPriority);
+ else
+ this.actionSetVlanPriority = null;
+ //
+ if (other.actionStripVlan != null)
+ this.actionStripVlan = new ActionStripVlan(other.actionStripVlan);
+ else
+ this.actionStripVlan = null;
+ //
+ if (other.actionSetEthernetSrcAddr != null)
+ this.actionSetEthernetSrcAddr = new ActionSetEthernetAddr(other.actionSetEthernetSrcAddr);
+ else
+ this.actionSetEthernetSrcAddr = null;
+ //
+ if (other.actionSetEthernetDstAddr != null)
+ this.actionSetEthernetDstAddr = new ActionSetEthernetAddr(other.actionSetEthernetDstAddr);
+ else
+ this.actionSetEthernetDstAddr = null;
+ //
+ if (other.actionSetIPv4SrcAddr != null)
+ this.actionSetIPv4SrcAddr = new ActionSetIPv4Addr(other.actionSetIPv4SrcAddr);
+ else
+ this.actionSetIPv4SrcAddr = null;
+ //
+ if (other.actionSetIPv4DstAddr != null)
+ this.actionSetIPv4DstAddr = new ActionSetIPv4Addr(other.actionSetIPv4DstAddr);
+ else
+ this.actionSetIPv4DstAddr = null;
+ //
+ if (other.actionSetIpToS != null)
+ this.actionSetIpToS = new ActionSetIpToS(other.actionSetIpToS);
+ else
+ this.actionSetIpToS = null;
+ //
+ if (other.actionSetTcpUdpSrcPort != null)
+ this.actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpSrcPort);
+ else
+ this.actionSetTcpUdpSrcPort = null;
+ //
+ if (other.actionSetTcpUdpDstPort != null)
+ this.actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpDstPort);
+ else
+ this.actionSetTcpUdpDstPort = null;
+ //
+ if (other.actionEnqueue != null)
+ this.actionEnqueue = new ActionEnqueue(other.actionEnqueue);
+ else
+ this.actionEnqueue = null;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [type=XXX action=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public FlowEntryAction(String actionStr) {
+ this.fromString(actionStr);
+ }
+
+ /**
+ * Get the action type.
+ *
+ * @return the action type.
+ */
+ @JsonProperty("actionType")
+ public ActionValues actionType() { return actionType; }
+
+ /**
+ * Get the output action.
+ *
+ * @return the output action.
+ */
+ @JsonProperty("actionOutput")
+ public ActionOutput actionOutput() { return actionOutput; }
+
+ /**
+ * Set the output action on a port.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionOutput")
+ public void setActionOutput(ActionOutput action) {
+ actionOutput = action;
+ actionType = ActionValues.ACTION_OUTPUT;
+ }
+
+ /**
+ * Set the output action on a port.
+ *
+ * @param port the output port to set.
+ */
+ public void setActionOutput(Port port) {
+ actionOutput = new ActionOutput(port);
+ actionType = ActionValues.ACTION_OUTPUT;
+ }
+
+ /**
+ * Set the output action to controller.
+ *
+ * @param maxLen the maximum length (in bytes) to send to controller.
+ */
+ public void setActionOutputToController(short maxLen) {
+ Port port = new Port(Port.PortValues.PORT_CONTROLLER);
+ actionOutput = new ActionOutput(port, maxLen);
+ actionType = ActionValues.ACTION_OUTPUT;
+ }
+
+ /**
+ * Get the action to set the VLAN ID.
+ *
+ * @return the action to set the VLAN ID.
+ */
+ @JsonProperty("actionSetVlanId")
+ public ActionSetVlanId actionSetVlanId() { return actionSetVlanId; }
+
+ /**
+ * Set the action to set the VLAN ID.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetVlanId")
+ public void setActionSetVlanId(ActionSetVlanId action) {
+ actionSetVlanId = action;
+ actionType = ActionValues.ACTION_SET_VLAN_VID;
+ }
+
+ /**
+ * Set the action to set the VLAN ID.
+ *
+ * @param vlanId the VLAN ID to set.
+ */
+ public void setActionSetVlanId(short vlanId) {
+ actionSetVlanId = new ActionSetVlanId(vlanId);
+ actionType = ActionValues.ACTION_SET_VLAN_VID;
+ }
+
+ /**
+ * Get the action to set the VLAN priority.
+ *
+ * @return the action to set the VLAN priority.
+ */
+ @JsonProperty("actionSetVlanPriority")
+ public ActionSetVlanPriority actionSetVlanPriority() {
+ return actionSetVlanPriority;
+ }
+
+ /**
+ * Set the action to set the VLAN priority.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetVlanPriority")
+ public void setActionSetVlanPriority(ActionSetVlanPriority action) {
+ actionSetVlanPriority = action;
+ actionType = ActionValues.ACTION_SET_VLAN_PCP;
+ }
+
+ /**
+ * Set the action to set the VLAN priority.
+ *
+ * @param vlanPriority the VLAN priority to set.
+ */
+ public void setActionSetVlanPriority(byte vlanPriority) {
+ actionSetVlanPriority = new ActionSetVlanPriority(vlanPriority);
+ actionType = ActionValues.ACTION_SET_VLAN_PCP;
+ }
+
+ /**
+ * Get the action to strip the VLAN header.
+ *
+ * @return the action to strip the VLAN header.
+ */
+ @JsonProperty("actionStripVlan")
+ public ActionStripVlan actionStripVlan() {
+ return actionStripVlan;
+ }
+
+ /**
+ * Set the action to strip the VLAN header.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionStripVlan")
+ public void setActionStripVlan(ActionStripVlan action) {
+ actionStripVlan = action;
+ actionType = ActionValues.ACTION_STRIP_VLAN;
+ }
+
+ /**
+ * Set the action to strip the VLAN header.
+ *
+ * @param stripVlan if true, strip the VLAN header.
+ */
+ public void setActionStripVlan(boolean stripVlan) {
+ actionStripVlan = new ActionStripVlan(stripVlan);
+ actionType = ActionValues.ACTION_STRIP_VLAN;
+ }
+
+ /**
+ * Get the action to set the Ethernet source address.
+ *
+ * @return the action to set the Ethernet source address.
+ */
+ @JsonProperty("actionSetEthernetSrcAddr")
+ public ActionSetEthernetAddr actionSetEthernetSrcAddr() {
+ return actionSetEthernetSrcAddr;
+ }
+
+ /**
+ * Set the action to set the Ethernet source address.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetEthernetSrcAddr")
+ public void setActionSetEthernetSrcAddr(ActionSetEthernetAddr action) {
+ actionSetEthernetSrcAddr = action;
+ actionType = ActionValues.ACTION_SET_DL_SRC;
+ }
+
+ /**
+ * Set the action to set the Ethernet source address.
+ *
+ * @param addr the MAC address to set as the Ethernet source address.
+ */
+ public void setActionSetEthernetSrcAddr(MACAddress addr) {
+ actionSetEthernetSrcAddr = new ActionSetEthernetAddr(addr);
+ actionType = ActionValues.ACTION_SET_DL_SRC;
+ }
+
+ /**
+ * Get the action to set the Ethernet destination address.
+ *
+ * @return the action to set the Ethernet destination address.
+ */
+ @JsonProperty("actionSetEthernetDstAddr")
+ public ActionSetEthernetAddr actionSetEthernetDstAddr() {
+ return actionSetEthernetDstAddr;
+ }
+
+ /**
+ * Set the action to set the Ethernet destination address.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetEthernetDstAddr")
+ public void setActionSetEthernetDstAddr(ActionSetEthernetAddr action) {
+ actionSetEthernetDstAddr = action;
+ actionType = ActionValues.ACTION_SET_DL_DST;
+ }
+
+ /**
+ * Set the action to set the Ethernet destination address.
+ *
+ * @param addr the MAC address to set as the Ethernet destination address.
+ */
+ public void setActionSetEthernetDstAddr(MACAddress addr) {
+ actionSetEthernetDstAddr = new ActionSetEthernetAddr(addr);
+ actionType = ActionValues.ACTION_SET_DL_DST;
+ }
+
+ /**
+ * Get the action to set the IPv4 source address.
+ *
+ * @return the action to set the IPv4 source address.
+ */
+ @JsonProperty("actionSetIPv4SrcAddr")
+ public ActionSetIPv4Addr actionSetIPv4SrcAddr() {
+ return actionSetIPv4SrcAddr;
+ }
+
+ /**
+ * Set the action to set the IPv4 source address.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetIPv4SrcAddr")
+ public void setActionSetIPv4SrcAddr(ActionSetIPv4Addr action) {
+ actionSetIPv4SrcAddr = action;
+ actionType = ActionValues.ACTION_SET_NW_SRC;
+ }
+
+ /**
+ * Set the action to set the IPv4 source address.
+ *
+ * @param addr the IPv4 address to set as the IPv4 source address.
+ */
+ public void setActionSetIPv4SrcAddr(IPv4 addr) {
+ actionSetIPv4SrcAddr = new ActionSetIPv4Addr(addr);
+ actionType = ActionValues.ACTION_SET_NW_SRC;
+ }
+
+ /**
+ * Get the action to set the IPv4 destination address.
+ *
+ * @return the action to set the IPv4 destination address.
+ */
+ @JsonProperty("actionSetIPv4DstAddr")
+ public ActionSetIPv4Addr actionSetIPv4DstAddr() {
+ return actionSetIPv4DstAddr;
+ }
+
+ /**
+ * Set the action to set the IPv4 destination address.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetIPv4DstAddr")
+ public void setActionSetIPv4DstAddr(ActionSetIPv4Addr action) {
+ actionSetIPv4DstAddr = action;
+ actionType = ActionValues.ACTION_SET_NW_DST;
+ }
+
+ /**
+ * Set the action to set the IPv4 destination address.
+ *
+ * @param addr the IPv4 address to set as the IPv4 destination address.
+ */
+ public void setActionSetIPv4DstAddr(IPv4 addr) {
+ actionSetIPv4DstAddr = new ActionSetIPv4Addr(addr);
+ actionType = ActionValues.ACTION_SET_NW_DST;
+ }
+
+ /**
+ * Get the action to set the IP ToS (DSCP field, 6 bits).
+ *
+ * @return the action to set the IP ToS (DSCP field, 6 bits).
+ */
+ @JsonProperty("actionSetIpToS")
+ public ActionSetIpToS actionSetIpToS() {
+ return actionSetIpToS;
+ }
+
+ /**
+ * Set the action to set the IP ToS (DSCP field, 6 bits).
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetIpToS")
+ public void setActionSetIpToS(ActionSetIpToS action) {
+ actionSetIpToS = action;
+ actionType = ActionValues.ACTION_SET_NW_TOS;
+ }
+
+ /**
+ * Set the action to set the IP ToS (DSCP field, 6 bits).
+ *
+ * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
+ */
+ public void setActionSetIpToS(byte ipToS) {
+ actionSetIpToS = new ActionSetIpToS(ipToS);
+ actionType = ActionValues.ACTION_SET_NW_TOS;
+ }
+
+ /**
+ * Get the action to set the TCP/UDP source port.
+ *
+ * @return the action to set the TCP/UDP source port.
+ */
+ @JsonProperty("actionSetTcpUdpSrcPort")
+ public ActionSetTcpUdpPort actionSetTcpUdpSrcPort() {
+ return actionSetTcpUdpSrcPort;
+ }
+
+ /**
+ * Set the action to set the TCP/UDP source port.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetTcpUdpSrcPort")
+ public void setActionSetTcpUdpSrcPort(ActionSetTcpUdpPort action) {
+ actionSetTcpUdpSrcPort = action;
+ actionType = ActionValues.ACTION_SET_TP_SRC;
+ }
+
+ /**
+ * Set the action to set the TCP/UDP source port.
+ *
+ * @param port the TCP/UDP port to set as the TCP/UDP source port.
+ */
+ public void setActionSetTcpUdpSrcPort(short port) {
+ actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(port);
+ actionType = ActionValues.ACTION_SET_TP_SRC;
+ }
+
+ /**
+ * Get the action to set the TCP/UDP destination port.
+ *
+ * @return the action to set the TCP/UDP destination port.
+ */
+ @JsonProperty("actionSetTcpUdpDstPort")
+ public ActionSetTcpUdpPort actionSetTcpUdpDstPort() {
+ return actionSetTcpUdpDstPort;
+ }
+
+ /**
+ * Set the action to set the TCP/UDP destination port.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionSetTcpUdpDstPort")
+ public void setActionSetTcpUdpDstPort(ActionSetTcpUdpPort action) {
+ actionSetTcpUdpDstPort = action;
+ actionType = ActionValues.ACTION_SET_TP_DST;
+ }
+
+ /**
+ * Set the action to set the TCP/UDP destination port.
+ *
+ * @param port the TCP/UDP port to set as the TCP/UDP destination port.
+ */
+ public void setActionSetTcpUdpDstPort(short port) {
+ actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(port);
+ actionType = ActionValues.ACTION_SET_TP_DST;
+ }
+
+ /**
+ * Get the action to output to queue on a port.
+ *
+ * @return the action to output to queue on a port.
+ */
+ @JsonProperty("actionEnqueue")
+ public ActionEnqueue actionEnqueue() { return actionEnqueue; }
+
+ /**
+ * Set the action to output to queue on a port.
+ *
+ * @param action the action to set.
+ */
+ @JsonProperty("actionEnqueue")
+ public void setActionEnqueue(ActionEnqueue action) {
+ actionEnqueue = action;
+ actionType = ActionValues.ACTION_ENQUEUE;
+ }
+
+ /**
+ * Set the action to output to queue on a port.
+ *
+ * @param port the port to set.
+ * @param queueId the queue ID to set.
+ */
+ public void setActionEnqueue(Port port, int queueId) {
+ actionEnqueue = new ActionEnqueue(port, queueId);
+ actionType = ActionValues.ACTION_ENQUEUE;
+ }
+
+ /**
+ * Convert the action to a string.
+ *
+ * The string has the following form:
+ * [type=XXX action=XXX]
+ *
+ * @return the action as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ ret += "type=" + actionType;
+ switch (actionType) {
+ case ACTION_OUTPUT:
+ ret += " action=" + actionOutput.toString();
+ break;
+ case ACTION_SET_VLAN_VID:
+ ret += " action=" + actionSetVlanId.toString();
+ break;
+ case ACTION_SET_VLAN_PCP:
+ ret += " action=" + actionSetVlanPriority.toString();
+ break;
+ case ACTION_STRIP_VLAN:
+ ret += " action=" + actionStripVlan.toString();
+ break;
+ case ACTION_SET_DL_SRC:
+ ret += " action=" + actionSetEthernetSrcAddr.toString();
+ break;
+ case ACTION_SET_DL_DST:
+ ret += " action=" + actionSetEthernetDstAddr.toString();
+ break;
+ case ACTION_SET_NW_SRC:
+ ret += " action=" + actionSetIPv4SrcAddr.toString();
+ break;
+ case ACTION_SET_NW_DST:
+ ret += " action=" + actionSetIPv4DstAddr.toString();
+ break;
+ case ACTION_SET_NW_TOS:
+ ret += " action=" + actionSetIpToS.toString();
+ break;
+ case ACTION_SET_TP_SRC:
+ ret += " action=" + actionSetTcpUdpSrcPort.toString();
+ break;
+ case ACTION_SET_TP_DST:
+ ret += " action=" + actionSetTcpUdpDstPort.toString();
+ break;
+ case ACTION_ENQUEUE:
+ ret += " action=" + actionEnqueue.toString();
+ break;
+ case ACTION_VENDOR:
+ ret += " action=VENDOR";
+ break;
+ }
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to an action.
+ *
+ * The string has the following form:
+ * [type=XXX action=XXX]
+ *
+ * @param actionStr the action as a string.
+ */
+ public void fromString(String actionStr) {
+ String[] parts = actionStr.split("type=");
+ String decode = null;
+
+ // Extract the string after the "type="
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode == null)
+ throw new IllegalArgumentException("Invalid action string");
+
+ // Remove the trailing ']'
+ if ((decode.length() > 0) && (decode.charAt(decode.length() - 1) == ']')) {
+ decode = decode.substring(0, decode.length() - 1);
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+
+ // Extract the type value and the action value
+ parts = decode.split(" action=");
+
+ // Decode the "type=XXX" payload
+ if (parts.length > 0)
+ decode = parts[0];
+ if (decode != null) {
+ try {
+ actionType = Enum.valueOf(ActionValues.class, decode);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+
+ // Decode the "action=XXX" payload
+ decode = null;
+ if (parts.length > 1)
+ decode = parts[1];
+ if (decode == null)
+ throw new IllegalArgumentException("Invalid action string");
+ //
+ try {
+ switch (actionType) {
+ case ACTION_OUTPUT:
+ actionOutput = new ActionOutput(decode);
+ break;
+ case ACTION_SET_VLAN_VID:
+ actionSetVlanId = new ActionSetVlanId(decode);
+ break;
+ case ACTION_SET_VLAN_PCP:
+ actionSetVlanPriority = new ActionSetVlanPriority(decode);
+ break;
+ case ACTION_STRIP_VLAN:
+ actionStripVlan = new ActionStripVlan(decode);
+ break;
+ case ACTION_SET_DL_SRC:
+ actionSetEthernetSrcAddr = new ActionSetEthernetAddr(decode);
+ break;
+ case ACTION_SET_DL_DST:
+ actionSetEthernetDstAddr = new ActionSetEthernetAddr(decode);
+ break;
+ case ACTION_SET_NW_SRC:
+ actionSetIPv4SrcAddr = new ActionSetIPv4Addr(decode);
+ break;
+ case ACTION_SET_NW_DST:
+ actionSetIPv4DstAddr = new ActionSetIPv4Addr(decode);
+ break;
+ case ACTION_SET_NW_TOS:
+ actionSetIpToS = new ActionSetIpToS(decode);
+ break;
+ case ACTION_SET_TP_SRC:
+ actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(decode);
+ break;
+ case ACTION_SET_TP_DST:
+ actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(decode);
+ break;
+ case ACTION_ENQUEUE:
+ actionEnqueue = new ActionEnqueue(decode);
+ break;
+ case ACTION_VENDOR:
+ // TODO: Handle it as appropriate
+ break;
+ }
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryActions.java b/src/main/java/net/onrc/onos/core/util/FlowEntryActions.java
new file mode 100644
index 0000000..8839ceb
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryActions.java
@@ -0,0 +1,148 @@
+package net.onrc.onos.core.util;
+
+import java.util.ArrayList;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing multiple Flow Entry actions.
+ *
+ * A set of Flow Entry actions need to be applied to each packet.
+ */
+public class FlowEntryActions {
+ private ArrayList<FlowEntryAction> actions; // The Flow Entry Actions
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntryActions() {
+ actions = new ArrayList<FlowEntryAction>();
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * The string has the following form:
+ * [[type=XXX action=XXX];[type=XXX action=XXX];...;]
+ *
+ * @param actionsStr the set of actions as a string.
+ */
+ public FlowEntryActions(String actionsStr) {
+ this.fromString(actionsStr);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public FlowEntryActions(FlowEntryActions other) {
+ actions = new ArrayList<FlowEntryAction>();
+
+ for (FlowEntryAction action : other.actions) {
+ FlowEntryAction newAction = new FlowEntryAction(action);
+ actions.add(newAction);
+ }
+ }
+
+ /**
+ * Get the Flow Entry Actions.
+ *
+ * @return the Flow Entry Actions.
+ */
+ @JsonProperty("actions")
+ public ArrayList<FlowEntryAction> actions() {
+ return actions;
+ }
+
+ /**
+ * Set the Flow Entry Actions.
+ *
+ * @param actions the Flow Entry Actions to set.
+ */
+ @JsonProperty("actions")
+ public void setActions(ArrayList<FlowEntryAction> actions) {
+ this.actions = actions;
+ }
+
+ /**
+ * Add a Flow Entry Action.
+ *
+ * @param flowEntryAction the Flow Entry Action to add.
+ */
+ public void addAction(FlowEntryAction flowEntryAction) {
+ actions.add(flowEntryAction);
+ }
+
+ /**
+ * Test whether the set of actions is empty.
+ *
+ * @return true if the set of actions is empty, otherwise false.
+ */
+ @JsonIgnore
+ public Boolean isEmpty() {
+ return actions.isEmpty();
+ }
+
+ /**
+ * Convert the set of actions to a string.
+ *
+ * The string has the following form:
+ * [[type=XXX action=XXX];[type=XXX action=XXX];...;]
+ *
+ * @return the set of actions as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ for (FlowEntryAction action : actions) {
+ ret += action.toString() + ";";
+ }
+ ret += "]";
+
+ return ret;
+ }
+
+ /**
+ * Convert a string to a set of actions.
+ *
+ * The string has the following form:
+ * [[type=XXX action=XXX];[type=XXX action=XXX];...;]
+ *
+ * @param actionsStr the set of actions as a string.
+ */
+ public void fromString(String actionsStr) {
+ String decode = actionsStr;
+
+ actions = new ArrayList<FlowEntryAction>();
+
+ if (decode.isEmpty())
+ return; // Nothing to do
+
+ // Remove the '[' and ']' in the beginning and the end of the string
+ if ((decode.length() > 1) && (decode.charAt(0) == '[') &&
+ (decode.charAt(decode.length() - 1) == ']')) {
+ decode = decode.substring(1, decode.length() - 1);
+ } else {
+ throw new IllegalArgumentException("Invalid action string");
+ }
+
+ // Split the string, and decode each action
+ String[] parts = decode.split(";");
+ for (int i = 0; i < parts.length; i++) {
+ decode = parts[i];
+ if ((decode == null) || decode.isEmpty())
+ continue;
+ FlowEntryAction flowEntryAction = null;
+ try {
+ flowEntryAction = new FlowEntryAction(decode);
+ } catch (IllegalArgumentException e) {
+ // TODO: Ignore invalid actions for now
+ continue;
+ }
+ if (flowEntryAction != null)
+ actions.add(flowEntryAction);
+ }
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryErrorState.java b/src/main/java/net/onrc/onos/core/util/FlowEntryErrorState.java
new file mode 100644
index 0000000..e1c5731
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryErrorState.java
@@ -0,0 +1,91 @@
+package net.onrc.onos.core.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing the Flow Entry error state.
+ */
+public class FlowEntryErrorState {
+ private short type; // The error type (e.g., see OF-1.3.1 spec, pp. 95)
+ private short code; // The error code (e.g., see OF-1.3.1 spec, pp. 95)
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntryErrorState() {
+ this.type = 0;
+ this.code = 0;
+ }
+
+ /**
+ * Constructor for a given error type and code.
+ *
+ * @param type the error type to use.
+ * @param code the error code to use.
+ */
+ public FlowEntryErrorState(short type, short code) {
+ this.type = type;
+ this.code = code;
+ }
+
+ /**
+ * Get the error type.
+ *
+ * @return the error type.
+ */
+ @JsonProperty("type")
+ public short type() { return type; }
+
+ /**
+ * Set the error type.
+ *
+ * @param type the error type to use.
+ */
+ @JsonProperty("type")
+ public void setType(short type) {
+ this.type = type;
+ }
+
+ /**
+ * Get the error code.
+ *
+ * @return the error code.
+ */
+ @JsonProperty("code")
+ public short code() { return code; }
+
+ /**
+ * Set the error code.
+ *
+ * @param code the error code to use.
+ */
+ @JsonProperty("code")
+ public void setCode(short code) {
+ this.code = code;
+ }
+
+ /**
+ * Set the values of the error type and code.
+ *
+ * @param type the error type to use.
+ * @param code the error code to use.
+ */
+ public void setValue(short type, short code) {
+ this.type = type;
+ this.code = code;
+ }
+
+ /**
+ * Convert the error type and code to a string.
+ *
+ * The string has the following form:
+ * [type=1 code=2]
+ *
+ * @return the error type and code as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[type=" + this.type + " code=" + code + "]";
+ return ret;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryId.java b/src/main/java/net/onrc/onos/core/util/FlowEntryId.java
new file mode 100644
index 0000000..e4dd32c
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryId.java
@@ -0,0 +1,113 @@
+package net.onrc.onos.core.util;
+
+import java.math.BigInteger;
+
+import net.onrc.onos.core.util.serializers.FlowEntryIdDeserializer;
+import net.onrc.onos.core.util.serializers.FlowEntryIdSerializer;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing a Flow Entry ID.
+ */
+@JsonDeserialize(using=FlowEntryIdDeserializer.class)
+@JsonSerialize(using=FlowEntryIdSerializer.class)
+public class FlowEntryId {
+ private long value;
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntryId() {
+ this.value = -1;
+ }
+
+ /**
+ * Constructor from an integer value.
+ *
+ * @param value the value to use.
+ */
+ public FlowEntryId(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public FlowEntryId(String value) {
+ //
+ // Use the help of BigInteger to parse strings representing
+ // large unsigned hex long values.
+ //
+ char c = 0;
+ if (value.length() > 2)
+ c = value.charAt(1);
+ if ((c == 'x') || (c == 'X'))
+ this.value = new BigInteger(value.substring(2), 16).longValue();
+ else
+ this.value = Long.decode(value);
+ }
+
+ /**
+ * Get the value of the Flow Entry ID.
+ *
+ * @return the value of the Flow Entry ID.
+ */
+ public long value() { return value; }
+
+ /**
+ * Set the value of the Flow Entry ID.
+ *
+ * @param value the value to set.
+ */
+ public void setValue(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Test whether the Flow Entry ID is valid.
+ *
+ * @return true if the Flow Entry ID is valid, otherwise false.
+ */
+ @JsonIgnore
+ public boolean isValid() {
+ return (this.value() != -1);
+ }
+
+ /**
+ * Returns true of the object is another Flow Entry ID with
+ * the same value; otherwise, returns false.
+ *
+ * @param Object to compare
+ */
+ @Override
+ public boolean equals(Object obj){
+ if(obj != null && obj.getClass() == this.getClass()) {
+ FlowEntryId entry = (FlowEntryId) obj;
+ return this.value() == entry.value();
+ }
+ return false;
+ }
+
+ /**
+ * Return the hash code of the Flow Entry ID
+ */
+ @Override
+ public int hashCode() {
+ return Long.valueOf(value).hashCode();
+ }
+
+ /**
+ * Convert the Flow Entry ID value to a hexadecimal string.
+ *
+ * @return the Flow Entry ID value to a hexadecimal string.
+ */
+ @Override
+ public String toString() {
+ return "0x" + Long.toHexString(this.value);
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java b/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java
new file mode 100644
index 0000000..cc18071
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java
@@ -0,0 +1,711 @@
+package net.onrc.onos.core.util;
+
+import net.floodlightcontroller.util.MACAddress;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing the Flow Entry Matching filter.
+ *
+ * The Flow Entry matching filter that is used to specify
+ * the network data that would be forwarded on the data path from
+ * the source to the destination. Examples: source or destination MAC address,
+ * IP prefix that includes the destination's IP address, etc.
+ */
+public class FlowEntryMatch {
+ /**
+ * A class for storing a value to match.
+ */
+ public static class Field<T> {
+ /**
+ * Default constructor.
+ */
+ public Field() {
+ this.enabled = false;
+ }
+
+ /**
+ * Constructor for a given value to match.
+ *
+ * @param value the value to match.
+ */
+ public Field(T value) {
+ this.value = value;
+ this.enabled = true;
+ }
+
+ /**
+ * Get the value.
+ *
+ * @return the value.
+ */
+ public T value() { return this.value; }
+
+ /**
+ * Enable the matching for a given value.
+ *
+ * @param value the value to set.
+ */
+ public void enableMatch(T value) {
+ this.value = value;
+ this.enabled = true;
+ }
+
+ /**
+ * Disable the matching.
+ */
+ public void disableMatch() {
+ this.enabled = false;
+ }
+
+ /**
+ * Test whether matching is enabled.
+ *
+ * @return true if matching is enabled, otherwise false.
+ */
+ public boolean enabled() { return this.enabled; }
+
+ private T value; // The value to match
+ private boolean enabled; // Set to true, if matching is enabled
+ }
+
+ private Field<Port> inPort; // Matching input switch port
+ private Field<MACAddress> srcMac; // Matching source MAC address
+ private Field<MACAddress> dstMac; // Matching destination MAC address
+ private Field<Short> ethernetFrameType; // Matching Ethernet frame type
+ private Field<Short> vlanId; // Matching VLAN ID
+ private Field<Byte> vlanPriority; // Matching VLAN priority
+ private Field<IPv4Net> srcIPv4Net; // Matching source IPv4 prefix
+ private Field<IPv4Net> dstIPv4Net; // Matching destination IPv4 prefix
+ private Field<Byte> ipProto; // Matching IP protocol
+ private Field<Byte> ipToS; // Matching IP ToS (DSCP field, 6 bits)
+ private Field<Short> srcTcpUdpPort; // Matching source TCP/UDP port
+ private Field<Short> dstTcpUdpPort; // Matching destination TCP/UDP port
+
+ /**
+ * Default constructor.
+ */
+ public FlowEntryMatch() {
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public FlowEntryMatch(FlowEntryMatch other) {
+ if ((other.inPort != null) && other.inPort.enabled())
+ this.enableInPort(other.inPort.value());
+ if ((other.srcMac != null) && other.srcMac.enabled())
+ this.enableSrcMac(other.srcMac.value());
+ if ((other.dstMac != null) && other.dstMac.enabled())
+ this.enableDstMac(other.dstMac.value());
+ if ((other.ethernetFrameType != null) && other.ethernetFrameType.enabled())
+ this.enableEthernetFrameType(other.ethernetFrameType.value());
+ if ((other.vlanId != null) && other.vlanId.enabled())
+ this.enableVlanId(other.vlanId.value());
+ if ((other.vlanPriority != null) && other.vlanPriority.enabled())
+ this.enableVlanPriority(other.vlanPriority.value());
+ if ((other.srcIPv4Net != null) && other.srcIPv4Net.enabled())
+ this.enableSrcIPv4Net(other.srcIPv4Net.value());
+ if ((other.dstIPv4Net != null) && other.dstIPv4Net.enabled())
+ this.enableDstIPv4Net(other.dstIPv4Net.value());
+ if ((other.ipProto != null) && other.ipProto.enabled())
+ this.enableIpProto(other.ipProto.value());
+ if ((other.ipToS != null) && other.ipToS.enabled())
+ this.enableIpToS(other.ipToS.value());
+ if ((other.srcTcpUdpPort != null) && other.srcTcpUdpPort.enabled())
+ this.enableSrcTcpUdpPort(other.srcTcpUdpPort.value());
+ if ((other.dstTcpUdpPort != null) && other.dstTcpUdpPort.enabled())
+ this.enableDstTcpUdpPort(other.dstTcpUdpPort.value());
+ }
+
+ /**
+ * Get the matching input switch port.
+ *
+ * @return the matching input switch port.
+ */
+ @JsonProperty("inPort")
+ public Port inPort() {
+ if (inPort != null)
+ return inPort.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on input switch port.
+ *
+ * @param inPort the input switch port value to enable for matching.
+ */
+ @JsonProperty("inPort")
+ public void enableInPort(Port inPort) {
+ this.inPort = new Field<Port>(inPort);
+ }
+
+ /**
+ * Disable the matching on input switch port.
+ */
+ public void disableInPort() {
+ this.inPort = null;
+ }
+
+ /**
+ * Test if matching on input switch port is enabled.
+ *
+ * @return true if matching on input switch port is enabled.
+ */
+ @JsonProperty("matchInPort")
+ public boolean matchInPort() {
+ if (inPort != null)
+ return inPort.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching source MAC address.
+ *
+ * @return the matching source MAC address.
+ */
+ @JsonProperty("srcMac")
+ public MACAddress srcMac() {
+ if (srcMac != null)
+ return srcMac.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on source MAC address.
+ *
+ * @param srcMac the source MAC address value to enable for matching.
+ */
+ @JsonProperty("srcMac")
+ public void enableSrcMac(MACAddress srcMac) {
+ this.srcMac = new Field<MACAddress>(srcMac);
+ }
+
+ /**
+ * Disable the matching on source MAC address.
+ */
+ public void disableSrcMac() {
+ this.srcMac = null;
+ }
+
+ /**
+ * Test if matching on source MAC address is enabled.
+ *
+ * @return true if matching on source MAC address is enabled.
+ */
+ @JsonProperty("matchSrcMac")
+ public boolean matchSrcMac() {
+ if (srcMac != null)
+ return srcMac.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching destination MAC address.
+ *
+ * @return the matching destination MAC address.
+ */
+ @JsonProperty("dstMac")
+ public MACAddress dstMac() {
+ if (dstMac != null)
+ return dstMac.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on destination MAC address.
+ *
+ * @param dstMac the destination MAC address value to enable for matching.
+ */
+ @JsonProperty("dstMac")
+ public void enableDstMac(MACAddress dstMac) {
+ this.dstMac = new Field<MACAddress>(dstMac);
+ }
+
+ /**
+ * Disable the matching on destination MAC address.
+ */
+ public void disableDstMac() {
+ this.dstMac = null;
+ }
+
+ /**
+ * Test if matching on destination MAC address is enabled.
+ *
+ * @return true if matching on destination MAC address is enabled.
+ */
+ @JsonProperty("matchDstMac")
+ public boolean matchDstMac() {
+ if (dstMac != null)
+ return dstMac.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching Ethernet frame type.
+ *
+ * @return the matching Ethernet frame type.
+ */
+ @JsonProperty("ethernetFrameType")
+ public Short ethernetFrameType() {
+ if (ethernetFrameType != null)
+ return ethernetFrameType.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on Ethernet frame type.
+ *
+ * @param ethernetFrameType the Ethernet frame type value to enable for
+ * matching.
+ */
+ @JsonProperty("ethernetFrameType")
+ public void enableEthernetFrameType(Short ethernetFrameType) {
+ this.ethernetFrameType = new Field<Short>(ethernetFrameType);
+ }
+
+ /**
+ * Disable the matching on Ethernet frame type.
+ */
+ public void disableEthernetFrameType() {
+ this.ethernetFrameType = null;
+ }
+
+ /**
+ * Test if matching on Ethernet frame type is enabled.
+ *
+ * @return true if matching on Ethernet frame type is enabled.
+ */
+ @JsonProperty("matchEthernetFrameType")
+ public boolean matchEthernetFrameType() {
+ if (ethernetFrameType != null)
+ return ethernetFrameType.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching VLAN ID.
+ *
+ * @return the matching VLAN ID.
+ */
+ @JsonProperty("vlanId")
+ public Short vlanId() {
+ if (vlanId != null)
+ return vlanId.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on VLAN ID.
+ *
+ * @param vlanId the VLAN ID value to enable for matching.
+ */
+ @JsonProperty("vlanId")
+ public void enableVlanId(Short vlanId) {
+ this.vlanId = new Field<Short>(vlanId);
+ }
+
+ /**
+ * Disable the matching on VLAN ID.
+ */
+ public void disableVlanId() {
+ this.vlanId = null;
+ }
+
+ /**
+ * Test if matching on VLAN ID is enabled.
+ *
+ * @return true if matching on VLAN ID is enabled.
+ */
+ @JsonProperty("matchVlanId")
+ public boolean matchVlanId() {
+ if (vlanId != null)
+ return vlanId.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching VLAN priority.
+ *
+ * @return the matching VLAN priority.
+ */
+ @JsonProperty("vlanPriority")
+ public Byte vlanPriority() {
+ if (vlanPriority != null)
+ return vlanPriority.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on VLAN priority.
+ *
+ * @param vlanPriority the VLAN priority value to enable for matching.
+ */
+ @JsonProperty("vlanPriority")
+ public void enableVlanPriority(Byte vlanPriority) {
+ this.vlanPriority = new Field<Byte>(vlanPriority);
+ }
+
+ /**
+ * Disable the matching on VLAN priority.
+ */
+ public void disableVlanPriority() {
+ this.vlanPriority = null;
+ }
+
+ /**
+ * Test if matching on VLAN priority is enabled.
+ *
+ * @return true if matching on VLAN priority is enabled.
+ */
+ @JsonProperty("matchVlanPriority")
+ public boolean matchVlanPriority() {
+ if (vlanPriority != null)
+ return vlanPriority.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching source IPv4 prefix.
+ *
+ * @return the matching source IPv4 prefix.
+ */
+ @JsonProperty("srcIPv4Net")
+ public IPv4Net srcIPv4Net() {
+ if (srcIPv4Net != null)
+ return srcIPv4Net.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on source IPv4 prefix.
+ *
+ * @param srcIPv4Net the source IPv4 prefix value to enable for matching.
+ */
+ @JsonProperty("srcIPv4Net")
+ public void enableSrcIPv4Net(IPv4Net srcIPv4Net) {
+ this.srcIPv4Net = new Field<IPv4Net>(srcIPv4Net);
+ }
+
+ /**
+ * Disable the matching on source IPv4 prefix.
+ */
+ public void disableSrcIPv4Net() {
+ this.srcIPv4Net = null;
+ }
+
+ /**
+ * Test if matching on source IPv4 prefix is enabled.
+ *
+ * @return true if matching on source IPv4 prefix is enabled.
+ */
+ @JsonProperty("matchSrcIPv4Net")
+ public boolean matchSrcIPv4Net() {
+ if (srcIPv4Net != null)
+ return srcIPv4Net.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching destination IPv4 prefix.
+ *
+ * @return the matching destination IPv4 prefix.
+ */
+ @JsonProperty("dstIPv4Net")
+ public IPv4Net dstIPv4Net() {
+ if (dstIPv4Net != null)
+ return dstIPv4Net.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on destination IPv4 prefix.
+ *
+ * @param dstIPv4Net the destination IPv4 prefix value to enable for
+ * matching.
+ */
+ @JsonProperty("dstIPv4Net")
+ public void enableDstIPv4Net(IPv4Net dstIPv4Net) {
+ this.dstIPv4Net = new Field<IPv4Net>(dstIPv4Net);
+ }
+
+ /**
+ * Disable the matching on destination IPv4 prefix.
+ */
+ public void disableDstIPv4Net() {
+ this.dstIPv4Net = null;
+ }
+
+ /**
+ * Test if matching on destination IPv4 prefix is enabled.
+ *
+ * @return true if matching on destination IPv4 prefix is enabled.
+ */
+ @JsonProperty("matchDstIPv4Net")
+ public boolean matchDstIPv4Net() {
+ if (dstIPv4Net != null)
+ return dstIPv4Net.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching IP protocol.
+ *
+ * @return the matching IP protocol.
+ */
+ @JsonProperty("ipProto")
+ public Byte ipProto() {
+ if (ipProto != null)
+ return ipProto.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on IP protocol.
+ *
+ * @param ipProto the IP protocol value to enable for matching.
+ */
+ @JsonProperty("ipProto")
+ public void enableIpProto(Byte ipProto) {
+ this.ipProto = new Field<Byte>(ipProto);
+ }
+
+ /**
+ * Disable the matching on IP protocol.
+ */
+ public void disableIpProto() {
+ this.ipProto = null;
+ }
+
+ /**
+ * Test if matching on IP protocol is enabled.
+ *
+ * @return true if matching on IP protocol is enabled.
+ */
+ @JsonProperty("matchIpProto")
+ public boolean matchIpProto() {
+ if (ipProto != null)
+ return ipProto.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching IP ToS (DSCP field, 6 bits)
+ *
+ * @return the matching IP ToS.
+ */
+ @JsonProperty("ipToS")
+ public Byte ipToS() {
+ if (ipToS != null)
+ return ipToS.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on IP ToS (DSCP field, 6 bits).
+ *
+ * @param ipToS the IP ToS value to enable for matching.
+ */
+ @JsonProperty("ipToS")
+ public void enableIpToS(Byte ipToS) {
+ this.ipToS = new Field<Byte>(ipToS);
+ }
+
+ /**
+ * Disable the matching on IP ToS (DSCP field, 6 bits).
+ */
+ public void disableIpToS() {
+ this.ipToS = null;
+ }
+
+ /**
+ * Test if matching on IP ToS (DSCP field, 6 bits) is enabled.
+ *
+ * @return true if matching on IP ToS is enabled.
+ */
+ @JsonProperty("matchIpToS")
+ public boolean matchIpToS() {
+ if (ipToS != null)
+ return ipToS.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching source TCP/UDP port.
+ *
+ * @return the matching source TCP/UDP port.
+ */
+ @JsonProperty("srcTcpUdpPort")
+ public Short srcTcpUdpPort() {
+ if (srcTcpUdpPort != null)
+ return srcTcpUdpPort.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on source TCP/UDP port.
+ *
+ * @param srcTcpUdpPort the source TCP/UDP port to enable for matching.
+ */
+ @JsonProperty("srcTcpUdpPort")
+ public void enableSrcTcpUdpPort(Short srcTcpUdpPort) {
+ this.srcTcpUdpPort = new Field<Short>(srcTcpUdpPort);
+ }
+
+ /**
+ * Disable the matching on source TCP/UDP port.
+ */
+ public void disableSrcTcpUdpPort() {
+ this.srcTcpUdpPort = null;
+ }
+
+ /**
+ * Test if matching on source TCP/UDP port is enabled.
+ *
+ * @return true if matching on source TCP/UDP port is enabled.
+ */
+ @JsonProperty("matchSrcTcpUdpPort")
+ public boolean matchSrcTcpUdpPort() {
+ if (srcTcpUdpPort != null)
+ return srcTcpUdpPort.enabled();
+ return false;
+ }
+
+ /**
+ * Get the matching destination TCP/UDP port.
+ *
+ * @return the matching destination TCP/UDP port.
+ */
+ @JsonProperty("dstTcpUdpPort")
+ public Short dstTcpUdpPort() {
+ if (dstTcpUdpPort != null)
+ return dstTcpUdpPort.value();
+ return null;
+ }
+
+ /**
+ * Enable the matching on destination TCP/UDP port.
+ *
+ * @param dstTcpUdpPort the destination TCP/UDP port to enable for
+ * matching.
+ */
+ @JsonProperty("dstTcpUdpPort")
+ public void enableDstTcpUdpPort(Short dstTcpUdpPort) {
+ this.dstTcpUdpPort = new Field<Short>(dstTcpUdpPort);
+ }
+
+ /**
+ * Disable the matching on destination TCP/UDP port.
+ */
+ public void disableDstTcpUdpPort() {
+ this.dstTcpUdpPort = null;
+ }
+
+ /**
+ * Test if matching on destination TCP/UDP port is enabled.
+ *
+ * @return true if matching on destination TCP/UDP port is enabled.
+ */
+ @JsonProperty("matchDstTcpUdpPort")
+ public boolean matchDstTcpUdpPort() {
+ if (dstTcpUdpPort != null)
+ return dstTcpUdpPort.enabled();
+ return false;
+ }
+
+ /**
+ * Convert the matching filter to a string.
+ *
+ * The string has the following form:
+ * [srcMac=XXX dstMac=XXX srcIPv4Net=XXX dstIPv4Net=XXX]
+ *
+ * @return the matching filter as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[";
+ boolean addSpace = false;
+
+ //
+ // Conditionally add only those matching fields that are enabled
+ //
+ if (matchInPort()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "inPort=" + this.inPort().toString();
+ }
+ if (matchSrcMac()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "srcMac=" + this.srcMac().toString();
+ }
+ if (matchDstMac()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "dstMac=" + this.dstMac().toString();
+ }
+ if (matchEthernetFrameType()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "ethernetFrameType=" + this.ethernetFrameType().toString();
+ }
+ if (matchVlanId()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "vlanId=" + this.vlanId().toString();
+ }
+ if (matchVlanPriority()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "vlanPriority=" + this.vlanPriority().toString();
+ }
+ if (matchSrcIPv4Net()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "srcIPv4Net=" + this.srcIPv4Net().toString();
+ }
+ if (matchDstIPv4Net()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "dstIPv4Net=" + this.dstIPv4Net().toString();
+ }
+ if (matchIpProto()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "ipProto=" + this.ipProto().toString();
+ }
+ if (matchIpToS()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "ipToS=" + this.ipToS().toString();
+ }
+ if (matchSrcTcpUdpPort()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "srcTcpUdpPort=" + this.srcTcpUdpPort().toString();
+ }
+ if (matchDstTcpUdpPort()) {
+ if (addSpace)
+ ret += " ";
+ addSpace = true;
+ ret += "dstTcpUdpPort=" + this.dstTcpUdpPort().toString();
+ }
+
+ ret += "]";
+
+ return ret;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntrySwitchState.java b/src/main/java/net/onrc/onos/core/util/FlowEntrySwitchState.java
new file mode 100644
index 0000000..c5a79de
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntrySwitchState.java
@@ -0,0 +1,12 @@
+package net.onrc.onos.core.util;
+
+/**
+ * The Flow Entry state as set by the controller.
+ */
+public enum FlowEntrySwitchState {
+ FE_SWITCH_UNKNOWN, // Initialization value: state unknown
+ FE_SWITCH_NOT_UPDATED, // Switch not updated with this entry
+ FE_SWITCH_UPDATE_IN_PROGRESS, // Switch update in progress
+ FE_SWITCH_UPDATED, // Switch updated with this entry
+ FE_SWITCH_UPDATE_FAILED // Error updating the switch with this entry
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryUserState.java b/src/main/java/net/onrc/onos/core/util/FlowEntryUserState.java
new file mode 100644
index 0000000..64d283a
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryUserState.java
@@ -0,0 +1,11 @@
+package net.onrc.onos.core.util;
+
+/**
+ * The Flow Entry state as set by the user (via the ONOS API).
+ */
+public enum FlowEntryUserState {
+ FE_USER_UNKNOWN, // Initialization value: state unknown
+ FE_USER_ADD, // Flow entry that is added
+ FE_USER_MODIFY, // Flow entry that is modified
+ FE_USER_DELETE // Flow entry that is deleted
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowId.java b/src/main/java/net/onrc/onos/core/util/FlowId.java
new file mode 100644
index 0000000..a6ceed8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowId.java
@@ -0,0 +1,102 @@
+package net.onrc.onos.core.util;
+
+import java.math.BigInteger;
+
+import net.onrc.onos.core.util.serializers.FlowIdDeserializer;
+import net.onrc.onos.core.util.serializers.FlowIdSerializer;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing a Flow ID.
+ */
+@JsonDeserialize(using=FlowIdDeserializer.class)
+@JsonSerialize(using=FlowIdSerializer.class)
+public class FlowId implements Comparable<FlowId> {
+ private long value;
+
+ /**
+ * Default constructor.
+ */
+ public FlowId() {
+ this.value = -1;
+ }
+
+ /**
+ * Constructor from an integer value.
+ *
+ * @param value the value to use.
+ */
+ public FlowId(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public FlowId(String value) {
+ //
+ // Use the help of BigInteger to parse strings representing
+ // large unsigned hex long values.
+ //
+ char c = 0;
+ if (value.length() > 2)
+ c = value.charAt(1);
+ if ((c == 'x') || (c == 'X'))
+ this.value = new BigInteger(value.substring(2), 16).longValue();
+ else
+ this.value = Long.decode(value);
+ }
+
+ /**
+ * Get the value of the Flow ID.
+ *
+ * @return the value of the Flow ID.
+ */
+ public long value() { return value; }
+
+ /**
+ * Set the value of the Flow ID.
+ *
+ * @param value the value to set.
+ */
+ public void setValue(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Test whether the Flow ID is valid.
+ *
+ * @return true if the Flow ID is valid, otherwise false.
+ */
+ @JsonIgnore
+ public boolean isValid() {
+ return (this.value() != -1);
+ }
+
+ /**
+ * Convert the Flow ID value to a hexadecimal string.
+ *
+ * @return the Flow ID value to a hexadecimal string.
+ */
+ @Override
+ public String toString() {
+ return "0x" + Long.toHexString(this.value);
+ }
+
+ /**
+ * Compare two FlowId objects numerically using their Flow IDs.
+ *
+ * @return the value 0 if the Flow ID is equal to the argument's Flow ID;
+ * a value less than 0 if the Flow ID is numerically less than the argument's Flow ID;
+ * and a value greater than 0 if the Flow ID is numerically greater than the argument's Flow ID.
+ */
+ @Override
+ public int compareTo(FlowId o) {
+ return Long.valueOf(this.value).compareTo(o.value());
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowPath.java b/src/main/java/net/onrc/onos/core/util/FlowPath.java
new file mode 100644
index 0000000..2bb5ad3
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowPath.java
@@ -0,0 +1,316 @@
+package net.onrc.onos.core.util;
+
+import java.util.ArrayList;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * 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
+ private FlowPathUserState flowPathUserState; // The Flow Path User state
+ 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
+ private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
+ // the first Flow Entry
+
+ /**
+ * Default constructor.
+ */
+ public FlowPath() {
+ flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
+ flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
+ flowPathFlags = new FlowPathFlags();
+ priority = FlowPath.PRIORITY_DEFAULT;
+ dataPath = new DataPath();
+ flowEntryActions = new FlowEntryActions();
+ }
+
+ /**
+ * Get the flow path Flow ID.
+ *
+ * @return the flow path Flow ID.
+ */
+ @JsonProperty("flowId")
+ public FlowId flowId() { return flowId; }
+
+ /**
+ * Set the flow path Flow ID.
+ *
+ * @param flowId the flow path Flow ID to set.
+ */
+ @JsonProperty("flowId")
+ public void setFlowId(FlowId flowId) {
+ this.flowId = flowId;
+ }
+
+ /**
+ * Test whether the Flow ID is valid.
+ *
+ * @return true if the Flow ID is valid, otherwise false.
+ */
+ @JsonIgnore
+ public boolean isValidFlowId() {
+ if (this.flowId == null)
+ return false;
+ return (this.flowId.isValid());
+ }
+
+ /**
+ * Get the Caller ID of the flow path installer.
+ *
+ * @return the Caller ID of the flow path installer.
+ */
+ @JsonProperty("installerId")
+ public CallerId installerId() { return installerId; }
+
+ /**
+ * Set the Caller ID of the flow path installer.
+ *
+ * @param installerId the Caller ID of the flow path installer.
+ */
+ @JsonProperty("installerId")
+ public void setInstallerId(CallerId installerId) {
+ this.installerId = installerId;
+ }
+
+ /**
+ * Get the flow path type.
+ *
+ * @return the flow path type.
+ */
+ @JsonProperty("flowPathType")
+ public FlowPathType flowPathType() { return flowPathType; }
+
+ /**
+ * Set the flow path type.
+ *
+ * @param flowPathType the flow path type to set.
+ */
+ @JsonProperty("flowPathType")
+ public void setFlowPathType(FlowPathType flowPathType) {
+ this.flowPathType = flowPathType;
+ }
+
+ /**
+ * Get the flow path user state.
+ *
+ * @return the flow path user state.
+ */
+ @JsonProperty("flowPathUserState")
+ public FlowPathUserState flowPathUserState() { return flowPathUserState; }
+
+ /**
+ * Set the flow path user state.
+ *
+ * @param flowPathUserState the flow path user state to set.
+ */
+ @JsonProperty("flowPathUserState")
+ public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
+ this.flowPathUserState = flowPathUserState;
+ }
+
+ /**
+ * 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 idle timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @return the flow idle timeout.
+ */
+ @JsonProperty("idleTimeout")
+ public int idleTimeout() { return idleTimeout; }
+
+ /**
+ * Set the flow idle timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @param idleTimeout the flow idle timeout to set.
+ */
+ @JsonProperty("idleTimeout")
+ public void setIdleTimeout(int idleTimeout) {
+ this.idleTimeout = 0xffff & idleTimeout;
+ }
+
+ /**
+ * Get the flow hard timeout in seconds.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @return the flow hard timeout.
+ */
+ @JsonProperty("hardTimeout")
+ public int hardTimeout() { return hardTimeout; }
+
+ /**
+ * Set the flow hard timeout.
+ *
+ * It should be an unsigned integer in the interval [0, 65535].
+ * If zero, the timeout is not set.
+ *
+ * @param hardTimeout the flow hard timeout to set.
+ */
+ @JsonProperty("hardTimeout")
+ public void setHardTimeout(int hardTimeout) {
+ this.hardTimeout = 0xffff & hardTimeout;
+ }
+
+ /**
+ * 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.
+ */
+ @JsonProperty("dataPath")
+ public DataPath dataPath() { return dataPath; }
+
+ /**
+ * Set the flow path's data path.
+ *
+ * @param dataPath the flow path's data path to set.
+ */
+ @JsonProperty("dataPath")
+ public void setDataPath(DataPath dataPath) {
+ this.dataPath = dataPath;
+ }
+
+ /**
+ * Get the data path flow entries.
+ *
+ * @return the data path flow entries.
+ */
+ public ArrayList<FlowEntry> flowEntries() {
+ return this.dataPath.flowEntries();
+ }
+
+ /**
+ * Get the flow path's match conditions common for all Flow Entries.
+ *
+ * @return the flow path's match conditions common for all Flow Entries.
+ */
+ @JsonProperty("flowEntryMatch")
+ public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
+
+ /**
+ * Set the flow path's match conditions common for all Flow Entries.
+ *
+ * @param flowEntryMatch the flow path's match conditions common for all
+ * Flow Entries.
+ */
+ @JsonProperty("flowEntryMatch")
+ public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
+ this.flowEntryMatch = flowEntryMatch;
+ }
+
+ /**
+ * Get the flow path's flow entry actions for the first Flow Entry.
+ *
+ * @return the flow path's flow entry actions for the first Flow Entry.
+ */
+ @JsonProperty("flowEntryActions")
+ public FlowEntryActions flowEntryActions() {
+ return flowEntryActions;
+ }
+
+ /**
+ * Set the flow path's flow entry actions for the first Flow Entry.
+ *
+ * @param flowEntryActions the flow path's flow entry actions for the first
+ * Flow Entry.
+ */
+ @JsonProperty("flowEntryActions")
+ public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
+ this.flowEntryActions = flowEntryActions;
+ }
+
+ /**
+ * Convert the flow path to a string.
+ *
+ * The string has the following form:
+ * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
+ * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
+ * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
+ *
+ * @return the flow path as a string.
+ */
+ @Override
+ public String toString() {
+ String ret = "[flowId=" + this.flowId.toString();
+ ret += " installerId=" + this.installerId.toString();
+ ret += " flowPathType=" + this.flowPathType;
+ ret += " flowPathUserState=" + this.flowPathUserState;
+ 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)
+ ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
+ if (flowEntryActions != null)
+ ret += " flowEntryActions=" + this.flowEntryActions.toString();
+ ret += "]";
+ return ret;
+ }
+
+ /**
+ * CompareTo method to order flowPath by Id
+ */
+ @Override
+ public int compareTo(FlowPath f) {
+ return (int) (this.flowId.value() - f.flowId.value());
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowPathFlags.java b/src/main/java/net/onrc/onos/core/util/FlowPathFlags.java
new file mode 100644
index 0000000..b52d888
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowPathFlags.java
@@ -0,0 +1,129 @@
+package net.onrc.onos.core.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
+ public static final long DISCARD_FIRST_HOP_ENTRY = (1 << 0);
+
+ // Keep only the first-hop Flow Entry
+ public static 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) {
+ flagsStr += "DISCARD_FIRST_HOP_ENTRY";
+ }
+ if ((this.flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0) {
+ if (flagsStr != null)
+ flagsStr += ",";
+ flagsStr += "KEEP_ONLY_FIRST_HOP_ENTRY";
+ }
+ if (flagsStr != null)
+ ret += flagsStr;
+ ret += "]";
+
+ return ret;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowPathType.java b/src/main/java/net/onrc/onos/core/util/FlowPathType.java
new file mode 100644
index 0000000..4b1214e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowPathType.java
@@ -0,0 +1,10 @@
+package net.onrc.onos.core.util;
+
+/**
+ * The Flow Path types.
+ */
+public enum FlowPathType {
+ FP_TYPE_UNKNOWN, // Initialization value: state unknown
+ FP_TYPE_SHORTEST_PATH, // Shortest path flow
+ FP_TYPE_EXPLICIT_PATH // Flow path with explicit flow entries
+}
diff --git a/src/main/java/net/onrc/onos/core/util/FlowPathUserState.java b/src/main/java/net/onrc/onos/core/util/FlowPathUserState.java
new file mode 100644
index 0000000..bc91c2a
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/FlowPathUserState.java
@@ -0,0 +1,11 @@
+package net.onrc.onos.core.util;
+
+/**
+ * The Flow Path state as set by the user (via the ONOS API).
+ */
+public enum FlowPathUserState {
+ FP_USER_UNKNOWN, // Initialization value: state unknown
+ FP_USER_ADD, // Flow path that is added
+ FP_USER_MODIFY, // Flow path that is modified
+ FP_USER_DELETE // Flow path that is deleted
+}
diff --git a/src/main/java/net/onrc/onos/core/util/IPv4.java b/src/main/java/net/onrc/onos/core/util/IPv4.java
new file mode 100644
index 0000000..86795aa
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/IPv4.java
@@ -0,0 +1,88 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.IPv4Deserializer;
+import net.onrc.onos.core.util.serializers.IPv4Serializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing an IPv4 address.
+ */
+@JsonDeserialize(using=IPv4Deserializer.class)
+@JsonSerialize(using=IPv4Serializer.class)
+public class IPv4 {
+ private int value;
+
+ /**
+ * Default constructor.
+ */
+ public IPv4() {
+ this.value = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public IPv4(IPv4 other) {
+ this.value = other.value;
+ }
+
+ /**
+ * Constructor from an integer value.
+ *
+ * @param value the value to use.
+ */
+ public IPv4(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public IPv4(String value) {
+ String[] splits = value.split("\\.");
+ if (splits.length != 4)
+ throw new IllegalArgumentException("Specified IPv4 address must contain four " +
+ "numerical digits separated by '.'");
+
+ int result = 0;
+ for (int i = 0; i < 4; ++i) {
+ result |= Integer.valueOf(splits[i]) << ((3-i)*8);
+ }
+ this.value = result;
+ }
+
+ /**
+ * Get the value of the IPv4 address.
+ *
+ * @return the value of the IPv4 address.
+ */
+ public int value() { return value; }
+
+ /**
+ * Set the value of the IPv4 address.
+ *
+ * @param value the value to set.
+ */
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Convert the IPv4 value to a '.' separated string.
+ *
+ * @return the IPv4 value as a '.' separated string.
+ */
+ @Override
+ public String toString() {
+ return ((this.value >> 24) & 0xFF) + "." +
+ ((this.value >> 16) & 0xFF) + "." +
+ ((this.value >> 8) & 0xFF) + "." +
+ (this.value & 0xFF);
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/IPv4Net.java b/src/main/java/net/onrc/onos/core/util/IPv4Net.java
new file mode 100644
index 0000000..82f2fc6
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/IPv4Net.java
@@ -0,0 +1,114 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.IPv4NetDeserializer;
+import net.onrc.onos.core.util.serializers.IPv4NetSerializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing an IPv4 network address.
+ */
+@JsonDeserialize(using=IPv4NetDeserializer.class)
+@JsonSerialize(using=IPv4NetSerializer.class)
+public class IPv4Net {
+ private IPv4 address; // The IPv4 address
+ private short prefixLen; // The prefix length
+
+ /**
+ * Default constructor.
+ */
+ public IPv4Net() {
+ this.prefixLen = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public IPv4Net(IPv4Net other) {
+ if (other.address != null)
+ this.address = new IPv4(other.address);
+ this.prefixLen = other.prefixLen;
+ }
+
+ /**
+ * Constructor for a given address and prefix length.
+ *
+ * @param address the address to use.
+ * @param prefixLen the prefix length to use.
+ */
+ public IPv4Net(IPv4 address, short prefixLen) {
+ this.address = address;
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public IPv4Net(String value) {
+ String[] splits = value.split("/");
+ if (splits.length != 2) {
+ throw new IllegalArgumentException("Specified IPv4Net address must contain an IPv4 " +
+ "address and a prefix length separated by '/'");
+ }
+ this.address = new IPv4(splits[0]);
+ this.prefixLen = Short.decode(splits[1]);
+ }
+
+ /**
+ * Get the address value of the IPv4Net address.
+ *
+ * @return the address value of the IPv4Net address.
+ */
+ public IPv4 address() { return address; }
+
+ /**
+ * Set the address value of the IPv4Net address.
+ *
+ * @param address the address to use.
+ */
+ public void setAddress(IPv4 address) {
+ this.address = address;
+ }
+
+ /**
+ * Get the prefix length value of the IPv4Net address.
+ *
+ * @return the prefix length value of the IPv4Net address.
+ */
+ public short prefixLen() { return prefixLen; }
+
+ /**
+ * Set the prefix length value of the IPv4Net address.
+ *
+ * @param prefixLen the prefix length to use.
+ */
+ public void setPrefixLen(short prefixLen) {
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Set the value of the IPv4Net address.
+ *
+ * @param address the address to use.
+ * @param prefixLen the prefix length to use.
+ */
+ public void setValue(IPv4 address, short prefixLen) {
+ this.address = address;
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Convert the IPv4Net value to an "address/prefixLen" string.
+ *
+ * @return the IPv4Net value as an "address/prefixLen" string.
+ */
+ @Override
+ public String toString() {
+ return this.address.toString() + "/" + this.prefixLen;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/IPv6.java b/src/main/java/net/onrc/onos/core/util/IPv6.java
new file mode 100644
index 0000000..1648723
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/IPv6.java
@@ -0,0 +1,114 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.IPv6Deserializer;
+import net.onrc.onos.core.util.serializers.IPv6Serializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.openflow.util.HexString;
+
+/**
+ * The class representing an IPv6 address.
+ */
+@JsonDeserialize(using=IPv6Deserializer.class)
+@JsonSerialize(using=IPv6Serializer.class)
+public class IPv6 {
+ private long valueHigh; // The higher (more significant) 64 bits
+ private long valueLow; // The lower (less significant) 64 bits
+
+ /**
+ * Default constructor.
+ */
+ public IPv6() {
+ this.valueHigh = 0;
+ this.valueLow = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public IPv6(IPv6 other) {
+ this.valueHigh = other.valueHigh;
+ this.valueLow = other.valueLow;
+ }
+
+ /**
+ * Constructor from integer values.
+ *
+ * @param valueHigh the higher (more significant) 64 bits of the address.
+ * @param valueLow the lower (less significant) 64 bits of the address.
+ */
+ public IPv6(long valueHigh, long valueLow) {
+ this.valueHigh = valueHigh;
+ this.valueLow = valueLow;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public IPv6(String value) {
+ // TODO: Implement it!
+ this.valueHigh = 0;
+ this.valueLow = 0;
+ }
+
+ /**
+ * Get the value of the higher (more significant) 64 bits of the address.
+ *
+ * @return the value of the higher (more significant) 64 bits of the
+ * address.
+ */
+ public long valueHigh() { return valueHigh; }
+
+ /**
+ * Set the value of the higher (more significant) 64 bits of the address.
+ *
+ * @param valueHigh the higher (more significant) 64 bits of the address.
+ */
+ public void setValueHigh(long valueHigh) {
+ this.valueHigh = valueHigh;
+ }
+
+ /**
+ * Get the value of the lower (less significant) 64 bits of the address.
+ *
+ * @return the value of the lower (less significant) 64 bits of the
+ * address.
+ */
+ public long valueLow() { return valueLow; }
+
+ /**
+ * Get the value of the lower (less significant) 64 bits of the address.
+ *
+ * @param valueLow the lower (less significant) 64 bits of the address.
+ */
+ public void setValueLow(long valueLow) {
+ this.valueLow = valueLow;
+ }
+
+ /**
+ * Set the value of the IPv6 address.
+ *
+ * @param valueHigh the higher (more significant) 64 bits of the address.
+ * @param valueLow the lower (less significant) 64 bits of the address.
+ */
+ public void setValue(long valueHigh, long valueLow) {
+ this.valueHigh = valueHigh;
+ this.valueLow = valueLow;
+ }
+
+ /**
+ * Convert the IPv6 value to a ':' separated string.
+ *
+ * @return the IPv6 value as a ':' separated string.
+ */
+ @Override
+ public String toString() {
+ return HexString.toHexString(this.valueHigh) + ":" +
+ HexString.toHexString(this.valueLow);
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/IPv6Net.java b/src/main/java/net/onrc/onos/core/util/IPv6Net.java
new file mode 100644
index 0000000..486f8e8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/IPv6Net.java
@@ -0,0 +1,114 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.IPv6NetDeserializer;
+import net.onrc.onos.core.util.serializers.IPv6NetSerializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing an IPv6 network address.
+ */
+@JsonDeserialize(using=IPv6NetDeserializer.class)
+@JsonSerialize(using=IPv6NetSerializer.class)
+public class IPv6Net {
+ private IPv6 address; // The IPv6 address
+ private short prefixLen; // The prefix length
+
+ /**
+ * Default constructor.
+ */
+ public IPv6Net() {
+ this.prefixLen = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public IPv6Net(IPv6Net other) {
+ if (other.address != null)
+ this.address = new IPv6(other.address);
+ this.prefixLen = other.prefixLen;
+ }
+
+ /**
+ * Constructor for a given address and prefix length.
+ *
+ * @param address the address to use.
+ * @param prefixLen the prefix length to use.
+ */
+ public IPv6Net(IPv6 address, short prefixLen) {
+ this.address = address;
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public IPv6Net(String value) {
+ String[] splits = value.split("/");
+ if (splits.length != 2) {
+ throw new IllegalArgumentException("Specified IPv6Net address must contain an IPv6 " +
+ "address and a prefix length separated by '/'");
+ }
+ this.address = new IPv6(splits[0]);
+ this.prefixLen = Short.decode(splits[1]);
+ }
+
+ /**
+ * Get the address value of the IPv6Net address.
+ *
+ * @return the address value of the IPv6Net address.
+ */
+ public IPv6 address() { return address; }
+
+ /**
+ * Set the address value of the IPv6Net address.
+ *
+ * @param address the address to use.
+ */
+ public void setAddress(IPv6 address) {
+ this.address = address;
+ }
+
+ /**
+ * Get the prefix length value of the IPv6Net address.
+ *
+ * @return the prefix length value of the IPv6Net address.
+ */
+ public short prefixLen() { return prefixLen; }
+
+ /**
+ * Set the prefix length value of the IPv6Net address.
+ *
+ * @param prefixLen the prefix length to use.
+ */
+ public void setPrefixLen(short prefixLen) {
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Set the value of the IPv6Net address.
+ *
+ * @param address the address to use.
+ * @param prefixLen the prefix length to use.
+ */
+ public void setValue(IPv6 address, short prefixLen) {
+ this.address = address;
+ this.prefixLen = prefixLen;
+ }
+
+ /**
+ * Convert the IPv6Net value to an "address/prefixLen" string.
+ *
+ * @return the IPv6Net value as an "address/prefixLen" string.
+ */
+ @Override
+ public String toString() {
+ return this.address.toString() + "/" + this.prefixLen;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/Pair.java b/src/main/java/net/onrc/onos/core/util/Pair.java
new file mode 100644
index 0000000..36a76bb
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/Pair.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util;
+
+/**
+ * A generic class representing a pair of two values.
+ */
+public class Pair<F, S> {
+ public F first; // The first value in the pair
+ public S second; // The second value in the pair
+
+ /**
+ * Constructor for a pair of two values.
+ *
+ * @param first the first value in the pair.
+ * @param second the second value in the pair.
+ */
+ public Pair(F first, S second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("<%s, %s>", first, second);
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/PerformanceMonitor.java b/src/main/java/net/onrc/onos/core/util/PerformanceMonitor.java
new file mode 100644
index 0000000..dd5e36f
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/PerformanceMonitor.java
@@ -0,0 +1,292 @@
+package net.onrc.onos.core.util;
+
+import java.util.Map.Entry;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for collecting performance measurements
+ */
+public class PerformanceMonitor {
+ private final static Logger log = LoggerFactory.getLogger(PerformanceMonitor.class);
+
+ // experiment name -> PerformanceMonitor
+ private static final ConcurrentHashMap<String,PerformanceMonitor> perfMons = new ConcurrentHashMap<>();
+ public static PerformanceMonitor experiment(String name) {
+ PerformanceMonitor pm = perfMons.get(name);
+ if (pm == null) {
+ pm = new PerformanceMonitor();
+ PerformanceMonitor existing = perfMons.putIfAbsent(name, pm);
+ if (existing != null) {
+ pm = existing;
+ }
+ }
+ return pm;
+ }
+
+ // tag -> Measurements
+ private final ConcurrentHashMap<String, Queue<Measurement>> map = new ConcurrentHashMap<>();
+ private long overhead;
+ private long experimentStart = Long.MAX_VALUE;
+ private final static double normalization = Math.pow(10, 6);
+
+ /**
+ * Start a performance measurement, identified by a tag
+ *
+ * Note: Only a single measurement can use the same tag at a time.
+ * ..... not true anymore.
+ *
+ * @param tag for performance measurement
+ */
+ public Measurement startStep(String tag) {
+ long start = System.nanoTime();
+ if(start < experimentStart) {
+ experimentStart = start;
+ }
+ Queue<Measurement> list = map.get(tag);
+ if(list == null) {
+ list = new ConcurrentLinkedQueue<Measurement>();
+ Queue<Measurement> existing_list = map.putIfAbsent(tag, list);
+ if (existing_list != null) {
+ // someone concurrently added, using theirs
+ list = existing_list;
+ }
+ }
+ Measurement m = new Measurement();
+ list.add(m);
+ m.start();
+ overhead += System.nanoTime() - start;
+ return m;
+ }
+
+ /**
+ * Stop a performance measurement.
+ *
+ * You must have already started a measurement with tag.
+ *
+ * @param tag for performance measurement
+ */
+ public void stopStep(String tag) {
+ long time = System.nanoTime();
+ Queue<Measurement> list = map.get(tag);
+ if(list == null || list.size() == 0) {
+ log.error("Tag {} does not exist", tag);
+ }
+ list.peek().stop(time);
+ if(list.size() > 1) {
+ log.error("Tag {} has multiple measurements", tag);
+ }
+ overhead += System.nanoTime() - time;
+ }
+
+ /**
+ * Clear all performance measurements.
+ */
+ public void reset() {
+ map.clear();
+ overhead = 0;
+ experimentStart = Long.MAX_VALUE;
+ }
+
+ /**
+ * Write all performance measurements to the log
+ */
+ public void reportAll() {
+ String result = "Performance Results: (avg/start/stop/count)\n";
+ if(map.size() == 0) {
+ result += "No Measurements";
+ log.error(result);
+ return;
+ }
+ long experimentEnd = -1;
+ for(Entry<String, Queue<Measurement>> e : map.entrySet()) {
+ String key = e.getKey();
+ Queue<Measurement> list = e.getValue();
+ long total = 0, count = 0;
+ long start = Long.MAX_VALUE, stop = -1;
+ for(Measurement m : list) {
+ if(m.stop < 0) {
+ continue; // measurement has not been stopped
+ }
+ // Collect overall start and end times
+ if(m.start < start) {
+ start = m.start;
+ }
+ if(m.stop > stop) {
+ stop = m.stop;
+ if(stop > experimentEnd) {
+ experimentEnd = stop;
+ }
+ }
+ // Collect statistics for average
+ total += m.elapsed();
+ count++;
+ }
+ double avg = (double) total / count;
+ // Normalize start/stop
+ start -= experimentStart;
+ stop -= experimentStart;
+ result += key + '=' +
+ (avg / normalization) + '/' +
+ (start / normalization) + '/' +
+ (stop / normalization) + '/' +
+ count + '\n';
+ }
+ double overheadMs = overhead / normalization;
+ double experimentElapsed = (experimentEnd - experimentStart) / normalization;
+ result += "TotalTime:" + experimentElapsed + "/Overhead:" + overheadMs;
+ log.error(result);
+// log.error("Performance Results: {} with measurement overhead: {} ms", map, overheadMilli);
+ }
+
+ /**
+ * Write the performance measurement for a tag to the log
+ *
+ * @param tag the tag name.
+ */
+ public void reportStep(String tag) {
+ Queue<Measurement> list = map.get(tag);
+ if(list == null) {
+ return; //TODO
+ }
+ //TODO: fix this;
+ Measurement m = list.peek();
+ if (m != null) {
+ log.error("Performance Result: tag = {} start = {} stop = {} elapsed = {}",
+ tag, m.start, m.stop, m.toString());
+ } else {
+ log.error("Performance Result: unknown tag {}", tag);
+ }
+ }
+
+ /**
+ * A single performance measurement
+ */
+ public static class Measurement {
+ long start;
+ long stop = -1;
+
+ /**
+ * Start the measurement
+ */
+ public void start() {
+ if(start <= 0) {
+ start = System.nanoTime();
+ }
+ }
+
+ /**
+ * Stop the measurement
+ */
+ public void stop() {
+ long now = System.nanoTime();
+ stop(now);
+ }
+
+ /**
+ * Stop the measurement at a specific time
+ * @param time to stop
+ */
+ public void stop(long time){
+ if(stop <= 0) {
+ stop = time;
+ }
+ }
+
+ /**
+ * Compute the elapsed time of the measurement in nanoseconds
+ *
+ * @return the measurement time in nanoseconds, or -1 if the measurement is stil running.
+ */
+ public long elapsed() {
+ if(stop <= 0) {
+ return -1;
+ }
+ else {
+ return stop - start;
+ }
+ }
+
+ /**
+ * Returns the number of milliseconds for the measurement as a String.
+ */
+ @Override
+ public String toString() {
+ double milli = elapsed() / normalization;
+ double startMs = start / normalization;
+ double stopMs = stop / normalization;
+
+ return milli + "ms/" + startMs + '/' + stopMs;
+ }
+ }
+
+ @Deprecated
+ private static final PerformanceMonitor theInstance = new PerformanceMonitor();
+
+ @Deprecated
+ public static Measurement start(String tag) {
+ return theInstance.startStep(tag);
+ }
+
+ @Deprecated
+ public static void stop(String tag) {
+ theInstance.stopStep(tag);;
+ }
+
+ @Deprecated
+ public static void clear() {
+ theInstance.reset();;
+ }
+
+ @Deprecated
+ public static void report() {
+ theInstance.reportAll();;
+ }
+
+ @Deprecated
+ public static void report(String tag) {
+ theInstance.reportStep(tag);
+ }
+
+ public static void main(String args[]){
+ // test the measurement overhead
+ String tag;
+ for(int i = 0; i < 2; i++){
+ tag = "foo foo foo";
+ Measurement m;
+ m = start(tag); System.out.println(tag); m.stop();
+ m = start(tag); System.out.println(tag); m.stop();
+ m = start(tag); System.out.println(tag); m.stop();
+ m = start(tag); System.out.println(tag); m.stop();
+ tag = "bar";
+ start(tag); stop(tag);
+ tag = "baz";
+ start(tag); stop(tag);
+ report();
+ clear();
+ }
+ for(int i = 0; i < 100; i++){
+ tag = "a";
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+ start(tag); stop(tag);
+
+ tag = "b";
+ start(tag); stop(tag);
+ tag = "c";
+ start(tag); stop(tag);
+ report();
+ clear();
+ }
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/Port.java b/src/main/java/net/onrc/onos/core/util/Port.java
new file mode 100644
index 0000000..722c802
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/Port.java
@@ -0,0 +1,153 @@
+package net.onrc.onos.core.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing a network port of a switch.
+ */
+
+public class Port {
+ /**
+ * Special port values.
+ *
+ * Those values are taken as-is from the OpenFlow-v1.0.0 specification
+ * (pp 18-19).
+ */
+ public enum PortValues {
+ /* Maximum number of physical switch ports. */
+ PORT_MAX ((short)0xff00),
+
+ /* Fake output "ports". */
+
+ /* Send the packet out the input port. This
+ virtual port must be explicitly used
+ in order to send back out of the input
+ port. */
+ PORT_IN_PORT ((short)0xfff8),
+
+ /* Perform actions in flow table.
+ NB: This can only be the destination
+ port for packet-out messages. */
+ PORT_TABLE ((short)0xfff9),
+
+ /* Process with normal L2/L3 switching. */
+ PORT_NORMAL ((short)0xfffa),
+
+ /* All physical ports except input port and
+ those disabled by STP. */
+ PORT_FLOOD ((short)0xfffb),
+
+ /* All physical ports except input port. */
+ PORT_ALL ((short)0xfffc),
+
+ /* Send to controller. */
+ PORT_CONTROLLER ((short)0xfffd),
+
+ /* Local openflow "port". */
+ PORT_LOCAL ((short)0xfffe),
+
+ /* Not associated with a physical port. */
+ PORT_NONE ((short)0xffff);
+
+ private final short value; // The value
+
+ /**
+ * Constructor for a given value.
+ *
+ * @param value the value to use for the initialization.
+ */
+ private PortValues(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the value as a short integer.
+ *
+ * @return the value as a short integer.
+ */
+ private short value() { return this.value; }
+ }
+
+ private short value;
+
+ /**
+ * Default constructor.
+ */
+ public Port() {
+ this.value = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public Port(Port other) {
+ this.value = other.value();
+ }
+
+ /**
+ * Constructor from a short integer value.
+ *
+ * @param value the value to use.
+ */
+ public Port(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a PortValues enum value.
+ *
+ * @param value the value to use.
+ */
+ public Port(PortValues value) {
+ this.value = value.value();
+ }
+
+ /**
+ * Get the value of the port.
+ *
+ * @return the value of the port.
+ */
+ @JsonProperty("value")
+ public short value() { return value; }
+
+ /**
+ * Set the value of the port.
+ *
+ * @param value the value to set.
+ */
+ @JsonProperty("value")
+ public void setValue(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Convert the port value to a string.
+ *
+ * @return the port value as a string.
+ */
+ @Override
+ public String toString() {
+ return Short.toString(this.value);
+ }
+
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Port)) {
+ return false;
+ }
+
+ Port otherPort = (Port) other;
+
+ return value == otherPort.value;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash += 31 * hash + (int)value;
+ return hash;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/Switch.java b/src/main/java/net/onrc/onos/core/util/Switch.java
new file mode 100644
index 0000000..e3c525f
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/Switch.java
@@ -0,0 +1,116 @@
+package net.onrc.onos.core.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing a Switch.
+ * NOTE: Currently this class is (almost) not used.
+ */
+public class Switch {
+ /**
+ * The Switch state.
+ */
+ public enum SwitchState {
+ INACTIVE,
+ ACTIVE,
+ }
+
+ private Dpid dpid; // The DPID of the switch
+ private SwitchState state; // The state of the switch
+
+ /**
+ * Default constructor.
+ *
+ * NOTE: The default state for the switch is INACTIVE.
+ */
+ public Switch() {
+ this.dpid = new Dpid();
+ this.state = SwitchState.INACTIVE;
+ }
+
+ /**
+ * Constructor for a given DPID.
+ *
+ * NOTE: The state for the switch with a given DPID is ACTIVE.
+ *
+ * @param dpid the DPID to use.
+ */
+ public Switch(Dpid dpid) {
+ this.dpid = dpid;
+ this.state = SwitchState.ACTIVE;
+ }
+
+ /**
+ * Constructor for a given DPID and Switch State.
+ *
+ * @param dpid the DPID to use.
+ * @param state the Switch State to use.
+ */
+ public Switch(Dpid dpid, SwitchState state) {
+ this.dpid = dpid;
+ this.state = state;
+ }
+
+ /**
+ * Get the DPID.
+ *
+ * @return the DPID.
+ */
+ @JsonProperty("dpid")
+ public Dpid dpid() { return dpid; }
+
+ /**
+ * Set the DPID.
+ *
+ * @param dpid the DPID to use.
+ */
+ @JsonProperty("dpid")
+ public void setDpid(Dpid dpid) {
+ this.dpid = dpid;
+ }
+
+ /**
+ * Get the state.
+ *
+ * @return the state.
+ */
+ @JsonProperty("state")
+ public SwitchState state() { return state; }
+
+ /**
+ * Set the state.
+ *
+ * @param state the state to use.
+ */
+ @JsonProperty("state")
+ public void setState(SwitchState state) {
+ this.state = state;
+ }
+
+ /**
+ * Set the Switch State to ACTIVE.
+ */
+ public void setStateActive() {
+ this.state = SwitchState.ACTIVE;
+ }
+
+ /**
+ * Set the Switch State to INACTIVE.
+ */
+ public void setStateInactive() {
+ this.state = SwitchState.INACTIVE;
+ }
+
+ /**
+ * Convert the Switch value to a string.
+ *
+ * The string has the following form:
+ * dpid/state
+ *
+ * @return the Switch value as a string.
+ */
+ @Override
+ public String toString() {
+ return this.dpid.toString() + "/" + this.state.toString();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/SwitchPort.java b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
new file mode 100644
index 0000000..edc8905
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
@@ -0,0 +1,109 @@
+package net.onrc.onos.core.util;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * The class representing a Switch-Port.
+ */
+public class SwitchPort {
+ private Dpid dpid; // The DPID of the switch
+ private Port port; // The port of the switch
+
+ /**
+ * Default constructor.
+ */
+ public SwitchPort() {
+ }
+
+ /**
+ * Constructor for a given DPID and a port.
+ *
+ * @param dpid the DPID to use.
+ * @param port the port to use.
+ */
+ public SwitchPort(Dpid dpid, Port port) {
+ this.dpid = dpid;
+ this.port = port;
+ }
+
+ /**
+ * Get the DPID value of the Switch-Port.
+ *
+ * @return the DPID value of the Switch-Port.
+ */
+ @JsonProperty("dpid")
+ public Dpid dpid() { return dpid; }
+
+ /**
+ * Set the DPID value of the Switch-Port.
+ *
+ * @param dpid the DPID to use.
+ */
+ @JsonProperty("dpid")
+ public void setDpid(Dpid dpid) {
+ this.dpid = dpid;
+ }
+
+ /**
+ * Get the port value of the Switch-Port.
+ *
+ * @return the port value of the Switch-Port.
+ */
+ @JsonProperty("port")
+ public Port port() { return port; }
+
+ /**
+ * Set the port value of the Switch-Port.
+ *
+ * @param port the port to use.
+ */
+ @JsonProperty("port")
+ public void setPort(Port port) {
+ this.port = port;
+ }
+
+ /**
+ * Set the DPID and port values of the Switch-Port.
+ *
+ * @param dpid the DPID to use.
+ * @param port the port to use.
+ */
+ public void setValue(Dpid dpid, Port port) {
+ this.dpid = dpid;
+ this.port = port;
+ }
+
+ /**
+ * Convert the Switch-Port value to a string.
+ *
+ * The string has the following form:
+ * 01:02:03:04:05:06:07:08/1234
+ *
+ * @return the Switch-Port value as a string.
+ */
+ @Override
+ public String toString() {
+ return this.dpid.toString() + "/" + this.port;
+ }
+
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof SwitchPort)) {
+ return false;
+ }
+
+ SwitchPort otherSwitchPort = (SwitchPort) other;
+
+ return (dpid.equals(otherSwitchPort.dpid) &&
+ port.equals(otherSwitchPort.port));
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash += 31 * hash + dpid.hashCode();
+ hash += 31 * hash + port.hashCode();
+ return hash;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/DpidDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/DpidDeserializer.java
new file mode 100644
index 0000000..7a8c570
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/DpidDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.Dpid;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize a DPID from a string.
+ */
+public class DpidDeserializer extends JsonDeserializer<Dpid> {
+
+ protected final static Logger log = LoggerFactory.getLogger(DpidDeserializer.class);
+
+ @Override
+ public Dpid deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ Dpid dpid = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ dpid = new Dpid(value);
+ }
+ }
+ return dpid;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/DpidSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/DpidSerializer.java
new file mode 100644
index 0000000..4e784f2
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/DpidSerializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.Dpid;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize a DPID as a string.
+ */
+public class DpidSerializer extends JsonSerializer<Dpid> {
+
+ @Override
+ public void serialize(Dpid dpid, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", dpid.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdDeserializer.java
new file mode 100644
index 0000000..712daa8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.FlowEntryId;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize a Flow Entry ID from a string.
+ */
+public class FlowEntryIdDeserializer extends JsonDeserializer<FlowEntryId> {
+
+ protected final static Logger log = LoggerFactory.getLogger(FlowEntryIdDeserializer.class);
+
+ @Override
+ public FlowEntryId deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ FlowEntryId flowEntryId = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: " + fieldname + " Value: " + value);
+ flowEntryId = new FlowEntryId(value);
+ }
+ }
+ return flowEntryId;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdSerializer.java
new file mode 100644
index 0000000..3911a4c
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/FlowEntryIdSerializer.java
@@ -0,0 +1,23 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.FlowEntryId;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize a Flow Entry ID as a hexadecimal string.
+ */
+public class FlowEntryIdSerializer extends JsonSerializer<FlowEntryId> {
+
+ @Override
+ public void serialize(FlowEntryId flowEntryId, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeString(flowEntryId.toString());
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/FlowIdDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/FlowIdDeserializer.java
new file mode 100644
index 0000000..d1b91a8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/FlowIdDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.FlowId;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize a Flow ID from a string.
+ */
+public class FlowIdDeserializer extends JsonDeserializer<FlowId> {
+
+ protected final static Logger log = LoggerFactory.getLogger(FlowIdDeserializer.class);
+
+ @Override
+ public FlowId deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ FlowId flowId = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ flowId = new FlowId(value);
+ }
+ }
+ return flowId;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/FlowIdSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/FlowIdSerializer.java
new file mode 100644
index 0000000..b0d020e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/FlowIdSerializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.FlowId;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize a Flow ID as a hexadecimal string.
+ */
+public class FlowIdSerializer extends JsonSerializer<FlowId> {
+
+ @Override
+ public void serialize(FlowId flowId, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", flowId.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv4Deserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv4Deserializer.java
new file mode 100644
index 0000000..2992bfd
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv4Deserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv4;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize an IPv4 address from a string.
+ */
+public class IPv4Deserializer extends JsonDeserializer<IPv4> {
+
+ protected final static Logger log = LoggerFactory.getLogger(IPv4Deserializer.class);
+
+ @Override
+ public IPv4 deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ IPv4 ipv4 = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ ipv4 = new IPv4(value);
+ }
+ }
+ return ipv4;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetDeserializer.java
new file mode 100644
index 0000000..68f74c4
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv4Net;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize an IPv4Net address from a string.
+ */
+public class IPv4NetDeserializer extends JsonDeserializer<IPv4Net> {
+
+ protected final static Logger log = LoggerFactory.getLogger(IPv4NetDeserializer.class);
+
+ @Override
+ public IPv4Net deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ IPv4Net ipv4Net = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ ipv4Net = new IPv4Net(value);
+ }
+ }
+ return ipv4Net;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetSerializer.java
new file mode 100644
index 0000000..697f846
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv4NetSerializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv4Net;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize an IPv4Net address as a string.
+ */
+public class IPv4NetSerializer extends JsonSerializer<IPv4Net> {
+
+ @Override
+ public void serialize(IPv4Net ipv4Net, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", ipv4Net.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv4Serializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv4Serializer.java
new file mode 100644
index 0000000..773fd1d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv4Serializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv4;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize an IPv4 address as a string.
+ */
+public class IPv4Serializer extends JsonSerializer<IPv4> {
+
+ @Override
+ public void serialize(IPv4 ipv4, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", ipv4.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv6Deserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv6Deserializer.java
new file mode 100644
index 0000000..6627d2a
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv6Deserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv6;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize an IPv6 address from a string.
+ */
+public class IPv6Deserializer extends JsonDeserializer<IPv6> {
+
+ protected final static Logger log = LoggerFactory.getLogger(IPv6Deserializer.class);
+
+ @Override
+ public IPv6 deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ IPv6 ipv6 = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ ipv6 = new IPv6(value);
+ }
+ }
+ return ipv6;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetDeserializer.java
new file mode 100644
index 0000000..08b8018
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv6Net;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize an IPv6Net address from a string.
+ */
+public class IPv6NetDeserializer extends JsonDeserializer<IPv6Net> {
+
+ protected final static Logger log = LoggerFactory.getLogger(IPv6NetDeserializer.class);
+
+ @Override
+ public IPv6Net deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ IPv6Net ipv6Net = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ ipv6Net = new IPv6Net(value);
+ }
+ }
+ return ipv6Net;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetSerializer.java
new file mode 100644
index 0000000..99bd654
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv6NetSerializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv6Net;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize an IPv6Net address as a string.
+ */
+public class IPv6NetSerializer extends JsonSerializer<IPv6Net> {
+
+ @Override
+ public void serialize(IPv6Net ipv6Net, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", ipv6Net.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/IPv6Serializer.java b/src/main/java/net/onrc/onos/core/util/serializers/IPv6Serializer.java
new file mode 100644
index 0000000..b165658
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/IPv6Serializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.onrc.onos.core.util.IPv6;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize an IPv6 address as a string.
+ */
+public class IPv6Serializer extends JsonSerializer<IPv6> {
+
+ @Override
+ public void serialize(IPv6 ipv6, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", ipv6.toString());
+ jGen.writeEndObject();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
new file mode 100644
index 0000000..4cd4a00
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -0,0 +1,238 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.apps.proxyarp.ArpReplyNotification;
+import net.onrc.onos.apps.proxyarp.BroadcastPacketOutNotification;
+import net.onrc.onos.apps.proxyarp.PacketOutNotification;
+import net.onrc.onos.apps.proxyarp.SinglePacketOutNotification;
+import net.onrc.onos.core.devicemanager.OnosDevice;
+import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
+import net.onrc.onos.core.intent.ErrorIntent;
+import net.onrc.onos.core.intent.Intent;
+import net.onrc.onos.core.intent.IntentOperation;
+import net.onrc.onos.core.intent.IntentOperationList;
+import net.onrc.onos.core.intent.PathIntent;
+import net.onrc.onos.core.intent.ShortestPathIntent;
+import net.onrc.onos.core.intent.runtime.IntentStateList;
+import net.onrc.onos.core.util.CallerId;
+import net.onrc.onos.core.util.DataPath;
+import net.onrc.onos.core.util.DataPathEndpoints;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.FlowEntry;
+import net.onrc.onos.core.util.FlowEntryAction;
+import net.onrc.onos.core.util.FlowEntryActions;
+import net.onrc.onos.core.util.FlowEntryErrorState;
+import net.onrc.onos.core.util.FlowEntryId;
+import net.onrc.onos.core.util.FlowEntryMatch;
+import net.onrc.onos.core.util.FlowEntrySwitchState;
+import net.onrc.onos.core.util.FlowEntryUserState;
+import net.onrc.onos.core.util.FlowId;
+import net.onrc.onos.core.util.FlowPath;
+import net.onrc.onos.core.util.FlowPathFlags;
+import net.onrc.onos.core.util.FlowPathType;
+import net.onrc.onos.core.util.FlowPathUserState;
+import net.onrc.onos.core.util.IPv4;
+import net.onrc.onos.core.util.IPv4Net;
+import net.onrc.onos.core.util.IPv6;
+import net.onrc.onos.core.util.IPv6Net;
+import net.onrc.onos.core.util.Port;
+import net.onrc.onos.core.util.Switch;
+import net.onrc.onos.ofcontroller.networkgraph.DeviceEvent;
+import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
+import net.onrc.onos.ofcontroller.networkgraph.Path;
+import net.onrc.onos.ofcontroller.networkgraph.PortEvent;
+import net.onrc.onos.ofcontroller.networkgraph.SwitchEvent;
+import net.onrc.onos.ofcontroller.networkgraph.TopologyEvent;
+// import net.onrc.onos.core.util.SwitchPort;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import com.esotericsoftware.kryo.Kryo;
+
+/**
+ * Class factory for allocating Kryo instances for
+ * serialization/deserialization of classes.
+ */
+public class KryoFactory {
+ private static final int DEFAULT_PREALLOCATIONS = 100;
+ private ArrayList<Kryo> kryoList = new ArrayList<Kryo>();
+
+ /**
+ * Default constructor.
+ *
+ * Preallocates {@code DEFAULT_PREALLOCATIONS} Kryo instances.
+ */
+ public KryoFactory() {
+ this(DEFAULT_PREALLOCATIONS);
+ }
+
+ /**
+ * Constructor to explicitly specify number of Kryo instances to pool
+ *
+ * @param initialCapacity number of Kryo instance to preallocate
+ */
+ public KryoFactory(final int initialCapacity) {
+ // Preallocate
+ kryoList.ensureCapacity(initialCapacity);
+ for (int i = 0; i < initialCapacity; i++) {
+ Kryo kryo = newKryoImpl();
+ kryoList.add(kryo);
+ }
+ }
+
+ /**
+ * Create and initialize a new Kryo object.
+ *
+ * @return the created Kryo object.
+ */
+ public Kryo newKryo() {
+ return newDeleteKryo(null);
+ }
+
+ /**
+ * Delete an existing Kryo object.
+ *
+ * @param deleteKryo the object to delete.
+ */
+ public void deleteKryo(Kryo deleteKryo) {
+ newDeleteKryo(deleteKryo);
+ }
+
+ /**
+ * Create or delete a Kryo object.
+ *
+ * @param deleteKryo if null, then allocate and return a new object,
+ * otherwise delete the provided object.
+ * @return a new Kryo object if needed, otherwise null.
+ */
+ synchronized private Kryo newDeleteKryo(Kryo deleteKryo) {
+ if (deleteKryo != null) {
+ // Delete an entry by moving it back to the buffer
+ kryoList.add(deleteKryo);
+ return null;
+ } else {
+ Kryo kryo = null;
+ if (kryoList.isEmpty()) {
+ // Preallocate
+ for (int i = 0; i < 100; i++) {
+ kryo = newKryoImpl();
+ kryoList.add(kryo);
+ }
+ }
+
+ kryo = kryoList.remove(kryoList.size() - 1);
+ return kryo;
+ }
+ }
+
+ /**
+ * Create and initialize a new Kryo object.
+ *
+ * @return the created Kryo object.
+ */
+ private Kryo newKryoImpl() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ //
+ // WARNING: Order of register() calls affects serialized bytes.
+ // - Do no insert new entry in the middle, always add to the end.
+ // - Do not simply remove existing entry
+ //
+
+ // kryo.setReferences(false);
+ //
+ kryo.register(ArrayList.class);
+
+ // FlowPath and related classes
+ kryo.register(CallerId.class);
+ kryo.register(DataPath.class);
+ kryo.register(DataPathEndpoints.class);
+ kryo.register(Dpid.class);
+ kryo.register(FlowEntryAction.class);
+ kryo.register(FlowEntryAction.ActionEnqueue.class);
+ kryo.register(FlowEntryAction.ActionOutput.class);
+ kryo.register(FlowEntryAction.ActionSetEthernetAddr.class);
+ kryo.register(FlowEntryAction.ActionSetIpToS.class);
+ kryo.register(FlowEntryAction.ActionSetIPv4Addr.class);
+ kryo.register(FlowEntryAction.ActionSetTcpUdpPort.class);
+ kryo.register(FlowEntryAction.ActionSetVlanId.class);
+ kryo.register(FlowEntryAction.ActionSetVlanPriority.class);
+ kryo.register(FlowEntryAction.ActionStripVlan.class);
+ kryo.register(FlowEntryAction.ActionValues.class);
+ kryo.register(FlowEntryActions.class);
+ kryo.register(FlowEntryErrorState.class);
+ kryo.register(FlowEntryId.class);
+ kryo.register(FlowEntry.class);
+ kryo.register(FlowEntryMatch.class);
+ kryo.register(FlowEntryMatch.Field.class);
+ kryo.register(FlowEntrySwitchState.class);
+ kryo.register(FlowEntryUserState.class);
+ kryo.register(FlowId.class);
+ kryo.register(FlowPath.class);
+ kryo.register(FlowPathFlags.class);
+ kryo.register(FlowPathType.class);
+ kryo.register(FlowPathUserState.class);
+ kryo.register(IPv4.class);
+ kryo.register(IPv4Net.class);
+ kryo.register(IPv6.class);
+ kryo.register(IPv6Net.class);
+ kryo.register(byte[].class);
+ kryo.register(MACAddress.class);
+ kryo.register(Port.class);
+ kryo.register(Switch.class);
+ // kryo.register(SwitchPort.class);
+
+ // New data model-related classes
+ kryo.register(DeviceEvent.class);
+ kryo.register(InetAddress.class);
+ kryo.register(LinkEvent.class);
+ kryo.register(PortEvent.class);
+ kryo.register(PortEvent.SwitchPort.class);
+ kryo.register(SwitchEvent.class);
+ kryo.register(TopologyEvent.class);
+
+ // Intent-related classes
+ kryo.register(Path.class);
+ kryo.register(Intent.class);
+ kryo.register(Intent.IntentState.class);
+ kryo.register(PathIntent.class);
+ kryo.register(ShortestPathIntent.class);
+ kryo.register(ConstrainedShortestPathIntent.class);
+ kryo.register(ErrorIntent.class);
+ kryo.register(ErrorIntent.ErrorType.class);
+ kryo.register(IntentOperation.class);
+ kryo.register(IntentOperation.Operator.class);
+ kryo.register(IntentOperationList.class);
+ kryo.register(IntentStateList.class);
+
+ // Device-related classes
+ kryo.register(HashSet.class);
+ kryo.register(Inet4Address.class);
+ kryo.register(OnosDevice.class);
+ kryo.register(Date.class);
+
+ // ProxyArp-related classes
+ kryo.register(BroadcastPacketOutNotification.class);
+ kryo.register(SinglePacketOutNotification.class);
+ kryo.register(ArpReplyNotification.class);
+
+ return kryo;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/MACAddressDeserializer.java b/src/main/java/net/onrc/onos/core/util/serializers/MACAddressDeserializer.java
new file mode 100644
index 0000000..4ed31a5
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/MACAddressDeserializer.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.floodlightcontroller.util.MACAddress;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Deserialize a MAC address from a string.
+ */
+public class MACAddressDeserializer extends JsonDeserializer<MACAddress> {
+
+ protected final static Logger log = LoggerFactory.getLogger(MACAddressDeserializer.class);
+
+ @Override
+ public MACAddress deserialize(JsonParser jp,
+ DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ MACAddress mac = null;
+
+ jp.nextToken(); // Move to JsonToken.START_OBJECT
+ while (jp.nextToken() != JsonToken.END_OBJECT) {
+ String fieldname = jp.getCurrentName();
+ if ("value".equals(fieldname)) {
+ String value = jp.getText();
+ log.debug("Fieldname: {} Value: {}", fieldname, value);
+ mac = MACAddress.valueOf(value);
+ }
+ }
+ return mac;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/MACAddressSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/MACAddressSerializer.java
new file mode 100644
index 0000000..e57a777
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/MACAddressSerializer.java
@@ -0,0 +1,25 @@
+package net.onrc.onos.core.util.serializers;
+
+import java.io.IOException;
+
+import net.floodlightcontroller.util.MACAddress;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+
+/**
+ * Serialize a MAC address as a string.
+ */
+public class MACAddressSerializer extends JsonSerializer<MACAddress> {
+
+ @Override
+ public void serialize(MACAddress mac, JsonGenerator jGen,
+ SerializerProvider serializer)
+ throws IOException, JsonProcessingException {
+ jGen.writeStartObject();
+ jGen.writeStringField("value", mac.toString());
+ jGen.writeEndObject();
+ }
+}