public static final long ONF_EXPERIMENTER_ID = 0x4F4E4600;
/** ONFOXM_ET_TCP_FLAGS value */
public static final int ONFOXM_ET_TCP_FLAGS = 42;
- /** ONF_ET_BUNDLE_CONTROL message type */
- public static final int ONF_ET_BUNDLE_CONTROL = 2300;
- /** ONF_ET_BUNDLE_ADD_MESSAGE message type */
- public static final int ONF_ET_BUNDLE_ADD_MESSAGE = 2301;
private EncodeConstants() {
//not called
prefix "ofext";
import yang-ext {prefix ext;}
- import ietf-inet-types {prefix inet;}
- import ietf-yang-types {prefix yang;}
-
- import openflow-types {prefix oft;}
- import openflow-protocol {prefix ofproto;}
- import openflow-action {prefix ofaction;}
- import openflow-instruction {prefix ofinstruction;}
import openflow-extensible-match {prefix oxm;}
import openflow-augments {prefix aug;}
}
//ONF Approved OpenFlow Extensions
-
- // ONF experimenter error codes
- typedef onf-experimenter-error-code {
- description "Error codes for experimenter error type.";
- type enumeration {
- enum ONFERR_ET_UNKNOWN {
- description "Unspecified error.";
- value 2300;
- }
- enum ONFERR_ET_EPERM {
- description "Permissions error.";
- value 2301;
- }
- enum ONFERR_ET_BAD_ID {
- description "Bundle ID doesn’t exist.";
- value 2302;
- }
- enum ONFERR_ET_BUNDLE_EXIST {
- description "Bundle ID already exist.";
- value 2303;
- }
- enum ONFERR_ET_BUNDLE_CLOSED {
- description "Bundle ID is closed.";
- value 2304;
- }
- enum ONFERR_ET_OUT_OF_BUNDLES {
- description "Too many bundles IDs.";
- value 2305;
- }
- enum ONFERR_ET_BAD_TYPE {
- description "Unsupported or unknown message control type.";
- value 2306;
- }
- enum ONFERR_ET_BAD_FLAGS {
- description "Unsupported, unknown, or inconsistent flags.";
- value 2307;
- }
- enum ONFERR_ET_MSG_BAD_LEN {
- description "Length problem in included message.";
- value 2308;
- }
- enum ONFERR_ET_MSG_BAD_XID {
- description "Inconsistent or duplicate XID.";
- value 2309;
- }
- enum ONFERR_ET_MSG_UNSUP {
- description "Unsupported message in this bundle.";
- value 2310;
- }
- enum ONFERR_ET_MSG_CONFLICT {
- description "Unsupported message combination in this bundle.";
- value 2311;
- }
- enum ONFERR_ET_MSG_TOO_MANY {
- description "Can not handle this many messages in bundle.";
- value 2312;
- }
- enum ONFERR_ET_MSG_FAILED {
- description "One message in bundle failed.";
- value 2313;
- }
- enum ONFERR_ET_TIMEOUT {
- description "Bundle is taking too long.";
- value 2314;
- }
- enum ONFERR_ET_BUNDLE_IN_PROGRESS {
- description "Bundle is locking the resource.";
- value 2315;
- }
- }
- }
-
// Extension 109 - TCP FLAGS
identity tcp_flags {
base oxm:match-field;
}
}
- // Extension 230 - Bundle Extension (experimenterID 0x4F4E4600)
- typedef bundle-id {
- description "Identify the bundle.";
- type uint32;
- }
-
- typedef bundle-control-type {
- description "Bundle control message type.";
- type enumeration {
- enum ONF_BCT_OPEN_REQUEST {
- value 0;
- }
- enum ONF_BCT_OPEN_REPLY {
- value 1;
- }
- enum ONF_BCT_CLOSE_REQUEST {
- value 2;
- }
- enum ONF_BCT_CLOSE_REPLY {
- value 3;
- }
- enum ONF_BCT_COMMIT_REQUEST {
- value 4;
- }
- enum ONF_BCT_COMMIT_REPLY {
- value 5;
- }
- enum ONF_BCT_DISCARD_REQUEST {
- value 6;
- }
- enum ONF_BCT_DISCARD_REPLY {
- value 7;
- }
- }
- }
-
- typedef bundle-flags {
- description "Bundle configuration flags.";
- type bits {
- bit atomic {
- description "Execute atomically.";
- position 0;
- }
- bit ordered {
- description "Execute in specified order.";
- position 1;
- }
- }
- }
-
- typedef bundle-property-type {
- description "Bundle property types.";
- type enumeration {
- enum ONF_ET_BPT_EXPERIMENTER {
- description "Experimenter property.";
- value 65535; //0xFFFF
- }
- }
- }
-
- grouping bundle-properties {
- list bundle-property {
- description "Bundle properties list.";
- leaf type {
- type bundle-property-type;
- }
- choice bundle-property-entry {
- case bundle-experimenter-property {
- leaf experimenter {
- type oft:experimenter-id;
- }
- leaf exp-type {
- type uint32;
- }
- choice bundle-experimenter-property-data {
- // to be augmented by vendors
- }
- }
- }
- }
- }
-
- augment "/ofproto:experimenter/ofproto:input/ofproto:experimenter-data-of-choice" {
- case bundle-control {
- description "ONF_ET_BUNDLE_CONTROL message in OpenFlow Switch Extension 230.";
- leaf bundle-id {
- type bundle-id;
- }
- leaf type {
- type bundle-control-type;
- }
- leaf flags {
- type bundle-flags;
- }
- uses bundle-properties;
- }
- case bundle-add-message {
- description "ONF_ET_BUNDLE_ADD_MESSAGE in OpenFlow Switch Extension 230.";
- leaf bundle-id {
- type bundle-id;
- }
- leaf flags {
- type bundle-flags;
- }
- // Inner message
- choice message {
- description "Message added to the bundle.";
- case flow-mod-case {
- uses ofproto:flow-mod;
- }
- case group-mod-case {
- uses ofproto:group-mod;
- }
- case port-mod-case {
- uses ofproto:port-mod;
- }
- }
- uses bundle-properties;
- }
- }
}
\ No newline at end of file
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter.BundleControlFactory;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter.OnfExperimenterErrorFactory;
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory;
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory;
helper.registerDeserializer(25, RoleRequestOutput.class, new RoleReplyMessageFactory());
helper.registerDeserializer(27, GetAsyncOutput.class, new GetAsyncReplyMessageFactory());
- // register ONF approved experimenter serializers
- helper.registerExperimenterErrorDeserializer(EncodeConstants.ONF_EXPERIMENTER_ID,
- new OnfExperimenterErrorFactory());
- helper.registerExperimenterDeserializer(EncodeConstants.ONF_EXPERIMENTER_ID,
- EncodeConstants.ONF_ET_BUNDLE_CONTROL, new BundleControlFactory());
-
// register OF v1.4 message deserializers
helper = new SimpleDeserializerRegistryHelper(EncodeConstants.OF14_VERSION_ID, registry);
helper.registerDeserializer(0, HelloMessage.class, new HelloMessageFactory());
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import java.util.ArrayList;
-import java.util.List;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleControlType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundlePropertyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterPropertyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControlBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
-
-/**
- * Translates BundleControl messages (OpenFlow v1.3 extension #230).
- */
-public class BundleControlFactory implements OFDeserializer<BundleControl>, DeserializerRegistryInjector {
-
- private DeserializerRegistry deserializerRegistry;
-
- @Override
- public BundleControl deserialize(ByteBuf message) {
- BundleId bundleId = new BundleId(message.readUnsignedInt());
- BundleControlType type = BundleControlType.forValue(message.readUnsignedShort());
- BundleFlags flags = createBundleFlags(message.readUnsignedShort());
- BundleControlBuilder builder = new BundleControlBuilder();
- List<BundleProperty> properties = createBundleProperties(message);
- return builder.setBundleId(bundleId)
- .setType(type)
- .setFlags(flags)
- .setBundleProperty(properties)
- .build();
- }
-
- private static BundleFlags createBundleFlags(final int flags) {
- Boolean isAtomic = (flags & (1 << 0)) != 0;
- Boolean isOrdered = (flags & (1 << 1)) != 0;
- return new BundleFlags(isAtomic, isOrdered);
- }
-
- private List<BundleProperty> createBundleProperties(final ByteBuf message) {
- List<BundleProperty> properties = new ArrayList<>();
- while (message.readableBytes() > 0) {
- BundlePropertyType type = BundlePropertyType.forValue(message.readUnsignedShort());
- int length = message.readUnsignedShort();
- if (type != null && type.equals(BundlePropertyType.ONFETBPTEXPERIMENTER)) {
- properties.add(createExperimenterBundleProperty(length, message));
- } else {
- message.skipBytes(length);
- }
- }
- return properties;
- }
-
- private BundleProperty createExperimenterBundleProperty(final int length, final ByteBuf message) {
- BundleExperimenterPropertyBuilder experimenterProperty = new BundleExperimenterPropertyBuilder();
- long experimenterId = message.readUnsignedInt();
- long expType = message.readUnsignedInt();
- experimenterProperty.setExperimenter(new ExperimenterId(experimenterId));
- experimenterProperty.setExpType(expType);
-
- OFDeserializer<BundleExperimenterPropertyData> deserializer = deserializerRegistry.getDeserializer(
- ExperimenterDeserializerKeyFactory.createBundlePropertyDeserializerKey(EncodeConstants.OF13_VERSION_ID,
- experimenterId, expType));
- experimenterProperty.setBundleExperimenterPropertyData(deserializer.deserialize(message.readBytes(length - 12)));
-
- return new BundlePropertyBuilder().setType(BundlePropertyType.ONFETBPTEXPERIMENTER)
- .setBundlePropertyEntry(experimenterProperty.build())
- .build();
- }
-
- @Override
- public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
- this.deserializerRegistry = deserializerRegistry;
- }
-
-}
-
-
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.OnfExperimenterErrorCode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdError;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdErrorBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Translates (ONF approved) experimenter error messages.
- */
-public class OnfExperimenterErrorFactory implements OFDeserializer<ErrorMessage> {
-
- private static final Logger LOG = LoggerFactory.getLogger(OnfExperimenterErrorFactory.class);
- private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE";
- private static final String UNKNOWN_CODE = "UNKNOWN_CODE";
-
- @Override
- public ErrorMessage deserialize(ByteBuf message) {
- ErrorMessageBuilder builder = new ErrorMessageBuilder();
- builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
- builder.setXid(message.readUnsignedInt());
-
- int type = message.readUnsignedShort();
- ErrorType errorType = ErrorType.forValue(type);
- if (errorType != null && errorType.equals(ErrorType.EXPERIMENTER)) {
- builder.setType(errorType.getIntValue());
- builder.setTypeString(errorType.getName());
- } else {
- LOG.warn("Deserializing other than {} error message with {}", ErrorType.EXPERIMENTER.getName(),
- this.getClass().getCanonicalName());
- builder.setType(type);
- builder.setTypeString(UNKNOWN_TYPE);
- }
-
- int code = message.readUnsignedShort();
- OnfExperimenterErrorCode errorCode = OnfExperimenterErrorCode.forValue(code);
- if (errorCode != null) {
- builder.setCode(errorCode.getIntValue());
- builder.setCodeString(errorCode.getName());
- } else {
- builder.setCode(code);
- builder.setCodeString(UNKNOWN_CODE);
- }
-
- builder.addAugmentation(ExperimenterIdError.class, new ExperimenterIdErrorBuilder()
- .setExperimenter(new ExperimenterId(message.readUnsignedInt()))
- .build());
-
- if (message.readableBytes() > 0) {
- byte[] data = new byte[message.readableBytes()];
- message.readBytes(data);
- builder.setData(data);
- }
- return builder.build();
- }
-}
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactory;
-import org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactory;
import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory;
import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory;
import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory;
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.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.FlowModCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.GroupModCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.PortModCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
registryHelper.registerSerializer(SetAsyncInput.class, new SetAsyncInputMessageFactory());
registryHelper.registerSerializer(SetConfigInput.class, new SetConfigMessageFactory());
registryHelper.registerSerializer(TableModInput.class, new TableModInputMessageFactory());
-
- // register ONF approved experimenter serializers
- registryHelper.registerExperimenterSerializer(EncodeConstants.ONF_EXPERIMENTER_ID,
- EncodeConstants.ONF_ET_BUNDLE_CONTROL, new BundleControlFactory());
- registryHelper.registerExperimenterSerializer(EncodeConstants.ONF_EXPERIMENTER_ID,
- EncodeConstants.ONF_ET_BUNDLE_ADD_MESSAGE, new BundleAddMessageFactory());
-
- // register serializers for inner messages of BundleAddMessage
- registryHelper.registerSerializer(FlowModCase.class, new FlowModInputMessageFactory());
- registryHelper.registerSerializer(GroupModCase.class, new GroupModInputMessageFactory());
- registryHelper.registerSerializer(PortModCase.class, new PortModInputMessageFactory());
}
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-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.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.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract class for common stuff of bundle messages.
- */
-public abstract class AbstractBundleMessageFactory<T extends DataContainer> implements OFSerializer<T>,
- SerializerRegistryInjector {
-
- private static final Logger LOG = LoggerFactory.getLogger(AbstractBundleMessageFactory.class);
- protected SerializerRegistry serializerRegistry;
-
- @Override
- public void serialize(T input, ByteBuf outBuffer) {
- // to be extended
- }
-
- @Override
- public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
- this.serializerRegistry = serializerRegistry;
- }
-
- protected static void writeBundleFlags(final BundleFlags bundleFlags, final ByteBuf outBuffer) {
- int flagsBitMap = ByteBufUtils.fillBitMask(0, bundleFlags.isAtomic(), bundleFlags.isOrdered());
- outBuffer.writeShort(flagsBitMap);
- }
-
- protected void writeBundleProperties(final List<BundleProperty> properties, final ByteBuf outBuffer) {
- for (BundleProperty property : properties) {
- BundlePropertyType type = property.getType();
- if (type != null && type.equals(BundlePropertyType.ONFETBPTEXPERIMENTER)) {
- int startIndex = outBuffer.writerIndex();
- outBuffer.writeShort(type.getIntValue());
- int lengthIndex = outBuffer.writerIndex();
- outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
- writeBundleExperimenterProperty(property, outBuffer);
- outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
- } else {
- LOG.warn("lTrying to serialize unknown bundle property (type: {}), skipping", type.getIntValue() );
- }
- }
- }
-
- protected void writeBundleExperimenterProperty(final BundleProperty bundleProperty, final ByteBuf outBuffer) {
- BundleExperimenterProperty property = (BundleExperimenterProperty) bundleProperty.getBundlePropertyEntry();
- int experimenterId = property.getExperimenter().getValue().intValue();
- int expType = property.getExpType().intValue();
- outBuffer.writeInt(experimenterId);
- outBuffer.writeInt(expType);
- OFSerializer<BundleExperimenterPropertyData> serializer = serializerRegistry.getSerializer(
- ExperimenterSerializerKeyFactory.createBundlePropertySerializerKey(EncodeConstants.OF13_VERSION_ID,
- experimenterId, expType));
- serializer.serialize(property.getBundleExperimenterPropertyData(), outBuffer);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import java.util.List;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
-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.approved.extensions.rev160802.bundle.properties.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleAddMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.Message;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
-
-/**
- * Translates BundleAddMessage messages (OpenFlow v1.3 extension #230).
- */
-public class BundleAddMessageFactory extends AbstractBundleMessageFactory<BundleAddMessage> {
-
- @Override
- public void serialize(BundleAddMessage input, ByteBuf outBuffer) {
- outBuffer.writeInt(input.getBundleId().getValue().intValue());
- outBuffer.writeZero(2);
- writeBundleFlags(input.getFlags(), outBuffer);
-
- int msgStart = outBuffer.writerIndex();
- serializeInnerMessage(input.getMessage(), outBuffer, input.getMessage().getImplementedInterface());
- int msgLength = outBuffer.writerIndex() - msgStart;
-
- List<BundleProperty> bundleProperties = input.getBundleProperty();
- if (bundleProperties != null && !bundleProperties.isEmpty()) {
- outBuffer.writeZero(paddingNeeded(msgLength));
- writeBundleProperties(input.getBundleProperty(), outBuffer);
- }
- }
-
- private <T extends DataContainer> void serializeInnerMessage(final Message innerMessage, final ByteBuf outBuffer,
- final Class<T> clazz) {
- OFSerializer<T> serializer = serializerRegistry.getSerializer(
- new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, clazz));
- serializer.serialize((T)innerMessage, outBuffer);
- }
-
- private static int paddingNeeded(final int length) {
- int paddingRemainder = length % EncodeConstants.PADDING;
- return (paddingRemainder != 0) ? (EncodeConstants.PADDING - paddingRemainder) : 0;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControl;
-
-/**
- * Translates BundleControl messages (OpenFlow v1.3 extension #230).
- */
-public class BundleControlFactory extends AbstractBundleMessageFactory<BundleControl> {
-
- @Override
- public void serialize(BundleControl input, ByteBuf outBuffer) {
- outBuffer.writeInt(input.getBundleId().getValue().intValue());
- outBuffer.writeShort(input.getType().getIntValue());
- writeBundleFlags(input.getFlags(), outBuffer);
- if (input.getBundleProperty() != null) {
- writeBundleProperties(input.getBundleProperty(), outBuffer);
- }
- }
-
-}
serializerRegistry.registerSerializer(new MessageTypeKey<>(version, msgType), serializer);
}
- /**
- * Registers experimenter serializer in registry.
- * @param experimenterId experimenterID of experimenter message
- * @param type type of experimenter message
- * @param serializer serializer instance
- */
- public void registerExperimenterSerializer(final long experimenterId, final long type,
- final OFGeneralSerializer serializer) {
- serializerRegistry.registerSerializer(ExperimenterSerializerKeyFactory
- .createExperimenterMessageSerializerKey(version, experimenterId, type), serializer);
- }
}
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer;
import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
-import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
/**
* Helper class for deserializer registration.
}
}
- /**
- * Register experimenter deserializer in registry.
- * @param experimenterId experimenterID of experimenter message
- * @param type type of experimenter message
- * @param deserializer deserializer instance
- */
- public void registerExperimenterDeserializer (final long experimenterId, final long type,
- final OFGeneralDeserializer deserializer) {
- registry.registerDeserializer(ExperimenterDeserializerKeyFactory
- .createExperimenterMessageDeserializerKey(version, experimenterId, type), deserializer);
- }
-
- /**
- * Register experimenter error deserializer in registry.
- * @param experimenterId experimenterID of experimenter message
- * @param deserializer deserializer instance
- */
- public void registerExperimenterErrorDeserializer (final long experimenterId,
- final OFGeneralDeserializer deserializer) {
- registry.registerDeserializer(ExperimenterDeserializerKeyFactory
- .createExperimenterErrorDeserializerKey(version, experimenterId), deserializer);
- }
-
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import org.junit.Assert;
-import org.junit.Before;
-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.DeserializerRegistry;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
-import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleControlType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControl;
-
-/**
- * Tests for {@link org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter.BundleControlFactory}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class BundleControlFactoryTest {
-
- private OFDeserializer<BundleControl> factory;
- @Mock
- DeserializerRegistry registry;
- @Mock
- OFDeserializer<BundleExperimenterPropertyData> experimenterPropertyDeserializer;
-
- @Before
- public void startUp() {
- DeserializerRegistry registry = new DeserializerRegistryImpl();
- registry.init();
- factory = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createExperimenterMessageDeserializerKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.ONF_EXPERIMENTER_ID, EncodeConstants.ONF_ET_BUNDLE_CONTROL));
- }
-
- @Test
- public void testDeserializeWithoutProperties() {
- ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 01 " // bundle ID
- + "00 01 " // type
- + "00 03"); // flags
- BundleControl builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals(1, builtByFactory.getBundleId().getValue().intValue());
- BundleFlags flags = new BundleFlags(true, true);
- Assert.assertEquals("Wrong atomic flag", flags.isAtomic(), builtByFactory.getFlags().isAtomic());
- Assert.assertEquals("Wrong ordered flag", flags.isOrdered(), builtByFactory.getFlags().isOrdered());
- Assert.assertEquals("Wrong type", BundleControlType.ONFBCTOPENREPLY, builtByFactory.getType());
- Assert.assertTrue("Properties not empty", builtByFactory.getBundleProperty().isEmpty());
- }
-
- @Test
- public void testDeserializeWithProperties() {
- ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 01 " // bundle ID
- + "00 05 " // type
- + "00 02 " // flags
- + "ff ff " // type 1
- + "00 0c " // length 1
- + "00 00 00 01 " // experimenter ID 1
- + "00 00 00 02 " // experimenter type 1
- + "00 00 00 00 " // experimenter data 1
- + "00 00 " // type 2
- + "00 04 " // length 2
- + "00 00 00 00"); // data 2
- Mockito.when(registry.getDeserializer(Matchers.any(MessageCodeKey.class))).thenReturn(experimenterPropertyDeserializer);
- ((DeserializerRegistryInjector)factory).injectDeserializerRegistry(registry);
- BundleControl builtByFactory = BufferHelper.deserialize(factory, buffer);
- Assert.assertEquals(1, builtByFactory.getBundleId().getValue().intValue());
- BundleFlags flags = new BundleFlags(false, true);
- Assert.assertEquals("Wrong atomic flag", flags.isAtomic(), builtByFactory.getFlags().isAtomic());
- Assert.assertEquals("Wrong ordered flag", flags.isOrdered(), builtByFactory.getFlags().isOrdered());
- Assert.assertEquals("Wrong type", BundleControlType.ONFBCTCOMMITREPLY, builtByFactory.getType());
- BundleProperty property = builtByFactory.getBundleProperty().get(0);
- Assert.assertEquals("Wrong bundle property type", BundlePropertyType.ONFETBPTEXPERIMENTER, property.getType());
- BundleExperimenterProperty experimenterProperty = (BundleExperimenterProperty) property.getBundlePropertyEntry();
- Assert.assertEquals("Wrong experimenter ID", 1, experimenterProperty.getExperimenter().getValue().intValue());
- Assert.assertEquals("Wrong experimenter type", 2, experimenterProperty.getExpType().longValue());
- Mockito.verify(experimenterPropertyDeserializer, Mockito.times(1)).deserialize(buffer);
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
-import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdError;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-
-/**
- * Tests for {@link org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter.OnfExperimenterErrorFactory}.
- */
-public class OnfExperimenterErrorFactoryTest {
-
- private OFDeserializer<ErrorMessage> factory;
-
- @Before
- public void startUp() {
- DeserializerRegistry registry = new DeserializerRegistryImpl();
- registry.init();
- factory = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createExperimenterErrorDeserializerKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.ONF_EXPERIMENTER_ID));
- }
-
- @Test
- public void testVersion() {
- ByteBuf buffer = BufferHelper.buildBuffer("ff ff 08 fc 00 00 00 01");
- ErrorMessage builtByFactory = factory.deserialize(buffer);
- BufferHelper.checkHeaderV13(builtByFactory);
- }
-
- @Test
- public void testDeserializeBase() {
- ByteBuf buffer = BufferHelper.buildBuffer("ff ff 08 fc 4f 4e 46 00");
- ErrorMessage builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong type", EncodeConstants.EXPERIMENTER_VALUE, builtByFactory.getType().intValue());
- Assert.assertEquals("Wrong type string", "EXPERIMENTER", builtByFactory.getTypeString());
- Assert.assertEquals("Wrong experimenter ID", EncodeConstants.ONF_EXPERIMENTER_ID,
- builtByFactory.getAugmentation(ExperimenterIdError.class).getExperimenter().getValue().intValue());
- Assert.assertNull("Data is not null", builtByFactory.getData());
- }
-
- @Test
- public void testDeserializeCodes() {
- ByteBuf buffer = BufferHelper.buildBuffer("ff ff 08 fc 00 00 00 01");
- ErrorMessage builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2300, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_UNKNOWN", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 08 fd 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2301, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_EPERM", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 08 fe 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2302, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_ID", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 08 ff 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2303, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_EXIST", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 00 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2304, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_CLOSED", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 01 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2305, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_OUT_OF_BUNDLES", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 02 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2306, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_TYPE", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 03 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2307, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_FLAGS", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 04 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2308, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_BAD_LEN", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 05 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2309, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_BAD_XID", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 06 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2310, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_UNSUP", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 07 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2311, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_CONFLICT", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 08 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2312, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_TOO_MANY", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 09 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2313, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_FAILED", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 0a 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2314, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_TIMEOUT", builtByFactory.getCodeString());
-
- buffer = BufferHelper.buildBuffer("ff ff 09 0b 00 00 00 01");
- builtByFactory = factory.deserialize(buffer);
- Assert.assertEquals("Wrong code", 2315, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_IN_PROGRESS", builtByFactory.getCodeString());
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.UnpooledByteBufAllocator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundlePropertyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterPropertyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.PortModCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.PortModCaseBuilder;
-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.PortConfig;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
-
-/**
- * Test for {@link org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.AbstractBundleMessageFactory}
- * and util methods.
- */
-public class AbstractBundleMessageFactoryTest {
-
- @Test
- public void writeBundleFlags() throws Exception {
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- AbstractBundleMessageFactory.writeBundleFlags(new BundleFlags(true, true), out);
- Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
- }
-
- public static List<BundleProperty> createListWithBundleExperimenterProperty(BundleExperimenterPropertyData data) {
- BundlePropertyBuilder propertyBuilder = new BundlePropertyBuilder();
- propertyBuilder.setType(BundlePropertyType.ONFETBPTEXPERIMENTER);
- BundleExperimenterPropertyBuilder experimenterPropertyBuilder = new BundleExperimenterPropertyBuilder();
- experimenterPropertyBuilder.setExperimenter(new ExperimenterId(1L));
- experimenterPropertyBuilder.setExpType(2L);
-
- experimenterPropertyBuilder.setBundleExperimenterPropertyData(data);
- propertyBuilder.setBundlePropertyEntry(experimenterPropertyBuilder.build());
- return new ArrayList<>(Collections.singleton(propertyBuilder.build()));
- }
-
- public static BundleExperimenterPropertyData createBundleExperimenterPropertyData() {
- return new BundleExperimenterPropertyData() {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return null;
- }
- };
- }
-
- public static PortModCase createPortModCase() {
- PortModCaseBuilder caseBuilder = new PortModCaseBuilder();
- caseBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
- caseBuilder.setXid(3L);
- caseBuilder.setPortNo(new PortNumber(9L));
- caseBuilder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
- caseBuilder.setConfig(new PortConfig(true, false, true, false));
- caseBuilder.setMask(new PortConfig(false, true, false, true));
- caseBuilder.setAdvertise(new PortFeatures(true, false, false, false,
- false, false, false, true,
- false, false, false, false,
- false, false, false, false));
- return caseBuilder.build();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.UnpooledByteBufAllocator;
-import org.junit.Assert;
-import org.junit.Before;
-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.extensibility.SerializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
-import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleAddMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleAddMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.Message;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortMod;
-
-/**
- * Test for {@link org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactory}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class BundleAddMessageFactoryTest {
-
- private OFSerializer<BundleAddMessage> factory;
- @Mock
- SerializerRegistry registry;
- @Mock
- OFSerializer<PortMod> portModSerializer;
- @Mock
- OFSerializer<BundleExperimenterPropertyData> propertySerializer;
-
- @Before
- public void setUp() {
- SerializerRegistry registry = new SerializerRegistryImpl();
- registry.init();
- factory = registry.getSerializer(ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.ONF_EXPERIMENTER_ID,
- EncodeConstants.ONF_ET_BUNDLE_ADD_MESSAGE));
- }
-
- @Test
- public void testSerializeWithoutProperties() {
- BundleAddMessageBuilder builder = new BundleAddMessageBuilder();
- builder.setBundleId(new BundleId(1L));
- builder.setFlags(new BundleFlags(true, false));
-
- Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase();
- builder.setMessage(innerMessage);
-
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(portModSerializer);
- ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
- factory.serialize(builder.build(), out);
-
- Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
- long padding = out.readUnsignedShort();
- Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());
- Mockito.verify(portModSerializer, Mockito.times(1)).serialize((PortMod)innerMessage, out);
- }
-
- @Test
- public void testSerializeWithExperimenterProperty() {
- BundleAddMessageBuilder builder = new BundleAddMessageBuilder();
- builder.setBundleId(new BundleId(2L));
- builder.setFlags(new BundleFlags(true, false));
-
- Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase();
- builder.setMessage(innerMessage);
-
- BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest.createBundleExperimenterPropertyData();
- builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data));
-
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class)))
- .thenReturn(portModSerializer)
- .thenReturn(propertySerializer);
- ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
- factory.serialize(builder.build(), out);
-
- Assert.assertEquals("Wrong bundle ID", 2L, out.readUnsignedInt());
- long padding = out.readUnsignedShort();
- Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());
- Mockito.verify(portModSerializer, Mockito.times(1)).serialize((PortMod)innerMessage, out);
- Mockito.verify(propertySerializer, Mockito.times(1)).serialize(data, out);
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowjava.protocol.impl.serialization.experimenter;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.UnpooledByteBufAllocator;
-import org.junit.Assert;
-import org.junit.Before;
-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.extensibility.SerializerRegistryInjector;
-import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
-import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleControlType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControlBuilder;
-
-/**
- * Test for {@link org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactory}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class BundleControlFactoryTest {
-
- private OFSerializer<BundleControl> factory;
- @Mock
- SerializerRegistry registry;
- @Mock
- OFSerializer<BundleExperimenterPropertyData> serializer;
-
- @Before
- public void setUp() throws Exception {
- SerializerRegistry registry = new SerializerRegistryImpl();
- registry.init();
- factory = registry.getSerializer(ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey(
- EncodeConstants.OF13_VERSION_ID, EncodeConstants.ONF_EXPERIMENTER_ID, EncodeConstants.ONF_ET_BUNDLE_CONTROL));
- }
-
- @Test
- public void testSerializeWithoutProperties() {
- BundleControlBuilder builder = new BundleControlBuilder();
- builder.setBundleId(new BundleId(1L));
- builder.setType(BundleControlType.ONFBCTOPENREQUEST);
- builder.setFlags(new BundleFlags(true, true));
-
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- factory.serialize(builder.build(), out);
-
- Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
- Assert.assertEquals("Wrong type", BundleControlType.ONFBCTOPENREQUEST.getIntValue(), out.readUnsignedShort());
- Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
- Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
- }
-
- @Test
- public void testSerializeWithExperimenterProperty() {
- BundleControlBuilder builder = new BundleControlBuilder();
- builder.setBundleId(new BundleId(3L));
- builder.setType(BundleControlType.ONFBCTCOMMITREQUEST);
- builder.setFlags(new BundleFlags(false, true));
-
- BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest.createBundleExperimenterPropertyData();
- builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data));
-
- ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(serializer);
- ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
- factory.serialize(builder.build(), out);
-
- Assert.assertEquals("Wrong bundle ID", 3L, out.readUnsignedInt());
- Assert.assertEquals("Wrong type", BundleControlType.ONFBCTCOMMITREQUEST.getIntValue(), out.readUnsignedShort());
- Assert.assertEquals("Wrong flags", 2, out.readUnsignedShort());
- Assert.assertEquals("Wrong property type", BundlePropertyType.ONFETBPTEXPERIMENTER.getIntValue(), out.readUnsignedShort());
- int length = out.readUnsignedShort();
- Assert.assertEquals("Wrong experimenter ID", 1, out.readUnsignedInt());
- Assert.assertEquals("Wrong experimenter type", 2, out.readUnsignedInt());
- Mockito.verify(serializer, Mockito.times(1)).serialize(data, out);
- }
-
-}
\ No newline at end of file
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
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;
return new ExperimenterIdDeserializerKey(version, experimenterId, MeterBandExperimenterCase.class);
}
- /**
- * @param version openflow wire version
- * @param experimenterId experimenter ID
- * @param type experimenter type according to vendor implementation
- * @return key instance
- */
- public static ExperimenterIdTypeDeserializerKey createBundlePropertyDeserializerKey(
- short version, long experimenterId, long type) {
- return new ExperimenterIdTypeDeserializerKey(version, experimenterId, type, BundleExperimenterPropertyData.class);
- }
}
\ No newline at end of file
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
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;
return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, meterSubType);
}
- /**
- * @param msgVersion openflow wire version
- * @param experimenterId experimenter ID
- * @param type experimenter type according to vendor implementation
- * @return key instance
- */
- public static ExperimenterIdSerializerKey<BundleExperimenterPropertyData> createBundlePropertySerializerKey(
- short msgVersion, long experimenterId, long type) {
- return new ExperimenterIdTypeSerializerKey<>(msgVersion, experimenterId, type, BundleExperimenterPropertyData.class);
- }
}
\ No newline at end of file