org.onosproject.net.pi.model.PiTableId Java Examples

The following examples show how to use org.onosproject.net.pi.model.PiTableId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private static TrafficTreatment nextIdOrTreatment(
        ForwardingObjective obj, PiTableId tableId)
        throws FabricPipelinerException {
    if (obj.nextId() == null) {
        return obj.treatment();
    } else {
        if (!NEXT_ID_ACTIONS.containsKey(tableId)) {
            throw new FabricPipelinerException(format(
                    "BUG? no next_id action set for table %s", tableId));
        }
        return DefaultTrafficTreatment.builder()
                .piTableAction(
                        setNextIdAction(obj.nextId(),
                                        NEXT_ID_ACTIONS.get(tableId)))
                .build();
    }
}
 
Example #2
Source File: Utils.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
public static GroupDescription buildSelectGroup(DeviceId deviceId,
                                                String tableId,
                                                String actionProfileId,
                                                int groupId,
                                                Collection<PiAction> actions,
                                                ApplicationId appId) {

    final GroupKey groupKey = new PiGroupKey(
            PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId);
    final List<GroupBucket> buckets = actions.stream()
            .map(action -> DefaultTrafficTreatment.builder()
                    .piTableAction(action).build())
            .map(DefaultGroupBucket::createSelectGroupBucket)
            .collect(Collectors.toList());
    return new DefaultGroupDescription(
            deviceId,
            GroupDescription.Type.SELECT,
            new GroupBuckets(buckets),
            groupKey,
            groupId,
            appId);
}
 
Example #3
Source File: MyTunnelApp.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts a flow rule in the system that using a PI criterion and action.
 *
 * @param switchId    switch ID
 * @param tableId     table ID
 * @param piCriterion PI criterion
 * @param piAction    PI action
 */
private void insertPiFlowRule(DeviceId switchId, PiTableId tableId,
                              PiCriterion piCriterion, PiAction piAction) {
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(switchId)
            .forTable(tableId)
            .fromApp(appId)
            .withPriority(FLOW_RULE_PRIORITY)
            .makePermanent()
            .withSelector(DefaultTrafficSelector.builder()
                                  .matchPi(piCriterion).build())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .build();
    flowRuleService.applyFlowRules(rule);
}
 
Example #4
Source File: P4RuntimeTableStatisticsDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: P4RuntimeTableStatisticsDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the number of added flows in each table.
 *
 * @param model pipeline model
 * @param interpreter pipeline interpreter
 * @param rules flow rules in this device
 * @return hashmap containing matched packet counting for each table
 */
private Map<PiTableId, Integer> piFlowRuleCounting(PiPipelineModel model, PiPipelineInterpreter interpreter,
                                                   List<FlowEntry> rules) {
    Map<PiTableId, Integer> piTableFlowCount = new HashMap<>();
    for (PiTableModel tableModel : model.tables()) {
        piTableFlowCount.put(tableModel.id(), 0);
    }
    for (FlowEntry f : rules) {
        if (f.state() == FlowEntry.FlowEntryState.ADDED) {
            PiTableId piTableId = getPiTableId(f, interpreter);
            if (piTableId != null) {
                piTableFlowCount.put(piTableId, piTableFlowCount.get(piTableId) + 1);
            }
        }
    }
    return piTableFlowCount;
}
 
Example #6
Source File: P4RuntimeTableStatisticsDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the number of matched packets for each table.
 *
 * @param model pipeline model
 * @param interpreter pipeline interpreter
 * @param rules flow rules in this device
 * @return hashmap containing flow rule counting for each table
 */
private Map<PiTableId, Long> piMatchedCounting(PiPipelineModel model, PiPipelineInterpreter interpreter,
                                               List<FlowEntry> rules) {
    Map<PiTableId, Long> piTableMatchCount = new HashMap<>();
    for (PiTableModel tableModel : model.tables()) {
        piTableMatchCount.put(tableModel.id(), (long) 0);
    }
    for (FlowEntry f : rules) {
        if (f.state() == FlowEntry.FlowEntryState.ADDED) {
            PiTableId piTableId = getPiTableId(f, interpreter);
            if (piTableId != null) {
                piTableMatchCount.put(piTableId, piTableMatchCount.get(piTableId) + f.packets());
            }
        }
    }
    return piTableMatchCount;
}
 
Example #7
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 6 votes vote down vote up
static PiAction mapFilteringTreatment(TrafficTreatment treatment, PiTableId tableId)
        throws PiInterpreterException {

    if (!tableId.equals(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN)) {
        // Mapping for other tables of the filtering block must be handled
        // in the pipeliner.
        tableException(tableId);
    }

    // VLAN_POP action is equivalent to the permit action (VLANs pop is done anyway)
    if (isNoAction(treatment) || isFilteringPopAction(treatment)) {
        // Permit action if table is ingress_port_vlan;
        return nop(tableId);
    }

    final ModVlanIdInstruction setVlanInst = (ModVlanIdInstruction) l2InstructionOrFail(
            treatment, VLAN_ID, tableId);
    return PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN)
            .withParameter(new PiActionParam(
                    FabricConstants.VLAN_ID, setVlanInst.vlanId().toShort()))
            .build();
}
 
Example #8
Source File: Utils.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
public static GroupDescription buildSelectGroup(DeviceId deviceId,
                                                String tableId,
                                                String actionProfileId,
                                                int groupId,
                                                Collection<PiAction> actions,
                                                ApplicationId appId) {

    final GroupKey groupKey = new PiGroupKey(
            PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId);
    final List<GroupBucket> buckets = actions.stream()
            .map(action -> DefaultTrafficTreatment.builder()
                    .piTableAction(action).build())
            .map(DefaultGroupBucket::createSelectGroupBucket)
            .collect(Collectors.toList());
    return new DefaultGroupDescription(
            deviceId,
            GroupDescription.Type.SELECT,
            new GroupBuckets(buckets),
            groupKey,
            groupId,
            appId);
}
 
Example #9
Source File: P4RuntimeTableStatisticsDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of table statistics for P4 switch.
 *
 * @param piTableFlowCount hashmap containing the number of flow rules for each table
 * @param piTableMatchCount hashmap containing the number of matched packets for each table
 * @param model pipeline model
 * @param deviceId device ID
 * @return list of table statistics for P4 switch
 */
private List<TableStatisticsEntry> generatePiFlowTableStatistics(Map<PiTableId, Integer> piTableFlowCount,
                                                                   Map<PiTableId, Long> piTableMatchCount,
                                                                   PiPipelineModel model, DeviceId deviceId) {
    List<TableStatisticsEntry> tableStatsList;
    Iterator it = piTableFlowCount.entrySet().iterator();
    tableStatsList = new ArrayList<>();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        TableStatisticsEntry tableStat = DefaultTableStatisticsEntry.builder()
                .withDeviceId(deviceId)
                .withTableId((PiTableId) pair.getKey())
                .withActiveFlowEntries(piTableFlowCount.get(pair.getKey()))
                .withPacketsMatchedCount(piTableMatchCount.get(pair.getKey()))
                .withMaxSize(model.table((PiTableId) pair.getKey()).get().maxSize()).build();
        tableStatsList.add(tableStat);
        it.remove();
    }
    return tableStatsList;
}
 
Example #10
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 6 votes vote down vote up
private PiAction mapNextVlanTreatment(TrafficTreatment treatment, PiTableId tableId)
        throws PiInterpreterException {
    final List<ModVlanIdInstruction> modVlanIdInst = l2InstructionsOrFail(treatment, VLAN_ID, tableId)
            .stream().map(i -> (ModVlanIdInstruction) i).collect(Collectors.toList());
    if (modVlanIdInst.size() == 1) {
        return PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
                .withParameter(new PiActionParam(
                        FabricConstants.VLAN_ID,
                        modVlanIdInst.get(0).vlanId().toShort()))
                .build();
    }
    if (modVlanIdInst.size() == 2 && capabilities.supportDoubleVlanTerm()) {
        return PiAction.builder()
                .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_DOUBLE_VLAN)
                .withParameter(new PiActionParam(
                        FabricConstants.INNER_VLAN_ID,
                        modVlanIdInst.get(0).vlanId().toShort()))
                .withParameter(new PiActionParam(
                        FabricConstants.OUTER_VLAN_ID,
                        modVlanIdInst.get(1).vlanId().toShort()))
                .build();
    }
    throw new PiInterpreterException("Too many VLAN instructions");
}
 
Example #11
Source File: FabricInterpreter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
        throws PiInterpreterException {
    if (FILTERING_CTRL_TBLS.contains(piTableId)) {
        return treatmentInterpreter.mapFilteringTreatment(treatment, piTableId);
    } else if (FORWARDING_CTRL_TBLS.contains(piTableId)) {
        return treatmentInterpreter.mapForwardingTreatment(treatment, piTableId);
    } else if (ACL_CTRL_TBLS.contains(piTableId)) {
        return treatmentInterpreter.mapAclTreatment(treatment, piTableId);
    } else if (NEXT_CTRL_TBLS.contains(piTableId)) {
        return treatmentInterpreter.mapNextTreatment(treatment, piTableId);
    } else if (E_NEXT_CTRL_TBLS.contains(piTableId)) {
        return treatmentInterpreter.mapEgressNextTreatment(treatment, piTableId);
    } else {
        throw new PiInterpreterException(format(
                "Treatment mapping not supported for table '%s'", piTableId));
    }
}
 
Example #12
Source File: TableEntryCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private P4RuntimeOuterClass.TableEntry.Builder keyMsgBuilder(
        PiTableId tableId, PiMatchKey matchKey, OptionalInt priority,
        PiPipeconf pipeconf, P4InfoBrowser browser)
        throws P4InfoBrowser.NotFoundException, CodecException {
    final P4RuntimeOuterClass.TableEntry.Builder tableEntryMsgBuilder =
            P4RuntimeOuterClass.TableEntry.newBuilder();
    final P4InfoOuterClass.Preamble tablePreamble = browser.tables()
            .getByName(tableId.id()).getPreamble();
    // Table id.
    tableEntryMsgBuilder.setTableId(tablePreamble.getId());
    // Field matches.
    if (matchKey.equals(PiMatchKey.EMPTY)) {
        tableEntryMsgBuilder.setIsDefaultAction(true);
    } else {
        tableEntryMsgBuilder.addAllMatch(
                CODECS.fieldMatch().encodeAll(
                        matchKey.fieldMatches(),
                        tablePreamble, pipeconf));
    }
    // Priority.
    priority.ifPresent(tableEntryMsgBuilder::setPriority);
    return tableEntryMsgBuilder;
}
 
Example #13
Source File: ReadRequestImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public P4RuntimeReadClient.ReadRequest directMeterCells(PiTableId tableId) {
    try {
        requestMsg.addEntities(
                P4RuntimeOuterClass.Entity.newBuilder()
                        .setDirectMeterEntry(
                                P4RuntimeOuterClass.DirectMeterEntry.newBuilder()
                                        .setTableEntry(
                                                P4RuntimeOuterClass.TableEntry
                                                        .newBuilder()
                                                        .setTableId(p4TableId(tableId))
                                                        .build())
                                        .build())
                        .build());
    } catch (InternalRequestException e) {
        log.warn("Unable to read direct meter cells for table '{}' from {}: {}",
                 tableId, client.deviceId(), e.getMessage());
    }
    return this;
}
 
Example #14
Source File: PiUtils.java    From onos with Apache License 2.0 6 votes vote down vote up
static PiTableId translateTableId(TableId tableId, PiPipelineInterpreter interpreter)
        throws PiTranslationException {
    switch (tableId.type()) {
        case PIPELINE_INDEPENDENT:
            return (PiTableId) tableId;
        case INDEX:
            IndexTableId indexId = (IndexTableId) tableId;
            if (interpreter == null) {
                throw new PiTranslationException(format(
                        "Unable to map table ID '%d' from index to PI: missing interpreter", indexId.id()));
            } else if (!interpreter.mapFlowRuleTableId(indexId.id()).isPresent()) {
                throw new PiTranslationException(format(
                        "Unable to map table ID '%d' from index to PI: missing ID in interpreter", indexId.id()));
            } else {
                return interpreter.mapFlowRuleTableId(indexId.id()).get();
            }
        default:
            throw new PiTranslationException(format(
                    "Unrecognized table ID type %s", tableId.type().name()));
    }
}
 
Example #15
Source File: P4InfoParser.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Map<Integer, PiMeterModel> parseDirectMeters(P4Info p4info)
        throws P4InfoParserException {
    final Map<Integer, PiMeterModel> meterMap = Maps.newHashMap();
    for (DirectMeter dirMeterMsg : p4info.getDirectMetersList()) {
        meterMap.put(
                dirMeterMsg.getPreamble().getId(),
                new P4MeterModel(
                        PiMeterId.of(dirMeterMsg.getPreamble().getName()),
                        PiMeterType.DIRECT,
                        mapMeterSpecUnit(dirMeterMsg.getSpec()),
                        PiTableId.of(getTableName(dirMeterMsg.getDirectTableId(), p4info)),
                        NO_SIZE));
    }
    return meterMap;
}
 
Example #16
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void cleanup() {
    if (!setupBehaviour()) {
        return;
    }

    StreamSupport.stream(flowRuleService.getFlowEntries(
            data().deviceId()).spliterator(), false)
            .filter(f -> f.table().type() == TableId.Type.PIPELINE_INDEPENDENT)
            .filter(f -> TABLES_TO_CLEANUP.contains((PiTableId) f.table()))
            .forEach(flowRuleService::removeFlowRules);
}
 
Example #17
Source File: P4InfoParser.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Map<Integer, PiActionProfileModel> parseActionProfiles(P4Info p4info)
        throws P4InfoParserException {
    final Map<Integer, PiActionProfileModel> actProfileMap = Maps.newHashMap();
    for (ActionProfile actProfileMsg : p4info.getActionProfilesList()) {
        final ImmutableSet.Builder<PiTableId> tableIdSetBuilder = ImmutableSet.builder();
        for (int tableId : actProfileMsg.getTableIdsList()) {
            tableIdSetBuilder.add(PiTableId.of(getTableName(tableId, p4info)));
        }
        // TODO: we should copy all annotations to model classes for later
        //  use in the PI framework.
        // This is a temporary workaround to the inability of p4c to
        // correctly interpret P4Runtime-defined max_group_size annotation:
        // https://s3-us-west-2.amazonaws.com/p4runtime/docs/master/
        // P4Runtime-Spec.html#sec-p4info-action-profile
        final String maxSizeAnnString = findAnnotation(
                "max_group_size", actProfileMsg.getPreamble());
        final int maxSizeAnn = maxSizeAnnString != null
                ? Integer.valueOf(maxSizeAnnString) : 0;
        final int maxGroupSize;
        if (actProfileMsg.getMaxGroupSize() == 0 && maxSizeAnn != 0) {
            log.warn("Found valid 'max_group_size' annotation for " +
                             "ActionProfile {}, using that...",
                     actProfileMsg.getPreamble().getName());
            maxGroupSize = maxSizeAnn;
        } else {
            maxGroupSize = actProfileMsg.getMaxGroupSize();
        }

        actProfileMap.put(
                actProfileMsg.getPreamble().getId(),
                new P4ActionProfileModel(
                        PiActionProfileId.of(actProfileMsg.getPreamble().getName()),
                        tableIdSetBuilder.build(),
                        actProfileMsg.getWithSelector(),
                        actProfileMsg.getSize(),
                        maxGroupSize));
    }
    return actProfileMap;
}
 
Example #18
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
static PiAction mapAclTreatment(TrafficTreatment treatment, PiTableId tableId)
        throws PiInterpreterException {
    if (isNoAction(treatment)) {
        return nop(tableId);
    }
    treatmentException(
            tableId, treatment,
            "unsupported treatment");

    // This function will never return null
    return null;
}
 
Example #19
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
static PiAction mapEgressNextTreatment(
        TrafficTreatment treatment, PiTableId tableId)
        throws PiInterpreterException {
    l2InstructionOrFail(treatment, VLAN_POP, tableId);
    return PiAction.builder()
            .withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN)
            .build();

}
 
Example #20
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Instruction l2InstructionOrFail(
        TrafficTreatment treatment,
        L2ModificationInstruction.L2SubType subType, PiTableId tableId)
        throws PiInterpreterException {
    final Instruction inst = l2Instruction(treatment, subType);
    if (inst == null) {
        treatmentException(tableId, treatment, format("missing %s instruction", subType));
    }
    return inst;
}
 
Example #21
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private int selectGroup(NextObjective obj,
                        ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
    final List<DefaultNextTreatment> defaultNextTreatments =
            defaultNextTreatments(obj.nextTreatments(), true);
    final List<TrafficTreatment> piTreatments = Lists.newArrayList();

    for (DefaultNextTreatment t : defaultNextTreatments) {
        // Map treatment to PI...
        piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId));
        // ...and handle egress if necessary.
        handleEgress(obj, t.treatment(), resultBuilder, false);
    }

    final List<GroupBucket> bucketList = piTreatments.stream()
            .map(DefaultGroupBucket::createSelectGroupBucket)
            .collect(Collectors.toList());

    final int groupId = obj.id();
    final PiGroupKey groupKey = new PiGroupKey(
            hashedTableId,
            FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR,
            groupId);

    resultBuilder.addGroup(new DefaultGroupDescription(
            deviceId,
            GroupDescription.Type.SELECT,
            new GroupBuckets(bucketList),
            groupKey,
            groupId,
            obj.appId()));

    return groupId;
}
 
Example #22
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Instruction instructionOrFail(
        TrafficTreatment treatment, Instruction.Type type, PiTableId tableId)
        throws PiInterpreterException {
    final Instruction inst = instruction(treatment, type);
    if (inst == null) {
        treatmentException(tableId, treatment, format("missing %s instruction", type));
    }
    return inst;
}
 
Example #23
Source File: AbstractObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
public FlowRule flowRule(T obj, PiTableId tableId, TrafficSelector selector,
                         TrafficTreatment treatment, Integer priority)
        throws FabricPipelinerException {
    return DefaultFlowRule.builder()
            .withSelector(selector)
            .withTreatment(mapTreatmentToPiIfNeeded(treatment, tableId))
            .forTable(tableId)
            .makePermanent()
            .withPriority(priority)
            .forDevice(deviceId)
            .fromApp(obj.appId())
            .build();
}
 
Example #24
Source File: FabricTreatmentInterpreter.java    From onos with Apache License 2.0 5 votes vote down vote up
private static PiAction mapNextXconnect(
        TrafficTreatment treatment, PiTableId tableId)
        throws PiInterpreterException {
    final PortNumber outPort = ((OutputInstruction) instructionOrFail(
            treatment, OUTPUT, tableId)).port();
    return PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_XCONNECT)
            .withParameter(new PiActionParam(
                    FabricConstants.PORT_NUM, outPort.toLong()))
            .build();
}
 
Example #25
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
                                    int matchValue, PiActionId actionId, ApplicationId appId) {
    PiCriterion instCriterion = PiCriterion.builder()
            .matchExact(matchFieldId, matchValue)
            .build();
    TrafficSelector instSelector = DefaultTrafficSelector.builder()
            .matchPi(instCriterion)
            .build();
    PiAction instAction = PiAction.builder()
            .withId(actionId)
            .build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(instAction)
            .build();

    FlowRule instFlowRule = DefaultFlowRule.builder()
            .withSelector(instSelector)
            .withTreatment(instTreatment)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(tableId)
            .fromApp(appId)
            .build();

    flowRuleService.applyFlowRules(instFlowRule);
}
 
Example #26
Source File: ReadRequestImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public P4RuntimeReadClient.ReadRequest tableEntries(PiTableId tableId) {
    try {
        doTableEntry(tableId, false);
    } catch (InternalRequestException e) {
        log.warn("Unable to read entries for table '{}' from {}: {}",
                 tableId, client.deviceId(), e.getMessage());
    }
    return this;
}
 
Example #27
Source File: ReadRequestImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public P4RuntimeReadClient.ReadRequest defaultTableEntry(PiTableId tableId) {
    try {
        doTableEntry(tableId, true);
    } catch (InternalRequestException e) {
        log.warn("Unable to read default entry for table '{}' from {}: {}",
                 tableId, client.deviceId(), e.getMessage());
    }
    return this;
}
 
Example #28
Source File: PiFlowRuleTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a PI action out of the given treatment, optionally using the given
 * interpreter.
 */
private static PiTableAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
                                         PiTableId tableId)
        throws PiTranslationException {

    PiTableAction piTableAction = null;

    // If treatment has only one instruction of type PiInstruction, use that.
    for (Instruction inst : treatment.allInstructions()) {
        if (inst.type() == Instruction.Type.PROTOCOL_INDEPENDENT) {
            if (treatment.allInstructions().size() == 1) {
                piTableAction = ((PiInstruction) inst).action();
            } else {
                throw new PiTranslationException(format(
                        "Unable to translate treatment, found multiple instructions " +
                                "of which one is protocol-independent: %s", treatment));
            }
        }
    }

    if (piTableAction == null && interpreter != null) {
        // No PiInstruction, use interpreter to build action.
        try {
            piTableAction = interpreter.mapTreatment(treatment, tableId);
        } catch (PiPipelineInterpreter.PiInterpreterException e) {
            throw new PiTranslationException(
                    "Interpreter was unable to translate treatment. " + e.getMessage());
        }
    }

    return piTableAction;
}
 
Example #29
Source File: P4CounterModel.java    From onos with Apache License 2.0 5 votes vote down vote up
P4CounterModel(PiCounterId id, PiCounterType counterType,
               Unit unit, PiTableId table, long size) {
    this.id = id;
    this.counterType = counterType;
    this.unit = unit;
    this.table = table;
    this.size = size;
}
 
Example #30
Source File: ReadRequestImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private void doTableEntry(PiTableId piTableId, boolean defaultEntries)
        throws InternalRequestException {
    checkNotNull(piTableId);
    final P4RuntimeOuterClass.Entity entityMsg = P4RuntimeOuterClass.Entity
            .newBuilder()
            .setTableEntry(
                    P4RuntimeOuterClass.TableEntry.newBuilder()
                            .setTableId(p4TableId(piTableId))
                            .setIsDefaultAction(defaultEntries)
                            .setCounterData(P4RuntimeOuterClass.CounterData
                                                    .getDefaultInstance())
                            .build())
            .build();
    requestMsg.addEntities(entityMsg);
}