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;
12 import java.util.List;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
18 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
19 import org.opendaylight.openflowjava.util.ByteBufUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupMod;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
24 * Translates GroupMod messages.
25 * OF protocol versions: 1.3.
26 * @author timotej.kubas
27 * @author michal.polkorab
29 public class GroupModInputMessageFactory implements OFSerializer<GroupMod>, SerializerRegistryInjector {
30 private static final byte MESSAGE_TYPE = 15;
31 private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
32 private static final byte PADDING_IN_BUCKET = 4;
33 private SerializerRegistry registry;
36 public void serialize(GroupMod message, ByteBuf outBuffer) {
37 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
38 outBuffer.writeShort(message.getCommand().getIntValue());
39 outBuffer.writeByte(message.getType().getIntValue());
40 outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE);
41 outBuffer.writeInt(message.getGroupId().getValue().intValue());
42 serializerBuckets(message.getBucketsList(), outBuffer);
43 ByteBufUtils.updateOFHeaderLength(outBuffer);
46 private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
47 if (buckets != null) {
48 for (BucketsList currentBucket : buckets) {
49 int bucketLengthIndex = outBuffer.writerIndex();
50 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
51 outBuffer.writeShort(currentBucket.getWeight().shortValue());
52 outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());
53 outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
54 outBuffer.writeZero(PADDING_IN_BUCKET);
55 ListSerializer.serializeList(currentBucket.getAction(), TypeKeyMakerFactory
56 .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
57 outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
63 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
64 this.registry = serializerRegistry;