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());
}
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();
}
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());
}
Aggregations