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