Search in sources :

Example 6 with BucketsBuilder

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

the class GroupDescStatsResponseConvertorTest method testGroupDescStats.

/**
 * Test single GroupDescStats conversion.
 */
@Test
public void testGroupDescStats() {
    // **********************************************
    // First group desc
    // **********************************************
    GroupDescBuilder builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTFF);
    builder.setGroupId(new GroupId(42L));
    // Buckets for first group desc
    BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(16);
    bucketsBuilder.setWatchPort(new PortNumber(84L));
    bucketsBuilder.setWatchGroup(168L);
    // Actions for buckets for first group desc
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build bucket with actions
    bucketsBuilder.setAction(actions);
    List<BucketsList> bucketsList = new ArrayList<>();
    bucketsList.add(bucketsBuilder.build());
    // Build first group desc
    builder.setBucketsList(bucketsList);
    List<GroupDesc> groupDescStats = new ArrayList<>();
    groupDescStats.add(builder.build());
    // **********************************************
    // Second group desc
    // **********************************************
    builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTINDIRECT);
    builder.setGroupId(new GroupId(50L));
    // First buckets for second group desc
    bucketsList = new ArrayList<>();
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(100);
    bucketsBuilder.setWatchPort(new PortNumber(200L));
    bucketsBuilder.setWatchGroup(400L);
    // Actions for first buckets for second group desc
    actions = new ArrayList<>();
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build first bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Second buckets for second group desc
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(5);
    bucketsBuilder.setWatchPort(new PortNumber(10L));
    bucketsBuilder.setWatchGroup(15L);
    // Actions for second buckets for second group desc
    actions = new ArrayList<>();
    // Build second bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Build second group desc
    builder.setBucketsList(bucketsList);
    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", 2, statsList.size());
    // **********************************************
    // Test first group desc
    // **********************************************
    GroupDescStats stat = statsList.get(0);
    Assert.assertEquals("Wrong type", GroupTypes.GroupFf, 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", 1, stat.getBuckets().getBucket().size());
    // Test first bucket for first group desc
    Bucket bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
    // Test first action for first bucket for first group desc
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
    // **********************************************
    // Test second group desc
    // **********************************************
    stat = statsList.get(1);
    Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
    // Test first bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
    // Test first action for first bucket of second group desc
    action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
    // Test second action for first bucket of second group desc
    action = bucket.getAction().get(1);
    Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
    // Test third action for first bucket of second group desc
    action = bucket.getAction().get(2);
    Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
    // Test second bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(1);
    Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) PopPbbCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder) ArrayList(java.util.ArrayList) 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) 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) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) CopyTtlInCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder) DecNwTtlCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) CopyTtlOutCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder) Test(org.junit.Test)

Example 7 with BucketsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder 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 8 with BucketsBuilder

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

the class MultipartReplyMessageFactory method setGroupDesc.

private MultipartReplyGroupDescCase setGroupDesc(final ByteBuf input) {
    MultipartReplyGroupDescCaseBuilder caseBuilder = new MultipartReplyGroupDescCaseBuilder();
    MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
    List<GroupDesc> groupDescsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        GroupDescBuilder groupDescBuilder = new GroupDescBuilder();
        final int bodyLength = input.readUnsignedShort();
        groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte()));
        input.skipBytes(PADDING_IN_GROUP_DESC_HEADER);
        groupDescBuilder.setGroupId(new GroupId(input.readUnsignedInt()));
        int actualLength = GROUP_DESC_HEADER_LENGTH;
        List<BucketsList> bucketsList = new ArrayList<>();
        while (actualLength < bodyLength) {
            BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
            final int bucketsLength = input.readUnsignedShort();
            bucketsBuilder.setWeight(input.readUnsignedShort());
            bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));
            bucketsBuilder.setWatchGroup(input.readUnsignedInt());
            input.skipBytes(PADDING_IN_BUCKETS_HEADER);
            CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
            List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, bucketsLength - BUCKETS_HEADER_LENGTH, input, keyMaker, registry);
            bucketsBuilder.setAction(actions);
            bucketsList.add(bucketsBuilder.build());
            actualLength += bucketsLength;
        }
        groupDescBuilder.setBucketsList(bucketsList);
        groupDescsList.add(groupDescBuilder.build());
    }
    builder.setGroupDesc(groupDescsList);
    caseBuilder.setMultipartReplyGroupDesc(builder.build());
    return caseBuilder.build();
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) MultipartReplyGroupDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) 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) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder) 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) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder)

Example 9 with BucketsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder 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 BucketsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder 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)20 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)14 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)13 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)13 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)11 BucketId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)9 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)6 BucketsList (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList)6 Test (org.junit.Test)5 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 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)5 Buckets (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets)5 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)5 BucketsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder)5 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)4 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)4 GroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder)4 GroupModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder)4