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
* @author timotej.kubas
* @param <E> message code type
*/
-public interface OFDeserializer<E extends DataObject> extends OFGeneralDeserializer {
+public interface OFDeserializer<E extends DataContainer> extends OFGeneralDeserializer {
/**
* Transforms byte message into POJO/DTO (of type E).
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
* @author timotej.kubas
* @param <T> message type
*/
-public interface OFSerializer <T extends DataObject> extends OFGeneralSerializer {
+public interface OFSerializer<T extends DataContainer> extends OFGeneralSerializer {
/**
* Transforms POJO/DTO into byte message (ByteBuf).
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;
* @param key used for serializer lookup
* @param serializer serializer implementation
*/
- void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey<ExperimenterInput> key,
- OFSerializer<ExperimenterInput> serializer);
+ void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey<? extends ExperimenterDataOfChoice> key,
+ OFSerializer<? extends ExperimenterDataOfChoice> serializer);
/**
* Registers multipart-request (stats-request) serializer
* @param key used for serializer lookup
* @param serializer serializer implementation
*/
- void registerMultipartRequestSerializer(ExperimenterIdSerializerKey<MultipartRequestExperimenterCase> key,
- OFSerializer<MultipartRequestExperimenterCase> serializer);
+ void registerMultipartRequestSerializer(ExperimenterIdSerializerKey<? extends ExperimenterDataOfChoice> key,
+ OFSerializer<? extends ExperimenterDataOfChoice> serializer);
/**
* Registers multipart-request table-features serializer
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 <T> class of object to be serialized
*/
-public class ExperimenterIdSerializerKey<T extends DataObject> extends MessageTypeKey<T>
+public class ExperimenterIdSerializerKey<T extends DataContainer> extends MessageTypeKey<T>
implements ExperimenterSerializerKey {
- private Long experimenterId;
+ private long experimenterId;
/**
* @param msgVersion protocol wire version
* @param objectClass class of object to be serialized
*/
public ExperimenterIdSerializerKey(short msgVersion,
- Long experimenterId, Class<T> objectClass) {
+ long experimenterId, Class<T> objectClass) {
super(msgVersion, objectClass);
this.experimenterId = experimenterId;
}
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) {
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;
--- /dev/null
+/*
+ * 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 <T> class of object to be serialized
+ * @author michal.polkorab
+ */
+public class ExperimenterIdTypeSerializerKey<T extends DataContainer> extends ExperimenterIdSerializerKey<T> {
+
+ 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<T> 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
}
}
-// 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";
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";
}
case multipart-request-experimenter-case {
container multipart-request-experimenter {
- // empty body - used for experimenter augmentation
+ uses experimenter-core;
}
}
}
}
rpc experimenter {
+ description "Send experimenter message to device, reply is not solicitated.";
input {
- uses experimenter;
+ uses experimenter-of-message;
}
}
* 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 =
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());
@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));
MessageTypeKey<?>mk = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID,ExperimenterMessage.class);
Assert.assertFalse("Wrong equal to different class.", key1.equals(mk));
--- /dev/null
+/*
+ * 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
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;
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;
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<br>
* C - {@link MatchEntrySerializerKey} parameter representing oxm_class (see specification)<br>
}
@Override
- public void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey<ExperimenterInput> key,
- OFSerializer<ExperimenterInput> serializer) {
+ public void registerExperimenterMessageSerializer(ExperimenterIdSerializerKey<? extends ExperimenterDataOfChoice> key,
+ OFSerializer<? extends ExperimenterDataOfChoice> serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void registerMultipartRequestSerializer(ExperimenterIdSerializerKey<MultipartRequestExperimenterCase> key,
- OFSerializer<MultipartRequestExperimenterCase> serializer) {
+ public void registerMultipartRequestSerializer(ExperimenterIdSerializerKey<? extends ExperimenterDataOfChoice> key,
+ OFSerializer<? extends ExperimenterDataOfChoice> serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
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;
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());
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<ExperimenterInput>,
+public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterOfMessage>,
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<ExperimenterInput> serializer = registry.getSerializer(
+ OFSerializer<ExperimenterDataOfChoice> 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
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;
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;
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;
MultipartRequestExperimenterCase expCase =
(MultipartRequestExperimenterCase) message.getMultipartRequestBody();
MultipartRequestExperimenter experimenter = expCase.getMultipartRequestExperimenter();
- long expId = experimenter.getAugmentation(ExperimenterIdMultipartRequest.class).getExperimenter().getValue();
- OFSerializer<MultipartRequestExperimenterCase> 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<ExperimenterDataOfChoice> 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) {
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.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;
private void serializeExperimenterBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
MultipartRequestExperimenterCase expCase = (MultipartRequestExperimenterCase) multipartRequestBody;
MultipartRequestExperimenter experimenter = expCase.getMultipartRequestExperimenter();
- long expId = experimenter.getAugmentation(ExperimenterIdMultipartRequest.class).getExperimenter().getValue();
- OFSerializer<MultipartRequestExperimenterCase> serializer = registry.getSerializer(
+ final long expId = experimenter.getExperimenter().getValue().longValue();
+
+ // write experimenterId
+ output.writeInt((int) expId);
+
+ OFSerializer<ExperimenterDataOfChoice> 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
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<ExperimenterInput>,
+public class VendorInputMessageFactory implements OFSerializer<ExperimenterOfMessage>,
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<ExperimenterInput> serializer = registry.getSerializer(
+ OFSerializer<ExperimenterDataOfChoice> 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
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;
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
*/
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;
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;
@Mock OFDeserializer<MultipartReplyMessage> deserializerMultipartRplMsg;
@Mock OFDeserializer<QueueProperty> deserializerQueueProperty;
@Mock OFDeserializer<MeterBandExperimenterCase> deserializerMeterBandExpCase;
- @Mock OFSerializer<ExperimenterInput> serializerExperimenterInput;
- @Mock OFSerializer<MultipartRequestExperimenterCase> serializerMultipartRequestExpCase;
+ @Mock OFSerializer<ExperimenterDataOfChoice> serializerExperimenterInput;
+ @Mock OFSerializer<ExperimenterDataOfChoice> serializerMultipartRequestExpCase;
@Mock OFSerializer<MeterBandExperimenterCase> serializerMeterBandExpCase;
private static final int SWITCH_IDLE_TIMEOUT = 2000;
private InetAddress startupAddress;
Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key", provider.unregisterDeserializer(key11));
// -- registerExperimenterMessageSerializer
- ExperimenterIdSerializerKey<ExperimenterInput> key12
- = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,ExperimenterInput.class);
+ ExperimenterIdSerializerKey<ExperimenterDataOfChoice> 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<MultipartRequestExperimenterCase> key13
- = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,MultipartRequestExperimenterCase.class);
+ ExperimenterIdSerializerKey<ExperimenterDataOfChoice> 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));
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;
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
public class ExperimenterInputMessageFactoryTest {
@Mock SerializerRegistry registry;
- @Mock OFSerializer<ExperimenterInput> serializer;
- private OFSerializer<ExperimenterInput> expFactory;
+ @Mock
+ private OFSerializer<ExperimenterDataOfChoice> serializer;
+ private OFSerializer<ExperimenterOfMessage> expFactory;
+ @Mock
+ private ExperimenterDataOfChoice vendorData;
+ @Mock
+ private ByteBuf out;
/**
* Sets up ExperimenterInputMessageFactory
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);
}
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);
}
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);
}
/**
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
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
public class VendorInputMessageFactoryTest {
@Mock SerializerRegistry registry;
- @Mock ExperimenterInputMessageFactory serializer;
+ @Mock OFSerializer<ExperimenterDataOfChoice> 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.<MessageTypeKey<?>>any()))
.thenReturn(serializer);
VendorInputMessageFactory factory = new VendorInputMessageFactory();
factory.injectSerializerRegistry(registry);
builder.setXid(12345L);
builder.setExperimenter(new ExperimenterId(42L));
builder.setExpType(84L);
+ builder.setExperimenterDataOfChoice(vendorData);
ExperimenterInput experimenterInput = builder.build();
+ Mockito.when(registry.getSerializer(Matchers.<ExperimenterIdSerializerKey<ExperimenterDataOfChoice>>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
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
-
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
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;
public class MultipartRequestExperimenterTest {
@Mock SerializerRegistry mockRegistry;
- @Mock OFSerializer<MultipartRequestExperimenterCase> serializer;
+ @Mock OFSerializer<ExperimenterDataOfChoice> serializer;
+
+ @Mock ExperimenterDataOfChoice vendorData;
/**
* Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization
*/
@Test
public void testExperimenter() throws Exception {
- Mockito.when(mockRegistry.getSerializer(Matchers.any(ExperimenterIdSerializerKey.class)))
+ Mockito.when(mockRegistry.getSerializer(Matchers.<ExperimenterIdTypeSerializerKey<ExperimenterDataOfChoice>>any()))
.thenReturn(serializer);
MultipartRequestInputFactory multipartFactory = new MultipartRequestInputFactory();
multipartFactory.injectSerializerRegistry(mockRegistry);
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();
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
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
-
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
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;
public class OF10StatsRequestExperimenterTest {
@Mock SerializerRegistry mockRegistry;
- @Mock OFSerializer<MultipartRequestExperimenterCase> serializer;
+ @Mock OFSerializer<ExperimenterDataOfChoice> serializer;
+ @Mock
+ private ExperimenterDataOfChoice vendorData;
/**
* Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization
*/
@Test
public void testExperimenter() throws Exception {
- Mockito.when(mockRegistry.getSerializer(Matchers.any(ExperimenterIdSerializerKey.class)))
+ Mockito.when(mockRegistry.getSerializer(Matchers.<ExperimenterIdTypeSerializerKey<ExperimenterDataOfChoice>>any()))
.thenReturn(serializer);
OF10StatsRequestInputFactory multipartFactory = new OF10StatsRequestInputFactory();
multipartFactory.injectSerializerRegistry(mockRegistry);
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();
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
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;
/**
/**
* @param msgVersion openflow wire version
* @param experimenterId experimenter / vendor ID
+ * @param type experimenter type according to vendor implementation
* @return key instance
*/
- public static ExperimenterIdSerializerKey<ExperimenterInput> createExperimenterMessageSerializerKey(
- short msgVersion, Long experimenterId) {
- return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, ExperimenterInput.class);
+ public static ExperimenterIdSerializerKey<ExperimenterDataOfChoice> 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<MultipartRequestExperimenterCase> createMultipartRequestSerializerKey(
- short msgVersion, Long experimenterId) {
- return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, MultipartRequestExperimenterCase.class);
+ public static ExperimenterIdSerializerKey<ExperimenterDataOfChoice> createMultipartRequestSerializerKey(
+ short msgVersion, long experimenterId, long type) {
+ return new ExperimenterIdTypeSerializerKey<>(msgVersion, experimenterId, type, ExperimenterDataOfChoice.class);
}
/**
* @return key instance
*/
public static ExperimenterIdSerializerKey<TableFeatureProperties> createMultipartRequestTFSerializerKey(
- short msgVersion, Long experimenterId) {
+ short msgVersion, long experimenterId) {
return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, TableFeatureProperties.class);
}
* @return key instance
*/
public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
- short msgVersion, Long experimenterId) {
+ short msgVersion, long experimenterId) {
return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class);
}
}
\ No newline at end of file
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