1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
6 import java.util.HashMap;
\r
7 import java.util.List;
\r
8 import java.util.Map;
\r
10 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
\r
11 import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;
\r
12 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
\r
13 import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer;
\r
14 import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroup;
\r
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeter;
\r
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfig;
\r
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats;
\r
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue;
\r
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeatures;
\r
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeatures;
\r
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties;
\r
43 * @author timotej.kubas
\r
44 * @author michal.polkorab
\r
46 public class MultipartRequestMessageFactory implements OFSerializer<MultipartRequestMessage> {
\r
47 private static final byte MESSAGE_TYPE = 18;
\r
48 private static final int MESSAGE_LENGTH = 16;
\r
49 private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4;
\r
50 private static final byte TABLE_FEAT_HEADER_LENGTH = 4;
\r
51 private static MultipartRequestMessageFactory instance;
\r
53 private MultipartRequestMessageFactory() {
\r
58 * @return singleton factory
\r
60 public static synchronized MultipartRequestMessageFactory getInstance() {
\r
61 if (instance == null) {
\r
62 instance = new MultipartRequestMessageFactory();
\r
68 public void messageToBuffer(short version, ByteBuf out,
\r
69 MultipartRequestMessage message) {
\r
70 ByteBufUtils.writeOFHeader(instance, message, out);
\r
71 out.writeShort(message.getType().getIntValue());
\r
72 out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
\r
73 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out);
\r
75 if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) {
\r
76 encodeFlowBody(message.getMultipartRequestBody(), out);
\r
77 } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) {
\r
78 encodeAggregateBody(message.getMultipartRequestBody(), out);
\r
79 } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStats) {
\r
80 encodePortStatsBody(message.getMultipartRequestBody(), out);
\r
81 } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueue) {
\r
82 encodeQueueBody(message.getMultipartRequestBody(), out);
\r
83 } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroup) {
\r
84 encodeGroupStatsBody(message.getMultipartRequestBody(), out);
\r
85 } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeter) {
\r
86 encodeMeterBody(message.getMultipartRequestBody(), out);
\r
87 } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfig) {
\r
88 encodeMeterConfigBody(message.getMultipartRequestBody(), out);
\r
89 } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeatures) {
\r
90 encodeTableFeaturesBody(message.getMultipartRequestBody(), out);
\r
91 } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenter) {
\r
92 encodeExperimenterBody(message.getMultipartRequestBody(), out);
\r
97 public int computeLength(MultipartRequestMessage message) {
\r
98 return MESSAGE_LENGTH + computeBodyLength(message);
\r
101 public byte getMessageType() {
\r
102 return MESSAGE_TYPE;
\r
108 * @return length of MultipartRequestMessage
\r
110 public int computeBodyLength(MultipartRequestMessage message) {
\r
112 MultipartType type = message.getType();
\r
113 if (type.equals(MultipartType.OFPMPFLOW)) {
\r
114 final byte FLOW_BODY_LENGTH = 32;
\r
115 MultipartRequestFlow body = (MultipartRequestFlow) message.getMultipartRequestBody();
\r
116 length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
\r
117 } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {
\r
118 final byte AGGREGATE_BODY_LENGTH = 32;
\r
119 MultipartRequestAggregate body = (MultipartRequestAggregate) message.getMultipartRequestBody();
\r
120 length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
\r
121 } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {
\r
122 final byte PORT_STATS_BODY_LENGTH = 8;
\r
123 length += PORT_STATS_BODY_LENGTH;
\r
124 } else if (type.equals(MultipartType.OFPMPQUEUE)) {
\r
125 final byte QUEUE_BODY_LENGTH = 8;
\r
126 length += QUEUE_BODY_LENGTH;
\r
127 } else if (type.equals(MultipartType.OFPMPGROUP)) {
\r
128 final byte GROUP_BODY_LENGTH = 8;
\r
129 length += GROUP_BODY_LENGTH;
\r
130 } else if (type.equals(MultipartType.OFPMPMETER)) {
\r
131 final byte METER_BODY_LENGTH = 8;
\r
132 length += METER_BODY_LENGTH;
\r
133 } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) {
\r
134 final byte METER_CONFIG_BODY_LENGTH = 8;
\r
135 length += METER_CONFIG_BODY_LENGTH;
\r
136 } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) {
\r
137 MultipartRequestTableFeatures body = (MultipartRequestTableFeatures) message.getMultipartRequestBody();
\r
138 length += computeTableFeaturesLength(body);
\r
139 } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {
\r
140 final byte EXPERIMENTER_BODY_LENGTH = 8;
\r
141 MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody();
\r
142 length += EXPERIMENTER_BODY_LENGTH;
\r
143 if (body.getData() != null) {
\r
144 length += body.getData().length;
\r
150 private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {
\r
151 final byte TABLE_FEATURES_LENGTH = 64;
\r
152 final byte STRUCTURE_HEADER_LENGTH = 4;
\r
154 if (body != null) {
\r
155 List<TableFeatures> tableFeatures = body.getTableFeatures();
\r
156 for (TableFeatures feature : tableFeatures) {
\r
157 length += TABLE_FEATURES_LENGTH;
\r
158 List<TableFeatureProperties> featureProperties = feature.getTableFeatureProperties();
\r
159 if (featureProperties != null) {
\r
160 for (TableFeatureProperties featProp : featureProperties) {
\r
161 length += TABLE_FEAT_HEADER_LENGTH;
\r
162 if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) {
\r
163 InstructionRelatedTableFeatureProperty property =
\r
164 featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class);
\r
165 length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH;
\r
166 } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) {
\r
167 NextTableRelatedTableFeatureProperty property =
\r
168 featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class);
\r
169 length += property.getNextTableIds().size();
\r
170 } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) {
\r
171 ActionRelatedTableFeatureProperty property =
\r
172 featProp.getAugmentation(ActionRelatedTableFeatureProperty.class);
\r
173 length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH;
\r
174 } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) {
\r
175 OxmRelatedTableFeatureProperty property =
\r
176 featProp.getAugmentation(OxmRelatedTableFeatureProperty.class);
\r
177 length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH;
\r
178 } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) {
\r
179 ExperimenterRelatedTableFeatureProperty property =
\r
180 featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class);
\r
181 length += 2 * (Integer.SIZE / Byte.SIZE);
\r
182 if (property.getData() != null) {
\r
183 length += property.getData().length;
\r
193 private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {
\r
194 int multipartRequestFlagsBitmask = 0;
\r
195 Map<Integer, Boolean> multipartRequestFlagsMap = new HashMap<>();
\r
196 multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE());
\r
198 multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap);
\r
199 return multipartRequestFlagsBitmask;
\r
202 private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
203 final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
\r
204 final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
\r
205 MultipartRequestFlow flow = (MultipartRequestFlow) multipartRequestBody;
\r
206 output.writeByte(flow.getTableId().byteValue());
\r
207 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01, output);
\r
208 output.writeInt(flow.getOutPort().intValue());
\r
209 output.writeInt(flow.getOutGroup().intValue());
\r
210 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02, output);
\r
211 output.writeLong(flow.getCookie().longValue());
\r
212 output.writeLong(flow.getCookieMask().longValue());
\r
213 MatchSerializer.encodeMatch(flow.getMatch(), output);
\r
216 private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
217 final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01 = 3;
\r
218 final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02 = 4;
\r
219 MultipartRequestAggregate aggregate = (MultipartRequestAggregate) multipartRequestBody;
\r
220 output.writeByte(aggregate.getTableId().byteValue());
\r
221 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01, output);
\r
222 output.writeInt(aggregate.getOutPort().intValue());
\r
223 output.writeInt(aggregate.getOutGroup().intValue());
\r
224 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02, output);
\r
225 output.writeLong(aggregate.getCookie().longValue());
\r
226 output.writeLong(aggregate.getCookieMask().longValue());
\r
227 MatchSerializer.encodeMatch(aggregate.getMatch(), output);
\r
230 private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
231 final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
\r
232 MultipartRequestPortStats portstats = (MultipartRequestPortStats) multipartRequestBody;
\r
233 output.writeInt(portstats.getPortNo().intValue());
\r
234 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output);
\r
237 private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
238 MultipartRequestQueue queue = (MultipartRequestQueue) multipartRequestBody;
\r
239 output.writeInt(queue.getPortNo().intValue());
\r
240 output.writeInt(queue.getQueueId().intValue());
\r
243 private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
244 final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4;
\r
245 MultipartRequestGroup groupStats = (MultipartRequestGroup) multipartRequestBody;
\r
246 output.writeInt(groupStats.getGroupId().intValue());
\r
247 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output);
\r
250 private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
251 final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4;
\r
252 MultipartRequestMeter meter = (MultipartRequestMeter) multipartRequestBody;
\r
253 output.writeInt(meter.getMeterId().intValue());
\r
254 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output);
\r
257 private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
258 final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4;
\r
259 MultipartRequestMeterConfig meterConfig = (MultipartRequestMeterConfig) multipartRequestBody;
\r
260 output.writeInt(meterConfig.getMeterId().intValue());
\r
261 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output);
\r
264 private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
265 MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody;
\r
266 output.writeInt(experimenter.getExperimenter().intValue());
\r
267 output.writeInt(experimenter.getExpType().intValue());
\r
268 byte[] data = experimenter.getData();
\r
269 if (data != null) {
\r
270 output.writeBytes(data);
\r
274 private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
\r
275 if (multipartRequestBody != null) {
\r
276 MultipartRequestTableFeatures tableFeatures = (MultipartRequestTableFeatures) multipartRequestBody;
\r
277 for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) {
\r
278 final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5;
\r
279 output.writeByte(currTableFeature.getTableId());
\r
280 ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output);
\r
281 output.writeBytes(currTableFeature.getName().getBytes());
\r
282 ByteBufUtils.padBuffer((32 - currTableFeature.getName().getBytes().length), output);
\r
283 output.writeLong(currTableFeature.getMetadataMatch().longValue());
\r
284 output.writeLong(currTableFeature.getMetadataWrite().longValue());
\r
285 output.writeInt(createTableConfigBitmask(currTableFeature.getConfig()));
\r
286 output.writeInt(currTableFeature.getMaxEntries().intValue());
\r
287 writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties());
\r
292 private static void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
\r
293 if (props != null) {
\r
294 for (TableFeatureProperties property : props) {
\r
295 TableFeaturesPropType type = property.getType();
\r
296 if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)) {
\r
297 final byte INSTRUCTIONS_CODE = 0;
\r
298 writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_CODE);
\r
299 } else if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
\r
300 final byte INSTRUCTIONS_MISS_CODE = 1;
\r
301 writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_MISS_CODE);
\r
302 } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)) {
\r
303 final byte NEXT_TABLE_CODE = 2;
\r
304 writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_CODE);
\r
305 } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) {
\r
306 final byte NEXT_TABLE_MISS_CODE = 3;
\r
307 writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_MISS_CODE);
\r
308 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)) {
\r
309 final byte WRITE_ACTIONS_CODE = 4;
\r
310 writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_CODE);
\r
311 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)) {
\r
312 final byte WRITE_ACTIONS_MISS_CODE = 5;
\r
313 writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_MISS_CODE);
\r
314 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)) {
\r
315 final byte APPLY_ACTIONS_CODE = 6;
\r
316 writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_CODE);
\r
317 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) {
\r
318 final byte APPLY_ACTIONS_MISS_CODE = 7;
\r
319 writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_MISS_CODE);
\r
320 } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)) {
\r
321 final byte MATCH_CODE = 8;
\r
322 writeOxmRelatedTableProperty(output, property, MATCH_CODE);
\r
323 } else if (type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)) {
\r
324 final byte WILDCARDS_CODE = 10;
\r
325 writeOxmRelatedTableProperty(output, property, WILDCARDS_CODE);
\r
326 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)) {
\r
327 final byte WRITE_SETFIELD_CODE = 12;
\r
328 writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_CODE);
\r
329 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)) {
\r
330 final byte WRITE_SETFIELD_MISS_CODE = 13;
\r
331 writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_MISS_CODE);
\r
332 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)) {
\r
333 final byte APPLY_SETFIELD_CODE = 14;
\r
334 writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_CODE);
\r
335 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
\r
336 final byte APPLY_SETFIELD_MISS_CODE = 15;
\r
337 writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_MISS_CODE);
\r
338 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) {
\r
339 final int EXPERIMENTER_CODE = 65534; // 0xFFFE
\r
340 writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_CODE);
\r
341 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
\r
342 final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF
\r
343 writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_MISS_CODE);
\r
349 private static void writeInstructionRelatedTableProperty(ByteBuf output,
\r
350 TableFeatureProperties property, byte code) {
\r
351 output.writeShort(code);
\r
352 List<Instructions> instructions = property.
\r
353 getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstructions();
\r
354 int length = TABLE_FEAT_HEADER_LENGTH;
\r
355 if (instructions != null) {
\r
356 output.writeShort(InstructionsSerializer.computeInstructionsLength(instructions)
\r
357 + TABLE_FEAT_HEADER_LENGTH);
\r
358 InstructionsSerializer.encodeInstructions(instructions, output);
\r
360 output.writeShort(length);
\r
364 private static void writeNextTableRelatedTableProperty(ByteBuf output,
\r
365 TableFeatureProperties property, byte code) {
\r
366 output.writeShort(code);
\r
367 List<NextTableIds> nextTableIds = property.
\r
368 getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds();
\r
369 int length = TABLE_FEAT_HEADER_LENGTH;
\r
370 if (nextTableIds != null) {
\r
371 output.writeShort(length + nextTableIds.size());
\r
372 for (NextTableIds next : nextTableIds) {
\r
373 output.writeByte(next.getTableId());
\r
376 output.writeShort(length);
\r
380 private static void writeActionsRelatedTableProperty(ByteBuf output,
\r
381 TableFeatureProperties property, byte code) {
\r
382 output.writeShort(code);
\r
383 List<ActionsList> actions = property.
\r
384 getAugmentation(ActionRelatedTableFeatureProperty.class).getActionsList();
\r
385 int length = TABLE_FEAT_HEADER_LENGTH;
\r
386 if (actions != null) {
\r
387 output.writeShort(ActionsSerializer.computeLengthOfActions(actions)
\r
388 + TABLE_FEAT_HEADER_LENGTH);
\r
389 ActionsSerializer.encodeActions(actions, output);
\r
391 output.writeShort(length);
\r
395 private static void writeOxmRelatedTableProperty(ByteBuf output,
\r
396 TableFeatureProperties property, byte code) {
\r
397 output.writeShort(code);
\r
398 List<MatchEntries> entries = property.
\r
399 getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntries();
\r
400 int length = TABLE_FEAT_HEADER_LENGTH;
\r
401 if (entries != null) {
\r
402 output.writeShort(MatchSerializer.computeMatchEntriesLength(entries)
\r
403 + TABLE_FEAT_HEADER_LENGTH);
\r
404 MatchSerializer.encodeMatchEntries(entries, output);
\r
406 output.writeShort(length);
\r
410 private static void writeExperimenterRelatedTableProperty(ByteBuf output,
\r
411 TableFeatureProperties property, int code) {
\r
412 output.writeShort(code);
\r
413 ExperimenterRelatedTableFeatureProperty exp = property.
\r
414 getAugmentation(ExperimenterRelatedTableFeatureProperty.class);
\r
415 byte[] data = exp.getData();
\r
416 int length = TABLE_FEAT_HEADER_LENGTH + 2 * (Integer.SIZE / Byte.SIZE);
\r
417 if (data != null) {
\r
418 output.writeShort(length + data.length);
\r
419 output.writeInt(exp.getExperimenter().intValue());
\r
420 output.writeInt(exp.getExpType().intValue());
\r
421 output.writeBytes(data);
\r
423 output.writeShort(length);
\r
424 output.writeInt(exp.getExperimenter().intValue());
\r
425 output.writeInt(exp.getExpType().intValue());
\r
429 private static int createTableConfigBitmask(TableConfig tableConfig) {
\r
430 int tableConfigBitmask = 0;
\r
431 Map<Integer, Boolean> tableConfigMap = new HashMap<>();
\r
432 tableConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK());
\r
434 tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap);
\r
435 return tableConfigBitmask;
\r