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 int index = outBuffer.writerIndex();
38 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
39 outBuffer.writeShort(message.getCommand().getIntValue());
40 outBuffer.writeByte(message.getType().getIntValue());
41 outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE);
42 outBuffer.writeInt(message.getGroupId().getValue().intValue());
43 serializerBuckets(message.getBucketsList(), outBuffer);
44 ByteBufUtils.updateOFHeaderLength(outBuffer, index);
47 private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
48 if (buckets != null) {
49 for (BucketsList currentBucket : buckets) {
50 int bucketLengthIndex = outBuffer.writerIndex();
51 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
52 outBuffer.writeShort(currentBucket.getWeight().shortValue());
53 outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());
54 outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
55 outBuffer.writeZero(PADDING_IN_BUCKET);
56 ListSerializer.serializeList(currentBucket.getAction(), TypeKeyMakerFactory
57 .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
58 outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
64 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
65 this.registry = serializerRegistry;