From: Michal Polkorab Date: Wed, 30 Apr 2014 10:26:24 +0000 (+0200) Subject: OF10ActionDeserializer and ActionDeserializer split into separate classes X-Git-Tag: release/helium~86 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7424f6fec6016081265f98bdd9c5b17f671c0d88;p=openflowjava.git OF10ActionDeserializer and ActionDeserializer split into separate classes - updated deserializer initializers Signed-off-by: Michal Polkorab --- diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/ActionDeserializerInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/ActionDeserializerInitializer.java new file mode 100644 index 00000000..a1ed6198 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/ActionDeserializerInitializer.java @@ -0,0 +1,89 @@ +/* + * 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.deserialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10EnqueueActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10OutputActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetDlDstActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetDlSrcActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetNwDstActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetNwSrcActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetNwTosActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetTpDstActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetTpSrcActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetVlanPcpActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10SetVlanVidActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF10StripVlanActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13CopyTtlInActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13CopyTtlOutActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13DecMplsTtlActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13DecNwTtlActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13GroupActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13OutputActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PopMplsActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PopPbbActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PopVlanActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PushMplsActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PushPbbActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13PushVlanActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetFieldActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetMplsTtlActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetNwTtlActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.action.OF13SetQueueActionDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; + +/** + * @author michal.polkorab + * + */ +public class ActionDeserializerInitializer { + + /** + * Registers action deserializers + * @param registry registry to be filled with deserializers + */ + public static void registerDeserializers(DeserializerRegistry registry) { + // register OF v1.0 action deserializers + SimpleDeserializerRegistryHelper helper = + new SimpleDeserializerRegistryHelper(EncodeConstants.OF10_VERSION_ID, registry); + helper.registerDeserializer(0, Action.class, new OF10OutputActionDeserializer()); + helper.registerDeserializer(1, Action.class, new OF10SetVlanVidActionDeserializer()); + helper.registerDeserializer(2, Action.class, new OF10SetVlanPcpActionDeserializer()); + helper.registerDeserializer(3, Action.class, new OF10StripVlanActionDeserializer()); + helper.registerDeserializer(4, Action.class, new OF10SetDlSrcActionDeserializer()); + helper.registerDeserializer(5, Action.class, new OF10SetDlDstActionDeserializer()); + helper.registerDeserializer(6, Action.class, new OF10SetNwSrcActionDeserializer()); + helper.registerDeserializer(7, Action.class, new OF10SetNwDstActionDeserializer()); + helper.registerDeserializer(8, Action.class, new OF10SetNwTosActionDeserializer()); + helper.registerDeserializer(9, Action.class, new OF10SetTpSrcActionDeserializer()); + helper.registerDeserializer(10, Action.class, new OF10SetTpDstActionDeserializer()); + helper.registerDeserializer(11, Action.class, new OF10EnqueueActionDeserializer()); + // register OF v1.3 action deserializers + helper = new SimpleDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry); + helper.registerDeserializer(0, Action.class, new OF13OutputActionDeserializer()); + helper.registerDeserializer(11, Action.class, new OF13CopyTtlOutActionDeserializer()); + helper.registerDeserializer(12, Action.class, new OF13CopyTtlInActionDeserializer()); + helper.registerDeserializer(15, Action.class, new OF13SetMplsTtlActionDeserializer()); + helper.registerDeserializer(16, Action.class, new OF13DecMplsTtlActionDeserializer()); + helper.registerDeserializer(17, Action.class, new OF13PushVlanActionDeserializer()); + helper.registerDeserializer(18, Action.class, new OF13PopVlanActionDeserializer()); + helper.registerDeserializer(19, Action.class, new OF13PushMplsActionDeserializer()); + helper.registerDeserializer(20, Action.class, new OF13PopMplsActionDeserializer()); + helper.registerDeserializer(21, Action.class, new OF13SetQueueActionDeserializer()); + helper.registerDeserializer(22, Action.class, new OF13GroupActionDeserializer()); + helper.registerDeserializer(23, Action.class, new OF13SetNwTtlActionDeserializer()); + helper.registerDeserializer(24, Action.class, new OF13DecNwTtlActionDeserializer()); + helper.registerDeserializer(25, Action.class, new OF13SetFieldActionDeserializer()); + helper.registerDeserializer(26, Action.class, new OF13PushPbbActionDeserializer()); + helper.registerDeserializer(27, Action.class, new OF13PopPbbActionDeserializer()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java index d32d53d9..7e3a156c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java @@ -9,9 +9,11 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization; import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters.ExperimenterActionDeserializer; import org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters.OF13ExperimenterInstructionDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper; +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; /** @@ -25,9 +27,16 @@ public class DefaultExperimenterDeserializerInitializer { * @param registry registry to be filled with deserializers */ public static void registerDeserializers(DeserializerRegistry registry) { - SimpleDeserializerRegistryHelper helper = - new SimpleDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry); - helper.registerDeserializer(EncodeConstants.EXPERIMENTER_VALUE, - Instruction.class, new OF13ExperimenterInstructionDeserializer()); + // register OF v1.0 default experimenter deserializers + // - default action deserializer + registry.registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, + EncodeConstants.EXPERIMENTER_VALUE, Action.class), new ExperimenterActionDeserializer()); + // register OF v1.3 default experimenter deserializers + // - default action deserializer + registry.registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EXPERIMENTER_VALUE, Action.class), new ExperimenterActionDeserializer()); + // - default instruction deserializer + registry.registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EXPERIMENTER_VALUE, Instruction.class), new OF13ExperimenterInstructionDeserializer()); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java index 6a08db8c..8808569f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java @@ -15,12 +15,9 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegi import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; 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.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.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; @@ -44,16 +41,14 @@ public class DeserializerRegistryImpl implements DeserializerRegistry { // register common structure deserializers registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class), new OF10MatchDeserializer()); - registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, - EncodeConstants.EMPTY_VALUE, Action.class), new OF10ActionsDeserializer()); registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class), new MatchDeserializer()); - registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, - EncodeConstants.EMPTY_VALUE, Action.class), new ActionsDeserializer()); // register match entry deserializers MatchEntryDeserializerInitializer.registerMatchEntryDeserializers(this); - //register instruction deserializers + // register action deserializers + ActionDeserializerInitializer.registerDeserializers(this); + // register instruction deserializers InstructionDeserializerInitializer.registerDeserializers(this); // register default experimenter deserializers DefaultExperimenterDeserializerInitializer.registerDeserializers(this); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractActionDeserializer.java new file mode 100644 index 00000000..a5b17631 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractActionDeserializer.java @@ -0,0 +1,38 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractActionDeserializer implements OFDeserializer, + HeaderDeserializer { + + @Override + public Action deserializeHeader(ByteBuf input) { + ActionBuilder actionBuilder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + actionBuilder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + return actionBuilder.build(); + } + + protected abstract Class getType(); + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractEthertypeActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractEthertypeActionDeserializer.java new file mode 100644 index 00000000..db859179 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractEthertypeActionDeserializer.java @@ -0,0 +1,38 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractEthertypeActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + EthertypeActionBuilder etherType = new EthertypeActionBuilder(); + etherType.setEthertype(new EtherType(input.readUnsignedShort())); + builder.addAugmentation(EthertypeAction.class, etherType.build()); + input.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractHeaderActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractHeaderActionDeserializer.java new file mode 100644 index 00000000..a04453ee --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/AbstractHeaderActionDeserializer.java @@ -0,0 +1,33 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.action.rev130731.actions.grouping.ActionBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractHeaderActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + input.skipBytes(ActionConstants.PADDING_IN_ACTION_HEADER); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractIpAddressActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractIpAddressActionDeserializer.java new file mode 100644 index 00000000..49e96eff --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractIpAddressActionDeserializer.java @@ -0,0 +1,54 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yangtools.yang.binding.Augmentation; + +import com.google.common.base.Joiner; + +/** + * @author michal.polkorab + * + */ +public abstract class OF10AbstractIpAddressActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.addAugmentation(IpAddressAction.class, + createNwAddressAugmentationAndPad(input)); + return builder.build(); + } + + private static Augmentation createNwAddressAugmentationAndPad(ByteBuf input) { + IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + groups.add(Short.toString(input.readUnsignedByte())); + } + Joiner joiner = Joiner.on("."); + ipBuilder.setIpAddress(new Ipv4Address(joiner.join(groups))); + return ipBuilder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractMacAddressActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractMacAddressActionDeserializer.java new file mode 100644 index 00000000..e2a7095a --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractMacAddressActionDeserializer.java @@ -0,0 +1,46 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.DlAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; +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.action.rev130731.actions.grouping.ActionBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class OF10AbstractMacAddressActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); + return builder.build(); + } + + private static DlAddressAction createDlAugmentationAndPad(ByteBuf input) { + DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder(); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + input.readBytes(address); + dlBuilder.setDlAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); + input.skipBytes(ActionConstants.PADDING_IN_DL_ADDRESS_ACTION); + return dlBuilder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractPortActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractPortActionDeserializer.java new file mode 100644 index 00000000..9819f860 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10AbstractPortActionDeserializer.java @@ -0,0 +1,43 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; + +/** + * @author michal.polkorab + * + */ +public abstract class OF10AbstractPortActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + createPortAugmentation(input, builder); + input.skipBytes(ActionConstants.PADDING_IN_TP_PORT_ACTION); + return builder.build(); + } + + protected static void createPortAugmentation(ByteBuf input, ActionBuilder actionBuilder) { + PortActionBuilder portBuilder = new PortActionBuilder(); + portBuilder.setPort(new PortNumber((long) input.readUnsignedShort())); + actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10EnqueueActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10EnqueueActionDeserializer.java new file mode 100644 index 00000000..b9286e10 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10EnqueueActionDeserializer.java @@ -0,0 +1,47 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10EnqueueActionDeserializer extends OF10AbstractPortActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + createPortAugmentation(input, builder); + input.skipBytes(ActionConstants.PADDING_IN_ENQUEUE_ACTION); + QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder(); + queueBuilder.setQueueId(input.readUnsignedInt()); + builder.addAugmentation(QueueIdAction.class, queueBuilder.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return Enqueue.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10OutputActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10OutputActionDeserializer.java new file mode 100644 index 00000000..25e1b2bb --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10OutputActionDeserializer.java @@ -0,0 +1,45 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10OutputActionDeserializer extends OF10AbstractPortActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + createPortAugmentation(input, builder); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(input.readUnsignedShort()); + builder.addAugmentation(MaxLengthAction.class, maxLen.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return Output.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlDstActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlDstActionDeserializer.java new file mode 100644 index 00000000..2cdc5d0d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlDstActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetDlDstActionDeserializer extends OF10AbstractMacAddressActionDeserializer { + + @Override + protected Class getType() { + return SetDlDst.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlSrcActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlSrcActionDeserializer.java new file mode 100644 index 00000000..34b16b4b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetDlSrcActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetDlSrcActionDeserializer extends OF10AbstractMacAddressActionDeserializer { + + @Override + protected Class getType() { + return SetDlSrc.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwDstActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwDstActionDeserializer.java new file mode 100644 index 00000000..c41021d8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwDstActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetNwDstActionDeserializer extends OF10AbstractIpAddressActionDeserializer { + + @Override + protected Class getType() { + return SetNwDst.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwSrcActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwSrcActionDeserializer.java new file mode 100644 index 00000000..31550133 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwSrcActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetNwSrcActionDeserializer extends OF10AbstractIpAddressActionDeserializer { + + @Override + protected Class getType() { + return SetNwSrc.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwTosActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwTosActionDeserializer.java new file mode 100644 index 00000000..bdb9510d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetNwTosActionDeserializer.java @@ -0,0 +1,46 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetNwTosActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + NwTosActionBuilder tosBuilder = new NwTosActionBuilder(); + tosBuilder.setNwTos(input.readUnsignedByte()); + builder.addAugmentation(NwTosAction.class, tosBuilder.build()); + input.skipBytes(ActionConstants.PADDING_IN_SET_NW_TOS_ACTION); + return builder.build(); + } + + @Override + protected Class getType() { + return SetNwTos.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpDstActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpDstActionDeserializer.java new file mode 100644 index 00000000..96a41ffd --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpDstActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetTpDstActionDeserializer extends OF10AbstractPortActionDeserializer { + + @Override + protected Class getType() { + return SetTpDst.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpSrcActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpSrcActionDeserializer.java new file mode 100644 index 00000000..31271a4a --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetTpSrcActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetTpSrcActionDeserializer extends OF10AbstractPortActionDeserializer { + + @Override + protected Class getType() { + return SetTpSrc.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanPcpActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanPcpActionDeserializer.java new file mode 100644 index 00000000..f46779d9 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanPcpActionDeserializer.java @@ -0,0 +1,46 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetVlanPcpActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + VlanPcpActionBuilder vlanBuilder = new VlanPcpActionBuilder(); + vlanBuilder.setVlanPcp(input.readUnsignedByte()); + input.skipBytes(ActionConstants.PADDING_IN_SET_VLAN_PCP_ACTION); + builder.addAugmentation(VlanPcpAction.class, vlanBuilder.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return SetVlanPcp.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanVidActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanVidActionDeserializer.java new file mode 100644 index 00000000..b422d881 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10SetVlanVidActionDeserializer.java @@ -0,0 +1,46 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10SetVlanVidActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(getType()); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder(); + vlanBuilder.setVlanVid(input.readUnsignedShort()); + input.skipBytes(ActionConstants.PADDING_IN_SET_VLAN_VID_ACTION); + builder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return SetVlanVid.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10StripVlanActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10StripVlanActionDeserializer.java new file mode 100644 index 00000000..bb5c4a48 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF10StripVlanActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF10StripVlanActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return StripVlan.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlInActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlInActionDeserializer.java new file mode 100644 index 00000000..e56c5818 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlInActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13CopyTtlInActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return CopyTtlIn.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlOutActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlOutActionDeserializer.java new file mode 100644 index 00000000..731a82ad --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13CopyTtlOutActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13CopyTtlOutActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return CopyTtlOut.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecMplsTtlActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecMplsTtlActionDeserializer.java new file mode 100644 index 00000000..bab50a98 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecMplsTtlActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13DecMplsTtlActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return DecMplsTtl.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecNwTtlActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecNwTtlActionDeserializer.java new file mode 100644 index 00000000..8f112ff2 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13DecNwTtlActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13DecNwTtlActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return DecNwTtl.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13GroupActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13GroupActionDeserializer.java new file mode 100644 index 00000000..aa8803fe --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13GroupActionDeserializer.java @@ -0,0 +1,43 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13GroupActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + GroupIdActionBuilder group = new GroupIdActionBuilder(); + group.setGroupId(input.readUnsignedInt()); + builder.addAugmentation(GroupIdAction.class, group.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return Group.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13OutputActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13OutputActionDeserializer.java new file mode 100644 index 00000000..90cf6690 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13OutputActionDeserializer.java @@ -0,0 +1,51 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; + +/** + * @author michal.polkorab + * + */ +public class OF13OutputActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + PortActionBuilder port = new PortActionBuilder(); + port.setPort(new PortNumber(input.readUnsignedInt())); + builder.addAugmentation(PortAction.class, port.build()); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(input.readUnsignedShort()); + builder.addAugmentation(MaxLengthAction.class, maxLen.build()); + input.skipBytes(ActionConstants.OUTPUT_PADDING); + return builder.build(); + } + + @Override + protected Class getType() { + return Output.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopMplsActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopMplsActionDeserializer.java new file mode 100644 index 00000000..408e5b30 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopMplsActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PopMplsActionDeserializer extends AbstractEthertypeActionDeserializer { + + @Override + protected Class getType() { + return PopMpls.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopPbbActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopPbbActionDeserializer.java new file mode 100644 index 00000000..99ec0380 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopPbbActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PopPbbActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return PopPbb.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopVlanActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopVlanActionDeserializer.java new file mode 100644 index 00000000..e31a9bfe --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PopVlanActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PopVlanActionDeserializer extends AbstractHeaderActionDeserializer { + + @Override + protected Class getType() { + return PopVlan.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushMplsActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushMplsActionDeserializer.java new file mode 100644 index 00000000..121e1e96 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushMplsActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PushMplsActionDeserializer extends AbstractEthertypeActionDeserializer { + + @Override + protected Class getType() { + return PushMpls.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushPbbActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushPbbActionDeserializer.java new file mode 100644 index 00000000..6a44f04f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushPbbActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PushPbbActionDeserializer extends AbstractEthertypeActionDeserializer { + + @Override + protected Class getType() { + return PushPbb.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushVlanActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushVlanActionDeserializer.java new file mode 100644 index 00000000..eb0b059d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13PushVlanActionDeserializer.java @@ -0,0 +1,25 @@ +/* + * 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.deserialization.action; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13PushVlanActionDeserializer extends AbstractEthertypeActionDeserializer { + + @Override + protected Class getType() { + return PushVlan.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetFieldActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetFieldActionDeserializer.java new file mode 100644 index 00000000..aba3e785 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetFieldActionDeserializer.java @@ -0,0 +1,73 @@ +/* + * 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.deserialization.action; + +import java.util.ArrayList; +import java.util.List; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OF13SetFieldActionDeserializer extends AbstractActionDeserializer + implements DeserializerRegistryInjector { + + private DeserializerRegistry registry; + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + int startIndex = input.readerIndex(); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); + int oxmClass = input.getUnsignedShort(input.readerIndex()); + // get oxm_field & hasMask byte and extract the field value + int oxmField = input.getUnsignedByte(input.readerIndex() + + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1; + OFDeserializer matchDeserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass, + oxmField, MatchEntries.class)); + List entry = new ArrayList<>(); + entry.add(matchDeserializer.deserialize(input)); + matchEntries.setMatchEntries(entry); + builder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); + int paddingRemainder = (input.readerIndex() - startIndex) % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + input.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } + return builder.build(); + } + + @Override + protected Class getType() { + return SetField.class; + } + + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + this.registry = deserializerRegistry; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetMplsTtlActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetMplsTtlActionDeserializer.java new file mode 100644 index 00000000..b70d8309 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetMplsTtlActionDeserializer.java @@ -0,0 +1,45 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13SetMplsTtlActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); + mplsTtl.setMplsTtl(input.readUnsignedByte()); + builder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); + input.skipBytes(ActionConstants.SET_MPLS_TTL_PADDING); + return builder.build(); + } + + @Override + protected Class getType() { + return SetMplsTtl.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetNwTtlActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetNwTtlActionDeserializer.java new file mode 100644 index 00000000..f3f119ef --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetNwTtlActionDeserializer.java @@ -0,0 +1,45 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13SetNwTtlActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); + nwTtl.setNwTtl(input.readUnsignedByte()); + builder.addAugmentation(NwTtlAction.class, nwTtl.build()); + input.skipBytes(ActionConstants.SET_NW_TTL_PADDING); + return builder.build(); + } + + @Override + protected Class getType() { + return SetNwTtl.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetQueueActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetQueueActionDeserializer.java new file mode 100644 index 00000000..0ac46715 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/action/OF13SetQueueActionDeserializer.java @@ -0,0 +1,43 @@ +/* + * 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.deserialization.action; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; +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.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; + +/** + * @author michal.polkorab + * + */ +public class OF13SetQueueActionDeserializer extends AbstractActionDeserializer { + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + builder.setType(getType()); + input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + QueueIdActionBuilder queueId = new QueueIdActionBuilder(); + queueId.setQueueId(input.readUnsignedInt()); + builder.addAugmentation(QueueIdAction.class, queueId.build()); + return builder.build(); + } + + @Override + protected Class getType() { + return SetQueue.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java new file mode 100644 index 00000000..9a851a1b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java @@ -0,0 +1,60 @@ +/* + * 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.deserialization.experimenters; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; +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.action.rev130731.actions.grouping.ActionBuilder; + +/** + * @author michal.polkorab + * + */ +public class ExperimenterActionDeserializer implements OFDeserializer, + HeaderDeserializer { + + @Override + public Action deserializeHeader(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(Experimenter.class); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + builder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + return builder.build(); + } + + @Override + public Action deserialize(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(Experimenter.class); + int length = input.readUnsignedShort(); + // subtract experimenter header length + length -= EncodeConstants.EXPERIMENTER_IDS_LENGTH; + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + if (length > 0) { + byte[] data = new byte[length]; + input.readBytes(data); + expBuilder.setData(data); + } + builder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java deleted file mode 100644 index 16e9808f..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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.ArrayList; -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.EnhancedMessageCodeKey; -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.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; -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.action.rev130731.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; - -/** - * Deserializes ofp_actions (OpenFlow v1.3) - * @author timotej.kubas - * @author michal.polkorab - */ -public class ActionsDeserializer implements OFDeserializer, - HeaderDeserializer, DeserializerRegistryInjector { - - private static final byte PADDING_IN_ACTIONS_HEADER = 4; - private static final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6; - private static final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3; - private static final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2; - private static final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3; - private DeserializerRegistry registry; - - @Override - public Action deserialize(ByteBuf input) { - Action action = null; - ActionBuilder actionBuilder = new ActionBuilder(); - int type = input.getUnsignedShort(input.readerIndex()); - switch(type) { - case 0: - action = createOutputAction(input, actionBuilder); - break; - case 11: - action = createCopyTtlOutAction(input, actionBuilder); - break; - case 12: - action = createCopyTtlInAction(input, actionBuilder); - break; - case 15: - action = createSetMplsTtlAction(input, actionBuilder); - break; - case 16: - action = createDecMplsTtlOutAction(input, actionBuilder); - break; - case 17: - action = createPushVlanAction(input, actionBuilder); - break; - case 18: - action = createPopVlanAction(input, actionBuilder); - break; - case 19: - action = createPushMplsAction(input, actionBuilder); - break; - case 20: - action = createPopMplsAction(input, actionBuilder); - break; - case 21: - action = createSetQueueAction(input, actionBuilder); - break; - case 22: - action = createGroupAction(input, actionBuilder); - break; - case 23: - action = createSetNwTtlAction(input, actionBuilder); - break; - case 24: - action = createDecNwTtlAction(input, actionBuilder); - break; - case 25: - action = createSetFieldAction(input, actionBuilder); - break; - case 26: - action = createPushPbbAction(input, actionBuilder); - break; - case 27: - action = createPopPbbAction(input, actionBuilder); - break; - case 0xFFFF: - OFDeserializer expDeserializer = registry.getDeserializer( - new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0xFFFF, ExperimenterAction.class)); - ExperimenterAction expAction = expDeserializer.deserialize(input); - actionBuilder.addAugmentation(ExperimenterAction.class, expAction); - break; - default: - break; - } - return action; - } - - @Override - public Action deserializeHeader(ByteBuf input) { - ActionBuilder builder; - builder = new ActionBuilder(); - int type = input.readUnsignedShort(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - switch(type) { - case 0: - builder.setType(Output.class); - break; - case 11: - builder.setType(CopyTtlOut.class); - break; - case 12: - builder.setType(CopyTtlIn.class); - break; - case 15: - builder.setType(SetMplsTtl.class); - break; - case 16: - builder.setType(DecMplsTtl.class); - break; - case 17: - builder.setType(PushVlan.class); - break; - case 18: - builder.setType(PopVlan.class); - break; - case 19: - builder.setType(PushMpls.class); - break; - case 20: - builder.setType(PopMpls.class); - break; - case 21: - builder.setType(SetQueue.class); - break; - case 22: - builder.setType(Group.class); - break; - case 23: - builder.setType(SetNwTtl.class); - break; - case 24: - builder.setType(DecNwTtl.class); - break; - case 25: - builder.setType(SetField.class); - break; - case 26: - builder.setType(PushPbb.class); - break; - case 27: - builder.setType(PopPbb.class); - break; - case 0xFFFF: - HeaderDeserializer expDeserializer = registry.getDeserializer( - new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0xFFFF, ExperimenterAction.class)); - ExperimenterAction expAction = expDeserializer.deserializeHeader(input); - builder.setType(Experimenter.class); - builder.addAugmentation(ExperimenterAction.class, expAction); - break; - default: - break; - } - return builder.build(); - } - - private static Action createEmptyHeader(Class action, - ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(action); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - in.skipBytes(PADDING_IN_ACTIONS_HEADER); - return actionBuilder.build(); - } - - private static Action createCopyTtlInAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(CopyTtlIn.class, in, actionBuilder); - } - - private static Action createCopyTtlOutAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(CopyTtlOut.class, in, actionBuilder); - } - - private static Action createDecMplsTtlOutAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(DecMplsTtl.class, in, actionBuilder); - } - - private static Action createPopVlanAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(PopVlan.class, in, actionBuilder); - } - - private static Action createDecNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(DecNwTtl.class, in, actionBuilder); - } - - private static Action createPopPbbAction(ByteBuf in, ActionBuilder actionBuilder) { - return createEmptyHeader(PopPbb.class, in, actionBuilder); - } - - private static Action createOutputAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(Output.class); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - PortActionBuilder port = new PortActionBuilder(); - port.setPort(new PortNumber(in.readUnsignedInt())); - actionBuilder.addAugmentation(PortAction.class, port.build()); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(in.readUnsignedShort()); - actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); - in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER); - return actionBuilder.build(); - } - - private static Action createSetMplsTtlAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(SetMplsTtl.class); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); - mplsTtl.setMplsTtl(in.readUnsignedByte()); - actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); - in.skipBytes(PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER); - return actionBuilder.build(); - } - - private static Action createPushAction(Class action, - ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(action); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - EthertypeActionBuilder etherType = new EthertypeActionBuilder(); - etherType.setEthertype(new EtherType(in.readUnsignedShort())); - actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); - in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER); - return actionBuilder.build(); - } - - private static Action createPushVlanAction(ByteBuf in, ActionBuilder actionBuilder) { - return createPushAction(PushVlan.class, in, actionBuilder); - } - - private static Action createPushMplsAction(ByteBuf in, ActionBuilder actionBuilder) { - return createPushAction(PushMpls.class, in, actionBuilder); - } - - private static Action createPopMplsAction(ByteBuf in, ActionBuilder actionBuilder) { - return createPushAction(PopMpls.class, in, actionBuilder); - } - - private static Action createPushPbbAction(ByteBuf in, ActionBuilder actionBuilder) { - return createPushAction(PushPbb.class, in, actionBuilder); - } - - private static Action createSetQueueAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(SetQueue.class); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - QueueIdActionBuilder queueId = new QueueIdActionBuilder(); - queueId.setQueueId(in.readUnsignedInt()); - actionBuilder.addAugmentation(QueueIdAction.class, queueId.build()); - return actionBuilder.build(); - } - - private static Action createGroupAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(Group.class); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - GroupIdActionBuilder group = new GroupIdActionBuilder(); - group.setGroupId(in.readUnsignedInt()); - actionBuilder.addAugmentation(GroupIdAction.class, group.build()); - return actionBuilder.build(); - } - - private static Action createSetNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(SetNwTtl.class); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); - nwTtl.setNwTtl(in.readUnsignedByte()); - actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); - in.skipBytes(PADDING_IN_NW_TTL_ACTIONS_HEADER); - return actionBuilder.build(); - } - - private Action createSetFieldAction(ByteBuf in, ActionBuilder actionBuilder) { - actionBuilder.setType(SetField.class); - int startIndex = in.readerIndex(); - in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); - int oxmClass = in.getUnsignedShort(in.readerIndex()); - // get oxm_field & hasMask byte and extract the field value - int oxmField = in.getUnsignedByte(in.readerIndex() - + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1; - OFDeserializer matchDeserializer = registry.getDeserializer( - new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass, - oxmField, MatchEntries.class)); - List entry = new ArrayList<>(); - entry.add(matchDeserializer.deserialize(in)); - matchEntries.setMatchEntries(entry); - actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); - int paddingRemainder = (in.readerIndex() - startIndex) % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - in.skipBytes(EncodeConstants.PADDING - paddingRemainder); - } - return actionBuilder.build(); - } - - @Override - public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { - registry = deserializerRegistry; - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodeKeyMakerFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodeKeyMakerFactory.java index f4002122..941140a0 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodeKeyMakerFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodeKeyMakerFactory.java @@ -47,11 +47,8 @@ public abstract class CodeKeyMakerFactory { return new AbstractCodeKeyMaker(version) { @Override public MessageCodeKey make(ByteBuf input) { - // EncodeConstants.EMPTY_VALUE used as temporary value - // until action deserializers are split -// int type = input.getUnsignedShort(input.readerIndex()); -// return new MessageCodeKey(getVersion(), type, Action.class); - return new MessageCodeKey(getVersion(), EncodeConstants.EMPTY_VALUE, Action.class); + int type = input.getUnsignedShort(input.readerIndex()); + return new MessageCodeKey(getVersion(), type, Action.class); } }; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java deleted file mode 100644 index 75be481a..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * 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.ArrayList; -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.MessageCodeKey; -import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -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.DlAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; -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.action.rev130731.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yangtools.yang.binding.Augmentation; - -import com.google.common.base.Joiner; - -/** - * Deserializes ofp_action (OpenFlow v1.0) structures - * @author michal.polkorab - */ -public class OF10ActionsDeserializer implements OFDeserializer, - DeserializerRegistryInjector { - - private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; - private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; - private static final byte PADDING_IN_STRIP_VLAN_ACTION = 4; - private static final byte PADDING_IN_SET_DL_ACTION = 6; - private static final byte PADDING_IN_NW_TOS_ACTION = 3; - private static final byte PADDING_IN_TP_ACTION = 2; - private static final byte PADDING_IN_ENQUEUE_ACTION = 6; - private DeserializerRegistry registry; - - @Override - public Action deserialize(ByteBuf input) { - int type = input.readUnsignedShort(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - ActionBuilder actionsBuilder = new ActionBuilder(); - Action actionsList = null; - switch(type) { - case 0: - actionsList = createOutputAction(input, actionsBuilder); - break; - case 1: - actionsList = createSetVlanVidAction(input, actionsBuilder); - break; - case 2: - actionsList = createVlanPcpAction(input, actionsBuilder); - break; - case 3: - actionsList = createStripVlanAction(input, actionsBuilder); - break; - case 4: - actionsList = createSetDlSrcAction(input, actionsBuilder); - break; - case 5: - actionsList = createSetDlDstAction(input, actionsBuilder); - break; - case 6: - actionsList = createSetNwSrcAction(input, actionsBuilder); - break; - case 7: - actionsList = createSetNwDstAction(input, actionsBuilder); - break; - case 8: - actionsList = createSetNwTosAction(input, actionsBuilder); - break; - case 9: - actionsList = createSetTpSrcAction(input, actionsBuilder); - break; - case 10: - actionsList = createSetTpDstAction(input, actionsBuilder); - break; - case 11: - actionsList = createEnqueueAction(input, actionsBuilder); - break; - case 0xFFFF: - OFDeserializer expDeserializer = registry.getDeserializer( - new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 0xFFFF, ExperimenterAction.class)); - expDeserializer.deserialize(input); - break; - default: - break; - } - return actionsList; - } - - /** - * @param in input ByteBuf - * @param builder - * @return ActionList - */ - public static Action createOutputAction(ByteBuf in, ActionBuilder builder) { - builder.setType(Output.class); - createPortAugmentation(in, builder); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(in.readUnsignedShort()); - builder.addAugmentation(MaxLengthAction.class, maxLen.build()); - return builder.build(); - } - - private static Action createSetVlanVidAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetVlanVid.class); - VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder(); - vlanBuilder.setVlanVid(input.readUnsignedShort()); - input.skipBytes(PADDING_IN_SET_VLAN_VID_ACTION); - builder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); - return builder.build(); - } - - private static Action createVlanPcpAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetVlanPcp.class); - VlanPcpActionBuilder vlanBuilder = new VlanPcpActionBuilder(); - vlanBuilder.setVlanPcp(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_SET_VLAN_PCP_ACTION); - builder.addAugmentation(VlanPcpAction.class, vlanBuilder.build()); - return builder.build(); - } - - private static Action createStripVlanAction(ByteBuf input, ActionBuilder builder) { - builder.setType(StripVlan.class); - input.skipBytes(PADDING_IN_STRIP_VLAN_ACTION); - return builder.build(); - } - - private static Action createSetDlSrcAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetDlSrc.class); - builder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); - return builder.build(); - } - - private static Action createSetDlDstAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetDlDst.class); - builder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); - return builder.build(); - } - - private static DlAddressAction createDlAugmentationAndPad(ByteBuf input) { - DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder(); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - input.readBytes(address); - dlBuilder.setDlAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); - input.skipBytes(PADDING_IN_SET_DL_ACTION); - return dlBuilder.build(); - } - - private static Action createSetNwSrcAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetNwSrc.class); - builder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); - return builder.build(); - } - - private static Action createSetNwDstAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetNwDst.class); - builder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); - return builder.build(); - } - - private static Augmentation createNwAddressAugmentationAndPad(ByteBuf input) { - IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - groups.add(Short.toString(input.readUnsignedByte())); - } - Joiner joiner = Joiner.on("."); - ipBuilder.setIpAddress(new Ipv4Address(joiner.join(groups))); - return ipBuilder.build(); - } - - private static Action createSetNwTosAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetNwTos.class); - NwTosActionBuilder tosBuilder = new NwTosActionBuilder(); - tosBuilder.setNwTos(input.readUnsignedByte()); - builder.addAugmentation(NwTosAction.class, tosBuilder.build()); - input.skipBytes(PADDING_IN_NW_TOS_ACTION); - return builder.build(); - } - - private static Action createSetTpSrcAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetTpSrc.class); - createPortAugmentation(input, builder); - input.skipBytes(PADDING_IN_TP_ACTION); - return builder.build(); - } - - private static Action createSetTpDstAction(ByteBuf input, ActionBuilder builder) { - builder.setType(SetTpDst.class); - createPortAugmentation(input, builder); - input.skipBytes(PADDING_IN_TP_ACTION); - return builder.build(); - } - - private static void createPortAugmentation(ByteBuf input, ActionBuilder actionBuilder) { - PortActionBuilder portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber((long) input.readUnsignedShort())); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - } - - private static Action createEnqueueAction(ByteBuf input, ActionBuilder builder) { - builder.setType(Enqueue.class); - createPortAugmentation(input, builder); - input.skipBytes(PADDING_IN_ENQUEUE_ACTION); - QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder(); - queueBuilder.setQueueId(input.readUnsignedInt()); - builder.addAugmentation(QueueIdAction.class, queueBuilder.build()); - return builder.build(); - } - - @Override - public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { - registry = deserializerRegistry; - } -}