adding javadoc to intent classes: Action, FlowEntry, ForwardAction, Match
Change-Id: Ia7d6475adc7c88430deeb182e22604d766252c2c
diff --git a/src/main/java/net/onrc/onos/core/intent/Action.java b/src/main/java/net/onrc/onos/core/intent/Action.java
index 6490fe5..100dc33 100644
--- a/src/main/java/net/onrc/onos/core/intent/Action.java
+++ b/src/main/java/net/onrc/onos/core/intent/Action.java
@@ -3,10 +3,15 @@
import net.onrc.onos.core.util.FlowEntryAction;
/**
- * @author Brian O'Connor <bocon@onlab.us>
+ * An abstract class that represents an OpenFlow action.
*/
public abstract class Action {
+ /**
+ * This function converts the Action into a legacy FlowEntryAction.
+ *
+ * @return an equivalent FlowEntryAction object
+ */
public abstract FlowEntryAction getFlowEntryAction();
}
diff --git a/src/main/java/net/onrc/onos/core/intent/FlowEntry.java b/src/main/java/net/onrc/onos/core/intent/FlowEntry.java
index 80b9849..c738cbc 100644
--- a/src/main/java/net/onrc/onos/core/intent/FlowEntry.java
+++ b/src/main/java/net/onrc/onos/core/intent/FlowEntry.java
@@ -1,6 +1,7 @@
package net.onrc.onos.core.intent;
import java.util.HashSet;
+import java.util.Objects;
import java.util.Set;
import net.floodlightcontroller.util.MACAddress;
@@ -11,7 +12,8 @@
import net.onrc.onos.core.util.FlowEntryUserState;
/**
- * @author Brian O'Connor <bocon@onlab.us>
+ * A class to represent an OpenFlow FlowMod.
+ * It is OpenFlow v.1.0-centric and contains a Match and an Action.
*/
public class FlowEntry {
@@ -23,6 +25,18 @@
protected int idleTimeout = 0;
protected long flowEntryId;
+ /**
+ * Constructor.
+ *
+ * @param sw switch's DPID
+ * @param srcPort source port on switch
+ * @param dstPort output port on switch
+ * @param srcMac source Ethernet MAC address
+ * @param dstMac destination Ethernet MAC address
+ * @param srcIpAddress source IP address
+ * @param dstIpAddress destination IP address
+ * @param operator OpenFlow operation/command (add, remove, etc.)
+ */
// CHECKSTYLE:OFF suppress the warning about too many parameters
public FlowEntry(long sw, long srcPort, long dstPort,
MACAddress srcMac, MACAddress dstMac,
@@ -37,7 +51,34 @@
this.flowEntryId = hashCode();
}
- /***
+ /**
+ * Gets the switch for this FlowEntry.
+ *
+ * @return the switch's DPID
+ */
+ public long getSwitch() {
+ return sw;
+ }
+
+ /**
+ * Gets the operator (i.e. add, remove, error).
+ *
+ * @return the operator
+ */
+ public Operator getOperator() {
+ return operator;
+ }
+
+ /**
+ * Sets the FlowMod operation (i.e. add, remove, error).
+ *
+ * @param op the operator
+ */
+ public void setOperator(Operator op) {
+ operator = op;
+ }
+
+ /**
* Gets hard timeout value in seconds.
*
* @return the hard timeout value in seconds
@@ -46,16 +87,7 @@
return hardTimeout;
}
- /***
- * Gets idle timeout value in seconds.
- *
- * @return the idle timeout value in seconds
- */
- public int getIdleTimeout() {
- return idleTimeout;
- }
-
- /***
+ /**
* Sets hard timeout value in seconds.
*
* @param hardTimeout hard timeout value in seconds
@@ -64,7 +96,16 @@
this.hardTimeout = hardTimeout;
}
- /***
+ /**
+ * Gets idle timeout value in seconds.
+ *
+ * @return the idle timeout value in seconds
+ */
+ public int getIdleTimeout() {
+ return idleTimeout;
+ }
+
+ /**
* Sets idle timeout value in seconds.
*
* @param idleTimeout idle timeout value in seconds
@@ -73,16 +114,16 @@
this.idleTimeout = idleTimeout;
}
- /***
+ /**
* Gets flowEntryId.
*
- * @param the flowEntryId to be set in cookie
+ * @return the flowEntryId to be set in cookie
*/
public long getFlowEntryId() {
return flowEntryId;
}
- /***
+ /**
* Sets flowEntryId.
*
* @param flowEntryId flowEntryId to be set in cookie
@@ -91,23 +132,11 @@
this.flowEntryId = flowEntryId;
}
- @Override
- public String toString() {
- return match + "->" + actions;
- }
-
- public long getSwitch() {
- return sw;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public void setOperator(Operator op) {
- operator = op;
- }
-
+ /**
+ * Converts the FlowEntry in to a legacy FlowEntry object.
+ *
+ * @return an equivalent legacy FlowEntry object
+ */
public net.onrc.onos.core.util.FlowEntry getFlowEntry() {
net.onrc.onos.core.util.FlowEntry entry = new net.onrc.onos.core.util.FlowEntry();
entry.setDpid(new Dpid(sw));
@@ -133,12 +162,29 @@
return entry;
}
-
+ /**
+ * Returns a String representation of this FlowEntry.
+ *
+ * @return the FlowEntry as a String
+ */
@Override
- public int hashCode() {
- return match.hashCode();
+ public String toString() {
+ return match + "->" + actions;
}
+ /**
+ * Generates hash using Objects.hash() on the match and actions.
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(match, actions);
+ }
+
+ /**
+ * Flow Entries are equal if their matches and action sets are equal.
+ *
+ * @return true if equal, false otherwise
+ */
@Override
public boolean equals(Object o) {
if (!(o instanceof FlowEntry)) {
diff --git a/src/main/java/net/onrc/onos/core/intent/ForwardAction.java b/src/main/java/net/onrc/onos/core/intent/ForwardAction.java
index 4e4088f..f0d09cb 100644
--- a/src/main/java/net/onrc/onos/core/intent/ForwardAction.java
+++ b/src/main/java/net/onrc/onos/core/intent/ForwardAction.java
@@ -3,20 +3,35 @@
import net.onrc.onos.core.util.FlowEntryAction;
/**
- * @author Brian O'Connor <bocon@onlab.us>
+ * A class to represent the OpenFlow forwarding action.
*/
class ForwardAction extends Action {
protected long dstPort;
+ /**
+ * Constructor.
+ *
+ * @param dstPort the destination port to forward packets
+ */
public ForwardAction(long dstPort) {
this.dstPort = dstPort;
}
+ /**
+ * Returns a String representation of this ForwardAction.
+ *
+ * @return the destination port as a String
+ */
public String toString() {
return Long.toString(dstPort);
}
+ /**
+ * Converts the FowardAction into a legacy FlowEntryAction object.
+ *
+ * @return an equivalent FlowEntryAction object
+ */
@Override
public FlowEntryAction getFlowEntryAction() {
FlowEntryAction action = new FlowEntryAction();
@@ -24,10 +39,21 @@
return action;
}
+ /**
+ * A simple hash function that just used the destination port.
+ *
+ * @return hashcode
+ */
public int hashCode() {
return (int) dstPort;
}
+ /**
+ * Objects are equal if they share a destination port.
+ *
+ * @params o another object to compare to this
+ * @return true if equal, false otherwise
+ */
public boolean equals(Object o) {
if (!(o instanceof ForwardAction)) {
return false;
diff --git a/src/main/java/net/onrc/onos/core/intent/Match.java b/src/main/java/net/onrc/onos/core/intent/Match.java
index d4e0ce2..0731395 100644
--- a/src/main/java/net/onrc/onos/core/intent/Match.java
+++ b/src/main/java/net/onrc/onos/core/intent/Match.java
@@ -5,14 +5,21 @@
import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.core.packet.Ethernet;
-//import net.onrc.onos.core.topology.Port;
-//import net.onrc.onos.core.topology.Switch;
import net.onrc.onos.core.util.FlowEntryMatch;
import net.onrc.onos.core.util.IPv4;
import net.onrc.onos.core.util.IPv4Net;
/**
- * @author Brian O'Connor <bocon@onlab.us>
+ * A class to represent the OpenFlow match.
+ * <p>
+ * At the moment, the supported match conditions are:
+ * <ul>
+ * <li>source port
+ * <li>source and destination MAC address
+ * <li>source and destination IP address
+ * </ul>
+ * <p>
+ * TODO: extend this object to allow more match conditions
*/
public class Match {
@@ -24,11 +31,29 @@
protected int dstIp;
protected long srcPort;
+ /**
+ * Constructor for Ethernet-based matches.
+ *
+ * @param sw switch's DPID
+ * @param srcPort source port on switch
+ * @param srcMac source Ethernet MAC address
+ * @param dstMac destination Ethernet MAC address
+ */
public Match(long sw, long srcPort,
MACAddress srcMac, MACAddress dstMac) {
this(sw, srcPort, srcMac, dstMac, ShortestPathIntent.EMPTYIPADDRESS, ShortestPathIntent.EMPTYIPADDRESS);
}
+ /**
+ * Generic constructor.
+ *
+ * @param sw switch's DPID
+ * @param srcPort source port on switch
+ * @param srcMac source Ethernet MAC address
+ * @param dstMac destination Ethernet MAC address
+ * @param srcIp source IP address
+ * @param dstIp destination IP address
+ */
public Match(long sw, long srcPort, MACAddress srcMac, MACAddress dstMac,
int srcIp, int dstIp) {
@@ -40,10 +65,16 @@
this.dstIp = dstIp;
}
+ /**
+ * Matches are equal if all object variables are equal.
+ *
+ * @return true if equal, false otherwise
+ */
@Override
public boolean equals(Object obj) {
if (obj instanceof Match) {
Match other = (Match) obj;
+ //TODO: we might consider excluding sw from this comparison
if (this.sw != other.sw) {
return false;
}
@@ -69,6 +100,11 @@
}
}
+ /**
+ * Converts the Match into a legacy FlowEntryMatch object.
+ *
+ * @return an equivalent FlowEntryMatch object
+ */
public FlowEntryMatch getFlowEntryMatch() {
FlowEntryMatch match = new FlowEntryMatch();
if (srcMac != null) {
@@ -93,13 +129,25 @@
return match;
}
+ /**
+ * Returns a String representation of this Match.
+ *
+ * @return the match as a String
+ */
@Override
public String toString() {
return "Sw:" + sw + " (" + srcPort + "," + srcMac + "," + dstMac + "," + srcIp + "," + dstIp + ")";
}
+ /**
+ * Generates hash using Objects.hash() to hash all object variables.
+ *
+ * @return hashcode
+ */
@Override
public int hashCode() {
+ //TODO: we might consider excluding sw from the hash function
+ // to make it easier to compare matches between switches
return Objects.hash(sw, srcPort, srcMac, dstMac, srcIp, dstIp);
}
}