Implementation of the Match porcelain interface for OF version 1.3:
1. Renamed ENUM values in MatchFields to conform with the OF spec to allow unified code generation.
2. Extended OFOxms factory with methods for creating OXM objects from a given field and value. This code is automatically generated from the oxm_map in java_model.
3. Implemented OFMatchV3Ver13.java custom template.
4. Implemented OFMatchV3Ver13.Builder.java custom template.
Tested new implementation on demo controller and it works.
diff --git a/java_gen/templates/custom/OFMatchV3Ver13.Builder.java b/java_gen/templates/custom/OFMatchV3Ver13.Builder.java
index 81e8d4e..b5fa630 100644
--- a/java_gen/templates/custom/OFMatchV3Ver13.Builder.java
+++ b/java_gen/templates/custom/OFMatchV3Ver13.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,6 +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