Added content to the template of Ver 1.2 and added additional casting to the OXM from field/value creation
mechanism as when compiling it outside of eclipse javac cannot cast from a generic type to the real type.
diff --git a/java_gen/templates/custom/OFMatchV3Ver12.Builder.java b/java_gen/templates/custom/OFMatchV3Ver12.Builder.java
index ba739bc..b5fa630 100644
--- a/java_gen/templates/custom/OFMatchV3Ver12.Builder.java
+++ b/java_gen/templates/custom/OFMatchV3Ver12.Builder.java
@@ -1,73 +1,108 @@
- @Override
- public <F extends OFValueType<F>> F get(MatchField<F> field)
- throws UnsupportedOperationException {
- // FIXME yotam - please replace with real implementation
- return null;
+ private OFOxmList.Builder oxmListBuilder;
+
+ private synchronized void initBuilder() {
+ if (oxmListBuilder != null)
+ return;
+ oxmListBuilder = new OFOxmList.Builder();
+ }
+
+ private synchronized void updateOxmList() {
+ this.oxmList = this.oxmListBuilder.build();
+ this.oxmListSet = true;
+ }
+
+ private <F extends OFValueType<F>> OFOxm<F> getOxm(MatchField<F> field) {
+//:: if has_parent:
+ return this.oxmListSet ? this.oxmList.get(field) : parentMessage.oxmList.get(field);
+//:: else:
+ return this.oxmListSet ? this.oxmList.get(field) : null;
+//:: #endif
}
@Override
- public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
+ public synchronized <F extends OFValueType<F>> F get(MatchField<F> field)
throws UnsupportedOperationException {
- // FIXME yotam - please replace with real implementation
- return null;
+ OFOxm<F> value = getOxm(field);
+ if (value == null)
+ return null;
+ return value.getValue();
+ }
+
+ @Override
+ public synchronized <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
+ throws UnsupportedOperationException {
+ OFOxm<F> value = getOxm(field);
+ if (value == null || !value.isMasked())
+ return null;
+ // TODO: If changing OXMs to extend Masked, then use it here
+ return Masked.of(value.getValue(), value.getMask());
}
@Override
public boolean supports(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ return supportsField(field);
}
@Override
public boolean supportsMasked(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ return supportsField(field);
}
@Override
- public boolean isExact(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ public synchronized boolean isExact(MatchField<?> field) {
+ OFOxm<?> value = getOxm(field);
+ return (value != null && !value.isMasked());
}
@Override
- public boolean isFullyWildcarded(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ public synchronized boolean isFullyWildcarded(MatchField<?> field) {
+ OFOxm<?> value = getOxm(field);
+ return (value == null);
}
@Override
- public boolean isPartiallyMasked(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ public synchronized boolean isPartiallyMasked(MatchField<?> field) {
+ OFOxm<?> value = getOxm(field);
+ return (value != null && value.isMasked());
}
@Override
- public <F extends OFValueType<F>> Match.Builder setExact(
+ public synchronized <F extends OFValueType<F>> Match.Builder setExact(
MatchField<F> field, F value) {
- // FIXME yotam - please replace with real implementation
- return null;
+ initBuilder();
+ OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValue(value, field);
+ this.oxmListBuilder.set(oxm);
+ updateOxmList();
+ return this;
}
@Override
- public <F extends OFValueType<F>> Match.Builder setMasked(
+ public synchronized <F extends OFValueType<F>> Match.Builder setMasked(
MatchField<F> field, F value, F mask) {
- // FIXME yotam - please replace with real implementation
- return null;
+ initBuilder();
+ OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValueAndMask(value, mask, field);
+ this.oxmListBuilder.set(oxm);
+ updateOxmList();
+ return this;
}
@Override
- public <F extends OFValueType<F>> Match.Builder setMasked(
+ public synchronized <F extends OFValueType<F>> Match.Builder setMasked(
MatchField<F> field, Masked<F> valueWithMask) {
- // FIXME yotam - please replace with real implementation
- return null;
+ initBuilder();
+ OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromMasked(valueWithMask, field);
+ this.oxmListBuilder.set(oxm);
+ updateOxmList();
+ return this;
}
@Override
- public <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
- // FIXME yotam - please replace with real implementation
- return null;
+ public synchronized <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
+ initBuilder();
+ this.oxmListBuilder.unset(field);
+ updateOxmList();
+ return this;
}
@Override
@@ -77,5 +112,6 @@
@Override
public void writeTo(ChannelBuffer bb) {
- // FIXME yotam - please replace with real implementation
- }
+ // TODO: What should this write?
+ throw new UnsupportedOperationException("Builder cannot be written");
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFMatchV3Ver12.java b/java_gen/templates/custom/OFMatchV3Ver12.java
index ec7bfcc..a4cc51c 100644
--- a/java_gen/templates/custom/OFMatchV3Ver12.java
+++ b/java_gen/templates/custom/OFMatchV3Ver12.java
@@ -2,43 +2,108 @@
@Override
public <F extends OFValueType<F>> F get(MatchField<F> field)
throws UnsupportedOperationException {
- // FIXME yotam - please replace with real implementation
- return null;
+ if (!supports(field))
+ throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
+
+ OFOxm<F> oxm = this.oxmList.get(field);
+
+ if (oxm == null || !field.arePrerequisitesOK(this))
+ return null;
+
+ return oxm.getValue();
}
@Override
public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
throws UnsupportedOperationException {
- // FIXME yotam - please replace with real implementation
- return null;
+ if (!supportsMasked(field))
+ throw new UnsupportedOperationException("OFMatchV3Ver13 does not support masked matching on field " + field.getName());
+
+ OFOxm<F> oxm = this.oxmList.get(field);
+
+ if (oxm == null || !field.arePrerequisitesOK(this))
+ return null;
+
+ if (oxm.getMask() == null)
+ return null;
+
+ // TODO: Make OfOxm extend Masked and just return the OXM?
+ return Masked.of(oxm.getValue(), oxm.getMask());
+ }
+
+ private static boolean supportsField(MatchField<?> field) {
+ switch (field.id) {
+ case IN_PORT:
+ case IN_PHY_PORT:
+ case METADATA:
+ case ETH_DST:
+ case ETH_SRC:
+ case ETH_TYPE:
+ case VLAN_VID:
+ case VLAN_PCP:
+ case IP_DSCP:
+ case IP_ECN:
+ case IP_PROTO:
+ case IPV4_SRC:
+ case IPV4_DST:
+ case TCP_SRC:
+ case TCP_DST:
+ case UDP_SRC:
+ case UDP_DST:
+ case SCTP_SRC:
+ case SCTP_DST:
+ case ICMPV4_TYPE:
+ case ICMPV4_CODE:
+ case ARP_OP:
+ case ARP_SPA:
+ case ARP_TPA:
+ case ARP_SHA:
+ case ARP_THA:
+ case IPV6_SRC:
+ case IPV6_DST:
+ case IPV6_FLABEL:
+ return true;
+ default:
+ return false;
+ }
}
@Override
public boolean supports(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ return supportsField(field);
}
@Override
public boolean supportsMasked(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ return supportsField(field);
}
@Override
public boolean isExact(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ if (!supports(field))
+ throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
+
+ OFOxm<?> oxm = this.oxmList.get(field);
+
+ return oxm != null && !oxm.isMasked();
}
@Override
public boolean isFullyWildcarded(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
+ if (!supports(field))
+ throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
+
+ OFOxm<?> oxm = this.oxmList.get(field);
+
+ return oxm == null;
}
@Override
public boolean isPartiallyMasked(MatchField<?> field) {
- // FIXME yotam - please replace with real implementation
- return false;
- }
+ if (!supports(field))
+ throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
+
+ OFOxm<?> oxm = this.oxmList.get(field);
+
+ return oxm != null && oxm.isMasked();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/of_factory_class.java b/java_gen/templates/of_factory_class.java
index 503c492..adf5df1 100644
--- a/java_gen/templates/of_factory_class.java
+++ b/java_gen/templates/of_factory_class.java
@@ -97,7 +97,8 @@
//:: method_name = oxm_name.replace('OFOxm', '')
//:: method_name = method_name[0].lower() + method_name[1:]
case ${value}:
- return (OFOxm<F>)${method_name}((${type_name})value);
+ //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
+ return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value)));
//:: #endfor
default:
return null;
@@ -115,7 +116,8 @@
//:: method_name = oxm_name.replace('OFOxm', '')
//:: method_name = method_name[0].lower() + method_name[1:]
case ${value}:
- return (OFOxm<F>)${method_name}((${type_name})value, (${type_name})mask);
+ //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
+ return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value), (${type_name})((Object)mask)));
//:: #endfor
default:
return null;
@@ -133,7 +135,8 @@
//:: method_name = oxm_name.replace('OFOxm', '')
//:: method_name = method_name[0].lower() + method_name[1:]
case ${value}:
- return (OFOxm<F>)${method_name}((${type_name})(masked.getValue()), (${type_name})(masked.getMask()));
+ //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
+ return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)(masked.getValue())), (${type_name})((Object)(masked.getMask()))));
//:: #endfor
default:
return null;