Search in sources :

Example 1 with Action

use of p4.v1.P4RuntimeOuterClass.Action in project onos by opennetworkinglab.

the class P4RuntimeGroupTest method testReadMembers.

@Test
public void testReadMembers() throws Exception {
    List<ActionProfileMember> members = Lists.newArrayList();
    MEMBER_IDS.forEach(id -> {
        byte outPort = (byte) (id - BASE_MEM_ID);
        ByteString bs = ByteString.copyFrom(new byte[] { 0, outPort });
        Action.Param param = Action.Param.newBuilder().setParamId(1).setValue(bs).build();
        Action action = Action.newBuilder().setActionId(SET_EGRESS_PORT_ID).addParams(param).build();
        ActionProfileMember actProfMember = ActionProfileMember.newBuilder().setActionProfileId(P4_INFO_ACT_PROF_ID).setMemberId(id).setAction(action).build();
        members.add(actProfMember);
    });
    List<ReadResponse> responses = Lists.newArrayList();
    responses.add(ReadResponse.newBuilder().addAllEntities(members.stream().map(m -> Entity.newBuilder().setActionProfileMember(m).build()).collect(Collectors.toList())).build());
    p4RuntimeServerImpl.willReturnReadResult(responses);
    CompletableFuture<Void> complete = p4RuntimeServerImpl.expectRequests(1);
    Collection<PiActionProfileMember> piMembers = client.read(P4_DEVICE_ID, PIPECONF).actionProfileMembers(ACT_PROF_ID).submitSync().all(PiActionProfileMember.class);
    complete.get(DEFAULT_TIMEOUT_TIME, TimeUnit.SECONDS);
    assertEquals(3, piMembers.size());
    assertTrue(GROUP_MEMBER_INSTANCES.containsAll(piMembers));
    assertTrue(piMembers.containsAll(GROUP_MEMBER_INSTANCES));
}
Also used : Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) ReadResponse(p4.v1.P4RuntimeOuterClass.ReadResponse) ByteString(com.google.protobuf.ByteString) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) ActionProfileMember(p4.v1.P4RuntimeOuterClass.ActionProfileMember) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) Test(org.junit.Test)

Example 2 with Action

use of p4.v1.P4RuntimeOuterClass.Action 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 3 with Action

use of p4.v1.P4RuntimeOuterClass.Action 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 4 with Action

use of p4.v1.P4RuntimeOuterClass.Action 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 Action

use of p4.v1.P4RuntimeOuterClass.Action in project onos by opennetworkinglab.

the class P4InfoParserTest method testParseP4RuntimeTranslationAndOptional.

/**
 * Tests parse method with P4Runtime translation fields and optional fields.
 * @throws Exception if equality group objects dose not match as expected
 */
@Test
public void testParseP4RuntimeTranslationAndOptional() throws Exception {
    PiPipelineModel model = P4InfoParser.parse(p4InfoUrl2);
    // Generate a P4Info object from the file
    final P4Info p4info;
    try {
        p4info = getP4InfoMessage(p4InfoUrl2);
    } catch (IOException e) {
        throw new P4InfoParserException("Unable to parse protobuf " + p4InfoUrl.toString(), e);
    }
    List<Table> tableMsgs = p4info.getTablesList();
    PiTableId table0Id = PiTableId.of(tableMsgs.get(0).getPreamble().getName());
    // parse tables
    PiTableModel table0Model = model.table(table0Id).orElse(null);
    // Check matchFields
    List<MatchField> matchFieldList = tableMsgs.get(0).getMatchFieldsList();
    List<PiMatchFieldModel> piMatchFieldList = new ArrayList<>();
    for (MatchField matchFieldIter : matchFieldList) {
        MatchField.MatchType matchType = matchFieldIter.getMatchType();
        PiMatchType piMatchType;
        switch(matchType) {
            case EXACT:
                piMatchType = PiMatchType.EXACT;
                break;
            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")) {
            piMatchFieldList.add(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldIter.getName()), P4MatchFieldModel.BIT_WIDTH_UNDEFINED, piMatchType));
        } else {
            piMatchFieldList.add(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldIter.getName()), matchFieldIter.getBitwidth(), piMatchType));
        }
    }
    assertThat("Incorrect order for matchFields", table0Model.matchFields(), IsIterableContainingInOrder.contains(piMatchFieldList.get(0), piMatchFieldList.get(1), piMatchFieldList.get(2), piMatchFieldList.get(3)));
    // check table0 actionsRefs
    List<ActionRef> actionRefList = tableMsgs.get(0).getActionRefsList();
    assertThat("Incorrect size for actionRefs", actionRefList.size(), is(equalTo(4)));
    // create action instances
    // Set egress with string as parameter
    PiActionId actionId = PiActionId.of("set_egress_port");
    PiActionParamId piActionParamId = PiActionParamId.of("port");
    PiActionParamModel actionParamModel = new P4ActionParamModel(piActionParamId, P4ActionParamModel.BIT_WIDTH_UNDEFINED);
    ImmutableMap<PiActionParamId, PiActionParamModel> params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
    PiActionModel setEgressPortAction = new P4ActionModel(actionId, params);
    // Set egress with 32 bit as parameter
    actionId = PiActionId.of("set_egress_port2");
    piActionParamId = PiActionParamId.of("port");
    int bitWitdth = 32;
    actionParamModel = new P4ActionParamModel(piActionParamId, bitWitdth);
    params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
    PiActionModel setEgressPortAction2 = new P4ActionModel(actionId, params);
    actionId = PiActionId.of("send_to_cpu");
    PiActionModel sendToCpuAction = new P4ActionModel(actionId, new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().build());
    actionId = PiActionId.of("drop");
    PiActionModel dropAction = new P4ActionModel(actionId, new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().build());
    // check table0 actions
    assertThat("action dose not match", table0Model.actions(), IsIterableContainingInAnyOrder.containsInAnyOrder(setEgressPortAction, setEgressPortAction2, sendToCpuAction, dropAction));
}
Also used : PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiActionId(org.onosproject.net.pi.model.PiActionId) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) ArrayList(java.util.ArrayList) MatchField(p4.config.v1.P4InfoOuterClass.MatchField) PiTableId(org.onosproject.net.pi.model.PiTableId) ActionRef(p4.config.v1.P4InfoOuterClass.ActionRef) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) Table(p4.config.v1.P4InfoOuterClass.Table) PiMatchType(org.onosproject.net.pi.model.PiMatchType) PiActionModel(org.onosproject.net.pi.model.PiActionModel) PiActionParamModel(org.onosproject.net.pi.model.PiActionParamModel) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) P4Info(p4.config.v1.P4InfoOuterClass.P4Info) PiMatchFieldModel(org.onosproject.net.pi.model.PiMatchFieldModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 EqualsTester (com.google.common.testing.EqualsTester)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 PiActionModel (org.onosproject.net.pi.model.PiActionModel)4 PiTableId (org.onosproject.net.pi.model.PiTableId)4 PiAction (org.onosproject.net.pi.runtime.PiAction)4 PiTableEntry (org.onosproject.net.pi.runtime.PiTableEntry)4 Action (p4.v1.P4RuntimeOuterClass.Action)4 IOException (java.io.IOException)3 PiActionId (org.onosproject.net.pi.model.PiActionId)3 PiActionParamId (org.onosproject.net.pi.model.PiActionParamId)3 PiActionParamModel (org.onosproject.net.pi.model.PiActionParamModel)3 PiActionProfileModel (org.onosproject.net.pi.model.PiActionProfileModel)3 PiMatchFieldModel (org.onosproject.net.pi.model.PiMatchFieldModel)3 PiTableModel (org.onosproject.net.pi.model.PiTableModel)3 ActionRef (p4.config.v1.P4InfoOuterClass.ActionRef)3 MatchField (p4.config.v1.P4InfoOuterClass.MatchField)3 P4Info (p4.config.v1.P4InfoOuterClass.P4Info)3 Table (p4.config.v1.P4InfoOuterClass.Table)3 TableEntry (p4.v1.P4RuntimeOuterClass.TableEntry)3