org.onosproject.net.group.GroupBucket Java Examples

The following examples show how to use org.onosproject.net.group.GroupBucket. 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: GroupModBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the GroupAdd OF message.
 *
 * @return GroupAdd OF message
 */
public OFGroupAdd buildGroupAdd() {
    // Build group add
    List<OFBucket> ofBuckets = new ArrayList<OFBucket>();
    for (GroupBucket bucket: buckets.buckets()) {
        OFBucket ofBucket = ofBucketBuilder(bucket).build();
        ofBuckets.add(ofBucket);
    }
    // Build the msg and return
    return factory.buildGroupAdd()
            .setGroup(OFGroup.of(groupId.id()))
            .setBuckets(ofBuckets)
            .setGroupType(getOFGroupType(type))
            .setXid(xid)
            .build();
 }
 
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: GroupViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public String format(Object value) {
    StringBuilder sb = new StringBuilder();
    List<GroupBucket> buckets = (List<GroupBucket>) value;

    if (buckets.isEmpty()) {
        return "(No buckets for this group)";
    }

    for (GroupBucket b : buckets) {
        sb.append("Bytes: ")
                .append(b.bytes())
                .append(" Packets: ")
                .append(b.packets())
                .append(" Actions: ")
                .append(b.treatment().allInstructions())
                .append(BREAK);
    }

    return sb.toString();
}
 
Example #7
Source File: GroupBucketCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectNode encode(GroupBucket bucket, CodecContext context) {
    checkNotNull(bucket, "Driver cannot be null");

    ObjectNode result = context.mapper().createObjectNode()
            .put(TYPE, bucket.type().toString())
            .put(WEIGHT, bucket.weight())
            .put(PACKETS, bucket.packets())
            .put(BYTES, bucket.bytes())
            .put(BUCKET_ID, bucket.hashCode());

    if (bucket.watchPort() != null) {
        result.put(WATCH_PORT, bucket.watchPort().toString());
    }

    if (bucket.watchGroup() != null) {
        result.put(WATCH_GROUP, bucket.watchGroup().toString());
    }

    if (bucket.treatment() != null) {
        result.set(TREATMENT, context.codec(TrafficTreatment.class).encode(bucket.treatment(), context));
    }

    return result;
}
 
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: 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 #10
Source File: OfdpaGroupHandlerUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
static List<GroupBucket> createL3MulticastBucket(List<GroupInfo> groupInfos) {
    List<GroupBucket> l3McastBuckets = new ArrayList<>();
    // For each inner group
    groupInfos.forEach(groupInfo -> {
        // Points to L3 interface group if there is one.
        // Otherwise points to L2 interface group directly.
        GroupDescription nextGroupDesc = (groupInfo.nextGroupDesc() != null) ?
                groupInfo.nextGroupDesc() : groupInfo.innerMostGroupDesc();
        TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();
        ttb.group(new GroupId(nextGroupDesc.givenGroupId()));
        GroupBucket abucket = DefaultGroupBucket.createAllGroupBucket(ttb.build());
        l3McastBuckets.add(abucket);
    });
    // Done return the new list of buckets
    return l3McastBuckets;
}
 
Example #11
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 #12
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 #13
Source File: RulePopulatorUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the group bucket with given traffic treatment and group type.
 *
 * @param treatment     traffic treatment
 * @param type          group type
 * @param weight        weight (only for select type)
 * @return group bucket
 */
public static GroupBucket buildGroupBucket(TrafficTreatment treatment,
                                           GroupDescription.Type type, short weight) {
    switch (type) {
        case ALL:
            return DefaultGroupBucket.createAllGroupBucket(treatment);
        case SELECT:
            if (weight == -1) {
                return DefaultGroupBucket.createSelectGroupBucket(treatment);
            } else {
                return DefaultGroupBucket.createSelectGroupBucket(treatment, weight);
            }
        case INDIRECT:
            return DefaultGroupBucket.createIndirectGroupBucket(treatment);
        default:
            return null;
    }
}
 
Example #14
Source File: RulePopulatorUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the group bucket with given traffic treatment and group type.
 *
 * @param treatment     traffic treatment
 * @param type          group type
 * @param weight        weight (only for select type)
 * @return group bucket
 */
public static GroupBucket buildGroupBucket(TrafficTreatment treatment,
                                           Type type, short weight) {
    switch (type) {
        case ALL:
            return DefaultGroupBucket.createAllGroupBucket(treatment);
        case SELECT:
            if (weight == -1) {
                return DefaultGroupBucket.createSelectGroupBucket(treatment);
            } else {
                return DefaultGroupBucket.createSelectGroupBucket(treatment, weight);
            }
        case INDIRECT:
            return DefaultGroupBucket.createIndirectGroupBucket(treatment);
        default:
            return null;
    }
}
 
Example #15
Source File: GroupsListCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private void printGroups(DeviceId deviceId, List<Group> groups) {
    print("deviceId=%s, groupCount=%s", deviceId, groups.size());

    if (countOnly) {
        return;
    }

    for (Group group : groups) {
        print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(),
              group.bytes(), group.packets(), group.appId().name(), group.referenceCount());
        int i = 0;
        for (GroupBucket bucket:group.buckets().buckets()) {
            print(BUCKET_FORMAT, Integer.toHexString(group.id().id()), ++i,
                  bucket.bytes(), bucket.packets(), bucket.weight(),
                  bucket.treatment().allInstructions());
        }
    }
}
 
Example #16
Source File: DistributedGroupStore.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the stats of an existing group entry.
 *
 * @param group the new stats
 * @param existing the existing group
 */
private void updateGroupEntryStatsInternal(Group group, StoredGroupEntry existing) {
    for (GroupBucket bucket : group.buckets().buckets()) {
        Optional<GroupBucket> matchingBucket =
                existing.buckets().buckets()
                        .stream()
                        .filter((existingBucket) -> (existingBucket.equals(bucket)))
                        .findFirst();
        if (matchingBucket.isPresent()) {
            ((StoredGroupBucketEntry) matchingBucket.
                    get()).setPackets(bucket.packets());
            ((StoredGroupBucketEntry) matchingBucket.
                    get()).setBytes(bucket.bytes());
        } else {
            log.warn("updateGroupEntryStatsInternal: No matching bucket {}" +
                    " to update stats", bucket);
        }
    }
    existing.setLife(group.life());
    existing.setPackets(group.packets());
    existing.setBytes(group.bytes());
    existing.setReferenceCount(group.referenceCount());
    existing.setFailedRetryCount(0);
}
 
Example #17
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 #18
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 #19
Source File: OpenFlowGroupProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the first live port in the failover group's bucket
 * has failed over.
 *
 * @param group       failover group to be checked for failover
 * @param id          device ID of switch whose port's status changed
 * @param portNumber  port number of port that was disabled
 * @return            whether the failover group experienced failover
 */
private boolean checkFailoverGroup(Group group, DeviceId id,
                                   PortNumber portNumber) {
    boolean portReached = false;
    boolean portEnabled = false;
    Iterator<GroupBucket> bIterator = group.buckets().buckets().iterator();
    GroupBucket bucket;
    while (bIterator.hasNext() && !portReached) {
        bucket = bIterator.next();
        if (deviceService.getPort(id, bucket.watchPort()).isEnabled()) {
            portEnabled = true;
        }
        if (bucket.watchPort().equals(portNumber)) {
            portReached = true;
        }
    }
    return portReached && !portEnabled;
}
 
Example #20
Source File: GroupModBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
  * Builds the GroupMod OF message.
  *
  * @return GroupMod OF message
  */
 public OFGroupMod buildGroupMod() {
     // Build group mod
     List<OFBucket> ofBuckets = new ArrayList<OFBucket>();
     for (GroupBucket bucket: buckets.buckets()) {
         OFBucket ofBucket = ofBucketBuilder(bucket).build();
         ofBuckets.add(ofBucket);
     }
     // Build the msg and return
     return factory.buildGroupModify()
             .setGroup(OFGroup.of(groupId.id()))
             .setBuckets(ofBuckets)
             .setGroupType(getOFGroupType(type))
             .setXid(xid)
             .build();
}
 
Example #21
Source File: GroupModBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
private OFBucket.Builder ofBucketBuilder(GroupBucket bucket) {
    OFBucket.Builder bucketBuilder = factory.buildBucket();
    List<OFAction> actions = buildActions(bucket.treatment());
    bucketBuilder.setActions(actions);
    if (type == GroupDescription.Type.SELECT) {
        bucketBuilder.setWeight(bucket.weight());
    }
    if (type == GroupDescription.Type.FAILOVER && bucket.watchPort() != null) {
        bucketBuilder.setWatchPort(OFPort.of((int) bucket.watchPort().toLong()));
    } else {
        bucketBuilder.setWatchPort(OFPort.ANY);
    }
    if (type == GroupDescription.Type.FAILOVER && bucket.watchGroup() != null) {
        bucketBuilder.setWatchGroup(OFGroup.of(bucket.watchGroup().id()));
    } else {
        bucketBuilder.setWatchGroup(OFGroup.ANY);
    }
    return bucketBuilder;
}
 
Example #22
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 #23
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 #24
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 #25
Source File: PiGroupTranslatorImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static GroupBucket selectOutputBucket(int portNum) {
    ImmutableByteSequence paramVal = copyFrom(portNum);
    PiActionParam param = new PiActionParam(PORT, paramVal);
    PiTableAction action = PiAction.builder()
            .withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT)
            .withParameter(param).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .add(Instructions.piTableAction(action))
            .build();
    return DefaultGroupBucket.createSelectGroupBucket(treatment);
}
 
Example #26
Source File: T3CliUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
private static StringBuilder printGroups(StaticPacketTrace trace, boolean verbose, ConnectPoint connectPoint,
                                         StringBuilder tracePrint) {
    List<GroupsInDevice> groupsInDevice = trace.getGroupOuputs(connectPoint.deviceId());
    if (groupsInDevice != null) {
        tracePrint.append("    Groups");
        tracePrint.append("\n");
        groupsInDevice.forEach(output -> {
            if (output.getOutput().equals(connectPoint)) {
                output.getGroups().forEach(group -> {
                    if (verbose) {
                        tracePrint.append("    " + String.format(GROUP_FORMAT, Integer.toHexString(group.id().id()),
                                group.state(), group.type(), group.bytes(), group.packets(),
                                group.appId().name(), group.referenceCount()));
                        tracePrint.append("\n");
                        int i = 0;
                        for (GroupBucket bucket : group.buckets().buckets()) {
                            tracePrint.append("    " + String.format(GROUP_BUCKET_FORMAT,
                                    Integer.toHexString(group.id().id()),
                                    ++i, bucket.bytes(), bucket.packets(),
                                    bucket.treatment().allInstructions()));
                            tracePrint.append("\n");
                        }
                    } else {
                        tracePrint.append("       groupId=" + group.id());
                        tracePrint.append("\n");
                    }
                });
                tracePrint.append("    Outgoing Packet " + output.getFinalPacket());
                tracePrint.append("\n");
            }
        });
    }
    return tracePrint;
}
 
Example #27
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 #28
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 #29
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 #30
Source File: K8sServiceHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private GroupBucket buildBuckets(DeviceId deviceId, String podIpStr, ServicePort sp) {
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setIpDst(IpAddress.valueOf(podIpStr));

    int targetPort;
    if (sp.getTargetPort().getIntVal() == null) {
        Pod pod = podByIp(k8sPodService, podIpStr);
        targetPort = portNumberByName(pod, sp.getTargetPort().getStrVal());
    } else {
        targetPort = sp.getTargetPort().getIntVal();
    }

    if (targetPort == 0) {
        return null;
    }

    if (TCP.equals(sp.getProtocol())) {
        tBuilder.setTcpDst(TpPort.tpPort(targetPort));
    } else if (UDP.equals(sp.getProtocol())) {
        tBuilder.setUdpDst(TpPort.tpPort(targetPort));
    }

    ExtensionTreatment resubmitTreatment = buildResubmitExtension(
            deviceService.getDevice(deviceId), ACL_TABLE);
    tBuilder.extension(resubmitTreatment, deviceId);

    // TODO: need to adjust group bucket weight by considering POD locality
    return buildGroupBucket(tBuilder.build(), SELECT, (short) -1);
}