Search in sources :

Example 1 with TableEntry

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)
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) PiCounterCellData(org.onosproject.net.pi.runtime.PiCounterCellData) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) CounterData(p4.v1.P4RuntimeOuterClass.CounterData) Test(org.junit.Test)

Example 2 with TableEntry

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();
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Example 3 with TableEntry

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)));
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) EqualsTester(com.google.common.testing.EqualsTester) PiOptionalFieldMatch(org.onosproject.net.pi.runtime.PiOptionalFieldMatch) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Example 4 with TableEntry

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));
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Test(org.junit.Test)

Example 5 with TableEntry

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)
}
Also used : TableEntry(p4.v1.P4RuntimeOuterClass.TableEntry) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) PiCounterCellData(org.onosproject.net.pi.runtime.PiCounterCellData) EqualsTester(com.google.common.testing.EqualsTester) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) CounterData(p4.v1.P4RuntimeOuterClass.CounterData) Test(org.junit.Test)

Aggregations

EqualsTester (com.google.common.testing.EqualsTester)5 Test (org.junit.Test)5 PiTableEntry (org.onosproject.net.pi.runtime.PiTableEntry)5 TableEntry (p4.v1.P4RuntimeOuterClass.TableEntry)5 PiAction (org.onosproject.net.pi.runtime.PiAction)2 PiCounterCellData (org.onosproject.net.pi.runtime.PiCounterCellData)2 Action (p4.v1.P4RuntimeOuterClass.Action)2 CounterData (p4.v1.P4RuntimeOuterClass.CounterData)2 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)1 PiOptionalFieldMatch (org.onosproject.net.pi.runtime.PiOptionalFieldMatch)1 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)1