Search in sources :

Example 1 with PiActionId

use of org.onosproject.net.pi.model.PiActionId 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)

Example 2 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class PiActionIdTest method testConstruction.

/**
 * Checks the construction of a PiActionId object.
 */
@Test
public void testConstruction() {
    final PiActionId actionId = PiActionId.of(DEC_TTL);
    assertThat(actionId, is(notNullValue()));
    assertThat(actionId.id(), is(DEC_TTL));
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) Test(org.junit.Test)

Example 3 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class PiActionTest method testMethodWithParameters.

/**
 * Checks the construction of a PiAction object with parameters.
 */
@Test
public void testMethodWithParameters() {
    PiActionId piActionId = PiActionId.of(MOD_NW_DST);
    Collection<PiActionParam> runtimeParams = Lists.newArrayList();
    PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101));
    runtimeParams.add(piActionParam);
    final PiAction piAction = PiAction.builder().withId(piActionId).withParameters(runtimeParams).build();
    assertThat(piAction, is(notNullValue()));
    assertThat(piAction.id(), is(piActionId));
    assertThat(piAction.parameters(), is(runtimeParams));
    assertThat(piAction.type(), is(PiTableAction.Type.ACTION));
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) Test(org.junit.Test)

Example 4 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class PiActionTest method testMethodWithParameter.

/**
 * Checks the construction of a PiAction object with parameter.
 */
@Test
public void testMethodWithParameter() {
    PiActionId piActionId = PiActionId.of(MOD_NW_DST);
    PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101));
    final PiAction piAction = PiAction.builder().withId(piActionId).withParameter(piActionParam).build();
    assertThat(piAction, is(notNullValue()));
    assertThat(piAction.id(), is(piActionId));
    assertThat(piAction.type(), is(PiTableAction.Type.ACTION));
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) Test(org.junit.Test)

Example 5 with PiActionId

use of org.onosproject.net.pi.model.PiActionId in project onos by opennetworkinglab.

the class MyTunnelApp method insertTunnelIngressRule.

/**
 * Generates and insert a flow rule to perform the tunnel INGRESS function
 * for the given switch, destination IP address and tunnel ID.
 *
 * @param switchId  switch ID
 * @param dstIpAddr IP address to forward inside the tunnel
 * @param tunId     tunnel ID
 */
private void insertTunnelIngressRule(DeviceId switchId, IpAddress dstIpAddr, int tunId) {
    PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");
    // Longest prefix match on IPv4 dest address.
    PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
    PiCriterion match = PiCriterion.builder().matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32).build();
    PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);
    PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
    PiAction action = PiAction.builder().withId(ingressActionId).withParameter(tunIdParam).build();
    log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}", switchId, tunnelIngressTableId, match, action);
    insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiActionId (org.onosproject.net.pi.model.PiActionId)10 Test (org.junit.Test)6 PiActionParamId (org.onosproject.net.pi.model.PiActionParamId)5 PiTableId (org.onosproject.net.pi.model.PiTableId)5 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 PiActionModel (org.onosproject.net.pi.model.PiActionModel)3 PiMatchFieldId (org.onosproject.net.pi.model.PiMatchFieldId)3 PiMatchFieldModel (org.onosproject.net.pi.model.PiMatchFieldModel)3 PiTableModel (org.onosproject.net.pi.model.PiTableModel)3 PiAction (org.onosproject.net.pi.runtime.PiAction)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 ArrayList (java.util.ArrayList)2 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)2 PiActionParamModel (org.onosproject.net.pi.model.PiActionParamModel)2 PiActionProfileId (org.onosproject.net.pi.model.PiActionProfileId)2