Merge "Bump odlparent/yangtools/mdsal/controller"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / MultipartReplyMessageFactoryTest.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.yang.types.rev130715.MacAddress;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeaturePropertyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeaturePropertyBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeaturePropertyBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeaturePropertyBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIdsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlActionBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.meter._case.MeterBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpEcn;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpProto;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCaseBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpEcnCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.phy.port._case.InPhyPortBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.ecn._case.IpEcnBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCaseBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCase;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCaseBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCaseBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCase;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCaseBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCaseBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroupBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStatsBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfigBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.BandsBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDesc;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDescBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder;
159 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;
160 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;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeatures;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeaturesBuilder;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder;
174 import org.opendaylight.yangtools.yang.common.Uint32;
175 import org.opendaylight.yangtools.yang.common.Uint8;
176
177 /**
178  * Unit tests for MultipartReplyMessageFactory.
179  *
180  * @author giuseppex.petralia@intel.com
181  */
182 public class MultipartReplyMessageFactoryTest {
183     private static final byte MESSAGE_TYPE = 19;
184     private static final byte PADDING = 4;
185
186     private OFSerializer<MultipartReplyMessage> factory;
187
188     @Before
189     public void startUp() {
190         SerializerRegistry registry = new SerializerRegistryImpl();
191         registry.init();
192         factory = registry
193                 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartReplyMessage.class));
194     }
195
196     @Test
197     public void testMultipartRequestTableFeaturesMessageFactory() throws Exception {
198         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
199         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
200         builder.setFlags(new MultipartRequestFlags(true));
201         builder.setType(MultipartType.forValue(12));
202         final MultipartReplyTableFeaturesCaseBuilder caseBuilder = new MultipartReplyTableFeaturesCaseBuilder();
203         final MultipartReplyTableFeaturesBuilder featuresBuilder = new MultipartReplyTableFeaturesBuilder();
204         final List<TableFeatures> tableFeaturesList = new ArrayList<>();
205         TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder();
206         tableFeaturesBuilder.setTableId((short) 8);
207         tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG");
208         tableFeaturesBuilder.setMetadataMatch(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 });
209         tableFeaturesBuilder.setMetadataWrite(new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 });
210         tableFeaturesBuilder.setConfig(new TableConfig(true));
211         tableFeaturesBuilder.setMaxEntries(65L);
212         TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder();
213         propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLES);
214         propBuilder.addAugmentation(new NextTableRelatedTableFeaturePropertyBuilder()
215             .setNextTableIds(List.of(
216                 new NextTableIdsBuilder().setTableId(Uint8.ONE).build(),
217                 new NextTableIdsBuilder().setTableId(Uint8.TWO).build()))
218             .build());
219         List<TableFeatureProperties> properties = new ArrayList<>();
220         properties.add(propBuilder.build());
221         propBuilder = new TableFeaturePropertiesBuilder();
222         propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS);
223         propBuilder.addAugmentation(new NextTableRelatedTableFeaturePropertyBuilder().build());
224         properties.add(propBuilder.build());
225         propBuilder = new TableFeaturePropertiesBuilder();
226         propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONS);
227         List<Instruction> insIds = new ArrayList<>();
228         InstructionBuilder insBuilder = new InstructionBuilder();
229         insBuilder.setInstructionChoice(new WriteActionsCaseBuilder().build());
230         insIds.add(insBuilder.build());
231         insBuilder = new InstructionBuilder();
232         insBuilder.setInstructionChoice(new GotoTableCaseBuilder().build());
233         insIds.add(insBuilder.build());
234         propBuilder.addAugmentation(new InstructionRelatedTableFeaturePropertyBuilder().setInstruction(insIds).build());
235         properties.add(propBuilder.build());
236         propBuilder = new TableFeaturePropertiesBuilder();
237         propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS);
238         insIds = new ArrayList<>();
239         insBuilder = new InstructionBuilder();
240         insBuilder.setInstructionChoice(new WriteMetadataCaseBuilder().build());
241         insIds.add(insBuilder.build());
242         insBuilder = new InstructionBuilder();
243         insBuilder.setInstructionChoice(new ApplyActionsCaseBuilder().build());
244         insIds.add(insBuilder.build());
245         insBuilder = new InstructionBuilder();
246         insBuilder.setInstructionChoice(new MeterCaseBuilder().build());
247         insIds.add(insBuilder.build());
248         insBuilder = new InstructionBuilder();
249         insBuilder.setInstructionChoice(new ClearActionsCaseBuilder().build());
250         insIds.add(insBuilder.build());
251         insBuilder = new InstructionBuilder();
252         insBuilder.setInstructionChoice(new GotoTableCaseBuilder().build());
253         insIds.add(insBuilder.build());
254         propBuilder.addAugmentation(new InstructionRelatedTableFeaturePropertyBuilder().setInstruction(insIds).build());
255         properties.add(propBuilder.build());
256         tableFeaturesBuilder.setTableFeatureProperties(properties);
257         tableFeaturesList.add(tableFeaturesBuilder.build());
258         tableFeaturesBuilder = new TableFeaturesBuilder();
259         tableFeaturesBuilder.setTableId((short) 8);
260         tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG");
261         byte[] metadataMatch = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 };
262         tableFeaturesBuilder.setMetadataMatch(metadataMatch);
263         byte[] metadataWrite = new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 };
264         tableFeaturesBuilder.setMetadataWrite(metadataWrite);
265         tableFeaturesBuilder.setConfig(new TableConfig(true));
266         tableFeaturesBuilder.setMaxEntries(67L);
267         properties = new ArrayList<>();
268         propBuilder = new TableFeaturePropertiesBuilder();
269         propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONS);
270         List<Action> actions = new ArrayList<>();
271         ActionBuilder actionBuilder = new ActionBuilder();
272         actionBuilder.setActionChoice(new OutputActionCaseBuilder().build());
273         actions.add(actionBuilder.build());
274         propBuilder.addAugmentation(new ActionRelatedTableFeaturePropertyBuilder().setAction(actions).build());
275         properties.add(propBuilder.build());
276         propBuilder = new TableFeaturePropertiesBuilder();
277         propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS);
278         propBuilder.addAugmentation(new ActionRelatedTableFeaturePropertyBuilder().build());
279         properties.add(propBuilder.build());
280         propBuilder = new TableFeaturePropertiesBuilder();
281         propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONS);
282         propBuilder.addAugmentation(new ActionRelatedTableFeaturePropertyBuilder().build());
283         properties.add(propBuilder.build());
284         propBuilder = new TableFeaturePropertiesBuilder();
285         propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS);
286         propBuilder.addAugmentation(new ActionRelatedTableFeaturePropertyBuilder().build());
287         properties.add(propBuilder.build());
288         propBuilder = new TableFeaturePropertiesBuilder();
289         propBuilder.setType(TableFeaturesPropType.OFPTFPTMATCH);
290         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
291         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
292         entriesBuilder.setOxmMatchField(InPhyPort.class);
293         entriesBuilder.setHasMask(false);
294         List<MatchEntry> entries = new ArrayList<>();
295         entries.add(entriesBuilder.build());
296         entriesBuilder = new MatchEntryBuilder();
297         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
298         entriesBuilder.setOxmMatchField(InPort.class);
299         entriesBuilder.setHasMask(false);
300         entries.add(entriesBuilder.build());
301         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().setMatchEntry(entries).build());
302         properties.add(propBuilder.build());
303         propBuilder = new TableFeaturePropertiesBuilder();
304         propBuilder.setType(TableFeaturesPropType.OFPTFPTWILDCARDS);
305         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().build());
306         properties.add(propBuilder.build());
307         propBuilder = new TableFeaturePropertiesBuilder();
308         propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELD);
309         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().build());
310         properties.add(propBuilder.build());
311         propBuilder = new TableFeaturePropertiesBuilder();
312         propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS);
313         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().build());
314         properties.add(propBuilder.build());
315         propBuilder = new TableFeaturePropertiesBuilder();
316         propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD);
317         entries = new ArrayList<>();
318         entriesBuilder = new MatchEntryBuilder();
319         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
320         entriesBuilder.setOxmMatchField(IpProto.class);
321         entriesBuilder.setHasMask(false);
322         entries.add(entriesBuilder.build());
323         entriesBuilder = new MatchEntryBuilder();
324         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
325         entriesBuilder.setOxmMatchField(IpEcn.class);
326         entriesBuilder.setHasMask(false);
327         entries.add(entriesBuilder.build());
328         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().setMatchEntry(entries).build());
329         properties.add(propBuilder.build());
330         propBuilder = new TableFeaturePropertiesBuilder();
331         propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS);
332         propBuilder.addAugmentation(new OxmRelatedTableFeaturePropertyBuilder().build());
333         properties.add(propBuilder.build());
334         tableFeaturesBuilder.setTableFeatureProperties(properties);
335         tableFeaturesList.add(tableFeaturesBuilder.build());
336         featuresBuilder.setTableFeatures(tableFeaturesList);
337         caseBuilder.setMultipartReplyTableFeatures(featuresBuilder.build());
338         builder.setMultipartReplyBody(caseBuilder.build());
339         MultipartReplyMessage message = builder.build();
340         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
341         factory.serialize(message, serializedBuffer);
342         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 520);
343         Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLEFEATURES.getIntValue(), serializedBuffer.readShort());
344         Assert.assertEquals("Wrong flags", message.getFlags(),
345                 createMultipartRequestFlags(serializedBuffer.readShort()));
346         serializedBuffer.skipBytes(PADDING);
347
348         Assert.assertEquals("Wrong length", 232, serializedBuffer.readUnsignedShort());
349         Assert.assertEquals("Wrong registry-id", 8, serializedBuffer.readUnsignedByte());
350         serializedBuffer.skipBytes(5);
351         Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",
352                 ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 32));
353         byte[] metadataMatchOutput = new byte[metadataMatch.length];
354         serializedBuffer.readBytes(metadataMatchOutput);
355         Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 },
356                 metadataMatchOutput);
357         serializedBuffer.skipBytes(64 - metadataMatch.length);
358         byte[] metadataWriteOutput = new byte[metadataWrite.length];
359         serializedBuffer.readBytes(metadataWriteOutput);
360         Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 },
361                 metadataWriteOutput);
362         serializedBuffer.skipBytes(64 - metadataWrite.length);
363         Assert.assertEquals("Wrong config", 1, serializedBuffer.readUnsignedInt());
364         Assert.assertEquals("Wrong max-entries", 65, serializedBuffer.readUnsignedInt());
365         Assert.assertEquals("Wrong property type", 2, serializedBuffer.readUnsignedShort());
366         Assert.assertEquals("Wrong property length", 6, serializedBuffer.readUnsignedShort());
367         Assert.assertEquals("Wrong next-registry-id", 1, serializedBuffer.readUnsignedByte());
368         Assert.assertEquals("Wrong next-registry-id", 2, serializedBuffer.readUnsignedByte());
369         serializedBuffer.skipBytes(2);
370         Assert.assertEquals("Wrong property type", 3, serializedBuffer.readUnsignedShort());
371         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
372         serializedBuffer.skipBytes(4);
373         Assert.assertEquals("Wrong property type", 0, serializedBuffer.readUnsignedShort());
374         Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort());
375         Assert.assertEquals("Wrong instruction type", 3, serializedBuffer.readUnsignedShort());
376         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
377         Assert.assertEquals("Wrong instruction type", 1, serializedBuffer.readUnsignedShort());
378         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
379         serializedBuffer.skipBytes(4);
380         Assert.assertEquals("Wrong property type", 1, serializedBuffer.readUnsignedShort());
381         Assert.assertEquals("Wrong property length", 24, serializedBuffer.readUnsignedShort());
382         Assert.assertEquals("Wrong instruction type", 2, serializedBuffer.readUnsignedShort());
383         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
384         Assert.assertEquals("Wrong instruction type", 4, serializedBuffer.readUnsignedShort());
385         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
386         Assert.assertEquals("Wrong instruction type", 6, serializedBuffer.readUnsignedShort());
387         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
388         Assert.assertEquals("Wrong instruction type", 5, serializedBuffer.readUnsignedShort());
389         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
390         Assert.assertEquals("Wrong instruction type", 1, serializedBuffer.readUnsignedShort());
391         Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort());
392         Assert.assertEquals("Wrong length", 272, serializedBuffer.readUnsignedShort());
393         Assert.assertEquals("Wrong registry-id", 8, serializedBuffer.readUnsignedByte());
394         serializedBuffer.skipBytes(5);
395         Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",
396                 ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 32));
397         metadataMatchOutput = new byte[metadataMatch.length];
398         serializedBuffer.readBytes(metadataMatchOutput);
399         serializedBuffer.skipBytes(64 - metadataMatch.length);
400         Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 },
401                 metadataMatchOutput);
402         metadataWriteOutput = new byte[metadataWrite.length];
403         serializedBuffer.readBytes(metadataWriteOutput);
404         serializedBuffer.skipBytes(64 - metadataWrite.length);
405         Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 },
406                 metadataWriteOutput);
407         Assert.assertEquals("Wrong config", 1, serializedBuffer.readUnsignedInt());
408         Assert.assertEquals("Wrong max-entries", 67, serializedBuffer.readUnsignedInt());
409         Assert.assertEquals("Wrong property type", 4, serializedBuffer.readUnsignedShort());
410         Assert.assertEquals("Wrong property length", 8, serializedBuffer.readUnsignedShort());
411         Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
412         Assert.assertEquals("Wrong action length", 4, serializedBuffer.readUnsignedShort());
413         Assert.assertEquals("Wrong property type", 5, serializedBuffer.readUnsignedShort());
414         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
415         serializedBuffer.skipBytes(4);
416         Assert.assertEquals("Wrong property type", 6, serializedBuffer.readUnsignedShort());
417         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
418         serializedBuffer.skipBytes(4);
419         Assert.assertEquals("Wrong property type", 7, serializedBuffer.readUnsignedShort());
420         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
421         serializedBuffer.skipBytes(4);
422         Assert.assertEquals("Wrong property type", 8, serializedBuffer.readUnsignedShort());
423         Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort());
424         Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort());
425         Assert.assertEquals("Wrong match field&mask", 2, serializedBuffer.readUnsignedByte());
426         Assert.assertEquals("Wrong match length", 4, serializedBuffer.readUnsignedByte());
427         Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort());
428         Assert.assertEquals("Wrong match field&mask", 0, serializedBuffer.readUnsignedByte());
429         Assert.assertEquals("Wrong match length", 4, serializedBuffer.readUnsignedByte());
430         serializedBuffer.skipBytes(4);
431         Assert.assertEquals("Wrong property type", 10, serializedBuffer.readUnsignedShort());
432         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
433         serializedBuffer.skipBytes(4);
434         Assert.assertEquals("Wrong property type", 12, serializedBuffer.readUnsignedShort());
435         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
436         serializedBuffer.skipBytes(4);
437         Assert.assertEquals("Wrong property type", 13, serializedBuffer.readUnsignedShort());
438         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
439         serializedBuffer.skipBytes(4);
440         Assert.assertEquals("Wrong property type", 14, serializedBuffer.readUnsignedShort());
441         Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort());
442         Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort());
443         Assert.assertEquals("Wrong match field&mask", 20, serializedBuffer.readUnsignedByte());
444         Assert.assertEquals("Wrong match length", 1, serializedBuffer.readUnsignedByte());
445         Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort());
446         Assert.assertEquals("Wrong match field&mask", 18, serializedBuffer.readUnsignedByte());
447         Assert.assertEquals("Wrong match length", 1, serializedBuffer.readUnsignedByte());
448         serializedBuffer.skipBytes(4);
449         Assert.assertEquals("Wrong property type", 15, serializedBuffer.readUnsignedShort());
450         Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort());
451         serializedBuffer.skipBytes(4);
452         Assert.assertTrue("Unread data", serializedBuffer.readableBytes() == 0);
453     }
454
455     @Test
456     public void testPortDescSerialize() throws Exception {
457         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
458         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
459         builder.setFlags(new MultipartRequestFlags(true));
460         builder.setType(MultipartType.forValue(13));
461         MultipartReplyPortDescCaseBuilder portDescCase = new MultipartReplyPortDescCaseBuilder();
462         MultipartReplyPortDescBuilder portDesc = new MultipartReplyPortDescBuilder();
463         portDesc.setPorts(createPortList());
464         portDescCase.setMultipartReplyPortDesc(portDesc.build());
465         builder.setMultipartReplyBody(portDescCase.build());
466         MultipartReplyMessage message = builder.build();
467         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
468         factory.serialize(message, serializedBuffer);
469         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80);
470         Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTDESC.getIntValue(), serializedBuffer.readShort());
471         Assert.assertEquals("Wrong flags", message.getFlags(),
472                 createMultipartRequestFlags(serializedBuffer.readShort()));
473         serializedBuffer.skipBytes(PADDING);
474         MultipartReplyPortDescCase body = (MultipartReplyPortDescCase) message.getMultipartReplyBody();
475         MultipartReplyPortDesc messageOutput = body.getMultipartReplyPortDesc();
476         Ports port = messageOutput.getPorts().get(0);
477         Assert.assertEquals("Wrong PortNo", port.getPortNo().intValue(), serializedBuffer.readUnsignedInt());
478         serializedBuffer.skipBytes(4);
479         byte[] address = new byte[6];
480         serializedBuffer.readBytes(address);
481         Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(),
482                 new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
483         serializedBuffer.skipBytes(2);
484         byte[] name = new byte[16];
485         serializedBuffer.readBytes(name);
486         Assert.assertEquals("Wrong name", port.getName(), new String(name).trim());
487         Assert.assertEquals("Wrong config", port.getConfig(), createPortConfig(serializedBuffer.readInt()));
488         Assert.assertEquals("Wrong state", port.getState(), createPortState(serializedBuffer.readInt()));
489         Assert.assertEquals("Wrong current", port.getCurrentFeatures(), createPortFeatures(serializedBuffer.readInt()));
490         Assert.assertEquals("Wrong advertised", port.getAdvertisedFeatures(),
491                 createPortFeatures(serializedBuffer.readInt()));
492         Assert.assertEquals("Wrong supported", port.getSupportedFeatures(),
493                 createPortFeatures(serializedBuffer.readInt()));
494         Assert.assertEquals("Wrong peer", port.getPeerFeatures(), createPortFeatures(serializedBuffer.readInt()));
495         Assert.assertEquals("Wrong Current speed", port.getCurrSpeed().longValue(), serializedBuffer.readInt());
496         Assert.assertEquals("Wrong Max speed", port.getMaxSpeed().longValue(), serializedBuffer.readInt());
497     }
498
499     @Test
500     public void testMeterFeaturesSerialize() throws Exception {
501         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
502         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
503         builder.setFlags(new MultipartRequestFlags(true));
504         builder.setType(MultipartType.forValue(11));
505         final MultipartReplyMeterFeaturesCaseBuilder meterFeaturesCase = new MultipartReplyMeterFeaturesCaseBuilder();
506         MultipartReplyMeterFeaturesBuilder meterFeatures = new MultipartReplyMeterFeaturesBuilder();
507         meterFeatures.setMaxMeter(1L);
508         meterFeatures.setBandTypes(new MeterBandTypeBitmap(true, false));
509         meterFeatures.setCapabilities(new MeterFlags(true, false, true, false));
510         meterFeatures.setMaxBands((short) 1);
511         meterFeatures.setMaxColor((short) 1);
512         meterFeaturesCase.setMultipartReplyMeterFeatures(meterFeatures.build());
513         builder.setMultipartReplyBody(meterFeaturesCase.build());
514         MultipartReplyMessage message = builder.build();
515         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
516         factory.serialize(message, serializedBuffer);
517         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 30);
518         Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERFEATURES.getIntValue(), serializedBuffer.readShort());
519         Assert.assertEquals("Wrong flags", message.getFlags(),
520                 createMultipartRequestFlags(serializedBuffer.readShort()));
521         serializedBuffer.skipBytes(PADDING);
522         MultipartReplyMeterFeaturesCase body = (MultipartReplyMeterFeaturesCase) message.getMultipartReplyBody();
523         MultipartReplyMeterFeatures messageOutput = body.getMultipartReplyMeterFeatures();
524         Assert.assertEquals("Wrong max meter", messageOutput.getMaxMeter().intValue(), serializedBuffer.readInt());
525         Assert.assertEquals("Wrong band type", messageOutput.getBandTypes(),
526                 createMeterBandTypeBitmap(serializedBuffer.readInt()));
527         Assert.assertEquals("Wrong capabilities", messageOutput.getCapabilities(),
528                 createMeterFlags(serializedBuffer.readShort()));
529         Assert.assertEquals("Wrong max bands", messageOutput.getMaxBands().shortValue(),
530                 serializedBuffer.readUnsignedByte());
531         Assert.assertEquals("Wrong max color", messageOutput.getMaxColor().shortValue(),
532                 serializedBuffer.readUnsignedByte());
533         serializedBuffer.skipBytes(2);
534     }
535
536     @Test
537     public void testMeterConfigSerialize() throws Exception {
538         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
539         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
540         builder.setFlags(new MultipartRequestFlags(true));
541         builder.setType(MultipartType.forValue(10));
542         MultipartReplyMeterConfigCaseBuilder meterConfigCase = new MultipartReplyMeterConfigCaseBuilder();
543         MultipartReplyMeterConfigBuilder meterConfigBuilder = new MultipartReplyMeterConfigBuilder();
544         meterConfigBuilder.setMeterConfig(createMeterConfig());
545         meterConfigCase.setMultipartReplyMeterConfig(meterConfigBuilder.build());
546         builder.setMultipartReplyBody(meterConfigCase.build());
547         MultipartReplyMessage message = builder.build();
548         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
549         factory.serialize(message, serializedBuffer);
550         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 48);
551         Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERCONFIG.getIntValue(), serializedBuffer.readShort());
552         Assert.assertEquals("Wrong flags", message.getFlags(),
553                 createMultipartRequestFlags(serializedBuffer.readShort()));
554         serializedBuffer.skipBytes(PADDING);
555         MultipartReplyMeterConfigCase body = (MultipartReplyMeterConfigCase) message.getMultipartReplyBody();
556         MultipartReplyMeterConfig messageOutput = body.getMultipartReplyMeterConfig();
557         MeterConfig meterConfig = messageOutput.getMeterConfig().get(0);
558         Assert.assertEquals("Wrong len", 32, serializedBuffer.readShort());
559         Assert.assertEquals("Wrong flags", meterConfig.getFlags(), createMeterFlags(serializedBuffer.readShort()));
560         Assert.assertEquals("Wrong meterId", meterConfig.getMeterId().getValue().intValue(),
561                 serializedBuffer.readInt());
562         Assert.assertEquals("Wrong bands", meterConfig.getBands(), decodeBandsList(serializedBuffer));
563     }
564
565     @Test
566     public void testMeterSerialize() throws Exception {
567         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
568         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
569         builder.setFlags(new MultipartRequestFlags(true));
570         builder.setType(MultipartType.forValue(9));
571         MultipartReplyMeterCaseBuilder meterCase = new MultipartReplyMeterCaseBuilder();
572         MultipartReplyMeterBuilder meter = new MultipartReplyMeterBuilder();
573         meter.setMeterStats(createMeterStats());
574         meterCase.setMultipartReplyMeter(meter.build());
575         builder.setMultipartReplyBody(meterCase.build());
576         MultipartReplyMessage message = builder.build();
577         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
578         factory.serialize(message, serializedBuffer);
579         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 74);
580         Assert.assertEquals("Wrong type", MultipartType.OFPMPMETER.getIntValue(), serializedBuffer.readShort());
581         Assert.assertEquals("Wrong flags", message.getFlags(),
582                 createMultipartRequestFlags(serializedBuffer.readShort()));
583         serializedBuffer.skipBytes(PADDING);
584         MultipartReplyMeterCase body = (MultipartReplyMeterCase) message.getMultipartReplyBody();
585         MultipartReplyMeter messageOutput = body.getMultipartReplyMeter();
586         MeterStats meterStats = messageOutput.getMeterStats().get(0);
587         Assert.assertEquals("Wrong meterId", meterStats.getMeterId().getValue().intValue(), serializedBuffer.readInt());
588         Assert.assertEquals("Wrong len", 58, serializedBuffer.readInt());
589         serializedBuffer.skipBytes(6);
590         Assert.assertEquals("Wrong flow count", meterStats.getFlowCount().intValue(), serializedBuffer.readInt());
591         Assert.assertEquals("Wrong packet in count", meterStats.getPacketInCount().longValue(),
592                 serializedBuffer.readLong());
593         Assert.assertEquals("Wrong byte in count", meterStats.getByteInCount().longValue(),
594                 serializedBuffer.readLong());
595         Assert.assertEquals("Wrong duration sec", meterStats.getDurationSec().intValue(), serializedBuffer.readInt());
596         Assert.assertEquals("Wrong duration nsec", meterStats.getDurationNsec().intValue(), serializedBuffer.readInt());
597         MeterBandStats meterBandStats = meterStats.getMeterBandStats().get(0);
598         Assert.assertEquals("Wrong packet in count", meterBandStats.getPacketBandCount().longValue(),
599                 serializedBuffer.readLong());
600         Assert.assertEquals("Wrong byte in count", meterBandStats.getByteBandCount().longValue(),
601                 serializedBuffer.readLong());
602     }
603
604     @Test
605     public void testGroupFeaturesSerialize() throws Exception {
606         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
607         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
608         builder.setFlags(new MultipartRequestFlags(true));
609         builder.setType(MultipartType.forValue(8));
610         final MultipartReplyGroupFeaturesCaseBuilder featureCase = new MultipartReplyGroupFeaturesCaseBuilder();
611         MultipartReplyGroupFeaturesBuilder feature = new MultipartReplyGroupFeaturesBuilder();
612         feature.setTypes(new GroupTypes(true, false, true, false));
613         feature.setCapabilities(new GroupCapabilities(true, false, true, true));
614         List<Uint32> maxGroups = new ArrayList<>();
615         maxGroups.add(Uint32.valueOf(1));
616         maxGroups.add(Uint32.valueOf(2));
617         maxGroups.add(Uint32.valueOf(3));
618         maxGroups.add(Uint32.valueOf(4));
619         feature.setMaxGroups(maxGroups);
620         feature.setActionsBitmap(createActionType());
621         featureCase.setMultipartReplyGroupFeatures(feature.build());
622         builder.setMultipartReplyBody(featureCase.build());
623         MultipartReplyMessage message = builder.build();
624         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
625         factory.serialize(message, serializedBuffer);
626         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 56);
627         Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPFEATURES.getIntValue(), serializedBuffer.readShort());
628         Assert.assertEquals("Wrong flags", message.getFlags(),
629                 createMultipartRequestFlags(serializedBuffer.readShort()));
630         serializedBuffer.skipBytes(PADDING);
631         MultipartReplyGroupFeaturesCase body = (MultipartReplyGroupFeaturesCase) message.getMultipartReplyBody();
632         MultipartReplyGroupFeatures messageOutput = body.getMultipartReplyGroupFeatures();
633         Assert.assertEquals("Wrong type", messageOutput.getTypes(), createGroupTypes(serializedBuffer.readInt()));
634         Assert.assertEquals("Wrong capabilities", messageOutput.getCapabilities(),
635                 createGroupCapabilities(serializedBuffer.readInt()));
636         Assert.assertEquals("Wrong max groups", messageOutput.getMaxGroups().get(0).intValue(),
637                 serializedBuffer.readInt());
638         Assert.assertEquals("Wrong max groups", messageOutput.getMaxGroups().get(1).intValue(),
639                 serializedBuffer.readInt());
640         Assert.assertEquals("Wrong max groups", messageOutput.getMaxGroups().get(2).intValue(),
641                 serializedBuffer.readInt());
642         Assert.assertEquals("Wrong max groups", messageOutput.getMaxGroups().get(3).intValue(),
643                 serializedBuffer.readInt());
644         Assert.assertEquals("Wrong actions", messageOutput.getActionsBitmap().get(0),
645                 createActionType(serializedBuffer.readInt()));
646         Assert.assertEquals("Wrong actions", messageOutput.getActionsBitmap().get(1),
647                 createActionType(serializedBuffer.readInt()));
648         Assert.assertEquals("Wrong actions", messageOutput.getActionsBitmap().get(2),
649                 createActionType(serializedBuffer.readInt()));
650         Assert.assertEquals("Wrong actions", messageOutput.getActionsBitmap().get(3),
651                 createActionType(serializedBuffer.readInt()));
652     }
653
654     @Test
655     public void testGroupDescSerialize() throws Exception {
656         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
657         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
658         builder.setFlags(new MultipartRequestFlags(true));
659         builder.setType(MultipartType.forValue(7));
660         MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder();
661         MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder();
662         group.setGroupDesc(createGroupDesc());
663         groupCase.setMultipartReplyGroupDesc(group.build());
664         builder.setMultipartReplyBody(groupCase.build());
665         MultipartReplyMessage message = builder.build();
666         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
667         factory.serialize(message, serializedBuffer);
668         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 64);
669         Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPDESC.getIntValue(), serializedBuffer.readShort());
670         Assert.assertEquals("Wrong flags", message.getFlags(),
671                 createMultipartRequestFlags(serializedBuffer.readShort()));
672         serializedBuffer.skipBytes(PADDING);
673         MultipartReplyGroupDescCase body = (MultipartReplyGroupDescCase) message.getMultipartReplyBody();
674         MultipartReplyGroupDesc messageOutput = body.getMultipartReplyGroupDesc();
675         GroupDesc groupDesc = messageOutput.getGroupDesc().get(0);
676         Assert.assertEquals("Wrong length", 48, serializedBuffer.readShort());
677         Assert.assertEquals("Wrong type", groupDesc.getType().getIntValue(), serializedBuffer.readUnsignedByte());
678         serializedBuffer.skipBytes(1);
679         Assert.assertEquals("Wrong group id", groupDesc.getGroupId().getValue().intValue(), serializedBuffer.readInt());
680         BucketsList bucketList = groupDesc.getBucketsList().get(0);
681         Assert.assertEquals("Wrong length", 40, serializedBuffer.readShort());
682         Assert.assertEquals("Wrong weight", bucketList.getWeight().intValue(), serializedBuffer.readShort());
683         Assert.assertEquals("Wrong watch port", bucketList.getWatchPort().getValue().intValue(),
684                 serializedBuffer.readInt());
685         Assert.assertEquals("Wrong watch group", bucketList.getWatchGroup().intValue(), serializedBuffer.readInt());
686         serializedBuffer.skipBytes(4);
687
688         Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
689         Assert.assertEquals("Wrong action length", 16, serializedBuffer.readUnsignedShort());
690         Assert.assertEquals("Wrong action type", 45, serializedBuffer.readUnsignedInt());
691         Assert.assertEquals("Wrong action type", 55, serializedBuffer.readUnsignedShort());
692         serializedBuffer.skipBytes(6);
693         Assert.assertEquals("Wrong action type", 23, serializedBuffer.readUnsignedShort());
694         Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
695         Assert.assertEquals("Wrong action type", 64, serializedBuffer.readUnsignedByte());
696         serializedBuffer.skipBytes(3);
697         Assert.assertTrue("Not all data were read", serializedBuffer.readableBytes() == 0);
698     }
699
700     @Test
701     public void testGroupSerialize() throws Exception {
702         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
703         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
704         builder.setFlags(new MultipartRequestFlags(true));
705         builder.setType(MultipartType.forValue(6));
706         MultipartReplyGroupCaseBuilder groupCase = new MultipartReplyGroupCaseBuilder();
707         MultipartReplyGroupBuilder group = new MultipartReplyGroupBuilder();
708         group.setGroupStats(createGroupStats());
709         groupCase.setMultipartReplyGroup(group.build());
710         builder.setMultipartReplyBody(groupCase.build());
711         MultipartReplyMessage message = builder.build();
712         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
713         factory.serialize(message, serializedBuffer);
714         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
715         Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUP.getIntValue(), serializedBuffer.readShort());
716         Assert.assertEquals("Wrong flags", message.getFlags(),
717                 createMultipartRequestFlags(serializedBuffer.readShort()));
718         serializedBuffer.skipBytes(PADDING);
719         MultipartReplyGroupCase body = (MultipartReplyGroupCase) message.getMultipartReplyBody();
720         MultipartReplyGroup messageOutput = body.getMultipartReplyGroup();
721         GroupStats groupStats = messageOutput.getGroupStats().get(0);
722         Assert.assertEquals("Wrong length", 56, serializedBuffer.readShort());
723         serializedBuffer.skipBytes(2);
724         Assert.assertEquals("Wrong group id", groupStats.getGroupId().getValue().intValue(),
725                 serializedBuffer.readInt());
726         Assert.assertEquals("Wrong ref count", groupStats.getRefCount().intValue(), serializedBuffer.readInt());
727         serializedBuffer.skipBytes(4);
728         Assert.assertEquals("Wrong Packet count", groupStats.getPacketCount().longValue(), serializedBuffer.readLong());
729         Assert.assertEquals("Wrong Byte count", groupStats.getByteCount().longValue(), serializedBuffer.readLong());
730         Assert.assertEquals("Wrong duration sec", groupStats.getDurationSec().intValue(), serializedBuffer.readInt());
731         Assert.assertEquals("Wrong duration nsec", groupStats.getDurationNsec().intValue(), serializedBuffer.readInt());
732         BucketStats bucketStats = groupStats.getBucketStats().get(0);
733         Assert.assertEquals("Wrong Packet count", bucketStats.getPacketCount().longValue(),
734                 serializedBuffer.readLong());
735         Assert.assertEquals("Wrong Byte count", bucketStats.getByteCount().longValue(), serializedBuffer.readLong());
736     }
737
738     @Test
739     public void testQueueSerialize() throws Exception {
740         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
741         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
742         builder.setFlags(new MultipartRequestFlags(true));
743         builder.setType(MultipartType.forValue(5));
744         MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder();
745         MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder();
746         queue.setQueueStats(createQueueStats());
747         queueCase.setMultipartReplyQueue(queue.build());
748         builder.setMultipartReplyBody(queueCase.build());
749         MultipartReplyMessage message = builder.build();
750         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
751         factory.serialize(message, serializedBuffer);
752         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 56);
753         Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort());
754         Assert.assertEquals("Wrong flags", message.getFlags(),
755                 createMultipartRequestFlags(serializedBuffer.readShort()));
756         serializedBuffer.skipBytes(PADDING);
757         MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody();
758         MultipartReplyQueue messageOutput = body.getMultipartReplyQueue();
759         QueueStats queueStats = messageOutput.getQueueStats().get(0);
760         Assert.assertEquals("Wrong PortNo", queueStats.getPortNo().intValue(), serializedBuffer.readUnsignedInt());
761         Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(), serializedBuffer.readUnsignedInt());
762         Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong());
763         Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong());
764         Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong());
765         Assert.assertEquals("Wrong duration sec", queueStats.getDurationSec().intValue(), serializedBuffer.readInt());
766         Assert.assertEquals("Wrong duration nsec", queueStats.getDurationNsec().intValue(), serializedBuffer.readInt());
767     }
768
769     @Test
770     public void testPortStatsSerialize() throws Exception {
771         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
772         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
773         builder.setFlags(new MultipartRequestFlags(true));
774         builder.setType(MultipartType.forValue(4));
775         MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder();
776         MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder();
777         portStats.setPortStats(createPortStats());
778         portStatsCase.setMultipartReplyPortStats(portStats.build());
779         builder.setMultipartReplyBody(portStatsCase.build());
780         MultipartReplyMessage message = builder.build();
781         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
782         factory.serialize(message, serializedBuffer);
783         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 128);
784         Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort());
785         Assert.assertEquals("Wrong flags", message.getFlags(),
786                 createMultipartRequestFlags(serializedBuffer.readShort()));
787         serializedBuffer.skipBytes(PADDING);
788         MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody();
789         MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats();
790         PortStats portStatsOutput = messageOutput.getPortStats().get(0);
791         Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt());
792         serializedBuffer.skipBytes(4);
793         Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(),
794                 serializedBuffer.readLong());
795         Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(),
796                 serializedBuffer.readLong());
797         Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(), serializedBuffer.readLong());
798         Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(), serializedBuffer.readLong());
799         Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(),
800                 serializedBuffer.readLong());
801         Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(),
802                 serializedBuffer.readLong());
803         Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(), serializedBuffer.readLong());
804         Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(), serializedBuffer.readLong());
805         Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(),
806                 serializedBuffer.readLong());
807         Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(),
808                 serializedBuffer.readLong());
809         Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(), serializedBuffer.readLong());
810         Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(),
811                 serializedBuffer.readLong());
812         Assert.assertEquals("Wrong duration sec", portStatsOutput.getDurationSec().intValue(),
813                 serializedBuffer.readInt());
814         Assert.assertEquals("Wrong duration nsec", portStatsOutput.getDurationNsec().intValue(),
815                 serializedBuffer.readInt());
816     }
817
818     @Test
819     public void testTableSerialize() throws Exception {
820         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
821         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
822         builder.setFlags(new MultipartRequestFlags(true));
823         builder.setType(MultipartType.forValue(3));
824         MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
825         MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
826         table.setTableStats(createTableStats());
827         tableCase.setMultipartReplyTable(table.build());
828         builder.setMultipartReplyBody(tableCase.build());
829         MultipartReplyMessage message = builder.build();
830         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
831         factory.serialize(message, serializedBuffer);
832         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 40);
833         Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
834         Assert.assertEquals("Wrong flags", message.getFlags(),
835                 createMultipartRequestFlags(serializedBuffer.readShort()));
836         serializedBuffer.skipBytes(PADDING);
837         MultipartReplyTableCase body = (MultipartReplyTableCase) message.getMultipartReplyBody();
838         MultipartReplyTable messageOutput = body.getMultipartReplyTable();
839         TableStats tableStats = messageOutput.getTableStats().get(0);
840         Assert.assertEquals("Wrong tableId", tableStats.getTableId().shortValue(), serializedBuffer.readUnsignedByte());
841         serializedBuffer.skipBytes(3);
842         Assert.assertEquals("Wrong active count", tableStats.getActiveCount().longValue(), serializedBuffer.readInt());
843         Assert.assertEquals("Wrong lookup count", tableStats.getLookupCount().longValue(), serializedBuffer.readLong());
844         Assert.assertEquals("Wrong matched count", tableStats.getMatchedCount().longValue(),
845                 serializedBuffer.readLong());
846     }
847
848     @Test
849     public void testAggregateSerialize() throws Exception {
850         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
851         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
852         builder.setFlags(new MultipartRequestFlags(true));
853         builder.setType(MultipartType.forValue(2));
854         final MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder();
855         MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder();
856         aggregate.setPacketCount(BigInteger.valueOf(1L));
857         aggregate.setByteCount(BigInteger.valueOf(1L));
858         aggregate.setFlowCount(1L);
859         aggregateCase.setMultipartReplyAggregate(aggregate.build());
860         builder.setMultipartReplyBody(aggregateCase.build());
861         MultipartReplyMessage message = builder.build();
862         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
863         factory.serialize(message, serializedBuffer);
864         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 40);
865         Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort());
866         Assert.assertEquals("Wrong flags", message.getFlags(),
867                 createMultipartRequestFlags(serializedBuffer.readShort()));
868         serializedBuffer.skipBytes(PADDING);
869         MultipartReplyAggregateCase body = (MultipartReplyAggregateCase) message.getMultipartReplyBody();
870         MultipartReplyAggregate messageOutput = body.getMultipartReplyAggregate();
871         Assert.assertEquals("Wrong Packet count", messageOutput.getPacketCount().longValue(),
872                 serializedBuffer.readLong());
873         Assert.assertEquals("Wrong Byte count", messageOutput.getByteCount().longValue(), serializedBuffer.readLong());
874         Assert.assertEquals("Wrong Flow count", messageOutput.getFlowCount().longValue(), serializedBuffer.readInt());
875         serializedBuffer.skipBytes(4);
876     }
877
878     @Test
879     public void testFlowSerialize() throws Exception {
880         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
881         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
882         builder.setFlags(new MultipartRequestFlags(true));
883         builder.setType(MultipartType.forValue(1));
884         MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
885         MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
886         flow.setFlowStats(createFlowStats());
887         flowCase.setMultipartReplyFlow(flow.build());
888         builder.setMultipartReplyBody(flowCase.build());
889         MultipartReplyMessage message = builder.build();
890         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
891         factory.serialize(message, serializedBuffer);
892         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 192);
893         Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
894         Assert.assertEquals("Wrong flags", message.getFlags(),
895                 createMultipartRequestFlags(serializedBuffer.readShort()));
896         serializedBuffer.skipBytes(PADDING);
897         testFlowBody(message.getMultipartReplyBody(), serializedBuffer);
898     }
899
900     @Test
901     public void testDescSerialize() throws Exception {
902         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
903         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
904         builder.setFlags(new MultipartRequestFlags(true));
905         builder.setType(MultipartType.forValue(0));
906         final MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
907         MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
908         desc.setMfrDesc("Test");
909         desc.setHwDesc("Test");
910         desc.setSwDesc("Test");
911         desc.setSerialNum("12345");
912         desc.setDpDesc("Test");
913         descCase.setMultipartReplyDesc(desc.build());
914         builder.setMultipartReplyBody(descCase.build());
915         MultipartReplyMessage message = builder.build();
916         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
917         factory.serialize(message, serializedBuffer);
918         BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 1072);
919         Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort());
920         Assert.assertEquals("Wrong flags", message.getFlags(),
921                 createMultipartRequestFlags(serializedBuffer.readShort()));
922         serializedBuffer.skipBytes(PADDING);
923         Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer));
924     }
925
926     private static void testFlowBody(MultipartReplyBody body, ByteBuf output) {
927         MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
928         MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
929         FlowStats flowStats = flow.getFlowStats().get(0);
930         Assert.assertEquals("Wrong length", 176, output.readShort());
931         Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte());
932         output.skipBytes(1);
933         Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt());
934         Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt());
935         Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort());
936         Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort());
937         Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort());
938         output.skipBytes(6);
939         Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong());
940         Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong());
941         Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong());
942         Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort());
943         output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
944         Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
945         short fieldAndMask = output.readUnsignedByte();
946         Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
947         Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
948         output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
949         Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt());
950         Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
951         fieldAndMask = output.readUnsignedByte();
952         Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
953         Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
954         output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
955         Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte());
956         output.skipBytes(7);
957         Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort());
958         Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
959         Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte());
960         output.skipBytes(3);
961         Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort());
962         Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
963         output.skipBytes(4);
964         byte[] actual = new byte[8];
965         output.readBytes(actual);
966         Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07",
967                 ByteBufUtils.bytesToHexString(actual));
968         actual = new byte[8];
969         output.readBytes(actual);
970         Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00",
971                 ByteBufUtils.bytesToHexString(actual));
972         Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort());
973         Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
974         output.skipBytes(4);
975         Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort());
976         Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
977         Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt());
978         Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort());
979         Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort());
980         output.skipBytes(4);
981         Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort());
982         Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort());
983         Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt());
984         Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort());
985         output.skipBytes(6);
986         Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort());
987         Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
988         Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte());
989         output.skipBytes(3);
990         Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort());
991         Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
992         output.skipBytes(4);
993         Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort());
994         Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
995         Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort());
996         output.skipBytes(2);
997         Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort());
998         Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
999         output.skipBytes(4);
1000         Assert.assertTrue("Not all data were read", output.readableBytes() == 0);
1001     }
1002
1003     private static List<Ports> createPortList() {
1004         PortsBuilder builder = new PortsBuilder();
1005         builder.setPortNo(1L);
1006         builder.setHwAddr(new MacAddress("94:de:80:a6:61:40"));
1007         builder.setName("Port name");
1008         builder.setConfig(new PortConfig(true, false, true, false));
1009         builder.setState(new PortState(true, false, true));
1010         builder.setCurrentFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false,
1011                 true, false, true, false, true, false));
1012         builder.setAdvertisedFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false,
1013                 true, false, true, false, true, false));
1014         builder.setSupportedFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false,
1015                 true, false, true, false, true, false));
1016         builder.setPeerFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false, true,
1017                 false, true, false, true, false));
1018         builder.setCurrSpeed(1234L);
1019         builder.setMaxSpeed(1234L);
1020         List<Ports> list = new ArrayList<>();
1021         list.add(builder.build());
1022         return list;
1023     }
1024
1025     private static PortConfig createPortConfig(long input) {
1026         final Boolean _portDown = (input & 1 << 0) > 0;
1027         final Boolean _noRecv = (input & 1 << 2) > 0;
1028         final Boolean _noFwd = (input & 1 << 5) > 0;
1029         final Boolean _noPacketIn = (input & 1 << 6) > 0;
1030         return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown);
1031     }
1032
1033     private static PortFeatures createPortFeatures(long input) {
1034         final Boolean _10mbHd = (input & 1 << 0) > 0;
1035         final Boolean _10mbFd = (input & 1 << 1) > 0;
1036         final Boolean _100mbHd = (input & 1 << 2) > 0;
1037         final Boolean _100mbFd = (input & 1 << 3) > 0;
1038         final Boolean _1gbHd = (input & 1 << 4) > 0;
1039         final Boolean _1gbFd = (input & 1 << 5) > 0;
1040         final Boolean _10gbFd = (input & 1 << 6) > 0;
1041         final Boolean _40gbFd = (input & 1 << 7) > 0;
1042         final Boolean _100gbFd = (input & 1 << 8) > 0;
1043         final Boolean _1tbFd = (input & 1 << 9) > 0;
1044         final Boolean _other = (input & 1 << 10) > 0;
1045         final Boolean _copper = (input & 1 << 11) > 0;
1046         final Boolean _fiber = (input & 1 << 12) > 0;
1047         final Boolean _autoneg = (input & 1 << 13) > 0;
1048         final Boolean _pause = (input & 1 << 14) > 0;
1049         final Boolean _pauseAsym = (input & 1 << 15) > 0;
1050         return new PortFeatures(_100gbFd, _100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, _1gbFd, _1gbHd, _1tbFd,
1051                 _40gbFd, _autoneg, _copper, _fiber, _other, _pause, _pauseAsym);
1052     }
1053
1054     private static PortState createPortState(long input) {
1055         final Boolean one = (input & 1 << 0) > 0;
1056         final Boolean two = (input & 1 << 1) > 0;
1057         final Boolean three = (input & 1 << 2) > 0;
1058         return new PortState(two, one, three);
1059     }
1060
1061     private static List<Bands> decodeBandsList(ByteBuf input) {
1062         final List<Bands> bandsList = new ArrayList<>();
1063         final BandsBuilder bandsBuilder = new BandsBuilder();
1064         final MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
1065         MeterBandDropBuilder dropBand = new MeterBandDropBuilder();
1066         dropBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
1067         input.skipBytes(Short.SIZE / Byte.SIZE);
1068         dropBand.setRate(input.readUnsignedInt());
1069         dropBand.setBurstSize(input.readUnsignedInt());
1070         dropCaseBuilder.setMeterBandDrop(dropBand.build());
1071         bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build());
1072         final MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
1073         MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder();
1074         dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
1075         input.skipBytes(Short.SIZE / Byte.SIZE);
1076         dscpRemarkBand.setRate(input.readUnsignedInt());
1077         dscpRemarkBand.setBurstSize(input.readUnsignedInt());
1078         dscpRemarkBand.setPrecLevel((short) 3);
1079         dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
1080         bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
1081         return bandsList;
1082     }
1083
1084     private static List<MeterConfig> createMeterConfig() {
1085         MeterConfigBuilder builder = new MeterConfigBuilder();
1086         builder.setFlags(new MeterFlags(true, false, true, false));
1087         builder.setMeterId(new MeterId(1L));
1088         builder.setBands(createBandsList());
1089         List<MeterConfig> list = new ArrayList<>();
1090         list.add(builder.build());
1091         return list;
1092     }
1093
1094     private static MeterBandTypeBitmap createMeterBandTypeBitmap(int input) {
1095         final Boolean one = (input & 1 << 0) > 0;
1096         final Boolean two = (input & 1 << 1) > 0;
1097         return new MeterBandTypeBitmap(one, two);
1098     }
1099
1100     private static List<Bands> createBandsList() {
1101         final List<Bands> bandsList = new ArrayList<>();
1102         final BandsBuilder bandsBuilder = new BandsBuilder();
1103         final MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
1104         MeterBandDropBuilder dropBand = new MeterBandDropBuilder();
1105         dropBand.setType(MeterBandType.OFPMBTDROP);
1106         dropBand.setRate(1L);
1107         dropBand.setBurstSize(2L);
1108         dropCaseBuilder.setMeterBandDrop(dropBand.build());
1109         bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build());
1110         final MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
1111         MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder();
1112         dscpRemarkBand.setType(MeterBandType.OFPMBTDSCPREMARK);
1113         dscpRemarkBand.setRate(1L);
1114         dscpRemarkBand.setBurstSize(2L);
1115         dscpRemarkBand.setPrecLevel((short) 3);
1116         dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
1117         bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
1118         return bandsList;
1119     }
1120
1121     private static MeterFlags createMeterFlags(int input) {
1122         final Boolean one = (input & 1 << 0) > 0;
1123         final Boolean two = (input & 1 << 1) > 0;
1124         final Boolean three = (input & 1 << 2) > 0;
1125         final Boolean four = (input & 1 << 3) > 0;
1126         return new MeterFlags(three, one, two, four);
1127     }
1128
1129     private static List<MeterStats> createMeterStats() {
1130         MeterStatsBuilder builder = new MeterStatsBuilder();
1131         builder.setMeterId(new MeterId(1L));
1132         builder.setFlowCount(1L);
1133         builder.setPacketInCount(BigInteger.valueOf(1L));
1134         builder.setByteInCount(BigInteger.valueOf(1L));
1135         builder.setDurationSec(1L);
1136         builder.setDurationNsec(1L);
1137         builder.setMeterBandStats(createMeterBandStats());
1138         List<MeterStats> list = new ArrayList<>();
1139         list.add(builder.build());
1140         return list;
1141     }
1142
1143     private static List<MeterBandStats> createMeterBandStats() {
1144         MeterBandStatsBuilder builder = new MeterBandStatsBuilder();
1145         builder.setPacketBandCount(BigInteger.valueOf(1L));
1146         builder.setByteBandCount(BigInteger.valueOf(1L));
1147         List<MeterBandStats> list = new ArrayList<>();
1148         list.add(builder.build());
1149         return list;
1150     }
1151
1152     private static ActionType createActionType(int input) {
1153         final Boolean one = (input & 1 << 0) > 0;
1154         final Boolean two = (input & 1 << 1) > 0;
1155         final Boolean three = (input & 1 << 2) > 0;
1156         final Boolean four = (input & 1 << 3) > 0;
1157         final Boolean five = (input & 1 << 4) > 0;
1158         final Boolean six = (input & 1 << 5) > 0;
1159         final Boolean seven = (input & 1 << 6) > 0;
1160         final Boolean eight = (input & 1 << 7) > 0;
1161         final Boolean nine = (input & 1 << 8) > 0;
1162         final Boolean ten = (input & 1 << 9) > 0;
1163         final Boolean eleven = (input & 1 << 10) > 0;
1164         final Boolean twelve = (input & 1 << 11) > 0;
1165         final Boolean thirteen = (input & 1 << 12) > 0;
1166         final Boolean fourteen = (input & 1 << 13) > 0;
1167         final Boolean fifthteen = (input & 1 << 14) > 0;
1168         final Boolean sixteen = (input & 1 << 15) > 0;
1169         final Boolean seventeen = (input & 1 << 16) > 0;
1170         return new ActionType(three, two, five, thirteen, seventeen, eleven, one, nine, sixteen, seven, eight,
1171                 fifthteen, six, fourteen, four, twelve, ten);
1172     }
1173
1174     private static List<ActionType> createActionType() {
1175         ActionType actionType1 = new ActionType(true, false, true, false, true, false, true, false, true, false, true,
1176                 false, true, false, true, false, true);
1177         ActionType actionType2 = new ActionType(true, false, false, false, true, false, true, false, true, false, true,
1178                 false, true, false, true, true, true);
1179         ActionType actionType3 = new ActionType(true, false, true, false, true, false, true, false, true, false, true,
1180                 false, true, false, true, false, true);
1181         ActionType actionType4 = new ActionType(true, false, true, false, true, false, true, false, true, false, true,
1182                 false, true, false, true, false, true);
1183         List<ActionType> list = new ArrayList<>();
1184         list.add(actionType1);
1185         list.add(actionType2);
1186         list.add(actionType3);
1187         list.add(actionType4);
1188         return list;
1189
1190     }
1191
1192     private static GroupCapabilities createGroupCapabilities(int input) {
1193         final Boolean one = (input & 1 << 0) > 0;
1194         final Boolean two = (input & 1 << 1) > 0;
1195         final Boolean three = (input & 1 << 2) > 0;
1196         final Boolean four = (input & 1 << 3) > 0;
1197         return new GroupCapabilities(three, four, two, one);
1198     }
1199
1200     private static GroupTypes createGroupTypes(int input) {
1201         final Boolean one = (input & 1 << 0) > 0;
1202         final Boolean two = (input & 1 << 1) > 0;
1203         final Boolean three = (input & 1 << 2) > 0;
1204         final Boolean four = (input & 1 << 3) > 0;
1205         return new GroupTypes(one, four, three, two);
1206     }
1207
1208     private static List<GroupDesc> createGroupDesc() {
1209         GroupDescBuilder builder = new GroupDescBuilder();
1210         builder.setType(GroupType.forValue(1));
1211         builder.setGroupId(new GroupId(1L));
1212         builder.setBucketsList(createBucketsList());
1213         List<GroupDesc> list = new ArrayList<>();
1214         list.add(builder.build());
1215         return list;
1216     }
1217
1218     private static List<GroupStats> createGroupStats() {
1219         GroupStatsBuilder builder = new GroupStatsBuilder();
1220         builder.setGroupId(new GroupId(1L));
1221         builder.setRefCount(1L);
1222         builder.setPacketCount(BigInteger.valueOf(1L));
1223         builder.setByteCount(BigInteger.valueOf(1L));
1224         builder.setDurationSec(1L);
1225         builder.setDurationNsec(1L);
1226         builder.setBucketStats(createBucketStats());
1227         List<GroupStats> list = new ArrayList<>();
1228         list.add(builder.build());
1229         return list;
1230     }
1231
1232     private static List<BucketsList> createBucketsList() {
1233         BucketsListBuilder builder = new BucketsListBuilder();
1234         builder.setWeight(1);
1235         builder.setWatchPort(new PortNumber(1L));
1236         builder.setWatchGroup(1L);
1237         builder.setAction(createActionList());
1238         List<BucketsList> list = new ArrayList<>();
1239         list.add(builder.build());
1240         return list;
1241     }
1242
1243     private static List<Action> createActionList() {
1244         final List<Action> actions = new ArrayList<>();
1245         OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
1246         OutputActionBuilder outputBuilder = new OutputActionBuilder();
1247         outputBuilder.setPort(new PortNumber(45L));
1248         outputBuilder.setMaxLength(55);
1249         caseBuilder.setOutputAction(outputBuilder.build());
1250         ActionBuilder actionBuilder = new ActionBuilder();
1251         actionBuilder.setActionChoice(caseBuilder.build());
1252         actions.add(actionBuilder.build());
1253         actionBuilder = new ActionBuilder();
1254         SetNwTtlCaseBuilder ttlCaseBuilder = new SetNwTtlCaseBuilder();
1255         SetNwTtlActionBuilder ttlActionBuilder = new SetNwTtlActionBuilder();
1256         ttlActionBuilder.setNwTtl((short) 64);
1257         ttlCaseBuilder.setSetNwTtlAction(ttlActionBuilder.build());
1258         actionBuilder.setActionChoice(ttlCaseBuilder.build());
1259         actions.add(actionBuilder.build());
1260         return actions;
1261     }
1262
1263     private static List<BucketStats> createBucketStats() {
1264         BucketStatsBuilder builder = new BucketStatsBuilder();
1265         builder.setPacketCount(BigInteger.valueOf(1L));
1266         builder.setByteCount(BigInteger.valueOf(1L));
1267         List<BucketStats> list = new ArrayList<>();
1268         list.add(builder.build());
1269         return list;
1270     }
1271
1272     private static List<QueueStats> createQueueStats() {
1273         QueueStatsBuilder builder = new QueueStatsBuilder();
1274         builder.setPortNo(1L);
1275         builder.setQueueId(1L);
1276         builder.setTxBytes(BigInteger.valueOf(1L));
1277         builder.setTxPackets(BigInteger.valueOf(1L));
1278         builder.setTxErrors(BigInteger.valueOf(1L));
1279         builder.setDurationSec(1L);
1280         builder.setDurationNsec(1L);
1281         List<QueueStats> list = new ArrayList<>();
1282         list.add(builder.build());
1283         return list;
1284     }
1285
1286     private static List<PortStats> createPortStats() {
1287         PortStatsBuilder builder = new PortStatsBuilder();
1288         builder.setPortNo(1L);
1289         builder.setRxPackets(BigInteger.valueOf(1L));
1290         builder.setTxPackets(BigInteger.valueOf(1L));
1291         builder.setRxBytes(BigInteger.valueOf(1L));
1292         builder.setTxBytes(BigInteger.valueOf(1L));
1293         builder.setRxDropped(BigInteger.valueOf(1L));
1294         builder.setTxDropped(BigInteger.valueOf(1L));
1295         builder.setRxErrors(BigInteger.valueOf(1L));
1296         builder.setTxErrors(BigInteger.valueOf(1L));
1297         builder.setRxFrameErr(BigInteger.valueOf(1L));
1298         builder.setRxOverErr(BigInteger.valueOf(1L));
1299         builder.setRxCrcErr(BigInteger.valueOf(1L));
1300         builder.setCollisions(BigInteger.valueOf(1L));
1301         builder.setDurationSec(1L);
1302         builder.setDurationNsec(1L);
1303         List<PortStats> list = new ArrayList<>();
1304         list.add(builder.build());
1305         return list;
1306     }
1307
1308     private static List<TableStats> createTableStats() {
1309         TableStatsBuilder builder = new TableStatsBuilder();
1310         builder.setTableId((short) 1);
1311         builder.setActiveCount(1L);
1312         builder.setLookupCount(BigInteger.valueOf(1L));
1313         builder.setMatchedCount(BigInteger.valueOf(1L));
1314         List<TableStats> list = new ArrayList<>();
1315         list.add(builder.build());
1316         return list;
1317     }
1318
1319     private static List<FlowStats> createFlowStats() {
1320         FlowStatsBuilder builder = new FlowStatsBuilder();
1321         builder.setTableId((short) 1);
1322         builder.setDurationSec(1L);
1323         builder.setDurationNsec(1L);
1324         builder.setPriority(1);
1325         builder.setIdleTimeout(1);
1326         builder.setHardTimeout(1);
1327         builder.setCookie(BigInteger.valueOf(1234L));
1328         builder.setPacketCount(BigInteger.valueOf(1234L));
1329         builder.setByteCount(BigInteger.valueOf(1234L));
1330         MatchBuilder matchBuilder = new MatchBuilder();
1331         matchBuilder.setType(OxmMatchType.class);
1332         final List<MatchEntry> entries = new ArrayList<>();
1333         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
1334         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
1335         entriesBuilder.setOxmMatchField(InPhyPort.class);
1336         entriesBuilder.setHasMask(false);
1337         InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
1338         InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
1339         inPhyPortBuilder.setPortNumber(new PortNumber(42L));
1340         inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
1341         entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
1342         entries.add(entriesBuilder.build());
1343         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
1344         entriesBuilder.setOxmMatchField(IpEcn.class);
1345         entriesBuilder.setHasMask(false);
1346         IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
1347         IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
1348         ipEcnBuilder.setEcn((short) 4);
1349         ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
1350         entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
1351         entries.add(entriesBuilder.build());
1352         matchBuilder.setMatchEntry(entries);
1353         builder.setMatch(matchBuilder.build());
1354         final List<Instruction> instructions = new ArrayList<>();
1355         // Goto_table instruction
1356         InstructionBuilder builderInstruction = new InstructionBuilder();
1357         GotoTableCaseBuilder gotoCaseBuilder = new GotoTableCaseBuilder();
1358         GotoTableBuilder instructionBuilder = new GotoTableBuilder();
1359         instructionBuilder.setTableId((short) 5);
1360         gotoCaseBuilder.setGotoTable(instructionBuilder.build());
1361         builderInstruction.setInstructionChoice(gotoCaseBuilder.build());
1362         instructions.add(builderInstruction.build());
1363         // Write_metadata instruction
1364         builderInstruction = new InstructionBuilder();
1365         WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
1366         WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
1367         metadataBuilder.setMetadata(ByteBufUtils.hexStringToBytes("00 01 02 03 04 05 06 07"));
1368         metadataBuilder.setMetadataMask(ByteBufUtils.hexStringToBytes("07 06 05 04 03 02 01 00"));
1369         metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
1370         builderInstruction.setInstructionChoice(metadataCaseBuilder.build());
1371         instructions.add(builderInstruction.build());
1372         // Clear_actions instruction
1373         builderInstruction = new InstructionBuilder();
1374         builderInstruction.setInstructionChoice(new ClearActionsCaseBuilder().build());
1375         instructions.add(builderInstruction.build());
1376         // Meter instruction
1377         builderInstruction = new InstructionBuilder();
1378         MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
1379         MeterBuilder meterBuilder = new MeterBuilder();
1380         meterBuilder.setMeterId(42L);
1381         meterCaseBuilder.setMeter(meterBuilder.build());
1382         builderInstruction.setInstructionChoice(meterCaseBuilder.build());
1383         instructions.add(builderInstruction.build());
1384         // Write_actions instruction
1385         builderInstruction = new InstructionBuilder();
1386         final WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
1387         final WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
1388         OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
1389         OutputActionBuilder outputBuilder = new OutputActionBuilder();
1390         outputBuilder.setPort(new PortNumber(45L));
1391         outputBuilder.setMaxLength(55);
1392         caseBuilder.setOutputAction(outputBuilder.build());
1393         ActionBuilder actionBuilder = new ActionBuilder();
1394         actionBuilder.setActionChoice(caseBuilder.build());
1395         List<Action> actions = new ArrayList<>();
1396         actions.add(actionBuilder.build());
1397         actionBuilder = new ActionBuilder();
1398         SetNwTtlCaseBuilder ttlCaseBuilder = new SetNwTtlCaseBuilder();
1399         SetNwTtlActionBuilder ttlActionBuilder = new SetNwTtlActionBuilder();
1400         ttlActionBuilder.setNwTtl((short) 64);
1401         ttlCaseBuilder.setSetNwTtlAction(ttlActionBuilder.build());
1402         actionBuilder.setActionChoice(ttlCaseBuilder.build());
1403         actions.add(actionBuilder.build());
1404         writeActionsBuilder.setAction(actions);
1405         writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
1406         builderInstruction.setInstructionChoice(writeActionsCaseBuilder.build());
1407         instructions.add(builderInstruction.build());
1408         // Apply_actions instruction
1409         builderInstruction = new InstructionBuilder();
1410         final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
1411         final ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
1412         actions = new ArrayList<>();
1413         actionBuilder = new ActionBuilder();
1414         PushVlanCaseBuilder vlanCaseBuilder = new PushVlanCaseBuilder();
1415         PushVlanActionBuilder vlanBuilder = new PushVlanActionBuilder();
1416         vlanBuilder.setEthertype(new EtherType(new EtherType(14)));
1417         vlanCaseBuilder.setPushVlanAction(vlanBuilder.build());
1418         actionBuilder.setActionChoice(vlanCaseBuilder.build());
1419         actions.add(actionBuilder.build());
1420         actionBuilder = new ActionBuilder();
1421         actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
1422         actions.add(actionBuilder.build());
1423         applyActionsBuilder.setAction(actions);
1424         applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
1425         builderInstruction.setInstructionChoice(applyActionsCaseBuilder.build());
1426         instructions.add(builderInstruction.build());
1427         builder.setInstruction(instructions);
1428         List<FlowStats> list = new ArrayList<>();
1429         list.add(builder.build());
1430         return list;
1431     }
1432
1433     private static MultipartRequestFlags createMultipartRequestFlags(int input) {
1434         final Boolean one = (input & 1 << 0) > 0;
1435         return new MultipartRequestFlags(one);
1436     }
1437
1438     private static MultipartReplyDescCase decodeDescBody(ByteBuf output) {
1439         final MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
1440         MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
1441         byte[] mfrDesc = new byte[256];
1442         output.readBytes(mfrDesc);
1443         desc.setMfrDesc(new String(mfrDesc).trim());
1444         byte[] hwDesc = new byte[256];
1445         output.readBytes(hwDesc);
1446         desc.setHwDesc(new String(hwDesc).trim());
1447         byte[] swDesc = new byte[256];
1448         output.readBytes(swDesc);
1449         desc.setSwDesc(new String(swDesc).trim());
1450         byte[] serialNumber = new byte[32];
1451         output.readBytes(serialNumber);
1452         desc.setSerialNum(new String(serialNumber).trim());
1453         byte[] dpDesc = new byte[256];
1454         output.readBytes(dpDesc);
1455         desc.setDpDesc(new String(dpDesc).trim());
1456         descCase.setMultipartReplyDesc(desc.build());
1457         return descCase.build();
1458     }
1459 }