Match field iteration
diff --git a/java_gen/templates/custom/OFMatchV1Ver10.java b/java_gen/templates/custom/OFMatchV1Ver10.java
index 82ff10f..7b750bb 100644
--- a/java_gen/templates/custom/OFMatchV1Ver10.java
+++ b/java_gen/templates/custom/OFMatchV1Ver10.java
@@ -334,3 +334,77 @@
throw new UnsupportedOperationException("OFMatch does not support masked matching on field " + field.getName());
}
}
+
+ @Override
+ public Iterable<MatchField<?>> getMatchFields() {
+ ImmutableList.Builder<MatchField<?>> builder = ImmutableList.builder();
+ if ((wildcards & OFPFW_IN_PORT) == 0)
+ builder.add(MatchField.IN_PORT);
+ if ((wildcards & OFPFW_DL_VLAN) == 0)
+ builder.add(MatchField.VLAN_VID);
+ if ((wildcards & OFPFW_DL_SRC) == 0)
+ builder.add(MatchField.ETH_SRC);
+ if ((wildcards & OFPFW_DL_DST) == 0)
+ builder.add(MatchField.ETH_DST);
+ if ((wildcards & OFPFW_DL_TYPE) == 0)
+ builder.add(MatchField.ETH_TYPE);
+ if ((wildcards & OFPFW_NW_PROTO) == 0) {
+ if (ethType == EthType.ARP) {
+ builder.add(MatchField.ARP_OP);
+ } else if (ethType == EthType.IPv4) {
+ builder.add(MatchField.IP_PROTO);
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported Ethertype for matching on network protocol " + ethType);
+ }
+ }
+ if ((wildcards & OFPFW_TP_SRC) == 0) {
+ if (ipProto == IpProtocol.UDP) {
+ builder.add(MatchField.UDP_SRC);
+ } else if (ipProto == IpProtocol.TCP) {
+ builder.add(MatchField.TCP_SRC);
+ } else if (ipProto == IpProtocol.SCTP) {
+ builder.add(MatchField.SCTP_SRC);
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported IP protocol for matching on source port " + ipProto);
+ }
+ }
+ if ((wildcards & OFPFW_TP_DST) == 0) {
+ if (ipProto == IpProtocol.UDP) {
+ builder.add(MatchField.UDP_DST);
+ } else if (ipProto == IpProtocol.TCP) {
+ builder.add(MatchField.TCP_DST);
+ } else if (ipProto == IpProtocol.SCTP) {
+ builder.add(MatchField.SCTP_DST);
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported IP protocol for matching on destination port " + ipProto);
+ }
+ }
+ if (((wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT) < 32) {
+ if (ethType == EthType.ARP) {
+ builder.add(MatchField.ARP_SPA);
+ } else if (ethType == EthType.IPv4) {
+ builder.add(MatchField.IPV4_SRC);
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported Ethertype for matching on source IP " + ethType);
+ }
+ }
+ if (((wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT) < 32) {
+ if (ethType == EthType.ARP) {
+ builder.add(MatchField.ARP_TPA);
+ } else if (ethType == EthType.IPv4) {
+ builder.add(MatchField.IPV4_DST);
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported Ethertype for matching on destination IP " + ethType);
+ }
+ }
+ if ((wildcards & OFPFW_DL_VLAN_PCP) == 0)
+ builder.add(MatchField.VLAN_PCP);
+ if ((wildcards & OFPFW_NW_TOS) == 0)
+ builder.add(MatchField.IP_DSCP);
+ return builder.build();
+ }
diff --git a/java_gen/templates/custom/OFMatchV2Ver11.java b/java_gen/templates/custom/OFMatchV2Ver11.java
index ec7bfcc..ef79ffb 100644
--- a/java_gen/templates/custom/OFMatchV2Ver11.java
+++ b/java_gen/templates/custom/OFMatchV2Ver11.java
@@ -42,3 +42,8 @@
// FIXME yotam - please replace with real implementation
return false;
}
+
+ @Override
+ public Iterable<MatchField<?>> getMatchFields() {
+ throw new UnsupportedOperationException();
+ }
diff --git a/java_gen/templates/custom/OFMatchV3Ver12.java b/java_gen/templates/custom/OFMatchV3Ver12.java
index a4cc51c..81092c1 100644
--- a/java_gen/templates/custom/OFMatchV3Ver12.java
+++ b/java_gen/templates/custom/OFMatchV3Ver12.java
@@ -106,4 +106,9 @@
OFOxm<?> oxm = this.oxmList.get(field);
return oxm != null && oxm.isMasked();
- }
\ No newline at end of file
+ }
+
+ @Override
+ public Iterable<MatchField<?>> getMatchFields() {
+ throw new UnsupportedOperationException();
+ }
diff --git a/java_gen/templates/custom/OFMatchV3Ver13.java b/java_gen/templates/custom/OFMatchV3Ver13.java
index 8955e1e..9bfb234 100644
--- a/java_gen/templates/custom/OFMatchV3Ver13.java
+++ b/java_gen/templates/custom/OFMatchV3Ver13.java
@@ -108,3 +108,31 @@
return oxm != null && oxm.isMasked();
}
+
+ private class MatchFieldIterator extends UnmodifiableIterator<MatchField<?>> {
+ private Iterator<OFOxm<?>> oxmIterator;
+
+ MatchFieldIterator() {
+ oxmIterator = oxmList.iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return oxmIterator.hasNext();
+ }
+
+ @Override
+ public MatchField<?> next() {
+ OFOxm<?> next = oxmIterator.next();
+ return next.getMatchField();
+ }
+ }
+
+ @Override
+ public Iterable<MatchField<?>> getMatchFields() {
+ return new Iterable<MatchField<?>>() {
+ public Iterator<MatchField<?>> iterator() {
+ return new MatchFieldIterator();
+ }
+ };
+ }