org.onosproject.net.pi.runtime.PiGroupKey Java Examples

The following examples show how to use org.onosproject.net.pi.runtime.PiGroupKey. 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: Utils.java    From ngsdn-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 #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: 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 #4
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 #5
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);

}