Search in sources :

Example 6 with Buckets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.

the class GroupDescStatsResponseConvertorTest method testSingleGroupDescStat.

/**
 * Test single GroupDescStat conversion without buckets.
 */
@Test
public void testSingleGroupDescStat() {
    GroupDescBuilder builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTALL);
    builder.setGroupId(new GroupId(42L));
    builder.setBucketsList(new ArrayList<>());
    List<GroupDesc> groupDescStats = new ArrayList<>();
    groupDescStats.add(builder.build());
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    List<GroupDescStats> statsList = convert(groupDescStats, data);
    Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
    GroupDescStats stat = statsList.get(0);
    Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) ArrayList(java.util.ArrayList) GroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) Test(org.junit.Test)

Example 7 with Buckets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.

the class ReconcileUtil method resolveAndDivideGroupDiffs.

/**
 * Returns a list of safe synchronization steps.
 *
 * @param nodeId             target node
 * @param installedGroupsArg groups resent on device
 * @param pendingGroups      groups configured for device
 * @param gatherUpdates      check content of pending item if present on device (and create update task eventually)
 * @return list of safe synchronization steps
 */
public static List<ItemSyncBox<Group>> resolveAndDivideGroupDiffs(final NodeId nodeId, final Map<Long, Group> installedGroupsArg, final Collection<Group> pendingGroups, final boolean gatherUpdates) {
    final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
    final List<ItemSyncBox<Group>> plan = new ArrayList<>();
    while (!Iterables.isEmpty(pendingGroups)) {
        final ItemSyncBox<Group> stepPlan = new ItemSyncBox<>();
        final Iterator<Group> iterator = pendingGroups.iterator();
        final Map<Long, Group> installIncrement = new HashMap<>();
        while (iterator.hasNext()) {
            final Group group = iterator.next();
            final Group existingGroup = installedGroups.get(group.getGroupId().getValue());
            if (existingGroup != null) {
                if (!gatherUpdates) {
                    iterator.remove();
                } else {
                    // check buckets and eventually update
                    if (group.equals(existingGroup)) {
                        iterator.remove();
                    } else {
                        if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                            iterator.remove();
                            LOG.trace("Group {} on device {} differs - planned for update", group.getGroupId(), nodeId);
                            stepPlan.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingGroup, group));
                        }
                    }
                }
            } else if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                iterator.remove();
                installIncrement.put(group.getGroupId().getValue(), group);
                stepPlan.getItemsToPush().add(group);
            }
        }
        if (!stepPlan.isEmpty()) {
            // atomic update of installed flows in order to keep plan portions clean of local group dependencies
            installedGroups.putAll(installIncrement);
            plan.add(stepPlan);
        } else if (!pendingGroups.isEmpty()) {
            LOG.warn("Failed to resolve and divide groups into preconditions-match based ordered plan: {}, " + "resolving stuck at level {}", nodeId.getValue(), plan.size());
            throw new IllegalStateException("Failed to resolve and divide groups when matching preconditions");
        }
    }
    return plan;
}
Also used : Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with Buckets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.

the class GroupMessageDeserializer method deserialize.

@Override
public GroupMessage deserialize(ByteBuf message) {
    final GroupMessageBuilder builder = new GroupMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCommand(GroupModCommand.forValue(message.readUnsignedShort()));
    builder.setGroupType(GroupTypes.forValue(message.readUnsignedByte()));
    message.skipBytes(PADDING);
    builder.setGroupId(new GroupId(message.readUnsignedInt()));
    final List<Bucket> buckets = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final int length = message.readUnsignedShort();
        final BucketBuilder bucket = new BucketBuilder().setWeight(message.readUnsignedShort()).setWatchPort(message.readUnsignedInt()).setWatchGroup(message.readUnsignedInt());
        message.skipBytes(PADDING_IN_BUCKETS_HEADER);
        if (message.readableBytes() > 0) {
            final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions = new ArrayList<>();
            final int startIndex = message.readerIndex();
            final int bucketLength = length - BUCKETS_HEADER_LENGTH;
            int offset = 0;
            while (message.readerIndex() - startIndex < bucketLength) {
                actions.add(new ActionBuilder().setKey(new ActionKey(offset)).setOrder(offset).setAction(ActionUtil.readAction(EncodeConstants.OF13_VERSION_ID, message, registry, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION)).build());
                offset++;
            }
            bucket.setAction(actions);
        }
        buckets.add(bucket.build());
    }
    buckets.sort(COMPARATOR);
    return builder.setBuckets(new BucketsBuilder().setBucket(buckets).build()).build();
}
Also used : ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) ArrayList(java.util.ArrayList) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) BucketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) GroupMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder)

Example 9 with Buckets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project openflowplugin by opendaylight.

the class GroupStatsResponseConvertor method toSALBuckets.

private Buckets toSALBuckets(List<BucketStats> bucketStats) {
    BucketsBuilder salBuckets = new BucketsBuilder();
    List<BucketCounter> allBucketStats = new ArrayList<>();
    int bucketKey = 0;
    for (BucketStats bucketStat : bucketStats) {
        BucketCounterBuilder bucketCounter = new BucketCounterBuilder();
        bucketCounter.setByteCount(new Counter64(bucketStat.getByteCount()));
        bucketCounter.setPacketCount(new Counter64(bucketStat.getPacketCount()));
        BucketId bucketId = new BucketId((long) bucketKey);
        bucketCounter.setKey(new BucketCounterKey(bucketId));
        bucketCounter.setBucketId(bucketId);
        bucketKey++;
        allBucketStats.add(bucketCounter.build());
    }
    salBuckets.setBucketCounter(allBucketStats);
    return salBuckets.build();
}
Also used : BucketCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) ArrayList(java.util.ArrayList) BucketCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterKey) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.BucketsBuilder) BucketCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterBuilder) BucketId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId) BucketStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats)

Example 10 with Buckets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets in project genius by opendaylight.

the class MDSALUtil method buildBuckets.

protected static Buckets buildBuckets(List<BucketInfo> listBucketInfo) {
    long index = 0;
    if (listBucketInfo != null) {
        BucketsBuilder bucketsBuilder = new BucketsBuilder();
        List<Bucket> bucketList = new ArrayList<>();
        for (BucketInfo bucketInfo : listBucketInfo) {
            BucketBuilder bucketBuilder = new BucketBuilder();
            bucketBuilder.setAction(bucketInfo.buildActions());
            bucketBuilder.setWeight(bucketInfo.getWeight());
            bucketBuilder.setBucketId(new BucketId(index++));
            bucketBuilder.setWeight(bucketInfo.getWeight()).setWatchPort(bucketInfo.getWatchPort()).setWatchGroup(bucketInfo.getWatchGroup());
            bucketList.add(bucketBuilder.build());
        }
        bucketsBuilder.setBucket(bucketList);
        return bucketsBuilder.build();
    }
    return EMPTY_BUCKETS;
}
Also used : BucketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) ArrayList(java.util.ArrayList) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder) BucketId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)

Aggregations

ArrayList (java.util.ArrayList)15 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)13 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)8 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)8 Test (org.junit.Test)7 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)7 Buckets (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets)6 GroupActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase)5 GroupAction (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction)5 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)4 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)4 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)4 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)4 VersionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)3 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)3 GroupActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder)3 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)3 SetMplsTtlAction (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction)3 BucketId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)3 GroupModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder)3