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.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import java.nio.charset.StandardCharsets;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
20 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMaker;
21 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
22 import org.opendaylight.openflowjava.util.ByteBufUtils;
23 import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeatureProperty;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdTableFeatureProperty;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeatureProperty;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmRelatedTableFeatureProperty;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIds;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortDescCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregate;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroup;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeter;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfig;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStats;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueue;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeatures;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
68 * Translates MultipartRequest messages.
70 * @author timotej.kubas
71 * @author michal.polkorab
73 public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput>, SerializerRegistryInjector {
74 private static final byte MESSAGE_TYPE = 18;
75 private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4;
76 private static final byte INSTRUCTIONS_CODE = 0;
77 private static final byte INSTRUCTIONS_MISS_CODE = 1;
78 private static final byte NEXT_TABLE_CODE = 2;
79 private static final byte NEXT_TABLE_MISS_CODE = 3;
80 private static final byte WRITE_ACTIONS_CODE = 4;
81 private static final byte WRITE_ACTIONS_MISS_CODE = 5;
82 private static final byte APPLY_ACTIONS_CODE = 6;
83 private static final byte APPLY_ACTIONS_MISS_CODE = 7;
84 private static final byte MATCH_CODE = 8;
85 private static final byte WILDCARDS_CODE = 10;
86 private static final byte WRITE_SETFIELD_CODE = 12;
87 private static final byte WRITE_SETFIELD_MISS_CODE = 13;
88 private static final byte APPLY_SETFIELD_CODE = 14;
89 private static final byte APPLY_SETFIELD_MISS_CODE = 15;
90 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
91 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
92 private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01 = 3;
93 private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02 = 4;
94 private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
95 private static final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4;
96 private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4;
97 private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4;
98 private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5;
99 private SerializerRegistry registry;
102 public void serialize(final MultipartRequestInput message, final ByteBuf outBuffer) {
103 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
104 outBuffer.writeShort(message.getType().getIntValue());
105 outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
106 outBuffer.writeZero(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
108 if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase) {
110 } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
111 serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
112 } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
113 serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
114 } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
115 serializeTableBody();
116 } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
117 serializePortStatsBody(message.getMultipartRequestBody(), outBuffer);
118 } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
119 serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
120 } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupCase) {
121 serializeeGroupStatsBody(message.getMultipartRequestBody(), outBuffer);
122 } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDescCase) {
123 serializeGroupDescBody();
124 } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeaturesCase) {
125 serializeGroupFeaturesBody();
126 } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterCase) {
127 serializeMeterBody(message.getMultipartRequestBody(), outBuffer);
128 } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfigCase) {
129 serializeMeterConfigBody(message.getMultipartRequestBody(), outBuffer);
130 } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeaturesCase) {
131 serializeMeterFeaturesBody();
132 } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeaturesCase) {
133 serializeTableFeaturesBody(message.getMultipartRequestBody(), outBuffer);
134 } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDescCase) {
135 serializePortDescBody();
136 } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
137 serializeExperimenterBody(message, outBuffer);
139 ByteBufUtils.updateOFHeaderLength(outBuffer);
142 private void serializeExperimenterBody(final MultipartRequestInput message,
143 final ByteBuf outBuffer) {
144 MultipartRequestExperimenterCase expCase =
145 (MultipartRequestExperimenterCase) message.getMultipartRequestBody();
146 MultipartRequestExperimenter experimenter = expCase.getMultipartRequestExperimenter();
147 final long expId = experimenter.getExperimenter().getValue().longValue();
148 final long expType = experimenter.getExpType().longValue();
150 // write experimenterId and type
151 outBuffer.writeInt((int) expId);
152 outBuffer.writeInt((int) expType);
154 // serialize experimenter data
155 OFSerializer<ExperimenterDataOfChoice> serializer = registry.getSerializer(
156 ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey(
157 EncodeConstants.OF13_VERSION_ID, expId, expType));
158 serializer.serialize(experimenter.getExperimenterDataOfChoice(), outBuffer);
161 private static int createMultipartRequestFlagsBitmask(final MultipartRequestFlags flags) {
162 return ByteBufUtils.fillBitMask(0, flags.isOFPMPFREQMORE());
165 private void serializeDescBody() {
166 // The body of MultiPartRequestDesc is empty
169 private void serializeTableBody() {
170 // The body of MultiPartTable is empty
173 private void serializeGroupDescBody() {
174 // The body of MultiPartRequestGroupDesc is empty
177 private void serializeGroupFeaturesBody() {
178 // The body of MultiPartRequestGroupFeatures is empty
181 private void serializeMeterFeaturesBody() {
182 // The body of MultiPartMeterFeatures is empty
185 private void serializePortDescBody() {
186 // The body of MultiPartPortDesc is empty
189 private void serializeFlowBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
190 MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
191 MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
192 output.writeByte(flow.getTableId().byteValue());
193 output.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
194 output.writeInt(flow.getOutPort().intValue());
195 output.writeInt(flow.getOutGroup().intValue());
196 output.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
197 output.writeLong(flow.getCookie().longValue());
198 output.writeLong(flow.getCookieMask().longValue());
199 OFSerializer<Match> serializer = registry.getSerializer(new MessageTypeKey<>(
200 EncodeConstants.OF13_VERSION_ID, Match.class));
201 serializer.serialize(flow.getMatch(), output);
204 private void serializeAggregateBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
205 MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody;
206 MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate();
207 output.writeByte(aggregate.getTableId().byteValue());
208 output.writeZero(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01);
209 output.writeInt(aggregate.getOutPort().intValue());
210 output.writeInt(aggregate.getOutGroup().intValue());
211 output.writeZero(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02);
212 output.writeLong(aggregate.getCookie().longValue());
213 output.writeLong(aggregate.getCookieMask().longValue());
214 OFSerializer<Match> serializer = registry.getSerializer(new MessageTypeKey<>(
215 EncodeConstants.OF13_VERSION_ID, Match.class));
216 serializer.serialize(aggregate.getMatch(), output);
219 private static void serializePortStatsBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
220 MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody;
221 MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats();
222 output.writeInt(portstats.getPortNo().intValue());
223 output.writeZero(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
226 private static void serializeQueueBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
227 MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody;
228 MultipartRequestQueue queue = queueCase.getMultipartRequestQueue();
229 output.writeInt(queue.getPortNo().intValue());
230 output.writeInt(queue.getQueueId().intValue());
233 private static void serializeeGroupStatsBody(final MultipartRequestBody multipartRequestBody,
234 final ByteBuf output) {
235 MultipartRequestGroupCase groupStatsCase = (MultipartRequestGroupCase) multipartRequestBody;
236 MultipartRequestGroup groupStats = groupStatsCase.getMultipartRequestGroup();
237 output.writeInt(groupStats.getGroupId().getValue().intValue());
238 output.writeZero(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY);
241 private static void serializeMeterBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
242 MultipartRequestMeterCase meterCase = (MultipartRequestMeterCase) multipartRequestBody;
243 MultipartRequestMeter meter = meterCase.getMultipartRequestMeter();
244 output.writeInt(meter.getMeterId().getValue().intValue());
245 output.writeZero(PADDING_IN_MULTIPART_REQUEST_METER_BODY);
248 private static void serializeMeterConfigBody(final MultipartRequestBody multipartRequestBody,
249 final ByteBuf output) {
250 MultipartRequestMeterConfigCase meterConfigCase = (MultipartRequestMeterConfigCase) multipartRequestBody;
251 MultipartRequestMeterConfig meterConfig = meterConfigCase.getMultipartRequestMeterConfig();
252 output.writeInt(meterConfig.getMeterId().getValue().intValue());
253 output.writeZero(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY);
256 private void serializeTableFeaturesBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
257 if (multipartRequestBody != null) {
258 MultipartRequestTableFeaturesCase tableFeaturesCase =
259 (MultipartRequestTableFeaturesCase)multipartRequestBody;
260 MultipartRequestTableFeatures tableFeatures = tableFeaturesCase.getMultipartRequestTableFeatures();
261 if (tableFeatures.getTableFeatures() != null) {
262 for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) {
263 final int tableFeatureLengthIndex = output.writerIndex();
264 output.writeShort(EncodeConstants.EMPTY_LENGTH);
265 output.writeByte(currTableFeature.getTableId());
266 output.writeZero(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY);
267 final byte[] nameBytes = currTableFeature.getName().getBytes(StandardCharsets.UTF_8);
268 output.writeBytes(nameBytes);
269 output.writeZero(32 - nameBytes.length);
270 output.writeLong(currTableFeature.getMetadataMatch().longValue());
271 output.writeLong(currTableFeature.getMetadataWrite().longValue());
272 output.writeInt(createTableConfigBitmask(currTableFeature.getConfig()));
273 output.writeInt(currTableFeature.getMaxEntries().intValue());
274 writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties());
275 output.setShort(tableFeatureLengthIndex, output.writerIndex() - tableFeatureLengthIndex);
281 private void writeTableFeatureProperties(final ByteBuf output, final List<TableFeatureProperties> props) {
283 for (TableFeatureProperties property : props) {
284 TableFeaturesPropType type = property.getType();
285 if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)) {
286 writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_CODE);
287 } else if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
288 writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_MISS_CODE);
289 } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)) {
290 writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_CODE);
291 } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) {
292 writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_MISS_CODE);
293 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)) {
294 writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_CODE);
295 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)) {
296 writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_MISS_CODE);
297 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)) {
298 writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_CODE);
299 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) {
300 writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_MISS_CODE);
301 } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)) {
302 writeOxmRelatedTableProperty(output, property, MATCH_CODE);
303 } else if (type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)) {
304 writeOxmRelatedTableProperty(output, property, WILDCARDS_CODE);
305 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)) {
306 writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_CODE);
307 } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)) {
308 writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_MISS_CODE);
309 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)) {
310 writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_CODE);
311 } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
312 writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_MISS_CODE);
313 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) {
314 writeExperimenterRelatedTableProperty(output, property);
315 } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
316 writeExperimenterRelatedTableProperty(output, property);
322 private void writeInstructionRelatedTableProperty(final ByteBuf output,
323 final TableFeatureProperties property, final byte code) {
324 final int startIndex = output.writerIndex();
325 output.writeShort(code);
326 int lengthIndex = output.writerIndex();
327 output.writeShort(EncodeConstants.EMPTY_LENGTH);
328 List<Instruction> instructions = property.augmentation(
329 InstructionRelatedTableFeatureProperty.class).getInstruction();
330 if (instructions != null) {
331 TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory
332 .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
333 ListSerializer.serializeHeaderList(instructions, keyMaker, registry, output);
335 int length = output.writerIndex() - startIndex;
336 output.setShort(lengthIndex, length);
337 output.writeZero(paddingNeeded(length));
340 private static void writeNextTableRelatedTableProperty(final ByteBuf output,
341 final TableFeatureProperties property, final byte code) {
342 final int startIndex = output.writerIndex();
343 output.writeShort(code);
344 int lengthIndex = output.writerIndex();
345 output.writeShort(EncodeConstants.EMPTY_LENGTH);
346 List<NextTableIds> nextTableIds = property.augmentation(
347 NextTableRelatedTableFeatureProperty.class).getNextTableIds();
348 if (nextTableIds != null) {
349 for (NextTableIds next : nextTableIds) {
350 output.writeByte(next.getTableId());
353 int length = output.writerIndex() - startIndex;
354 output.setShort(lengthIndex, length);
355 output.writeZero(paddingNeeded(length));
358 private static int paddingNeeded(final int length) {
359 int paddingRemainder = length % EncodeConstants.PADDING;
361 if (paddingRemainder != 0) {
362 result = EncodeConstants.PADDING - paddingRemainder;
367 private void writeActionsRelatedTableProperty(final ByteBuf output,
368 final TableFeatureProperties property, final byte code) {
369 final int startIndex = output.writerIndex();
370 output.writeShort(code);
371 int lengthIndex = output.writerIndex();
372 output.writeShort(EncodeConstants.EMPTY_LENGTH);
373 List<Action> actions = property.augmentation(ActionRelatedTableFeatureProperty.class).getAction();
374 if (actions != null) {
375 TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory
376 .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
377 ListSerializer.serializeHeaderList(actions, keyMaker, registry, output);
379 int length = output.writerIndex() - startIndex;
380 output.setShort(lengthIndex, length);
381 output.writeZero(paddingNeeded(length));
384 private void writeOxmRelatedTableProperty(final ByteBuf output,
385 final TableFeatureProperties property, final byte code) {
386 final int startIndex = output.writerIndex();
387 output.writeShort(code);
388 int lengthIndex = output.writerIndex();
389 output.writeShort(EncodeConstants.EMPTY_LENGTH);
390 List<MatchEntry> entries = property.augmentation(OxmRelatedTableFeatureProperty.class).getMatchEntry();
391 if (entries != null) {
392 TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory
393 .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
394 ListSerializer.serializeHeaderList(entries, keyMaker, registry, output);
396 int length = output.writerIndex() - startIndex;
397 output.setShort(lengthIndex, length);
398 output.writeZero(paddingNeeded(length));
401 private void writeExperimenterRelatedTableProperty(final ByteBuf output,
402 final TableFeatureProperties property) {
403 long expId = property.augmentation(ExperimenterIdTableFeatureProperty.class).getExperimenter().getValue();
404 OFSerializer<TableFeatureProperties> serializer = registry.getSerializer(
405 ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey(
406 EncodeConstants.OF13_VERSION_ID, expId));
407 serializer.serialize(property, output);
410 private static int createTableConfigBitmask(final TableConfig tableConfig) {
411 return ByteBufUtils.fillBitMask(3, tableConfig.isOFPTCDEPRECATEDMASK());
415 public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
416 this.registry = serializerRegistry;