use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder in project openflowplugin by opendaylight.
the class MultipartReplyGroupDescDeserializer method deserialize.
@Override
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
final List<GroupDescStats> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final int itemLength = message.readUnsignedShort();
final GroupDescStatsBuilder itemBuilder = new GroupDescStatsBuilder().setGroupType(GroupTypes.forValue(message.readUnsignedByte()));
message.skipBytes(PADDING_IN_GROUP_DESC_HEADER);
itemBuilder.setGroupId(new GroupId(message.readUnsignedInt()));
itemBuilder.setKey(new GroupDescStatsKey(itemBuilder.getGroupId()));
final List<Bucket> subItems = new ArrayList<>();
int actualLength = GROUP_DESC_HEADER_LENGTH;
long bucketKey = 0;
while (actualLength < itemLength) {
final int bucketsLength = message.readUnsignedShort();
final BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketKey)).setKey(new BucketKey(new BucketId(bucketKey))).setWeight(message.readUnsignedShort()).setWatchPort(message.readUnsignedInt()).setWatchGroup(message.readUnsignedInt());
message.skipBytes(PADDING_IN_BUCKETS_HEADER);
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 = bucketsLength - 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++;
}
bucketBuilder.setAction(actions);
subItems.add(bucketBuilder.build());
bucketKey++;
actualLength += bucketsLength;
}
items.add(itemBuilder.setBuckets(new BucketsBuilder().setBucket(subItems).build()).build());
}
return builder.setGroupDescStats(items).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorUtil method translateGroupDesc.
private static org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc translateGroupDesc(final MultipartReply msg, final VersionDatapathIdConvertorData data, final ConvertorExecutor convertorExecutor) {
MultipartReplyGroupDescBuilder message = new MultipartReplyGroupDescBuilder();
MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase) msg.getMultipartReplyBody();
MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc();
final Optional<List<GroupDescStats>> groupDescStatsList = convertorExecutor.convert(replyBody.getGroupDesc(), data);
message.setGroupDescStats(groupDescStatsList.orElse(Collections.emptyList()));
return message.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder 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.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testGroupDescSerialize.
@Test
public void testGroupDescSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(7));
MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder();
MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder();
group.setGroupDesc(createGroupDesc());
groupCase.setMultipartReplyGroupDesc(group.build());
builder.setMultipartReplyBody(groupCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 64);
Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPDESC.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
MultipartReplyGroupDescCase body = (MultipartReplyGroupDescCase) message.getMultipartReplyBody();
MultipartReplyGroupDesc messageOutput = body.getMultipartReplyGroupDesc();
GroupDesc groupDesc = messageOutput.getGroupDesc().get(0);
Assert.assertEquals("Wrong length", 48, serializedBuffer.readShort());
Assert.assertEquals("Wrong type", groupDesc.getType().getIntValue(), serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(1);
Assert.assertEquals("Wrong group id", groupDesc.getGroupId().getValue().intValue(), serializedBuffer.readInt());
BucketsList bucketList = groupDesc.getBucketsList().get(0);
Assert.assertEquals("Wrong length", 40, serializedBuffer.readShort());
Assert.assertEquals("Wrong weight", bucketList.getWeight().intValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong watch port", bucketList.getWatchPort().getValue().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong watch group", bucketList.getWatchGroup().intValue(), serializedBuffer.readInt());
serializedBuffer.skipBytes(4);
Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong action length", 16, serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong action type", 45, serializedBuffer.readUnsignedInt());
Assert.assertEquals("Wrong action type", 55, serializedBuffer.readUnsignedShort());
serializedBuffer.skipBytes(6);
Assert.assertEquals("Wrong action type", 23, serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
Assert.assertEquals("Wrong action type", 64, serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(3);
Assert.assertTrue("Not all data were read", serializedBuffer.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder in project openflowplugin by opendaylight.
the class OpendaylightGroupStatisticsServiceImplTest method testGetGroupDescription.
@Test
public void testGetGroupDescription() throws Exception {
GetGroupDescriptionInputBuilder input = new GetGroupDescriptionInputBuilder().setNode(createNodeRef("unitProt:123"));
rpcResult = RpcResultBuilder.<Object>success(Collections.singletonList(new MultipartReplyMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setMultipartReplyBody(new MultipartReplyGroupDescCaseBuilder().setMultipartReplyGroupDesc(new MultipartReplyGroupDescBuilder().setGroupDesc(Collections.singletonList(new GroupDescBuilder().setGroupId(GROUP_ID).setBucketsList(Collections.singletonList(new BucketsListBuilder().setWatchGroup(51L).setWatchPort(new PortNumber(52L)).setWeight(53).build())).setType(GroupType.OFPGTALL).build())).build()).build()).build())).build();
final Future<RpcResult<GetGroupDescriptionOutput>> resultFuture = groupStatisticsService.getGroupDescription(input.build());
Assert.assertTrue(resultFuture.isDone());
final RpcResult<GetGroupDescriptionOutput> rpcResult = resultFuture.get();
Assert.assertTrue(rpcResult.isSuccessful());
Assert.assertEquals(MultipartType.OFPMPGROUPDESC, requestInput.getValue().getType());
}
Aggregations