Search in sources :

Example 1 with GroupMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder 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 2 with GroupMessageBuilder

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

the class SingleLayerGroupService method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final Group input) throws ServiceException {
    final GroupMessageBuilder groupMessageBuilder = new GroupMessageBuilder(input);
    final Class<? extends DataContainer> clazz = input.getImplementedInterface();
    if (clazz.equals(AddGroupInput.class)) {
        groupMessageBuilder.setCommand(GroupModCommand.OFPGCADD);
    } else if (clazz.equals(UpdatedGroup.class)) {
        groupMessageBuilder.setCommand(GroupModCommand.OFPGCMODIFY);
    } else if (clazz.equals(RemoveGroupInput.class) || clazz.equals(OriginalGroup.class)) {
        groupMessageBuilder.setCommand(GroupModCommand.OFPGCDELETE);
    }
    return groupMessageBuilder.setVersion(getVersion()).setXid(xid.getValue()).build();
}
Also used : RemoveGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput) OriginalGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroup) GroupMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder) UpdatedGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup)

Aggregations

GroupMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessageBuilder)2 ArrayList (java.util.ArrayList)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 RemoveGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput)1 OriginalGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroup)1 UpdatedGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup)1 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)1 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)1 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)1 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)1