use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupDescStatsResponseConvertor method toSALBucketsDesc.
private org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets toSALBucketsDesc(List<BucketsList> bucketDescStats, short version) {
final ActionResponseConvertorData data = new ActionResponseConvertorData(version);
data.setActionPath(ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder salBucketsDesc = new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder();
List<Bucket> allBuckets = new ArrayList<>();
int bucketKey = 0;
for (BucketsList bucketDetails : bucketDescStats) {
BucketBuilder bucketDesc = new BucketBuilder();
final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> convertedSalActions = getConvertorExecutor().convert(bucketDetails.getAction(), data);
if (convertedSalActions.isPresent()) {
List<Action> actions = new ArrayList<>();
int actionKey = 0;
for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : convertedSalActions.get()) {
ActionBuilder wrappedAction = new ActionBuilder();
wrappedAction.setAction(action);
wrappedAction.setKey(new ActionKey(actionKey));
wrappedAction.setOrder(actionKey);
actions.add(wrappedAction.build());
actionKey++;
}
bucketDesc.setAction(actions);
} else {
bucketDesc.setAction(Collections.emptyList());
}
bucketDesc.setWeight(bucketDetails.getWeight());
bucketDesc.setWatchPort(bucketDetails.getWatchPort().getValue());
bucketDesc.setWatchGroup(bucketDetails.getWatchGroup());
BucketId bucketId = new BucketId((long) bucketKey);
bucketDesc.setBucketId(bucketId);
bucketDesc.setKey(new BucketKey(bucketId));
bucketKey++;
allBuckets.add(bucketDesc.build());
}
salBucketsDesc.setBucket(allBuckets);
return salBucketsDesc.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupModInputMessageFactoryTest method test.
@Test
public void test() {
ByteBuf bb = BufferHelper.buildBuffer("00 02 03 00 00 00 01 00 00 10 00 0a 00 " + "00 00 41 00 00 00 16 00 00 00 00");
GroupModInput deserializedMessage = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(deserializedMessage);
// Test Message
Assert.assertEquals("Wrong command", GroupModCommand.forValue(2), deserializedMessage.getCommand());
Assert.assertEquals("Wrong type", GroupType.forValue(3), deserializedMessage.getType());
Assert.assertEquals("Wrong group id", new GroupId(256L), deserializedMessage.getGroupId());
BucketsList bucket = deserializedMessage.getBucketsList().get(0);
Assert.assertEquals("Wrong weight", 10, bucket.getWeight().intValue());
Assert.assertEquals("Wrong watch port", new PortNumber(65L), bucket.getWatchPort());
Assert.assertEquals("Wrong watch group", 22L, bucket.getWatchGroup().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupConvertorTest method testGroupModConvertSortedBuckets.
/**
* test of {@link GroupConvertor#convert(Group, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testGroupModConvertSortedBuckets() {
final int actionOrder = 0;
final ArrayList<Bucket> bucket = new ArrayList<>();
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 4)).setWatchPort((long) 2).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:2")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 3)).setWatchPort((long) 6).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:6")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 2)).setWatchPort((long) 5).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:5")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 1)).setWatchPort((long) 4).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:4")).build()).build()).build())).build());
bucket.add(new BucketBuilder().setBucketId(new BucketId((long) 0)).setWatchPort((long) 3).setWatchGroup((long) 1).setAction(ImmutableList.of(new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("openflow:1:3")).build()).build()).build())).build());
final AddGroupInput input = new AddGroupInputBuilder().setGroupId(new GroupId((long) 1)).setGroupName("Foo").setGroupType(GroupTypes.GroupFf).setBuckets(new BucketsBuilder().setBucket(bucket).build()).build();
VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData((short) 0X4);
data.setDatapathId(BigInteger.valueOf(1));
final GroupModInputBuilder outAddGroupInput = convert(input, data);
final List<BucketsList> bucketList = outAddGroupInput.getBucketsList();
assertEquals(Long.valueOf(1), bucketList.get(0).getWatchGroup());
assertEquals(Long.valueOf(3), bucketList.get(0).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(1).getWatchGroup());
assertEquals(Long.valueOf(4), bucketList.get(1).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(2).getWatchGroup());
assertEquals(Long.valueOf(5), bucketList.get(2).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(3).getWatchGroup());
assertEquals(Long.valueOf(6), bucketList.get(3).getWatchPort().getValue());
assertEquals(Long.valueOf(1), bucketList.get(4).getWatchGroup());
assertEquals(Long.valueOf(2), bucketList.get(4).getWatchPort().getValue());
}
Aggregations