java_gen: cleanup / preparations for Match
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessage.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessage.java
index c1e4456..32319fa 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessage.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessage.java
@@ -1,6 +1,6 @@
package org.openflow.protocol;
-public interface OFMessage {
+public interface OFMessage extends OFObject {
int getXid();
OFType getType();
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessageWriter.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessageWriter.java
index 84e5507..bcca1fd 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessageWriter.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFMessageWriter.java
@@ -4,5 +4,5 @@
import org.openflow.exceptions.OFParseError;
public interface OFMessageWriter<T> {
- public int write(ChannelBuffer bb, T message) throws OFParseError;
+ public void write(ChannelBuffer bb, T message) throws OFParseError;
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFObject.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFObject.java
index 4a7557f..140182b 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/OFObject.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/OFObject.java
@@ -3,17 +3,15 @@
import org.jboss.netty.buffer.ChannelBuffer;
/**
- * Base interface of all OpenFlow objects (e.g., messages, actions, stats, etc.)
+ * Base interface of all OpenFlow objects (e.g., messages, actions, stats, etc.)
*
- * All objects have a length and can be read and written from a buffer.
- * When writing, the length field is dynamically updated, so it need not be
- * managed manually. However, you can override the auto calculated length with
- * overrideLength() call, if, for example, you want to intentionally create
- * malformed packets, for example, for negative testing.
+ * All objects have a length and can be read and written from a buffer. When
+ * writing, the length field is dynamically updated, so it need not be managed
+ * manually. However, you can override the auto calculated length with
+ * overrideLength() call, if, for example, you want to intentionally create
+ * malformed packets, for example, for negative testing.
*/
-
public interface OFObject {
void writeTo(ChannelBuffer bb);
- int getLength();
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/Wildcards.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/Wildcards.java
index 25b2c21..e1993f5 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/Wildcards.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/Wildcards.java
@@ -1,5 +1,656 @@
+/**
+ * Copyright 2013, Big Switch Networks, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ **/
+
package org.openflow.protocol;
-public class Wildcards {
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
-}
+import com.google.common.base.Joiner;
+
+/**
+ * a more user friendly representation of the wildcards bits in an OpenFlow
+ * match. The Wildcards object is
+ * <ul>
+ * <li>immutable (i.e., threadsafe)</li>
+ * <li>instance managed (don't instantiate it yourself), instead call "of"</li>
+ * <ul>
+ * <p>
+ * You can construct a Wildcard object from either its integer representation
+ * </p>
+ * <code>
+ * Wildcard.of(0x3820e0);
+ * </code>
+ * <p>
+ * Or start with either an empty or full wildcard, and select/unselect foo.
+ * </p>
+ * <code>
+ * Wildcard w = Wildcards.NONE
+ * .set(Flag.DL_SRC, Flag. DL_DST, Flag.DL_VLAN_PCP)
+ * .setNwDstMask(8)
+ * .setNwSrcMask(8);
+ * </code>
+ * <p>
+ * <b>Remember:</b> Wildcards objects are immutable. set... operations have
+ * <b>NO EFFECT</b> on the current wildcard object. You HAVE to use the returned
+ * changed object.
+ * </p>
+ *
+ * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
+ */
+public class Wildcards {
+ public class OFWildcardFlags {
+ final public static int OFPFW_ALL = ((1 << 22) - 1);
+
+ final public static int OFPFW_IN_PORT = 1 << 0; /* Switch input port. */
+ final public static int OFPFW_DL_VLAN = 1 << 1; /* VLAN id. */
+ final public static int OFPFW_DL_SRC = 1 << 2; /* Ethernet source address. */
+ final public static int OFPFW_DL_DST = 1 << 3; /*
+ * Ethernet destination
+ * address.
+ */
+ final public static int OFPFW_DL_TYPE = 1 << 4; /* Ethernet frame type. */
+ final public static int OFPFW_NW_PROTO = 1 << 5; /* IP protocol. */
+ final public static int OFPFW_TP_SRC = 1 << 6; /* TCP/UDP source port. */
+ final public static int OFPFW_TP_DST = 1 << 7; /* TCP/UDP destination port. */
+
+ /*
+ * IP source address wildcard bit count. 0 is exact match, 1 ignores the
+ * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
+ * the entire field. This is the *opposite* of the usual convention where
+ * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded.
+ */
+ final public static int OFPFW_NW_SRC_SHIFT = 8;
+ final public static int OFPFW_NW_SRC_BITS = 6;
+ final public static int OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT;
+ final public static int OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT;
+
+ /* IP destination address wildcard bit count. Same format as source. */
+ final public static int OFPFW_NW_DST_SHIFT = 14;
+ final public static int OFPFW_NW_DST_BITS = 6;
+ final public static int OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT;
+ final public static int OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT;
+
+ final public static int OFPFW_DL_VLAN_PCP = 1 << 20; /* VLAN priority. */
+ final public static int OFPFW_NW_TOS = 1 << 21; /*
+ * IP ToS (DSCP field, 6
+ * bits).
+ */
+
+ final public static int OFPFW_ALL_SANITIZED = (((1 << 22) - 1)
+ & ~OFPFW_NW_SRC_MASK & ~OFPFW_NW_DST_MASK)
+ | OFPFW_NW_SRC_ALL
+ | OFPFW_NW_DST_ALL;
+
+
+ }
+
+ public final static Wildcards FULL = new Wildcards(OFWildcardFlags.OFPFW_ALL_SANITIZED);
+ private static final int FULL_INT = FULL.getInt();
+
+ public final static Wildcards EXACT = new Wildcards(0);
+
+ // floodlight common case: matches on inport + l2
+ public final static int INT_INPORT_L2_MATCH = 0x3820e0;
+ public final static Wildcards INPORT_L2_MATCH = new Wildcards(
+ INT_INPORT_L2_MATCH);
+
+ /**
+ * enum type for the binary flags that can be set in the wildcards field of
+ * an OFWildcardFlags. Replaces the unwieldy c-ish int constants in OFWildcardFlags.
+ */
+ public static enum Flag {
+ IN_PORT(OFWildcardFlags.OFPFW_IN_PORT), /* Switch input port. */
+ DL_VLAN(OFWildcardFlags.OFPFW_DL_VLAN), /* VLAN id. */
+ DL_SRC(OFWildcardFlags.OFPFW_DL_SRC), /* Ethernet source address. */
+ DL_DST(OFWildcardFlags.OFPFW_DL_DST), /* Ethernet destination addr */
+ DL_TYPE(OFWildcardFlags.OFPFW_DL_TYPE), /* Ethernet frame type. */
+ NW_PROTO(OFWildcardFlags.OFPFW_NW_PROTO), /* IP protocol. */
+ TP_SRC(OFWildcardFlags.OFPFW_TP_SRC), /* TCP/UDP source port. */
+ TP_DST(OFWildcardFlags.OFPFW_TP_DST), /* TCP/UDP destination port. */
+ DL_VLAN_PCP(OFWildcardFlags.OFPFW_DL_VLAN_PCP), /* VLAN priority. */
+ NW_SRC(-1) { /*
+ * virtual NW_SRC flag => translates to the strange 6 bits
+ * in the header
+ */
+ @Override
+ boolean isBolean() {
+ return false;
+ }
+
+ @Override
+ int getInt(int flags) {
+ return ((flags & OFWildcardFlags.OFPFW_NW_SRC_MASK) >> OFWildcardFlags.OFPFW_NW_SRC_SHIFT);
+ }
+
+ @Override
+ int setInt(int flags, int srcMask) {
+ return (flags & ~OFWildcardFlags.OFPFW_NW_SRC_MASK) | (srcMask << OFWildcardFlags.OFPFW_NW_SRC_SHIFT);
+ }
+
+ @Override
+ int wildcard(int flags) {
+ return flags & ~OFWildcardFlags.OFPFW_NW_SRC_MASK;
+ }
+
+ @Override
+ int matchOn(int flags) {
+ return flags | OFWildcardFlags.OFPFW_NW_SRC_ALL;
+ }
+
+ @Override
+ boolean isPartiallyOn(int flags) {
+ int intValue = getInt(flags);
+ return intValue > 0 && intValue < 32;
+ }
+
+ @Override
+ boolean isFullyOn(int flags) {
+ return getInt(flags) >= 32;
+ }
+
+ },
+ NW_DST(-1) { /*
+ * virtual NW_SRC flag => translates to the strange 6 bits
+ * in the header
+ */
+ @Override
+ boolean isBolean() {
+ return false;
+ }
+
+ @Override
+ int getInt(int flags) {
+ return ((flags & OFWildcardFlags.OFPFW_NW_DST_MASK) >> OFWildcardFlags.OFPFW_NW_DST_SHIFT);
+ }
+
+ @Override
+ int setInt(int flags, int srcMask) {
+ return (flags & ~OFWildcardFlags.OFPFW_NW_DST_MASK) | (srcMask << OFWildcardFlags.OFPFW_NW_DST_SHIFT);
+ }
+
+ @Override
+ int wildcard(int flags) {
+ return flags & ~OFWildcardFlags.OFPFW_NW_DST_MASK;
+ }
+
+ @Override
+ int matchOn(int flags) {
+ return flags | OFWildcardFlags.OFPFW_NW_DST_ALL;
+ }
+
+ @Override
+ boolean isFullyOn(int flags) {
+ return getInt(flags) >= 32;
+ }
+ },
+ NW_TOS(OFWildcardFlags.OFPFW_NW_TOS); /* IP ToS (DSCP field, 6 bits). */
+
+ final int bitPosition;
+
+ Flag(int bitPosition) {
+ this.bitPosition = bitPosition;
+ }
+
+ /**
+ * @return a modified OF-1.0 flags field with this flag cleared (match
+ * on this field)
+ */
+ int matchOn(int flags) {
+ return flags & ~this.bitPosition;
+ }
+
+ /**
+ * @return a modified OF-1.0 flags field with this flag set (wildcard
+ * this field)
+ */
+ int wildcard(int flags) {
+ return flags | this.bitPosition;
+ }
+
+ /**
+ * @return true iff this is a true boolean flag that can either be off
+ * or on.True in OF-1.0 for all fields except NW_SRC and NW_DST
+ */
+ boolean isBolean() {
+ return false;
+ }
+
+ /**
+ * @return true iff this wildcard field is currently 'partially on'.
+ * Always false for true Boolean Flags. Can be true in OF-1.0
+ * for NW_SRC, NW_DST.
+ */
+ boolean isPartiallyOn(int flags) {
+ return false;
+ }
+
+ /**
+ * @return true iff this wildcard field currently fully on (fully
+ * wildcarded). Equivalent to the boolean flag being set in the
+ * bitmask for bit flags, and to the wildcarded bit length set
+ * to >=32 for NW_SRC and NW_DST
+ * @param flags
+ * @return
+ */
+ boolean isFullyOn(int flags) {
+ return (flags & this.bitPosition) != 0;
+ }
+
+ /**
+ * set the integer representation of this flag. only for NW_SRC and
+ * NW_DST
+ */
+ int setInt(int flags, int srcMask) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * set the integer representation of this flag. only for NW_SRC and
+ * NW_DST
+ */
+ int getInt(int flags) {
+ throw new UnsupportedOperationException();
+ }
+
+
+ }
+
+ private final int flags;
+
+ /** private constructor. use Wildcard.of() instead */
+ private Wildcards(int flags) {
+ this.flags = flags;
+ }
+
+ /**
+ * return a wildcard object matching the given int flags. May reuse / cache
+ * frequently used wildcard instances. Don't rely on it though (use equals
+ * not ==).
+ *
+ * @param flags
+ * @return
+ */
+ public static Wildcards of(int paramFlags) {
+ int flags = sanitizeInt(paramFlags);
+ switch(flags) {
+ case 0x0000:
+ return EXACT;
+ case OFWildcardFlags.OFPFW_ALL_SANITIZED:
+ return FULL;
+ case INT_INPORT_L2_MATCH:
+ return INPORT_L2_MATCH;
+ default:
+ return new Wildcards(flags);
+ }
+ }
+
+ /** convience method return a wildcard for exactly one set flag */
+ public static Wildcards of(Wildcards.Flag setFlag) {
+ return Wildcards.of(setFlag.wildcard(0));
+ }
+
+ /** convience method return a wildcard for exactly two set flags */
+ public static Wildcards of(Wildcards.Flag setFlag, Wildcards.Flag setFlag2) {
+ return Wildcards.of(setFlag.wildcard(setFlag2.wildcard(0)));
+ }
+
+ /** convience method return a wildcard for an arbitrary number of set flags */
+ public static Wildcards of(Wildcards.Flag... setFlags) {
+ int flags = 0;
+ for (Wildcards.Flag flag : setFlags)
+ flags = flag.wildcard(0);
+ return Wildcards.of(flags);
+ }
+
+ /** convience method return a wildcards for ofmatches that match on one flag */
+ public static Wildcards ofMatches(Wildcards.Flag setFlag) {
+ return Wildcards.of(setFlag.matchOn(FULL_INT));
+ }
+
+ /**
+ * convience method return a wildcard for for an ofmatch that match on two
+ * flags
+ */
+ public static Wildcards ofMatches(Wildcards.Flag setFlag, Wildcards.Flag setFlag2) {
+ return Wildcards.of(setFlag.matchOn(setFlag2.matchOn(FULL_INT)));
+ }
+
+ /**
+ * convience method return a wildcard for an ofmatch that amtch on an
+ * arbitrary number of set flags
+ */
+ public static Wildcards ofMatches(Wildcards.Flag... setFlags) {
+ int flags = FULL_INT;
+ for (Wildcards.Flag flag : setFlags)
+ flags = flag.matchOn(flags);
+ return Wildcards.of(flags);
+ }
+
+ public static Wildcards ofMatches(Set<Wildcards.Flag> wSet) {
+ int flags = FULL_INT;
+ for (Wildcards.Flag flag : wSet)
+ flags = flag.matchOn(flags);
+ return Wildcards.of(flags);
+ }
+
+ /**
+ * return a Wildcards object that has the given flags set
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards wildcard(Wildcards.Flag flag) {
+ int flags = flag.wildcard(this.flags);
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcards object that has the given flags set
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards wildcard(Wildcards.Flag flag, Wildcards.Flag flag2) {
+ int flags = flag.wildcard(flag2.wildcard(this.flags));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcards object that has the given flags wildcarded
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards wildcard(Wildcards.Flag... setFlags) {
+ int flags = this.flags;
+ for (Wildcards.Flag flag : setFlags)
+ flags = flag.wildcard(flags);
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcards object that matches on exactly the given flag
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards matchOn(Wildcards.Flag flag) {
+ int flags = flag.matchOn(this.flags);
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcards object that matches on exactly the given flags
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards matchOn(Wildcards.Flag flag, Wildcards.Flag flag2) {
+ int flags = flag.matchOn(flag2.matchOn(this.flags));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcards object that matches on exactly the given flags
+ * <p>
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ */
+ public Wildcards matchOn(Wildcards.Flag... setFlags) {
+ int flags = this.flags;
+ for (Wildcards.Flag flag : setFlags)
+ flags = flag.matchOn(flags);
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return the nw src mask in normal CIDR style, e.g., 8 means x.x.x.x/8
+ * means 8 bits wildcarded
+ */
+ public int getNwSrcMask() {
+ return Math.max(0, 32 - Flag.NW_SRC.getInt(flags));
+ }
+
+ /**
+ * return the nw dst mask in normal CIDR style, e.g., 8 means x.x.x.x/8
+ * means 8 bits wildcarded
+ */
+ public int getNwDstMask() {
+ return Math.max(0, 32 - Flag.NW_DST.getInt(flags));
+ }
+
+ /**
+ * return a Wildcard object that has the given nwSrcCidrMask set.
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ *
+ * @param srcCidrMask
+ * source mask to set in <b>normal CIDR notation</b>, i.e., 8
+ * means x.x.x.x/8
+ * @return a modified object
+ */
+ public Wildcards withNwSrcMask(int srcCidrMask) {
+ int flags = Flag.NW_SRC.setInt(this.flags, Math.max(0, 32 - srcCidrMask));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcard object that has the given nwDstCidrMask set.
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ *
+ * @param dstCidrMask
+ * dest mask to set in <b>normal CIDR notation</b>, i.e., 8 means
+ * x.x.x.x/8
+ * @return a modified object
+ */
+ public Wildcards withNwDstMask(int dstCidrMask) {
+ int flags = Flag.NW_DST.setInt(this.flags, Math.max(0, 32 - dstCidrMask));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcard object that is inverted to this wildcard object.
+ * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
+ * unmodified. </b>
+ * @return a modified object
+ */
+ public Wildcards inverted() {
+ return Wildcards.of(flags ^ OFWildcardFlags.OFPFW_ALL_SANITIZED);
+ }
+
+ public boolean isWildcarded(Flag flag) {
+ return flag.isFullyOn(flags);
+ }
+
+ /**
+ * return all wildcard flags that are fully wildcarded as an EnumSet. Do not
+ * modify. Note: some flags (like NW_SRC and NW_DST) that are partially
+ * wildcarded are not returned in this set.
+ *
+ * @return the EnumSet of wildcards
+ */
+ public EnumSet<Wildcards.Flag> getWildcardedFlags() {
+ EnumSet<Wildcards.Flag> res = EnumSet.noneOf(Wildcards.Flag.class);
+ for (Wildcards.Flag flag : Flag.values()) {
+ if (flag.isFullyOn(flags)) {
+ res.add(flag);
+ }
+ }
+ return res;
+ }
+
+ /** return the OpenFlow 'wire' integer representation of these wildcards */
+ public int getInt() {
+ return flags;
+ }
+
+ /**
+ * return the OpenFlow 'wire' integer representation of these wildcards.
+ * Sanitize nw_src and nw_dst to be max. 32 (values > 32 are technically
+ * possible, but don't make semantic sense)
+ */
+ public static int sanitizeInt(int flags) {
+ if (((flags & OFWildcardFlags.OFPFW_NW_SRC_MASK) >> OFWildcardFlags.OFPFW_NW_SRC_SHIFT) > 32) {
+ flags = (flags & ~OFWildcardFlags.OFPFW_NW_SRC_MASK) | OFWildcardFlags.OFPFW_NW_SRC_ALL;
+ }
+ if (((flags & OFWildcardFlags.OFPFW_NW_DST_MASK) >> OFWildcardFlags.OFPFW_NW_DST_SHIFT) > 32) {
+ flags = (flags & ~OFWildcardFlags.OFPFW_NW_DST_MASK) | OFWildcardFlags.OFPFW_NW_DST_ALL;
+ }
+ return flags;
+ }
+
+ /**
+ * is this a wildcard set that has all flags set + and full (/0) nw_src and
+ * nw_dst wildcarding ?
+ */
+ public boolean isFull() {
+ return flags == OFWildcardFlags.OFPFW_ALL || flags == OFWildcardFlags.OFPFW_ALL_SANITIZED;
+ }
+
+ /** is this a wildcard of an exact match */
+ public boolean isExact() {
+ return flags == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + flags;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Wildcards other = (Wildcards) obj;
+ if (flags != other.flags)
+ return false;
+ return true;
+ }
+
+ private final static Joiner pipeJoiner = Joiner.on("|");
+
+ @Override
+ public String toString() {
+ List<String> res = new ArrayList<String>();
+ for (Wildcards.Flag flag : Flag.values()) {
+ if (flag.isFullyOn(flags)) {
+ res.add(flag.name().toLowerCase());
+ }
+ }
+
+ if (Flag.NW_SRC.isPartiallyOn(flags)) {
+ res.add("nw_src(/" + getNwSrcMask() + ")");
+ }
+
+ if (Flag.NW_DST.isPartiallyOn(flags)) {
+ res.add("nw_dst(/" + getNwDstMask() + ")");
+ }
+
+ return pipeJoiner.join(res);
+ }
+
+ private final static Joiner commaJoiner = Joiner.on(", ");
+
+ /** a Java expression that constructs 'this' wildcards set */
+ public String toJava() {
+ if(isFull()) {
+ return "Wildcards.FULL";
+ } else if (isExact()){
+ return "Wildcards.EXACT";
+ }
+
+ StringBuilder b = new StringBuilder();
+
+ EnumSet<Flag> myFlags = getWildcardedFlags();
+ if (myFlags.size() < 3) {
+ // default to start with empty
+ b.append("Wildcards.of("
+ + commaJoiner.join(prefix("Flag.", myFlags.iterator())) + ")");
+ } else {
+ // too many - start with full
+
+ EnumSet<Flag> invFlags = inverted().getWildcardedFlags();
+ b.append("Wildcards.ofMatches("
+ + commaJoiner.join(prefix("Flag.", invFlags.iterator())) + ")");
+ }
+ if (Flag.NW_SRC.isPartiallyOn(flags)) {
+ b.append(".setNwSrcMask(" + getNwSrcMask() + ")");
+ }
+ if (Flag.NW_DST.isPartiallyOn(flags)) {
+ b.append(".setNwDstMask(" + getNwDstMask() + ")");
+ }
+ return b.toString();
+ }
+
+ private Iterator<String> prefix(final String prefix, final Iterator<?> i) {
+ return new Iterator<String>() {
+
+ @Override
+ public boolean hasNext() {
+ return i.hasNext();
+ }
+
+ @Override
+ public String next() {
+ Object next = i.next();
+ return next == null ? null : prefix + next.toString();
+ }
+
+ @Override
+ public void remove() {
+ i.remove();
+ }
+ };
+ }
+
+
+}
\ No newline at end of file
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/Match.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/Match.java
index 99b7de4..d35f709 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/Match.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/Match.java
@@ -5,23 +5,23 @@
import org.openflow.types.OFValueType;
public interface Match extends OFObject {
-
+
/*
* Preconditions
- * On preconditions (from the OF1.1 spec, page 28, the OF1.0 spec failed to explicitly
+ * On preconditions (from the OF1.1 spec, page 28, the OF1.0 spec failed to explicitly
* specify this, but it is the behavior of Of1.0 switches):
- * Protocol-specific fields within ofp_match will be ignored within a single table when
- * the corresponding protocol is not specified in the match. The MPLS match fields will
- * be ignored unless the Ethertype is specified as MPLS. Likewise, the IP header and
- * transport header fields will be ignored unless the Ethertype is specified as either
- * IPv4 or ARP. The tp_src and tp_dst fields will be ignored unless the network protocol
- * specified is as TCP, UDP or SCTP. Fields that are ignored donÕt need to be wildcarded
+ * Protocol-specific fields within ofp_match will be ignored within a single table when
+ * the corresponding protocol is not specified in the match. The MPLS match fields will
+ * be ignored unless the Ethertype is specified as MPLS. Likewise, the IP header and
+ * transport header fields will be ignored unless the Ethertype is specified as either
+ * IPv4 or ARP. The tp_src and tp_dst fields will be ignored unless the network protocol
+ * specified is as TCP, UDP or SCTP. Fields that are ignored don�t need to be wildcarded
* and should be set to 0.
*/
-
+
/**
* Returns the value for the given field from this match.
- *
+ *
* @param field Match field to retrieve
* @return Value of match field
*/
@@ -30,7 +30,7 @@
/**
* Returns the masked value for the given field from this match.
* Precondition: field is partially wildcarded.
- *
+ *
* @param field Match field to retrieve
* @return Masked value of match field or null if no mask
*/
@@ -38,44 +38,44 @@
/**
* Returns true if this match object supports the given match field.
- *
+ *
* @param field Match field
- * @return
+ * @return
*/
public boolean supports(MatchField<?> field);
/**
- * true iff field supports a bitmask mask that wildcards part of the field
+ * true iff field supports a bitmask mask that wildcards part of the field
* (note: not all possible values of this bitmask have to be acceptable)
- *
+ *
* @param field Match field
- * @return
+ * @return
*/
public boolean supportsMasked(MatchField<?> field);
/**
- * True iff this field is currently fully specified in the match, i.e., the
+ * True iff this field is currently fully specified in the match, i.e., the
* match will only select packets that match the exact value of getField(field).
- *
+ *
* @param field Match field
- * @return
+ * @return
*/
public boolean isExact(MatchField<?> field);
/**
- * True if this field is currently logically unspecified in the match, i.e, the
- * value returned by getValue(f) has no impact on whether a packet will be selected
+ * True if this field is currently logically unspecified in the match, i.e, the
+ * value returned by getValue(f) has no impact on whether a packet will be selected
* by the match or not.
- *
+ *
* @param field
* @return
*/
public boolean isFullyWildcarded(MatchField<?> field);
/**
- * True if this field is currently partially specified in the match, i.e, the
+ * True if this field is currently partially specified in the match, i.e, the
* match will select packets that match (p.value & getMask(field)) == getValue(field).
- *
+ *
* @param field
* @return
*/
@@ -85,5 +85,8 @@
* Returns a builder to build new instances of this type of match object.
* @return Match builder
*/
- public MatchBuilder getBuilder();
+ public MatchBuilder createBuilder();
+
+ interface Builder extends MatchBuilder {
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilder.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilder.java
index 4372e30..be7b8b0 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilder.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilder.java
@@ -3,14 +3,77 @@
import org.openflow.types.Masked;
import org.openflow.types.OFValueType;
-public interface MatchBuilder extends Match {
- public <F extends OFValueType<F>> MatchBuilder setExact(MatchField<F> field, F value);
-
- public <F extends OFValueType<F>> MatchBuilder setMasked(MatchField<F> field, F value, F mask);
+public interface MatchBuilder {
+ /**
+ * Returns the value for the given field from this match.
+ *
+ * @param field Match field to retrieve
+ * @return Value of match field
+ */
+ public <F extends OFValueType<F>> F get(MatchField<F> field) throws UnsupportedOperationException;
- public <F extends OFValueType<F>> MatchBuilder setMasked(MatchField<F> field, Masked<F> valueWithMask);
+ /**
+ * Returns the masked value for the given field from this match.
+ * Precondition: field is partially wildcarded.
+ *
+ * @param field Match field to retrieve
+ * @return Masked value of match field or null if no mask
+ */
+ public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field) throws UnsupportedOperationException;
+
+ /**
+ * Returns true if this match object supports the given match field.
+ *
+ * @param field Match field
+ * @return
+ */
+ public boolean supports(MatchField<?> field);
+
+ /**
+ * true iff field supports a bitmask mask that wildcards part of the field
+ * (note: not all possible values of this bitmask have to be acceptable)
+ *
+ * @param field Match field
+ * @return
+ */
+ public boolean supportsMasked(MatchField<?> field);
+
+ /**
+ * True iff this field is currently fully specified in the match, i.e., the
+ * match will only select packets that match the exact value of getField(field).
+ *
+ * @param field Match field
+ * @return
+ */
+ public boolean isExact(MatchField<?> field);
+
+ /**
+ * True if this field is currently logically unspecified in the match, i.e, the
+ * value returned by getValue(f) has no impact on whether a packet will be selected
+ * by the match or not.
+ *
+ * @param field
+ * @return
+ */
+ public boolean isFullyWildcarded(MatchField<?> field);
+
+ /**
+ * True if this field is currently partially specified in the match, i.e, the
+ * match will select packets that match (p.value & getMask(field)) == getValue(field).
+ *
+ * @param field
+ * @return
+ */
+ public boolean isPartiallyMasked(MatchField<?> field);
+
+
+ public <F extends OFValueType<F>> MatchBuilder setExact(MatchField<F> field, F value);
+
+ public <F extends OFValueType<F>> MatchBuilder setMasked(MatchField<F> field, F value, F mask);
+
+ public <F extends OFValueType<F>> MatchBuilder setMasked(MatchField<F> field, Masked<F> valueWithMask);
public <F extends OFValueType<F>> MatchBuilder wildcard(MatchField<F> field);
-
+
public Match getMatch();
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilderVer10.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilderVer10.java
deleted file mode 100644
index 62c77e5..0000000
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchBuilderVer10.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package org.openflow.protocol.match;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.types.EthType;
-import org.openflow.types.IPv4;
-import org.openflow.types.IpDscp;
-import org.openflow.types.IpProtocol;
-import org.openflow.types.MacAddress;
-import org.openflow.types.Masked;
-import org.openflow.types.OFPort;
-import org.openflow.types.OFValueType;
-import org.openflow.types.U16;
-import org.openflow.types.VlanPcp;
-import org.openflow.types.VlanVid;
-
-public class MatchBuilderVer10 implements MatchBuilder {
-
- interface BuilderParamHandler<T> {
- public T get(MatchBuilderVer10 builder);
-
- public void set(MatchBuilderVer10 builder, T value);
- }
-
- // public static Map<MatchField<?,?>, BuilderParamHandler<?>>
- // handlerMap = new HashMap();
-
- protected int wildcards;
- protected OFPort inputPort;
- protected MacAddress dataLayerSource;
- protected MacAddress dataLayerDestination;
- protected VlanVid dataLayerVirtualLan;
- protected VlanPcp dataLayerVirtualLanPriorityCodePoint;
- protected EthType dataLayerType;
- protected IpDscp ipDscp;
- protected IpProtocol networkProtocol;
- protected IPv4 networkSource;
- protected IPv4 networkDestination;
- protected U16 transportSource;
- protected U16 transportDestination;
-
- @SuppressWarnings("unchecked")
- @Override
- public <F extends OFValueType<F>> F get(final MatchField<F> match) {
- switch (match.id) {
- case IN_PORT:
- return (F) inputPort;
- case ETH_SRC:
- return (F) dataLayerSource;
- default:
- return null;
- }
- }
-
- @Override
- public <F extends OFValueType<F>> Masked<F>
- getMasked(MatchField<F> field)
- throws UnsupportedOperationException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public <F extends OFValueType<F>> MatchBuilder setExact(final MatchField<F> match, final F value) {
- switch (match.id) {
- case IN_PORT:
- inputPort = (OFPort) value;
- break;
- case ETH_SRC:
- dataLayerSource = (MacAddress) value;
- break;
- default:
- break;
- }
- return this;
- }
-
- @Override
- public <F extends OFValueType<F>> MatchBuilder
- setMasked(MatchField<F> field, Masked<F> valueWithMask) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public <F extends OFValueType<F>> MatchBuilder
- setMasked(MatchField<F> field, F value, F mask) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public <F extends OFValueType<F>> MatchBuilder wildcard(final MatchField<F> match) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public OFPort getInputPort() {
- return inputPort;
- }
-
- public void setInputPort(final OFPort inputPort) {
- this.inputPort = inputPort;
- }
-
- public MacAddress getDataLayerSource() {
- return dataLayerSource;
- }
-
- public void setDataLayerSource(final MacAddress dataLayerSource) {
- this.dataLayerSource = dataLayerSource;
- }
-
- @Override
- public boolean supports(final MatchField<?> field) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean supportsMasked(final MatchField<?> field) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isExact(final MatchField<?> field) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isFullyWildcarded(final MatchField<?> field) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isPartiallyMasked(final MatchField<?> field) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public MatchBuilder getBuilder() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public int getLength() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void writeTo(final ChannelBuffer bb) {
- // TODO Auto-generated method stub
-
- }
-/*
- @Override
- public <M> void setMasked(final MatchField<?, M> match, final M value) {
- // TODO Auto-generated method stub
-
- }
-*/
- @Override
- public Match getMatch() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}