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