Extend openflow-protocol-impl serialization
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10StatsReplyMessageFactoryTest.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium 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 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
20 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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.inet.types.rev100924.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStatsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder;
63
64 /**
65  * @author giuseppex.petralia@intel.com
66  *
67  */
68 public class OF10StatsReplyMessageFactoryTest {
69     private OFSerializer<MultipartReplyMessage> factory;
70     private static final byte MESSAGE_TYPE = 17;
71
72     @Before
73     public void startUp() {
74         SerializerRegistry registry = new SerializerRegistryImpl();
75         registry.init();
76         factory = registry
77                 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartReplyMessage.class));
78     }
79
80     @Test
81     public void testDescBodySerialize() throws Exception {
82         MultipartReplyMessageBuilder builder;
83         builder = new MultipartReplyMessageBuilder();
84         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
85         builder.setFlags(new MultipartRequestFlags(true));
86         builder.setType(MultipartType.forValue(0));
87         MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
88         MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
89         desc.setMfrDesc("Test");
90         desc.setHwDesc("Test");
91         desc.setSwDesc("Test");
92         desc.setSerialNum("12345");
93         desc.setDpDesc("Test");
94         descCase.setMultipartReplyDesc(desc.build());
95         builder.setMultipartReplyBody(descCase.build());
96         MultipartReplyMessage message = builder.build();
97         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
98         factory.serialize(message, serializedBuffer);
99         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 1068);
100         Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort());
101         Assert.assertEquals("Wrong flags", message.getFlags(),
102                 createMultipartRequestFlags(serializedBuffer.readShort()));
103         Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer));
104     }
105
106     @Test
107     public void testFlowBodySerialize() throws Exception {
108         MultipartReplyMessageBuilder builder;
109         builder = new MultipartReplyMessageBuilder();
110         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
111         builder.setFlags(new MultipartRequestFlags(true));
112         builder.setType(MultipartType.forValue(1));
113         MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
114         MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
115         flow.setFlowStats(createFlowStats());
116         flowCase.setMultipartReplyFlow(flow.build());
117         builder.setMultipartReplyBody(flowCase.build());
118         MultipartReplyMessage message = builder.build();
119
120         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
121         factory.serialize(message, serializedBuffer);
122         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 108);
123         Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
124         Assert.assertEquals("Wrong flags", message.getFlags(),
125                 createMultipartRequestFlags(serializedBuffer.readShort()));
126         FlowStats flowStats = flow.getFlowStats().get(0);
127         Assert.assertEquals("Wrong length", 96, serializedBuffer.readShort());
128         Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), serializedBuffer.readUnsignedByte());
129         serializedBuffer.skipBytes(1);
130         Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt());
131         Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort());
132         byte[] dlSrc = new byte[6];
133         serializedBuffer.readBytes(dlSrc);
134         Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
135         byte[] dlDst = new byte[6];
136         serializedBuffer.readBytes(dlDst);
137         Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
138         Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort());
139         Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte());
140         serializedBuffer.skipBytes(1);
141         Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort());
142         Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte());
143         Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte());
144         serializedBuffer.skipBytes(2);
145         Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt());
146         Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt());
147         Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort());
148         Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort());
149         Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), serializedBuffer.readInt());
150         Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), serializedBuffer.readInt());
151         Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), serializedBuffer.readShort());
152         Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), serializedBuffer.readShort());
153         Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), serializedBuffer.readShort());
154         serializedBuffer.skipBytes(6);
155         Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), serializedBuffer.readLong());
156         Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), serializedBuffer.readLong());
157         Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), serializedBuffer.readLong());
158         Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
159         Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
160         Assert.assertEquals("Wrong port", 42, serializedBuffer.readUnsignedShort());
161         Assert.assertEquals("Wrong maxlength", 50, serializedBuffer.readUnsignedShort());
162     }
163
164     @Test
165     public void testAggregateBodySerialize() throws Exception {
166         MultipartReplyMessageBuilder builder;
167         builder = new MultipartReplyMessageBuilder();
168         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
169         builder.setFlags(new MultipartRequestFlags(true));
170         builder.setType(MultipartType.forValue(2));
171         MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder();
172         MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder();
173         aggregate.setPacketCount(BigInteger.valueOf(1234L));
174         aggregate.setByteCount(BigInteger.valueOf(1234L));
175         aggregate.setFlowCount(1L);
176         aggregateCase.setMultipartReplyAggregate(aggregate.build());
177         builder.setMultipartReplyBody(aggregateCase.build());
178         MultipartReplyMessage message = builder.build();
179
180         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
181         factory.serialize(message, serializedBuffer);
182         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 36);
183         Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort());
184         Assert.assertEquals("Wrong flags", message.getFlags(),
185                 createMultipartRequestFlags(serializedBuffer.readShort()));
186         Assert.assertEquals("Wrong Packet count", 1234L, serializedBuffer.readLong());
187         Assert.assertEquals("Wrong Byte count", 1234L, serializedBuffer.readLong());
188         Assert.assertEquals("Wrong flow count", 1L, serializedBuffer.readInt());
189         serializedBuffer.skipBytes(4);
190     }
191
192     @Test
193     public void testTableBodySerialize() throws Exception {
194         MultipartReplyMessageBuilder builder;
195         builder = new MultipartReplyMessageBuilder();
196         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
197         builder.setFlags(new MultipartRequestFlags(true));
198         builder.setType(MultipartType.forValue(3));
199         MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
200         MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
201         table.setTableStats(createTableStats());
202         tableCase.setMultipartReplyTable(table.build());
203         builder.setMultipartReplyBody(tableCase.build());
204         MultipartReplyMessage message = builder.build();
205
206         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
207         factory.serialize(message, serializedBuffer);
208         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60);
209         Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
210         Assert.assertEquals("Wrong flags", message.getFlags(),
211                 createMultipartRequestFlags(serializedBuffer.readShort()));
212         Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte());
213         serializedBuffer.skipBytes(3);
214         Assert.assertEquals("Wrong name", "Table name", ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16));
215         Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt());
216         Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt());
217         Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt());
218         Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong());
219         Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong());
220     }
221
222     @Test
223     public void testPortStatsBodySerialize() throws Exception {
224         MultipartReplyMessageBuilder builder;
225         builder = new MultipartReplyMessageBuilder();
226         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
227         builder.setFlags(new MultipartRequestFlags(true));
228         builder.setType(MultipartType.forValue(4));
229         MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder();
230         MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder();
231         portStats.setPortStats(createPortStats());
232         portStatsCase.setMultipartReplyPortStats(portStats.build());
233         builder.setMultipartReplyBody(portStatsCase.build());
234         MultipartReplyMessage message = builder.build();
235
236         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
237         factory.serialize(message, serializedBuffer);
238         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 118);
239         Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort());
240         Assert.assertEquals("Wrong flags", message.getFlags(),
241                 createMultipartRequestFlags(serializedBuffer.readShort()));
242         MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody();
243         MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats();
244         PortStats portStatsOutput = messageOutput.getPortStats().get(0);
245         Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt());
246         serializedBuffer.skipBytes(6);
247         Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(),
248                 serializedBuffer.readLong());
249         Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(),
250                 serializedBuffer.readLong());
251         Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(), serializedBuffer.readLong());
252         Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(), serializedBuffer.readLong());
253         Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(),
254                 serializedBuffer.readLong());
255         Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(),
256                 serializedBuffer.readLong());
257         Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(), serializedBuffer.readLong());
258         Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(), serializedBuffer.readLong());
259         Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(),
260                 serializedBuffer.readLong());
261         Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(),
262                 serializedBuffer.readLong());
263         Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(), serializedBuffer.readLong());
264         Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(),
265                 serializedBuffer.readLong());
266     }
267
268     @Test
269     public void testQueueBodySerialize() throws Exception {
270         MultipartReplyMessageBuilder builder;
271         builder = new MultipartReplyMessageBuilder();
272         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
273         builder.setFlags(new MultipartRequestFlags(true));
274         builder.setType(MultipartType.forValue(5));
275         MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder();
276         MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder();
277         queue.setQueueStats(createQueueStats());
278         queueCase.setMultipartReplyQueue(queue.build());
279         builder.setMultipartReplyBody(queueCase.build());
280         MultipartReplyMessage message = builder.build();
281
282         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
283         factory.serialize(message, serializedBuffer);
284         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 44);
285         Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort());
286         Assert.assertEquals("Wrong flags", message.getFlags(),
287                 createMultipartRequestFlags(serializedBuffer.readShort()));
288         MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody();
289         MultipartReplyQueue messageOutput = body.getMultipartReplyQueue();
290         QueueStats queueStats = messageOutput.getQueueStats().get(0);
291         Assert.assertEquals("Wrong length", 32, serializedBuffer.readUnsignedShort());
292         serializedBuffer.skipBytes(2);
293         Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(), serializedBuffer.readUnsignedInt());
294         Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong());
295         Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong());
296         Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong());
297     }
298
299     private static List<QueueStats> createQueueStats() {
300         QueueStatsBuilder builder = new QueueStatsBuilder();
301         builder.setQueueId(1L);
302         builder.setTxBytes(BigInteger.valueOf(1L));
303         builder.setTxPackets(BigInteger.valueOf(1L));
304         builder.setTxErrors(BigInteger.valueOf(1L));
305         List<QueueStats> list = new ArrayList<>();
306         list.add(builder.build());
307         return list;
308     }
309
310     private static List<PortStats> createPortStats() {
311         PortStatsBuilder builder = new PortStatsBuilder();
312         builder.setPortNo(1L);
313         builder.setRxPackets(BigInteger.valueOf(1L));
314         builder.setTxPackets(BigInteger.valueOf(1L));
315         builder.setRxBytes(BigInteger.valueOf(1L));
316         builder.setTxBytes(BigInteger.valueOf(1L));
317         builder.setRxDropped(BigInteger.valueOf(1L));
318         builder.setTxDropped(BigInteger.valueOf(1L));
319         builder.setRxErrors(BigInteger.valueOf(1L));
320         builder.setTxErrors(BigInteger.valueOf(1L));
321         builder.setRxFrameErr(BigInteger.valueOf(1L));
322         builder.setRxOverErr(BigInteger.valueOf(1L));
323         builder.setRxCrcErr(BigInteger.valueOf(1L));
324         builder.setCollisions(BigInteger.valueOf(1L));
325         List<PortStats> list = new ArrayList<PortStats>();
326         list.add(builder.build());
327         return list;
328     }
329
330     private static List<TableStats> createTableStats() {
331         TableStatsBuilder builder = new TableStatsBuilder();
332         builder.setTableId((short) 1);
333         builder.setName("Table name");
334         builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
335         builder.setMaxEntries(1L);
336         builder.setActiveCount(1L);
337         builder.setLookupCount(BigInteger.valueOf(1234L));
338         builder.setMatchedCount(BigInteger.valueOf(1234L));
339         List<TableStats> list = new ArrayList<>();
340         list.add(builder.build());
341         return list;
342     }
343
344     private static List<FlowStats> createFlowStats() {
345         FlowStatsBuilder builder = new FlowStatsBuilder();
346         builder.setTableId((short) 1);
347         MatchV10Builder matchBuilder = new MatchV10Builder();
348         matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
349         matchBuilder.setNwSrcMask((short) 0);
350         matchBuilder.setNwDstMask((short) 0);
351         matchBuilder.setInPort(58);
352         matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
353         matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
354         matchBuilder.setDlVlan(18);
355         matchBuilder.setDlVlanPcp((short) 5);
356         matchBuilder.setDlType(42);
357         matchBuilder.setNwTos((short) 4);
358         matchBuilder.setNwProto((short) 7);
359         matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
360         matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
361         matchBuilder.setTpSrc(6653);
362         matchBuilder.setTpDst(6633);
363         builder.setMatchV10(matchBuilder.build());
364         builder.setDurationSec(1L);
365         builder.setDurationNsec(2L);
366         builder.setPriority(1);
367         builder.setIdleTimeout(1);
368         builder.setHardTimeout(1);
369         builder.setCookie(BigInteger.valueOf(1234L));
370         builder.setPacketCount(BigInteger.valueOf(1234L));
371         builder.setByteCount(BigInteger.valueOf(1234L));
372         List<Action> actions = new ArrayList<>();
373         ActionBuilder actionBuilder = new ActionBuilder();
374         OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
375         OutputActionBuilder outputBuilder = new OutputActionBuilder();
376         outputBuilder.setPort(new PortNumber(42L));
377         outputBuilder.setMaxLength(50);
378         caseBuilder.setOutputAction(outputBuilder.build());
379         actionBuilder.setActionChoice(caseBuilder.build());
380         actions.add(actionBuilder.build());
381         builder.setAction(actions);
382         List<FlowStats> list = new ArrayList<FlowStats>();
383         list.add(builder.build());
384         return list;
385     }
386
387     private static MultipartRequestFlags createMultipartRequestFlags(int input) {
388         final Boolean one = ((input) & (1 << 0)) > 0;
389         return new MultipartRequestFlags(one);
390     }
391
392     private static MultipartReplyDescCase decodeDescBody(ByteBuf output) {
393         MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
394         MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
395         byte[] mfrDesc = new byte[256];
396         output.readBytes(mfrDesc);
397         desc.setMfrDesc(new String(mfrDesc).trim());
398         byte[] hwDesc = new byte[256];
399         output.readBytes(hwDesc);
400         desc.setHwDesc(new String(hwDesc).trim());
401         byte[] swDesc = new byte[256];
402         output.readBytes(swDesc);
403         desc.setSwDesc(new String(swDesc).trim());
404         byte[] serialNumber = new byte[32];
405         output.readBytes(serialNumber);
406         desc.setSerialNum(new String(serialNumber).trim());
407         byte[] dpDesc = new byte[256];
408         output.readBytes(dpDesc);
409         desc.setDpDesc(new String(dpDesc).trim());
410         descCase.setMultipartReplyDesc(desc.build());
411         return descCase.build();
412     }
413 }