* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.impl.protocol.serialization.messages;
import com.google.common.base.MoreObjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand;
+import org.opendaylight.yangtools.yang.common.Uint16;
/**
* Translates GroupMod messages.
* OF protocol versions: 1.3.
*/
public class GroupMessageSerializer extends AbstractMessageSerializer<GroupMessage> implements
- SerializerRegistryInjector {
+ SerializerRegistryInjector {
private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
private static final byte PADDING_IN_BUCKET = 4;
+ private static final int OFPGC_ADD_OR_MOD = 32768;
+ private final boolean isGroupAddModEnabled;
private static final Comparator<Bucket> COMPARATOR = (bucket1, bucket2) -> {
if (bucket1.getBucketId() == null || bucket2.getBucketId() == null) {
private SerializerRegistry registry;
+ public GroupMessageSerializer(final boolean isGroupAddModEnabled) {
+ this.isGroupAddModEnabled = isGroupAddModEnabled;
+ }
+
@Override
- public void serialize(GroupMessage message, ByteBuf outBuffer) {
+ public void serialize(final GroupMessage message, final ByteBuf outBuffer) {
final int index = outBuffer.writerIndex();
super.serialize(message, outBuffer);
- outBuffer.writeShort(message.getCommand().getIntValue());
+ if (isGroupAddModEnabled) {
+ if (message.getCommand().equals(GroupModCommand.OFPGCADD)
+ || message.getCommand().equals(GroupModCommand.OFPGCMODIFY)) {
+ outBuffer.writeShort(OFPGC_ADD_OR_MOD);
+ } else {
+ outBuffer.writeShort(message.getCommand().getIntValue());
+ }
+ } else {
+ outBuffer.writeShort(message.getCommand().getIntValue());
+ }
outBuffer.writeByte(message.getGroupType().getIntValue());
outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE);
outBuffer.writeInt(message.getGroupId().getValue().intValue());
Optional.ofNullable(message.getBuckets())
.filter(b -> !GroupModCommand.OFPGCDELETE.equals(message.getCommand()))
- .flatMap(b -> Optional.ofNullable(b.getBucket()))
- .ifPresent(b -> b.stream()
+ .flatMap(b -> Optional.ofNullable(b.nonnullBucket()))
+ .ifPresent(b -> b.values().stream()
.sorted(COMPARATOR)
.forEach(bucket -> {
final int bucketIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
- outBuffer.writeShort(MoreObjects.firstNonNull(bucket.getWeight(), 0));
+ outBuffer.writeShort(MoreObjects.firstNonNull(bucket.getWeight(), Uint16.ZERO).toJava());
outBuffer.writeInt(MoreObjects.firstNonNull(bucket.getWatchPort(), OFConstants.OFPG_ANY)
.intValue());
outBuffer.writeInt(MoreObjects.firstNonNull(bucket.getWatchGroup(), OFConstants.OFPG_ANY)
.intValue());
outBuffer.writeZero(PADDING_IN_BUCKET);
- Optional.ofNullable(bucket.getAction()).ifPresent(as -> as
+ Optional.ofNullable(bucket.nonnullAction()).ifPresent(as -> as.values()
.stream()
.sorted(OrderComparator.build())
.forEach(a -> ActionUtil.writeAction(
outBuffer.setShort(bucketIndex, outBuffer.writerIndex() - bucketIndex);
}));
-
outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
}
}
@Override
- public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
registry = serializerRegistry;
}
}