From 774bedf030142fd05a31e02b21c4079745cf83f0 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Wed, 30 Apr 2014 17:56:11 +0200 Subject: [PATCH] Default experimenters moved to separate bundle + unit tests (ConfigSubsystem migration will be added later) Change-Id: Ia6477919fa56347d1e28fd329949b2fb4b852b55 Signed-off-by: Michal Polkorab --- .../src/main/yang/openflow-augments.yang | 3 + openflow-protocol-ext/pom.xml | 47 ++++++ ...ltExperimenterDeserializerInitializer.java | 18 +-- .../OF10StatsReplyVendorDeserializer.java | 35 +++++ .../OF10VendorActionDeserializer.java | 14 +- .../OF10VendorMessageDeserializer.java | 38 +++++ .../OF13ExperimenterActionDeserializer.java | 60 +++++++ ...3ExperimenterErrorMessageDeserializer.java | 36 +++++ ...13ExperimenterInstructionDeserializer.java | 13 +- .../OF13ExperimenterMessageDeserializer.java | 39 +++++ ...ultipartReplyExperimenterDeserializer.java | 36 +++++ ...etConfigReplyExperimenterDeserializer.java | 53 +++++++ ...TableFeaturesExperimenterDeserializer.java | 49 ++++++ .../DefaultExperimenterInitializer.java | 68 ++++++++ .../OF10StatsRequestVendorSerializer.java | 16 +- .../OF10VendorActionSerializer.java | 12 +- .../OF10VendorInputMessageFactory.java | 20 +-- .../OF13ExperimenterActionSerializer.java | 16 +- .../OF13ExperimenterInputMessageFactory.java | 22 +-- ...OF13ExperimenterInstructionSerializer.java | 12 +- .../OF13MeterBandExperimenterSerializer.java | 25 +-- .../OF13MultipartExperimenterSerializer.java | 21 +-- .../OF13TableFeatExpSerializer.java | 38 +++-- .../protocol/ext/util/ExtBufferUtils.java | 53 +++++++ .../protocol/ext/util/ExtConstants.java | 43 +++++ .../src/main/resources/log4j.xml | 20 +++ .../OF10StatsReplyVendorDeserializerTest.java | 59 +++++++ .../OF10VendorActionDeserializerTest.java | 114 ++++++++++++++ .../OF10VendorMessageDeserializerTest.java | 65 ++++++++ ...F13ExperimenterActionDeserializerTest.java | 114 ++++++++++++++ ...erimenterErrorMessageDeserializerTest.java | 63 ++++++++ ...perimenterInstructionDeserializerTest.java | 114 ++++++++++++++ ...13ExperimenterMessageDeserializerTest.java | 69 ++++++++ ...partReplyExperimenterDeserializerTest.java | 63 ++++++++ ...nfigReplyExperimenterDeserializerTest.java | 75 +++++++++ ...eFeaturesExperimenterDeserializerTest.java | 125 +++++++++++++++ .../OF10StatsRequestVendorSerializerTest.java | 65 ++++++++ .../OF10VendorActionSerializerTest.java | 79 ++++++++++ .../OF10VendorInputMessageFactoryTest.java | 77 +++++++++ .../OF13ExperimenterActionSerializerTest.java | 126 +++++++++++++++ ...13ExperimenterInputMessageFactoryTest.java | 77 +++++++++ ...ExperimenterInstructionSerializerTest.java | 126 +++++++++++++++ ...13MeterBandExperimenterSerializerTest.java | 51 ++++++ ...13MultipartExperimenterSerializerTest.java | 69 ++++++++ .../OF13TableFeatExpSerializerTest.java | 147 ++++++++++++++++++ .../DeserializerRegistryImpl.java | 2 - .../factories/ErrorMessageFactory.java | 35 +++-- .../MultipartReplyMessageFactory.java | 17 +- .../QueueGetConfigReplyMessageFactory.java | 36 +++-- .../DefaultExperimenterInitializer.java | 66 -------- .../serialization/SerializerRegistryImpl.java | 2 - .../MeterModInputMessageFactoryTest.java | 21 +-- .../MultipartRequestInputFactoryTest.java | 67 -------- .../OF10StatsRequestInputFactoryTest.java | 61 -------- .../OF10VendorInputMessageFactoryTest.java | 71 --------- ...13ExperimenterInputMessageFactoryTest.java | 72 --------- .../multipart/TableFeaturesTest.java | 43 +---- .../impl/util/OF10ActionsSerializerTest.java | 26 ---- .../impl/util/OF13ActionsSerializerTest.java | 26 ---- pom.xml | 1 + 60 files changed, 2442 insertions(+), 589 deletions(-) create mode 100644 openflow-protocol-ext/pom.xml rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext}/deserialization/DefaultExperimenterDeserializerInitializer.java (55%) create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializer.java rename openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializer.java (80%) create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializer.java rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization}/OF13ExperimenterInstructionDeserializer.java (81%) create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializer.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/DefaultExperimenterInitializer.java rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF10StatsRequestVendorSerializer.java (57%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF10VendorActionSerializer.java (79%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF10VendorInputMessageFactory.java (65%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13ExperimenterActionSerializer.java (77%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13ExperimenterInputMessageFactory.java (63%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13ExperimenterInstructionSerializer.java (78%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13MeterBandExperimenterSerializer.java (57%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13MultipartExperimenterSerializer.java (56%) rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters => openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization}/OF13TableFeatExpSerializer.java (63%) create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/util/ExtBufferUtils.java create mode 100644 openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/util/ExtConstants.java create mode 100644 openflow-protocol-ext/src/main/resources/log4j.xml create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactoryTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactoryTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInstructionSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MeterBandExperimenterSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializerTest.java create mode 100644 openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializerTest.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/DefaultExperimenterInitializer.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF13ExperimenterInputMessageFactoryTest.java diff --git a/openflow-protocol-api/src/main/yang/openflow-augments.yang b/openflow-protocol-api/src/main/yang/openflow-augments.yang index 4f274d4c..ed6d01d1 100644 --- a/openflow-protocol-api/src/main/yang/openflow-augments.yang +++ b/openflow-protocol-api/src/main/yang/openflow-augments.yang @@ -379,6 +379,9 @@ leaf experimenter { type uint32; } + leaf data { + type binary; + } } } \ No newline at end of file diff --git a/openflow-protocol-ext/pom.xml b/openflow-protocol-ext/pom.xml new file mode 100644 index 00000000..171aa3f6 --- /dev/null +++ b/openflow-protocol-ext/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + org.opendaylight.openflowjava + openflow-protocol-parent + 0.5-SNAPSHOT + + org.opendaylight.openflowjava + openflow-protocol-ext + 0.5-SNAPSHOT + bundle + Openflow Protocol Library - EXT + http://maven.apache.org + + https://wiki.opendaylight.org/view/Openflow_Protocol_Library:Main + HEAD + + + + + ${project.groupId} + openflow-protocol-api + ${project.version} + + + ${project.groupId} + openflow-protocol-spi + ${project.version} + + + io.netty + netty-buffer + + + junit + junit + test + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/DefaultExperimenterDeserializerInitializer.java similarity index 55% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/DefaultExperimenterDeserializerInitializer.java index 44115fad..9dde85e3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DefaultExperimenterDeserializerInitializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/DefaultExperimenterDeserializerInitializer.java @@ -6,13 +6,11 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; +package org.opendaylight.openflowjava.protocol.ext.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.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; 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; @@ -29,14 +27,14 @@ public class DefaultExperimenterDeserializerInitializer { public static void registerDeserializers(DeserializerRegistry registry) { // 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()); + registry.registerDeserializer(new MessageCodeKey(ExtConstants.OF10_VERSION_ID, + ExtConstants.EXPERIMENTER_VALUE, Action.class), new OF13ExperimenterActionDeserializer()); // 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()); + registry.registerDeserializer(new MessageCodeKey(ExtConstants.OF13_VERSION_ID, + ExtConstants.EXPERIMENTER_VALUE, Action.class), new OF13ExperimenterActionDeserializer()); // - default instruction deserializer - registry.registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, - EncodeConstants.EXPERIMENTER_VALUE, Instruction.class), new OF13ExperimenterInstructionDeserializer()); + registry.registerDeserializer(new MessageCodeKey(ExtConstants.OF13_VERSION_ID, + ExtConstants.EXPERIMENTER_VALUE, Instruction.class), new OF13ExperimenterInstructionDeserializer()); } } diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializer.java new file mode 100644 index 00000000..f2447447 --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializer.java @@ -0,0 +1,35 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10StatsReplyVendorDeserializer implements OFDeserializer { + + @Override + public MultipartReplyExperimenter deserialize(ByteBuf message) { + MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); + builder.setExperimenter(message.readUnsignedInt()); + if (message.readableBytes() > 0) { + byte[] data = new byte[message.readableBytes()]; + message.readBytes(data); + builder.setData(data); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializer.java similarity index 80% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializer.java index 316d970f..f52d8310 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/ExperimenterActionDeserializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializer.java @@ -6,13 +6,13 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.deserialization; 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.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; 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; @@ -23,15 +23,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 * @author michal.polkorab * */ -public class ExperimenterActionDeserializer implements OFDeserializer, +public class OF10VendorActionDeserializer implements OFDeserializer, HeaderDeserializer { @Override public Action deserializeHeader(ByteBuf input) { ActionBuilder builder = new ActionBuilder(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + input.skipBytes(ExtConstants.SIZE_OF_SHORT_IN_BYTES); builder.setType(Experimenter.class); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + input.skipBytes(ExtConstants.SIZE_OF_SHORT_IN_BYTES); ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); expBuilder.setExperimenter(input.readUnsignedInt()); builder.addAugmentation(ExperimenterAction.class, expBuilder.build()); @@ -41,11 +41,11 @@ public class ExperimenterActionDeserializer implements OFDeserializer, @Override public Action deserialize(ByteBuf input) { ActionBuilder builder = new ActionBuilder(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + input.skipBytes(ExtConstants.SIZE_OF_SHORT_IN_BYTES); builder.setType(Experimenter.class); int length = input.readUnsignedShort(); // subtract experimenter header length - length -= EncodeConstants.EXPERIMENTER_IDS_LENGTH; + length -= ExtConstants.EXPERIMENTER_IDS_LENGTH; ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); expBuilder.setExperimenter(input.readUnsignedInt()); if (length > 0) { diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializer.java new file mode 100644 index 00000000..493b35af --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializer.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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10VendorMessageDeserializer implements OFDeserializer { + + @Override + public ExperimenterMessage deserialize(ByteBuf message) { + ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); + builder.setVersion((short) ExtConstants.OF10_VERSION_ID); + builder.setXid(message.readUnsignedInt()); + builder.setExperimenter(message.readUnsignedInt()); + if (message.readableBytes() > 0) { + byte[] data = new byte[message.readableBytes()]; + message.readBytes(data); + builder.setData(data); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializer.java new file mode 100644 index 00000000..0da1c33f --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializer.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.ext.deserialization; + +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.ext.util.ExtConstants; +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 OF13ExperimenterActionDeserializer implements OFDeserializer, + HeaderDeserializer { + + @Override + public Action deserializeHeader(ByteBuf input) { + ActionBuilder builder = new ActionBuilder(); + input.skipBytes(ExtConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(Experimenter.class); + input.skipBytes(ExtConstants.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(ExtConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setType(Experimenter.class); + int length = input.readUnsignedShort(); + // subtract experimenter header length + length -= ExtConstants.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-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializer.java new file mode 100644 index 00000000..2239d119 --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializer.java @@ -0,0 +1,36 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterErrorBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterErrorMessageDeserializer implements OFDeserializer { + + @Override + public ExperimenterError deserialize(ByteBuf message) { + ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder(); + expBuilder.setExpType(message.readUnsignedShort()); + expBuilder.setExperimenter(message.readUnsignedInt()); + if (message.readableBytes() > 0) { + byte[] data = new byte[message.readableBytes()]; + message.readBytes(data); + expBuilder.setData(data); + } + return expBuilder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/OF13ExperimenterInstructionDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializer.java similarity index 81% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/OF13ExperimenterInstructionDeserializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializer.java index ab14cf66..c6a3b389 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/experimenters/OF13ExperimenterInstructionDeserializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializer.java @@ -6,13 +6,13 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.deserialization; 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.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; @@ -29,20 +29,21 @@ public class OF13ExperimenterInstructionDeserializer implements OFDeserializer 0) { diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializer.java new file mode 100644 index 00000000..43b0356f --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializer.java @@ -0,0 +1,39 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterMessageDeserializer implements OFDeserializer { + + @Override + public ExperimenterMessage deserialize(ByteBuf message) { + ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); + builder.setVersion((short) ExtConstants.OF13_VERSION_ID); + builder.setXid(message.readUnsignedInt()); + builder.setExperimenter(message.readUnsignedInt()); + builder.setExpType(message.readUnsignedInt()); + if (message.readableBytes() > 0) { + byte[] data = new byte[message.readableBytes()]; + message.readBytes(data); + builder.setData(data); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializer.java new file mode 100644 index 00000000..138bb702 --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializer.java @@ -0,0 +1,36 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13MultipartReplyExperimenterDeserializer implements OFDeserializer { + + @Override + public MultipartReplyExperimenter deserialize(ByteBuf message) { + MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); + builder.setExperimenter(message.readUnsignedInt()); + builder.setExpType(message.readUnsignedInt()); + if (message.readableBytes() > 0) { + byte[] data = new byte[message.readableBytes()]; + message.readBytes(data); + builder.setData(data); + } + return builder.build(); + } + +} \ No newline at end of file diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializer.java new file mode 100644 index 00000000..87bcff00 --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializer.java @@ -0,0 +1,53 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13QueueGetConfigReplyExperimenterDeserializer + implements OFDeserializer { + + private static final int PADDING_IN_QUEUE_PROPERTY_HEADER = 4; + private static final int PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY = 4; + + @Override + public QueueProperty deserialize(ByteBuf input) { + QueuePropertyBuilder builder = new QueuePropertyBuilder(); + QueueProperties property = QueueProperties.forValue(input.readUnsignedShort()); + builder.setProperty(property); + int length = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); + ExperimenterQueuePropertyBuilder expBuilder = new ExperimenterQueuePropertyBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY); + // extract experimenter_data length + length = length - 2 * ExtConstants.SIZE_OF_SHORT_IN_BYTES - PADDING_IN_QUEUE_PROPERTY_HEADER + - ExtConstants.SIZE_OF_INT_IN_BYTES - PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY; + if (length > 0) { + byte[] data = new byte[length]; + input.readBytes(data); + expBuilder.setData(data); + } + builder.addAugmentation(ExperimenterQueueProperty.class, expBuilder.build()); + return builder.build(); + } + +} diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializer.java new file mode 100644 index 00000000..ef9a811e --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializer.java @@ -0,0 +1,49 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13TableFeaturesExperimenterDeserializer + implements OFDeserializer{ + + @Override + public TableFeatureProperties deserialize(ByteBuf input) { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort()); + builder.setType(type); + int length = input.readUnsignedShort(); + ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = + new ExperimenterRelatedTableFeaturePropertyBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + expBuilder.setExpType(input.readUnsignedInt()); + // extract experimenter_data length + length = length - 2 * ExtConstants.SIZE_OF_SHORT_IN_BYTES - 2 * ExtConstants.SIZE_OF_INT_IN_BYTES; + if (length > 0) { + byte[] data = new byte[length]; + input.readBytes(data); + expBuilder.setData(data); + } + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); + return builder.build(); + } + +} diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/DefaultExperimenterInitializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/DefaultExperimenterInitializer.java new file mode 100644 index 00000000..a3509fab --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/DefaultExperimenterInitializer.java @@ -0,0 +1,68 @@ +/* + * 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.ext.serialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +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.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; + +/** + * @author michal.polkorab + * + */ +public class DefaultExperimenterInitializer { + + /** + * Registers message serializers into provided registry + * @param registry registry to be initialized with message serializers + */ + public static void registerDefaultExperimenterSerializers(SerializerRegistry registry) { + // register OF v1.0 default experimenter serializers + short version = ExtConstants.OF10_VERSION_ID; + // - default vendor (experimenter) message serializer + registry.registerSerializer(new MessageTypeKey<>(version, ExperimenterInput.class), + new OF10VendorInputMessageFactory()); + // - default vendor (experimenter) action serializer + registry.registerSerializer(new EnhancedMessageTypeKey<>(version, Action.class, + Experimenter.class), new OF10VendorActionSerializer()); + // - default vendor stats (experimenter multipart) serializer + registry.registerSerializer(new MessageTypeKey<>(version, MultipartRequestExperimenter.class), + new OF10StatsRequestVendorSerializer()); + + // register OF v1.3 default experimenter serializers + version = ExtConstants.OF13_VERSION_ID; + // - default experimenter message serializer + registry.registerSerializer(new MessageTypeKey<>(version, ExperimenterInput.class), + new OF13ExperimenterInputMessageFactory()); + // - default experimenter action serializer + registry.registerSerializer(new EnhancedMessageTypeKey<>(version, Action.class, + Experimenter.class), new OF13ExperimenterActionSerializer()); + // - default vendor stats (experimenter multipart) serializer + registry.registerSerializer(new MessageTypeKey<>(version, MultipartRequestExperimenter.class), + new OF13MultipartExperimenterSerializer()); + // - default experimenter instruction serializer + registry.registerSerializer(new EnhancedMessageTypeKey<>(version, Instruction.class, + org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common + .instruction.rev130731.Experimenter.class), new OF13ExperimenterInstructionSerializer()); + // - default experimenter message serializer + registry.registerSerializer(new MessageTypeKey<>(version, TableFeatureProperties.class), + new OF13TableFeatExpSerializer()); + // - default experimenter message serializer + registry.registerSerializer(new MessageTypeKey<>(version, MeterBandExperimenter.class), + new OF13MeterBandExperimenterSerializer()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10StatsRequestVendorSerializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializer.java similarity index 57% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10StatsRequestVendorSerializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializer.java index 37d9212d..a2f94f3e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10StatsRequestVendorSerializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializer.java @@ -1,18 +1,22 @@ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; +/** + * @author michal.polkorab + * + */ public class OF10StatsRequestVendorSerializer implements OFSerializer{ - @Override - public void serialize(MultipartRequestExperimenter input, ByteBuf outBuffer) { - outBuffer.writeInt(input.getExperimenter().intValue()); + @Override + public void serialize(MultipartRequestExperimenter input, ByteBuf outBuffer) { + outBuffer.writeInt(input.getExperimenter().intValue()); if (input.getData() != null) { - outBuffer.writeBytes(input.getData()); + outBuffer.writeBytes(input.getData()); } - } + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorActionSerializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializer.java similarity index 79% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorActionSerializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializer.java index db950929..83d20ad7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorActionSerializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializer.java @@ -6,23 +6,27 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +/** + * @author michal.polkorab + * + */ public class OF10VendorActionSerializer implements OFSerializer { @Override public void serialize(Action action, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); + outBuffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); int lengthIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(ExtConstants.EMPTY_LENGTH); ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); outBuffer.writeInt(experimenter.getExperimenter().intValue()); byte[] data = experimenter.getData(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorInputMessageFactory.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactory.java similarity index 65% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorInputMessageFactory.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactory.java index 2a9cfb66..ef1f7633 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF10VendorInputMessageFactory.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactory.java @@ -6,13 +6,13 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtBufferUtils; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; /** @@ -22,16 +22,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class OF10VendorInputMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 4; - - @Override - public void serialize(ExperimenterInput input, ByteBuf outBuffer) { - ByteBufUtils.writeOFHeader(MESSAGE_TYPE, input, outBuffer, EncodeConstants.EMPTY_LENGTH); + + @Override + public void serialize(ExperimenterInput input, ByteBuf outBuffer) { + ExtBufferUtils.writeOFHeader(MESSAGE_TYPE, input, outBuffer, ExtConstants.EMPTY_LENGTH); outBuffer.writeInt(input.getExperimenter().intValue()); byte[] data = input.getData(); if (data != null) { outBuffer.writeBytes(data); } - ByteBufUtils.updateOFHeaderLength(outBuffer); - } - + ExtBufferUtils.updateOFHeaderLength(outBuffer); + } + } \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterActionSerializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializer.java similarity index 77% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterActionSerializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializer.java index a2f320f0..c0fbb480 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterActionSerializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializer.java @@ -6,25 +6,29 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +/** + * @author michal.polkorab + * + */ public class OF13ExperimenterActionSerializer implements OFSerializer, HeaderSerializer { @Override public void serialize(Action action, ByteBuf outBuffer) { int actionStartIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); + outBuffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); int actionLengthIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(ExtConstants.EMPTY_LENGTH); ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class); outBuffer.writeInt(expAction.getExperimenter().intValue()); if (expAction.getData() != null) { @@ -35,8 +39,8 @@ public class OF13ExperimenterActionSerializer implements OFSerializer, @Override public void serializeHeader(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); - outBuffer.writeShort(EncodeConstants.EXPERIMENTER_IDS_LENGTH); + outBuffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + outBuffer.writeShort(ExtConstants.EXPERIMENTER_IDS_LENGTH); ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class); outBuffer.writeInt(expAction.getExperimenter().intValue()); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterInputMessageFactory.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactory.java similarity index 63% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterInputMessageFactory.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactory.java index 58b2b68e..0b5752c8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13ExperimenterInputMessageFactory.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactory.java @@ -6,13 +6,13 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtBufferUtils; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; /** @@ -24,17 +24,17 @@ public class OF13ExperimenterInputMessageFactory implements OFSerializer { +/** + * @author michal.polkorab + * + */ +public class OF13MeterBandExperimenterSerializer implements OFSerializer { - @Override - public void serialize(MeterBandExperimenter meterBand, ByteBuf outBuffer) { - int startIndex = outBuffer.writerIndex(); - outBuffer.writeShort(meterBand.getType().getIntValue()); - int lengthIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + @Override + public void serialize(MeterBandExperimenter meterBand, ByteBuf outBuffer) { + int startIndex = outBuffer.writerIndex(); + outBuffer.writeShort(meterBand.getType().getIntValue()); + int lengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(ExtConstants.EMPTY_LENGTH); outBuffer.writeInt(meterBand.getRate().intValue()); outBuffer.writeInt(meterBand.getBurstSize().intValue()); outBuffer.writeInt(meterBand.getExperimenter().intValue()); if (meterBand.getData() != null) { - outBuffer.writeBytes(meterBand.getData()); + outBuffer.writeBytes(meterBand.getData()); } outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13MultipartExperimenterSerializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializer.java similarity index 56% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13MultipartExperimenterSerializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializer.java index 42002a4a..d018bf75 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13MultipartExperimenterSerializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializer.java @@ -6,23 +6,26 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; -public class OF13MultipartExperimenterSerializer - implements OFSerializer { +/** + * @author michal.polkorab + * + */ +public class OF13MultipartExperimenterSerializer implements OFSerializer { - @Override - public void serialize(MultipartRequestExperimenter input, ByteBuf outBuffer) { - outBuffer.writeInt(input.getExperimenter().intValue()); - outBuffer.writeInt(input.getExpType().intValue()); + @Override + public void serialize(MultipartRequestExperimenter input, ByteBuf outBuffer) { + outBuffer.writeInt(input.getExperimenter().intValue()); + outBuffer.writeInt(input.getExpType().intValue()); if (input.getData() != null) { - outBuffer.writeBytes(input.getData()); + outBuffer.writeBytes(input.getData()); } - } + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13TableFeatExpSerializer.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializer.java similarity index 63% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13TableFeatExpSerializer.java rename to openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializer.java index 2c4f49f1..5eba6bf1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/experimenters/OF13TableFeatExpSerializer.java +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializer.java @@ -6,32 +6,36 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters; +package org.opendaylight.openflowjava.protocol.ext.serialization; import io.netty.buffer.ByteBuf; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.ext.util.ExtBufferUtils; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; +/** + * @author michal.polkorab + * + */ public class OF13TableFeatExpSerializer implements OFSerializer { private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF - @Override - public void serialize(TableFeatureProperties property, ByteBuf outBuffer) { - int startIndex = outBuffer.writerIndex(); - if (property.getType().equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) { - outBuffer.writeShort(EXPERIMENTER_CODE); - } else { - outBuffer.writeShort(EXPERIMENTER_MISS_CODE); - } - int lengthIndex = outBuffer.writerIndex(); - outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + @Override + public void serialize(TableFeatureProperties property, ByteBuf outBuffer) { + int startIndex = outBuffer.writerIndex(); + if (property.getType().equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) { + outBuffer.writeShort(EXPERIMENTER_CODE); + } else { + outBuffer.writeShort(EXPERIMENTER_MISS_CODE); + } + int lengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(ExtConstants.EMPTY_LENGTH); ExperimenterRelatedTableFeatureProperty exp = property. getAugmentation(ExperimenterRelatedTableFeatureProperty.class); outBuffer.writeInt(exp.getExperimenter().intValue()); @@ -40,12 +44,12 @@ public class OF13TableFeatExpSerializer implements OFSerializer void writeOFHeader(byte msgType, E message, ByteBuf out, int length) { + out.writeByte(message.getVersion()); + out.writeByte(msgType); + out.writeShort(length); + out.writeInt(message.getXid().intValue()); + } + + /** + * Write length standard OF header + * @param out writing buffer + */ + public static void updateOFHeaderLength(ByteBuf out) { + out.setShort(ExtConstants.OFHEADER_LENGTH_INDEX, out.readableBytes()); + } + + /** + * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding + * @param length + * @param out ByteBuf to be padded + */ + public static void padBuffer(int length, ByteBuf out) { + for (int i = 0; i < length; i++) { + out.writeByte(0); + } + } +} diff --git a/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/util/ExtConstants.java b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/util/ExtConstants.java new file mode 100644 index 00000000..80c384f3 --- /dev/null +++ b/openflow-protocol-ext/src/main/java/org/opendaylight/openflowjava/protocol/ext/util/ExtConstants.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.ext.util; + +/** + * @author michal.polkorab + * + */ +public class ExtConstants { + + /** Default OF padding (in bytes) */ + public static final byte PADDING = 8; + /** OpenFlow v1.0 wire protocol number */ + public static final byte OF10_VERSION_ID = 0x01; + /** OpenFlow v1.0 wire protocol number */ + public static final byte OF13_VERSION_ID = 0x04; + /** Index of length in Openflow header */ + public static final int OFHEADER_LENGTH_INDEX = 2; + /** Zero length - used when the length is updated later */ + public static final int EMPTY_LENGTH = 0; + + /** Length of long in bytes */ + public static final byte SIZE_OF_LONG_IN_BYTES = Long.SIZE / Byte.SIZE; + /** Length of int in bytes */ + public static final byte SIZE_OF_INT_IN_BYTES = Integer.SIZE / Byte.SIZE; + /** Length of short in bytes */ + public static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE; + /** Length of byte in bytes */ + public static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE; + /** Length of 3 bytes */ + public static final byte SIZE_OF_3_BYTES = 3; + + /** Common experimenter value */ + public static final int EXPERIMENTER_VALUE = 0xFFFF; + /** OF v1.3 lenght of experimenter_ids - see Multipart TableFeatures (properties) message */ + public static final byte EXPERIMENTER_IDS_LENGTH = 8; +} diff --git a/openflow-protocol-ext/src/main/resources/log4j.xml b/openflow-protocol-ext/src/main/resources/log4j.xml new file mode 100644 index 00000000..a51c5b5b --- /dev/null +++ b/openflow-protocol-ext/src/main/resources/log4j.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializerTest.java new file mode 100644 index 00000000..8979b7dd --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10StatsReplyVendorDeserializerTest.java @@ -0,0 +1,59 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter; + +/** + * @author michal.polkorab + * + */ +public class OF10StatsReplyVendorDeserializerTest { + + /** + * Testing of {@link OF10StatsReplyVendorDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 3, 2, 1, 0}; + buffer.writeBytes(data); + + OF10StatsReplyVendorDeserializer deserializer = + new OF10StatsReplyVendorDeserializer(); + MultipartReplyExperimenter message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong experimenter", 42, message.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, message.getData()); + } + + /** + * Testing of {@link OF10StatsReplyVendorDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(42); + + OF10StatsReplyVendorDeserializer deserializer = + new OF10StatsReplyVendorDeserializer(); + MultipartReplyExperimenter message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong experimenter", 42, message.getExperimenter().intValue()); + Assert.assertNull("Unexpected data", message.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializerTest.java new file mode 100644 index 00000000..46f4a410 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorActionDeserializerTest.java @@ -0,0 +1,114 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +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; + +/** + * @author michal.polkorab + * + */ +public class OF10VendorActionDeserializerTest { + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(16); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF10VendorActionDeserializer deserializer = + new OF10VendorActionDeserializer(); + Action action = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF10VendorActionDeserializer deserializer = + new OF10VendorActionDeserializer(); + Action action = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeader() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF10VendorActionDeserializer deserializer = + new OF10VendorActionDeserializer(); + Action action = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeaderWithData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF10VendorActionDeserializer deserializer = + new OF10VendorActionDeserializer(); + Action action = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializerTest.java new file mode 100644 index 00000000..76514bd8 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF10VendorMessageDeserializerTest.java @@ -0,0 +1,65 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; + +/** + * @author michal.polkorab + * + */ +public class OF10VendorMessageDeserializerTest { + + /** + * Testing of {@link OF10VendorMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(12345); + buffer.writeInt(98765); + byte[] data = new byte[]{5, 6, 7, 8}; + buffer.writeBytes(data); + + OF10VendorMessageDeserializer deserializer = + new OF10VendorMessageDeserializer(); + ExperimenterMessage message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong version", 1, message.getVersion().shortValue()); + Assert.assertEquals("Wrong XID", 12345, message.getXid().intValue()); + Assert.assertEquals("Wrong experimenter", 98765, message.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, message.getData()); + } + + /** + * Testing of {@link OF10VendorMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(12345); + buffer.writeInt(98765); + + OF10VendorMessageDeserializer deserializer = + new OF10VendorMessageDeserializer(); + ExperimenterMessage message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong version", 1, message.getVersion().shortValue()); + Assert.assertEquals("Wrong XID", 12345, message.getXid().intValue()); + Assert.assertEquals("Wrong experimenter", 98765, message.getExperimenter().intValue()); + Assert.assertNull("Unexpected data", message.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializerTest.java new file mode 100644 index 00000000..4ea3bf3c --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterActionDeserializerTest.java @@ -0,0 +1,114 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +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; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterActionDeserializerTest { + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(16); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF13ExperimenterActionDeserializer deserializer = + new OF13ExperimenterActionDeserializer(); + Action action = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF13ExperimenterActionDeserializer deserializer = + new OF13ExperimenterActionDeserializer(); + Action action = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeader() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF13ExperimenterActionDeserializer deserializer = + new OF13ExperimenterActionDeserializer(); + Action action = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeaderWithData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF13ExperimenterActionDeserializer deserializer = + new OF13ExperimenterActionDeserializer(); + Action action = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, action.getType()); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializerTest.java new file mode 100644 index 00000000..e37f62e4 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterErrorMessageDeserializerTest.java @@ -0,0 +1,63 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterErrorMessageDeserializerTest { + + /** + * Testing of {@link OF13ExperimenterErrorMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(35000); + buffer.writeInt(70000); + byte[] data = new byte[]{5, 5, 5, 6, 7, 8, 9, 10}; + buffer.writeBytes(data); + + OF13ExperimenterErrorMessageDeserializer deserializer = + new OF13ExperimenterErrorMessageDeserializer(); + ExperimenterError message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong exp-type", 35000, message.getExpType().intValue()); + Assert.assertEquals("Wrong experimenter", 70000, message.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, message.getData()); + } + + /** + * Testing of {@link OF13ExperimenterErrorMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(35000); + buffer.writeInt(70000); + + OF13ExperimenterErrorMessageDeserializer deserializer = + new OF13ExperimenterErrorMessageDeserializer(); + ExperimenterError message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong exp-type", 35000, message.getExpType().intValue()); + Assert.assertEquals("Wrong experimenter", 70000, message.getExperimenter().intValue()); + Assert.assertNull("Unexpected data", message.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializerTest.java new file mode 100644 index 00000000..bd9f8db0 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterInstructionDeserializerTest.java @@ -0,0 +1,114 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterInstructionDeserializerTest { + + /** + * Testing of {@link OF13ExperimenterInstructionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF13ExperimenterInstructionDeserializer deserializer = + new OF13ExperimenterInstructionDeserializer(); + Instruction instruction = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, instruction.getType()); + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterInstructionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF13ExperimenterInstructionDeserializer deserializer = + new OF13ExperimenterInstructionDeserializer(); + Instruction instruction = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, instruction.getType()); + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterInstructionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeader() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + + OF13ExperimenterInstructionDeserializer deserializer = + new OF13ExperimenterInstructionDeserializer(); + Instruction instruction = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, instruction.getType()); + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } + + /** + * Testing of {@link OF13ExperimenterInstructionDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testHeaderWithData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(8); + buffer.writeInt(42); + byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0}; + buffer.writeBytes(data); + + OF13ExperimenterInstructionDeserializer deserializer = + new OF13ExperimenterInstructionDeserializer(); + Instruction instruction = deserializer.deserializeHeader(buffer); + + Assert.assertEquals("Wrong type", Experimenter.class, instruction.getType()); + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue()); + Assert.assertNull("Data not null", experimenter.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializerTest.java new file mode 100644 index 00000000..f5cc9619 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13ExperimenterMessageDeserializerTest.java @@ -0,0 +1,69 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterMessageDeserializerTest { + + /** + * Testing of {@link OF13ExperimenterMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(12345); + buffer.writeInt(98765); + buffer.writeInt(89123); + byte[] data = new byte[]{5, 6, 7, 8}; + buffer.writeBytes(data); + + OF13ExperimenterMessageDeserializer deserializer = + new OF13ExperimenterMessageDeserializer(); + ExperimenterMessage message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong version", 4, message.getVersion().shortValue()); + Assert.assertEquals("Wrong XID", 12345, message.getXid().intValue()); + Assert.assertEquals("Wrong experimenter", 98765, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 89123, message.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", data, message.getData()); + } + + /** + * Testing of {@link OF13ExperimenterMessageDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(12345); + buffer.writeInt(98765); + buffer.writeInt(89123); + + OF13ExperimenterMessageDeserializer deserializer = + new OF13ExperimenterMessageDeserializer(); + ExperimenterMessage message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong version", 4, message.getVersion().shortValue()); + Assert.assertEquals("Wrong XID", 12345, message.getXid().intValue()); + Assert.assertEquals("Wrong experimenter", 98765, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 89123, message.getExpType().intValue()); + Assert.assertNull("Unexpected data", message.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializerTest.java new file mode 100644 index 00000000..ad36b542 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13MultipartReplyExperimenterDeserializerTest.java @@ -0,0 +1,63 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter; + +/** + * @author michal.polkorab + * + */ +public class OF13MultipartReplyExperimenterDeserializerTest { + + /** + * Testing of {@link OF13MultipartReplyExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(456654); + buffer.writeInt(888222); + byte[] data = new byte[]{0, 0, 1, 1, 2, 2, 3, 3}; + buffer.writeBytes(data); + + OF13MultipartReplyExperimenterDeserializer deserializer = + new OF13MultipartReplyExperimenterDeserializer(); + MultipartReplyExperimenter message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong experimenter", 456654, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 888222, message.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", data, message.getData()); + } + + /** + * Testing of {@link OF13MultipartReplyExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeInt(456654); + buffer.writeInt(888222); + + OF13MultipartReplyExperimenterDeserializer deserializer = + new OF13MultipartReplyExperimenterDeserializer(); + MultipartReplyExperimenter message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong experimenter", 456654, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 888222, message.getExpType().intValue()); + Assert.assertNull("Unexpected data", message.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializerTest.java new file mode 100644 index 00000000..b11d466d --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13QueueGetConfigReplyExperimenterDeserializerTest.java @@ -0,0 +1,75 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.ext.util.ExtBufferUtils; +import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; + +/** + * @author michal.polkorab + * + */ +public class OF13QueueGetConfigReplyExperimenterDeserializerTest { + + /** + * Testing of {@link OF13QueueGetConfigReplyExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void test() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(24); + ExtBufferUtils.padBuffer(4, buffer); + buffer.writeInt(128); + ExtBufferUtils.padBuffer(4, buffer); + byte[] data = new byte[]{0, 0, 1, 1, 2, 2, 3, 3}; + buffer.writeBytes(data); + + OF13QueueGetConfigReplyExperimenterDeserializer deserializer = + new OF13QueueGetConfigReplyExperimenterDeserializer(); + QueueProperty message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong property", QueueProperties.OFPQTEXPERIMENTER, message.getProperty()); + ExperimenterQueueProperty exp = message.getAugmentation(ExperimenterQueueProperty.class); + Assert.assertEquals("Wrong experimenter", 128, exp.getExperimenter().intValue()); + Assert.assertArrayEquals("Wrong data", data, exp.getData()); + } + + /** + * Testing of {@link OF13QueueGetConfigReplyExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE); + buffer.writeShort(16); + ExtBufferUtils.padBuffer(4, buffer); + buffer.writeInt(128); + ExtBufferUtils.padBuffer(4, buffer); + + OF13QueueGetConfigReplyExperimenterDeserializer deserializer = + new OF13QueueGetConfigReplyExperimenterDeserializer(); + QueueProperty message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong property", QueueProperties.OFPQTEXPERIMENTER, message.getProperty()); + ExperimenterQueueProperty exp = message.getAugmentation(ExperimenterQueueProperty.class); + Assert.assertEquals("Wrong experimenter", 128, exp.getExperimenter().intValue()); + Assert.assertNull("Unexpected data", exp.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializerTest.java new file mode 100644 index 00000000..600a36fd --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/deserialization/OF13TableFeaturesExperimenterDeserializerTest.java @@ -0,0 +1,125 @@ +/* + * 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.ext.deserialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; + +/** + * @author michal.polkorab + * + */ +public class OF13TableFeaturesExperimenterDeserializerTest { + + /** + * Testing of {@link OF13TableFeaturesExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testExperimenter() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(65534); + buffer.writeShort(16); + buffer.writeInt(256); + buffer.writeInt(546); + byte[] data = new byte[]{1, 2, 3, 4}; + buffer.writeBytes(data); + + OF13TableFeaturesExperimenterDeserializer deserializer = + new OF13TableFeaturesExperimenterDeserializer(); + TableFeatureProperties message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", TableFeaturesPropType.OFPTFPTEXPERIMENTER, message.getType()); + ExperimenterRelatedTableFeatureProperty property = + message.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + Assert.assertEquals("Wrong experimenter", 256, property.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 546, property.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", data, property.getData()); + } + + /** + * Testing of {@link OF13TableFeaturesExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testExperimenterWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(65534); + buffer.writeShort(12); + buffer.writeInt(256); + buffer.writeInt(546); + + OF13TableFeaturesExperimenterDeserializer deserializer = + new OF13TableFeaturesExperimenterDeserializer(); + TableFeatureProperties message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", TableFeaturesPropType.OFPTFPTEXPERIMENTER, message.getType()); + ExperimenterRelatedTableFeatureProperty property = + message.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + Assert.assertEquals("Wrong experimenter", 256, property.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 546, property.getExpType().intValue()); + Assert.assertNull("Unexpected data", property.getData()); + } + + /** + * Testing of {@link OF13TableFeaturesExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testExperimenterMiss() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(65535); + buffer.writeShort(16); + buffer.writeInt(256); + buffer.writeInt(546); + byte[] data = new byte[]{1, 2, 3, 4}; + buffer.writeBytes(data); + + OF13TableFeaturesExperimenterDeserializer deserializer = + new OF13TableFeaturesExperimenterDeserializer(); + TableFeatureProperties message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS, message.getType()); + ExperimenterRelatedTableFeatureProperty property = + message.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + Assert.assertEquals("Wrong experimenter", 256, property.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 546, property.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", data, property.getData()); + } + + /** + * Testing of {@link OF13TableFeaturesExperimenterDeserializer} for correct translation into POJO + * @throws Exception + */ + @Test + public void testExperimenterMissWithoutData() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + buffer.writeShort(65535); + buffer.writeShort(12); + buffer.writeInt(256); + buffer.writeInt(546); + + OF13TableFeaturesExperimenterDeserializer deserializer = + new OF13TableFeaturesExperimenterDeserializer(); + TableFeatureProperties message = deserializer.deserialize(buffer); + + Assert.assertEquals("Wrong type", TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS, message.getType()); + ExperimenterRelatedTableFeatureProperty property = + message.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + Assert.assertEquals("Wrong experimenter", 256, property.getExperimenter().intValue()); + Assert.assertEquals("Wrong exp-type", 546, property.getExpType().intValue()); + Assert.assertNull("Unexpected data", property.getData()); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializerTest.java new file mode 100644 index 00000000..e5fd1f6b --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10StatsRequestVendorSerializerTest.java @@ -0,0 +1,65 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10StatsRequestVendorSerializerTest { + + /** + * Testing of {@link OF10StatsRequestVendorSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() { + MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); + expBuilder.setExperimenter(42L); + byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; + expBuilder.setData(data); + MultipartRequestExperimenter message = expBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10StatsRequestVendorSerializer serializer = new OF10StatsRequestVendorSerializer(); + serializer.serialize(message, buffer); + + Assert.assertEquals("Wrong experimenter", 42, buffer.readUnsignedInt()); + byte[] expData = new byte[8]; + buffer.readBytes(expData); + Assert.assertArrayEquals("Wrong experimenter data", data, expData); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF10StatsRequestVendorSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); + expBuilder.setExperimenter(42L); + MultipartRequestExperimenter message = expBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10StatsRequestVendorSerializer serializer = new OF10StatsRequestVendorSerializer(); + serializer.serialize(message, buffer); + + Assert.assertEquals("Wrong experimenter", 42, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializerTest.java new file mode 100644 index 00000000..bdb06aaa --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorActionSerializerTest.java @@ -0,0 +1,79 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +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 OF10VendorActionSerializerTest { + + /** + * Testing of {@link OF10VendorActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testVendorActionWithData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(82L); + byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; + expBuilder.setData(expData); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorActionSerializer serializer = new OF10VendorActionSerializer(); + serializer.serialize(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 82, buffer.readUnsignedInt()); + byte[] tmp = new byte[8]; + buffer.readBytes(tmp); + Assert.assertArrayEquals("Wrong data", expData, tmp); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF10VendorActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testVendorActionWithoutData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(102L); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorActionSerializer serializer = new OF10VendorActionSerializer(); + serializer.serialize(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 102, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactoryTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactoryTest.java new file mode 100644 index 00000000..2d9e82f9 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF10VendorInputMessageFactoryTest.java @@ -0,0 +1,77 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10VendorInputMessageFactoryTest { + + /** + * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + builder.setVersion((short) 1); + builder.setXid(1024L); + builder.setExperimenter(0x0001020304L); + byte[] data = new byte[]{5, 6, 7, 8}; + builder.setData(data); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory(); + vendorFactory.serialize(message, out); + + Assert.assertEquals("Wrong version", 1, out.readUnsignedByte()); + Assert.assertEquals("Wrong type", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong length", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong xid", 1024, out.readUnsignedInt()); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + byte[] expData = new byte[4]; + out.readBytes(expData); + Assert.assertArrayEquals("Wrong data", data, expData); + Assert.assertTrue("Unexpected data", out.readableBytes() == 0); + } + + /** + * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutData() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + builder.setVersion((short) 1); + builder.setXid(1024L); + builder.setExperimenter(0x0001020304L); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory(); + vendorFactory.serialize(message, out); + + Assert.assertEquals("Wrong version", 1, out.readUnsignedByte()); + Assert.assertEquals("Wrong type", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong length", 12, out.readUnsignedShort()); + Assert.assertEquals("Wrong xid", 1024, out.readUnsignedInt()); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + Assert.assertTrue("Unexpected data", out.readableBytes() == 0); + } +} \ No newline at end of file diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializerTest.java new file mode 100644 index 00000000..2eaf92bc --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterActionSerializerTest.java @@ -0,0 +1,126 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +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 OF13ExperimenterActionSerializerTest { + + /** + * Testing of {@link OF13ExperimenterActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testVendorActionWithData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(82L); + byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; + expBuilder.setData(expData); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterActionSerializer serializer = new OF13ExperimenterActionSerializer(); + serializer.serialize(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 82, buffer.readUnsignedInt()); + byte[] tmp = new byte[8]; + buffer.readBytes(tmp); + Assert.assertArrayEquals("Wrong data", expData, tmp); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testVendorActionWithoutData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(102L); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterActionSerializer serializer = new OF13ExperimenterActionSerializer(); + serializer.serialize(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 102, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testHeaderWithData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(82L); + byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; + expBuilder.setData(expData); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterActionSerializer serializer = new OF13ExperimenterActionSerializer(); + serializer.serializeHeader(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 82, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterActionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testHeaderWithoutData() { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(102L); + actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); + Action action = actionBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterActionSerializer serializer = new OF13ExperimenterActionSerializer(); + serializer.serializeHeader(action, buffer); + + Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 102, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactoryTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactoryTest.java new file mode 100644 index 00000000..1a14b9d6 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInputMessageFactoryTest.java @@ -0,0 +1,77 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterInputMessageFactoryTest { + + /** + * Testing of {@link OF13ExperimenterInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + builder.setVersion((short) 4); + builder.setXid(888L); + builder.setExperimenter(0x0001020304L); + byte[] data = new byte[]{5, 6, 7, 8}; + builder.setData(data); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory(); + vendorFactory.serialize(message, out); + + Assert.assertEquals("Wrong version", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong type", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong length", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong xid", 888, out.readUnsignedInt()); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + byte[] expData = new byte[4]; + out.readBytes(expData); + Assert.assertArrayEquals("Wrong data", data, expData); + Assert.assertTrue("Unexpected data", out.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutData() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + builder.setVersion((short) 4); + builder.setXid(888L); + builder.setExperimenter(0x0001020304L); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory(); + vendorFactory.serialize(message, out); + + Assert.assertEquals("Wrong version", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong type", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong length", 12, out.readUnsignedShort()); + Assert.assertEquals("Wrong xid", 888, out.readUnsignedInt()); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + Assert.assertTrue("Unexpected data", out.readableBytes() == 0); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInstructionSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInstructionSerializerTest.java new file mode 100644 index 00000000..177ef631 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13ExperimenterInstructionSerializerTest.java @@ -0,0 +1,126 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13ExperimenterInstructionSerializerTest { + + /** + * Testing of {@link OF13ExperimenterInstructionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() { + InstructionBuilder builder = new InstructionBuilder(); + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(142L); + byte[] data = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; + expBuilder.setData(data); + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + Instruction instruction = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterInstructionSerializer serializer = new OF13ExperimenterInstructionSerializer(); + serializer.serialize(instruction, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 142, buffer.readUnsignedInt()); + byte[] expData = new byte[8]; + buffer.readBytes(expData); + Assert.assertArrayEquals("Wrong experimenter data", data, expData); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterInstructionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + InstructionBuilder builder = new InstructionBuilder(); + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(142L); + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + Instruction instruction = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterInstructionSerializer serializer = new OF13ExperimenterInstructionSerializer(); + serializer.serialize(instruction, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 142, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterInstructionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testHeader() { + InstructionBuilder builder = new InstructionBuilder(); + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(142L); + byte[] data = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; + expBuilder.setData(data); + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + Instruction instruction = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterInstructionSerializer serializer = new OF13ExperimenterInstructionSerializer(); + serializer.serializeHeader(instruction, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 142, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13ExperimenterInstructionSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testHeaderWithoutData() { + InstructionBuilder builder = new InstructionBuilder(); + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(142L); + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + Instruction instruction = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13ExperimenterInstructionSerializer serializer = new OF13ExperimenterInstructionSerializer(); + serializer.serializeHeader(instruction, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 8, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 142, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MeterBandExperimenterSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MeterBandExperimenterSerializerTest.java new file mode 100644 index 00000000..624a6536 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MeterBandExperimenterSerializerTest.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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenterBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13MeterBandExperimenterSerializerTest { + + /** + * Testing of {@link OF13MeterBandExperimenterSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() { + MeterBandExperimenterBuilder builder = new MeterBandExperimenterBuilder(); + builder.setType(MeterBandType.OFPMBTEXPERIMENTER); + builder.setRate(128L); + builder.setBurstSize(256L); + builder.setExperimenter(512L); + MeterBandExperimenter band = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13MeterBandExperimenterSerializer serializer = new OF13MeterBandExperimenterSerializer(); + serializer.serialize(band, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong type", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong type", 128, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong type", 256, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong type", 512, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializerTest.java new file mode 100644 index 00000000..216e5c72 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13MultipartExperimenterSerializerTest.java @@ -0,0 +1,69 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13MultipartExperimenterSerializerTest { + + /** + * Testing of {@link OF10StatsRequestVendorSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() { + MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); + expBuilder.setExperimenter(42L); + expBuilder.setExpType(84L); + byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; + expBuilder.setData(data); + MultipartRequestExperimenter message = expBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13MultipartExperimenterSerializer serializer = new OF13MultipartExperimenterSerializer(); + serializer.serialize(message, buffer); + + Assert.assertEquals("Wrong experimenter", 42, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 84, buffer.readUnsignedInt()); + byte[] expData = new byte[8]; + buffer.readBytes(expData); + Assert.assertArrayEquals("Wrong experimenter data", data, expData); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF10StatsRequestVendorSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutData() { + MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); + expBuilder.setExperimenter(42L); + expBuilder.setExpType(84L); + MultipartRequestExperimenter message = expBuilder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13MultipartExperimenterSerializer serializer = new OF13MultipartExperimenterSerializer(); + serializer.serialize(message, buffer); + + Assert.assertEquals("Wrong experimenter", 42, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 84, buffer.readUnsignedInt()); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } +} diff --git a/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializerTest.java b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializerTest.java new file mode 100644 index 00000000..b6f89c54 --- /dev/null +++ b/openflow-protocol-ext/src/test/java/org/opendaylight/openflowjava/protocol/ext/serialization/OF13TableFeatExpSerializerTest.java @@ -0,0 +1,147 @@ +/* + * 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.ext.serialization; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF13TableFeatExpSerializerTest { + + /** + * Testing of {@link OF13TableFeatExpSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testExperimenter() { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + builder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTER); + ExperimenterRelatedTableFeaturePropertyBuilder propBuilder = + new ExperimenterRelatedTableFeaturePropertyBuilder(); + propBuilder.setExperimenter(891L); + propBuilder.setExpType(6546L); + byte[] data = new byte[]{0, 1, 2, 3}; + propBuilder.setData(data); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, + propBuilder.build()); + TableFeatureProperties property = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13TableFeatExpSerializer serializer = new OF13TableFeatExpSerializer(); + serializer.serialize(property, buffer); + + Assert.assertEquals("Wrong type", 65534, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 891, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 6546, buffer.readUnsignedInt()); + byte[] expData = new byte[4]; + buffer.readBytes(expData); + Assert.assertArrayEquals("Wrong experimenter data", data, expData); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13TableFeatExpSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testExperimenterWithoutData() { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + builder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTER); + ExperimenterRelatedTableFeaturePropertyBuilder propBuilder = + new ExperimenterRelatedTableFeaturePropertyBuilder(); + propBuilder.setExperimenter(891L); + propBuilder.setExpType(6546L); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, + propBuilder.build()); + TableFeatureProperties property = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13TableFeatExpSerializer serializer = new OF13TableFeatExpSerializer(); + serializer.serialize(property, buffer); + + Assert.assertEquals("Wrong type", 65534, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 891, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 6546, buffer.readUnsignedInt()); + buffer.skipBytes(4); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13TableFeatExpSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testExperimenterMiss() { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + builder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS); + ExperimenterRelatedTableFeaturePropertyBuilder propBuilder = + new ExperimenterRelatedTableFeaturePropertyBuilder(); + propBuilder.setExperimenter(8L); + propBuilder.setExpType(6L); + byte[] data = new byte[]{4, 5, 6, 7}; + propBuilder.setData(data); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, + propBuilder.build()); + TableFeatureProperties property = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13TableFeatExpSerializer serializer = new OF13TableFeatExpSerializer(); + serializer.serialize(property, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 8, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 6, buffer.readUnsignedInt()); + byte[] expData = new byte[4]; + buffer.readBytes(expData); + Assert.assertArrayEquals("Wrong experimenter data", data, expData); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Testing of {@link OF13TableFeatExpSerializer} for correct translation from POJO + * @throws Exception + */ + @Test + public void testExperimenterMissWithoutData() { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + builder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS); + ExperimenterRelatedTableFeaturePropertyBuilder propBuilder = + new ExperimenterRelatedTableFeaturePropertyBuilder(); + propBuilder.setExperimenter(8L); + propBuilder.setExpType(6L); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, + propBuilder.build()); + TableFeatureProperties property = builder.build(); + + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF13TableFeatExpSerializer serializer = new OF13TableFeatExpSerializer(); + serializer.serialize(property, buffer); + + Assert.assertEquals("Wrong type", 65535, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort()); + Assert.assertEquals("Wrong experimenter", 8, buffer.readUnsignedInt()); + Assert.assertEquals("Wrong exp-type", 6, buffer.readUnsignedInt()); + buffer.skipBytes(4); + Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0); + } +} 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 ff618542..f7f8b6fb 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 @@ -50,8 +50,6 @@ public class DeserializerRegistryImpl implements DeserializerRegistry { ActionDeserializerInitializer.registerDeserializers(this); // register instruction deserializers InstructionDeserializerInitializer.registerDeserializers(this); - // register default experimenter deserializers - DefaultExperimenterDeserializerInitializer.registerDeserializers(this); } @Override diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java index 5a049c51..45b25aba 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java @@ -10,10 +10,12 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; 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.MessageCodeKey; import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterErrorBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCode; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadInstructionCode; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadMatchCode; @@ -37,10 +39,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab * @author timotej.kubas */ -public class ErrorMessageFactory implements OFDeserializer { +public class ErrorMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; + private DeserializerRegistry registry; @Override public ErrorMessage deserialize(ByteBuf rawMessage) { @@ -49,10 +53,18 @@ public class ErrorMessageFactory implements OFDeserializer { builder.setXid(rawMessage.readUnsignedInt()); int type = rawMessage.readUnsignedShort(); ErrorType errorType = ErrorType.forValue(type); - decodeType(builder, errorType, type); - decodeCode(rawMessage, builder, errorType); - if (rawMessage.readableBytes() > 0) { - builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + if (ErrorType.EXPERIMENTER.equals(errorType)) { + builder.setType(errorType.getIntValue()); + OFDeserializer deserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, ErrorMessage.class)); + ExperimenterError error = deserializer.deserialize(rawMessage); + builder.addAugmentation(ExperimenterError.class, error); + } else { + decodeType(builder, errorType, type); + decodeCode(rawMessage, builder, errorType); + if (rawMessage.readableBytes() > 0) { + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + } } return builder.build(); } @@ -212,12 +224,6 @@ public class ErrorMessageFactory implements OFDeserializer { } break; } - case EXPERIMENTER: - ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder(); - expBuilder.setExpType(code); - expBuilder.setExperimenter(rawMessage.readUnsignedInt()); - builder.addAugmentation(ExperimenterError.class, expBuilder.build()); - break; default: setUnknownCode(builder, code); break; @@ -237,4 +243,9 @@ public class ErrorMessageFactory implements OFDeserializer { builder.setCodeString(codeString); } + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + this.registry = deserializerRegistry; + } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java index cf3e2d74..98192092 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java @@ -26,8 +26,6 @@ import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; @@ -432,14 +430,15 @@ public class MultipartReplyMessageFactory implements OFDeserializer propDeserializer = registry.getDeserializer( + // return index to property start, so that the experimenter properties are deserialized + // correctly - as whole ofp_table_feature_prop_experimenter property + input.readerIndex(input.readerIndex() - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + OFDeserializer propDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, - type.getIntValue(), ExperimenterRelatedTableFeatureProperty.class)); - ExperimenterRelatedTableFeatureProperty expProp = propDeserializer.deserialize(input); - builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expProp); + type.getIntValue(), TableFeatureProperties.class)); + TableFeatureProperties expProp = propDeserializer.deserialize(input); + properties.add(expProp); + continue; } if (paddingRemainder != 0) { input.skipBytes(EncodeConstants.PADDING - paddingRemainder); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java index 26110ec4..ab05b53c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java @@ -13,9 +13,11 @@ 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.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; @@ -33,14 +35,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class QueueGetConfigReplyMessageFactory implements OFDeserializer { +public class QueueGetConfigReplyMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4; private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; private static final int PADDING_IN_RATE_QUEUE_PROPERTY = 6; - private static final int PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY = 4; private static final byte PACKET_QUEUE_LENGTH = 16; + private static final byte QUEUE_PROP_HEADER_SIZE = 8; + private DeserializerRegistry registry; @Override public GetQueueConfigOutput deserialize(ByteBuf rawMessage) { @@ -53,7 +57,7 @@ public class QueueGetConfigReplyMessageFactory implements OFDeserializer createQueuesList(ByteBuf input){ + private List createQueuesList(ByteBuf input){ List queuesList = new ArrayList<>(); while (input.readableBytes() > 0) { QueuesBuilder queueBuilder = new QueuesBuilder(); @@ -67,7 +71,7 @@ public class QueueGetConfigReplyMessageFactory implements OFDeserializer createPropertiesList(ByteBuf input, int length){ + private List createPropertiesList(ByteBuf input, int length){ int propertiesLength = length; List propertiesList = new ArrayList<>(); while (propertiesLength > 0) { @@ -83,16 +87,26 @@ public class QueueGetConfigReplyMessageFactory implements OFDeserializer deserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EXPERIMENTER_VALUE, QueueProperty.class)); + QueueProperty expProp = deserializer.deserialize(input.slice(input.readerIndex(), + currentPropertyLength - QUEUE_PROP_HEADER_SIZE)); + propertiesList.add(expProp); + continue; } propertiesList.add(propertiesBuilder.build()); } return propertiesList; } + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + this.registry = deserializerRegistry; + } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/DefaultExperimenterInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/DefaultExperimenterInitializer.java deleted file mode 100644 index 5aaa458e..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/DefaultExperimenterInitializer.java +++ /dev/null @@ -1,66 +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.serialization; - -import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10StatsRequestVendorSerializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10VendorInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterActionSerializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterInstructionSerializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13MeterBandExperimenterSerializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13MultipartExperimenterSerializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13TableFeatExpSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.CommonMessageRegistryHelper; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.EnhancedKeyRegistryHelper; -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.instruction.rev130731.instructions.grouping.Instruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; - -/** - * @author michal.polkorab - * - */ -public class DefaultExperimenterInitializer { - - /** - * Registers message serializers into provided registry - * @param serializerRegistry registry to be initialized with message serializers - */ - public static void registerDefaultExperimenterSerializers(SerializerRegistry serializerRegistry) { - // register OF v1.0 default experimenter serializers - short version = EncodeConstants.OF10_VERSION_ID; - CommonMessageRegistryHelper helper = new CommonMessageRegistryHelper(version, serializerRegistry); - helper.registerSerializer(ExperimenterInput.class, new OF10VendorInputMessageFactory()); - EnhancedKeyRegistryHelper actionHelper = new EnhancedKeyRegistryHelper<>( - EncodeConstants.OF10_VERSION_ID, Action.class, serializerRegistry); - actionHelper.registerSerializer(Experimenter.class, new OF13ExperimenterActionSerializer()); - helper.registerSerializer(MultipartRequestExperimenter.class, new OF10StatsRequestVendorSerializer()); - // register OF v1.3 default experimenter serializers - version = EncodeConstants.OF13_VERSION_ID; - helper = new CommonMessageRegistryHelper(version, serializerRegistry); - helper.registerSerializer(ExperimenterInput.class, new OF13ExperimenterInputMessageFactory()); - helper.registerSerializer(MultipartRequestExperimenter.class, new OF13MultipartExperimenterSerializer()); - helper.registerSerializer(TableFeatureProperties.class, new OF13TableFeatExpSerializer()); - helper.registerSerializer(MeterBandExperimenter.class, new OF13MeterBandExperimenterSerializer()); - actionHelper = new EnhancedKeyRegistryHelper<>( - EncodeConstants.OF13_VERSION_ID, Action.class, serializerRegistry); - actionHelper.registerSerializer(Experimenter.class, new OF13ExperimenterActionSerializer()); - EnhancedKeyRegistryHelper insHelper = new EnhancedKeyRegistryHelper<>( - EncodeConstants.OF13_VERSION_ID, Instruction.class, serializerRegistry); - insHelper.registerSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight - .openflow.common.instruction.rev130731.Experimenter.class, - new OF13ExperimenterInstructionSerializer()); - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java index 4f36b054..3d8e3a62 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java @@ -50,8 +50,6 @@ public class SerializerRegistryImpl implements SerializerRegistry { ActionsInitializer.registerActionSerializers(this); // instruction serializers InstructionsInitializer.registerInstructionSerializers(this); - // default vendor / experimenter serializers - DefaultExperimenterInitializer.registerDefaultExperimenterSerializers(this); } /** diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java index 11068f3f..718f134b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java @@ -32,10 +32,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder; @@ -76,7 +74,7 @@ public class MeterModInputMessageFactoryTest { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); meterModFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, (byte) 29, 64); + BufferHelper.checkHeaderV13(out, (byte) 29, 48); Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort())); Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt()); @@ -109,14 +107,6 @@ public class MeterModInputMessageFactoryTest { dscpRemarkBand.setPrecLevel((short) 3); dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build()); bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build()); - MeterBandExperimenterCaseBuilder expCaseBuilder = new MeterBandExperimenterCaseBuilder(); - MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); - experimenterBand.setType(MeterBandType.OFPMBTEXPERIMENTER); - experimenterBand.setRate(1L); - experimenterBand.setBurstSize(2L); - experimenterBand.setExperimenter(4L); - expCaseBuilder.setMeterBandExperimenter(experimenterBand.build()); - bandsList.add(bandsBuilder.setMeterBand(expCaseBuilder.build()).build()); return bandsList; } @@ -142,15 +132,6 @@ public class MeterModInputMessageFactoryTest { input.skipBytes(3); dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build()); bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build()); - MeterBandExperimenterCaseBuilder expCaseBuilder = new MeterBandExperimenterCaseBuilder(); - MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); - experimenterBand.setType(MeterBandType.forValue(input.readUnsignedShort())); - input.skipBytes(Short.SIZE/Byte.SIZE); - experimenterBand.setRate(input.readUnsignedInt()); - experimenterBand.setBurstSize(input.readUnsignedInt()); - experimenterBand.setExperimenter(input.readUnsignedInt()); - expCaseBuilder.setMeterBandExperimenter(experimenterBand.build()); - bandsList.add(bandsBuilder.setMeterBand(expCaseBuilder.build()).build()); return bandsList; } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java index 4227330b..1c34f365 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java @@ -32,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase; @@ -47,7 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.desc._case.MultipartRequestDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder; @@ -453,69 +451,4 @@ public class MultipartRequestInputFactoryTest { return caseBuilder.build(); } - /** - * Testing OF10StatsRequestInputFactory (Vendor) for correct serialization - * @throws Exception - */ - @Test - public void testExperimenter() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setType(MultipartType.OFPMPEXPERIMENTER); - builder.setFlags(new MultipartRequestFlags(false)); - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - expBuilder.setExperimenter(56L); - expBuilder.setExpType(148L); - byte[] expData = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; - expBuilder.setData(expData); - caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); - builder.setMultipartRequestBody(caseBuilder.build()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - multipartFactory.serialize(message, out); - - BufferHelper.checkHeaderV10(out, (byte) 18, 32); - Assert.assertEquals("Wrong type", 0xFFFF, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); - Assert.assertEquals("Wrong experimenter", 56, out.readUnsignedInt()); - Assert.assertEquals("Wrong exp-type", 148, out.readUnsignedInt()); - byte[] temp = new byte[8]; - out.readBytes(temp); - Assert.assertArrayEquals("Wrong data", expData, temp); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } - - /** - * Testing OF10StatsRequestInputFactory (Vendor) for correct serialization - * @throws Exception - */ - @Test - public void testExperimenterWithoutData() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setType(MultipartType.OFPMPEXPERIMENTER); - builder.setFlags(new MultipartRequestFlags(false)); - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - expBuilder.setExperimenter(56L); - expBuilder.setExpType(152L); - caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); - builder.setMultipartRequestBody(caseBuilder.build()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - multipartFactory.serialize(message, out); - - BufferHelper.checkHeaderV10(out, (byte) 18, 24); - Assert.assertEquals("Wrong type", 0xFFFF, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); - Assert.assertEquals("Wrong experimenter", 56, out.readUnsignedInt()); - Assert.assertEquals("Wrong exp-type", 152, out.readUnsignedInt()); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } - } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java index 737acecc..5909067e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java @@ -29,13 +29,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.desc._case.MultipartRequestDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder; @@ -302,63 +300,4 @@ public class OF10StatsRequestInputFactoryTest { Assert.assertEquals("Wrong queue-id", 16, out.readUnsignedInt()); Assert.assertTrue("Unread data", out.readableBytes() == 0); } - - /** - * Testing OF10StatsRequestInputFactory (Vendor) for correct serialization - * @throws Exception - */ - @Test - public void testExperimenter() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setType(MultipartType.OFPMPEXPERIMENTER); - builder.setFlags(new MultipartRequestFlags(false)); - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - expBuilder.setExperimenter(56L); - byte[] expData = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; - expBuilder.setData(expData); - caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); - builder.setMultipartRequestBody(caseBuilder.build()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - multipartFactory.serialize(message, out); - - BufferHelper.checkHeaderV10(out, (byte) 16, 24); - Assert.assertEquals("Wrong type", 0xFFFF, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 56, out.readUnsignedInt()); - byte[] temp = new byte[8]; - out.readBytes(temp); - Assert.assertArrayEquals("Wrong data", expData, temp); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } - - /** - * Testing OF10StatsRequestInputFactory (Vendor) for correct serialization - * @throws Exception - */ - @Test - public void testExperimenterWithoutData() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setType(MultipartType.OFPMPEXPERIMENTER); - builder.setFlags(new MultipartRequestFlags(false)); - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - expBuilder.setExperimenter(56L); - caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); - builder.setMultipartRequestBody(caseBuilder.build()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - multipartFactory.serialize(message, out); - - BufferHelper.checkHeaderV10(out, (byte) 16, 16); - Assert.assertEquals("Wrong type", 0xFFFF, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 56, out.readUnsignedInt()); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java deleted file mode 100644 index 022b3349..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java +++ /dev/null @@ -1,71 +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.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; -import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; -import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; -import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10VendorInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10VendorInputMessageFactoryTest { - - private SerializerRegistry registry; - private OFSerializer vendorFactory; - - /** - * Initializes serializer registry and stores correct factory in field - */ - @Before - public void startUp() { - registry = new SerializerRegistryImpl(); - registry.init(); - vendorFactory = registry.getSerializer( - new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, ExperimenterInput.class)); - } - - - /** - * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04}); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - vendorFactory.serialize(message, out); - - BufferHelper.checkHeaderV10(out, (byte) 4, 16); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - byte[] data = new byte[4]; - out.readBytes(data); - Assert.assertArrayEquals("Wrong data", message.getData(), data); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } - -} \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF13ExperimenterInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF13ExperimenterInputMessageFactoryTest.java deleted file mode 100644 index 362f95ac..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF13ExperimenterInputMessageFactoryTest.java +++ /dev/null @@ -1,72 +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.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; -import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; -import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; -import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class OF13ExperimenterInputMessageFactoryTest { - - private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = 4; - private SerializerRegistry registry; - private OFSerializer expFactory; - - /** - * Initializes serializer registry and stores correct factory in field - */ - @Before - public void startUp() { - registry = new SerializerRegistryImpl(); - registry.init(); - expFactory = registry.getSerializer( - new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, ExperimenterInput.class)); - } - - /** - * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setExpType(0x0001020304L); - byte[] expData = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; - builder.setData(expData); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - expFactory.serialize(message, out); - - BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 24); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); - byte[] tmp = new byte[8]; - out.readBytes(tmp); - Assert.assertArrayEquals("Wrong data", expData, tmp); - } - -} \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java index 12cb7244..347ca633 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java @@ -26,8 +26,6 @@ import org.opendaylight.openflowjava.protocol.impl.serialization.factories.Multi import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; @@ -204,27 +202,6 @@ public class TableFeaturesTest { oxmBuilder.setMatchEntries(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); - propBuilder = new TableFeaturePropertiesBuilder(); - propBuilder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTER); - ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = - new ExperimenterRelatedTableFeaturePropertyBuilder(); - expBuilder.setExperimenter(1024L); - expBuilder.setExpType(2048L); - byte[] expData = new byte[]{0, 1, 2}; - expBuilder.setData(expData); - propBuilder.addAugmentation( - ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); - properties.add(propBuilder.build()); - propBuilder = new TableFeaturePropertiesBuilder(); - propBuilder.setType(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS); - expBuilder = new ExperimenterRelatedTableFeaturePropertyBuilder(); - expBuilder.setExperimenter(4098L); - expBuilder.setExpType(8152L); - byte[] expData2 = new byte[]{3, 4, 6, 7, 8, 9}; - expBuilder.setData(expData2); - propBuilder.addAugmentation( - ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); - properties.add(propBuilder.build()); tableFeaturesBuilder.setTableFeatureProperties(properties); tableFeaturesList.add(tableFeaturesBuilder.build()); featuresBuilder.setTableFeatures(tableFeaturesList); @@ -235,7 +212,7 @@ public class TableFeaturesTest { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, (byte) 18, 272); + BufferHelper.checkHeaderV13(out, (byte) 18, 232); Assert.assertEquals("Wrong type", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort()); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -282,7 +259,7 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); - Assert.assertEquals("Wrong length", 136, out.readUnsignedShort()); + Assert.assertEquals("Wrong length", 96, out.readUnsignedShort()); Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte()); out.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", @@ -315,22 +292,6 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte()); out.skipBytes(4); - Assert.assertEquals("Wrong property type", 0xFFFE, out.readUnsignedShort()); - Assert.assertEquals("Wrong property length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 1024, out.readUnsignedInt()); - Assert.assertEquals("Wrong exp-type", 2048, out.readUnsignedInt()); - byte[] tmp = new byte[3]; - out.readBytes(tmp); - Assert.assertArrayEquals("Wrong experimenter data", expData, tmp); - out.skipBytes(1); - Assert.assertEquals("Wrong property type", 0xFFFF, out.readUnsignedShort()); - Assert.assertEquals("Wrong property length", 24, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 4098, out.readUnsignedInt()); - Assert.assertEquals("Wrong exp-type", 8152, out.readUnsignedInt()); - byte[] tmp2 = new byte[6]; - out.readBytes(tmp2); - Assert.assertArrayEquals("Wrong experimenter data", expData2, tmp2); - out.skipBytes(6); Assert.assertTrue("Unread data", out.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java index eba0d98b..533bfa40 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java @@ -24,8 +24,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. 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.ExperimenterActionBuilder; 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; @@ -41,7 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002 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.Experimenter; 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; @@ -155,20 +152,6 @@ public class OF10ActionsSerializerTest { queueBuilder.setQueueId(400L); actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build()); actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(82L); - byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; - expBuilder.setData(expData); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(102L); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory @@ -230,15 +213,6 @@ public class OF10ActionsSerializerTest { Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort()); out.skipBytes(6); Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt()); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 82, out.readUnsignedInt()); - byte[] tmp = new byte[8]; - out.readBytes(tmp); - Assert.assertArrayEquals("Wrong data", expData, tmp); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 102, out.readUnsignedInt()); Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java index b450ccdc..76784c92 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java @@ -21,8 +21,6 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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.ExperimenterActionBuilder; 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; @@ -43,7 +41,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 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; @@ -178,20 +175,6 @@ public class OF13ActionsSerializerTest { actionBuilder = new ActionBuilder(); actionBuilder.setType(PopPbb.class); actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(82L); - byte[] expData = new byte[]{0, 0, 0, 0, 0, 0, 0, 1}; - expBuilder.setData(expData); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(102L); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory @@ -257,15 +240,6 @@ public class OF13ActionsSerializerTest { Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 82, out.readUnsignedInt()); - byte[] tmp = new byte[8]; - out.readBytes(tmp); - Assert.assertArrayEquals("Wrong data", expData, tmp); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 102, out.readUnsignedInt()); Assert.assertTrue("Unread data", out.readableBytes() == 0); } diff --git a/pom.xml b/pom.xml index 05862144..b691ee2e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ openflow-protocol-it feature simple-client + openflow-protocol-ext scm:git:ssh://git.opendaylight.org:29418/openflowjava.git -- 2.36.6