2 * Copyright (c) 2013 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer;
19 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
20 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
21 import org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer;
22 import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeaturePropertyBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeaturePropertyBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenterBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCaseBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCase;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCaseBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCaseBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCase;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroupBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder;
103 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;
104 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;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder;
106 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;
107 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;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder;
112 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;
113 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;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder;
115 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;
116 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;
117 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;
118 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;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDescBuilder;
121 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;
122 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;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder;
124 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;
125 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;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder;
133 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;
134 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;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeaturePropertiesBuilder;
139 * Translates MultipartReply messages
140 * @author timotej.kubas
141 * @author michal.polkorab
143 public class MultipartReplyMessageFactory implements OFDeserializer<MultipartReplyMessage> {
145 private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4;
146 private static final int DESC_STR_LEN = 256;
147 private static final int SERIAL_NUM_LEN = 32;
148 private static final byte PADDING_IN_FLOW_STATS_HEADER_01 = 1;
149 private static final byte PADDING_IN_FLOW_STATS_HEADER_02 = 4;
150 private static final byte PADDING_IN_AGGREGATE_HEADER = 4;
151 private static final byte PADDING_IN_TABLE_HEADER = 3;
152 private static final byte PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES = 5;
153 private static final byte MAX_TABLE_NAME_LENGTH = 32;
154 private static final byte MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH = 64;
155 private static final byte COMMON_PROPERTY_LENGTH = 4;
156 private static final byte PADDING_IN_PORT_STATS_HEADER = 4;
157 private static final byte PADDING_IN_GROUP_HEADER_01 = 2;
158 private static final byte PADDING_IN_GROUP_HEADER_02 = 4;
159 private static final byte BUCKET_COUNTER_LENGTH = 16;
160 private static final byte GROUP_BODY_LENGTH = 40;
161 private static final byte PADDING_IN_METER_FEATURES_HEADER = 2;
162 private static final byte PADDING_IN_METER_STATS_HEADER = 6;
163 private static final byte METER_BAND_STATS_LENGTH = 16;
164 private static final byte METER_BODY_LENGTH = 40;
165 private static final byte METER_CONFIG_LENGTH = 8;
166 private static final byte PADDING_IN_METER_BAND_DROP_HEADER = 4;
167 private static final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3;
168 private static final byte PADDING_IN_PORT_DESC_HEADER_01 = 4;
169 private static final byte PADDING_IN_PORT_DESC_HEADER_02 = 2;
170 private static final int GROUP_TYPES = 4;
171 private static final byte PADDING_IN_GROUP_DESC_HEADER = 1;
172 private static final byte PADDING_IN_BUCKETS_HEADER = 4;
173 private static final byte GROUP_DESC_HEADER_LENGTH = 8;
174 private static final byte BUCKETS_HEADER_LENGTH = 16;
177 private static MultipartReplyMessageFactory instance;
179 private MultipartReplyMessageFactory() {
184 * @return singleton factory
186 public static synchronized MultipartReplyMessageFactory getInstance() {
187 if (instance == null){
188 instance = new MultipartReplyMessageFactory();
194 public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) {
195 MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
196 builder.setVersion(version);
197 builder.setXid(rawMessage.readUnsignedInt());
198 int type = rawMessage.readUnsignedShort();
199 builder.setType(MultipartType.forValue(type));
200 builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0));
201 rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);
204 case 0: builder.setMultipartReplyBody(setDesc(rawMessage));
206 case 1: builder.setMultipartReplyBody(setFlow(rawMessage));
208 case 2: builder.setMultipartReplyBody(setAggregate(rawMessage));
210 case 3: builder.setMultipartReplyBody(setTable(rawMessage));
212 case 4: builder.setMultipartReplyBody(setPortStats(rawMessage));
214 case 5: builder.setMultipartReplyBody(setQueue(rawMessage));
216 case 6: builder.setMultipartReplyBody(setGroup(rawMessage));
218 case 7: builder.setMultipartReplyBody(setGroupDesc(rawMessage));
220 case 8: builder.setMultipartReplyBody(setGroupFeatures(rawMessage));
222 case 9: builder.setMultipartReplyBody(setMeter(rawMessage));
224 case 10: builder.setMultipartReplyBody(setMeterConfig(rawMessage));
226 case 11: builder.setMultipartReplyBody(setMeterFeatures(rawMessage));
228 case 12: builder.setMultipartReplyBody(setTableFeatures(rawMessage));
230 case 13: builder.setMultipartReplyBody(setPortDesc(rawMessage));
232 case 0xFFFF: builder.setMultipartReplyBody(setExperimenter(rawMessage));
238 return builder.build();
241 private static MultipartReplyDescCase setDesc(ByteBuf input) {
242 MultipartReplyDescCaseBuilder caseBuilder = new MultipartReplyDescCaseBuilder();
243 MultipartReplyDescBuilder descBuilder = new MultipartReplyDescBuilder();
244 byte[] mfrDescBytes = new byte[DESC_STR_LEN];
245 input.readBytes(mfrDescBytes);
246 String mfrDesc = new String(mfrDescBytes);
247 descBuilder.setMfrDesc(mfrDesc.trim());
248 byte[] hwDescBytes = new byte[DESC_STR_LEN];
249 input.readBytes(hwDescBytes);
250 String hwDesc = new String(hwDescBytes);
251 descBuilder.setHwDesc(hwDesc.trim());
252 byte[] swDescBytes = new byte[DESC_STR_LEN];
253 input.readBytes(swDescBytes);
254 String swDesc = new String(swDescBytes);
255 descBuilder.setSwDesc(swDesc.trim());
256 byte[] serialNumBytes = new byte[SERIAL_NUM_LEN];
257 input.readBytes(serialNumBytes);
258 String serialNum = new String(serialNumBytes);
259 descBuilder.setSerialNum(serialNum.trim());
260 byte[] dpDescBytes = new byte[DESC_STR_LEN];
261 input.readBytes(dpDescBytes);
262 String dpDesc = new String(dpDescBytes);
263 descBuilder.setDpDesc(dpDesc.trim());
264 caseBuilder.setMultipartReplyDesc(descBuilder.build());
265 return caseBuilder.build();
268 private static MultipartReplyFlowCase setFlow(ByteBuf input) {
269 MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
270 MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
271 List<FlowStats> flowStatsList = new ArrayList<>();
272 while (input.readableBytes() > 0) {
273 FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
274 input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
275 flowStatsBuilder.setTableId(input.readUnsignedByte());
276 input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
277 flowStatsBuilder.setDurationSec(input.readUnsignedInt());
278 flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
279 flowStatsBuilder.setPriority(input.readUnsignedShort());
280 flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
281 flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
282 flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(input.readShort()));
283 input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
284 byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
285 input.readBytes(cookie);
286 flowStatsBuilder.setCookie(new BigInteger(1, cookie));
287 byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
288 input.readBytes(packetCount);
289 flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
290 byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
291 input.readBytes(byteCount);
292 flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
293 flowStatsBuilder.setMatch(MatchDeserializer.createMatch(input));
294 flowStatsBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, input.readableBytes()));
295 flowStatsList.add(flowStatsBuilder.build());
297 flowBuilder.setFlowStats(flowStatsList);
298 caseBuilder.setMultipartReplyFlow(flowBuilder.build());
299 return caseBuilder.build();
302 private static FlowModFlags createFlowModFlagsFromBitmap(short input){
303 final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) != 0;
304 final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) != 0;
305 final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) != 0;
306 final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) != 0;
307 final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) != 0;
308 return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM);
311 private static MultipartReplyAggregateCase setAggregate(ByteBuf input) {
312 MultipartReplyAggregateCaseBuilder caseBuilder = new MultipartReplyAggregateCaseBuilder();
313 MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder();
314 byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
315 input.readBytes(packetCount);
316 builder.setPacketCount(new BigInteger(1, packetCount));
317 byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
318 input.readBytes(byteCount);
319 builder.setByteCount(new BigInteger(1, byteCount));
320 builder.setFlowCount(input.readUnsignedInt());
321 input.skipBytes(PADDING_IN_AGGREGATE_HEADER);
322 caseBuilder.setMultipartReplyAggregate(builder.build());
323 return caseBuilder.build();
326 private static MultipartReplyTableCase setTable(ByteBuf input) {
327 MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder();
328 MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();
329 List<TableStats> tableStatsList = new ArrayList<>();
330 while (input.readableBytes() > 0) {
331 TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();
332 tableStatsBuilder.setTableId(input.readUnsignedByte());
333 input.skipBytes(PADDING_IN_TABLE_HEADER);
334 tableStatsBuilder.setActiveCount(input.readUnsignedInt());
335 byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
336 input.readBytes(lookupCount);
337 tableStatsBuilder.setLookupCount(new BigInteger(1, lookupCount));
338 byte[] matchedCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
339 input.readBytes(matchedCount);
340 tableStatsBuilder.setMatchedCount(new BigInteger(1, matchedCount));
341 tableStatsList.add(tableStatsBuilder.build());
343 builder.setTableStats(tableStatsList);
344 caseBuilder.setMultipartReplyTable(builder.build());
345 return caseBuilder.build();
348 private static MultipartReplyTableFeaturesCase setTableFeatures(ByteBuf input) {
349 MultipartReplyTableFeaturesCaseBuilder caseBuilder = new MultipartReplyTableFeaturesCaseBuilder();
350 MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder();
351 List<TableFeatures> features = new ArrayList<>();
352 while (input.readableBytes() > 0) {
353 TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder();
354 int length = input.readUnsignedShort();
355 featuresBuilder.setTableId(input.readUnsignedByte());
356 input.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES);
357 featuresBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString());
358 byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
359 input.readBytes(metadataMatch);
360 featuresBuilder.setMetadataMatch(metadataMatch);
361 byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
362 input.readBytes(metadataWrite);
363 featuresBuilder.setMetadataWrite(metadataWrite);
364 featuresBuilder.setConfig(createTableConfig(input.readUnsignedInt()));
365 featuresBuilder.setMaxEntries(input.readUnsignedInt());
366 featuresBuilder.setTableFeatureProperties(createTableFeaturesProperties(input,
367 length - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH));
368 features.add(featuresBuilder.build());
370 builder.setTableFeatures(features);
371 caseBuilder.setMultipartReplyTableFeatures(builder.build());
372 return caseBuilder.build();
375 private static TableConfig createTableConfig(long input) {
376 boolean deprecated = (input & 3) != 0;
377 return new TableConfig(deprecated);
380 private static List<TableFeatureProperties> createTableFeaturesProperties(ByteBuf input, int length) {
381 List<TableFeatureProperties> properties = new ArrayList<>();
382 int tableFeaturesLength = length;
383 while (tableFeaturesLength > 0) {
384 TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder();
385 TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort());
386 builder.setType(type);
387 int propertyLength = input.readUnsignedShort();
388 int paddingRemainder = propertyLength % EncodeConstants.PADDING;
389 tableFeaturesLength -= propertyLength;
390 if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)
391 || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
392 InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder();
393 insBuilder.setInstructions(InstructionsDeserializer.createInstructionIds(input, propertyLength - COMMON_PROPERTY_LENGTH));
394 builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build());
395 } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)
396 || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) {
397 propertyLength -= COMMON_PROPERTY_LENGTH;
398 NextTableRelatedTableFeaturePropertyBuilder tableBuilder = new NextTableRelatedTableFeaturePropertyBuilder();
399 List<NextTableIds> ids = new ArrayList<>();
400 while (propertyLength > 0) {
401 NextTableIdsBuilder nextTableIdsBuilder = new NextTableIdsBuilder();
402 nextTableIdsBuilder.setTableId(input.readUnsignedByte());
403 ids.add(nextTableIdsBuilder.build());
406 tableBuilder.setNextTableIds(ids);
407 builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, tableBuilder.build());
408 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)
409 || type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)
410 || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)
411 || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) {
412 ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder();
413 actionBuilder.setActionsList(ActionsDeserializer.createActionIds(input, propertyLength - COMMON_PROPERTY_LENGTH));
414 builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build());
415 } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)
416 || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)
417 || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)
418 || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)
419 || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)
420 || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
421 OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder();
422 oxmBuilder.setMatchEntries(MatchDeserializer.createMatchIds(input, propertyLength - COMMON_PROPERTY_LENGTH));
423 builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());
424 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)
425 || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
426 ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = new ExperimenterRelatedTableFeaturePropertyBuilder();
427 expBuilder.setExperimenter(input.readUnsignedInt());
428 expBuilder.setExpType(input.readUnsignedInt());
430 if (paddingRemainder != 0) {
431 input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
432 tableFeaturesLength -= EncodeConstants.PADDING - paddingRemainder;
434 properties.add(builder.build());
439 private static MultipartReplyPortStatsCase setPortStats(ByteBuf input) {
440 MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder();
441 MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder();
442 List<PortStats> portStatsList = new ArrayList<>();
443 while (input.readableBytes() > 0) {
444 PortStatsBuilder portStatsBuilder = new PortStatsBuilder();
445 portStatsBuilder.setPortNo(input.readUnsignedInt());
446 input.skipBytes(PADDING_IN_PORT_STATS_HEADER);
447 byte[] rxPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
448 input.readBytes(rxPackets);
449 portStatsBuilder.setRxPackets(new BigInteger(1, rxPackets));
450 byte[] txPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
451 input.readBytes(txPackets);
452 portStatsBuilder.setTxPackets(new BigInteger(1, txPackets));
453 byte[] rxBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
454 input.readBytes(rxBytes);
455 portStatsBuilder.setRxBytes(new BigInteger(1, rxBytes));
456 byte[] txBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
457 input.readBytes(txBytes);
458 portStatsBuilder.setTxBytes(new BigInteger(1, txBytes));
459 byte[] rxDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
460 input.readBytes(rxDropped);
461 portStatsBuilder.setRxDropped(new BigInteger(1, rxDropped));
462 byte[] txDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
463 input.readBytes(txDropped);
464 portStatsBuilder.setTxDropped(new BigInteger(1, txDropped));
465 byte[] rxErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
466 input.readBytes(rxErrors);
467 portStatsBuilder.setRxErrors(new BigInteger(1, rxErrors));
468 byte[] txErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
469 input.readBytes(txErrors);
470 portStatsBuilder.setTxErrors(new BigInteger(1, txErrors));
471 byte[] rxFrameErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
472 input.readBytes(rxFrameErr);
473 portStatsBuilder.setRxFrameErr(new BigInteger(1, rxFrameErr));
474 byte[] rxOverErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
475 input.readBytes(rxOverErr);
476 portStatsBuilder.setRxOverErr(new BigInteger(1, rxOverErr));
477 byte[] rxCrcErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
478 input.readBytes(rxCrcErr);
479 portStatsBuilder.setRxCrcErr(new BigInteger(1, rxCrcErr));
480 byte[] collisions = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
481 input.readBytes(collisions);
482 portStatsBuilder.setCollisions(new BigInteger(1, collisions));
483 portStatsBuilder.setDurationSec(input.readUnsignedInt());
484 portStatsBuilder.setDurationNsec(input.readUnsignedInt());
485 portStatsList.add(portStatsBuilder.build());
487 builder.setPortStats(portStatsList);
488 caseBuilder.setMultipartReplyPortStats(builder.build());
489 return caseBuilder.build();
492 private static MultipartReplyQueueCase setQueue(ByteBuf input) {
493 MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder();
494 MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder();
495 List<QueueStats> queueStatsList = new ArrayList<>();
496 while (input.readableBytes() > 0) {
497 QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();
498 queueStatsBuilder.setPortNo(input.readUnsignedInt());
499 queueStatsBuilder.setQueueId(input.readUnsignedInt());
500 byte[] txBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
501 input.readBytes(txBytes);
502 queueStatsBuilder.setTxBytes(new BigInteger(1, txBytes));
503 byte[] txPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
504 input.readBytes(txPackets);
505 queueStatsBuilder.setTxPackets(new BigInteger(1, txPackets));
506 byte[] txErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
507 input.readBytes(txErrors);
508 queueStatsBuilder.setTxErrors(new BigInteger(1, txErrors));
509 queueStatsBuilder.setDurationSec(input.readUnsignedInt());
510 queueStatsBuilder.setDurationNsec(input.readUnsignedInt());
511 queueStatsList.add(queueStatsBuilder.build());
513 builder.setQueueStats(queueStatsList);
514 caseBuilder.setMultipartReplyQueue(builder.build());
515 return caseBuilder.build();
518 private static MultipartReplyGroupCase setGroup(ByteBuf input) {
519 MultipartReplyGroupCaseBuilder caseBuilder = new MultipartReplyGroupCaseBuilder();
520 MultipartReplyGroupBuilder builder = new MultipartReplyGroupBuilder();
521 List<GroupStats> groupStatsList = new ArrayList<>();
522 while (input.readableBytes() > 0) {
523 GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder();
524 int bodyLength = input.readUnsignedShort();
525 input.skipBytes(PADDING_IN_GROUP_HEADER_01);
526 groupStatsBuilder.setGroupId(new GroupId(input.readUnsignedInt()));
527 groupStatsBuilder.setRefCount(input.readUnsignedInt());
528 input.skipBytes(PADDING_IN_GROUP_HEADER_02);
529 byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
530 input.readBytes(packetCount);
531 groupStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
532 byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
533 input.readBytes(byteCount);
534 groupStatsBuilder.setByteCount(new BigInteger(1, byteCount));
535 groupStatsBuilder.setDurationSec(input.readUnsignedInt());
536 groupStatsBuilder.setDurationNsec(input.readUnsignedInt());
537 int actualLength = GROUP_BODY_LENGTH;
538 List<BucketStats> bucketStatsList = new ArrayList<>();
539 while (actualLength < bodyLength) {
540 BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();
541 byte[] packetCountBucket = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
542 input.readBytes(packetCountBucket);
543 bucketStatsBuilder.setPacketCount(new BigInteger(1, packetCountBucket));
544 byte[] byteCountBucket = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
545 input.readBytes(byteCountBucket);
546 bucketStatsBuilder.setByteCount(new BigInteger(1, byteCountBucket));
547 bucketStatsList.add(bucketStatsBuilder.build());
548 actualLength += BUCKET_COUNTER_LENGTH;
550 groupStatsBuilder.setBucketStats(bucketStatsList);
551 groupStatsList.add(groupStatsBuilder.build());
553 builder.setGroupStats(groupStatsList);
554 caseBuilder.setMultipartReplyGroup(builder.build());
555 return caseBuilder.build();
558 private static MultipartReplyMeterFeaturesCase setMeterFeatures(ByteBuf input) {
559 MultipartReplyMeterFeaturesCaseBuilder caseBuilder = new MultipartReplyMeterFeaturesCaseBuilder();
560 MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder();
561 builder.setMaxMeter(input.readUnsignedInt());
562 builder.setBandTypes(createMeterBandsBitmap(input.readUnsignedInt()));
563 builder.setCapabilities(createMeterFlags(input.readUnsignedInt()));
564 builder.setMaxBands(input.readUnsignedByte());
565 builder.setMaxColor(input.readUnsignedByte());
566 input.skipBytes(PADDING_IN_METER_FEATURES_HEADER);
567 caseBuilder.setMultipartReplyMeterFeatures(builder.build());
568 return caseBuilder.build();
571 private static MeterFlags createMeterFlags(long input){
572 final Boolean _oFPMFKBPS = (input & (1 << 0)) != 0;
573 final Boolean _oFPMFPKTPS = (input & (1 << 1)) != 0;
574 final Boolean _oFPMFBURST = (input & (1 << 2)) != 0;
575 final Boolean _oFPMFSTATS = (input & (1 << 3)) != 0;
576 return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS);
579 private static MeterBandTypeBitmap createMeterBandsBitmap(long input) {
580 final Boolean _oFPMBTDROP = (input & (1 << 0)) != 0;
581 final Boolean _oFPMBTDSCPREMARK = (input & (1 << 1)) != 0;
582 return new MeterBandTypeBitmap(_oFPMBTDROP, _oFPMBTDSCPREMARK);
585 private static MultipartReplyMeterCase setMeter(ByteBuf input) {
586 MultipartReplyMeterCaseBuilder caseBuilder = new MultipartReplyMeterCaseBuilder();
587 MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder();
588 List<MeterStats> meterStatsList = new ArrayList<>();
589 while (input.readableBytes() > 0) {
590 MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
591 meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
592 int meterStatsBodyLength = input.readUnsignedShort();
593 input.skipBytes(PADDING_IN_METER_STATS_HEADER);
594 meterStatsBuilder.setFlowCount(input.readUnsignedInt());
595 byte[] packetInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
596 input.readBytes(packetInCount);
597 meterStatsBuilder.setPacketInCount(new BigInteger(1, packetInCount));
598 byte[] byteInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
599 input.readBytes(byteInCount);
600 meterStatsBuilder.setByteInCount(new BigInteger(1, byteInCount));
601 meterStatsBuilder.setDurationSec(input.readUnsignedInt());
602 meterStatsBuilder.setDurationNsec(input.readUnsignedInt());
603 int actualLength = METER_BODY_LENGTH;
604 List<MeterBandStats> meterBandStatsList = new ArrayList<>();
605 while (actualLength < meterStatsBodyLength) {
606 MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
607 byte[] packetBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
608 input.readBytes(packetBandCount);
609 meterBandStatsBuilder.setPacketBandCount(new BigInteger(1, packetBandCount));
610 byte[] byteBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
611 input.readBytes(byteBandCount);
612 meterBandStatsBuilder.setByteBandCount(new BigInteger(1, byteBandCount));
613 meterBandStatsList.add(meterBandStatsBuilder.build());
614 actualLength += METER_BAND_STATS_LENGTH;
616 meterStatsBuilder.setMeterBandStats(meterBandStatsList);
617 meterStatsList.add(meterStatsBuilder.build());
619 builder.setMeterStats(meterStatsList);
620 caseBuilder.setMultipartReplyMeter(builder.build());
621 return caseBuilder.build();
624 private static MultipartReplyMeterConfigCase setMeterConfig(ByteBuf input) {
625 MultipartReplyMeterConfigCaseBuilder caseBuilder = new MultipartReplyMeterConfigCaseBuilder();
626 MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();
627 List<MeterConfig> meterConfigList = new ArrayList<>();
628 while (input.readableBytes() > 0) {
629 MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();
630 int meterConfigBodyLength = input.readUnsignedShort();
631 meterConfigBuilder.setFlags(createMeterFlags(input.readUnsignedShort()));
632 meterConfigBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
633 int actualLength = METER_CONFIG_LENGTH;
634 List<Bands> bandsList = new ArrayList<>();
635 while (actualLength < meterConfigBodyLength) {
636 BandsBuilder bandsBuilder = new BandsBuilder();
637 int bandType = input.readUnsignedShort();
640 MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
641 MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
642 bandDropBuilder.setType(MeterBandType.forValue(bandType));
643 actualLength += input.readUnsignedShort();
644 bandDropBuilder.setRate(input.readUnsignedInt());
645 bandDropBuilder.setBurstSize(input.readUnsignedInt());
646 input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
647 bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build());
648 bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
651 MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
652 MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
653 bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
654 actualLength += input.readUnsignedShort();
655 bandDscpRemarkBuilder.setRate(input.readUnsignedInt());
656 bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt());
657 bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte());
658 input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
659 bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
660 bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
663 MeterBandExperimenterCaseBuilder bandExperimenterCaseBuilder = new MeterBandExperimenterCaseBuilder();
664 MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder();
665 bandExperimenterBuilder.setType(MeterBandType.forValue(bandType));
666 actualLength += input.readUnsignedShort();
667 bandExperimenterBuilder.setRate(input.readUnsignedInt());
668 bandExperimenterBuilder.setBurstSize(input.readUnsignedInt());
669 bandExperimenterBuilder.setExperimenter(input.readUnsignedInt());
670 bandExperimenterCaseBuilder.setMeterBandExperimenter(bandExperimenterBuilder.build());
671 bandsBuilder.setMeterBand(bandExperimenterCaseBuilder.build());
676 bandsList.add(bandsBuilder.build());
678 meterConfigBuilder.setBands(bandsList);
679 meterConfigList.add(meterConfigBuilder.build());
681 builder.setMeterConfig(meterConfigList);
682 caseBuilder.setMultipartReplyMeterConfig(builder.build());
683 return caseBuilder.build();
686 private static MultipartReplyExperimenterCase setExperimenter(ByteBuf input) {
687 MultipartReplyExperimenterCaseBuilder caseBuilder = new MultipartReplyExperimenterCaseBuilder();
688 MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder();
689 builder.setExperimenter(input.readUnsignedInt());
690 builder.setExpType(input.readUnsignedInt());
691 byte[] data = new byte[input.readableBytes()];
692 input.readBytes(data);
693 builder.setData(data);
694 caseBuilder.setMultipartReplyExperimenter(builder.build());
695 return caseBuilder.build();
698 private static MultipartReplyPortDescCase setPortDesc(ByteBuf input) {
699 MultipartReplyPortDescCaseBuilder caseBuilder = new MultipartReplyPortDescCaseBuilder();
700 MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder();
701 List<Ports> portsList = new ArrayList<>();
702 while (input.readableBytes() > 0) {
703 PortsBuilder portsBuilder = new PortsBuilder();
704 portsBuilder.setPortNo(input.readUnsignedInt());
705 input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01);
706 byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
707 input.readBytes(hwAddress);
708 portsBuilder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(hwAddress)));
709 input.skipBytes(PADDING_IN_PORT_DESC_HEADER_02);
710 portsBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, EncodeConstants.MAX_PORT_NAME_LENGTH));
711 portsBuilder.setConfig(createPortConfig(input.readUnsignedInt()));
712 portsBuilder.setState(createPortState(input.readUnsignedInt()));
713 portsBuilder.setCurrentFeatures(createPortFeatures(input.readUnsignedInt()));
714 portsBuilder.setAdvertisedFeatures(createPortFeatures(input.readUnsignedInt()));
715 portsBuilder.setSupportedFeatures(createPortFeatures(input.readUnsignedInt()));
716 portsBuilder.setPeerFeatures(createPortFeatures(input.readUnsignedInt()));
717 portsBuilder.setCurrSpeed(input.readUnsignedInt());
718 portsBuilder.setMaxSpeed(input.readUnsignedInt());
719 portsList.add(portsBuilder.build());
721 builder.setPorts(portsList);
722 caseBuilder.setMultipartReplyPortDesc(builder.build());
723 return caseBuilder.build();
726 private static PortConfig createPortConfig(long input){
727 final Boolean _portDown = ((input) & (1<<0)) != 0;
728 final Boolean _noRecv = ((input) & (1<<2)) != 0;
729 final Boolean _noFwd = ((input) & (1<<5)) != 0;
730 final Boolean _noPacketIn = ((input) & (1<<6)) != 0;
731 return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown);
734 private static PortState createPortState(long input){
735 final Boolean _linkDown = ((input) & (1<<0)) != 0;
736 final Boolean _blocked = ((input) & (1<<1)) != 0;
737 final Boolean _live = ((input) & (1<<2)) != 0;
738 return new PortState(_blocked, _linkDown, _live);
741 private static PortFeatures createPortFeatures(long input){
742 final Boolean _10mbHd = ((input) & (1<<0)) != 0;
743 final Boolean _10mbFd = ((input) & (1<<1)) != 0;
744 final Boolean _100mbHd = ((input) & (1<<2)) != 0;
745 final Boolean _100mbFd = ((input) & (1<<3)) != 0;
746 final Boolean _1gbHd = ((input) & (1<<4)) != 0;
747 final Boolean _1gbFd = ((input) & (1<<5)) != 0;
748 final Boolean _10gbFd = ((input) & (1<<6)) != 0;
749 final Boolean _40gbFd = ((input) & (1<<7)) != 0;
750 final Boolean _100gbFd = ((input) & (1<<8)) != 0;
751 final Boolean _1tbFd = ((input) & (1<<9)) != 0;
752 final Boolean _other = ((input) & (1<<10)) != 0;
753 final Boolean _copper = ((input) & (1<<11)) != 0;
754 final Boolean _fiber = ((input) & (1<<12)) != 0;
755 final Boolean _autoneg = ((input) & (1<<13)) != 0;
756 final Boolean _pause = ((input) & (1<<14)) != 0;
757 final Boolean _pauseAsym = ((input) & (1<<15)) != 0;
758 return new PortFeatures(_100gbFd, _100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, _1gbFd,
759 _1gbHd, _1tbFd, _40gbFd, _autoneg, _copper, _fiber, _other, _pause, _pauseAsym);
762 private static MultipartReplyGroupFeaturesCase setGroupFeatures(ByteBuf rawMessage) {
763 MultipartReplyGroupFeaturesCaseBuilder caseBuilder = new MultipartReplyGroupFeaturesCaseBuilder();
764 MultipartReplyGroupFeaturesBuilder featuresBuilder = new MultipartReplyGroupFeaturesBuilder();
765 featuresBuilder.setTypes(createGroupType(rawMessage.readUnsignedInt()));
766 featuresBuilder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
767 List<Long> maxGroupsList = new ArrayList<>();
768 for (int i = 0; i < GROUP_TYPES ; i++) {
769 maxGroupsList.add(rawMessage.readUnsignedInt());
771 featuresBuilder.setMaxGroups(maxGroupsList);
772 List<ActionType> actionBitmaps = new ArrayList<>();
773 for (int i = 0; i < GROUP_TYPES ; i++) {
774 actionBitmaps.add(createActionBitmap(rawMessage.readUnsignedInt()));
776 featuresBuilder.setActionsBitmap(actionBitmaps);
777 caseBuilder.setMultipartReplyGroupFeatures(featuresBuilder.build());
778 return caseBuilder.build();
781 private static ActionType createActionBitmap(long input) {
782 final Boolean OFPAT_OUTPUT = ((input) & (1<<0)) != 0;
783 final Boolean OFPAT_COPY_TTL_OUT = ((input) & (1<<1)) != 0;
784 final Boolean OFPAT_COPY_TTL_IN = ((input) & (1<<2)) != 0;
785 final Boolean OFPAT_SET_MPLS_TTL = ((input) & (1<<3)) != 0;
786 final Boolean OFPAT_DEC_MPLS_TTL = ((input) & (1<<4)) != 0;
787 final Boolean OFPAT_PUSH_VLAN = ((input) & (1<<5)) != 0;
788 final Boolean OFPAT_POP_VLAN = ((input) & (1<<6)) != 0;
789 final Boolean OFPAT_PUSH_MPLS = ((input) & (1<<7)) != 0;
790 final Boolean OFPAT_POP_MPLS = ((input) & (1<<8)) != 0;
791 final Boolean OFPAT_SET_QUEUE = ((input) & (1<<9)) != 0;
792 final Boolean OFPAT_GROUP = ((input) & (1<<10)) != 0;
793 final Boolean OFPAT_SET_NW_TTL = ((input) & (1<<11)) != 0;
794 final Boolean OFPAT_DEC_NW_TTL = ((input) & (1<<12)) != 0;
795 final Boolean OFPAT_SET_FIELD = ((input) & (1<<13)) != 0;
796 final Boolean OFPAT_PUSH_PBB = ((input) & (1<<14)) != 0;
797 final Boolean OFPAT_POP_PBB = ((input) & (1<<15)) != 0;
798 final Boolean OFPAT_EXPERIMENTER = ((input) & (1<<16)) != 0;
799 return new ActionType(OFPAT_COPY_TTL_IN, OFPAT_COPY_TTL_OUT, OFPAT_DEC_MPLS_TTL,
800 OFPAT_DEC_NW_TTL, OFPAT_EXPERIMENTER, OFPAT_GROUP, OFPAT_OUTPUT, OFPAT_POP_MPLS,
801 OFPAT_POP_PBB, OFPAT_POP_VLAN, OFPAT_PUSH_MPLS, OFPAT_PUSH_PBB, OFPAT_PUSH_VLAN,
802 OFPAT_SET_FIELD, OFPAT_SET_MPLS_TTL, OFPAT_SET_NW_TTL, OFPAT_SET_QUEUE);
805 private static GroupCapabilities createCapabilities(long input) {
806 final Boolean OFOFPGFC_SELECT_WEIGHT = ((input) & (1<<0)) != 0;
807 final Boolean OFPGFC_SELECT_LIVENESS = ((input) & (1<<1)) != 0;
808 final Boolean OFPGFC_CHAINING = ((input) & (1<<2)) != 0;
809 final Boolean OFPGFC_CHAINING_CHECKS = ((input) & (1<<3)) != 0;
810 return new GroupCapabilities(OFPGFC_CHAINING, OFPGFC_CHAINING_CHECKS, OFPGFC_SELECT_LIVENESS, OFOFPGFC_SELECT_WEIGHT);
813 private static GroupTypes createGroupType(long input) {
814 final Boolean OFPGT_ALL = ((input) & (1<<0)) != 0;
815 final Boolean OFPGT_SELECT = ((input) & (1<<1)) != 0;
816 final Boolean OFPGT_INDIRECT = ((input) & (1<<2)) != 0;
817 final Boolean OFPGT_FF = ((input) & (1<<3)) != 0;
818 return new GroupTypes(OFPGT_ALL, OFPGT_FF, OFPGT_INDIRECT, OFPGT_SELECT);
821 private static MultipartReplyGroupDescCase setGroupDesc(ByteBuf input) {
822 MultipartReplyGroupDescCaseBuilder caseBuilder = new MultipartReplyGroupDescCaseBuilder();
823 MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
824 List<GroupDesc> groupDescsList = new ArrayList<>();
825 while (input.readableBytes() > 0) {
826 GroupDescBuilder groupDescBuilder = new GroupDescBuilder();
827 int bodyLength = input.readUnsignedShort();
828 groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte()));
829 input.skipBytes(PADDING_IN_GROUP_DESC_HEADER);
830 groupDescBuilder.setGroupId(new GroupId(input.readUnsignedInt()));
831 int actualLength = GROUP_DESC_HEADER_LENGTH;
832 List<BucketsList> bucketsList = new ArrayList<>();
833 while (actualLength < bodyLength) {
834 BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
835 int bucketsLength = input.readUnsignedShort();
836 bucketsBuilder.setWeight(input.readUnsignedShort());
837 bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));
838 bucketsBuilder.setWatchGroup(input.readUnsignedInt());
839 input.skipBytes(PADDING_IN_BUCKETS_HEADER);
840 List<ActionsList> actionsList = ActionsDeserializer
841 .createActionsList(input, bucketsLength - BUCKETS_HEADER_LENGTH);
842 bucketsBuilder.setActionsList(actionsList);
843 bucketsList.add(bucketsBuilder.build());
844 actualLength += bucketsLength;
846 groupDescBuilder.setBucketsList(bucketsList);
847 groupDescsList.add(groupDescBuilder.build());
849 builder.setGroupDesc(groupDescsList);
850 caseBuilder.setMultipartReplyGroupDesc(builder.build());
851 return caseBuilder.build();