Search in sources :

Example 6 with BucketsList

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);
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyGroupDescCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) 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) MultipartReplyGroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc) MultipartReplyGroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) ByteBuf(io.netty.buffer.ByteBuf) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) MultipartReplyGroupDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder) Test(org.junit.Test)

Example 7 with BucketsList

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;
}
Also used : BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) 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)

Example 8 with 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 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;
}
Also used : BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) 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)

Example 9 with 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());
}
Also used : GroupModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) ByteBuf(io.netty.buffer.ByteBuf) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) GroupModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput) Test(org.junit.Test)

Example 10 with 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 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;
}
Also used : BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) 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)

Aggregations

BucketsList (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList)15 ArrayList (java.util.ArrayList)9 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)7 BucketsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder)7 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)6 Test (org.junit.Test)5 ByteBuf (io.netty.buffer.ByteBuf)4 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)4 GroupModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder)4 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)4 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)3 MultipartReplyGroupDescCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder)3 MultipartReplyGroupDescBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder)3 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)3 List (java.util.List)2 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)2 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)2 AddGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput)2 BucketId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)2 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)2