Changes required to adopt new loxi APIs into legacy OFMatch:
1. Added value getters to new value types
2. Changed Match, MatchBuilder interfaces according to new desing
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 fa42737..3ff65ab 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
@@ -4,17 +4,76 @@
import org.openflow.types.OFValueType;
public interface Match extends OFObject {
- public <F extends OFValueType> F get(MatchField<F> match);
+
+ /*
+ * Preconditions
+ * 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
+ * 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
+ */
+ public <F extends OFValueType<F>> F get(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);
+ /**
+ * Returns a builder to build new instances of this type of match object.
+ * @return Match builder
+ */
public MatchBuilder getBuilder();
}
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 3c601f8..fc4c07a 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,8 +3,10 @@
import org.openflow.types.OFValueType;
public interface MatchBuilder extends Match {
- public <F extends OFValueType> MatchBuilder set(MatchField<F> match, F value);
+ public <F extends OFValueType<F>> MatchBuilder set(MatchField<F> field, F value);
+ public <F extends OFValueType<F>> MatchBuilder unset(MatchField<F> field);
+
//public <M> void setMasked(MatchField<?, M> match, M value);
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
index 0fbe84b..1c91201 100644
--- 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
@@ -22,33 +22,6 @@
// public static Map<MatchField<?,?>, BuilderParamHandler<?>>
// handlerMap = new HashMap();
- static BuilderParamHandler<?>[] handlers = new BuilderParamHandler<?>[2];
-
- static {
- handlers[MatchField.IN_PORT.id] = new BuilderParamHandler<OFPort>() {
- @Override
- public void set(final MatchBuilderVer10 builder, final OFPort value) {
- builder.inputPort = value;
- }
-
- @Override
- public OFPort get(final MatchBuilderVer10 builder) {
- return builder.inputPort;
- }
- };
-
- handlers[MatchField.ETH_SRC.id] = new BuilderParamHandler<MacAddress>() {
- @Override
- public void set(final MatchBuilderVer10 builder, final MacAddress value) {
- builder.dataLayerSource = value;
- }
-
- @Override
- public MacAddress get(final MatchBuilderVer10 builder) {
- return builder.dataLayerSource;
- }
- };
- }
protected int wildcards;
protected OFPort inputPort;
@@ -66,30 +39,37 @@
@SuppressWarnings("unchecked")
@Override
- public <F extends OFValueType> F get(final MatchField<F> match) {
+ public <F extends OFValueType<F>> F get(final MatchField<F> match) {
switch (match.id) {
- case 0:
+ case IN_PORT:
return (F) inputPort;
- case 1:
+ case ETH_SRC:
return (F) dataLayerSource;
default:
return null;
}
}
- @SuppressWarnings("unchecked")
@Override
- public <F extends OFValueType> MatchBuilder set(final MatchField<F> match, final F value) {
+ public <F extends OFValueType<F>> MatchBuilder set(final MatchField<F> match, final F value) {
switch (match.id) {
- case 0:
+ case IN_PORT:
inputPort = (OFPort) value;
break;
- case 1:
+ case ETH_SRC:
dataLayerSource = (MacAddress) value;
break;
+ default:
+ break;
}
return this;
}
+
+ @Override
+ public <F extends OFValueType<F>> MatchBuilder unset(final MatchField<F> match) {
+ // TODO Auto-generated method stub
+ return null;
+ }
public OFPort getInputPort() {
return inputPort;
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
index d9d68ec..071eaa0 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchField.java
@@ -4,9 +4,9 @@
import org.openflow.types.EthType;
import org.openflow.types.ICMPv4Code;
import org.openflow.types.ICMPv4Type;
-import org.openflow.types.IPv4WithMask;
+import org.openflow.types.IPv4;
+import org.openflow.types.IPv6;
import org.openflow.types.IPv6FlowLabel;
-import org.openflow.types.IPv6WithMask;
import org.openflow.types.IpDscp;
import org.openflow.types.IpEcn;
import org.openflow.types.IpProtocol;
@@ -18,91 +18,86 @@
import org.openflow.types.VlanPcp;
import org.openflow.types.VlanVid;
-public class MatchField<F extends OFValueType> {
+public class MatchField<F extends OFValueType<F>> {
private final String name;
- public final int id;
+ public final MatchFields id;
- public MatchField(final String name) {
- this.name = name;
- this.id = -1;
- }
-
- public MatchField(final String name, final int id) {
+ private MatchField(final String name, final MatchFields id) {
this.name = name;
this.id = id;
}
public final static MatchField<OFPort> IN_PORT =
- new MatchField<OFPort>("in_port", 0);
+ new MatchField<OFPort>("in_port", MatchFields.IN_PORT);
public final static MatchField<OFPort> IN_PHY_PORT =
- new MatchField<OFPort>("in_phy_port");
+ new MatchField<OFPort>("in_phy_port", MatchFields.PHYSICAL_PORT);
public final static MatchField<OFPort> METADATA =
- new MatchField<OFPort>("metadata");
+ new MatchField<OFPort>("metadata", MatchFields.METADATA);
public final static MatchField<Masked<MacAddress>> ETH_DST =
- new MatchField<Masked<MacAddress>>("eth_dst");
+ new MatchField<Masked<MacAddress>>("eth_dst", MatchFields.ETH_DST);
public final static MatchField<Masked<MacAddress>> ETH_SRC =
- new MatchField<Masked<MacAddress>>("eth_src", 1);
+ new MatchField<Masked<MacAddress>>("eth_src", MatchFields.ETH_SRC);
public final static MatchField<EthType> ETH_TYPE =
- new MatchField<EthType>("eth_type");
+ new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE);
public final static MatchField<Masked<VlanVid>> VLAN_VID =
- new MatchField<Masked<VlanVid>>("vlan_vid");
+ new MatchField<Masked<VlanVid>>("vlan_vid", MatchFields.VLAN_VID);
public final static MatchField<VlanPcp> VLAN_PCP =
- new MatchField<VlanPcp>("vlan_pcp");
+ new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP);
public final static MatchField<IpDscp> IP_DSCP =
- new MatchField<IpDscp>("ip_dscp");
+ new MatchField<IpDscp>("ip_dscp", MatchFields.IP_DSCP);
public final static MatchField<IpEcn> IP_ECN =
- new MatchField<IpEcn>("ip_dscp");
+ new MatchField<IpEcn>("ip_dscp", MatchFields.IP_ECN);
public final static MatchField<IpProtocol> IP_PROTO =
- new MatchField<IpProtocol>("ip_proto");
+ new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO);
- public final static MatchField<IPv4WithMask> IPV4_SRC =
- new MatchField<IPv4WithMask>("ipv4_src");
- public final static MatchField<IPv4WithMask> IPV4_DST =
- new MatchField<IPv4WithMask>("ipv4_dst");
+ public final static MatchField<Masked<IPv4>> IPV4_SRC =
+ new MatchField<Masked<IPv4>>("ipv4_src", MatchFields.IPV4_SRC);
+ public final static MatchField<Masked<IPv4>> IPV4_DST =
+ new MatchField<Masked<IPv4>>("ipv4_dst", MatchFields.IPV4_DST);
public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>(
- "tcp_src");
+ "tcp_src", MatchFields.TCP_SRC);
public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>(
- "tcp_dst");
+ "tcp_dst", MatchFields.TCP_DST);
public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>(
- "udp_src");
+ "udp_src", MatchFields.UDP_SRC);
public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>(
- "udp_dst");
+ "udp_dst", MatchFields.UDP_DST);
public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>(
- "sctp_src");
+ "sctp_src", MatchFields.SCTP_SRC);
public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>(
- "sctp_dst");
+ "sctp_dst", MatchFields.SCTP_DST);
public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>(
- "icmpv4_src");
+ "icmpv4_src", MatchFields.ICMPV4_TYPE);
public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>(
- "icmpv4_dst");
+ "icmpv4_dst", MatchFields.ICMPV4_CODE);
public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>(
- "arp_op");
- public final static MatchField<IPv4WithMask> ARP_SPA =
- new MatchField<IPv4WithMask>("arp_spa");
- public final static MatchField<IPv4WithMask> ARP_TPA =
- new MatchField<IPv4WithMask>("arp_tpa");
+ "arp_op", MatchFields.ARP_OP);
+ public final static MatchField<Masked<IPv4>> ARP_SPA =
+ new MatchField<Masked<IPv4>>("arp_spa", MatchFields.ARP_SPA);
+ public final static MatchField<Masked<IPv4>> ARP_TPA =
+ new MatchField<Masked<IPv4>>("arp_tpa", MatchFields.ARP_TPA);
public final static MatchField<Masked<MacAddress>> ARP_SHA =
- new MatchField<Masked<MacAddress>>("arp_sha");
+ new MatchField<Masked<MacAddress>>("arp_sha", MatchFields.ARP_SHA);
public final static MatchField<Masked<MacAddress>> ARP_THA =
- new MatchField<Masked<MacAddress>>("arp_tha");
+ new MatchField<Masked<MacAddress>>("arp_tha", MatchFields.ARP_THA);
- public final static MatchField<IPv6WithMask> IPV6_SRC =
- new MatchField<IPv6WithMask>("ipv6_src");
- public final static MatchField<IPv6WithMask> IPV6_DST =
- new MatchField<IPv6WithMask>("ipv6_dst");
+ public final static MatchField<Masked<IPv6>> IPV6_SRC =
+ new MatchField<Masked<IPv6>>("ipv6_src", MatchFields.IPV6_SRC);
+ public final static MatchField<Masked<IPv6>> IPV6_DST =
+ new MatchField<Masked<IPv6>>("ipv6_dst", MatchFields.IPV6_DST);
public final static MatchField<Masked<IPv6FlowLabel>> IPV6_FLABEL =
- new MatchField<Masked<IPv6FlowLabel>>("ipv6_flabel");
+ new MatchField<Masked<IPv6FlowLabel>>("ipv6_flabel", MatchFields.IPV6_FLOWLABEL);
public String getName() {
return name;
diff --git a/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchFields.java b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchFields.java
new file mode 100644
index 0000000..21043f2
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/openflow/protocol/match/MatchFields.java
@@ -0,0 +1,33 @@
+package org.openflow.protocol.match;
+
+public enum MatchFields {
+ IN_PORT,
+ PHYSICAL_PORT,
+ METADATA,
+ ETH_DST,
+ ETH_SRC,
+ ETH_TYPE,
+ VLAN_VID,
+ VLAN_PCP,
+ IP_DSCP,
+ IP_ECN,
+ IP_PROTO,
+ IPV4_SRC,
+ IPV4_DST,
+ TCP_SRC,
+ TCP_DST,
+ UDP_SRC,
+ UDP_DST,
+ SCTP_SRC,
+ SCTP_DST,
+ ICMPV4_TYPE,
+ ICMPV4_CODE,
+ ARP_OP,
+ ARP_SPA,
+ ARP_TPA,
+ ARP_SHA,
+ ARP_THA,
+ IPV6_SRC,
+ IPV6_DST,
+ IPV6_FLOWLABEL,
+}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/ArpOpcode.java b/java_gen/pre-written/src/main/java/org/openflow/types/ArpOpcode.java
index 852aa20..6ebf447 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/ArpOpcode.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/ArpOpcode.java
@@ -2,7 +2,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
-public class ArpOpcode implements OFValueType {
+public class ArpOpcode implements OFValueType<ArpOpcode> {
final static int LENGTH = 2;
@@ -142,4 +142,14 @@
public static ArpOpcode read2Bytes(ChannelBuffer c) {
return ArpOpcode.of(c.readUnsignedShort());
}
+
+ @Override
+ public ArpOpcode applyMask(ArpOpcode mask) {
+ return ArpOpcode.of(this.opcode & mask.opcode);
+ }
+
+ public int getOpCode() {
+ return opcode;
+ }
+
}
\ No newline at end of file
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java b/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
index f0f0a2c..ea16e67 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/EthType.java
@@ -8,7 +8,7 @@
*
* @author Yotam Harchol (yotam.harchol@bigswitch.com)
*/
-public class EthType implements OFValueType {
+public class EthType implements OFValueType<EthType> {
static final int LENGTH = 2;
private final int rawValue;
@@ -235,4 +235,14 @@
return EthType.of(c.readUnsignedShort());
}
+ @Override
+ public EthType applyMask(EthType mask) {
+ return EthType.of(this.rawValue & mask.rawValue);
+ }
+
+ public int getValue() {
+ return rawValue;
+ }
+
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Code.java b/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Code.java
index 147b5f7..42cc5be 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Code.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Code.java
@@ -7,7 +7,7 @@
* @author Yotam Harchol (yotam.harchol@bigswitch.com)
*
*/
-public class ICMPv4Code implements OFValueType {
+public class ICMPv4Code implements OFValueType<ICMPv4Code> {
final static int LENGTH = 1;
final static short MAX_CODE = 0xFF;
@@ -41,4 +41,10 @@
return ICMPv4Code.of(c.readUnsignedByte());
}
+ @Override
+ public ICMPv4Code applyMask(ICMPv4Code mask) {
+ return ICMPv4Code.of((short)(this.code & mask.code));
+ }
+
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Type.java b/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Type.java
index 01d6e8f..b1bbdc0 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Type.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/ICMPv4Type.java
@@ -2,7 +2,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
-public class ICMPv4Type implements OFValueType {
+public class ICMPv4Type implements OFValueType<ICMPv4Type> {
final static int LENGTH = 1;
@@ -155,4 +155,10 @@
return ICMPv4Type.of(c.readUnsignedByte());
}
+ @Override
+ public ICMPv4Type applyMask(ICMPv4Type mask) {
+ return ICMPv4Type.of((short)(this.type & mask.type));
+ }
+
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
index 78b8dd2..f89f683 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4.java
@@ -9,7 +9,7 @@
*
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
-public class IPv4 implements OFValueType {
+public class IPv4 implements OFValueType<IPv4> {
static final int LENGTH = 4;
private final int rawValue;
@@ -122,5 +122,11 @@
public static IPv4 read4Bytes(ChannelBuffer c) {
return IPv4.of(c.readInt());
}
+
+ @Override
+ public IPv4 applyMask(IPv4 mask) {
+ return IPv4.of(this.rawValue & mask.rawValue);
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java
index afb89ed..c24c4fd 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv4WithMask.java
@@ -36,7 +36,7 @@
return res.toString();
}
- public static OFValueType ofPossiblyMasked(final String string) {
+ public static OFValueType<?> ofPossiblyMasked(final String string) {
int slashPos;
String ip = string;
int maskBits = 0;
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
index e3166fd..200a33d 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6.java
@@ -11,7 +11,7 @@
*
* @author Andreas Wundsam <andreas.wundsam@teleteach.de>
*/
-public class IPv6 implements OFValueType {
+public class IPv6 implements OFValueType<IPv6> {
static final int LENGTH = 16;
private final long raw1;
private final long raw2;
@@ -278,4 +278,9 @@
public static IPv6 read16Bytes(ChannelBuffer c) throws OFParseError {
return IPv6.of(c.readLong(), c.readLong());
}
+
+ @Override
+ public IPv6 applyMask(IPv6 mask) {
+ return IPv6.of(this.raw1 & mask.raw1, this.raw2 & mask.raw2);
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6FlowLabel.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6FlowLabel.java
index 6d9bfb5..d49e4e2 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6FlowLabel.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6FlowLabel.java
@@ -3,7 +3,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-public class IPv6FlowLabel implements OFValueType {
+public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> {
static final int LENGTH = 4;
@@ -53,4 +53,12 @@
return IPv6FlowLabel.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
}
+ @Override
+ public IPv6FlowLabel applyMask(IPv6FlowLabel mask) {
+ return IPv6FlowLabel.of(this.label & mask.label);
+ }
+
+ public int getIPv6FlowLabelValue() {
+ return label;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java
index f809d67..72319e3 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IPv6WithMask.java
@@ -31,7 +31,7 @@
return res.toString();
}
- public static OFValueType ofPossiblyMasked(final String string) {
+ public static OFValueType<?> ofPossiblyMasked(final String string) {
int slashPos;
String ip = string;
int maskBits = 0;
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IpDscp.java b/java_gen/pre-written/src/main/java/org/openflow/types/IpDscp.java
index 033e574..44e6296 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IpDscp.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IpDscp.java
@@ -3,7 +3,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-public enum IpDscp implements OFValueType {
+public enum IpDscp implements OFValueType<IpDscp> {
DSCP_0((byte)0),
DSCP_1((byte)1),
DSCP_2((byte)2),
@@ -230,4 +230,12 @@
return IpDscp.of((byte)(c.readUnsignedByte()));
}
+ @Override
+ public IpDscp applyMask(IpDscp mask) {
+ return IpDscp.of((byte)(this.dscp & mask.dscp));
+ }
+
+ public byte getDscpValue() {
+ return dscp;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IpEcn.java b/java_gen/pre-written/src/main/java/org/openflow/types/IpEcn.java
index b261d41..90600df 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IpEcn.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IpEcn.java
@@ -3,7 +3,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-public enum IpEcn implements OFValueType {
+public enum IpEcn implements OFValueType<IpEcn> {
ECN_00((byte)0),
ECN_01((byte)1),
ECN_10((byte)2),
@@ -50,4 +50,12 @@
return IpEcn.of((byte)(c.readUnsignedByte()));
}
+ @Override
+ public IpEcn applyMask(IpEcn mask) {
+ return IpEcn.of((byte)(this.ecn & mask.ecn));
+ }
+
+ public byte getEcnValue() {
+ return ecn;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java b/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
index 436db1d..f40eded 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/IpProtocol.java
@@ -7,7 +7,7 @@
*
* @author Yotam Harchol (yotam.harchol@bigswitch.com)
*/
-public class IpProtocol implements OFValueType {
+public class IpProtocol implements OFValueType<IpProtocol> {
static final short MAX_PROTO = 0xFF;
static final int LENGTH = 1;
@@ -632,4 +632,14 @@
public static IpProtocol readByte(ChannelBuffer c) {
return IpProtocol.of(c.readUnsignedByte());
}
+
+ @Override
+ public IpProtocol applyMask(IpProtocol mask) {
+ return IpProtocol.of((short)(this.proto & mask.proto));
+ }
+
+ public short getIpProtocolNumber() {
+ return proto;
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java b/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
index a18dff3..cb8ce84 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/MacAddress.java
@@ -10,7 +10,7 @@
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
-public class MacAddress implements OFValueType {
+public class MacAddress implements OFValueType<MacAddress> {
static final int MacAddrLen = 6;
private final long rawValue;
@@ -116,6 +116,11 @@
long raw = c.readUnsignedInt() << 16 | c.readUnsignedShort();
return MacAddress.of(raw);
}
+
+ @Override
+ public MacAddress applyMask(MacAddress mask) {
+ return MacAddress.of(this.rawValue & mask.rawValue);
+ }
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java b/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
index 011bae8..043c00a 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/Masked.java
@@ -2,12 +2,12 @@
-public class Masked<T extends OFValueType> implements OFValueType {
+public class Masked<T extends OFValueType<T>> implements OFValueType<Masked<T>> {
protected T value;
protected T mask;
protected Masked(T value, T mask) {
- this.value = value;
+ this.value = value.applyMask(mask);
this.mask = mask;
}
@@ -48,5 +48,10 @@
sb.append(value.toString()).append('/').append(mask.toString());
return sb.toString();
}
+
+ @Override
+ public Masked<T> applyMask(Masked<T> mask) {
+ return this;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
index d8f71a3..7755a4a 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
@@ -10,7 +10,7 @@
* @author capveg
*/
-public class OFPhysicalPort implements OFValueType {
+public class OFPhysicalPort implements OFValueType<OFPhysicalPort> {
static final int LENGTH = 4;
@@ -60,4 +60,12 @@
return OFPhysicalPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
}
+ @Override
+ public OFPhysicalPort applyMask(OFPhysicalPort mask) {
+ return OFPhysicalPort.of(this.port & mask.port);
+ }
+
+ public int getPortNumber() {
+ return port;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
index 3272660..9dc197f 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFPort.java
@@ -15,7 +15,7 @@
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
@Immutable
-public class OFPort implements OFValueType {
+public class OFPort implements OFValueType<OFPort> {
static final int LENGTH = 4;
// private int constants (OF1.1+) to avoid duplication in the code
@@ -530,4 +530,9 @@
public static OFPort read4Bytes(ChannelBuffer c) throws OFParseError {
return OFPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
}
+
+ @Override
+ public OFPort applyMask(OFPort mask) {
+ return OFPort.of(this.portNumber & mask.portNumber);
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java
index 51c8b36..8e2f9ed 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFValueType.java
@@ -3,8 +3,10 @@
-public interface OFValueType {
+public interface OFValueType<T extends OFValueType<T>> {
public int getLength();
+
+ public T applyMask(T mask);
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java
index cecb349..82dab41 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/TransportPort.java
@@ -8,7 +8,7 @@
*
* @author Yotam Harchol (yotam.harchol@bigswitch.com)
*/
-public class TransportPort implements OFValueType {
+public class TransportPort implements OFValueType<TransportPort> {
static final int LENGTH = 2;
static final int MAX_PORT = 0xFFFF;
@@ -31,6 +31,10 @@
public int getLength() {
return LENGTH;
}
+
+ public int getPort() {
+ return port;
+ }
@Override
public boolean equals(Object obj) {
@@ -63,4 +67,9 @@
return TransportPort.of((c.readUnsignedShort() & 0x0FFFF));
}
+ @Override
+ public TransportPort applyMask(TransportPort mask) {
+ return TransportPort.of(this.port & mask.port);
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java b/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
index 2f406c8..531f878 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/VlanPcp.java
@@ -3,7 +3,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-public class VlanPcp implements OFValueType {
+public class VlanPcp implements OFValueType<VlanPcp> {
private static final byte VALIDATION_MASK = 0x07;
static final int LENGTH = 1;
@@ -57,5 +57,10 @@
public static VlanPcp readByte(ChannelBuffer c) throws OFParseError {
return VlanPcp.of((byte)(c.readUnsignedByte() & 0xFF));
}
+
+ @Override
+ public VlanPcp applyMask(VlanPcp mask) {
+ return VlanPcp.of((byte)(this.pcp & mask.pcp));
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java b/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
index a2b38b2..ca2c3c2 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/VlanVid.java
@@ -3,7 +3,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
-public class VlanVid implements OFValueType {
+public class VlanVid implements OFValueType<VlanVid> {
private static final short VALIDATION_MASK = 0x0FFF;
final static int LENGTH = 2;
@@ -73,5 +73,10 @@
public VlanVid read2Bytes(ChannelBuffer c) throws OFParseError {
return VlanVid.of(c.readShort());
}
+
+ @Override
+ public VlanVid applyMask(VlanVid mask) {
+ return VlanVid.of((short)(this.vid & mask.vid));
+ }
}