--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters.OF13ExperimenterInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class DefaultExperimenterDeserializerInitializer {\r
+\r
+ /**\r
+ * Registers default experimenter deserializers\r
+ * @param registry registry to be filled with deserializers\r
+ */\r
+ public static void registerDeserializers(DeserializerRegistry registry) {\r
+ SimpleDeserializerRegistryHelper helper =\r
+ new SimpleDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry);\r
+ helper.registerDeserializer(EncodeConstants.EXPERIMENTER_VALUE,\r
+ Instruction.class, new OF13ExperimenterInstructionDeserializer());\r
+ }\r
+}\r
import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
EncodeConstants.EMPTY_VALUE, Match.class), new MatchDeserializer());
registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,
EncodeConstants.EMPTY_VALUE, Action.class), new ActionsDeserializer());
- registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,
- EncodeConstants.EMPTY_VALUE, Instruction.class), new InstructionsDeserializer());
// register match entry deserializers
MatchEntryDeserializerInitializer.registerMatchEntryDeserializers(this);
+ //register instruction deserializers
+ InstructionDeserializerInitializer.registerDeserializers(this);
+ // register default experimenter deserializers
+ DefaultExperimenterDeserializerInitializer.registerDeserializers(this);
}
@Override
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.ApplyActionsInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.ClearActionsInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.GoToTableInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.MeterInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.WriteActionsInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.WriteMetadataInstructionDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class InstructionDeserializerInitializer {\r
+\r
+ /**\r
+ * Registers instruction deserializers\r
+ * @param registry registry to be filled with deserializers\r
+ */\r
+ public static void registerDeserializers(DeserializerRegistry registry) {\r
+ // register OF v1.3 instruction deserializers\r
+ SimpleDeserializerRegistryHelper helper =\r
+ new SimpleDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry);\r
+ helper.registerDeserializer(1, Instruction.class, new GoToTableInstructionDeserializer());\r
+ helper.registerDeserializer(2, Instruction.class, new WriteMetadataInstructionDeserializer());\r
+ helper.registerDeserializer(3, Instruction.class, new WriteActionsInstructionDeserializer());\r
+ helper.registerDeserializer(4, Instruction.class, new ApplyActionsInstructionDeserializer());\r
+ helper.registerDeserializer(5, Instruction.class, new ClearActionsInstructionDeserializer());\r
+ helper.registerDeserializer(6, Instruction.class, new MeterInstructionDeserializer());\r
+ }\r
+}\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
-import org.opendaylight.openflowjava.protocol.impl.util.MessageDeserializerRegistryHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;\r
*/\r
public static void registerMessageDeserializers(DeserializerRegistry registry) {\r
// register OF v1.0 message deserializers\r
- MessageDeserializerRegistryHelper helper =\r
- new MessageDeserializerRegistryHelper(EncodeConstants.OF10_VERSION_ID, registry);\r
- helper.registerMessageDeserializer(0, HelloMessage.class, new OF10HelloMessageFactory());\r
- helper.registerMessageDeserializer(1, ErrorMessage.class, new OF10ErrorMessageFactory());\r
- helper.registerMessageDeserializer(2, EchoRequestMessage.class, new OF10EchoRequestMessageFactory());\r
- helper.registerMessageDeserializer(3, EchoOutput.class, new OF10EchoReplyMessageFactory());\r
- helper.registerMessageDeserializer(6, GetFeaturesOutput.class, new OF10FeaturesReplyMessageFactory());\r
- helper.registerMessageDeserializer(8, GetConfigOutput.class, new OF10GetConfigReplyMessageFactory());\r
- helper.registerMessageDeserializer(10, PacketInMessage.class, new OF10PacketInMessageFactory());\r
- helper.registerMessageDeserializer(11, FlowRemovedMessage.class, new OF10FlowRemovedMessageFactory());\r
- helper.registerMessageDeserializer(12, PortStatusMessage.class, new OF10PortStatusMessageFactory());\r
- helper.registerMessageDeserializer(17, MultipartReplyMessage.class, new OF10StatsReplyMessageFactory());\r
- helper.registerMessageDeserializer(19, BarrierOutput.class, new OF10BarrierReplyMessageFactory());\r
- helper.registerMessageDeserializer(21, GetQueueConfigOutput.class, new OF10QueueGetConfigReplyMessageFactory());\r
+ SimpleDeserializerRegistryHelper helper =\r
+ new SimpleDeserializerRegistryHelper(EncodeConstants.OF10_VERSION_ID, registry);\r
+ helper.registerDeserializer(0, HelloMessage.class, new OF10HelloMessageFactory());\r
+ helper.registerDeserializer(1, ErrorMessage.class, new OF10ErrorMessageFactory());\r
+ helper.registerDeserializer(2, EchoRequestMessage.class, new OF10EchoRequestMessageFactory());\r
+ helper.registerDeserializer(3, EchoOutput.class, new OF10EchoReplyMessageFactory());\r
+ helper.registerDeserializer(6, GetFeaturesOutput.class, new OF10FeaturesReplyMessageFactory());\r
+ helper.registerDeserializer(8, GetConfigOutput.class, new OF10GetConfigReplyMessageFactory());\r
+ helper.registerDeserializer(10, PacketInMessage.class, new OF10PacketInMessageFactory());\r
+ helper.registerDeserializer(11, FlowRemovedMessage.class, new OF10FlowRemovedMessageFactory());\r
+ helper.registerDeserializer(12, PortStatusMessage.class, new OF10PortStatusMessageFactory());\r
+ helper.registerDeserializer(17, MultipartReplyMessage.class, new OF10StatsReplyMessageFactory());\r
+ helper.registerDeserializer(19, BarrierOutput.class, new OF10BarrierReplyMessageFactory());\r
+ helper.registerDeserializer(21, GetQueueConfigOutput.class, new OF10QueueGetConfigReplyMessageFactory());\r
// register Of v1.3 message deserializers\r
- helper = new MessageDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry);\r
- helper.registerMessageDeserializer(0, HelloMessage.class, new HelloMessageFactory());\r
- helper.registerMessageDeserializer(1, ErrorMessage.class, new ErrorMessageFactory());\r
- helper.registerMessageDeserializer(2, EchoRequestMessage.class, new EchoRequestMessageFactory());\r
- helper.registerMessageDeserializer(3, EchoOutput.class, new EchoReplyMessageFactory());\r
- helper.registerMessageDeserializer(6, GetFeaturesOutput.class, new FeaturesReplyMessageFactory());\r
- helper.registerMessageDeserializer(8, GetConfigOutput.class, new GetConfigReplyMessageFactory());\r
- helper.registerMessageDeserializer(10, PacketInMessage.class, new PacketInMessageFactory());\r
- helper.registerMessageDeserializer(11, FlowRemovedMessage.class, new FlowRemovedMessageFactory());\r
- helper.registerMessageDeserializer(12, PortStatusMessage.class, new PortStatusMessageFactory());\r
- helper.registerMessageDeserializer(19, MultipartReplyMessage.class, new MultipartReplyMessageFactory());\r
- helper.registerMessageDeserializer(21, BarrierOutput.class, new BarrierReplyMessageFactory());\r
- helper.registerMessageDeserializer(23, GetQueueConfigOutput.class, new QueueGetConfigReplyMessageFactory());\r
- helper.registerMessageDeserializer(25, RoleRequestOutput.class, new RoleReplyMessageFactory());\r
- helper.registerMessageDeserializer(27, GetAsyncOutput.class, new GetAsyncReplyMessageFactory());\r
+ helper = new SimpleDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry);\r
+ helper.registerDeserializer(0, HelloMessage.class, new HelloMessageFactory());\r
+ helper.registerDeserializer(1, ErrorMessage.class, new ErrorMessageFactory());\r
+ helper.registerDeserializer(2, EchoRequestMessage.class, new EchoRequestMessageFactory());\r
+ helper.registerDeserializer(3, EchoOutput.class, new EchoReplyMessageFactory());\r
+ helper.registerDeserializer(6, GetFeaturesOutput.class, new FeaturesReplyMessageFactory());\r
+ helper.registerDeserializer(8, GetConfigOutput.class, new GetConfigReplyMessageFactory());\r
+ helper.registerDeserializer(10, PacketInMessage.class, new PacketInMessageFactory());\r
+ helper.registerDeserializer(11, FlowRemovedMessage.class, new FlowRemovedMessageFactory());\r
+ helper.registerDeserializer(12, PortStatusMessage.class, new PortStatusMessageFactory());\r
+ helper.registerDeserializer(19, MultipartReplyMessage.class, new MultipartReplyMessageFactory());\r
+ helper.registerDeserializer(21, BarrierOutput.class, new BarrierReplyMessageFactory());\r
+ helper.registerDeserializer(23, GetQueueConfigOutput.class, new QueueGetConfigReplyMessageFactory());\r
+ helper.registerDeserializer(25, RoleRequestOutput.class, new RoleReplyMessageFactory());\r
+ helper.registerDeserializer(27, GetAsyncOutput.class, new GetAsyncReplyMessageFactory());\r
}\r
}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF13ExperimenterInstructionDeserializer implements OFDeserializer<Instruction>,\r
+ HeaderDeserializer<Instruction> {\r
+\r
+ @Override\r
+ public Instruction deserializeHeader(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(Experimenter.class);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();\r
+ expBuilder.setExperimenter(input.readUnsignedInt());\r
+ return builder.build();\r
+ }\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(Experimenter.class);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();\r
+ expBuilder.setExperimenter(input.readUnsignedInt());\r
+ if (input.readableBytes() > 0) {\r
+ byte[] data = new byte[input.readableBytes()];\r
+ input.readBytes(data);\r
+ expBuilder.setData(data);\r
+ }\r
+ builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build());\r
+ return builder.build();\r
+ }\r
+\r
+}\r
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
-import org.opendaylight.openflowjava.protocol.impl.util.DecodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker;
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(
EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput));
- OFDeserializer<Instruction> insDeserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Instruction.class));
- List<Instruction> instructions = DecodingUtils.deserializeList(
- subInput.readableBytes(), subInput, insDeserializer);
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory
+ .createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<Instruction> instructions = ListDeserializer.deserializeList(
+ EncodeConstants.OF13_VERSION_ID, subInput.readableBytes(), subInput, keyMaker, registry);
flowStatsBuilder.setInstruction(instructions);
flowStatsList.add(flowStatsBuilder.build());
}
if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)
|| type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) {
InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder();
- HeaderDeserializer<Instruction> insDeserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Instruction.class));
- List<Instruction> instructions = DecodingUtils.deserializeHeaders(
- propertyLength - COMMON_PROPERTY_LENGTH, input, insDeserializer);
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<Instruction> instructions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID,
+ propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
insBuilder.setInstruction(instructions);
builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build());
} else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)
|| type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)
|| type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) {
ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder();
- HeaderDeserializer<Action> deserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class));
- List<Action> actions = DecodingUtils.deserializeHeaders(
- propertyLength - COMMON_PROPERTY_LENGTH, input, deserializer);
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<Action> actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID,
+ propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
actionBuilder.setAction(actions);
builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build());
} else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)
|| type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)
|| type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) {
OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder();
- oxmBuilder.setMatchEntries(DecodingUtils.deserializeMatchEntryHeaders(
- propertyLength - COMMON_PROPERTY_LENGTH, input, registry));
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory
+ .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<MatchEntries> entries = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID,
+ propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry);
+ oxmBuilder.setMatchEntries(entries);
builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());
} else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)
|| type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) {
bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));
bucketsBuilder.setWatchGroup(input.readUnsignedInt());
input.skipBytes(PADDING_IN_BUCKETS_HEADER);
- OFDeserializer<Action> deserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class));
- List<Action> actionsList = DecodingUtils.deserializeList(
- bucketsLength - BUCKETS_HEADER_LENGTH, input, deserializer);
- bucketsBuilder.setAction(actionsList);
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,
+ bucketsLength - BUCKETS_HEADER_LENGTH, input, keyMaker, registry);
+ bucketsBuilder.setAction(actions);
bucketsList.add(bucketsBuilder.build());
actualLength += bucketsLength;
}
import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
-import org.opendaylight.openflowjava.protocol.impl.util.DecodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker;
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer;
import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
- OFDeserializer<Action> deserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class));
- List<Action> actions = DecodingUtils.deserializeList(length - LENGTH_OF_FLOW_STATS,
- input, deserializer);
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
+ List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID,
+ length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry);
flowStatsBuilder.setAction(actions);
flowStatsList.add(flowStatsBuilder.build());
}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;\r
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker;\r
+import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class AbstractActionInstructionDeserializer extends AbstractInstructionDeserializer\r
+ implements DeserializerRegistryInjector {\r
+\r
+ private DeserializerRegistry registry;\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(getType());\r
+ int instructionLength = input.readUnsignedShort();\r
+ input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);\r
+ ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();\r
+ int length = instructionLength - InstructionConstants.STANDARD_INSTRUCTION_LENGTH;\r
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);\r
+ List<Action> actions = ListDeserializer.deserializeList(\r
+ EncodeConstants.OF13_VERSION_ID, length, input, keyMaker, getRegistry());\r
+ actionsBuilder.setAction(actions);\r
+ builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());\r
+ return builder.build();\r
+ }\r
+\r
+ protected abstract Class<? extends InstructionBase> getType();\r
+\r
+ protected DeserializerRegistry getRegistry() {\r
+ return registry;\r
+ }\r
+\r
+ @Override\r
+ public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {\r
+ this.registry = deserializerRegistry;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class AbstractInstructionDeserializer implements OFDeserializer<Instruction>,\r
+ HeaderDeserializer<Instruction> {\r
+\r
+ @Override\r
+ public Instruction deserializeHeader(ByteBuf rawMessage) {\r
+ InstructionBuilder builder = processHeader(rawMessage);\r
+ rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ return builder.build();\r
+ }\r
+\r
+ protected InstructionBuilder processHeader(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ int type = input.readUnsignedShort();\r
+ switch (type) {\r
+ case 1:\r
+ builder.setType(GotoTable.class);\r
+ break;\r
+ case 2:\r
+ builder.setType(WriteMetadata.class);\r
+ break;\r
+ case 3:\r
+ builder.setType(WriteActions.class);\r
+ break;\r
+ case 4:\r
+ builder.setType(ApplyActions.class);\r
+ break;\r
+ case 5:\r
+ builder.setType(ClearActions.class);\r
+ break;\r
+ case 6:\r
+ builder.setType(Meter.class);\r
+ break;\r
+ default:\r
+ throw new IllegalStateException("Unknown instruction type received, type: " + type);\r
+ }\r
+ return builder;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ApplyActionsInstructionDeserializer extends AbstractActionInstructionDeserializer {\r
+\r
+ @Override\r
+ protected Class<? extends InstructionBase> getType() {\r
+ return ApplyActions.class;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ClearActionsInstructionDeserializer extends AbstractInstructionDeserializer {\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = super.processHeader(input);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);\r
+ ActionsInstructionBuilder actionsBuilder = \r
+ new ActionsInstructionBuilder();\r
+ List<Action> actions = new ArrayList<>();\r
+ actionsBuilder.setAction(actions);\r
+ builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());\r
+ return builder.build();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class GoToTableInstructionDeserializer extends AbstractInstructionDeserializer {\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(GotoTable.class);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder();\r
+ tableBuilder.setTableId(input.readUnsignedByte());\r
+ builder.addAugmentation(TableIdInstruction.class, tableBuilder.build());\r
+ input.skipBytes(InstructionConstants.PADDING_IN_GOTO_TABLE);\r
+ return builder.build();\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class MeterInstructionDeserializer extends AbstractInstructionDeserializer {\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(Meter.class);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();\r
+ meterBuilder.setMeterId(input.readUnsignedInt());\r
+ builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());\r
+ return builder.build();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class WriteActionsInstructionDeserializer extends AbstractActionInstructionDeserializer {\r
+\r
+ @Override\r
+ protected Class<? extends InstructionBase> getType() {\r
+ return WriteActions.class;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class WriteMetadataInstructionDeserializer extends AbstractInstructionDeserializer {\r
+\r
+ @Override\r
+ public Instruction deserialize(ByteBuf input) {\r
+ InstructionBuilder builder = new InstructionBuilder();\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ builder.setType(WriteMetadata.class);\r
+ input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+ input.skipBytes(InstructionConstants.PADDING_IN_WRITE_METADATA);\r
+ MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();\r
+ byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ input.readBytes(metadata);\r
+ metadataBuilder.setMetadata(metadata);\r
+ byte[] metadata_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ input.readBytes(metadata_mask);\r
+ metadataBuilder.setMetadataMask(metadata_mask);\r
+ builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());\r
+ return builder.build();\r
+ }\r
+}\r
registry.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class))
.serialize(message.getMatch(), outBuffer);
ListSerializer.serializeList(message.getInstruction(), EnhancedTypeKeyMakerFactory
- .createInstructionKeyBuilder(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
+ .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
ByteBufUtils.updateOFHeaderLength(outBuffer);
}
outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);
ListSerializer.serializeList(currentBucket.getAction(), EnhancedTypeKeyMakerFactory
- .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
}
}
padding = paddingNeeded(length);
output.writeShort(length);
EnhancedTypeKeyMaker<Instruction> keyMaker = EnhancedTypeKeyMakerFactory
- .createInstructionKeyBuilder(EncodeConstants.OF13_VERSION_ID);
+ .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
ListSerializer.serializeHeaderList(instructions, keyMaker, registry, output);
} else {
padding = paddingNeeded(length);
padding += paddingNeeded(length);
output.writeShort(length);
EnhancedTypeKeyMaker<Action> keyMaker = EnhancedTypeKeyMakerFactory
- .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID);
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
ListSerializer.serializeHeaderList(actions, keyMaker, registry, output);
} else {
padding = paddingNeeded(length);
outBuffer.writeShort(message.getOutPort().getValue().intValue());
outBuffer.writeShort(createFlowModFlagsBitmask(message.getFlagsV10()));
ListSerializer.serializeList(message.getAction(), EnhancedTypeKeyMakerFactory
- .createActionKeyBuilder(EncodeConstants.OF10_VERSION_ID), registry, outBuffer);
+ .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, outBuffer);
ByteBufUtils.updateOFHeaderLength(outBuffer);
}
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
int actionsStartIndex = outBuffer.writerIndex();
ListSerializer.serializeList(message.getAction(), EnhancedTypeKeyMakerFactory
- .createActionKeyBuilder(EncodeConstants.OF10_VERSION_ID), registry, outBuffer);
+ .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, outBuffer);
outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
byte[] data = message.getData();
if (data != null) {
ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, outBuffer);
int actionsStartIndex = outBuffer.writerIndex();
ListSerializer.serializeList(message.getAction(), EnhancedTypeKeyMakerFactory
- .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
byte[] data = message.getData();
if (data != null) {
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);\r
ByteBufUtils.padBuffer(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION, outBuffer);\r
ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory\r
- .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID), getRegistry(), outBuffer);\r
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), getRegistry(), outBuffer);\r
int instructionLength = outBuffer.writerIndex() - startIndex;\r
outBuffer.setShort(lengthIndex, instructionLength);\r
} else {\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @param <T> type the key maker is based on \r
+ */\r
+public abstract class AbstractCodeKeyMaker implements CodeKeyMaker {\r
+\r
+ private short version;\r
+\r
+ /**\r
+ * @param version openflow wire version\r
+ */\r
+ public AbstractCodeKeyMaker(short version) {\r
+ this.version = version;\r
+ \r
+ }\r
+\r
+ /**\r
+ * @return the version\r
+ */\r
+ public short getVersion() {\r
+ return version;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ */\r
+public interface CodeKeyMaker {\r
+\r
+ /**\r
+ * @param input buffer that will be the needed data gathered from\r
+ * @return key for deserializer lookup\r
+ */\r
+ public abstract MessageCodeKey make(ByteBuf input);\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class CodeKeyMakerFactory {\r
+\r
+ /**\r
+ * @param version\r
+ * @return\r
+ */\r
+ public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {\r
+ return new AbstractCodeKeyMaker(version) {\r
+ @Override\r
+ public MessageCodeKey make(ByteBuf input) {\r
+ int oxmClass = input.getUnsignedShort(input.readerIndex());\r
+ int oxmField = input.getUnsignedByte(input.readerIndex()\r
+ + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;\r
+ return new EnhancedMessageCodeKey(getVersion(), oxmClass,\r
+ oxmField, MatchEntries.class);\r
+ }\r
+ };\r
+ }\r
+\r
+ /**\r
+ * @param version\r
+ * @return\r
+ */\r
+ public static CodeKeyMaker createActionsKeyMaker(short version) {\r
+ return new AbstractCodeKeyMaker(version) {\r
+ @Override\r
+ public MessageCodeKey make(ByteBuf input) {\r
+ // EncodeConstants.EMPTY_VALUE used as temporary value\r
+ // until action deserializers are split\r
+// int type = input.getUnsignedShort(input.readerIndex());\r
+// return new MessageCodeKey(getVersion(), type, Action.class);\r
+ return new MessageCodeKey(getVersion(), EncodeConstants.EMPTY_VALUE, Action.class);\r
+ }\r
+ };\r
+ }\r
+\r
+ /**\r
+ * @param version\r
+ * @return\r
+ */\r
+ public static CodeKeyMaker createInstructionsKeyMaker(short version) {\r
+ return new AbstractCodeKeyMaker(version) {\r
+ @Override\r
+ public MessageCodeKey make(ByteBuf input) {\r
+ int type = input.getUnsignedShort(input.readerIndex());\r
+ return new MessageCodeKey(getVersion(), type, Instruction.class);\r
+ }\r
+ };\r
+ }\r
+}\r
+++ /dev/null
-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-import org.opendaylight.yangtools.yang.binding.DataObject;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public abstract class DecodingUtils {\r
-\r
- /**\r
- * Deserializes lists of actions or instructions\r
- * @param length length of list (in bytes)\r
- * @param input input bytebuf\r
- * @param deserializer \r
- * false in case of whole body deserialization\r
- * @return List of actions or instructions\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static <E extends DataObject> List<E> deserializeList(int length, ByteBuf input,\r
- OFGeneralDeserializer deserializer) {\r
- List<E> list = new ArrayList<>();\r
- int startIndex = input.readerIndex();\r
- OFDeserializer<E> actionsDeserializer = (OFDeserializer<E>) deserializer;\r
- while ((input.readerIndex() - startIndex) < length) {\r
- list.add(actionsDeserializer.deserialize(input));\r
- }\r
- return list;\r
- }\r
-\r
- /**\r
- * Deserializes action or instruction headers\r
- * @param length length of list (in bytes)\r
- * @param input input bytebuf\r
- * @param deserializer \r
- * false in case of whole body deserialization\r
- * @return List of action or instruction headers\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static <E extends DataObject> List<E> deserializeHeaders(int length, ByteBuf input,\r
- OFGeneralDeserializer deserializer) {\r
- List<E> list = new ArrayList<>();\r
- int startIndex = input.readerIndex();\r
- HeaderDeserializer<E> instructionsDeserializer = (HeaderDeserializer<E>) deserializer;\r
- while ((input.readerIndex() - startIndex) < length) {\r
- list.add(instructionsDeserializer.deserializeHeader(input));\r
- }\r
- return list;\r
- }\r
-\r
- /**\r
- * Deserializes match entry headers\r
- * @param length length of list (in bytes)\r
- * @param input input bytebuf\r
- * @param registry registry with deserializers\r
- * false in case of whole body deserialization\r
- * @return List of match entry headers\r
- */\r
- public static List<MatchEntries> deserializeMatchEntryHeaders(int length, ByteBuf input,\r
- DeserializerRegistry registry) {\r
- List<MatchEntries> list = new ArrayList<>();\r
- int startIndex = input.readerIndex();\r
- while ((input.readerIndex() - startIndex) < length) {\r
- int oxmClass = input.getUnsignedShort(input.readerIndex());\r
- int oxmField = input.getUnsignedByte(input.readerIndex()\r
- + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >> 1;\r
- HeaderDeserializer<MatchEntries> deserializer = registry.getDeserializer(\r
- new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass,\r
- oxmField, MatchEntries.class));\r
- list.add(deserializer.deserializeHeader(input));\r
- }\r
- return list;\r
- }\r
-\r
- /**\r
- * Deserializes list of match entries\r
- * @param length length of list (in bytes)\r
- * @param input input bytebuf\r
- * @param registry registry with deserializers\r
- * false in case of whole body deserialization\r
- * @return List of match entries\r
- */\r
- public static List<MatchEntries> deserializeMatchEntries(int length, ByteBuf input,\r
- DeserializerRegistry registry) {\r
- List<MatchEntries> list = new ArrayList<>();\r
- int startIndex = input.readerIndex();\r
- while ((input.readerIndex() - startIndex) < length) {\r
- int oxmClass = input.getUnsignedShort(input.readerIndex());\r
- int oxmField = input.getUnsignedByte(input.readerIndex()\r
- + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >> 1;\r
- OFDeserializer<MatchEntries> deserializer = registry.getDeserializer(\r
- new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass,\r
- oxmField, MatchEntries.class));\r
- list.add(deserializer.deserialize(input));\r
- }\r
- return list;\r
- }\r
-}\r
* in lookup key\r
* @return lookup key\r
*/\r
- public static EnhancedTypeKeyMaker<MatchEntries> createMatchEntriesKeyBuilder(short version) {\r
+ public static EnhancedTypeKeyMaker<MatchEntries> createMatchEntriesKeyMaker(short version) {\r
return new AbstractEnhancedTypeKeyMaker<MatchEntries>(version) {\r
@Override\r
public EnhancedMessageTypeKey<?, ?> make(MatchEntries entry) {\r
* in lookup key\r
* @return lookup key\r
*/\r
- public static EnhancedTypeKeyMaker<Action> createActionKeyBuilder(short version) {\r
+ public static EnhancedTypeKeyMaker<Action> createActionKeyMaker(short version) {\r
return new AbstractEnhancedTypeKeyMaker<Action>(version) {\r
@Override\r
public EnhancedMessageTypeKey<?, ?> make(Action entry) {\r
* in lookup key\r
* @return lookup key\r
*/\r
- public static EnhancedTypeKeyMaker<Instruction> createInstructionKeyBuilder(short version) {\r
+ public static EnhancedTypeKeyMaker<Instruction> createInstructionKeyMaker(short version) {\r
return new AbstractEnhancedTypeKeyMaker<Instruction>(version) {\r
@Override\r
public EnhancedMessageTypeKey<?, ?> make(Instruction entry) {\r
+++ /dev/null
-/*
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.util;
-
-import io.netty.buffer.ByteBuf;
-
-import java.util.List;
-
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
-import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
-
-/**
- * Deserializes ofp_instruction (OpenFlow v1.3) structures
- * @author michal.polkorab
- * @author timotej.kubas
- */
-public class InstructionsDeserializer implements OFDeserializer<Instruction>,
- HeaderDeserializer<Instruction>, DeserializerRegistryInjector {
-
- private static final byte WRITE_APPLY_CLEAR_ACTION_LENGTH = 8;
- private static final byte GOTO_TABLE_PADDING = 3;
- private static final byte WRITE_METADATA_PADDING = 4;
- private static final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4;
- private DeserializerRegistry registry;
-
- @Override
- public Instruction deserialize(ByteBuf input) {
- InstructionBuilder builder = new InstructionBuilder();
- int type = input.readUnsignedShort();
- switch (type) {
- case 1:
- createGotoTableInstruction(builder, input);
- break;
- case 2:
- createMetadataInstruction(builder, input);
- break;
- case 3:
- builder.setType(WriteActions.class);
- createActionRelatedInstruction(input, builder);
- break;
- case 4:
- builder.setType(ApplyActions.class);
- createActionRelatedInstruction(input, builder);
- break;
- case 5:
- builder.setType(ClearActions.class);
- createActionRelatedInstruction(input, builder);
- break;
- case 6:
- builder.setType(Meter.class);
- input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
- meterBuilder.setMeterId(input.readUnsignedInt());
- builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
- break;
- case 65535:
- builder.setType(Experimenter.class);
- OFDeserializer<ExperimenterInstruction> deserializer = registry.getDeserializer(
- new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, type, ExperimenterInstruction.class));
- ExperimenterInstruction expInstruction = deserializer.deserialize(input);
- builder.addAugmentation(ExperimenterInstruction.class, expInstruction);
- break;
- default:
- break;
- }
- return builder.build();
- }
-
- @Override
- public Instruction deserializeHeader(ByteBuf input) {
- InstructionBuilder builder = new InstructionBuilder();
- int type = input.readUnsignedShort();
- switch (type) {
- case 1:
- builder.setType(GotoTable.class);
- break;
- case 2:
- builder.setType(WriteMetadata.class);
- break;
- case 3:
- builder.setType(WriteActions.class);
- break;
- case 4:
- builder.setType(ApplyActions.class);
- break;
- case 5:
- builder.setType(ClearActions.class);
- break;
- case 6:
- builder.setType(Meter.class);
- break;
- case 65535:
- builder.setType(Experimenter.class);
- ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();
- expBuilder.setExperimenter(input.readUnsignedInt());
- builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build());
- break;
- default:
- break;
- }
- return builder.build();
- }
-
- private static void createGotoTableInstruction(InstructionBuilder builder,
- ByteBuf input) {
- builder.setType(GotoTable.class);
- input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder();
- tableBuilder.setTableId(input.readUnsignedByte());
- builder.addAugmentation(TableIdInstruction.class, tableBuilder.build());
- input.skipBytes(GOTO_TABLE_PADDING);
- }
-
- private static void createMetadataInstruction(InstructionBuilder builder,
- ByteBuf input) {
- builder.setType(WriteMetadata.class);
- input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- input.skipBytes(WRITE_METADATA_PADDING);
- MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();
- byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
- input.readBytes(metadata);
- metadataBuilder.setMetadata(metadata);
- byte[] metadata_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
- input.readBytes(metadata_mask);
- metadataBuilder.setMetadataMask(metadata_mask);
- builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());
- }
-
- private void createActionRelatedInstruction(ByteBuf input, InstructionBuilder builder) {
- int instructionLength = input.readUnsignedShort();
- input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING);
- ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();
- OFDeserializer<Action> deserializer = registry.getDeserializer(new MessageCodeKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class));
- List<Action> actions = DecodingUtils.deserializeList(
- instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH, input, deserializer);
- actionsBuilder.setAction(actions);
- builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
- }
-
- @Override
- public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
- registry = deserializerRegistry;
- }
-}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ListDeserializer {\r
+\r
+ /**\r
+ * Deserializes items into list\r
+ * @param version openflow wire version\r
+ * @param length length of list in ByteBuf (bytes)\r
+ * @param input input buffer\r
+ * @param keyMaker creates keys for deserializer lookup\r
+ * @param registry stores deserializers\r
+ * @return list of items\r
+ */\r
+ public static <E extends DataObject> List<E> deserializeList(short version, int length,\r
+ ByteBuf input, CodeKeyMaker keyMaker, DeserializerRegistry registry) {\r
+ List<E> items = null;\r
+ if (input.readableBytes() > 0) {\r
+ items = new ArrayList<>();\r
+ int startIndex = input.readerIndex();\r
+ while ((input.readerIndex() - startIndex) < length){\r
+ OFDeserializer<E> deserializer = registry.getDeserializer(keyMaker.make(input));\r
+ E item = deserializer.deserialize(input);\r
+ items.add(item);\r
+ }\r
+ }\r
+ return items;\r
+ }\r
+\r
+ /**\r
+ * Deserializes headers of items into list\r
+ * @param version openflow wire version\r
+ * @param length length of list in ByteBuf (bytes)\r
+ * @param input input buffer\r
+ * @param keyMaker creates keys for deserializer lookup\r
+ * @param registry stores deserializers\r
+ * @return list of items\r
+ */\r
+ public static <E extends DataObject> List<E> deserializeHeaders(short version, int length,\r
+ ByteBuf input, CodeKeyMaker keyMaker, DeserializerRegistry registry) {\r
+ List<E> items = null;\r
+ if (input.readableBytes() > 0) {\r
+ items = new ArrayList<>();\r
+ int startIndex = input.readerIndex();\r
+ while ((input.readerIndex() - startIndex) < length){\r
+ HeaderDeserializer<E> deserializer = registry.getDeserializer(keyMaker.make(input));\r
+ E item = deserializer.deserializeHeader(input);\r
+ items.add(item);\r
+ }\r
+ }\r
+ return items;\r
+ }\r
+}\r
import io.netty.buffer.ByteBuf;
+import java.util.List;
+
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
/**
* Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures
default:
break;
}
- builder.setMatchEntries(DecodingUtils.deserializeMatchEntries(
- length - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES, input, registry));
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory
+ .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
+ List<MatchEntries> entries = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,
+ length - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES, input, keyMaker, registry);
+ builder.setMatchEntries(entries);
int paddingRemainder = length % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
* @author michal.polkorab\r
*\r
*/\r
-public class MessageDeserializerRegistryHelper {\r
+public class SimpleDeserializerRegistryHelper {\r
\r
private short version;\r
private DeserializerRegistry registry;\r
* @param version wire protocol version\r
* @param deserializerRegistry registry to be filled with message deserializers\r
*/\r
- public MessageDeserializerRegistryHelper(short version, DeserializerRegistry deserializerRegistry) {\r
+ public SimpleDeserializerRegistryHelper(short version, DeserializerRegistry deserializerRegistry) {\r
this.version = version;\r
this.registry = deserializerRegistry;\r
}\r
* by given deserializer\r
* @param deserializer deserializer instance\r
*/\r
- public void registerMessageDeserializer(int code,\r
+ public void registerDeserializer(int code,\r
Class<?> deserializedObjectClass, OFGeneralDeserializer deserializer) {\r
registry.registerDeserializer(new MessageCodeKey(version, code,\r
deserializedObjectClass), deserializer);\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
\r
private static final Logger LOGGER = LoggerFactory\r
.getLogger(ActionsDeserializerTest.class);\r
- private OFDeserializer<Action> actionDeserializer;\r
+ private DeserializerRegistry registry;\r
\r
/**\r
* Initializes deserializer registry and lookups correct deserializer\r
*/\r
@Before\r
public void startUp() {\r
- DeserializerRegistry registry = new DeserializerRegistryImpl();\r
+ registry = new DeserializerRegistryImpl();\r
registry.init();\r
- actionDeserializer = registry.getDeserializer(\r
- new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,\r
- EncodeConstants.EMPTY_VALUE, Action.class));\r
}\r
\r
/**\r
message.skipBytes(4); // skip XID\r
LOGGER.info("bytes: " + message.readableBytes());\r
\r
- \r
- List<Action> actions = DecodingUtils.deserializeList(message.readableBytes(),\r
- message, actionDeserializer);\r
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);\r
+ List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,\r
+ message.readableBytes(), message, keyMaker, registry);\r
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
+ "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());\r
Assert.assertEquals("Wrong action port", 1,\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
*/\r
public class InstructionsDeserializerTest {\r
\r
- private OFDeserializer<Instruction> insDeserializer;\r
+\r
+ private DeserializerRegistry registry;\r
\r
/**\r
* Initializes deserializer registry and lookups correct deserializer\r
*/\r
@Before\r
public void startUp() {\r
- DeserializerRegistry registry = new DeserializerRegistryImpl();\r
+ registry = new DeserializerRegistryImpl();\r
registry.init();\r
- insDeserializer = registry.getDeserializer(\r
- new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,\r
- EncodeConstants.EMPTY_VALUE, Instruction.class));\r
}\r
\r
/**\r
\r
message.skipBytes(4); // skip XID\r
\r
- List<Instruction> instructions = DecodingUtils.deserializeList(\r
- message.readableBytes(), message, insDeserializer);\r
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);\r
+ List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,\r
+ message.readableBytes(), message, keyMaker, registry);\r
Instruction i1 = instructions.get(0);\r
Assert.assertEquals("Wrong type - i1", "org.opendaylight.yang.gen.v1.urn."\r
+ "opendaylight.openflow.common.instruction.rev130731.GotoTable", i1.getType().getName());\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
*/\r
public class OF10ActionsDeserializerTest {\r
\r
- private OFDeserializer<Action> actionsDeserializer;\r
+ private DeserializerRegistry registry;\r
\r
/**\r
* Initializes deserializer registry and lookups correct deserializer\r
*/\r
@Before\r
public void startUp() {\r
- DeserializerRegistry registry = new DeserializerRegistryImpl();\r
+ registry = new DeserializerRegistryImpl();\r
registry.init();\r
- actionsDeserializer = registry.getDeserializer(\r
- new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE,\r
- Action.class));\r
}\r
\r
/**\r
+ "00 0B 00 10 00 04 00 00 00 00 00 00 00 00 00 30");\r
\r
message.skipBytes(4); // skip XID\r
- List<Action> actions = DecodingUtils.deserializeList(message.readableBytes(),\r
- message, actionsDeserializer);\r
+ CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);\r
+ List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID,\r
+ message.readableBytes(), message, keyMaker, registry);\r
Assert.assertEquals("Wrong number of actions", 12, actions.size());\r
Action action1 = actions.get(0);\r
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory\r
- .createActionKeyBuilder(EncodeConstants.OF10_VERSION_ID), registry, out);\r
+ .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, out);\r
\r
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory\r
- .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID), registry, out);\r
+ .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);\r
\r
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
ListSerializer.serializeList(instructions, EnhancedTypeKeyMakerFactory\r
- .createInstructionKeyBuilder(EncodeConstants.OF13_VERSION_ID), registry, out);\r
+ .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);\r
\r
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());\r