Add Optional match fields support to PI subsystem
Change-Id: Ic458f59cab98340e40c04a0ad060d3c725ac5dbb
diff --git a/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4InfoParser.java b/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4InfoParser.java
index 6558d80..b2f662b 100644
--- a/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4InfoParser.java
+++ b/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4InfoParser.java
@@ -114,6 +114,7 @@
.put(MatchField.MatchType.LPM, PiMatchType.LPM)
.put(MatchField.MatchType.TERNARY, PiMatchType.TERNARY)
.put(MatchField.MatchType.RANGE, PiMatchType.RANGE)
+ .put(MatchField.MatchType.OPTIONAL, PiMatchType.OPTIONAL)
// Don't map UNSPECIFIED as we don't support it at the moment.
.build();
public static final int NO_SIZE = -1;
diff --git a/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4InfoParserTest.java b/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4InfoParserTest.java
index 0432a18..558acb1 100644
--- a/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4InfoParserTest.java
+++ b/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4InfoParserTest.java
@@ -281,11 +281,11 @@
}
/**
- * Tests parse method with P4Runtime translation fields.
+ * Tests parse method with P4Runtime translation fields and optional fields.
* @throws Exception if equality group objects dose not match as expected
*/
@Test
- public void testParseP4RuntimeTranslation() throws Exception {
+ public void testParseP4RuntimeTranslationAndOptional() throws Exception {
PiPipelineModel model = P4InfoParser.parse(p4InfoUrl2);
// Generate a P4Info object from the file
final P4Info p4info;
@@ -312,6 +312,7 @@
case LPM: piMatchType = PiMatchType.LPM; break;
case TERNARY: piMatchType = PiMatchType.TERNARY; break;
case RANGE: piMatchType = PiMatchType.RANGE; break;
+ case OPTIONAL: piMatchType = PiMatchType.OPTIONAL; break;
default: Assert.fail(); return;
}
if (matchFieldIter.getTypeName().getName().equals("mac_addr_t")) {
diff --git a/protocols/p4runtime/model/src/test/resources/org/onosproject/p4runtime/model/test_p4runtime_translation_p4info.txt b/protocols/p4runtime/model/src/test/resources/org/onosproject/p4runtime/model/test_p4runtime_translation_p4info.txt
index 241d989..b984b4c 100644
--- a/protocols/p4runtime/model/src/test/resources/org/onosproject/p4runtime/model/test_p4runtime_translation_p4info.txt
+++ b/protocols/p4runtime/model/src/test/resources/org/onosproject/p4runtime/model/test_p4runtime_translation_p4info.txt
@@ -36,7 +36,7 @@
id: 4
name: "hdr.ethernet.etherType"
bitwidth: 16
- match_type: EXACT
+ match_type: OPTIONAL
}
action_refs {
id: 27607748