Search in sources :

Example 1 with GroupModInput

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.");
    }
}
Also used : ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) BundleRemoveGroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleRemoveGroupCase) BundleAddGroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleAddGroupCase) BundleUpdateGroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleUpdateGroupCase) RemoveGroupInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder) GroupModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder) UpdatedGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder) GroupModCaseDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.add.message.grouping.bundle.inner.message.bundle.group.mod._case.GroupModCaseDataBuilder) AddGroupInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder) BundleGroupModCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.add.message.grouping.bundle.inner.message.BundleGroupModCaseBuilder)

Example 2 with GroupModInput

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

Example 3 with GroupModInput

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);
}
Also used : GroupModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder) 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 4 with GroupModInput

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());
}
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 5 with GroupModInput

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();
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) ArrayList(java.util.ArrayList) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) 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) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)

Aggregations

GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)4 GroupModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)3 Test (org.junit.Test)3 GroupModInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput)3 BucketsList (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList)3 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)2 ArrayList (java.util.ArrayList)1 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)1 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)1 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)1 RemoveGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder)1 UpdatedGroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)1 BucketsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder)1 BundleAddGroupCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleAddGroupCase)1 BundleRemoveGroupCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleRemoveGroupCase)1 BundleUpdateGroupCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.bundle.inner.message.grouping.bundle.inner.message.BundleUpdateGroupCase)1 BundleGroupModCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.add.message.grouping.bundle.inner.message.BundleGroupModCaseBuilder)1 GroupModCaseDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.add.message.grouping.bundle.inner.message.bundle.group.mod._case.GroupModCaseDataBuilder)1