use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput in project openflowplugin by opendaylight.
the class BundleAddMessageConverter method convertBundleGroupCase.
private BundleGroupModCase convertBundleGroupCase(final BundleInnerMessage messageCase, final VersionDatapathIdConvertorData data) throws ConversionException {
Optional<GroupModInputBuilder> groupModInput = Optional.empty();
final Class clazz = messageCase.getImplementedInterface();
if (clazz.equals(BundleAddGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new AddGroupInputBuilder(((BundleAddGroupCase) messageCase).getAddGroupCaseData()).build(), data);
} else if (clazz.equals(BundleUpdateGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new UpdatedGroupBuilder(((BundleUpdateGroupCase) messageCase).getUpdateGroupCaseData()).build(), data);
} else if (clazz.equals(BundleRemoveGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new RemoveGroupInputBuilder(((BundleRemoveGroupCase) messageCase).getRemoveGroupCaseData()).build(), data);
}
if (groupModInput.isPresent()) {
return new BundleGroupModCaseBuilder().setGroupModCaseData(new GroupModCaseDataBuilder(groupModInput.get().setXid(xid).build()).build()).build();
} else {
throw new ConversionException("BundleGroupCase conversion unsuccessful.");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput 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.GroupModInput in project openflowplugin by opendaylight.
the class GroupModInputMessageFactoryTest method testGroupModInputWithNoBuckets.
/**
* Testing of {@link GroupModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testGroupModInputWithNoBuckets() 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));
GroupModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
groupModFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
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());
Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput 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.GroupModInput in project openflowplugin by opendaylight.
the class GroupModInputMessageFactory method deserialize.
@Override
public GroupModInput deserialize(ByteBuf rawMessage) {
GroupModInputBuilder builder = new GroupModInputBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
builder.setCommand(GroupModCommand.forValue(rawMessage.readUnsignedShort()));
builder.setType(GroupType.forValue(rawMessage.readUnsignedByte()));
rawMessage.skipBytes(PADDING);
builder.setGroupId(new GroupId(rawMessage.readUnsignedInt()));
List<BucketsList> bucketsList = new ArrayList<>();
while (rawMessage.readableBytes() > 0) {
BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
final int bucketsLength = rawMessage.readUnsignedShort();
bucketsBuilder.setWeight(rawMessage.readUnsignedShort());
bucketsBuilder.setWatchPort(new PortNumber(rawMessage.readUnsignedInt()));
bucketsBuilder.setWatchGroup(rawMessage.readUnsignedInt());
rawMessage.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, rawMessage, keyMaker, registry);
bucketsBuilder.setAction(actions);
bucketsList.add(bucketsBuilder.build());
}
builder.setBucketsList(bucketsList);
return builder.build();
}
Aggregations