use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList 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.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method createBucketsList.
private static List<BucketsList> createBucketsList() {
BucketsListBuilder builder = new BucketsListBuilder();
builder.setWeight(1);
builder.setWatchPort(new PortNumber(1L));
builder.setWatchGroup(1L);
builder.setAction(createActionList());
List<BucketsList> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupModInputMessageFactoryTest method createBucketsList.
private static List<BucketsList> createBucketsList() {
final List<BucketsList> bucketsList = new ArrayList<>();
BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
bucketsBuilder.setWeight(10);
bucketsBuilder.setWatchPort(new PortNumber(65L));
bucketsBuilder.setWatchGroup(22L);
BucketsList bucket = bucketsBuilder.build();
bucketsList.add(bucket);
return bucketsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupModInputMessageFactoryTest method testGroupModInputMessage.
/**
* Testing of {@link GroupModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testGroupModInputMessage() throws Exception {
GroupModInputBuilder builder = new GroupModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setCommand(GroupModCommand.forValue(2));
builder.setType(GroupType.forValue(3));
builder.setGroupId(new GroupId(256L));
List<BucketsList> exp = createBucketsList();
builder.setBucketsList(exp);
final GroupModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
// simulate parent message
out.writeInt(1);
out.writeZero(2);
out.writeShort(3);
groupModFactory.serialize(message, out);
// read parent message
out.readInt();
out.skipBytes(2);
out.readShort();
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 32);
Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort());
Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte());
out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE);
Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt());
List<BucketsList> rec = createBucketsListFromBufer(out);
Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList in project openflowplugin by opendaylight.
the class GroupModInputMessageFactoryTest method createBucketsListFromBufer.
private static List<BucketsList> createBucketsListFromBufer(ByteBuf out) {
final List<BucketsList> bucketsList = new ArrayList<>();
BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
bucketsBuilder.setWeight(out.readUnsignedShort());
bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt()));
bucketsBuilder.setWatchGroup(out.readUnsignedInt());
out.skipBytes(4);
BucketsList bucket = bucketsBuilder.build();
bucketsList.add(bucket);
return bucketsList;
}
Aggregations