org.onosproject.net.group.GroupBuckets Java Examples

The following examples show how to use org.onosproject.net.group.GroupBuckets. 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: VirtualNetworkGroupManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private Group createSouthboundGroupEntry(GroupId gId,
                                         List<PortNumber> ports,
                                         long referenceCount, DeviceId deviceId) {
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(ports);

    List<GroupBucket> buckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber)
                .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
                .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
                .pushMpls()
                .setMpls(MplsLabel.mplsLabel(106));
        buckets.add(DefaultGroupBucket.createSelectGroupBucket(
                tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    StoredGroupEntry group = new DefaultGroup(
            gId, deviceId, Group.Type.SELECT, groupBuckets);
    group.setReferenceCount(referenceCount);
    return group;
}
 
Example #2
Source File: GroupsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Removes buckets from a group using the group service.
 *
 * @param deviceIdString device Id
 * @param appCookieString application cookie
 * @param bucketIds comma separated list of bucket Ids to remove
 */
private void removeGroupBuckets(String deviceIdString, String appCookieString, String bucketIds) {
    DeviceId deviceId = DeviceId.deviceId(deviceIdString);
    final GroupKey groupKey = createKey(appCookieString);
    GroupService groupService = get(GroupService.class);

    Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);

    List<GroupBucket> groupBucketList = new ArrayList<>();

    List<String> bucketsToRemove = ImmutableList.copyOf(bucketIds.split(","));

    bucketsToRemove.forEach(
            bucketIdToRemove -> {
                group.buckets().buckets().stream()
                        .filter(bucket -> Integer.toString(bucket.hashCode()).equals(bucketIdToRemove))
                        .forEach(groupBucketList::add);
            }
    );
    groupService.removeBucketsFromGroup(deviceId, groupKey,
                                        new GroupBuckets(groupBucketList), groupKey,
                                        group.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: 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 #5
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 #6
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a indirect group contains pop_vlan and punt actions.
 * <p>
 * Using group instead of immediate action to ensure that
 * the copy of packet on the data plane is not affected by the pop vlan action.
 */
private void initPopVlanPuntGroup() {
    GroupKey groupKey = popVlanPuntGroupKey();
    TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder()
            .popVlan().punt().build();
    GroupBucket bucket =
            DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment);
    GroupDescription groupDesc =
            new DefaultGroupDescription(
                    deviceId,
                    GroupDescription.Type.INDIRECT,
                    new GroupBuckets(Collections.singletonList(bucket)),
                    groupKey,
                    POP_VLAN_PUNT_GROUP_ID,
                    driverId);
    groupService.addGroup(groupDesc);

    log.info("Initialized pop vlan punt group on {}", deviceId);
}
 
Example #7
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Mpls group of type swap.
 *
 * @param nextGroupId the next group in the chain
 * @param subtype the mpls swap label group subtype
 * @param index the index of the group
 * @param mplsLabel the mpls label to swap
 * @param applicationId the application id
 * @return the group description
 */
protected GroupDescription createMplsSwap(int nextGroupId,
                                          OfdpaMplsGroupSubType subtype,
                                          int index,
                                          MplsLabel mplsLabel,
                                          ApplicationId applicationId) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setMpls(mplsLabel);
    // We point the group to the next group.
    treatment.group(new GroupId(nextGroupId));
    GroupBucket groupBucket = DefaultGroupBucket
            .createIndirectGroupBucket(treatment.build());
    // Finally we build the group description.
    int groupId = makeMplsLabelGroupId(subtype, index);
    GroupKey groupKey = new DefaultGroupKey(
            Ofdpa2Pipeline.appKryo.serialize(index));
    return new DefaultGroupDescription(
            deviceId,
            INDIRECT,
            new GroupBuckets(Collections.singletonList(groupBucket)),
            groupKey,
            groupId,
            applicationId);
}
 
Example #8
Source File: SimpleGroupStoreTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private void testRemoveBuckets(GroupKey currKey, GroupKey removeKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    List<GroupBucket> buckets = new ArrayList<>();
    buckets.addAll(existingGroup.buckets().buckets());

    List<GroupBucket> toRemoveBuckets = new ArrayList<>();

    // There should be 4 buckets in the current group
    toRemoveBuckets.add(buckets.remove(0));
    toRemoveBuckets.add(buckets.remove(1));
    GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets);

    GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets);
    InternalGroupStoreDelegate removeGroupDescDelegate =
            new InternalGroupStoreDelegate(removeKey,
                                           remainingGroupBuckets,
                                           GroupEvent.Type.GROUP_UPDATE_REQUESTED);
    simpleGroupStore.setDelegate(removeGroupDescDelegate);
    simpleGroupStore.updateGroupDescription(D1,
                                            currKey,
                                            UpdateType.REMOVE,
                                            toRemoveGroupBuckets,
                                            removeKey);
    simpleGroupStore.unsetDelegate(removeGroupDescDelegate);
}
 
Example #9
Source File: GroupManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Group createSouthboundGroupEntry(GroupId gId,
                                         List<PortNumber> ports,
                                         long referenceCount, DeviceId deviceId) {
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(ports);

    List<GroupBucket> buckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber)
                .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
                .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
                .pushMpls()
                .setMpls(MplsLabel.mplsLabel(106));
        buckets.add(DefaultGroupBucket.createSelectGroupBucket(
                tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    StoredGroupEntry group = new DefaultGroup(
            gId, deviceId, Group.Type.SELECT, groupBuckets);
    group.setReferenceCount(referenceCount);
    return group;
}
 
Example #10
Source File: PointToPointIntentCompiler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void updateFailoverGroup(PointToPointIntent pointIntent) {
    DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
    GroupKey groupKey = makeGroupKey(pointIntent.id());
    Group group = waitForGroup(deviceId, groupKey);
    Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
    while (groupIterator.hasNext()) {
        GroupBucket bucket = groupIterator.next();
        Instruction individualInstruction = bucket.treatment().allInstructions().get(0);
        if (individualInstruction instanceof Instructions.OutputInstruction) {
            Instructions.OutputInstruction outInstruction =
                    (Instructions.OutputInstruction) individualInstruction;
            Port port = deviceService.getPort(deviceId, outInstruction.port());
            if (port == null || !port.isEnabled()) {
                GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
                groupService.removeBucketsFromGroup(deviceId, groupKey,
                                                    removeBuckets, groupKey,
                                                    pointIntent.appId());
            }
        }
    }
}
 
Example #11
Source File: PointToPointIntentCompiler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new failover group with the initial ports of the links
 * from the primary and backup path.
 *
 * @param links         links from the primary path
 * @param backupLinks   links from the backup path
 * @param intent        intent from which this call originates
 */
private void createFailoverTreatmentGroup(List<Link> links,
                                          List<Link> backupLinks,
                                          PointToPointIntent intent) {

    List<GroupBucket> buckets = new ArrayList<>();

    TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder();
    ConnectPoint src = links.get(0).src();
    tBuilderIn.setOutput(src.port());

    TrafficTreatment.Builder tBuilderIn2 = DefaultTrafficTreatment.builder();
    ConnectPoint src2 = backupLinks.get(0).src();
    tBuilderIn2.setOutput(src2.port());

    buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null));
    buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn2.build(), src2.port(), null));

    GroupBuckets groupBuckets = new GroupBuckets(buckets);

    GroupDescription groupDesc = new DefaultGroupDescription(src.deviceId(), Group.Type.FAILOVER,
                                     groupBuckets, makeGroupKey(intent.id()), null, intent.appId());
    log.trace("adding failover group {}", groupDesc);
    groupService.addGroup(groupDesc);
}
 
Example #12
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private DefaultGroupDescription createCloneGroup(
        ApplicationId appId,
        int cloneSessionId,
        PortNumber outPort) {
    final GroupKey groupKey = new DefaultGroupKey(
            FabricPipeliner.KRYO.serialize(cloneSessionId));

    final List<GroupBucket> bucketList = ImmutableList.of(
            createCloneGroupBucket(DefaultTrafficTreatment.builder()
                                           .setOutput(outPort)
                                           .build()));
    final DefaultGroupDescription cloneGroup = new DefaultGroupDescription(
            deviceId, GroupDescription.Type.CLONE,
            new GroupBuckets(bucketList),
            groupKey, cloneSessionId, appId);
    return cloneGroup;
}
 
Example #13
Source File: SelectGroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Updates groupBuckets in select type group.
 *
 * @param deviceId target device id to update the group
 * @param nodeList updated gateway node list for bucket action
 * @param isInsert update type(add or remove)
 */
public void updateGatewayGroupBuckets(DeviceId deviceId,
                                      List<GatewayNode> nodeList,
                                      boolean isInsert) {
    List<GroupBucket> bucketList = generateBucketsForSelectGroup(deviceId, nodeList);
    GroupKey groupKey = getGroupKey(deviceId);
    if (isInsert) {
        groupService.addBucketsToGroup(
                deviceId,
                groupKey,
                new GroupBuckets(bucketList),
                groupKey, appId);
    } else {
        groupService.removeBucketsFromGroup(
                deviceId,
                groupKey,
                new GroupBuckets(bucketList),
                groupKey, appId);
    }
}
 
Example #14
Source File: OFAgentVirtualGroupBucketEntryBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a GroupBuckets.
 *
 * @return GroupBuckets object, a list of GroupBuckets
 */
public GroupBuckets build() {
    List<GroupBucket> bucketList = Lists.newArrayList();

    for (OFBucket bucket: ofBuckets) {
        TrafficTreatment treatment = buildTreatment(bucket.getActions());
        // TODO: Use GroupBucketEntry
        GroupBucket groupBucket = null;
        switch (type) {
            case INDIRECT:
                groupBucket =
                        DefaultGroupBucket.createIndirectGroupBucket(treatment);
                break;
            case SELECT:
                groupBucket =
                        DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight());
                break;
            case FF:
                PortNumber port =
                        PortNumber.portNumber(bucket.getWatchPort().getPortNumber());
                GroupId groupId =
                        new GroupId(bucket.getWatchGroup().getGroupNumber());
                groupBucket =
                        DefaultGroupBucket.createFailoverGroupBucket(treatment,
                                port, groupId);
                break;
            case ALL:
                groupBucket =
                        DefaultGroupBucket.createAllGroupBucket(treatment);
                break;
            default:
                log.error("Unsupported Group type : {}", type);
        }
        if (groupBucket != null) {
            bucketList.add(groupBucket);
        }
    }
    return new GroupBuckets(bucketList);
}
 
Example #15
Source File: Utils.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private static GroupDescription buildReplicationGroup(
        ApplicationId appId,
        DeviceId deviceId,
        int groupId,
        Collection<PortNumber> ports,
        boolean isClone) {

    checkNotNull(deviceId);
    checkNotNull(appId);
    checkArgument(!ports.isEmpty());

    final GroupKey groupKey = new DefaultGroupKey(
            ByteBuffer.allocate(4).putInt(groupId).array());

    final List<GroupBucket> bucketList = ports.stream()
            .map(p -> DefaultTrafficTreatment.builder()
                    .setOutput(p).build())
            .map(t -> isClone ? createCloneGroupBucket(t)
                    : createAllGroupBucket(t))
            .collect(Collectors.toList());

    return new DefaultGroupDescription(
            deviceId,
            isClone ? GroupDescription.Type.CLONE : GroupDescription.Type.ALL,
            new GroupBuckets(bucketList),
            groupKey, groupId, appId);
}
 
Example #16
Source File: SelectGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates select type group description according to given deviceId.
 *
 * @param srcDeviceId target device id for group description
 * @param nodeList gateway node list for bucket action
 * @return created select type group description
 */
public GroupId createGatewayGroup(DeviceId srcDeviceId, List<GatewayNode> nodeList) {
    List<GroupBucket> bucketList = generateBucketsForSelectGroup(srcDeviceId, nodeList);
    GroupId groupId = getGroupId(srcDeviceId);
    GroupDescription groupDescription = new DefaultGroupDescription(
            srcDeviceId,
            GroupDescription.Type.SELECT,
            new GroupBuckets(bucketList),
            getGroupKey(srcDeviceId),
            groupId.id(),
            appId);

    groupService.addGroup(groupDescription);
    return groupId;
}
 
Example #17
Source File: VirtualNetworkGroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void addBucketsToGroup(DeviceId deviceId, GroupKey oldCookie, GroupBuckets buckets,
                              GroupKey newCookie, ApplicationId appId) {
    store.updateGroupDescription(networkId(),
                                 deviceId,
                                 oldCookie,
                                 VirtualNetworkGroupStore.UpdateType.ADD,
                                 buckets,
                                 newCookie);
}
 
Example #18
Source File: K8sGroupRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setBuckets(ApplicationId appId, DeviceId deviceId, int groupId,
                       List<GroupBucket> buckets, boolean install) {

    if (install) {
        groupService.addBucketsToGroup(deviceId, getGroupKey(groupId),
                new GroupBuckets(buckets), getGroupKey(groupId), appId);
    } else {
        groupService.removeBucketsFromGroup(deviceId, getGroupKey(groupId),
                new GroupBuckets(buckets), getGroupKey(groupId), appId);
    }
}
 
Example #19
Source File: VirtualNetworkGroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void removeBucketsFromGroup(DeviceId deviceId, GroupKey oldCookie,
                                   GroupBuckets buckets, GroupKey newCookie,
                                   ApplicationId appId) {
    store.updateGroupDescription(networkId(),
                                 deviceId,
                                 oldCookie,
                                 VirtualNetworkGroupStore.UpdateType.REMOVE,
                                 buckets,
                                 newCookie);

}
 
Example #20
Source File: VirtualNetworkGroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setBucketsForGroup(DeviceId deviceId,
                               GroupKey oldCookie,
                               GroupBuckets buckets,
                               GroupKey newCookie,
                               ApplicationId appId) {
    store.updateGroupDescription(networkId(),
                                 deviceId,
                                 oldCookie,
                                 VirtualNetworkGroupStore.UpdateType.SET,
                                 buckets,
                                 newCookie);
}
 
Example #21
Source File: OpenstackGroupRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setBuckets(ApplicationId appId, DeviceId deviceId,
                       int groupId, List<GroupBucket> buckets, boolean install) {
    if (install) {
        groupService.addBucketsToGroup(deviceId, getGroupKey(groupId),
                new GroupBuckets(buckets), getGroupKey(groupId), appId);
        log.info("Adding buckets for group rule {}", groupId);
    } else {
        groupService.removeBucketsFromGroup(deviceId, getGroupKey(groupId),
                new GroupBuckets(buckets), getGroupKey(groupId), appId);
        log.info("Removing buckets for group rule {}", groupId);
    }
}
 
Example #22
Source File: GroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Append buckets to existing group. The caller can optionally
 * associate a new cookie during this updation. GROUP_UPDATED or
 * GROUP_UPDATE_FAILED notifications would be provided along with
 * cookie depending on the result of the operation on the device.
 *
 * @param deviceId  device identifier
 * @param oldCookie cookie to be used to retrieve the existing group
 * @param buckets   immutable list of group bucket to be added
 * @param newCookie immutable cookie to be used post update operation
 * @param appId     Application Id
 */
@Override
public void addBucketsToGroup(DeviceId deviceId,
                              GroupKey oldCookie,
                              GroupBuckets buckets,
                              GroupKey newCookie,
                              ApplicationId appId) {
    checkPermission(GROUP_WRITE);
    store.updateGroupDescription(deviceId,
                                 oldCookie,
                                 UpdateType.ADD,
                                 buckets,
                                 newCookie);
}
 
Example #23
Source File: GroupManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Remove buckets from existing group. The caller can optionally
 * associate a new cookie during this updation. GROUP_UPDATED or
 * GROUP_UPDATE_FAILED notifications would be provided along with
 * cookie depending on the result of the operation on the device.
 *
 * @param deviceId  device identifier
 * @param oldCookie cookie to be used to retrieve the existing group
 * @param buckets   immutable list of group bucket to be removed
 * @param newCookie immutable cookie to be used post update operation
 * @param appId     Application Id
 */
@Override
public void removeBucketsFromGroup(DeviceId deviceId,
                                   GroupKey oldCookie,
                                   GroupBuckets buckets,
                                   GroupKey newCookie,
                                   ApplicationId appId) {
    checkPermission(GROUP_WRITE);
    store.updateGroupDescription(deviceId,
                                 oldCookie,
                                 UpdateType.REMOVE,
                                 buckets,
                                 newCookie);
}
 
Example #24
Source File: Utils.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
private static GroupDescription buildReplicationGroup(
        ApplicationId appId,
        DeviceId deviceId,
        int groupId,
        Collection<PortNumber> ports,
        boolean isClone) {

    checkNotNull(deviceId);
    checkNotNull(appId);
    checkArgument(!ports.isEmpty());

    final GroupKey groupKey = new DefaultGroupKey(
            ByteBuffer.allocate(4).putInt(groupId).array());

    final List<GroupBucket> bucketList = ports.stream()
            .map(p -> DefaultTrafficTreatment.builder()
                    .setOutput(p).build())
            .map(t -> isClone ? createCloneGroupBucket(t)
                    : createAllGroupBucket(t))
            .collect(Collectors.toList());

    return new DefaultGroupDescription(
            deviceId,
            isClone ? GroupDescription.Type.CLONE : GroupDescription.Type.ALL,
            new GroupBuckets(bucketList),
            groupKey, groupId, appId);
}
 
Example #25
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 #26
Source File: OpenFlowGroupProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void groupModFailure() {
    TestOpenFlowGroupProviderService testProviderService =
            (TestOpenFlowGroupProviderService) providerService;

    GroupId groupId = new GroupId(1);
    List<GroupBucket> bucketList = Lists.newArrayList();
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(PortNumber.portNumber(1));
    GroupBucket bucket =
            DefaultGroupBucket.createSelectGroupBucket(builder.build());
    bucketList.add(bucket);
    GroupBuckets buckets = new GroupBuckets(bucketList);
    List<GroupOperation> operationList = Lists.newArrayList();
    GroupOperation operation = GroupOperation.createAddGroupOperation(groupId,
            GroupDescription.Type.SELECT, buckets);
    operationList.add(operation);
    GroupOperations operations = new GroupOperations(operationList);

    provider.performGroupOperation(deviceId, operations);

    OFGroupModFailedErrorMsg.Builder errorBuilder =
            OFFactories.getFactory(OFVersion.OF_13).errorMsgs().buildGroupModFailedErrorMsg();
    OFGroupMod.Builder groupBuilder = OFFactories.getFactory(OFVersion.OF_13).buildGroupModify();
    groupBuilder.setGroupType(OFGroupType.ALL);
    groupBuilder.setGroup(OFGroup.of(1));
    errorBuilder.setCode(OFGroupModFailedCode.GROUP_EXISTS);
    errorBuilder.setXid(provider.getXidAndAdd(0) - 1);

    controller.processPacket(dpid1, errorBuilder.build());

    assertNotNull("Operation failed should not be null",
            testProviderService.failedOperation);
}
 
Example #27
Source File: OpenFlowGroupProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void addGroup() {

    GroupId groupId = new GroupId(1);

    List<GroupBucket> bucketList = Lists.newArrayList();
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(PortNumber.portNumber(1));
    GroupBucket bucket =
            DefaultGroupBucket.createSelectGroupBucket(builder.build());
    bucketList.add(bucket);
    GroupBuckets buckets = new GroupBuckets(bucketList);

    List<GroupOperation> operationList = Lists.newArrayList();
    GroupOperation operation = GroupOperation.createAddGroupOperation(groupId,
            GroupDescription.Type.SELECT, buckets);
    operationList.add(operation);
    GroupOperations operations = new GroupOperations(operationList);

    provider.performGroupOperation(deviceId, operations);

    final Dpid dpid = Dpid.dpid(deviceId.uri());
    TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid);
    assertNotNull("Switch should not be nul", sw);
    assertNotNull("OFGroupMsg should not be null", sw.msg);

}
 
Example #28
Source File: Utils.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private static GroupDescription buildReplicationGroup(
        ApplicationId appId,
        DeviceId deviceId,
        int groupId,
        Collection<PortNumber> ports,
        boolean isClone) {

    checkNotNull(deviceId);
    checkNotNull(appId);
    checkArgument(!ports.isEmpty());

    final GroupKey groupKey = new DefaultGroupKey(
            ByteBuffer.allocate(4).putInt(groupId).array());

    final List<GroupBucket> bucketList = ports.stream()
            .map(p -> DefaultTrafficTreatment.builder()
                    .setOutput(p).build())
            .map(t -> isClone ? createCloneGroupBucket(t)
                    : createAllGroupBucket(t))
            .collect(Collectors.toList());

    return new DefaultGroupDescription(
            deviceId,
            isClone ? GroupDescription.Type.CLONE : GroupDescription.Type.ALL,
            new GroupBuckets(bucketList),
            groupKey, groupId, appId);
}
 
Example #29
Source File: GroupModBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
private GroupModBuilder(GroupBuckets buckets, GroupId groupId,
                         GroupDescription.Type type, OFFactory factory,
                         Optional<Long> xid, Optional<DriverService> driverService) {
    this.buckets = buckets;
    this.groupId = groupId;
    this.type = type;
    this.factory = factory;
    this.xid = xid.orElse((long) 0);
    this.driverService = driverService;
}
 
Example #30
Source File: K8sGroupRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId,
                    Type type, List<GroupBucket> buckets, boolean install) {

    if (install) {
        GroupDescription groupDesc = new DefaultGroupDescription(deviceId,
                type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
        groupService.addGroup(groupDesc);
    } else {
        groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
    }
}