Add architecture method to PiPipelineModel Interface.
The field `pkg_info:arch` is now parsed, when parsing a P4Info file.
Change-Id: Ia1b24b929fe4ed8ac2a2becfa0ce7678642e9037
diff --git a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineModel.java b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineModel.java
index bddbae8..2efa40f 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineModel.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineModel.java
@@ -28,6 +28,13 @@
public interface PiPipelineModel {
/**
+ * Returns the data plane target architecture supported by this pipeline model.
+ *
+ * @return optional architecture string.
+ */
+ Optional<String> architecture();
+
+ /**
* Returns the table model associated with the given ID, if present.
*
* @param tableId table ID
diff --git a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/upf/MockPiPipelineModel.java b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/upf/MockPiPipelineModel.java
index db438b5..2560346 100644
--- a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/upf/MockPiPipelineModel.java
+++ b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/upf/MockPiPipelineModel.java
@@ -49,6 +49,11 @@
}
@Override
+ public Optional<String> architecture() {
+ return Optional.empty();
+ }
+
+ @Override
public Optional<PiTableModel> table(PiTableId tableId) {
return Optional.ofNullable(tableMap.getOrDefault(tableId, null));
}
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 0bb0360..85deacc 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
@@ -155,6 +155,8 @@
// Start by parsing and mapping instances to to their integer P4Info IDs.
// Convenient to build the table model at the end.
+ final String architecture = parseArchitecture(p4info);
+
// Counters.
final Map<Integer, PiCounterModel> counterMap = Maps.newHashMap();
counterMap.putAll(parseCounters(p4info));
@@ -263,9 +265,16 @@
registerImmMap,
actProfileImmMap,
ImmutableMap.copyOf(pktOpMap),
+ architecture,
fingerprint);
}
+ private static String parseArchitecture(P4Info p4info) {
+ if (p4info.hasPkgInfo()) {
+ return p4info.getPkgInfo().getArch();
+ }
+ return null;
+ }
private static Map<Integer, PiCounterModel> parseCounters(P4Info p4info)
throws P4InfoParserException {
diff --git a/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4PipelineModel.java b/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4PipelineModel.java
index 28e5372..46889a6 100644
--- a/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4PipelineModel.java
+++ b/protocols/p4runtime/model/src/main/java/org/onosproject/p4runtime/model/P4PipelineModel.java
@@ -48,6 +48,7 @@
private final ImmutableMap<PiRegisterId, PiRegisterModel> registers;
private final ImmutableMap<PiActionProfileId, PiActionProfileModel> actionProfiles;
private final ImmutableMap<PiPacketOperationType, PiPacketOperationModel> packetOperations;
+ private final String architecture;
private final int fingerprint;
P4PipelineModel(
@@ -57,6 +58,7 @@
ImmutableMap<PiRegisterId, PiRegisterModel> registers,
ImmutableMap<PiActionProfileId, PiActionProfileModel> actionProfiles,
ImmutableMap<PiPacketOperationType, PiPacketOperationModel> packetOperations,
+ String architecture,
int fingerprint) {
this.tables = tables;
this.counters = counters;
@@ -65,6 +67,12 @@
this.actionProfiles = actionProfiles;
this.packetOperations = packetOperations;
this.fingerprint = fingerprint;
+ this.architecture = architecture;
+ }
+
+ @Override
+ public Optional<String> architecture() {
+ return Optional.ofNullable(this.architecture);
}
@Override
@@ -160,6 +168,7 @@
.add("actionProfiles", actionProfiles.values())
.add("packetOperations", packetOperations.values())
.add("fingerprint", fingerprint)
+ .add("architecture", architecture)
.toString();
}
}
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 558acb1..22d3e11 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
@@ -59,6 +59,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
/**
* Test for P4Info Parser.
@@ -75,25 +76,48 @@
private static final int DEFAULT_MAX_GROUP_SIZE = 16;
/**
+ * Tests the parsing of the architecture field.
+ * @throws Exception if the equality group objects does not match expected
+ */
+ @Test
+ public void testParseArchitecture() throws Exception {
+ // Generate two PiPipelineModels from the same p4Info file
+ PiPipelineModel model = P4InfoParser.parse(p4InfoUrl);
+ PiPipelineModel sameAsModel = P4InfoParser.parse(p4InfoUrl);
+
+ PiPipelineModel model3 = P4InfoParser.parse(p4InfoUrl2);
+
+ String architecture1 = model.architecture().orElse(null);
+ String architecture2 = sameAsModel.architecture().orElse(null);
+
+ assertThat("null value is returned if `arch` not present in P4Info",
+ architecture1,
+ is(nullValue()));
+ assertThat("null value is returned if `arch` not present in P4Info",
+ architecture2,
+ is(nullValue()));
+
+ String architecture3 = model3.architecture().orElse(null);
+ assertThat("test that `arch` field is correctly parsed",
+ architecture3,
+ is("v1model"));
+ }
+
+ /**
* Tests parse method.
* @throws Exception if equality group objects dose not match as expected
*/
@Test
public void testParse() throws Exception {
- // Generate two PiPipelineModels from p4Info file
+ // Generate two PiPipelineModels from the same p4Info file
PiPipelineModel model = P4InfoParser.parse(p4InfoUrl);
- PiPipelineModel model2 = P4InfoParser.parse(p4InfoUrl);
+ PiPipelineModel sameAsModel = P4InfoParser.parse(p4InfoUrl);
// Check equality
- new EqualsTester().addEqualityGroup(model, model2).testEquals();
+ new EqualsTester().addEqualityGroup(model, sameAsModel).testEquals();
// Generate a P4Info object from the file
- final P4Info p4info;
- try {
- p4info = getP4InfoMessage(p4InfoUrl);
- } catch (IOException e) {
- throw new P4InfoParserException("Unable to parse protobuf " + p4InfoUrl.toString(), e);
- }
+ final P4Info p4info = getP4InfoMessage(p4InfoUrl);
List<Table> tableMsgs = p4info.getTablesList();
PiTableId table0Id = PiTableId.of(tableMsgs.get(0).getPreamble().getName());
@@ -102,8 +126,8 @@
//parse tables
PiTableModel table0Model = model.table(table0Id).orElse(null);
PiTableModel wcmpTableModel = model.table(wcmpTableId).orElse(null);
- PiTableModel table0Model2 = model2.table(table0Id).orElse(null);
- PiTableModel wcmpTableModel2 = model2.table(wcmpTableId).orElse(null);
+ PiTableModel table0Model2 = sameAsModel.table(table0Id).orElse(null);
+ PiTableModel wcmpTableModel2 = sameAsModel.table(wcmpTableId).orElse(null);
new EqualsTester().addEqualityGroup(table0Model, table0Model2)
.addEqualityGroup(wcmpTableModel, wcmpTableModel2).testEquals();
@@ -211,7 +235,7 @@
true, DEFAULT_MAX_ACTION_PROFILE_SIZE,
DEFAULT_MAX_GROUP_SIZE);
PiActionProfileModel wcmpSelector = model.actionProfiles(actionProfileId).orElse(null);
- PiActionProfileModel wcmpSelector2 = model2.actionProfiles(actionProfileId).orElse(null);
+ PiActionProfileModel wcmpSelector2 = sameAsModel.actionProfiles(actionProfileId).orElse(null);
new EqualsTester().addEqualityGroup(wcmpSelector, wcmpSelector2, wcmpSelector3).testEquals();
@@ -232,13 +256,13 @@
model.counter(PiCounterId.of("wcmp_control.wcmp_table_counter")).orElse(null);
PiCounterModel ingressPortCounterModel2 =
- model2.counter(PiCounterId.of("port_counters_ingress.ingress_port_counter")).orElse(null);
+ sameAsModel.counter(PiCounterId.of("port_counters_ingress.ingress_port_counter")).orElse(null);
PiCounterModel egressPortCounterModel2 =
- model2.counter(PiCounterId.of("port_counters_egress.egress_port_counter")).orElse(null);
+ sameAsModel.counter(PiCounterId.of("port_counters_egress.egress_port_counter")).orElse(null);
PiCounterModel table0CounterModel2 =
- model2.counter(PiCounterId.of("table0_control.table0_counter")).orElse(null);
+ sameAsModel.counter(PiCounterId.of("table0_control.table0_counter")).orElse(null);
PiCounterModel wcmpTableCounterModel2 =
- model2.counter(PiCounterId.of("wcmp_control.wcmp_table_counter")).orElse(null);
+ sameAsModel.counter(PiCounterId.of("wcmp_control.wcmp_table_counter")).orElse(null);
new EqualsTester()
.addEqualityGroup(ingressPortCounterModel, ingressPortCounterModel2)
@@ -254,7 +278,7 @@
//Parse meters
Collection<PiMeterModel> meterModel = model.meters();
- Collection<PiMeterModel> meterModel2 = model2.meters();
+ Collection<PiMeterModel> meterModel2 = sameAsModel.meters();
assertThat("model pased meter collaction should be empty", meterModel.isEmpty(), is(true));
assertThat("model pased meter collaction should be empty", meterModel2.isEmpty(), is(true));
@@ -266,9 +290,9 @@
model.packetOperationModel(PiPacketOperationType.PACKET_OUT).orElse(null);
PiPacketOperationModel packetInOperationalModel2 =
- model2.packetOperationModel(PiPacketOperationType.PACKET_IN).orElse(null);
+ sameAsModel.packetOperationModel(PiPacketOperationType.PACKET_IN).orElse(null);
PiPacketOperationModel packetOutOperationalModel2 =
- model2.packetOperationModel(PiPacketOperationType.PACKET_OUT).orElse(null);
+ sameAsModel.packetOperationModel(PiPacketOperationType.PACKET_OUT).orElse(null);
new EqualsTester()
.addEqualityGroup(packetInOperationalModel, packetInOperationalModel2)
diff --git a/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4PipelineModelTest.java b/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4PipelineModelTest.java
index fdc3d2e..8aa222d 100644
--- a/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4PipelineModelTest.java
+++ b/protocols/p4runtime/model/src/test/java/org/onosproject/p4runtime/model/P4PipelineModelTest.java
@@ -27,8 +27,6 @@
import org.onosproject.net.pi.model.PiActionParamModel;
import org.onosproject.net.pi.model.PiActionProfileId;
import org.onosproject.net.pi.model.PiActionProfileModel;
-import org.onosproject.net.pi.model.PiPacketMetadataId;
-import org.onosproject.net.pi.model.PiPacketMetadataModel;
import org.onosproject.net.pi.model.PiCounterId;
import org.onosproject.net.pi.model.PiCounterModel;
import org.onosproject.net.pi.model.PiCounterType;
@@ -38,6 +36,8 @@
import org.onosproject.net.pi.model.PiMeterId;
import org.onosproject.net.pi.model.PiMeterModel;
import org.onosproject.net.pi.model.PiMeterType;
+import org.onosproject.net.pi.model.PiPacketMetadataId;
+import org.onosproject.net.pi.model.PiPacketMetadataModel;
import org.onosproject.net.pi.model.PiPacketOperationModel;
import org.onosproject.net.pi.model.PiPacketOperationType;
import org.onosproject.net.pi.model.PiPipelineModel;
@@ -355,18 +355,22 @@
private static final int FINGER_PRINT_1 = 0;
private static final int FINGER_PRINT_2 = 1;
+ private static final String ARCHITECTURE_ID_1 = "tna";
+ private static final String ARCHITECTURE_ID_2 = "v1model";
+
+
private static final PiPipelineModel P4_PIPELINE_MODEL_1 =
new P4PipelineModel(TABLES_1, COUNTERS_1, METERS_1, REGISTERS_1, ACTION_PROFILES_1, PACKET_OPERATIONS_1,
- FINGER_PRINT_1);
+ ARCHITECTURE_ID_1, FINGER_PRINT_1);
private static final PiPipelineModel SAME_AS_P4_PIPELINE_MODEL_1 =
new P4PipelineModel(TABLES_1, COUNTERS_1, METERS_1, REGISTERS_1, ACTION_PROFILES_1, PACKET_OPERATIONS_1,
- FINGER_PRINT_1);
+ ARCHITECTURE_ID_1, FINGER_PRINT_1);
private static final PiPipelineModel P4_PIPELINE_MODEL_2 =
new P4PipelineModel(TABLES_2, COUNTERS_2, METERS_2, REGISTERS_1, ACTION_PROFILES_2, PACKET_OPERATIONS_2,
- FINGER_PRINT_2);
+ ARCHITECTURE_ID_2, FINGER_PRINT_2);
private static final PiPipelineModel P4_PIPELINE_MODEL_3 =
new P4PipelineModel(TABLES_2, COUNTERS_2, METERS_2, REGISTERS_1, ACTION_PROFILES_2, PACKET_OPERATIONS_3,
- FINGER_PRINT_2);
+ ARCHITECTURE_ID_2, FINGER_PRINT_2);
/**
* Checks that the P4PipelineModel class is immutable.