From 433d6eb1a30efb37e9b2f86884399316c990e985 Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Thu, 22 Oct 2015 14:59:51 +0200 Subject: [PATCH] BUG-4283: experimenter msg support - serialization part - added serialization support for symmetric and multipart experimenter message - comments worked in Change-Id: I8fc4d00e6afc058b335034e8298f9b846d24d8bc Signed-off-by: Michal Rehak --- .../api/extensibility/OFDeserializer.java | 5 +- .../api/extensibility/OFSerializer.java | 5 +- .../SerializerExtensionProvider.java | 11 ++- .../api/keys/ExperimenterIdSerializerKey.java | 20 +++--- .../keys/ExperimenterIdTypeSerializerKey.java | 60 ++++++++++++++++ .../src/main/yang/openflow-augments.yang | 20 ------ .../src/main/yang/openflow-protocol.yang | 25 ++++++- .../ExperimenterIdSerializerKeyTest.java | 7 +- .../ExperimenterIdTypeSerializerKeyTest.java | 72 +++++++++++++++++++ .../core/SwitchConnectionProviderImpl.java | 15 ++-- .../MessageFactoryInitializer.java | 3 +- .../ExperimenterInputMessageFactory.java | 27 ++++--- .../MultipartRequestInputFactory.java | 19 +++-- .../OF10StatsRequestInputFactory.java | 16 +++-- .../factories/VendorInputMessageFactory.java | 20 +++--- .../ConnectionAdapterImplStatisticsTest.java | 12 ++-- .../SwitchConnectionProviderImpl02Test.java | 15 ++-- .../ExperimenterInputMessageFactoryTest.java | 27 ++++--- .../VendorInputMessageFactoryTest.java | 17 +++-- .../MultipartRequestExperimenterTest.java | 23 +++--- .../OF10StatsRequestExperimenterTest.java | 23 +++--- .../ExperimenterSerializerKeyFactory.java | 22 +++--- .../ExperimenterSerializerKeyFactoryTest.java | 72 ++++++++++--------- 23 files changed, 353 insertions(+), 183 deletions(-) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeSerializerKey.java create mode 100644 openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeSerializerKeyTest.java diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java index a49d84c3..06c54f9d 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java @@ -9,8 +9,7 @@ package org.opendaylight.openflowjava.protocol.api.extensibility; import io.netty.buffer.ByteBuf; - -import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Uniform interface for deserializing factories @@ -18,7 +17,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject; * @author timotej.kubas * @param message code type */ -public interface OFDeserializer extends OFGeneralDeserializer { +public interface OFDeserializer extends OFGeneralDeserializer { /** * Transforms byte message into POJO/DTO (of type E). diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java index 6b2ef473..ec63be53 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java @@ -8,9 +8,8 @@ package org.opendaylight.openflowjava.protocol.api.extensibility; -import org.opendaylight.yangtools.yang.binding.DataObject; - import io.netty.buffer.ByteBuf; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Uniform interface for serializers @@ -18,7 +17,7 @@ import io.netty.buffer.ByteBuf; * @author timotej.kubas * @param message type */ -public interface OFSerializer extends OFGeneralSerializer { +public interface OFSerializer extends OFGeneralSerializer { /** * Transforms POJO/DTO into byte message (ByteBuf). diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java index ebccdad8..13162491 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerExtensionProvider.java @@ -15,9 +15,8 @@ import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; @@ -73,16 +72,16 @@ public interface SerializerExtensionProvider { * @param key used for serializer lookup * @param serializer serializer implementation */ - void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey key, - OFSerializer serializer); + void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey key, + OFSerializer serializer); /** * Registers multipart-request (stats-request) serializer * @param key used for serializer lookup * @param serializer serializer implementation */ - void registerMultipartRequestSerializer(ExperimenterIdSerializerKey key, - OFSerializer serializer); + void registerMultipartRequestSerializer(ExperimenterIdSerializerKey key, + OFSerializer serializer); /** * Registers multipart-request table-features serializer diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdSerializerKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdSerializerKey.java index 89525282..8a900e34 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdSerializerKey.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdSerializerKey.java @@ -8,16 +8,16 @@ package org.opendaylight.openflowjava.protocol.api.keys; -import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * @author michal.polkorab * @param class of object to be serialized */ -public class ExperimenterIdSerializerKey extends MessageTypeKey +public class ExperimenterIdSerializerKey extends MessageTypeKey implements ExperimenterSerializerKey { - private Long experimenterId; + private long experimenterId; /** * @param msgVersion protocol wire version @@ -25,7 +25,7 @@ public class ExperimenterIdSerializerKey extends MessageTy * @param objectClass class of object to be serialized */ public ExperimenterIdSerializerKey(short msgVersion, - Long experimenterId, Class objectClass) { + long experimenterId, Class objectClass) { super(msgVersion, objectClass); this.experimenterId = experimenterId; } @@ -34,10 +34,14 @@ public class ExperimenterIdSerializerKey extends MessageTy public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode()); + result = prime * result + hashCodeOfLong(experimenterId); return result; } + protected int hashCodeOfLong(long longValue) { + return (int) (longValue ^ (longValue >>> 32)); + } + @Override public boolean equals(Object obj) { if (this == obj) { @@ -50,11 +54,7 @@ public class ExperimenterIdSerializerKey extends MessageTy return false; } ExperimenterIdSerializerKey other = (ExperimenterIdSerializerKey) obj; - if (experimenterId == null) { - if (other.experimenterId != null) { - return false; - } - } else if (!experimenterId.equals(other.experimenterId)) { + if (experimenterId != other.experimenterId) { return false; } return true; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeSerializerKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeSerializerKey.java new file mode 100644 index 00000000..b8f6ac93 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeSerializerKey.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014 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.api.keys; + +import org.opendaylight.yangtools.yang.binding.DataContainer; + +/** + * @param class of object to be serialized + * @author michal.polkorab + */ +public class ExperimenterIdTypeSerializerKey extends ExperimenterIdSerializerKey { + + private long type; + + /** + * @param msgVersion protocol wire version + * @param experimenterId experimenter / vendor ID + * @param type data type according to vendor implementation + * @param objectClass class of object to be serialized + */ + public ExperimenterIdTypeSerializerKey(short msgVersion, + long experimenterId, long type, Class objectClass) { + super(msgVersion, experimenterId, objectClass); + this.type = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + hashCodeOfLong(type); + return result; + } + + @Override + public boolean equals(Object obj) { + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof ExperimenterIdTypeSerializerKey)) { + return false; + } + ExperimenterIdTypeSerializerKey other = (ExperimenterIdTypeSerializerKey) obj; + if (type != other.type) { + return false; + } + return true; + } + + @Override + public String toString() { + return super.toString() + "; type: " + type; + } +} \ No newline at end of file diff --git a/openflow-protocol-api/src/main/yang/openflow-augments.yang b/openflow-protocol-api/src/main/yang/openflow-augments.yang index f0f96369..e5be7e56 100644 --- a/openflow-protocol-api/src/main/yang/openflow-augments.yang +++ b/openflow-protocol-api/src/main/yang/openflow-augments.yang @@ -121,26 +121,6 @@ } } -// OFP_MULTIPART AUGMENTS - augment "/ofproto:multipart-request/ofproto:input/ofproto:multipart-request-body/ofproto:multipart-request-experimenter-case/ofproto:multipart-request-experimenter" { - ext:augment-identifier "experimenter-id-multipart-request"; - leaf experimenter { - type oft:experimenter-id; - } - leaf exp-type { - type uint32; - } - } - augment "/ofproto:multipart-reply-message/ofproto:multipart-reply-body/ofproto:multipart-reply-experimenter-case/ofproto:multipart-reply-experimenter" { - ext:augment-identifier "experimenter-id-multipart-reply"; - leaf experimenter { - type oft:experimenter-id; - } - leaf exp-type { - type uint32; - } - } - // OFP_METER_BAND AUGMENTS augment "/ofproto:meter-band-container/ofproto:meter-band/ofproto:meter-band-experimenter-case/ofproto:meter-band-experimenter" { ext:augment-identifier "experimenter-id-meter-band"; diff --git a/openflow-protocol-api/src/main/yang/openflow-protocol.yang b/openflow-protocol-api/src/main/yang/openflow-protocol.yang index 3d9f1d6c..84e78a58 100644 --- a/openflow-protocol-api/src/main/yang/openflow-protocol.yang +++ b/openflow-protocol-api/src/main/yang/openflow-protocol.yang @@ -219,6 +219,26 @@ type uint32; } } + + grouping experimenter-core { + description "General experimenter message content suitable for symmetric and multipart message"; + leaf experimenter { + type oft:experimenter-id; + } + leaf exp_type { + type uint32; + } + choice experimenter-data-of-choice { + // to be augmented by vendors + } + } + grouping experimenter-of-message { + reference "OFPT_EXPERIMENTER message in Openflow Switch 1.3 Spec"; + /* Symmetric message */ + uses ofHeader; + uses experimenter-core; + } + /* Switch configuration messages. */ grouping features-request { reference "OFPT_FEATURES_REQUEST message in Openflow Switch 1.3 Spec"; @@ -678,7 +698,7 @@ } case multipart-request-experimenter-case { container multipart-request-experimenter { - // empty body - used for experimenter augmentation + uses experimenter-core; } } } @@ -1280,8 +1300,9 @@ } rpc experimenter { + description "Send experimenter message to device, reply is not solicitated."; input { - uses experimenter; + uses experimenter-of-message; } } diff --git a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdSerializerKeyTest.java b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdSerializerKeyTest.java index aa5d1275..a3bf7891 100644 --- a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdSerializerKeyTest.java +++ b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdSerializerKeyTest.java @@ -26,7 +26,7 @@ public class ExperimenterIdSerializerKeyTest { * Test ExperimenterIdSerializerKey equals and hashCode */ @Test - public void test() { + public void testHashCodeAndEquals() { ExperimenterIdSerializerKey key1 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class); ExperimenterIdSerializerKey key2 = @@ -36,9 +36,6 @@ public class ExperimenterIdSerializerKeyTest { key2 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF13_VERSION_ID, 42L, ExperimenterMessage.class); Assert.assertFalse("Wrong equals", key1.equals(key2)); Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); - key2 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, ExperimenterMessage.class); - Assert.assertFalse("Wrong equals", key1.equals(key2)); - Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); key2 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 55L, ExperimenterMessage.class); Assert.assertFalse("Wrong equals", key1.equals(key2)); Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); @@ -56,7 +53,7 @@ public class ExperimenterIdSerializerKeyTest { @Test public void testEquals() { ExperimenterIdSerializerKey key1 = - new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, ExperimenterMessage.class); + new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 41L, ExperimenterMessage.class); Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1)); MessageTypeKeymk = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID,ExperimenterMessage.class); Assert.assertFalse("Wrong equal to different class.", key1.equals(mk)); diff --git a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeSerializerKeyTest.java b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeSerializerKeyTest.java new file mode 100644 index 00000000..a613d0d8 --- /dev/null +++ b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeSerializerKeyTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 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.api.keys.experimenter; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; + +/** + * @author michal.polkorab + */ +public class ExperimenterIdTypeSerializerKeyTest { + + /** + * Test ExperimenterIdTypeSerializerKey equals and hashCode + */ + @Test + public void testHashCodeAndEquals() { + ExperimenterIdTypeSerializerKey key1 = + new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class); + ExperimenterIdTypeSerializerKey key2 = + new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class); + Assert.assertTrue("Wrong equals", key1.equals(key2)); + Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode()); + key2 = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF13_VERSION_ID, 42L, 1L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equals", key1.equals(key2)); + Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); + key2 = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 55L, 1L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equals", key1.equals(key2)); + Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); + key2 = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 55L, 1L, null); + Assert.assertFalse("Wrong equals", key1.equals(key2)); + Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); + key2 = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 55L, 1L, ErrorMessage.class); + Assert.assertFalse("Wrong equals", key1.equals(key2)); + Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); + + key2 = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, 2L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equals", key1.equals(key2)); + Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode()); + } + + /** + * Test ExperimenterIdTypeSerializerKey equals - additional test + */ + @Test + public void testEquals() { + ExperimenterIdTypeSerializerKey key1 = + new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 41L, 1L, ExperimenterMessage.class); + Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1)); + ExperimenterIdSerializerKey mk = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equal to different class.", key1.equals(mk)); + ExperimenterIdTypeSerializerKey key2 = + new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2)); + + ExperimenterIdTypeSerializerKey key3 = + new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 41L, 2L, ExperimenterMessage.class); + Assert.assertFalse("Wrong equal by type.", key1.equals(key3)); + } + +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java index c2b4890d..5d6d26c2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java @@ -9,8 +9,9 @@ package org.opendaylight.openflowjava.protocol.impl.core; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.SettableFuture; import io.netty.channel.nio.NioEventLoopGroup; - import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; @@ -43,6 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; @@ -50,9 +52,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; - /** * Exposed class for server handling
* C - {@link MatchEntrySerializerKey} parameter representing oxm_class (see specification)
@@ -253,14 +252,14 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C } @Override - public void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey key, - OFSerializer serializer) { + public void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey key, + OFSerializer serializer) { serializerRegistry.registerSerializer(key, serializer); } @Override - public void registerMultipartRequestSerializer(ExperimenterIdSerializerKey key, - OFSerializer serializer) { + public void registerMultipartRequestSerializer(ExperimenterIdSerializerKey key, + OFSerializer serializer) { serializerRegistry.registerSerializer(key, serializer); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java index c3610c13..95303409 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java @@ -35,6 +35,7 @@ import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleR import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.VendorInputMessageFactory; import org.opendaylight.openflowjava.protocol.impl.util.CommonMessageRegistryHelper; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; @@ -77,7 +78,7 @@ public final class MessageFactoryInitializer { registryHelper.registerSerializer(BarrierInput.class, new OF10BarrierInputMessageFactory()); registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory()); registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory()); - registryHelper.registerSerializer(ExperimenterInput.class, new ExperimenterInputMessageFactory()); + registryHelper.registerSerializer(ExperimenterInput.class, new VendorInputMessageFactory()); registryHelper.registerSerializer(FlowModInput.class, new OF10FlowModInputMessageFactory()); registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory()); registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory()); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java index 6dd5f663..b544a8ff 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java @@ -9,30 +9,41 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; - import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOfMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; /** - * Translates Experimenter messages + * Translates Experimenter messages (both: symmetric request and single reply) * @author michal.polkorab */ -public class ExperimenterInputMessageFactory implements OFSerializer, +public class ExperimenterInputMessageFactory implements OFSerializer, SerializerRegistryInjector { private SerializerRegistry registry; + /** Code type of symmetric Experimenter message */ + private static final byte MESSAGE_TYPE = 4; + @Override - public void serialize(ExperimenterInput message, ByteBuf outBuffer) { + public void serialize(ExperimenterOfMessage message, ByteBuf outBuffer) { long expId = message.getExperimenter().getValue(); - OFSerializer serializer = registry.getSerializer( + OFSerializer serializer = registry.getSerializer( ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey( - EncodeConstants.OF10_VERSION_ID, expId)); - serializer.serialize(message, outBuffer); + EncodeConstants.OF13_VERSION_ID, expId, message.getExpType().longValue())); + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + + // write experimenterId and type + outBuffer.writeInt(message.getExperimenter().getValue().intValue()); + outBuffer.writeInt(message.getExpType().intValue()); + + serializer.serialize(message.getExperimenterDataOfChoice(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } @Override diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java index 7afb253b..2287a64a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java @@ -9,9 +9,7 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; - import java.util.List; - import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; @@ -23,7 +21,6 @@ import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory; import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequest; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty; @@ -37,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; 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.MultipartRequestDescCase; @@ -144,11 +142,18 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer( + final long expId = experimenter.getExperimenter().getValue().longValue(); + final long expType = experimenter.getExpType().longValue(); + + // write experimenterId and type + outBuffer.writeInt((int) expId); + outBuffer.writeInt((int) expType); + + // serialize experimenter data + OFSerializer serializer = registry.getSerializer( ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey( - EncodeConstants.OF13_VERSION_ID, expId)); - serializer.serialize(expCase, outBuffer); + EncodeConstants.OF13_VERSION_ID, expId, expType)); + serializer.serialize(experimenter.getExperimenterDataOfChoice(), outBuffer); } private static int createMultipartRequestFlagsBitmask(final MultipartRequestFlags flags) { diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java index ca81ef13..fa01f6d8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java @@ -9,7 +9,6 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; - import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; @@ -17,10 +16,10 @@ import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequest; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; 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.MultipartRequestDescCase; @@ -132,11 +131,16 @@ public class OF10StatsRequestInputFactory implements OFSerializer serializer = registry.getSerializer( + final long expId = experimenter.getExperimenter().getValue().longValue(); + + // write experimenterId + output.writeInt((int) expId); + + OFSerializer serializer = registry.getSerializer( ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey( - EncodeConstants.OF10_VERSION_ID, expId)); - serializer.serialize(expCase, output); + EncodeConstants.OF10_VERSION_ID, expId, + -1 /* in order not to collide with OF >= 1.3 codecs*/)); + serializer.serialize(experimenter.getExperimenterDataOfChoice(), output); } @Override diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactory.java index 1cf2adc3..2cc7148e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactory.java @@ -9,30 +9,34 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; - import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOfMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; /** - * Translates Vendor messages + * Translates Vendor messages (OF-1.0 limited version - skipping experimenter type) * @author michal.polkorab */ -public class VendorInputMessageFactory implements OFSerializer, +public class VendorInputMessageFactory implements OFSerializer, SerializerRegistryInjector { private SerializerRegistry registry; @Override - public void serialize(ExperimenterInput message, ByteBuf outBuffer) { + public void serialize(ExperimenterOfMessage message, ByteBuf outBuffer) { long expId = message.getExperimenter().getValue(); - OFSerializer serializer = registry.getSerializer( + OFSerializer serializer = registry.getSerializer( ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey( - EncodeConstants.OF10_VERSION_ID, expId)); - serializer.serialize(message, outBuffer); + EncodeConstants.OF10_VERSION_ID, expId, message.getExpType().longValue())); + + // write experimenterId + outBuffer.writeInt(message.getExperimenter().getValue().intValue()); + + serializer.serialize(message.getExperimenterDataOfChoice(), outBuffer); } @Override diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java index a770e853..862de53d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java @@ -8,15 +8,18 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection; import static org.mockito.Mockito.when; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPipeline; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.socket.SocketChannel; - import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -57,11 +60,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener; import org.opendaylight.yangtools.yang.binding.DataObject; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; - /** * Test counters in ConnectionAdapter (at least DS_ENTERED_OFJAVA, DS_FLOW_MODS_ENTERED and US_MESSAGE_PASS counters have to be enabled) * @author madamjak diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java index c83e60c5..f70962f6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java @@ -7,9 +7,9 @@ */ package org.opendaylight.openflowjava.protocol.impl.core.connection; +import com.google.common.util.concurrent.ListenableFuture; import java.net.InetAddress; import java.net.UnknownHostException; - import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; @@ -43,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; @@ -63,8 +64,8 @@ public class SwitchConnectionProviderImpl02Test { @Mock OFDeserializer deserializerMultipartRplMsg; @Mock OFDeserializer deserializerQueueProperty; @Mock OFDeserializer deserializerMeterBandExpCase; - @Mock OFSerializer serializerExperimenterInput; - @Mock OFSerializer serializerMultipartRequestExpCase; + @Mock OFSerializer serializerExperimenterInput; + @Mock OFSerializer serializerMultipartRequestExpCase; @Mock OFSerializer serializerMeterBandExpCase; private static final int SWITCH_IDLE_TIMEOUT = 2000; private InetAddress startupAddress; @@ -211,14 +212,14 @@ public class SwitchConnectionProviderImpl02Test { Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11)); Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key", provider.unregisterDeserializer(key11)); // -- registerExperimenterMessageSerializer - ExperimenterIdSerializerKey key12 - = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,ExperimenterInput.class); + ExperimenterIdSerializerKey key12 + = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class); provider.registerExperimenterMessageSerializer(key12, serializerExperimenterInput); Assert.assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12)); Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key", provider.unregisterSerializer(key12)); //registerMultipartRequestSerializer - ExperimenterIdSerializerKey key13 - = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,MultipartRequestExperimenterCase.class); + ExperimenterIdSerializerKey key13 + = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class); provider.registerMultipartRequestSerializer(key13, serializerMultipartRequestExpCase); Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13)); Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key", provider.unregisterSerializer(key13)); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java index 89e0f958..9b6720e4 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java @@ -9,8 +9,6 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mock; @@ -26,6 +24,8 @@ import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOfMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; /** * @author michal.polkorab @@ -34,8 +34,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class ExperimenterInputMessageFactoryTest { @Mock SerializerRegistry registry; - @Mock OFSerializer serializer; - private OFSerializer expFactory; + @Mock + private OFSerializer serializer; + private OFSerializer expFactory; + @Mock + private ExperimenterDataOfChoice vendorData; + @Mock + private ByteBuf out; /** * Sets up ExperimenterInputMessageFactory @@ -64,9 +69,10 @@ public class ExperimenterInputMessageFactoryTest { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setExperimenter(new ExperimenterId(42L)); + builder.setExpType(21L); + builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput input = builder.build(); - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); expFactory.serialize(input, out); } @@ -81,9 +87,10 @@ public class ExperimenterInputMessageFactoryTest { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setExperimenter(new ExperimenterId(42L)); + builder.setExpType(22L); + builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput input = builder.build(); - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); expFactory.serialize(input, out); } @@ -98,13 +105,15 @@ public class ExperimenterInputMessageFactoryTest { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setExperimenter(new ExperimenterId(42L)); + builder.setExpType(21L); + builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput input = builder.build(); Mockito.when(registry.getSerializer( (ExperimenterIdSerializerKey) Matchers.any())).thenReturn(serializer); - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); expFactory.serialize(input, out); + Mockito.verify(serializer, Mockito.times(1)).serialize(input.getExperimenterDataOfChoice(), out); } /** @@ -118,12 +127,14 @@ public class ExperimenterInputMessageFactoryTest { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setExperimenter(new ExperimenterId(42L)); + builder.setExpType(21L); + builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput input = builder.build(); Mockito.when(registry.getSerializer( (ExperimenterIdSerializerKey) Matchers.any())).thenReturn(serializer); - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); expFactory.serialize(input, out); + Mockito.verify(serializer, Mockito.times(1)).serialize(input.getExperimenterDataOfChoice(), out); } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java index 15496598..f299e818 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/VendorInputMessageFactoryTest.java @@ -10,19 +10,21 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; /** * @author michal.polkorab @@ -32,14 +34,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class VendorInputMessageFactoryTest { @Mock SerializerRegistry registry; - @Mock ExperimenterInputMessageFactory serializer; + @Mock OFSerializer foundSerializer; + @Mock ExperimenterDataOfChoice vendorData; + VendorInputMessageFactory serializer; /** - * Tests {@link VendorInputMessageFactory#serialize(ExperimenterInput, ByteBuf)} + * Tests {@link VendorInputMessageFactory#serialize(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOfMessage, ByteBuf)} */ @Test public void test() { - Mockito.when(registry.getSerializer((MessageTypeKey) Matchers.any(MessageTypeKey.class))) + Mockito.when(registry.getSerializer(Matchers.>any())) .thenReturn(serializer); VendorInputMessageFactory factory = new VendorInputMessageFactory(); factory.injectSerializerRegistry(registry); @@ -49,9 +53,12 @@ public class VendorInputMessageFactoryTest { builder.setXid(12345L); builder.setExperimenter(new ExperimenterId(42L)); builder.setExpType(84L); + builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput experimenterInput = builder.build(); + Mockito.when(registry.getSerializer(Matchers.>any())) + .thenReturn(foundSerializer); factory.serialize(experimenterInput, buffer); - Mockito.verify(serializer, Mockito.times(1)).serialize(experimenterInput, buffer); + Mockito.verify(foundSerializer, Mockito.times(1)).serialize(experimenterInput.getExperimenterDataOfChoice(), buffer); } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/MultipartRequestExperimenterTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/MultipartRequestExperimenterTest.java index c4d58dc9..ce94f426 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/MultipartRequestExperimenterTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/MultipartRequestExperimenterTest.java @@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories.mult import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,18 +19,16 @@ import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequestBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; 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.MultipartRequestExperimenterCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; 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.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; @@ -43,7 +40,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class MultipartRequestExperimenterTest { @Mock SerializerRegistry mockRegistry; - @Mock OFSerializer serializer; + @Mock OFSerializer serializer; + + @Mock ExperimenterDataOfChoice vendorData; /** * Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization @@ -51,7 +50,7 @@ public class MultipartRequestExperimenterTest { */ @Test public void testExperimenter() throws Exception { - Mockito.when(mockRegistry.getSerializer(Matchers.any(ExperimenterIdSerializerKey.class))) + Mockito.when(mockRegistry.getSerializer(Matchers.>any())) .thenReturn(serializer); MultipartRequestInputFactory multipartFactory = new MultipartRequestInputFactory(); multipartFactory.injectSerializerRegistry(mockRegistry); @@ -61,9 +60,9 @@ public class MultipartRequestExperimenterTest { builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - ExperimenterIdMultipartRequestBuilder expIdBuilder = new ExperimenterIdMultipartRequestBuilder(); - expIdBuilder.setExperimenter(new ExperimenterId(42L)); - expBuilder.addAugmentation(ExperimenterIdMultipartRequest.class, expIdBuilder.build()); + expBuilder.setExperimenter(new ExperimenterId(42L)); + expBuilder.setExpType(21L); + expBuilder.setExperimenterDataOfChoice(vendorData); caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); builder.setMultipartRequestBody(caseBuilder.build()); MultipartRequestInput message = builder.build(); @@ -71,9 +70,9 @@ public class MultipartRequestExperimenterTest { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, (byte) 18, 16); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", 65535, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - Mockito.verify(serializer, Mockito.times(1)).serialize(Matchers.any(MultipartRequestExperimenterCase.class), Matchers.any(ByteBuf.class)); + Mockito.verify(serializer, Mockito.times(1)).serialize(vendorData, out); } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/OF10StatsRequestExperimenterTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/OF10StatsRequestExperimenterTest.java index 0fcacef1..15430aa6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/OF10StatsRequestExperimenterTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/OF10StatsRequestExperimenterTest.java @@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories.mult import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,18 +19,16 @@ import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; -import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMultipartRequestBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; 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.MultipartRequestExperimenterCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; 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.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; @@ -43,7 +40,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class OF10StatsRequestExperimenterTest { @Mock SerializerRegistry mockRegistry; - @Mock OFSerializer serializer; + @Mock OFSerializer serializer; + @Mock + private ExperimenterDataOfChoice vendorData; /** * Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization @@ -51,7 +50,7 @@ public class OF10StatsRequestExperimenterTest { */ @Test public void testExperimenter() throws Exception { - Mockito.when(mockRegistry.getSerializer(Matchers.any(ExperimenterIdSerializerKey.class))) + Mockito.when(mockRegistry.getSerializer(Matchers.>any())) .thenReturn(serializer); OF10StatsRequestInputFactory multipartFactory = new OF10StatsRequestInputFactory(); multipartFactory.injectSerializerRegistry(mockRegistry); @@ -61,9 +60,9 @@ public class OF10StatsRequestExperimenterTest { builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); - ExperimenterIdMultipartRequestBuilder expIdBuilder = new ExperimenterIdMultipartRequestBuilder(); - expIdBuilder.setExperimenter(new ExperimenterId(42L)); - expBuilder.addAugmentation(ExperimenterIdMultipartRequest.class, expIdBuilder.build()); + expBuilder.setExperimenter(new ExperimenterId(42L)); + expBuilder.setExpType(21L); + expBuilder.setExperimenterDataOfChoice(vendorData); caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); builder.setMultipartRequestBody(caseBuilder.build()); MultipartRequestInput message = builder.build(); @@ -71,9 +70,9 @@ public class OF10StatsRequestExperimenterTest { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, (byte) 16, 12); + BufferHelper.checkHeaderV10(out, (byte) 16, 16); Assert.assertEquals("Wrong type", 65535, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); - Mockito.verify(serializer, Mockito.times(1)).serialize(Matchers.any(MultipartRequestExperimenterCase.class), Matchers.any(ByteBuf.class)); + Mockito.verify(serializer, Mockito.times(1)).serialize(vendorData, out); } } \ No newline at end of file diff --git a/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactory.java b/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactory.java index 36033d07..edc6f25e 100644 --- a/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactory.java +++ b/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactory.java @@ -9,9 +9,9 @@ package org.opendaylight.openflowjava.util; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; /** @@ -23,21 +23,23 @@ public abstract class ExperimenterSerializerKeyFactory { /** * @param msgVersion openflow wire version * @param experimenterId experimenter / vendor ID + * @param type experimenter type according to vendor implementation * @return key instance */ - public static ExperimenterIdSerializerKey createExperimenterMessageSerializerKey( - short msgVersion, Long experimenterId) { - return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, ExperimenterInput.class); + public static ExperimenterIdSerializerKey createExperimenterMessageSerializerKey( + short msgVersion, long experimenterId, long type) { + return new ExperimenterIdTypeSerializerKey<>(msgVersion, experimenterId, type, ExperimenterDataOfChoice.class); } /** * @param msgVersion openflow wire version * @param experimenterId experimenter / vendor ID + * @param type experimenter type according to vendor implementation * @return key instance */ - public static ExperimenterIdSerializerKey createMultipartRequestSerializerKey( - short msgVersion, Long experimenterId) { - return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, MultipartRequestExperimenterCase.class); + public static ExperimenterIdSerializerKey createMultipartRequestSerializerKey( + short msgVersion, long experimenterId, long type) { + return new ExperimenterIdTypeSerializerKey<>(msgVersion, experimenterId, type, ExperimenterDataOfChoice.class); } /** @@ -46,7 +48,7 @@ public abstract class ExperimenterSerializerKeyFactory { * @return key instance */ public static ExperimenterIdSerializerKey createMultipartRequestTFSerializerKey( - short msgVersion, Long experimenterId) { + short msgVersion, long experimenterId) { return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, TableFeatureProperties.class); } @@ -56,7 +58,7 @@ public abstract class ExperimenterSerializerKeyFactory { * @return key instance */ public static ExperimenterIdSerializerKey createMeterBandSerializerKey( - short msgVersion, Long experimenterId) { + short msgVersion, long experimenterId) { return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class); } } \ No newline at end of file diff --git a/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactoryTest.java b/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactoryTest.java index 91435929..211186d7 100644 --- a/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactoryTest.java +++ b/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactoryTest.java @@ -11,62 +11,64 @@ package org.opendaylight.openflowjava.util; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey; +import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey; 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.experimenter.core.ExperimenterDataOfChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; /** + * Test ExperimenterSerializerKeyFactory key creation * @author michal.polkorab * */ public class ExperimenterSerializerKeyFactoryTest { - /** - * Test ExperimenterSerializerKeyFactory key creation - */ @Test - public void test() { - ExperimenterIdSerializerKey createdKey = ExperimenterSerializerKeyFactory - .createExperimenterMessageSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L); - ExperimenterIdSerializerKey comparationKey = - new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterInput.class); - Assert.assertEquals("Wrong key created", comparationKey, createdKey); - createdKey = ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey( - EncodeConstants.OF10_VERSION_ID, null); - comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - null, ExperimenterInput.class); - Assert.assertEquals("Wrong key created", comparationKey, createdKey); - createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey( - EncodeConstants.OF10_VERSION_ID, 43L); - comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - 43L, MeterBandExperimenterCase.class); - Assert.assertEquals("Wrong key created", comparationKey, createdKey); - createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey( - EncodeConstants.OF10_VERSION_ID, null); - comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - null, MeterBandExperimenterCase.class); - Assert.assertEquals("Wrong key created", comparationKey, createdKey); - createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey( - EncodeConstants.OF10_VERSION_ID, 44L); - comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - 44L, MultipartRequestExperimenterCase.class); + public void testCreateExperimenterMessageSerializerKey() throws Exception { + ExperimenterIdSerializerKey createdKey; + ExperimenterIdSerializerKey comparationKey; + + createdKey = ExperimenterSerializerKeyFactory + .createExperimenterMessageSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, 1L); + comparationKey = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, + 42L, 1L, ExperimenterDataOfChoice.class); Assert.assertEquals("Wrong key created", comparationKey, createdKey); + } + + @Test + public void testCreateMultipartRequestSerializerKey() throws Exception { + ExperimenterIdSerializerKey createdKey; + ExperimenterIdSerializerKey comparationKey; + createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey( - EncodeConstants.OF10_VERSION_ID, null); + EncodeConstants.OF10_VERSION_ID, 44L, 1L); comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - null, MultipartRequestExperimenterCase.class); + 44L, ExperimenterDataOfChoice.class); Assert.assertEquals("Wrong key created", comparationKey, createdKey); + } + + @Test + public void testCreateMultipartRequestTFSerializerKey() throws Exception { + ExperimenterIdSerializerKey createdKey; + ExperimenterIdSerializerKey comparationKey; + createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey( EncodeConstants.OF10_VERSION_ID, 45L); comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 45L, TableFeatureProperties.class); Assert.assertEquals("Wrong key created", comparationKey, createdKey); - createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey( - EncodeConstants.OF10_VERSION_ID, null); + } + + @Test + public void testCreateMeterBandSerializerKey() throws Exception { + ExperimenterIdSerializerKey createdKey; + ExperimenterIdSerializerKey comparationKey; + + createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey( + EncodeConstants.OF10_VERSION_ID, 43L); comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, - null, TableFeatureProperties.class); + 43L, MeterBandExperimenterCase.class); Assert.assertEquals("Wrong key created", comparationKey, createdKey); } } \ No newline at end of file -- 2.36.6