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