Java Code Examples for org.onosproject.net.pi.runtime.PiActionProfileGroupId#of()

The following examples show how to use org.onosproject.net.pi.runtime.PiActionProfileGroupId#of() . 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: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    final String tableId = "IngressPipeImpl.routing_v6_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example 2
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l3_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example 3
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "MODIFY ME";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("MODIFY ME"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example 4
Source File: TableEntryCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
private PiTableAction decodeTableActionMsg(
        P4RuntimeOuterClass.TableAction tableActionMsg, PiPipeconf pipeconf)
        throws CodecException {
    P4RuntimeOuterClass.TableAction.TypeCase typeCase = tableActionMsg.getTypeCase();
    switch (typeCase) {
        case ACTION:
            P4RuntimeOuterClass.Action actionMsg = tableActionMsg.getAction();
            return CODECS.action().decode(
                    actionMsg, null, pipeconf);
        case ACTION_PROFILE_GROUP_ID:
            return PiActionProfileGroupId.of(
                    tableActionMsg.getActionProfileGroupId());
        case ACTION_PROFILE_MEMBER_ID:
            return PiActionProfileMemberId.of(
                    tableActionMsg.getActionProfileMemberId());
        default:
            throw new CodecException(
                    format("Decoding of table action type %s not implemented",
                           typeCase.name()));
    }
}
 
Example 5
Source File: InstructionCodecTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the encoding of protocol-independent instructions.
 */
@Test
public void piInstructionEncodingTest() {
    PiActionId actionId = PiActionId.of("set_egress_port");
    PiActionParamId actionParamId = PiActionParamId.of("port");
    PiActionParam actionParam = new PiActionParam(actionParamId, ImmutableByteSequence.copyFrom(10));
    PiTableAction action = PiAction.builder().withId(actionId).withParameter(actionParam).build();
    final PiInstruction actionInstruction = Instructions.piTableAction(action);
    final ObjectNode actionInstructionJson =
            instructionCodec.encode(actionInstruction, context);
    assertThat(actionInstructionJson, matchesInstruction(actionInstruction));

    PiTableAction actionGroupId = PiActionProfileGroupId.of(10);
    final PiInstruction actionGroupIdInstruction = Instructions.piTableAction(actionGroupId);
    final ObjectNode actionGroupIdInstructionJson =
            instructionCodec.encode(actionGroupIdInstruction, context);
    assertThat(actionGroupIdInstructionJson, matchesInstruction(actionGroupIdInstruction));

    PiTableAction actionProfileMemberId = PiActionProfileMemberId.of(10);
    final PiInstruction actionProfileMemberIdInstruction = Instructions.piTableAction(actionProfileMemberId);
    final ObjectNode actionProfileMemberIdInstructionJson =
            instructionCodec.encode(actionProfileMemberIdInstruction, context);
    assertThat(actionProfileMemberIdInstructionJson, matchesInstruction(actionProfileMemberIdInstruction));
}
 
Example 6
Source File: FabricNextPipelinerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Test program ecmp output group for Hashed table.
 */
@Test
public void testHashedOutput() throws Exception {
    PiAction piAction1 = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED)
            .withParameter(new PiActionParam(
                    FabricConstants.SMAC, ROUTER_MAC.toBytes()))
            .withParameter(new PiActionParam(
                    FabricConstants.DMAC, HOST_MAC.toBytes()))
            .withParameter(new PiActionParam(
                    FabricConstants.PORT_NUM, PORT_1.toLong()))
            .build();
    PiAction piAction2 = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED)
            .withParameter(new PiActionParam(
                    FabricConstants.SMAC, ROUTER_MAC.toBytes()))
            .withParameter(new PiActionParam(
                    FabricConstants.DMAC, HOST_MAC.toBytes()))
            .withParameter(new PiActionParam(
                    FabricConstants.PORT_NUM, PORT_1.toLong()))
            .build();
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder()
            .piTableAction(piAction1)
            .build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder()
            .piTableAction(piAction2)
            .build();

    NextObjective nextObjective = DefaultNextObjective.builder()
            .withId(NEXT_ID_1)
            .withPriority(PRIORITY)
            .withMeta(VLAN_META)
            .addTreatment(treatment1)
            .addTreatment(treatment2)
            .withType(NextObjective.Type.HASHED)
            .makePermanent()
            .fromApp(APP_ID)
            .add();

    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);

    // Expected hashed table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
            .build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
            .matchPi(nextIdCriterion)
            .build();
    PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(actionGroupId)
            .build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder()
            .forDevice(DEVICE_ID)
            .fromApp(APP_ID)
            .makePermanent()
            // FIXME: currently next objective doesn't support priority, ignore this
            .withPriority(0)
            .forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED)
            .withSelector(nextIdSelector)
            .withTreatment(treatment)
            .build();

    // Expected group
    List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
    List<GroupBucket> buckets = treatments.stream()
            .map(DefaultGroupBucket::createSelectGroupBucket)
            .collect(Collectors.toList());
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED,
                                         FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR,
                                         NEXT_ID_1);
    GroupDescription expectedGroup = new DefaultGroupDescription(
            DEVICE_ID,
            GroupDescription.Type.SELECT,
            groupBuckets,
            groupKey,
            NEXT_ID_1,
            APP_ID
    );

    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
            .addFlowRule(expectedFlowRule)
            .addFlowRule(vlanMetaFlowRule)
            .addGroup(expectedGroup)
            .build();

    assertEquals(expectedTranslation, actualTranslation);

}