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.OFSerializer;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
18 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
19 import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
20 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
25 * Translates GroupMod messages
26 * @author timotej.kubas
27 * @author michal.polkorab
29 public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>, 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(GroupModInput 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 ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, outBuffer);
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 ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);
55 CodingUtils.serializeActions(currentBucket.getAction(), registry,
56 outBuffer, EncodeConstants.OF13_VERSION_ID);
57 outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
63 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
64 this.registry = serializerRegistry;