Search in sources :

Example 6 with PiPipelineModel

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

the class P4RuntimeTableStatisticsDiscovery method getTableStatistics.

@Override
public List<TableStatisticsEntry> getTableStatistics() {
    if (!setupBehaviour("getTableStatistics()")) {
        return Collections.emptyList();
    }
    FlowRuleService flowService = handler().get(FlowRuleService.class);
    PiPipelineInterpreter interpreter = getInterpreter(handler());
    PiPipelineModel model = pipeconf.pipelineModel();
    List<TableStatisticsEntry> tableStatsList;
    List<FlowEntry> rules = newArrayList(flowService.getFlowEntries(deviceId));
    Map<PiTableId, Integer> piTableFlowCount = piFlowRuleCounting(model, interpreter, rules);
    Map<PiTableId, Long> piTableMatchCount = piMatchedCounting(model, interpreter, rules);
    tableStatsList = generatePiFlowTableStatistics(piTableFlowCount, piTableMatchCount, model, deviceId);
    return tableStatsList;
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 7 with PiPipelineModel

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

the class P4InfoParserTest method testParse.

/**
 * Tests parse method.
 * @throws Exception if equality group objects dose not match as expected
 */
@Test
public void testParse() throws Exception {
    // Generate two PiPipelineModels from the same p4Info file
    PiPipelineModel model = P4InfoParser.parse(p4InfoUrl);
    PiPipelineModel sameAsModel = P4InfoParser.parse(p4InfoUrl);
    // Check equality
    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);
    }
    List<Table> tableMsgs = p4info.getTablesList();
    PiTableId table0Id = PiTableId.of(tableMsgs.get(0).getPreamble().getName());
    PiTableId wcmpTableId = PiTableId.of(tableMsgs.get(1).getPreamble().getName());
    PiTableId wcmpTableOneShotId = PiTableId.of(tableMsgs.get(2).getPreamble().getName());
    // parse tables
    PiTableModel table0Model = model.table(table0Id).orElse(null);
    PiTableModel wcmpTableModel = model.table(wcmpTableId).orElse(null);
    PiTableModel wcmpTableOneShotModel = model.table(wcmpTableOneShotId).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();
    // Check existence
    assertThat("model parsed value is null", table0Model, notNullValue());
    assertThat("model parsed value is null", wcmpTableModel, notNullValue());
    assertThat("model parsed value is null", wcmpTableOneShotModel, notNullValue());
    assertThat("Incorrect size for table0 size", table0Model.maxSize(), is(equalTo(DEFAULT_MAX_TABLE_SIZE)));
    assertThat("Incorrect size for wcmp_table size", wcmpTableModel.maxSize(), is(equalTo(DEFAULT_MAX_TABLE_SIZE)));
    assertThat("Incorrect size for wcmp_table_one_shot size", wcmpTableOneShotModel.maxSize(), is(equalTo(DEFAULT_MAX_TABLE_SIZE)));
    // Check one-shot annotation
    assertThat("error parsing one-shot annotation", wcmpTableModel.oneShotOnly(), is(false));
    assertThat("error parsing one-shot annotation", wcmpTableOneShotModel.oneShotOnly(), is(true));
    // 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;
            default:
                Assert.fail();
                return;
        }
        piMatchFieldList.add(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldIter.getName()), matchFieldIter.getBitwidth(), piMatchType));
    }
    // Check MatchFields size
    assertThat("Incorrect size for matchFields", table0Model.matchFields().size(), is(equalTo(9)));
    // Check if matchFields are in order
    assertThat("Incorrect order for matchFields", table0Model.matchFields(), IsIterableContainingInOrder.contains(piMatchFieldList.get(0), piMatchFieldList.get(1), piMatchFieldList.get(2), piMatchFieldList.get(3), piMatchFieldList.get(4), piMatchFieldList.get(5), piMatchFieldList.get(6), piMatchFieldList.get(7), piMatchFieldList.get(8)));
    assertThat("Incorrect size for matchFields", wcmpTableModel.matchFields().size(), is(equalTo(1)));
    // check if matchFields are in order
    matchFieldList = tableMsgs.get(1).getMatchFieldsList();
    assertThat("Incorrect order for matchFields", wcmpTableModel.matchFields(), IsIterableContainingInOrder.contains(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldList.get(0).getName()), matchFieldList.get(0).getBitwidth(), PiMatchType.EXACT)));
    // check table0 actionsRefs
    List<ActionRef> actionRefList = tableMsgs.get(0).getActionRefsList();
    assertThat("Incorrect size for actionRefs", actionRefList.size(), is(equalTo(4)));
    // create action instances
    PiActionId actionId = PiActionId.of("set_egress_port");
    PiActionParamId piActionParamId = PiActionParamId.of("port");
    int bitWitdth = 9;
    PiActionParamModel actionParamModel = new P4ActionParamModel(piActionParamId, bitWitdth);
    ImmutableMap<PiActionParamId, PiActionParamModel> params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
    PiActionModel setEgressPortAction = 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());
    actionId = PiActionId.of("NoAction");
    PiActionModel noAction = new P4ActionModel(actionId, new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().build());
    actionId = PiActionId.of("table0_control.set_next_hop_id");
    piActionParamId = PiActionParamId.of("next_hop_id");
    bitWitdth = 16;
    actionParamModel = new P4ActionParamModel(piActionParamId, bitWitdth);
    params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
    PiActionModel setNextHopIdAction = new P4ActionModel(actionId, params);
    // check table0 actions
    assertThat("action dose not match", table0Model.actions(), IsIterableContainingInAnyOrder.containsInAnyOrder(setEgressPortAction, sendToCpuAction, setNextHopIdAction, dropAction));
    // check wcmp_table actions
    assertThat("actions dose not match", wcmpTableModel.actions(), IsIterableContainingInAnyOrder.containsInAnyOrder(setEgressPortAction, noAction));
    PiActionModel table0DefaultAction = table0Model.constDefaultAction().orElse(null);
    new EqualsTester().addEqualityGroup(table0DefaultAction, dropAction).testEquals();
    // Check existence
    assertThat("model parsed value is null", table0DefaultAction, notNullValue());
    // parse action profiles
    PiTableId tableId = PiTableId.of("wcmp_control.wcmp_table");
    ImmutableSet<PiTableId> tableIds = new ImmutableSet.Builder<PiTableId>().add(tableId).build();
    PiActionProfileId actionProfileId = PiActionProfileId.of("wcmp_control.wcmp_selector");
    PiActionProfileModel wcmpSelector3 = new P4ActionProfileModel(actionProfileId, tableIds, true, DEFAULT_MAX_ACTION_PROFILE_SIZE, DEFAULT_MAX_GROUP_SIZE);
    PiActionProfileModel wcmpSelector = model.actionProfiles(actionProfileId).orElse(null);
    PiActionProfileModel wcmpSelector2 = sameAsModel.actionProfiles(actionProfileId).orElse(null);
    new EqualsTester().addEqualityGroup(wcmpSelector, wcmpSelector2, wcmpSelector3).testEquals();
    // Check existence
    assertThat("model parsed value is null", wcmpSelector, notNullValue());
    assertThat("Incorrect value for actions profiles", model.actionProfiles(), containsInAnyOrder(wcmpSelector));
    // ActionProfiles size
    assertThat("Incorrect size for action profiles", model.actionProfiles().size(), is(equalTo(1)));
    // parse counters
    PiCounterModel ingressPortCounterModel = model.counter(PiCounterId.of("port_counters_ingress.ingress_port_counter")).orElse(null);
    PiCounterModel egressPortCounterModel = model.counter(PiCounterId.of("port_counters_egress.egress_port_counter")).orElse(null);
    PiCounterModel table0CounterModel = model.counter(PiCounterId.of("table0_control.table0_counter")).orElse(null);
    PiCounterModel wcmpTableCounterModel = model.counter(PiCounterId.of("wcmp_control.wcmp_table_counter")).orElse(null);
    PiCounterModel ingressPortCounterModel2 = sameAsModel.counter(PiCounterId.of("port_counters_ingress.ingress_port_counter")).orElse(null);
    PiCounterModel egressPortCounterModel2 = sameAsModel.counter(PiCounterId.of("port_counters_egress.egress_port_counter")).orElse(null);
    PiCounterModel table0CounterModel2 = sameAsModel.counter(PiCounterId.of("table0_control.table0_counter")).orElse(null);
    PiCounterModel wcmpTableCounterModel2 = sameAsModel.counter(PiCounterId.of("wcmp_control.wcmp_table_counter")).orElse(null);
    new EqualsTester().addEqualityGroup(ingressPortCounterModel, ingressPortCounterModel2).addEqualityGroup(egressPortCounterModel, egressPortCounterModel2).addEqualityGroup(table0CounterModel, table0CounterModel2).addEqualityGroup(wcmpTableCounterModel, wcmpTableCounterModel2).testEquals();
    assertThat("model parsed value is null", ingressPortCounterModel, notNullValue());
    assertThat("model parsed value is null", egressPortCounterModel, notNullValue());
    assertThat("model parsed value is null", table0CounterModel, notNullValue());
    assertThat("model parsed value is null", wcmpTableCounterModel, notNullValue());
    // Parse meters
    Collection<PiMeterModel> meterModel = model.meters();
    Collection<PiMeterModel> meterModel2 = sameAsModel.meters();
    assertThat("model parsed meter collection should be empty", meterModel.isEmpty(), is(true));
    assertThat("model parsed meter collection should be empty", meterModel2.isEmpty(), is(true));
    // parse packet operations
    PiPacketOperationModel packetInOperationalModel = model.packetOperationModel(PiPacketOperationType.PACKET_IN).orElse(null);
    PiPacketOperationModel packetOutOperationalModel = model.packetOperationModel(PiPacketOperationType.PACKET_OUT).orElse(null);
    PiPacketOperationModel packetInOperationalModel2 = sameAsModel.packetOperationModel(PiPacketOperationType.PACKET_IN).orElse(null);
    PiPacketOperationModel packetOutOperationalModel2 = sameAsModel.packetOperationModel(PiPacketOperationType.PACKET_OUT).orElse(null);
    new EqualsTester().addEqualityGroup(packetInOperationalModel, packetInOperationalModel2).addEqualityGroup(packetOutOperationalModel, packetOutOperationalModel2).testEquals();
    // Check existence
    assertThat("model parsed value is null", packetInOperationalModel, notNullValue());
    assertThat("model parsed value is null", packetOutOperationalModel, notNullValue());
}
Also used : PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiActionId(org.onosproject.net.pi.model.PiActionId) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiCounterModel(org.onosproject.net.pi.model.PiCounterModel) ArrayList(java.util.ArrayList) PiPacketOperationModel(org.onosproject.net.pi.model.PiPacketOperationModel) 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) EqualsTester(com.google.common.testing.EqualsTester) PiMeterModel(org.onosproject.net.pi.model.PiMeterModel) PiActionParamModel(org.onosproject.net.pi.model.PiActionParamModel) PiActionProfileId(org.onosproject.net.pi.model.PiActionProfileId) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) P4Info(p4.config.v1.P4InfoOuterClass.P4Info) PiActionProfileModel(org.onosproject.net.pi.model.PiActionProfileModel) PiMatchFieldModel(org.onosproject.net.pi.model.PiMatchFieldModel) Test(org.junit.Test)

Example 8 with PiPipelineModel

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

the class PiPipelineModelCodec method encode.

@Override
public ObjectNode encode(PiPipelineModel pipeline, CodecContext context) {
    ObjectNode result = context.mapper().createObjectNode();
    ArrayNode actions = result.putArray(ACTIONS);
    pipeline.tables().stream().flatMap(piTableModel -> piTableModel.actions().stream()).distinct().map(action -> context.encode(action, PiActionModel.class)).forEach(actions::add);
    ArrayNode tables = result.putArray(TABLES);
    pipeline.tables().stream().map(table -> context.encode(table, PiTableModel.class)).forEach(tables::add);
    return result;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CodecContext(org.onosproject.codec.CodecContext) PiTableModel(org.onosproject.net.pi.model.PiTableModel) PiActionModel(org.onosproject.net.pi.model.PiActionModel) JsonCodec(org.onosproject.codec.JsonCodec) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 9 with PiPipelineModel

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

the class AbstractP4RuntimePipelineProgrammable method getDefaultEntries.

/**
 * Once the pipeconf is set successfully, we should store all the default entries
 * before notify other service to prevent overwriting the default entries.
 * Default entries may be used in P4RuntimeFlowRuleProgrammable.
 * <p>
 * This method returns a completable future with the result of the pipeconf set
 * operation (which might not be true).
 *
 * @param pipeconfSet completable future for setting pipeconf
 * @param pipeconf pipeconf
 * @return completable future eventually true if the pipeconf set successfully
 */
private CompletableFuture<Boolean> getDefaultEntries(CompletableFuture<Boolean> pipeconfSet, PiPipeconf pipeconf) {
    if (!driverBoolProperty(SUPPORT_DEFAULT_TABLE_ENTRY, DEFAULT_SUPPORT_DEFAULT_TABLE_ENTRY)) {
        return pipeconfSet;
    }
    return pipeconfSet.thenApply(setSuccess -> {
        if (!setSuccess) {
            return setSuccess;
        }
        final P4RuntimeDefaultEntryMirror mirror = handler().get(P4RuntimeDefaultEntryMirror.class);
        final PiPipelineModel pipelineModel = pipeconf.pipelineModel();
        final P4RuntimeReadClient.ReadRequest request = client.read(p4DeviceId, pipeconf);
        // Read default entries from all non-constant tables.
        // Ignore constant default entries.
        pipelineModel.tables().stream().filter(t -> !t.isConstantTable()).forEach(t -> {
            if (!t.constDefaultAction().isPresent()) {
                request.defaultTableEntry(t.id());
            }
        });
        final P4RuntimeReadClient.ReadResponse response = request.submitSync();
        mirror.sync(deviceId, response.all(PiTableEntry.class));
        return true;
    });
}
Also used : P4RuntimeReadClient(org.onosproject.p4runtime.api.P4RuntimeReadClient) DEFAULT_SUPPORT_DEFAULT_TABLE_ENTRY(org.onosproject.drivers.p4runtime.P4RuntimeDriverProperties.DEFAULT_SUPPORT_DEFAULT_TABLE_ENTRY) Logger(org.slf4j.Logger) PiPipelineProgrammable(org.onosproject.net.behaviour.PiPipelineProgrammable) P4RuntimeReadClient(org.onosproject.p4runtime.api.P4RuntimeReadClient) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) SUPPORT_DEFAULT_TABLE_ENTRY(org.onosproject.drivers.p4runtime.P4RuntimeDriverProperties.SUPPORT_DEFAULT_TABLE_ENTRY) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) ByteBuffer(java.nio.ByteBuffer) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) P4RuntimeDefaultEntryMirror(org.onosproject.drivers.p4runtime.mirror.P4RuntimeDefaultEntryMirror) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) P4RuntimeDefaultEntryMirror(org.onosproject.drivers.p4runtime.mirror.P4RuntimeDefaultEntryMirror) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel)

Example 10 with PiPipelineModel

use of org.onosproject.net.pi.model.PiPipelineModel in project TFG by mattinelorza.

the class PipeconfLoader method buildPipeconf.

private PiPipeconf buildPipeconf() throws P4InfoParserException {
    final URL p4InfoUrl = PipeconfLoader.class.getResource(P4INFO_PATH);
    final URL bmv2JsonUrlUrl = PipeconfLoader.class.getResource(BMV2_JSON_PATH);
    final PiPipelineModel pipelineModel = P4InfoParser.parse(p4InfoUrl);
    return DefaultPiPipeconf.builder().withId(PIPECONF_ID).withPipelineModel(pipelineModel).addBehaviour(PiPipelineInterpreter.class, InterpreterImpl.class).addBehaviour(Pipeliner.class, PipelinerImpl.class).addExtension(P4_INFO_TEXT, p4InfoUrl).addExtension(BMV2_JSON, bmv2JsonUrlUrl).build();
}
Also used : Pipeliner(org.onosproject.net.behaviour.Pipeliner) URL(java.net.URL) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel)

Aggregations

PiPipelineModel (org.onosproject.net.pi.model.PiPipelineModel)10 PiActionModel (org.onosproject.net.pi.model.PiActionModel)4 PiTableId (org.onosproject.net.pi.model.PiTableId)4 PiTableModel (org.onosproject.net.pi.model.PiTableModel)4 URL (java.net.URL)3 Test (org.junit.Test)3 PiActionParamModel (org.onosproject.net.pi.model.PiActionParamModel)3 PiMatchFieldModel (org.onosproject.net.pi.model.PiMatchFieldModel)3 PiMatchType (org.onosproject.net.pi.model.PiMatchType)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PiActionId (org.onosproject.net.pi.model.PiActionId)2 PiPipelineInterpreter (org.onosproject.net.pi.model.PiPipelineInterpreter)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 EqualsTester (com.google.common.testing.EqualsTester)1 String.format (java.lang.String.format)1