1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
6 import java.util.Iterator;
\r
7 import java.util.List;
\r
9 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
\r
10 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsList;
\r
15 * @author timotej.kubas
\r
16 * @author michal.polkorab
\r
18 public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {
\r
19 private static final byte MESSAGE_TYPE = 15;
\r
20 private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
\r
21 private static final int MESSAGE_LENGTH = 16;
\r
22 private static GroupModInputMessageFactory instance;
\r
24 private GroupModInputMessageFactory() {
\r
29 * @return singleton factory
\r
31 public static synchronized GroupModInputMessageFactory getInstance() {
\r
32 if (instance == null) {
\r
33 instance = new GroupModInputMessageFactory();
\r
39 public void messageToBuffer(short version, ByteBuf out,
\r
40 GroupModInput message) {
\r
41 ByteBufUtils.writeOFHeader(instance, message, out);
\r
42 out.writeShort(message.getCommand().getIntValue());
\r
43 out.writeByte(message.getType().getIntValue());
\r
44 ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out);
\r
45 out.writeInt(message.getGroupId().intValue());
\r
46 encodeBuckets(message.getBucketsList(), out);
\r
50 public int computeLength() {
\r
51 return MESSAGE_LENGTH;
\r
55 public byte getMessageType() {
\r
56 return MESSAGE_TYPE;
\r
59 private static void encodeBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
\r
60 final byte PADDING_IN_BUCKET = 4;
\r
62 for (Iterator<BucketsList> iterator = buckets.iterator(); iterator.hasNext();) {
\r
63 BucketsList currentBucket = iterator.next();
\r
64 // TODO get method for field length missing
\r
65 outBuffer.writeShort(currentBucket.getWeight().intValue());
\r
66 outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());
\r
67 outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
\r
68 ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);
\r
69 // TODO actions structure missing
\r