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