Search in sources :

Example 1 with GroupMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage in project openflowplugin by opendaylight.

the class SingleLayerGroupServiceTest method buildRequest.

@Test
public void buildRequest() throws Exception {
    final AddGroupInput input = new AddGroupInputBuilder().setGroupId(new GroupId(GROUP_ID)).build();
    final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
    assertEquals(GroupMessage.class, ofHeader.getImplementedInterface());
    final GroupMessage result = GroupMessage.class.cast(ofHeader);
    assertEquals(GroupModCommand.OFPGCADD, result.getCommand());
    assertEquals(GROUP_ID, result.getGroupId().getValue().longValue());
}
Also used : AddGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) GroupMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage) AddGroupInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) Test(org.junit.Test)

Example 2 with GroupMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage in project openflowplugin by opendaylight.

the class GroupMessageDeserializer method deserialize.

@Override
public GroupMessage deserialize(ByteBuf message) {
    final GroupMessageBuilder builder = new GroupMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCommand(GroupModCommand.forValue(message.readUnsignedShort()));
    builder.setGroupType(GroupTypes.forValue(message.readUnsignedByte()));
    message.skipBytes(PADDING);
    builder.setGroupId(new GroupId(message.readUnsignedInt()));
    final List<Bucket> buckets = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final int length = message.readUnsignedShort();
        final BucketBuilder bucket = new BucketBuilder().setWeight(message.readUnsignedShort()).setWatchPort(message.readUnsignedInt()).setWatchGroup(message.readUnsignedInt());
        message.skipBytes(PADDING_IN_BUCKETS_HEADER);
        if (message.readableBytes() > 0) {
            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 = length - 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++;
            }
            bucket.setAction(actions);
        }
        buckets.add(bucket.build());
    }
    buckets.sort(COMPARATOR);
    return builder.setBuckets(new BucketsBuilder().setBucket(buckets).build()).build();
}
Also used : ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) ArrayList(java.util.ArrayList) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) BucketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) GroupMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder)

Example 3 with GroupMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage in project openflowplugin by opendaylight.

the class GroupMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Group header
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeShort(COMMAND.getIntValue());
    buffer.writeByte(GROUP_TYPE.getIntValue());
    buffer.writeZero(PADDING);
    buffer.writeInt(GROUP_ID);
    // Buckets header
    int index = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeShort(WEIGHT);
    buffer.writeInt(WATCH_PORT);
    buffer.writeInt(WATCH_GROUP);
    buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of buckets
    buffer.setShort(index, buffer.writerIndex() - index);
    // Deserialize and check everything
    final GroupMessage message = (GroupMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(XID, message.getXid().intValue());
    assertEquals(COMMAND.getIntValue(), message.getCommand().getIntValue());
    assertEquals(GROUP_TYPE.getIntValue(), message.getGroupType().getIntValue());
    assertEquals(1, message.getBuckets().getBucket().size());
    final Bucket bucket = message.getBuckets().getBucket().get(0);
    assertEquals(WEIGHT, bucket.getWeight().shortValue());
    assertEquals(WATCH_PORT, bucket.getWatchPort().intValue());
    assertEquals(WATCH_GROUP, bucket.getWatchGroup().intValue());
    assertEquals(1, bucket.getAction().size());
    assertEquals(PopPbbActionCase.class, bucket.getAction().get(0).getAction().getImplementedInterface());
}
Also used : Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) GroupMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Aggregations

Test (org.junit.Test)2 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)2 GroupMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage)2 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)2 ArrayList (java.util.ArrayList)1 AbstractDeserializerTest (org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)1 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)1 ActionKey (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey)1 AddGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput)1 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)1 GroupMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder)1 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)1 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1