Updated extension registration keys
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / MultipartReplyMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.math.BigInteger;
14
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.openflowjava.util.ByteBufUtils;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDrop;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemark;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDesc;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
96
97 /**
98  * @author timotej.kubas
99  * @author michal.polkorab
100  */
101 public class MultipartReplyMessageFactoryTest {
102
103     private OFDeserializer<MultipartReplyMessage> multipartFactory;
104
105     /**
106      * Initializes deserializer registry and lookups correct deserializer
107      */
108     @Before
109     public void startUp() {
110         DeserializerRegistry registry = new DeserializerRegistryImpl();
111         registry.init();
112         multipartFactory = registry.getDeserializer(
113                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 19, MultipartReplyMessage.class));
114     }
115
116     private static final Logger LOGGER = LoggerFactory
117             .getLogger(MultipartReplyMessageFactoryTest.class);
118     
119     /**
120      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
121      */
122     @Test
123     public void testMultipartReplyDescBody(){
124         final int DESC_STR_LEN = 256;
125         final int SERIAL_NUM_LEN = 32;
126         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 00 00 00");
127         
128         String mfrDesc = "Manufacturer description";
129         byte[] mfrDescBytes = new byte[256];
130         mfrDescBytes = mfrDesc.getBytes();
131         bb.writeBytes(mfrDescBytes);
132         ByteBufUtils.padBuffer((DESC_STR_LEN - mfrDescBytes.length), bb);
133         
134         String hwDesc = "Hardware description";
135         byte[] hwDescBytes = new byte[256];
136         hwDescBytes = hwDesc.getBytes();
137         bb.writeBytes(hwDescBytes);
138         ByteBufUtils.padBuffer((DESC_STR_LEN - hwDescBytes.length), bb);
139         
140         String swDesc = "Software description";
141         byte[] swDescBytes = new byte[256];
142         swDescBytes = swDesc.getBytes();
143         bb.writeBytes(swDescBytes);
144         ByteBufUtils.padBuffer((DESC_STR_LEN - swDescBytes.length), bb);
145         
146         String serialNum = "SN0123456789";
147         byte[] serialNumBytes = new byte[32];
148         serialNumBytes = serialNum.getBytes();
149         bb.writeBytes(serialNumBytes);
150         ByteBufUtils.padBuffer((SERIAL_NUM_LEN - serialNumBytes.length), bb);
151         
152         String dpDesc = "switch3 in room 3120";
153         byte[] dpDescBytes = new byte[256];
154         dpDescBytes = dpDesc.getBytes();
155         bb.writeBytes(dpDescBytes);
156         ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb);
157         
158         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
159         
160         BufferHelper.checkHeaderV13(builtByFactory);
161         Assert.assertEquals("Wrong type", 0x00, builtByFactory.getType().getIntValue());
162         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
163         MultipartReplyDescCase messageCase = (MultipartReplyDescCase) builtByFactory.getMultipartReplyBody();
164         MultipartReplyDesc message = messageCase.getMultipartReplyDesc();
165         Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc());
166         Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc());
167         Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc());
168         Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum());
169         Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc());
170     }
171     
172     /**
173      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
174      */
175     @Test
176     public void testMultipartReplyFlowBody(){
177         ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 "+
178                                               "00 48 "+//length
179                                               "08 "+//tableId
180                                               "00 "+//pad_01
181                                               "00 00 00 09 "+//durationSec
182                                               "00 00 00 07 "+//durationNsec
183                                               "00 0C "+//priority
184                                               "00 0E "+//idleTimeout
185                                               "00 0F "+//hardTimeout
186                                               "00 0B "+//flags
187                                               "00 00 00 00 "+//pad_02
188                                               "FF 01 01 01 01 01 01 01 "+//cookie
189                                               "EF 01 01 01 01 01 01 01 "+//packetCount
190                                               "7F 01 01 01 01 01 01 01 "+//byteCount
191                                               "00 01 00 04 00 00 00 00 "+//empty match
192                                               "00 01 00 08 06 00 00 00 "+
193                                               "00 01 00 08 06 00 00 00 "+
194                                               "00 48 "+//length
195                                               "08 "+//tableId
196                                               "00 "+//pad_01
197                                               "00 00 00 09 "+//durationSec
198                                               "00 00 00 07 "+//durationNsec
199                                               "00 0C "+//priority
200                                               "00 0E "+//idleTimeout
201                                               "00 0F "+//hardTimeout
202                                               "00 0B "+//flags
203                                               "00 00 00 00 "+//pad_02
204                                               "FF 01 01 01 01 01 01 01 "+//cookie
205                                               "EF 01 01 01 01 01 01 01 "+//packetCount
206                                               "7F 01 01 01 01 01 01 01 "+//byteCount
207                                               "00 01 00 04 00 00 00 00 "+//empty match
208                                               "00 01 00 08 06 00 00 00 "+
209                                               "00 01 00 08 06 00 00 00");
210         
211         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
212         
213         BufferHelper.checkHeaderV13(builtByFactory);
214         Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
215         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
216         MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
217         MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
218         FlowStats flowStats1 = message.getFlowStats().get(0);
219         Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
220         Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
221         Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
222         Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
223         Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
224         Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
225         Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), 
226                 flowStats1.getFlags());
227         Assert.assertEquals("Wrong cookie", 
228                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
229                 flowStats1.getCookie());
230         Assert.assertEquals("Wrong packetCount", 
231                 new BigInteger(1, new byte[]{(byte) 0xEF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
232                 flowStats1.getPacketCount());
233         Assert.assertEquals("Wrong byteCount", 
234                 new BigInteger(1, new byte[]{(byte) 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
235                 flowStats1.getByteCount());
236         Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
237     }
238     
239     /**
240      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
241      */
242     @Test
243     public void testMultipartReplyAggregateBody(){
244         ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 00 00 00 00 "+
245                                               "FF 01 01 01 01 01 01 01 "+//packetCount
246                                               "0F 01 01 01 01 01 01 01 "+//byteCount
247                                               "00 00 00 08 "+//flowCount
248                                               "00 00 00 00"//pad
249                                               );
250         
251         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
252         
253         BufferHelper.checkHeaderV13(builtByFactory);
254         Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue());
255         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
256         MultipartReplyAggregateCase messageCase = (MultipartReplyAggregateCase) builtByFactory.getMultipartReplyBody();
257         MultipartReplyAggregate message = messageCase.getMultipartReplyAggregate();
258         Assert.assertEquals("Wrong packetCount", 
259                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
260                 message.getPacketCount());
261         Assert.assertEquals("Wrong byteCount", 
262                 new BigInteger(1, new byte[]{(byte) 0x0F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
263                 message.getByteCount());
264         Assert.assertEquals("Wrong flowCount", 
265                 8, 
266                 message.getFlowCount().intValue());
267     }
268     
269     /**
270      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
271      */
272     @Test
273     public void testMultipartReplyTableBody(){
274         ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 00 00 00 00 "+
275                                               "08 "+//tableId
276                                               "00 00 00 "+//pad
277                                               "00 00 00 10 "+//activeCount
278                                               "FF 01 01 01 01 01 01 01 "+//lookupCount
279                                               "AF 01 01 01 01 01 01 01"//matchedCount
280                                               );
281         
282         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
283         
284         BufferHelper.checkHeaderV13(builtByFactory);
285         Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
286         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
287         
288         MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
289         MultipartReplyTable message = messageCase.getMultipartReplyTable();
290         Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
291         Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
292         Assert.assertEquals("Wrong lookupCount", 
293                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
294                 message.getTableStats().get(0).getLookupCount());
295         Assert.assertEquals("Wrong matchedCount", 
296                 new BigInteger(1, new byte[]{(byte) 0xAF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
297                 message.getTableStats().get(0).getMatchedCount());
298     }
299     
300     /**
301      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
302      */
303     @Test
304     public void testMultipartReplyPortStatsBody(){
305         ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 00 00 00 00 "+
306                                               "00 00 00 FF "+//portNo
307                                               "00 00 00 00 "+//pad
308                                               "FF 01 01 01 01 01 01 01 "+//rxPackets
309                                               "FF 02 02 02 02 02 02 02 "+//txPackets
310                                               "FF 02 03 02 03 02 03 02 "+//rxBytes
311                                               "FF 02 03 02 03 02 03 02 "+//txBytes
312                                               "FF 02 03 02 03 02 03 02 "+//rxDropped
313                                               "FF 02 03 02 03 02 03 02 "+//txDropped
314                                               "FF 02 03 02 03 02 03 02 "+//rxErrors
315                                               "FF 02 03 02 03 02 03 02 "+//txErrors
316                                               "FF 02 03 02 03 02 03 02 "+//rxFrameErr
317                                               "FF 02 03 02 03 02 03 02 "+//rxOverErr
318                                               "FF 02 03 02 03 02 03 02 "+//rxCrcErr
319                                               "FF 02 03 02 03 02 03 02 "+//collisions
320                                               "00 00 00 02 "+//durationSec
321                                               "00 00 00 04"//durationNsec
322                                               );
323         
324         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
325         
326         BufferHelper.checkHeaderV13(builtByFactory);
327         Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());
328         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
329         MultipartReplyPortStatsCase messageCase = (MultipartReplyPortStatsCase) builtByFactory.getMultipartReplyBody();
330         MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();
331         Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());
332         Assert.assertEquals("Wrong rxPackets", 
333                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
334                 message.getPortStats().get(0).getRxPackets());
335         Assert.assertEquals("Wrong txPackets", 
336                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
337                 message.getPortStats().get(0).getTxPackets());
338         Assert.assertEquals("Wrong rxBytes", 
339                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
340                 message.getPortStats().get(0).getRxBytes());
341         Assert.assertEquals("Wrong txBytes", 
342                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
343                 message.getPortStats().get(0).getTxBytes());
344         Assert.assertEquals("Wrong rxDropped", 
345                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
346                 message.getPortStats().get(0).getRxDropped());
347         Assert.assertEquals("Wrong txDropped", 
348                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
349                 message.getPortStats().get(0).getTxDropped());
350         Assert.assertEquals("Wrong rxErrors", 
351                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
352                 message.getPortStats().get(0).getRxErrors());
353         Assert.assertEquals("Wrong txErrors", 
354                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
355                 message.getPortStats().get(0).getTxErrors());
356         Assert.assertEquals("Wrong rxFrameErr", 
357                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
358                 message.getPortStats().get(0).getRxFrameErr());
359         Assert.assertEquals("Wrong rxOverErr", 
360                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
361                 message.getPortStats().get(0).getRxOverErr());
362         Assert.assertEquals("Wrong rxCrcErr", 
363                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
364                 message.getPortStats().get(0).getRxCrcErr());
365         Assert.assertEquals("Wrong collisions", 
366                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
367                 message.getPortStats().get(0).getCollisions());
368         Assert.assertEquals("Wrong durationSec", 2, message.getPortStats().get(0).getDurationSec().intValue());
369         Assert.assertEquals("Wrong durationNsec", 4, message.getPortStats().get(0).getDurationNsec().intValue());
370     }
371     
372     /**
373      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
374      */
375     @Test
376     public void testMultipartReplyQueueBody(){
377         ByteBuf bb = BufferHelper.buildBuffer("00 05 00 01 00 00 00 00 "+
378                                               "00 00 00 FF "+//portNo
379                                               "00 00 00 10 "+//queueId
380                                               "FF 02 03 02 03 02 03 02 "+//txBytes
381                                               "FF 02 02 02 02 02 02 02 "+//txPackets
382                                               "FF 02 03 02 03 02 03 02 "+//txErrors
383                                               "00 00 00 02 "+//durationSec
384                                               "00 00 00 04"//durationNsec
385                                               );
386         
387         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
388         
389         BufferHelper.checkHeaderV13(builtByFactory);
390         Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue());
391         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
392         MultipartReplyQueueCase messageCase = (MultipartReplyQueueCase) builtByFactory.getMultipartReplyBody();
393         MultipartReplyQueue message = messageCase.getMultipartReplyQueue();
394         Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue());
395         Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue());
396         Assert.assertEquals("Wrong txBytes", 
397                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
398                 message.getQueueStats().get(0).getTxBytes());
399         Assert.assertEquals("Wrong txPackets", 
400                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
401                 message.getQueueStats().get(0).getTxPackets());
402         Assert.assertEquals("Wrong txErrors", 
403                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), 
404                 message.getQueueStats().get(0).getTxErrors());
405         Assert.assertEquals("Wrong durationSec", 2, message.getQueueStats().get(0).getDurationSec().intValue());
406         Assert.assertEquals("Wrong durationNsec", 4, message.getQueueStats().get(0).getDurationNsec().intValue());
407     }
408     
409     /**
410      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
411      */
412     @Test
413     public void testMultipartReplyGroupBody(){
414         ByteBuf bb = BufferHelper.buildBuffer("00 06 00 01 00 00 00 00 "+
415                                               "00 48 "+//length
416                                               "00 00 "+//pad1
417                                               "00 00 00 10 "+//groupId
418                                               "00 00 00 12 "+//refCount
419                                               "00 00 00 00 "+//pad2
420                                               "FF 01 01 01 01 01 01 01 "+//packetCount
421                                               "FF 01 01 01 01 01 01 01 "+//byteCount
422                                               "00 00 00 08 "+//durationSec
423                                               "00 00 00 09 "+//durationNsec
424                                               "FF 01 01 01 01 01 01 01 "+//packetCountBucket
425                                               "FF 01 01 01 01 01 01 01 "+//byteCountBucket
426                                               "FF 02 02 02 02 02 02 02 "+//packetCountBucket_2
427                                               "FF 02 02 02 02 02 02 02 "+//byteCountBucket_2
428                                               "00 48 "+//length_2
429                                               "00 00 "+//pad1.2
430                                               "00 00 00 10 "+//groupId_2
431                                               "00 00 00 12 "+//refCount_2
432                                               "00 00 00 00 "+//pad2.2
433                                               "FF 01 01 01 01 01 01 01 "+//packetCount_2
434                                               "FF 01 01 01 01 01 01 01 "+//byteCount_2
435                                               "00 00 00 08 "+//durationSec_2
436                                               "00 00 00 09 "+//durationNsec_2
437                                               "FF 01 01 01 01 01 01 01 "+//packetCountBucket_1.2
438                                               "FF 01 01 01 01 01 01 01 "+//byteCountBucket_1.2
439                                               "FF 02 02 02 02 02 02 02 "+//packetCountBucket_2.2
440                                               "FF 02 02 02 02 02 02 02"//byteCountBucket_2.2
441                                               );
442         
443         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
444         
445         BufferHelper.checkHeaderV13(builtByFactory);
446         Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue());
447         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
448         MultipartReplyGroupCase messageCase = (MultipartReplyGroupCase) builtByFactory.getMultipartReplyBody();
449         MultipartReplyGroup message = messageCase.getMultipartReplyGroup();
450         Assert.assertEquals("Wrong groupId", 16, message.getGroupStats().get(0).getGroupId().getValue().intValue());
451         Assert.assertEquals("Wrong refCount", 18, message.getGroupStats().get(0).getRefCount().intValue());
452         Assert.assertEquals("Wrong packetCount", 
453                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
454                 message.getGroupStats().get(0).getPacketCount());
455         Assert.assertEquals("Wrong byteCount", 
456                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
457                 message.getGroupStats().get(0).getByteCount());
458         Assert.assertEquals("Wrong durationSec", 8, message.getGroupStats().get(0).getDurationSec().intValue());
459         Assert.assertEquals("Wrong durationNsec", 9, message.getGroupStats().get(0).getDurationNsec().intValue());
460         Assert.assertEquals("Wrong packetCountBucket", 
461                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
462                 message.getGroupStats().get(0).getBucketStats().get(0).getPacketCount());
463         Assert.assertEquals("Wrong byteCountBucket", 
464                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
465                 message.getGroupStats().get(0).getBucketStats().get(0).getByteCount());
466         Assert.assertEquals("Wrong packetCountBucket_2", 
467                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
468                 message.getGroupStats().get(0).getBucketStats().get(1).getPacketCount());
469         Assert.assertEquals("Wrong byteCountBucket_2", 
470                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
471                 message.getGroupStats().get(0).getBucketStats().get(1).getByteCount());
472         
473         Assert.assertEquals("Wrong groupId_2", 16, message.getGroupStats().get(1).getGroupId().getValue().intValue());
474         Assert.assertEquals("Wrong refCount_2", 18, message.getGroupStats().get(1).getRefCount().intValue());
475         Assert.assertEquals("Wrong packetCount_2", 
476                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
477                 message.getGroupStats().get(1).getPacketCount());
478         Assert.assertEquals("Wrong byteCount_2", 
479                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
480                 message.getGroupStats().get(1).getByteCount());
481         Assert.assertEquals("Wrong durationSec_2", 8, message.getGroupStats().get(1).getDurationSec().intValue());
482         Assert.assertEquals("Wrong durationNsec_2", 9, message.getGroupStats().get(1).getDurationNsec().intValue());
483         Assert.assertEquals("Wrong packetCountBucket_1.2", 
484                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
485                 message.getGroupStats().get(1).getBucketStats().get(0).getPacketCount());
486         Assert.assertEquals("Wrong byteCountBucket_1.2", 
487                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
488                 message.getGroupStats().get(1).getBucketStats().get(0).getByteCount());
489         Assert.assertEquals("Wrong packetCountBucket_2.2", 
490                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
491                 message.getGroupStats().get(1).getBucketStats().get(1).getPacketCount());
492         Assert.assertEquals("Wrong byteCountBucket_2.2", 
493                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
494                 message.getGroupStats().get(1).getBucketStats().get(1).getByteCount());
495     }
496     
497     /**
498      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
499      */
500     @Test
501     public void testMultipartReplyMeterFeaturesBody(){
502         ByteBuf bb = BufferHelper.buildBuffer("00 0B 00 01 00 00 00 00 "+
503                                               "00 00 00 09 "+//maxMeter
504                                               "00 00 00 01 "+//bandTypes
505                                               "00 00 00 03 "+//capabilities
506                                               "03 "+//maxBands
507                                               "04 "+//maxColor
508                                               "00 00"//pad
509                                               );
510         
511         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
512         
513         BufferHelper.checkHeaderV13(builtByFactory);
514         Assert.assertEquals("Wrong type", 11, builtByFactory.getType().getIntValue());
515         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
516         MultipartReplyMeterFeaturesCase messageCase = (MultipartReplyMeterFeaturesCase) builtByFactory.getMultipartReplyBody();
517         MultipartReplyMeterFeatures message = messageCase.getMultipartReplyMeterFeatures();        
518         Assert.assertEquals("Wrong maxMeter", 9, message.getMaxMeter().intValue());
519         Assert.assertEquals("Wrong bandTypes", new MeterBandTypeBitmap(true, false), message.getBandTypes());
520         Assert.assertEquals("Wrong capabilities", new MeterFlags(false, true, true, false), 
521                                                       message.getCapabilities());
522         Assert.assertEquals("Wrong maxBands", 3, message.getMaxBands().intValue());
523         Assert.assertEquals("Wrong maxColor", 4, message.getMaxColor().intValue());
524     }
525     
526     /**
527      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
528      */
529     @Test
530     public void testMultipartReplyMeterBody(){
531         ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+
532                                               "00 00 00 09 "+//meterId
533                                               "00 58 "+//len
534                                               "00 00 00 00 00 00 "+//pad
535                                               "00 00 00 07 "+//flowCount
536                                               "FF 01 01 01 01 01 01 01 "+//packetInCount
537                                               "FF 01 01 01 01 01 01 01 "+//byteInCount
538                                               "00 00 00 05 "+//durationSec
539                                               "00 00 00 05 "+//durationNsec
540                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_01
541                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_01
542                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_02
543                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_02
544                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_03
545                                               "FF 03 03 03 03 03 03 03"//byteBandCount_03
546                                               );
547         
548         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
549         
550         BufferHelper.checkHeaderV13(builtByFactory);
551         Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
552         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
553         MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
554         MultipartReplyMeter message = messageCase.getMultipartReplyMeter();
555         Assert.assertEquals("Wrong meterId", 9, 
556                              message.getMeterStats().get(0).getMeterId().getValue().intValue());
557         Assert.assertEquals("Wrong flowCount", 7, 
558                             message.getMeterStats().get(0).getFlowCount().intValue());
559         Assert.assertEquals("Wrong packetInCount", 
560                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
561                 message.getMeterStats().get(0).getPacketInCount());
562         Assert.assertEquals("Wrong byteInCount", 
563                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
564                 message.getMeterStats().get(0).getByteInCount());
565         Assert.assertEquals("Wrong durationSec", 5, 
566                 message.getMeterStats().get(0).getDurationSec().intValue());
567         Assert.assertEquals("Wrong durationNsec", 5, 
568                 message.getMeterStats().get(0).getDurationNsec().intValue());
569         Assert.assertEquals("Wrong packetBandCount_01", 
570                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
571                 message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
572         Assert.assertEquals("Wrong byteBandCount_01", 
573                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
574                 message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
575         Assert.assertEquals("Wrong packetBandCount_02", 
576                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
577                 message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
578         Assert.assertEquals("Wrong byteBandCount_02", 
579                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
580                 message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
581         Assert.assertEquals("Wrong packetBandCount_03", 
582                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
583                 message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
584         Assert.assertEquals("Wrong byteBandCount_03", 
585                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
586                 message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
587     }
588     
589     /**
590      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
591      */
592     @Test
593     public void testMultipartReplyMeterBodyMulti(){
594         ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+
595                                               "00 00 00 09 "+//meterId_0
596                                               "00 58 "+//len_0
597                                               "00 00 00 00 00 00 "+//pad_0
598                                               "00 00 00 07 "+//flowCount_0
599                                               "FF 01 01 01 01 01 01 01 "+//packetInCount_0
600                                               "FF 01 01 01 01 01 01 01 "+//byteInCount_0
601                                               "00 00 00 05 "+//durationSec_0
602                                               "00 00 00 05 "+//durationNsec_0
603                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_01
604                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_01
605                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_02
606                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_02
607                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_03
608                                               "FF 03 03 03 03 03 03 03 "+//byteBandCount_03
609                                               "00 00 00 08 "+//meterId_1
610                                               "00 58 "+//len_1
611                                               "00 00 00 00 00 00 "+//pad_1
612                                               "00 00 00 07 "+//flowCount_1
613                                               "FF 01 01 01 01 01 01 01 "+//packetInCount_1
614                                               "FF 01 01 01 01 01 01 01 "+//byteInCount_1
615                                               "00 00 00 05 "+//durationSec_1
616                                               "00 00 00 05 "+//durationNsec_1
617                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_11
618                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_11
619                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_12
620                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_12
621                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_13
622                                               "FF 03 03 03 03 03 03 03"//byteBandCount_13
623                                               );
624         
625         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
626         
627         BufferHelper.checkHeaderV13(builtByFactory);
628         Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
629         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
630         MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
631         MultipartReplyMeter message = messageCase.getMultipartReplyMeter();        
632         Assert.assertEquals("Wrong meterId", 9, 
633                              message.getMeterStats().get(0).getMeterId().getValue().intValue());
634         Assert.assertEquals("Wrong flowCount", 7, 
635                             message.getMeterStats().get(0).getFlowCount().intValue());
636         Assert.assertEquals("Wrong packetInCount", 
637                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
638                 message.getMeterStats().get(0).getPacketInCount());
639         Assert.assertEquals("Wrong byteInCount", 
640                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
641                 message.getMeterStats().get(0).getByteInCount());
642         Assert.assertEquals("Wrong durationSec", 5, 
643                 message.getMeterStats().get(0).getDurationSec().intValue());
644         Assert.assertEquals("Wrong durationNsec", 5, 
645                 message.getMeterStats().get(0).getDurationNsec().intValue());
646         Assert.assertEquals("Wrong packetBandCount_01", 
647                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
648                 message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
649         Assert.assertEquals("Wrong byteBandCount_01", 
650                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
651                 message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
652         Assert.assertEquals("Wrong packetBandCount_02", 
653                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
654                 message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
655         Assert.assertEquals("Wrong byteBandCount_02", 
656                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
657                 message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
658         Assert.assertEquals("Wrong packetBandCount_03", 
659                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
660                 message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
661         Assert.assertEquals("Wrong byteBandCount_03", 
662                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
663                 message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
664         
665         Assert.assertEquals("Wrong meterId", 8, 
666                 message.getMeterStats().get(1).getMeterId().getValue().intValue());
667         Assert.assertEquals("Wrong flowCount", 7, 
668                 message.getMeterStats().get(1).getFlowCount().intValue());
669         Assert.assertEquals("Wrong packetInCount", 
670                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
671                 message.getMeterStats().get(1).getPacketInCount());
672         Assert.assertEquals("Wrong byteInCount", 
673                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
674                 message.getMeterStats().get(1).getByteInCount());
675         Assert.assertEquals("Wrong durationSec", 5, 
676                 message.getMeterStats().get(1).getDurationSec().intValue());
677         Assert.assertEquals("Wrong durationNsec", 5, 
678                 message.getMeterStats().get(1).getDurationNsec().intValue());
679         Assert.assertEquals("Wrong packetBandCount_01", 
680                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
681                 message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount());
682         Assert.assertEquals("Wrong byteBandCount_01", 
683                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), 
684                 message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount());
685         Assert.assertEquals("Wrong packetBandCount_02", 
686                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
687                 message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount());
688         Assert.assertEquals("Wrong byteBandCount_02", 
689                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), 
690                 message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount());
691         Assert.assertEquals("Wrong packetBandCount_03", 
692                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
693                 message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount());
694         Assert.assertEquals("Wrong byteBandCount_03", 
695                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), 
696                 message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount());
697     }
698     
699     /**
700      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
701      */
702     @Test
703     public void testMultipartReplyMeterConfigBody(){
704         ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+
705                                               "00 38 "+//len
706                                               "00 0A "+//flags
707                                               "00 00 00 09 "+//meterId
708                                               "00 01 "+//meterBandDrop.type
709                                               "00 10 "+//meterBandDrop.len
710                                               "00 00 00 11 "+//meterBandDrop.rate
711                                               "00 00 00 20 "+//meterBandDrop.burstSize
712                                               "00 00 00 00 "+//meterBandDrop.pad
713                                               "00 02 "+//meterBandDscp.type
714                                               "00 10 "+//meterBandDscp.len
715                                               "00 00 00 11 "+//meterBandDscp.rate
716                                               "00 00 00 20 "+//meterBandDscp.burstSize
717                                               "04 "+//meterBandDscp.precLevel
718                                               "00 00 00 "+//meterBandDscp.pad
719                                               "FF FF "+//meterBandExperimenter.type
720                                               "00 10 "+//meterBandExperimenter.len
721                                               "00 00 00 11 "+//meterBandExperimenter.rate
722                                               "00 00 00 20 "+//meterBandExperimenter.burstSize
723                                               "00 00 00 04"//meterBandExperimenter.experimenter
724                                               );
725         
726         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
727         
728         BufferHelper.checkHeaderV13(builtByFactory);
729         Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue());
730         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
731         MultipartReplyMeterConfigCase messageCase = (MultipartReplyMeterConfigCase) builtByFactory.getMultipartReplyBody();
732         MultipartReplyMeterConfig message = messageCase.getMultipartReplyMeterConfig();        
733         Assert.assertEquals("Wrong flags", new MeterFlags(false, false, true, true),
734                              message.getMeterConfig().get(0).getFlags());
735         Assert.assertEquals("Wrong meterId", 9, 
736                              message.getMeterConfig().get(0).getMeterId().getValue().intValue());
737         
738         MeterBandDropCase dropCase = (MeterBandDropCase) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); 
739         MeterBandDrop meterBandDrop = dropCase.getMeterBandDrop();
740         Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); 
741         Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue());
742         Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue());
743         
744         MeterBandDscpRemarkCase dscpCase = (MeterBandDscpRemarkCase) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); 
745         MeterBandDscpRemark meterBandDscp = dscpCase.getMeterBandDscpRemark();
746         Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); 
747         Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue());
748         Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue());
749         Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue());
750         
751         MeterBandExperimenterCase experimenterCase = (MeterBandExperimenterCase) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); 
752         MeterBandExperimenter meterBandExperimenter = experimenterCase.getMeterBandExperimenter();
753         Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); 
754         Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue());
755         Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue());
756         Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue());
757     }
758     
759     /**
760      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
761      */
762     @Test
763     public void testMultipartReplyMeterConfigBodyMulti(){
764         ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+
765                                               "00 38 "+//len
766                                               "00 06 "+//flags
767                                               "00 00 00 09 "+//meterId
768                                               "00 01 "+//meterBandDrop.type
769                                               "00 10 "+//meterBandDrop.len
770                                               "00 00 00 11 "+//meterBandDrop.rate
771                                               "00 00 00 20 "+//meterBandDrop.burstSize
772                                               "00 00 00 00 "+//meterBandDrop.pad
773                                               "00 02 "+//meterBandDscp.type
774                                               "00 10 "+//meterBandDscp.len
775                                               "00 00 00 11 "+//meterBandDscp.rate
776                                               "00 00 00 20 "+//meterBandDscp.burstSize
777                                               "04 "+//meterBandDscp.precLevel
778                                               "00 00 00 "+//meterBandDscp.pad
779                                               "FF FF "+//meterBandExperimenter.type
780                                               "00 10 "+//meterBandExperimenter.len
781                                               "00 00 00 11 "+//meterBandExperimenter.rate
782                                               "00 00 00 20 "+//meterBandExperimenter.burstSize
783                                               "00 00 00 04 "+//meterBandExperimenter.experimenter
784                                               
785                                               "00 18 "+//len01
786                                               "00 03 "+//flags01
787                                               "00 00 00 07 "+//meterId01
788                                               "00 02 "+//meterBandDscp01.type
789                                               "00 10 "+//meterBandDscp01.len
790                                               "00 00 00 11 "+//meterBandDscp01.rate
791                                               "00 00 00 20 "+//meterBandDscp01.burstSize
792                                               "04 "+//meterBandDscp01.precLevel
793                                               "00 00 00"//meterBandDscp01.pad
794                                               );
795         
796         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
797         
798         BufferHelper.checkHeaderV13(builtByFactory);
799         Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue());
800         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
801         MultipartReplyMeterConfigCase messageCase = (MultipartReplyMeterConfigCase) builtByFactory.getMultipartReplyBody();
802         MultipartReplyMeterConfig message = messageCase.getMultipartReplyMeterConfig();        
803         Assert.assertEquals("Wrong flags", new MeterFlags(true, false, true, false), 
804                              message.getMeterConfig().get(0).getFlags());
805         Assert.assertEquals("Wrong meterId", 9, 
806                              message.getMeterConfig().get(0).getMeterId().getValue().intValue());
807         
808         MeterBandDropCase dropCase = (MeterBandDropCase) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); 
809         MeterBandDrop meterBandDrop = dropCase.getMeterBandDrop(); 
810         Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); 
811         Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue());
812         Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue());
813         
814         MeterBandDscpRemarkCase dscpCase = (MeterBandDscpRemarkCase) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); 
815         MeterBandDscpRemark meterBandDscp = dscpCase.getMeterBandDscpRemark();
816         Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); 
817         Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue());
818         Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue());
819         Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue());
820         
821         MeterBandExperimenterCase experimenterCase = (MeterBandExperimenterCase) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); 
822         MeterBandExperimenter meterBandExperimenter = experimenterCase.getMeterBandExperimenter();
823         Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); 
824         Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue());
825         Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue());
826         Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue());
827         
828         LOGGER.info(message.getMeterConfig().get(0).getFlags().toString());
829         Assert.assertEquals("Wrong flags01", new MeterFlags(false, true, true, false),
830                              message.getMeterConfig().get(1).getFlags());
831         Assert.assertEquals("Wrong meterId01", 7, 
832                              message.getMeterConfig().get(1).getMeterId().getValue().intValue());
833         
834         MeterBandDscpRemarkCase dscpCase01 = (MeterBandDscpRemarkCase) message.getMeterConfig().get(1).getBands().get(0).getMeterBand(); 
835         MeterBandDscpRemark meterBandDscp01 = dscpCase01.getMeterBandDscpRemark();
836         Assert.assertEquals("Wrong meterBandDscp01.type", 2, meterBandDscp01.getType().getIntValue()); 
837         Assert.assertEquals("Wrong meterBandDscp01.rate", 17, meterBandDscp01.getRate().intValue());
838         Assert.assertEquals("Wrong meterBandDscp01.burstSize", 32, meterBandDscp01.getBurstSize().intValue());
839         Assert.assertEquals("Wrong meterBandDscp01.precLevel", 4, meterBandDscp01.getPrecLevel().intValue());
840         
841     }
842     
843     /**
844      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
845      */
846     @Test
847     public void testMultipartReplyExperimenterBody(){
848         ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+
849                                               "00 00 00 0F "+//experimenterId
850                                               "00 00 00 FF "+//expType
851                                               "00 00 01 01 00 00 01 01"
852                                               );
853         
854         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
855         
856         BufferHelper.checkHeaderV13(builtByFactory);
857         Assert.assertEquals("Wrong type", 0xFFFF, builtByFactory.getType().getIntValue());
858         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
859         MultipartReplyExperimenterCase messageCase = (MultipartReplyExperimenterCase) builtByFactory.getMultipartReplyBody();
860         MultipartReplyExperimenter message = messageCase.getMultipartReplyExperimenter();        
861         Assert.assertEquals("Wrong experimenterId", 15, message.getExperimenter().intValue());
862         Assert.assertEquals("Wrong expType", 255, message.getExpType().intValue());
863         Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}, 
864                              message.getData());
865     }
866     
867     /**
868      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
869      */
870     @Test
871     public void testMultipartReplyPortDescBody(){
872         final byte MAX_PORT_NAME_LEN = 16;
873         ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 01 00 00 00 00 "+
874                                               "00 01 02 03 "+ //portNo
875                                               "00 00 00 00 "+ //padding01
876                                               "08 00 27 00 B0 EB " + //mac address
877                                               "00 00"); //padding02
878         //port name
879         String portName = "SampleText";
880         byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN];
881         portNameBytes = portName.getBytes();
882         bb.writeBytes(portNameBytes);
883         ByteBufUtils.padBuffer((MAX_PORT_NAME_LEN - portNameBytes.length), bb);
884         
885         ByteBuf bb2 =  BufferHelper.buildBuffer("00 00 00 41 " + //port config
886                                                 "00 00 00 05 " + //port state
887                                                 "00 00 00 81 " + //current features
888                                                 "00 00 81 81 " + //advertised features
889                                                 "00 00 C1 89 " + //supported features
890                                                 "00 00 C5 8D " + //peer features
891                                                 "00 00 00 81 " + //curr speed
892                                                 "00 00 00 80" //max speed
893                                                 );
894         bb.writeBytes(bb2.copy(4, bb2.readableBytes()-4));//excluding version and xid
895         
896         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
897         
898         BufferHelper.checkHeaderV13(builtByFactory);
899         Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue());
900         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
901         MultipartReplyPortDescCase messageCase = (MultipartReplyPortDescCase) builtByFactory.getMultipartReplyBody();
902         MultipartReplyPortDesc message = messageCase.getMultipartReplyPortDesc();
903         Assert.assertEquals("Wrong portNo", 66051L, message.getPorts().get(0).getPortNo().longValue());
904         Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), 
905                                                 message.getPorts().get(0).getHwAddr());
906         Assert.assertEquals("Wrong portName", "SampleText", 
907                                                 message.getPorts().get(0).getName());
908         Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), 
909                 message.getPorts().get(0).getConfig());
910         Assert.assertEquals("Wrong portState", new PortState(false, true, true),
911                                                message.getPorts().get(0).getState());
912         Assert.assertEquals("Wrong currentFeatures", new PortFeatures(false, false, false, false,
913                                                                       false, true, false, false, 
914                                                                       false, true, false, false, 
915                                                                       false, false, false, false), 
916                                                   message.getPorts().get(0).getCurrentFeatures());
917         Assert.assertEquals("Wrong advertisedFeatures", 
918                                             new PortFeatures(true, false, false, false,
919                                                             false, true, false, false, 
920                                                             false, true, false, false, 
921                                                             false, false, false, true), 
922                                               message.getPorts().get(0).getAdvertisedFeatures());
923         Assert.assertEquals("Wrong supportedFeatures", 
924                                             new PortFeatures(true, true, false, false,
925                                                             false, true, false, false, 
926                                                             false, true, false, false, 
927                                                             false, false, true, true), 
928                                               message.getPorts().get(0).getSupportedFeatures());
929         Assert.assertEquals("Wrong peerFeatures", 
930                                             new PortFeatures(true, true, true, false,
931                                                     false, true, false, false, 
932                                                     false, true, false, false, 
933                                                     false, true, true, true), 
934                                               message.getPorts().get(0).getPeerFeatures());
935         Assert.assertEquals("Wrong currSpeed", 129L, message.getPorts().get(0).getCurrSpeed().longValue());
936         Assert.assertEquals("Wrong maxSpeed", 128L, message.getPorts().get(0).getMaxSpeed().longValue());
937     }
938     
939     /**
940      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
941      * Test covers bodies of actions Output, Copy TTL Out, Copy TTL In
942      */
943     @Test
944     public void testMultipartReplyGroupDescBody01(){
945         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
946                                               "00 38 "+//len
947                                               "01 "+//type
948                                               "00 "+//pad
949                                               "00 00 00 08 "+//groupId
950                                               "00 30 "+//bucketLen
951                                               "00 06 "+//bucketWeight
952                                               "00 00 00 05 "+//bucketWatchPort
953                                               "00 00 00 04 "+//bucketWatchGroup
954                                               "00 00 00 00 "+//bucketPad
955                                               "00 00 "+//outputType
956                                               "00 10 "+//outputLen
957                                               "00 00 10 FF "+//outputPort
958                                               "FF FF "+//outputMaxLen
959                                               "00 00 00 00 00 00 "+//outputPad
960                                               "00 0B "+//copyTTLOutType
961                                               "00 08 "+//copyTTLOutLen
962                                               "00 00 00 00 "+//copyTTLOutPad
963                                               "00 0C "+//copyTTLIntType
964                                               "00 08 "+//copyTTLIntLen
965                                               "00 00 00 00"//copyTTLInPad
966                                               );
967         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
968         
969         BufferHelper.checkHeaderV13(builtByFactory);
970         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
971         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
972         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
973         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
974         Assert.assertEquals("Wrong type", 1, 
975                              message.getGroupDesc().get(0).getType().getIntValue());
976         Assert.assertEquals("Wrong groupId", 8, 
977                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
978         Assert.assertEquals("Wrong bucketWeight", 6, 
979                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
980         Assert.assertEquals("Wrong bucketWatchPort", 5, 
981                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().
982                                                                         getValue().intValue());
983         Assert.assertEquals("Wrong bucketWatchGroup", 4, 
984                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
985         
986         Assert.assertEquals("Wrong outputType", Output.class, 
987                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
988                 .getType());
989         
990         Assert.assertEquals("Wrong outputPort", 4351, 
991                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
992                 .getAugmentation(PortAction.class).
993                 getPort().getValue().intValue());
994         
995         Assert.assertEquals("Wrong outputMaxLen", 65535, 
996                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
997                 .getAugmentation(MaxLengthAction.class).
998                 getMaxLength().intValue());
999         
1000         Assert.assertEquals("Wrong copyTtlOutType", CopyTtlOut.class, 
1001                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1002                 .getType());
1003         
1004         Assert.assertEquals("Wrong copyTtlInType", CopyTtlIn.class, 
1005                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(2)
1006                 .getType());
1007     }
1008     
1009     /**
1010      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
1011      * Test covers bodies of actions Set MPLS TTL , Dec MPLS TTL, Push VLAN. Push MPLS, Push PBB
1012      */
1013     @Test
1014     public void testMultipartReplyGroupDescBody02(){
1015         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
1016                                               "00 40 "+//len
1017                                               "01 "+//type
1018                                               "00 "+//pad
1019                                               "00 00 00 08 "+//groupId
1020                                               "00 38 "+//bucketLen
1021                                               "00 06 "+//bucketWeight
1022                                               "00 00 00 05 "+//bucketWatchPort
1023                                               "00 00 00 04 "+//bucketWatchGroup
1024                                               "00 00 00 00 "+//bucketPad
1025                                               "00 0F "+//setMplsTtlType
1026                                               "00 08 "+//setMplsTtlLen
1027                                               "09 "+//setMplsTtlMPLS_TTL
1028                                               "00 00 00 "+//setMplsTtlPad
1029                                               "00 10 "+//decMplsTtlType
1030                                               "00 08 "+//decMplsTtlLen
1031                                               "00 00 00 00 "+//decMplsTtlPad
1032                                               "00 11 "+//pushVlanType
1033                                               "00 08 "+//pushVlanLen
1034                                               "00 20 "+//pushVlanEthertype
1035                                               "00 00 "+//pushVlanPad
1036                                               "00 13 "+//pushMplsType
1037                                               "00 08 "+//pushMplsLen
1038                                               "00 FF "+//pushMplsEthertype
1039                                               "00 00 "+//pushMplsPad
1040                                               "00 1A "+//pushPbbType
1041                                               "00 08 "+//pushPbbLen
1042                                               "0F FF "+//pushPbbEthertype
1043                                               "00 00"//pushPbbPad
1044                                               );
1045         
1046         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
1047         
1048         BufferHelper.checkHeaderV13(builtByFactory);
1049         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
1050         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
1051         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
1052         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();        
1053         Assert.assertEquals("Wrong type", 1, 
1054                              message.getGroupDesc().get(0).getType().getIntValue());
1055         Assert.assertEquals("Wrong groupId", 8, 
1056                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
1057         Assert.assertEquals("Wrong bucketWeight", 6, 
1058                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
1059         Assert.assertEquals("Wrong bucketWatchPort", 5, 
1060                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().getValue().intValue());
1061         Assert.assertEquals("Wrong bucketWatchGroup", 4, 
1062                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
1063         Assert.assertEquals("Wrong setMplsTtlType", SetMplsTtl.class, 
1064                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
1065                 .getType());
1066         Assert.assertEquals("Wrong setMplsTtlMPLS_TTL", 9, 
1067                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
1068                 .getAugmentation(MplsTtlAction.class).
1069                 getMplsTtl().intValue());
1070         Assert.assertEquals("Wrong decMplsTtlType", DecMplsTtl.class, 
1071                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1072                 .getType());
1073         Assert.assertEquals("Wrong pushVlanType", PushVlan.class, 
1074                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(2)
1075                 .getType());
1076         Assert.assertEquals("Wrong pushVlanEthertype", 32, 
1077                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(2)
1078                 .getAugmentation(EthertypeAction.class).
1079                 getEthertype().getValue().intValue());
1080         Assert.assertEquals("Wrong pushMplsType", PushMpls.class, 
1081                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(3)
1082                 .getType());
1083         Assert.assertEquals("Wrong pushMplsEthertype", 255, 
1084                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(3).
1085                 getAugmentation(EthertypeAction.class).
1086                 getEthertype().getValue().intValue());
1087         Assert.assertEquals("Wrong pushPbbType", PushPbb.class, 
1088                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(4)
1089                 .getType());
1090         Assert.assertEquals("Wrong pushPbbEthertype", 4095, 
1091                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(4)
1092                 .getAugmentation(EthertypeAction.class).
1093                 getEthertype().getValue().intValue());
1094     }
1095     
1096     /**
1097      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
1098      * Test covers bodies of actions Pop VLAN, Pop PBB, Pop MPLS, Group, Dec NW TTL
1099      */
1100     @Test
1101     public void testMultipartReplyGroupDescBody03(){
1102         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
1103                                               "00 48 "+//len
1104                                               "01 "+//type
1105                                               "00 "+//pad
1106                                               "00 00 00 08 "+//groupId
1107                                               "00 40 "+//bucketLen
1108                                               "00 06 "+//bucketWeight
1109                                               "00 00 00 05 "+//bucketWatchPort
1110                                               "00 00 00 04 "+//bucketWatchGroup
1111                                               "00 00 00 00 "+//bucketPad
1112                                               "00 12 "+//popVlanType
1113                                               "00 08 "+//popVlanLen
1114                                               "00 00 00 00 "+//popVlanPad
1115                                               "00 1B "+//popPbbType
1116                                               "00 08 "+//popPbbLen
1117                                               "00 00 00 00 "+//popPbbPad
1118                                               "00 14 "+//popMplsType
1119                                               "00 08 "+//popMplsLen
1120                                               "00 CF "+//popMplsEthertype
1121                                               "00 00 "+//popMplsPad
1122                                               "00 15 "+//setQueueType
1123                                               "00 08 "+//setQueueLen
1124                                               "00 CF 00 00 "+//setQueueQueueId
1125                                               "00 16 "+//groupType
1126                                               "00 08 "+//groupLen
1127                                               "00 CF 00 00 "+//groupGroupId
1128                                               "00 18 "+//decNwTtlType
1129                                               "00 08 "+//decNwTtlLen
1130                                               "00 00 00 00"//decNwTtlPad
1131                                               );
1132         
1133         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
1134         
1135         BufferHelper.checkHeaderV13(builtByFactory);
1136         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
1137         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
1138         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
1139         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();        
1140         Assert.assertEquals("Wrong type", 1, message.getGroupDesc().get(0).getType().getIntValue());
1141         Assert.assertEquals("Wrong groupId", 8, message.getGroupDesc().get(0).getGroupId().getValue().intValue());
1142         Assert.assertEquals("Wrong bucketWeight", 6, 
1143                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
1144         Assert.assertEquals("Wrong bucketWatchPort", 5, 
1145                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().getValue().intValue());
1146         Assert.assertEquals("Wrong bucketWatchGroup", 4, 
1147                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
1148         Assert.assertEquals("Wrong popVlanType", PopVlan.class, 
1149                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
1150                 .getType());
1151         Assert.assertEquals("Wrong popPbbType", PopPbb.class, 
1152                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1153                 .getType());
1154         Assert.assertEquals("Wrong popMplsType", PopMpls.class, 
1155                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(2)
1156                 .getType());
1157         Assert.assertEquals("Wrong popMplsEthertype", 207, 
1158                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(2)
1159                 .getAugmentation(EthertypeAction.class).
1160                 getEthertype().getValue().intValue());
1161         Assert.assertEquals("Wrong setQueueType", SetQueue.class, 
1162                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(3)
1163                 .getType());
1164         Assert.assertEquals("Wrong setQueueQueueId", 13565952, 
1165                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(3)
1166                 .getAugmentation(QueueIdAction.class).
1167                 getQueueId().intValue());
1168         Assert.assertEquals("Wrong groupType", Group.class, 
1169                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(4)
1170                 .getType());
1171         Assert.assertEquals("Wrong groupGroupId", 13565952, 
1172                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(4)
1173                 .getAugmentation(GroupIdAction.class).
1174                 getGroupId().intValue());
1175         Assert.assertEquals("Wrong decNwTtlType", DecNwTtl.class, 
1176                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(5)
1177                 .getType());
1178     }
1179     
1180     /**
1181      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
1182      * Test covers bodies of actions NW TTL, Experimenter
1183      */
1184     @Test
1185     public void testMultipartReplyGroupDescBody04(){
1186         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
1187                                               "00 30 "+//len
1188                                               "01 "+//type
1189                                               "00 "+//pad
1190                                               "00 00 00 08 "+//groupId
1191                                               "00 28 "+//bucketLen
1192                                               "00 06 "+//bucketWeight
1193                                               "00 00 00 05 "+//bucketWatchPort
1194                                               "00 00 00 04 "+//bucketWatchGroup
1195                                               "00 00 00 00 "+//bucketPad
1196                                               "00 17 "+//nwTTlType
1197                                               "00 08 "+//nwTTlLen
1198                                               "0E "+//nwTTlnwTTL
1199                                               "00 00 00 "+//nwTTlPad
1200                                               "00 19 "+//setFieldType
1201                                               "00 10 "+//setFieldLen
1202                                               "80 00 "+//setFieldOXMClass
1203                                               "00 "+//setFieldOXMField
1204                                               "04 "+//setFieldOXMLength
1205                                               "00 00 00 FF "+ //setFieldPort
1206                                               "00 00 00 00"
1207                 );
1208         
1209         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
1210         
1211         BufferHelper.checkHeaderV13(builtByFactory);
1212         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
1213         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
1214         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
1215         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
1216         Assert.assertEquals("Wrong type", 1, 
1217                              message.getGroupDesc().get(0).getType().getIntValue());
1218         Assert.assertEquals("Wrong groupId", 8, 
1219                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
1220         Assert.assertEquals("Wrong bucketWeight", 6, 
1221                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
1222         Assert.assertEquals("Wrong bucketWatchPort", 5, 
1223                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().
1224                                                                         getValue().intValue());
1225         Assert.assertEquals("Wrong bucketWatchGroup", 4, 
1226                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
1227         
1228         Assert.assertEquals("Wrong nwTTlType", SetNwTtl.class, 
1229                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
1230                 .getType());
1231         
1232         Assert.assertEquals("Wrong nwTTlnwTTL", 14, 
1233                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0)
1234                 .getAugmentation(NwTtlAction.class).getNwTtl().intValue());
1235         
1236         Assert.assertEquals("Wrong setFieldType", SetField.class, 
1237                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1238                 .getType());
1239         
1240         Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, 
1241                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1242                 .getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmClass());
1243         
1244         Assert.assertEquals("Wrong setFieldOXMField", InPort.class, 
1245                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1246                 .getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmMatchField());
1247         
1248         Assert.assertEquals("Wrong setFieldOXMValue", 255, 
1249                 message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
1250                 .getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).
1251                 getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());
1252     }
1253 }