Bug 2756 - Action model update
[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.OFDeserializer;
20 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
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.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDrop;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemark;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70
71 /**
72  * @author timotej.kubas
73  * @author michal.polkorab
74  */
75 public class MultipartReplyMessageFactoryTest {
76
77     private OFDeserializer<MultipartReplyMessage> multipartFactory;
78
79     /**
80      * Initializes deserializer registry and lookups correct deserializer
81      */
82     @Before
83     public void startUp() {
84         DeserializerRegistry registry = new DeserializerRegistryImpl();
85         registry.init();
86         multipartFactory = registry.getDeserializer(
87                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 19, MultipartReplyMessage.class));
88     }
89
90     private static final Logger LOGGER = LoggerFactory
91             .getLogger(MultipartReplyMessageFactoryTest.class);
92
93     /**
94      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
95      */
96     @Test
97     public void testMultipartReplyDescBody(){
98         final int DESC_STR_LEN = 256;
99         final int SERIAL_NUM_LEN = 32;
100         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 00 00 00");
101
102         String mfrDesc = "Manufacturer description";
103         byte[] mfrDescBytes = new byte[256];
104         mfrDescBytes = mfrDesc.getBytes();
105         bb.writeBytes(mfrDescBytes);
106         bb.writeZero(DESC_STR_LEN - mfrDescBytes.length);
107
108         String hwDesc = "Hardware description";
109         byte[] hwDescBytes = new byte[256];
110         hwDescBytes = hwDesc.getBytes();
111         bb.writeBytes(hwDescBytes);
112         bb.writeZero(DESC_STR_LEN - hwDescBytes.length);
113
114         String swDesc = "Software description";
115         byte[] swDescBytes = new byte[256];
116         swDescBytes = swDesc.getBytes();
117         bb.writeBytes(swDescBytes);
118         bb.writeZero(DESC_STR_LEN - swDescBytes.length);
119
120         String serialNum = "SN0123456789";
121         byte[] serialNumBytes = new byte[32];
122         serialNumBytes = serialNum.getBytes();
123         bb.writeBytes(serialNumBytes);
124         bb.writeZero(SERIAL_NUM_LEN - serialNumBytes.length);
125
126         String dpDesc = "switch3 in room 3120";
127         byte[] dpDescBytes = new byte[256];
128         dpDescBytes = dpDesc.getBytes();
129         bb.writeBytes(dpDescBytes);
130         bb.writeZero(DESC_STR_LEN - dpDescBytes.length);
131
132         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
133
134         BufferHelper.checkHeaderV13(builtByFactory);
135         Assert.assertEquals("Wrong type", 0x00, builtByFactory.getType().getIntValue());
136         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
137         MultipartReplyDescCase messageCase = (MultipartReplyDescCase) builtByFactory.getMultipartReplyBody();
138         MultipartReplyDesc message = messageCase.getMultipartReplyDesc();
139         Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc());
140         Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc());
141         Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc());
142         Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum());
143         Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc());
144     }
145
146     /**
147      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
148      */
149     @Test
150     public void testMultipartReplyAggregateBody(){
151         ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 00 00 00 00 "+
152                                               "FF 01 01 01 01 01 01 01 "+//packetCount
153                                               "0F 01 01 01 01 01 01 01 "+//byteCount
154                                               "00 00 00 08 "+//flowCount
155                                               "00 00 00 00"//pad
156                                               );
157
158         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
159
160         BufferHelper.checkHeaderV13(builtByFactory);
161         Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue());
162         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
163         MultipartReplyAggregateCase messageCase = (MultipartReplyAggregateCase) builtByFactory.getMultipartReplyBody();
164         MultipartReplyAggregate message = messageCase.getMultipartReplyAggregate();
165         Assert.assertEquals("Wrong packetCount",
166                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
167                 message.getPacketCount());
168         Assert.assertEquals("Wrong byteCount",
169                 new BigInteger(1, new byte[]{(byte) 0x0F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
170                 message.getByteCount());
171         Assert.assertEquals("Wrong flowCount",
172                 8,
173                 message.getFlowCount().intValue());
174     }
175
176     /**
177      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
178      */
179     @Test
180     public void testMultipartReplyTableBody(){
181         ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 00 00 00 00 "+
182                                               "08 "+//tableId
183                                               "00 00 00 "+//pad
184                                               "00 00 00 10 "+//activeCount
185                                               "FF 01 01 01 01 01 01 01 "+//lookupCount
186                                               "AF 01 01 01 01 01 01 01"//matchedCount
187                                               );
188
189         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
190
191         BufferHelper.checkHeaderV13(builtByFactory);
192         Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
193         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
194
195         MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
196         MultipartReplyTable message = messageCase.getMultipartReplyTable();
197         Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
198         Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
199         Assert.assertEquals("Wrong lookupCount",
200                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
201                 message.getTableStats().get(0).getLookupCount());
202         Assert.assertEquals("Wrong matchedCount",
203                 new BigInteger(1, new byte[]{(byte) 0xAF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
204                 message.getTableStats().get(0).getMatchedCount());
205     }
206
207     /**
208      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
209      */
210     @Test
211     public void testMultipartReplyPortStatsBody(){
212         ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 00 00 00 00 "+
213                                               "00 00 00 FF "+//portNo
214                                               "00 00 00 00 "+//pad
215                                               "FF 01 01 01 01 01 01 01 "+//rxPackets
216                                               "FF 02 02 02 02 02 02 02 "+//txPackets
217                                               "FF 02 03 02 03 02 03 02 "+//rxBytes
218                                               "FF 02 03 02 03 02 03 02 "+//txBytes
219                                               "FF 02 03 02 03 02 03 02 "+//rxDropped
220                                               "FF 02 03 02 03 02 03 02 "+//txDropped
221                                               "FF 02 03 02 03 02 03 02 "+//rxErrors
222                                               "FF 02 03 02 03 02 03 02 "+//txErrors
223                                               "FF 02 03 02 03 02 03 02 "+//rxFrameErr
224                                               "FF 02 03 02 03 02 03 02 "+//rxOverErr
225                                               "FF 02 03 02 03 02 03 02 "+//rxCrcErr
226                                               "FF 02 03 02 03 02 03 02 "+//collisions
227                                               "00 00 00 02 "+//durationSec
228                                               "00 00 00 04"//durationNsec
229                                               );
230
231         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
232
233         BufferHelper.checkHeaderV13(builtByFactory);
234         Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());
235         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
236         MultipartReplyPortStatsCase messageCase = (MultipartReplyPortStatsCase) builtByFactory.getMultipartReplyBody();
237         MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();
238         Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());
239         Assert.assertEquals("Wrong rxPackets",
240                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
241                 message.getPortStats().get(0).getRxPackets());
242         Assert.assertEquals("Wrong txPackets",
243                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
244                 message.getPortStats().get(0).getTxPackets());
245         Assert.assertEquals("Wrong rxBytes",
246                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
247                 message.getPortStats().get(0).getRxBytes());
248         Assert.assertEquals("Wrong txBytes",
249                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
250                 message.getPortStats().get(0).getTxBytes());
251         Assert.assertEquals("Wrong rxDropped",
252                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
253                 message.getPortStats().get(0).getRxDropped());
254         Assert.assertEquals("Wrong txDropped",
255                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
256                 message.getPortStats().get(0).getTxDropped());
257         Assert.assertEquals("Wrong rxErrors",
258                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
259                 message.getPortStats().get(0).getRxErrors());
260         Assert.assertEquals("Wrong txErrors",
261                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
262                 message.getPortStats().get(0).getTxErrors());
263         Assert.assertEquals("Wrong rxFrameErr",
264                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
265                 message.getPortStats().get(0).getRxFrameErr());
266         Assert.assertEquals("Wrong rxOverErr",
267                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
268                 message.getPortStats().get(0).getRxOverErr());
269         Assert.assertEquals("Wrong rxCrcErr",
270                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
271                 message.getPortStats().get(0).getRxCrcErr());
272         Assert.assertEquals("Wrong collisions",
273                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
274                 message.getPortStats().get(0).getCollisions());
275         Assert.assertEquals("Wrong durationSec", 2, message.getPortStats().get(0).getDurationSec().intValue());
276         Assert.assertEquals("Wrong durationNsec", 4, message.getPortStats().get(0).getDurationNsec().intValue());
277     }
278
279     /**
280      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
281      */
282     @Test
283     public void testMultipartReplyQueueBody(){
284         ByteBuf bb = BufferHelper.buildBuffer("00 05 00 01 00 00 00 00 "+
285                                               "00 00 00 FF "+//portNo
286                                               "00 00 00 10 "+//queueId
287                                               "FF 02 03 02 03 02 03 02 "+//txBytes
288                                               "FF 02 02 02 02 02 02 02 "+//txPackets
289                                               "FF 02 03 02 03 02 03 02 "+//txErrors
290                                               "00 00 00 02 "+//durationSec
291                                               "00 00 00 04"//durationNsec
292                                               );
293
294         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
295
296         BufferHelper.checkHeaderV13(builtByFactory);
297         Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue());
298         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
299         MultipartReplyQueueCase messageCase = (MultipartReplyQueueCase) builtByFactory.getMultipartReplyBody();
300         MultipartReplyQueue message = messageCase.getMultipartReplyQueue();
301         Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue());
302         Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue());
303         Assert.assertEquals("Wrong txBytes",
304                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
305                 message.getQueueStats().get(0).getTxBytes());
306         Assert.assertEquals("Wrong txPackets",
307                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
308                 message.getQueueStats().get(0).getTxPackets());
309         Assert.assertEquals("Wrong txErrors",
310                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}),
311                 message.getQueueStats().get(0).getTxErrors());
312         Assert.assertEquals("Wrong durationSec", 2, message.getQueueStats().get(0).getDurationSec().intValue());
313         Assert.assertEquals("Wrong durationNsec", 4, message.getQueueStats().get(0).getDurationNsec().intValue());
314     }
315
316     /**
317      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
318      */
319     @Test
320     public void testMultipartReplyGroupBody(){
321         ByteBuf bb = BufferHelper.buildBuffer("00 06 00 01 00 00 00 00 "+
322                                               "00 48 "+//length
323                                               "00 00 "+//pad1
324                                               "00 00 00 10 "+//groupId
325                                               "00 00 00 12 "+//refCount
326                                               "00 00 00 00 "+//pad2
327                                               "FF 01 01 01 01 01 01 01 "+//packetCount
328                                               "FF 01 01 01 01 01 01 01 "+//byteCount
329                                               "00 00 00 08 "+//durationSec
330                                               "00 00 00 09 "+//durationNsec
331                                               "FF 01 01 01 01 01 01 01 "+//packetCountBucket
332                                               "FF 01 01 01 01 01 01 01 "+//byteCountBucket
333                                               "FF 02 02 02 02 02 02 02 "+//packetCountBucket_2
334                                               "FF 02 02 02 02 02 02 02 "+//byteCountBucket_2
335                                               "00 48 "+//length_2
336                                               "00 00 "+//pad1.2
337                                               "00 00 00 10 "+//groupId_2
338                                               "00 00 00 12 "+//refCount_2
339                                               "00 00 00 00 "+//pad2.2
340                                               "FF 01 01 01 01 01 01 01 "+//packetCount_2
341                                               "FF 01 01 01 01 01 01 01 "+//byteCount_2
342                                               "00 00 00 08 "+//durationSec_2
343                                               "00 00 00 09 "+//durationNsec_2
344                                               "FF 01 01 01 01 01 01 01 "+//packetCountBucket_1.2
345                                               "FF 01 01 01 01 01 01 01 "+//byteCountBucket_1.2
346                                               "FF 02 02 02 02 02 02 02 "+//packetCountBucket_2.2
347                                               "FF 02 02 02 02 02 02 02"//byteCountBucket_2.2
348                                               );
349
350         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
351
352         BufferHelper.checkHeaderV13(builtByFactory);
353         Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue());
354         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
355         MultipartReplyGroupCase messageCase = (MultipartReplyGroupCase) builtByFactory.getMultipartReplyBody();
356         MultipartReplyGroup message = messageCase.getMultipartReplyGroup();
357         Assert.assertEquals("Wrong groupId", 16, message.getGroupStats().get(0).getGroupId().getValue().intValue());
358         Assert.assertEquals("Wrong refCount", 18, message.getGroupStats().get(0).getRefCount().intValue());
359         Assert.assertEquals("Wrong packetCount",
360                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
361                 message.getGroupStats().get(0).getPacketCount());
362         Assert.assertEquals("Wrong byteCount",
363                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
364                 message.getGroupStats().get(0).getByteCount());
365         Assert.assertEquals("Wrong durationSec", 8, message.getGroupStats().get(0).getDurationSec().intValue());
366         Assert.assertEquals("Wrong durationNsec", 9, message.getGroupStats().get(0).getDurationNsec().intValue());
367         Assert.assertEquals("Wrong packetCountBucket",
368                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
369                 message.getGroupStats().get(0).getBucketStats().get(0).getPacketCount());
370         Assert.assertEquals("Wrong byteCountBucket",
371                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
372                 message.getGroupStats().get(0).getBucketStats().get(0).getByteCount());
373         Assert.assertEquals("Wrong packetCountBucket_2",
374                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
375                 message.getGroupStats().get(0).getBucketStats().get(1).getPacketCount());
376         Assert.assertEquals("Wrong byteCountBucket_2",
377                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
378                 message.getGroupStats().get(0).getBucketStats().get(1).getByteCount());
379
380         Assert.assertEquals("Wrong groupId_2", 16, message.getGroupStats().get(1).getGroupId().getValue().intValue());
381         Assert.assertEquals("Wrong refCount_2", 18, message.getGroupStats().get(1).getRefCount().intValue());
382         Assert.assertEquals("Wrong packetCount_2",
383                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
384                 message.getGroupStats().get(1).getPacketCount());
385         Assert.assertEquals("Wrong byteCount_2",
386                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
387                 message.getGroupStats().get(1).getByteCount());
388         Assert.assertEquals("Wrong durationSec_2", 8, message.getGroupStats().get(1).getDurationSec().intValue());
389         Assert.assertEquals("Wrong durationNsec_2", 9, message.getGroupStats().get(1).getDurationNsec().intValue());
390         Assert.assertEquals("Wrong packetCountBucket_1.2",
391                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
392                 message.getGroupStats().get(1).getBucketStats().get(0).getPacketCount());
393         Assert.assertEquals("Wrong byteCountBucket_1.2",
394                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
395                 message.getGroupStats().get(1).getBucketStats().get(0).getByteCount());
396         Assert.assertEquals("Wrong packetCountBucket_2.2",
397                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
398                 message.getGroupStats().get(1).getBucketStats().get(1).getPacketCount());
399         Assert.assertEquals("Wrong byteCountBucket_2.2",
400                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
401                 message.getGroupStats().get(1).getBucketStats().get(1).getByteCount());
402     }
403
404     /**
405      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
406      */
407     @Test
408     public void testMultipartReplyMeterBody(){
409         ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+
410                                               "00 00 00 09 "+//meterId
411                                               "00 58 "+//len
412                                               "00 00 00 00 00 00 "+//pad
413                                               "00 00 00 07 "+//flowCount
414                                               "FF 01 01 01 01 01 01 01 "+//packetInCount
415                                               "FF 01 01 01 01 01 01 01 "+//byteInCount
416                                               "00 00 00 05 "+//durationSec
417                                               "00 00 00 05 "+//durationNsec
418                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_01
419                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_01
420                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_02
421                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_02
422                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_03
423                                               "FF 03 03 03 03 03 03 03"//byteBandCount_03
424                                               );
425
426         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
427
428         BufferHelper.checkHeaderV13(builtByFactory);
429         Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
430         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
431         MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
432         MultipartReplyMeter message = messageCase.getMultipartReplyMeter();
433         Assert.assertEquals("Wrong meterId", 9,
434                              message.getMeterStats().get(0).getMeterId().getValue().intValue());
435         Assert.assertEquals("Wrong flowCount", 7,
436                             message.getMeterStats().get(0).getFlowCount().intValue());
437         Assert.assertEquals("Wrong packetInCount",
438                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
439                 message.getMeterStats().get(0).getPacketInCount());
440         Assert.assertEquals("Wrong byteInCount",
441                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
442                 message.getMeterStats().get(0).getByteInCount());
443         Assert.assertEquals("Wrong durationSec", 5,
444                 message.getMeterStats().get(0).getDurationSec().intValue());
445         Assert.assertEquals("Wrong durationNsec", 5,
446                 message.getMeterStats().get(0).getDurationNsec().intValue());
447         Assert.assertEquals("Wrong packetBandCount_01",
448                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
449                 message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
450         Assert.assertEquals("Wrong byteBandCount_01",
451                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
452                 message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
453         Assert.assertEquals("Wrong packetBandCount_02",
454                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
455                 message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
456         Assert.assertEquals("Wrong byteBandCount_02",
457                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
458                 message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
459         Assert.assertEquals("Wrong packetBandCount_03",
460                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
461                 message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
462         Assert.assertEquals("Wrong byteBandCount_03",
463                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
464                 message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
465     }
466
467     /**
468      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
469      */
470     @Test
471     public void testMultipartReplyMeterBodyMulti(){
472         ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+
473                                               "00 00 00 09 "+//meterId_0
474                                               "00 58 "+//len_0
475                                               "00 00 00 00 00 00 "+//pad_0
476                                               "00 00 00 07 "+//flowCount_0
477                                               "FF 01 01 01 01 01 01 01 "+//packetInCount_0
478                                               "FF 01 01 01 01 01 01 01 "+//byteInCount_0
479                                               "00 00 00 05 "+//durationSec_0
480                                               "00 00 00 05 "+//durationNsec_0
481                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_01
482                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_01
483                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_02
484                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_02
485                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_03
486                                               "FF 03 03 03 03 03 03 03 "+//byteBandCount_03
487                                               "00 00 00 08 "+//meterId_1
488                                               "00 58 "+//len_1
489                                               "00 00 00 00 00 00 "+//pad_1
490                                               "00 00 00 07 "+//flowCount_1
491                                               "FF 01 01 01 01 01 01 01 "+//packetInCount_1
492                                               "FF 01 01 01 01 01 01 01 "+//byteInCount_1
493                                               "00 00 00 05 "+//durationSec_1
494                                               "00 00 00 05 "+//durationNsec_1
495                                               "FF 01 01 01 01 01 01 01 "+//packetBandCount_11
496                                               "FF 01 01 01 01 01 01 01 "+//byteBandCount_11
497                                               "FF 02 02 02 02 02 02 02 "+//packetBandCount_12
498                                               "FF 02 02 02 02 02 02 02 "+//byteBandCount_12
499                                               "FF 03 03 03 03 03 03 03 "+//packetBandCount_13
500                                               "FF 03 03 03 03 03 03 03"//byteBandCount_13
501                                               );
502
503         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
504
505         BufferHelper.checkHeaderV13(builtByFactory);
506         Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
507         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
508         MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
509         MultipartReplyMeter message = messageCase.getMultipartReplyMeter();
510         Assert.assertEquals("Wrong meterId", 9,
511                              message.getMeterStats().get(0).getMeterId().getValue().intValue());
512         Assert.assertEquals("Wrong flowCount", 7,
513                             message.getMeterStats().get(0).getFlowCount().intValue());
514         Assert.assertEquals("Wrong packetInCount",
515                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
516                 message.getMeterStats().get(0).getPacketInCount());
517         Assert.assertEquals("Wrong byteInCount",
518                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
519                 message.getMeterStats().get(0).getByteInCount());
520         Assert.assertEquals("Wrong durationSec", 5,
521                 message.getMeterStats().get(0).getDurationSec().intValue());
522         Assert.assertEquals("Wrong durationNsec", 5,
523                 message.getMeterStats().get(0).getDurationNsec().intValue());
524         Assert.assertEquals("Wrong packetBandCount_01",
525                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
526                 message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
527         Assert.assertEquals("Wrong byteBandCount_01",
528                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
529                 message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
530         Assert.assertEquals("Wrong packetBandCount_02",
531                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
532                 message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
533         Assert.assertEquals("Wrong byteBandCount_02",
534                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
535                 message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
536         Assert.assertEquals("Wrong packetBandCount_03",
537                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
538                 message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
539         Assert.assertEquals("Wrong byteBandCount_03",
540                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
541                 message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
542
543         Assert.assertEquals("Wrong meterId", 8,
544                 message.getMeterStats().get(1).getMeterId().getValue().intValue());
545         Assert.assertEquals("Wrong flowCount", 7,
546                 message.getMeterStats().get(1).getFlowCount().intValue());
547         Assert.assertEquals("Wrong packetInCount",
548                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
549                 message.getMeterStats().get(1).getPacketInCount());
550         Assert.assertEquals("Wrong byteInCount",
551                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
552                 message.getMeterStats().get(1).getByteInCount());
553         Assert.assertEquals("Wrong durationSec", 5,
554                 message.getMeterStats().get(1).getDurationSec().intValue());
555         Assert.assertEquals("Wrong durationNsec", 5,
556                 message.getMeterStats().get(1).getDurationNsec().intValue());
557         Assert.assertEquals("Wrong packetBandCount_01",
558                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
559                 message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount());
560         Assert.assertEquals("Wrong byteBandCount_01",
561                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}),
562                 message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount());
563         Assert.assertEquals("Wrong packetBandCount_02",
564                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
565                 message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount());
566         Assert.assertEquals("Wrong byteBandCount_02",
567                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}),
568                 message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount());
569         Assert.assertEquals("Wrong packetBandCount_03",
570                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
571                 message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount());
572         Assert.assertEquals("Wrong byteBandCount_03",
573                 new BigInteger(1, new byte[]{(byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}),
574                 message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount());
575     }
576
577     /**
578      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
579      */
580     @Test
581     public void testMultipartReplyMeterConfigBody(){
582         ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+
583                                               "00 28 "+//len
584                                               "00 0A "+//flags
585                                               "00 00 00 09 "+//meterId
586                                               "00 01 "+//meterBandDrop.type
587                                               "00 10 "+//meterBandDrop.len
588                                               "00 00 00 11 "+//meterBandDrop.rate
589                                               "00 00 00 20 "+//meterBandDrop.burstSize
590                                               "00 00 00 00 "+//meterBandDrop.pad
591                                               "00 02 "+//meterBandDscp.type
592                                               "00 10 "+//meterBandDscp.len
593                                               "00 00 00 11 "+//meterBandDscp.rate
594                                               "00 00 00 20 "+//meterBandDscp.burstSize
595                                               "04 "+//meterBandDscp.precLevel
596                                               "00 00 00");//meterBandDscp.pad
597
598         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
599
600         BufferHelper.checkHeaderV13(builtByFactory);
601         Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue());
602         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
603         MultipartReplyMeterConfigCase messageCase = (MultipartReplyMeterConfigCase) builtByFactory.getMultipartReplyBody();
604         MultipartReplyMeterConfig message = messageCase.getMultipartReplyMeterConfig();
605         Assert.assertEquals("Wrong flags", new MeterFlags(false, false, true, true),
606                              message.getMeterConfig().get(0).getFlags());
607         Assert.assertEquals("Wrong meterId", 9,
608                              message.getMeterConfig().get(0).getMeterId().getValue().intValue());
609
610         MeterBandDropCase dropCase = (MeterBandDropCase) message.getMeterConfig().get(0).getBands().get(0).getMeterBand();
611         MeterBandDrop meterBandDrop = dropCase.getMeterBandDrop();
612         Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue());
613         Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue());
614         Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue());
615
616         MeterBandDscpRemarkCase dscpCase = (MeterBandDscpRemarkCase) message.getMeterConfig().get(0).getBands().get(1).getMeterBand();
617         MeterBandDscpRemark meterBandDscp = dscpCase.getMeterBandDscpRemark();
618         Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue());
619         Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue());
620         Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue());
621         Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue());
622     }
623
624     /**
625      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
626      */
627     @Test
628     public void testMultipartReplyMeterConfigBodyMulti(){
629         ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+
630                                               "00 28 "+//len
631                                               "00 06 "+//flags
632                                               "00 00 00 09 "+//meterId
633                                               "00 01 "+//meterBandDrop.type
634                                               "00 10 "+//meterBandDrop.len
635                                               "00 00 00 11 "+//meterBandDrop.rate
636                                               "00 00 00 20 "+//meterBandDrop.burstSize
637                                               "00 00 00 00 "+//meterBandDrop.pad
638                                               "00 02 "+//meterBandDscp.type
639                                               "00 10 "+//meterBandDscp.len
640                                               "00 00 00 11 "+//meterBandDscp.rate
641                                               "00 00 00 20 "+//meterBandDscp.burstSize
642                                               "04 "+//meterBandDscp.precLevel
643                                               "00 00 00 "+//meterBandDscp.pad
644
645                                               "00 18 "+//len01
646                                               "00 03 "+//flags01
647                                               "00 00 00 07 "+//meterId01
648                                               "00 02 "+//meterBandDscp01.type
649                                               "00 10 "+//meterBandDscp01.len
650                                               "00 00 00 11 "+//meterBandDscp01.rate
651                                               "00 00 00 20 "+//meterBandDscp01.burstSize
652                                               "04 "+//meterBandDscp01.precLevel
653                                               "00 00 00"//meterBandDscp01.pad
654                                               );
655
656         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
657
658         BufferHelper.checkHeaderV13(builtByFactory);
659         Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue());
660         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
661         MultipartReplyMeterConfigCase messageCase = (MultipartReplyMeterConfigCase) builtByFactory.getMultipartReplyBody();
662         MultipartReplyMeterConfig message = messageCase.getMultipartReplyMeterConfig();
663         Assert.assertEquals("Wrong flags", new MeterFlags(true, false, true, false),
664                              message.getMeterConfig().get(0).getFlags());
665         Assert.assertEquals("Wrong meterId", 9,
666                              message.getMeterConfig().get(0).getMeterId().getValue().intValue());
667
668         MeterBandDropCase dropCase = (MeterBandDropCase) message.getMeterConfig().get(0).getBands().get(0).getMeterBand();
669         MeterBandDrop meterBandDrop = dropCase.getMeterBandDrop();
670         Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue());
671         Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue());
672         Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue());
673
674         MeterBandDscpRemarkCase dscpCase = (MeterBandDscpRemarkCase) message.getMeterConfig().get(0).getBands().get(1).getMeterBand();
675         MeterBandDscpRemark meterBandDscp = dscpCase.getMeterBandDscpRemark();
676         Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue());
677         Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue());
678         Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue());
679         Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue());
680
681         LOGGER.info(message.getMeterConfig().get(0).getFlags().toString());
682         Assert.assertEquals("Wrong flags01", new MeterFlags(false, true, true, false),
683                              message.getMeterConfig().get(1).getFlags());
684         Assert.assertEquals("Wrong meterId01", 7,
685                              message.getMeterConfig().get(1).getMeterId().getValue().intValue());
686
687         MeterBandDscpRemarkCase dscpCase01 = (MeterBandDscpRemarkCase) message.getMeterConfig().get(1).getBands().get(0).getMeterBand();
688         MeterBandDscpRemark meterBandDscp01 = dscpCase01.getMeterBandDscpRemark();
689         Assert.assertEquals("Wrong meterBandDscp01.type", 2, meterBandDscp01.getType().getIntValue());
690         Assert.assertEquals("Wrong meterBandDscp01.rate", 17, meterBandDscp01.getRate().intValue());
691         Assert.assertEquals("Wrong meterBandDscp01.burstSize", 32, meterBandDscp01.getBurstSize().intValue());
692         Assert.assertEquals("Wrong meterBandDscp01.precLevel", 4, meterBandDscp01.getPrecLevel().intValue());
693
694     }
695
696     /**
697      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
698      * Test covers bodies of actions Output, Copy TTL Out, Copy TTL In
699      */
700     @Test
701     public void testMultipartReplyGroupDescBody01(){
702         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
703                                               "00 38 "+//len
704                                               "01 "+//type
705                                               "00 "+//pad
706                                               "00 00 00 08 "+//groupId
707                                               "00 30 "+//bucketLen
708                                               "00 06 "+//bucketWeight
709                                               "00 00 00 05 "+//bucketWatchPort
710                                               "00 00 00 04 "+//bucketWatchGroup
711                                               "00 00 00 00 "+//bucketPad
712                                               "00 00 "+//outputType
713                                               "00 10 "+//outputLen
714                                               "00 00 10 FF "+//outputPort
715                                               "FF FF "+//outputMaxLen
716                                               "00 00 00 00 00 00 "+//outputPad
717                                               "00 0B "+//copyTTLOutType
718                                               "00 08 "+//copyTTLOutLen
719                                               "00 00 00 00 "+//copyTTLOutPad
720                                               "00 0C "+//copyTTLIntType
721                                               "00 08 "+//copyTTLIntLen
722                                               "00 00 00 00"//copyTTLInPad
723                                               );
724         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
725
726         BufferHelper.checkHeaderV13(builtByFactory);
727         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
728         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
729         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
730         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
731         Assert.assertEquals("Wrong type", 1,
732                              message.getGroupDesc().get(0).getType().getIntValue());
733         Assert.assertEquals("Wrong groupId", 8,
734                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
735         Assert.assertEquals("Wrong bucketWeight", 6,
736                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
737         Assert.assertEquals("Wrong bucketWatchPort", 5,
738                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().
739                                                                         getValue().intValue());
740         Assert.assertEquals("Wrong bucketWatchGroup", 4,
741                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
742
743         Assert.assertTrue("Wrong outputType",message.getGroupDesc().get(0).getBucketsList().get(0)
744                 .getAction().get(0).getActionChoice() instanceof OutputActionCase);
745
746         Assert.assertEquals("Wrong outputPort", 4351, ((OutputActionCase) message.getGroupDesc().get(0)
747                 .getBucketsList().get(0).getAction().get(0).getActionChoice())
748                 .getOutputAction().getPort().getValue().intValue());
749
750         Assert.assertEquals("Wrong outputMaxLen", 65535, ((OutputActionCase) message.getGroupDesc().get(0)
751                 .getBucketsList().get(0).getAction().get(0).getActionChoice())
752                 .getOutputAction().getMaxLength().intValue());
753
754         Assert.assertTrue("Wrong copyTtlOutType", message.getGroupDesc().get(0).getBucketsList()
755                 .get(0).getAction().get(1).getActionChoice() instanceof CopyTtlOutCase);
756
757         Assert.assertTrue("Wrong copyTtlInType", message.getGroupDesc().get(0).getBucketsList()
758                 .get(0).getAction().get(2).getActionChoice() instanceof CopyTtlInCase);
759     }
760
761     /**
762      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
763      * Test covers bodies of actions Set MPLS TTL , Dec MPLS TTL, Push VLAN. Push MPLS, Push PBB
764      */
765     @Test
766     public void testMultipartReplyGroupDescBody02(){
767         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
768                                               "00 40 "+//len
769                                               "01 "+//type
770                                               "00 "+//pad
771                                               "00 00 00 08 "+//groupId
772                                               "00 38 "+//bucketLen
773                                               "00 06 "+//bucketWeight
774                                               "00 00 00 05 "+//bucketWatchPort
775                                               "00 00 00 04 "+//bucketWatchGroup
776                                               "00 00 00 00 "+//bucketPad
777                                               "00 0F "+//setMplsTtlType
778                                               "00 08 "+//setMplsTtlLen
779                                               "09 "+//setMplsTtlMPLS_TTL
780                                               "00 00 00 "+//setMplsTtlPad
781                                               "00 10 "+//decMplsTtlType
782                                               "00 08 "+//decMplsTtlLen
783                                               "00 00 00 00 "+//decMplsTtlPad
784                                               "00 11 "+//pushVlanType
785                                               "00 08 "+//pushVlanLen
786                                               "00 20 "+//pushVlanEthertype
787                                               "00 00 "+//pushVlanPad
788                                               "00 13 "+//pushMplsType
789                                               "00 08 "+//pushMplsLen
790                                               "00 FF "+//pushMplsEthertype
791                                               "00 00 "+//pushMplsPad
792                                               "00 1A "+//pushPbbType
793                                               "00 08 "+//pushPbbLen
794                                               "0F FF "+//pushPbbEthertype
795                                               "00 00"//pushPbbPad
796                                               );
797
798         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
799
800         BufferHelper.checkHeaderV13(builtByFactory);
801         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
802         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
803         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
804         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
805         Assert.assertEquals("Wrong type", 1,
806                              message.getGroupDesc().get(0).getType().getIntValue());
807         Assert.assertEquals("Wrong groupId", 8,
808                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
809         Assert.assertEquals("Wrong bucketWeight", 6,
810                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
811         Assert.assertEquals("Wrong bucketWatchPort", 5,
812                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().getValue().intValue());
813         Assert.assertEquals("Wrong bucketWatchGroup", 4,
814                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
815         Assert.assertTrue("Wrong setMplsTtlType", message.getGroupDesc().get(0).getBucketsList().get(0)
816                 .getAction().get(0).getActionChoice() instanceof SetMplsTtlCase);
817         Assert.assertEquals("Wrong setMplsTtlMPLS_TTL", 9, ((SetMplsTtlCase) message.getGroupDesc().get(0)
818                 .getBucketsList().get(0).getAction().get(0).getActionChoice()).getSetMplsTtlAction()
819                 .getMplsTtl().intValue());
820         Assert.assertTrue("Wrong decMplsTtlType", message.getGroupDesc().get(0).getBucketsList().get(0)
821                 .getAction().get(1).getActionChoice() instanceof DecMplsTtlCase);
822         Assert.assertTrue("Wrong pushVlanType", message.getGroupDesc().get(0).getBucketsList().get(0)
823                 .getAction().get(2).getActionChoice() instanceof PushVlanCase);
824         Assert.assertEquals("Wrong pushVlanEthertype", 32,((PushVlanCase) message.getGroupDesc().get(0)
825                 .getBucketsList().get(0).getAction().get(2).getActionChoice())
826                 .getPushVlanAction().getEthertype().getValue().intValue());
827         Assert.assertTrue("Wrong pushMplsType", message.getGroupDesc().get(0).getBucketsList().get(0)
828                 .getAction().get(3).getActionChoice() instanceof PushMplsCase);
829         Assert.assertEquals("Wrong pushMplsEthertype", 255, ((PushMplsCase) message.getGroupDesc().get(0)
830                 .getBucketsList().get(0).getAction().get(3).getActionChoice())
831                 .getPushMplsAction().getEthertype().getValue().intValue());
832         Assert.assertTrue("Wrong pushPbbType", message.getGroupDesc().get(0).getBucketsList().get(0)
833                 .getAction().get(4).getActionChoice() instanceof PushPbbCase);
834         Assert.assertEquals("Wrong pushPbbEthertype", 4095, ((PushPbbCase) message.getGroupDesc().get(0)
835                 .getBucketsList().get(0).getAction().get(4).getActionChoice())
836                 .getPushPbbAction().getEthertype().getValue().intValue());
837     }
838
839     /**
840      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
841      * Test covers bodies of actions Pop VLAN, Pop PBB, Pop MPLS, Group, Dec NW TTL
842      */
843     @Test
844     public void testMultipartReplyGroupDescBody03(){
845         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
846                                               "00 48 "+//len
847                                               "01 "+//type
848                                               "00 "+//pad
849                                               "00 00 00 08 "+//groupId
850                                               "00 40 "+//bucketLen
851                                               "00 06 "+//bucketWeight
852                                               "00 00 00 05 "+//bucketWatchPort
853                                               "00 00 00 04 "+//bucketWatchGroup
854                                               "00 00 00 00 "+//bucketPad
855                                               "00 12 "+//popVlanType
856                                               "00 08 "+//popVlanLen
857                                               "00 00 00 00 "+//popVlanPad
858                                               "00 1B "+//popPbbType
859                                               "00 08 "+//popPbbLen
860                                               "00 00 00 00 "+//popPbbPad
861                                               "00 14 "+//popMplsType
862                                               "00 08 "+//popMplsLen
863                                               "00 CF "+//popMplsEthertype
864                                               "00 00 "+//popMplsPad
865                                               "00 15 "+//setQueueType
866                                               "00 08 "+//setQueueLen
867                                               "00 CF 00 00 "+//setQueueQueueId
868                                               "00 16 "+//groupType
869                                               "00 08 "+//groupLen
870                                               "00 CF 00 00 "+//groupGroupId
871                                               "00 18 "+//decNwTtlType
872                                               "00 08 "+//decNwTtlLen
873                                               "00 00 00 00"//decNwTtlPad
874                                               );
875
876         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
877
878         BufferHelper.checkHeaderV13(builtByFactory);
879         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
880         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
881         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
882         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
883         Assert.assertEquals("Wrong type", 1, message.getGroupDesc().get(0).getType().getIntValue());
884         Assert.assertEquals("Wrong groupId", 8, message.getGroupDesc().get(0).getGroupId().getValue().intValue());
885         Assert.assertEquals("Wrong bucketWeight", 6,
886                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
887         Assert.assertEquals("Wrong bucketWatchPort", 5,
888                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().getValue().intValue());
889         Assert.assertEquals("Wrong bucketWatchGroup", 4,
890                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
891         Assert.assertTrue("Wrong popVlanType", message.getGroupDesc().get(0).getBucketsList().get(0)
892                 .getAction().get(0).getActionChoice() instanceof PopVlanCase);
893         Assert.assertTrue("Wrong popPbbType", message.getGroupDesc().get(0).getBucketsList().get(0)
894                 .getAction().get(1).getActionChoice() instanceof PopPbbCase);
895         Assert.assertTrue("Wrong popMplsType", message.getGroupDesc().get(0).getBucketsList().get(0)
896                 .getAction().get(2).getActionChoice() instanceof PopMplsCase);
897         Assert.assertEquals("Wrong popMplsEthertype", 207, ((PopMplsCase) message.getGroupDesc().get(0)
898                 .getBucketsList().get(0).getAction().get(2).getActionChoice())
899                 .getPopMplsAction().getEthertype().getValue().intValue());
900         Assert.assertTrue("Wrong setQueueType", message.getGroupDesc().get(0).getBucketsList().get(0)
901                 .getAction().get(3).getActionChoice() instanceof SetQueueCase);
902         Assert.assertEquals("Wrong setQueueQueueId", 13565952, ((SetQueueCase) message.getGroupDesc().get(0)
903                 .getBucketsList().get(0).getAction().get(3).getActionChoice())
904                 .getSetQueueAction().getQueueId().intValue());
905         Assert.assertTrue("Wrong groupType", message.getGroupDesc().get(0).getBucketsList().get(0)
906                 .getAction().get(4).getActionChoice() instanceof GroupCase);
907         Assert.assertEquals("Wrong groupGroupId", 13565952, ((GroupCase) message.getGroupDesc().get(0)
908                 .getBucketsList().get(0).getAction().get(4).getActionChoice())
909                 .getGroupAction().getGroupId().intValue());
910         Assert.assertTrue("Wrong decNwTtlType", message.getGroupDesc().get(0).getBucketsList().get(0)
911                 .getAction().get(5).getActionChoice() instanceof DecNwTtlCase);
912     }
913
914     /**
915      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
916      * Test covers bodies of actions NW TTL, Experimenter
917      */
918     @Test
919     public void testMultipartReplyGroupDescBody04(){
920         ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+
921                                               "00 30 "+//len
922                                               "01 "+//type
923                                               "00 "+//pad
924                                               "00 00 00 08 "+//groupId
925                                               "00 28 "+//bucketLen
926                                               "00 06 "+//bucketWeight
927                                               "00 00 00 05 "+//bucketWatchPort
928                                               "00 00 00 04 "+//bucketWatchGroup
929                                               "00 00 00 00 "+//bucketPad
930                                               "00 17 "+//nwTTlType
931                                               "00 08 "+//nwTTlLen
932                                               "0E "+//nwTTlnwTTL
933                                               "00 00 00 "+//nwTTlPad
934                                               "00 19 "+//setFieldType
935                                               "00 10 "+//setFieldLen
936                                               "80 00 "+//setFieldOXMClass
937                                               "00 "+//setFieldOXMField
938                                               "04 "+//setFieldOXMLength
939                                               "00 00 00 FF "+ //setFieldPort
940                                               "00 00 00 00"
941                 );
942
943         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
944
945         BufferHelper.checkHeaderV13(builtByFactory);
946         Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
947         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
948         MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
949         MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
950         Assert.assertEquals("Wrong type", 1,
951                              message.getGroupDesc().get(0).getType().getIntValue());
952         Assert.assertEquals("Wrong groupId", 8,
953                              message.getGroupDesc().get(0).getGroupId().getValue().intValue());
954         Assert.assertEquals("Wrong bucketWeight", 6,
955                 message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
956         Assert.assertEquals("Wrong bucketWatchPort", 5,
957                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().
958                                                                         getValue().intValue());
959         Assert.assertEquals("Wrong bucketWatchGroup", 4,
960                 message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
961
962         Assert.assertTrue("Wrong nwTTlType", message.getGroupDesc().get(0).getBucketsList().get(0)
963                 .getAction().get(0).getActionChoice() instanceof SetNwTtlCase);
964
965         Assert.assertEquals("Wrong nwTTlnwTTL", 14, ((SetNwTtlCase) message.getGroupDesc().get(0)
966                 .getBucketsList().get(0).getAction().get(0).getActionChoice())
967                 .getSetNwTtlAction().getNwTtl().intValue());
968
969         Assert.assertTrue("Wrong setFieldType", message.getGroupDesc().get(0).getBucketsList().get(0)
970                 .getAction().get(1).getActionChoice() instanceof SetFieldCase);
971
972         Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class,
973                 ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
974                 .getActionChoice()).getSetFieldAction().getMatchEntry().get(0).getOxmClass());
975
976         Assert.assertEquals("Wrong setFieldOXMField", InPort.class,
977                 ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
978                         .getActionChoice()).getSetFieldAction().getMatchEntry().get(0).getOxmMatchField());
979
980         MatchEntry entry = ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1)
981                 .getActionChoice()).getSetFieldAction().getMatchEntry().get(0);
982         Assert.assertEquals("Wrong setFieldOXMValue", 255, ((InPortCase) entry.getMatchEntryValue())
983                 .getInPort().getPortNumber().getValue().intValue());
984     }
985 }