io.fabric8.kubernetes.api.model.EndpointSubset#org.onosproject.net.group.GroupBucket源码实例Demo

下面列出了io.fabric8.kubernetes.api.model.EndpointSubset#org.onosproject.net.group.GroupBucket 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ngsdn-tutorial   文件: Utils.java
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);
}
 
源代码2 项目: onos-p4-tutorial   文件: Utils.java
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);
}
 
源代码3 项目: onos-p4-tutorial   文件: Utils.java
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);
}
 
源代码4 项目: onos   文件: GroupsWebResource.java
/**
 * 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());
}
 
源代码5 项目: onos   文件: GroupViewMessageHandler.java
@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();
}
 
源代码6 项目: onos   文件: OfdpaGroupHandlerUtility.java
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;
}
 
源代码7 项目: onos   文件: OvsOfdpaPipeline.java
/**
 * 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);
}
 
源代码8 项目: onos   文件: Ofdpa2GroupHandler.java
/**
 * 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);
}
 
源代码9 项目: onos   文件: DistributedGroupStore.java
/**
 * 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);
}
 
源代码10 项目: onos   文件: OpenFlowGroupProvider.java
/**
 * 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;
}
 
源代码11 项目: onos   文件: GroupModBuilder.java
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;
}
 
源代码12 项目: onos   文件: GroupModBuilder.java
/**
 * 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();
 }
 
源代码13 项目: onos   文件: GroupModBuilder.java
/**
  * 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();
}
 
源代码14 项目: onos   文件: ForwardingObjectiveTranslator.java
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;
}
 
源代码15 项目: onos   文件: GroupsListCommand.java
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());
        }
    }
}
 
源代码16 项目: onos   文件: RulePopulatorUtil.java
/**
 * 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;
    }
}
 
源代码17 项目: onos   文件: RulePopulatorUtil.java
/**
 * 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;
    }
}
 
源代码18 项目: onos   文件: VirtualNetworkGroupManagerTest.java
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;
}
 
源代码19 项目: onos   文件: SelectGroupHandler.java
/**
 * 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);
    }
}
 
源代码20 项目: onos   文件: PointToPointIntentCompiler.java
/**
 * 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);
}
 
源代码21 项目: onos   文件: PointToPointIntentCompiler.java
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());
            }
        }
    }
}
 
源代码22 项目: onos   文件: GroupBucketCodec.java
@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;
}
 
源代码23 项目: ngsdn-tutorial   文件: Utils.java
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);
}
 
源代码24 项目: onos-p4-tutorial   文件: Utils.java
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);
}
 
源代码25 项目: onos-p4-tutorial   文件: Utils.java
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);
}
 
源代码26 项目: onos   文件: GroupCodecTest.java
@Test
public void codecEncodeTest() {
    GroupBucket bucket1 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBucket bucket2 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBucket bucket3 = DefaultGroupBucket.createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBuckets allBuckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2));
    GroupBuckets indirectBuckets = new GroupBuckets(ImmutableList.of(bucket3));

    DefaultGroup group = new DefaultGroup(
            new GroupId(1),
            NetTestTools.did("d1"),
            ALL,
            allBuckets);
    DefaultGroup group1 = new DefaultGroup(
            new GroupId(2),
            NetTestTools.did("d2"),
            INDIRECT,
            indirectBuckets);

    MockCodecContext context = new MockCodecContext();
    GroupCodec codec = new GroupCodec();
    ObjectNode groupJson = codec.encode(group, context);

    ObjectNode groupJsonIndirect = codec.encode(group1, context);

    assertThat(groupJson, matchesGroup(group));
    assertThat(groupJsonIndirect, matchesGroup(group1));
}
 
源代码27 项目: onos   文件: OfdpaGroupHandlerUtility.java
/**
 * Generates a list of group buckets from given list of group information
 * and group bucket type.
 *
 * @param groupInfos a list of group information
 * @param bucketType group bucket type
 * @return list of group bucket generate from group information
 */
static List<GroupBucket> generateNextGroupBuckets(List<GroupInfo> groupInfos,
                                                   GroupDescription.Type bucketType) {
    List<GroupBucket> newBuckets = Lists.newArrayList();

    groupInfos.forEach(groupInfo -> {
        GroupDescription groupDesc = groupInfo.nextGroupDesc();
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        treatmentBuilder.group(new GroupId(groupDesc.givenGroupId()));
        GroupBucket newBucket = null;
        switch (bucketType) {
            case ALL:
                newBucket =
                        DefaultGroupBucket.createAllGroupBucket(treatmentBuilder.build());
                break;
            case INDIRECT:
                newBucket =
                        DefaultGroupBucket.createIndirectGroupBucket(treatmentBuilder.build());
                break;
            case SELECT:
                newBucket =
                        DefaultGroupBucket.createSelectGroupBucket(treatmentBuilder.build());
                break;
            case FAILOVER:
                // TODO: support failover bucket type
            default:
                log.warn("Unknown bucket type: {}", bucketType);
                break;
        }

        if (newBucket != null) {
            newBuckets.add(newBucket);
        }

    });

    return ImmutableList.copyOf(newBuckets);
}
 
源代码28 项目: onos   文件: Ofdpa3GroupHandler.java
/**
 * Helper method to create a mpls tunnel label group.
 *
 * @param nextGroupId the next group in the chain
 * @param subtype the mpls tunnel label group subtype
 * @param index the index of the group
 * @param instructions the instructions to push
 * @param applicationId the application id
 * @return the group description
 */
private GroupDescription createMplsTunnelLabelGroup(int nextGroupId,
                                                    OfdpaMplsGroupSubType subtype,
                                                    int index,
                                                    List<Instruction> instructions,
                                                    ApplicationId applicationId) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    // We add all the instructions.
    instructions.forEach(treatment::add);
    // 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
    );
}
 
源代码29 项目: onos   文件: Ofdpa3GroupHandler.java
/**
 * Helper method to create a mpls l2 vpn group.
 *
 * @param nextGroupId the next group in the chain
 * @param index the index of the group
 * @param instructions the instructions to push
 * @param applicationId the application id
 * @return the group description
 */
private GroupDescription createMplsL2VpnGroup(int nextGroupId,
                                              int index,
                                              List<Instruction> instructions,
                                              ApplicationId applicationId) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    // We add the extensions and the instructions.
    treatment.extension(new Ofdpa3PushL2Header(), deviceId);
    treatment.pushVlan();
    instructions.forEach(treatment::add);
    treatment.extension(new Ofdpa3PushCw(), deviceId);
    // 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(OfdpaMplsGroupSubType.L2_VPN, index);
    GroupKey groupKey = new DefaultGroupKey(
            Ofdpa2Pipeline.appKryo.serialize(index)
    );
    return new DefaultGroupDescription(
            deviceId,
            INDIRECT,
            new GroupBuckets(Collections.singletonList(groupBucket)),
            groupKey,
            groupId,
            applicationId
    );
}
 
源代码30 项目: onos   文件: Ofdpa2GroupHandler.java
private void createL2MulticastGroup(NextObjective nextObj, VlanId vlanId,  List<GroupInfo> groupInfos) {
    // Realize & represent L2 multicast group in OFDPA driver layer
    // TODO : Need to identify significance of OfdpaNextGroup.
    Integer l2MulticastGroupId = L2_MULTICAST_TYPE | (vlanId.toShort() << 16);
    final GroupKey l2MulticastGroupKey = l2MulticastGroupKey(vlanId, deviceId);
    List<Deque<GroupKey>> l2MulticastAllGroup = Lists.newArrayList();
    groupInfos.forEach(groupInfo -> {
        Deque<GroupKey> groupKeyChain = new ArrayDeque<>();
        groupKeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
        groupKeyChain.addFirst(l2MulticastGroupKey);
        l2MulticastAllGroup.add(groupKeyChain);
    });
    OfdpaNextGroup ofdpaL2MulticastGroup = new OfdpaNextGroup(l2MulticastAllGroup, nextObj);
    updatePendingNextObjective(l2MulticastGroupKey, ofdpaL2MulticastGroup);
    // Group Chain Hierarchy creation using group service and thus in device level
    List<GroupBucket> l2McastBuckets = new ArrayList<>();
    groupInfos.forEach(groupInfo -> {
        // Points to L2 interface group directly.
        TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder();
        trafficTreatment.group(new GroupId(groupInfo.innerMostGroupDesc().givenGroupId()));
        GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment.build());
        l2McastBuckets.add(bucket);
    });
    GroupDescription l2MulticastGroupDescription =
            new DefaultGroupDescription(
                    deviceId,
                    ALL,
                    new GroupBuckets(l2McastBuckets),
                    l2MulticastGroupKey,
                    l2MulticastGroupId,
                    nextObj.appId());
    GroupChainElem l2MulticastGce = new GroupChainElem(l2MulticastGroupDescription,
                                                       groupInfos.size(), false, deviceId);
    groupInfos.forEach(groupInfo -> {
        updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), l2MulticastGce);
        groupService.addGroup(groupInfo.innerMostGroupDesc());
    });
}