2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import java.util.List;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
19 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
20 import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
21 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
27 * Translates GroupMod messages
28 * @author timotej.kubas
29 * @author michal.polkorab
31 public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>, SerializerRegistryInjector {
32 private static final byte MESSAGE_TYPE = 15;
33 private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
34 private static final byte PADDING_IN_BUCKET = 4;
35 private SerializerRegistry registry;
38 public void serialize(GroupModInput message, ByteBuf outBuffer) {
39 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
40 outBuffer.writeShort(message.getCommand().getIntValue());
41 outBuffer.writeByte(message.getType().getIntValue());
42 ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, outBuffer);
43 outBuffer.writeInt(message.getGroupId().getValue().intValue());
44 serializerBuckets(message.getBucketsList(), outBuffer);
45 ByteBufUtils.updateOFHeaderLength(outBuffer);
48 private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
49 if (buckets != null) {
50 for (BucketsList currentBucket : buckets) {
51 int bucketLengthIndex = outBuffer.writerIndex();
52 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
53 outBuffer.writeShort(currentBucket.getWeight().shortValue());
54 outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());
55 outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
56 ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);
57 OFSerializer<Action> actionSerializer = registry.getSerializer(
58 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));
59 CodingUtils.serializeList(currentBucket.getAction(), actionSerializer, outBuffer);
60 outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
66 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
67 this.registry = serializerRegistry;