use of p4.v1.P4RuntimeOuterClass.TableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testEncodeWithNoAction.
@Test
public void testEncodeWithNoAction() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutAction, null, defaultPipeconf);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntryWithoutAction, decodedPiTableEntry).testEquals();
// Table ID.
int p4InfoTableId = browser.tables().getByName(tableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Ternary match.
byte[] encodedTernaryMatchValue = tableEntryMsg.getMatch(0).getTernary().getValue().toByteArray();
assertThat(encodedTernaryMatchValue, is(ethAddr.asArray()));
// no action
assertThat(tableEntryMsg.hasAction(), is(false));
// Counter
CounterData counterData = tableEntryMsg.getCounterData();
PiCounterCellData encodedCounterData = new PiCounterCellData(counterData.getPacketCount(), counterData.getByteCount());
assertThat(encodedCounterData, is(counterCellData));
// TODO: improve, assert other field match types (ternary, LPM)
}
use of p4.v1.P4RuntimeOuterClass.TableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testTableEntryEncoderWithTranslations.
@Test
public void testTableEntryEncoderWithTranslations() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntry2, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntry2, decodedPiTableEntry).testEquals();
// Check the exact match with string
byte[] encodedExactMatchValueString = tableEntryMsg.getMatch(1).getExact().getValue().toByteArray();
assertThat(encodedExactMatchValueString, is(ethAddrString.asArray()));
Action actionMsg = tableEntryMsg.getAction().getAction();
// Check action param value with string
byte[] encodedActionParamString = actionMsg.getParams(0).getValue().toByteArray();
assertThat(encodedActionParamString, is(portValueString.asArray()));
TableEntry tableEntryMsg1 = Codecs.CODECS.tableEntry().encode(piTableEntry3, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry1 = Codecs.CODECS.tableEntry().decode(tableEntryMsg1, null, defaultPipeconf2);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntry3, decodedPiTableEntry1).testEquals();
}
use of p4.v1.P4RuntimeOuterClass.TableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testTableEntryEncoderWithoutOptionalField.
@Test
public void testTableEntryEncoderWithoutOptionalField() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutOptionalField, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
// Table ID.
int p4InfoTableId = browser2.tables().getByName(tableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntryWithoutOptionalField, decodedPiTableEntry).testEquals();
// no optional field
assertThat(tableEntryMsg.getMatchCount(), is(3));
assertThat(tableEntryMsg.getMatchList().stream().map(P4RuntimeOuterClass.FieldMatch::getFieldMatchTypeCase).collect(Collectors.toList()), not(hasItem(P4RuntimeOuterClass.FieldMatch.FieldMatchTypeCase.OPTIONAL)));
}
use of p4.v1.P4RuntimeOuterClass.TableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testActopProfileGroup.
@Test
public void testActopProfileGroup() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithGroupAction, null, defaultPipeconf);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntryWithGroupAction, decodedPiTableEntry).testEquals();
// Table ID.
int p4InfoTableId = browser.tables().getByName(ecmpTableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Exact match.
byte[] encodedTernaryMatchValue = tableEntryMsg.getMatch(0).getExact().getValue().toByteArray();
assertThat(encodedTernaryMatchValue, is(new byte[] { (byte) 0xff }));
// Action profile group id
int actionProfileGroupId = tableEntryMsg.getAction().getActionProfileGroupId();
assertThat(actionProfileGroupId, is(1));
}
use of p4.v1.P4RuntimeOuterClass.TableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testTableEntryEncoder.
@Test
public void testTableEntryEncoder() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntry, null, defaultPipeconf);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntry, decodedPiTableEntry).testEquals();
// Table ID.
int p4InfoTableId = browser.tables().getByName(tableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Ternary match.
byte[] encodedTernaryMatchValue = tableEntryMsg.getMatch(0).getTernary().getValue().toByteArray();
assertThat(encodedTernaryMatchValue, is(ethAddr.asArray()));
Action actionMsg = tableEntryMsg.getAction().getAction();
// Action ID.
int p4InfoActionId = browser.actions().getByName(outActionId.toString()).getPreamble().getId();
int encodedActionId = actionMsg.getActionId();
assertThat(encodedActionId, is(p4InfoActionId));
// Action param ID.
int p4InfoActionParamId = browser.actionParams(p4InfoActionId).getByName(portParamId.toString()).getId();
int encodedActionParamId = actionMsg.getParams(0).getParamId();
assertThat(encodedActionParamId, is(p4InfoActionParamId));
// Action param value.
byte[] encodedActionParam = actionMsg.getParams(0).getValue().toByteArray();
assertThat(encodedActionParam, is(portValue.asArray()));
// Counter
CounterData counterData = tableEntryMsg.getCounterData();
PiCounterCellData encodedCounterData = new PiCounterCellData(counterData.getPacketCount(), counterData.getByteCount());
assertThat(encodedCounterData, is(counterCellData));
// TODO: improve, assert other field match types (ternary, LPM)
}
Aggregations