From 5ac27ab3c68d12b2e1b01fbceb6029c49edb7420 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 24 Jul 2017 17:44:48 +0200 Subject: [PATCH] Update unit tests Add unit tests for: - Arp target transport address serializer - Packet in message deserializer - All serializers for multipart request messages - All serializers for table feature properties and match fields in table features - Configuration service and OpenFlowProviderConfigImpl - Device initializers (OF10 and OF13) - Single-layer direct statistics - Request context and input utils Remove custom comparators for sorting of actions and instructions and use OrderComparator.build() instead. Also, add missing sorting of table feature instructions and actions properties. See also: bug 8607 Change-Id: I83e0ad9a3469c80f4fa45df4de78c1e0fd53954b Signed-off-by: Tomas Slusny --- .../impl/OpenFlowPluginProviderImpl.java | 2 - .../ConfigurationServiceFactoryImpl.java | 4 +- .../initialization/OF10DeviceInitializer.java | 15 +- .../messages/GroupMessageDeserializer.java | 7 +- .../AbstractActionInstructionSerializer.java | 4 +- .../messages/FlowMessageSerializer.java | 15 +- ...plyActionsMissTablePropertySerializer.java | 22 +- .../ApplyActionsTablePropertySerializer.java | 22 +- ...structionsMissTablePropertySerializer.java | 22 +- .../InstructionsTablePropertySerializer.java | 22 +- ...iteActionsMissTablePropertySerializer.java | 22 +- .../WriteActionsTablePropertySerializer.java | 22 +- .../serialization/util/ActionUtil.java | 15 - .../serialization/util/InstructionUtil.java | 5 +- .../services/util/RequestContextUtil.java | 6 +- .../impl/services/util/RequestInputUtils.java | 6 +- .../impl/util/DeviceInitializationUtil.java | 2 +- .../impl/OpenFlowPluginProviderImplTest.java | 21 +- .../MultipartReplyTranslatorUtilTest.java | 327 ++++++++++++++ .../ConfigurationServiceFactoryImplTest.java | 148 +++++++ .../OpenFlowProviderConfigImplTest.java | 170 +++++++ .../device/TransactionChainManagerTest.java | 18 +- .../DeviceInitializerProviderTest.java | 46 ++ .../OF10DeviceInitializerTest.java | 141 ++++++ .../OF13DeviceInitializerTest.java | 156 +++++++ .../AbstractDeserializerTest.java | 7 + ...TransportAddressEntryDeserializerTest.java | 67 +++ .../PacketInMessageDeserializerTest.java | 88 ++++ .../MultipartRequestDescSerializerTest.java | 41 ++ ...questFlowAggregateStatsSerializerTest.java | 89 ++++ ...ltipartRequestFlowStatsSerializerTest.java | 89 ++++ ...rtRequestFlowTableStatsSerializerTest.java | 41 ++ ...ltipartRequestGroupDescSerializerTest.java | 41 ++ ...artRequestGroupFeaturesSerializerTest.java | 41 ++ ...tipartRequestGroupStatsSerializerTest.java | 48 ++ ...MultipartRequestMessageSerializerTest.java | 20 +- ...ipartRequestMeterConfigSerializerTest.java | 48 ++ ...artRequestMeterFeaturesSerializerTest.java | 41 ++ ...tipartRequestMeterStatsSerializerTest.java | 48 ++ ...ultipartRequestPortDescSerializerTest.java | 41 ++ ...ltipartRequestPortStatsSerializerTest.java | 48 ++ ...tipartRequestQueueStatsSerializerTest.java | 50 +++ ...artRequestTableFeaturesSerializerTest.java | 106 +++++ .../AbstractTablePropertySerializerTest.java | 55 +++ ...ctionsMissTablePropertySerializerTest.java | 56 +++ ...plyActionsTablePropertySerializerTest.java | 56 +++ ...tfieldMissTablePropertySerializerTest.java | 60 +++ ...lySetfieldTablePropertySerializerTest.java | 60 +++ ...ctionsMissTablePropertySerializerTest.java | 56 +++ ...structionsTablePropertySerializerTest.java | 56 +++ .../MatchTablePropertySerializerTest.java | 59 +++ ...tTableMissTablePropertySerializerTest.java | 47 ++ .../NextTableTablePropertySerializerTest.java | 47 ++ .../WildcardsTablePropertySerializerTest.java | 59 +++ ...ctionsMissTablePropertySerializerTest.java | 56 +++ ...iteActionsTablePropertySerializerTest.java | 56 +++ ...tfieldMissTablePropertySerializerTest.java | 60 +++ ...teSetfieldTablePropertySerializerTest.java | 60 +++ .../matchfield/MatchFieldSerializerTest.java | 418 ++++++++++++++++++ .../flow/DeviceFlowRegistryImplTest.java | 8 + .../group/DeviceGroupRegistryImplTest.java | 9 +- .../meter/DeviceMeterRegistryImplTest.java | 10 +- .../impl/rpc/RpcManagerImplTest.java | 33 +- .../services/util/RequestContextUtilTest.java | 52 +++ .../services/util/RequestInputUtilsTest.java | 35 ++ .../AbstractDirectStatisticsServiceTest.java | 2 +- .../FlowDirectStatisticsServiceTest.java | 115 +++++ .../GroupDirectStatisticsServiceTest.java | 95 ++++ .../MeterDirectStatisticsServiceTest.java | 106 +++++ ...eConnectorDirectStatisticsServiceTest.java | 92 ++++ .../QueueDirectStatisticsServiceTest.java | 102 +++++ .../util/DeviceInitializationUtilTest.java | 83 ++++ 72 files changed, 4046 insertions(+), 151 deletions(-) create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/common/MultipartReplyTranslatorUtilTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImplTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/OpenFlowProviderConfigImplTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/DeviceInitializerProviderTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF13DeviceInitializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/match/ArpTargetTransportAddressEntryDeserializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/PacketInMessageDeserializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestDescSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowAggregateStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowTableStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupDescSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupFeaturesSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterConfigSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterFeaturesSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortDescSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestQueueStatsSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestTableFeaturesSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/AbstractTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/MatchTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WildcardsTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldMissTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldTablePropertySerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/matchfield/MatchFieldSerializerTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtilTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtilsTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtilTest.java diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java index 7759922d36..b8edaff73d 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java @@ -41,8 +41,6 @@ import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager; import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager; -import org.opendaylight.openflowplugin.api.openflow.lifecycle.OwnershipChangeListener; -import org.opendaylight.openflowplugin.api.openflow.lifecycle.ReconciliationFrameworkRegistrar; import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager; import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager; diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java index 834b595fdc..b5e719ee22 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java @@ -83,8 +83,8 @@ public class ConfigurationServiceFactoryImpl implements ConfigurationServiceFact .build()); LOG.info("Loading configuration from '{}' configuration file", OFConstants.CONFIG_FILE_ID); - Optional.ofNullable(bundleContext.getServiceReference(ConfigurationAdmin.class.getName())).ifPresent(serviceReference -> { - final ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) bundleContext.getService(serviceReference); + Optional.ofNullable(bundleContext.getServiceReference(ConfigurationAdmin.class)).ifPresent(serviceReference -> { + final ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference); try { final Configuration configuration = configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializer.java index 161b7b83e5..b6d1dcfcf4 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializer.java @@ -66,7 +66,7 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { final CapabilitiesV10 capabilitiesV10 = connectionContext.getFeatures().getCapabilitiesV10(); // Set capabilities for this device based on capabilities of connection context - LOG.debug("Setting capabilities for device {}", deviceInfo.getLOGValue()); + LOG.debug("Setting capabilities for device {}", deviceInfo); DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(deviceState, capabilitiesV10); final ListenableFuture future = requestMultipart(MultipartType.OFPMPDESC, deviceContext); @@ -74,10 +74,10 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { @Override public void onSuccess(@Nullable final Boolean result) { if (Boolean.TRUE.equals(result)) { - LOG.debug("Creating empty flow capable node: {}", deviceInfo.getLOGValue()); + LOG.debug("Creating empty flow capable node: {}", deviceInfo); makeEmptyFlowCapableNode(deviceContext, deviceInfo); - LOG.debug("Creating empty tables for {}", deviceInfo.getLOGValue()); + LOG.debug("Creating empty tables for {}", deviceInfo); DeviceInitializationUtil.makeEmptyTables( deviceContext, deviceInfo, @@ -87,8 +87,8 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { @Override public void onFailure(@Nonnull final Throwable t) { - LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceInfo.getLOGValue()); - LOG.trace("Error for node {} : ", deviceInfo.getLOGValue(), t); + LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceInfo); + LOG.trace("Error for node {} : ", deviceInfo, t); } }); @@ -96,6 +96,7 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { @Nullable @Override public Void apply(@Nullable final Boolean input) { + LOG.debug("Writing physical port information for {}", deviceInfo); writePhyPortInformation(deviceContext); return null; } @@ -130,7 +131,7 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { new FlowCapableNodeConnectorStatisticsDataBuilder().build()) .build()); } catch (final Exception e) { - LOG.debug("Failed to write node {} to DS ", deviceInfo.getLOGValue(), e); + LOG.debug("Failed to write node {} to DS ", deviceInfo, e); } }); } @@ -143,7 +144,7 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer { .augmentation(FlowCapableNode.class), new FlowCapableNodeBuilder().build()); } catch (final Exception e) { - LOG.debug("Failed to write empty node {} to DS ", deviceInfo.getLOGValue(), e); + LOG.debug("Failed to write empty node {} to DS ", deviceInfo, e); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/GroupMessageDeserializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/GroupMessageDeserializer.java index 6a9d0b63dd..dfa74c5758 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/GroupMessageDeserializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/GroupMessageDeserializer.java @@ -8,11 +8,10 @@ package org.opendaylight.openflowplugin.impl.protocol.deserialization.messages; +import io.netty.buffer.ByteBuf; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; 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; @@ -30,8 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand; -import io.netty.buffer.ByteBuf; - public class GroupMessageDeserializer implements OFDeserializer, DeserializerRegistryInjector { private static final byte PADDING = 1; @@ -92,7 +89,7 @@ public class GroupMessageDeserializer implements OFDeserializer, D buckets.add(bucket.build()); } - Collections.sort(buckets, COMPARATOR); + buckets.sort(COMPARATOR); return builder .setBuckets(new BucketsBuilder() .setBucket(buckets) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/AbstractActionInstructionSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/AbstractActionInstructionSerializer.java index 47904b72e3..0de90d0fde 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/AbstractActionInstructionSerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/instructions/AbstractActionInstructionSerializer.java @@ -15,6 +15,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.ActionList; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction; @@ -38,7 +39,8 @@ public abstract class AbstractActionInstructionSerializer extends AbstractInstru int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION); - ActionUtil.sortActions(as).forEach(a -> ActionUtil.writeAction(a.getAction(), version, registry, outBuffer)); + as.stream().sorted(OrderComparator.build()).forEach(a -> ActionUtil + .writeAction(a.getAction(), version, registry, outBuffer)); outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); return actions; }).orElseGet(() -> { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/messages/FlowMessageSerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/messages/FlowMessageSerializer.java index d99feb7565..fb645268e1 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/messages/FlowMessageSerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/messages/FlowMessageSerializer.java @@ -13,7 +13,6 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -25,8 +24,8 @@ import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.InstructionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.ActionList; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; @@ -76,12 +75,6 @@ public class FlowMessageSerializer extends AbstractMessageSerializer COMPARATOR = (inst1, inst2) -> { - if (inst1.getOrder() == null || inst2.getOrder() == null) return 0; - return inst1.getOrder().compareTo(inst2.getOrder()); - }; - private static final VlanMatch VLAN_MATCH_FALSE = new VlanMatchBuilder() .setVlanId(new VlanIdBuilder() .setVlanIdPresent(false) @@ -190,7 +183,7 @@ public class FlowMessageSerializer extends AbstractMessageSerializer is .stream() .filter(Objects::nonNull) - .sorted(COMPARATOR) + .sorted(OrderComparator.build()) .map(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Instruction::getInstruction) .filter(Objects::nonNull) .map(i -> protocol.flatMap(p -> updateInstruction(i, p)).orElse(i)) @@ -274,8 +267,8 @@ public class FlowMessageSerializer extends AbstractMessageSerializer Optional.ofNullable(as.getAction())) - .map(a -> ActionUtil.sortActions(a) - .stream() + .map(a -> a.stream() + .sorted(OrderComparator.build()) .flatMap(action -> { final List actions = new ArrayList<>(); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializer.java index bbe617f8ad..6aea103385 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss; @@ -24,16 +25,17 @@ public class ApplyActionsMissTablePropertySerializer extends AbstractTableProper @Override protected void serializeProperty(final ApplyActionsMiss property, final ByteBuf byteBuf) { property - .getApplyActionsMiss() - .getAction() - .stream() - .map(Action::getAction) - .forEach(action -> ActionUtil - .writeActionHeader( - action, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getApplyActionsMiss() + .getAction() + .stream() + .sorted(OrderComparator.build()) + .map(Action::getAction) + .forEach(action -> ActionUtil + .writeActionHeader( + action, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializer.java index 22754799d9..d9689db68c 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions; @@ -24,16 +25,17 @@ public class ApplyActionsTablePropertySerializer extends AbstractTablePropertySe @Override protected void serializeProperty(final ApplyActions property, final ByteBuf byteBuf) { property - .getApplyActions() - .getAction() - .stream() - .map(Action::getAction) - .forEach(action -> ActionUtil - .writeActionHeader( - action, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getApplyActions() + .getAction() + .stream() + .sorted(OrderComparator.build()) + .map(Action::getAction) + .forEach(action -> ActionUtil + .writeActionHeader( + action, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializer.java index d5b1e97068..8f0c431ee3 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.InstructionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss; @@ -24,16 +25,17 @@ public class InstructionsMissTablePropertySerializer extends AbstractTableProper @Override protected void serializeProperty(final InstructionsMiss property, final ByteBuf byteBuf) { property - .getInstructionsMiss() - .getInstruction() - .stream() - .map(Instruction::getInstruction) - .forEach(instruction -> InstructionUtil - .writeInstructionHeader( - instruction, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getInstructionsMiss() + .getInstruction() + .stream() + .sorted(OrderComparator.build()) + .map(Instruction::getInstruction) + .forEach(instruction -> InstructionUtil + .writeInstructionHeader( + instruction, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializer.java index f5dcf71c86..d58c23c457 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.InstructionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions; @@ -24,16 +25,17 @@ public class InstructionsTablePropertySerializer extends AbstractTablePropertySe @Override protected void serializeProperty(final Instructions property, final ByteBuf byteBuf) { property - .getInstructions() - .getInstruction() - .stream() - .map(Instruction::getInstruction) - .forEach(instruction -> InstructionUtil - .writeInstructionHeader( - instruction, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getInstructions() + .getInstruction() + .stream() + .sorted(OrderComparator.build()) + .map(Instruction::getInstruction) + .forEach(instruction -> InstructionUtil + .writeInstructionHeader( + instruction, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializer.java index 7869880e76..1c0d240ce3 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss; @@ -24,16 +25,17 @@ public class WriteActionsMissTablePropertySerializer extends AbstractTableProper @Override protected void serializeProperty(final WriteActionsMiss property, final ByteBuf byteBuf) { property - .getWriteActionsMiss() - .getAction() - .stream() - .map(Action::getAction) - .forEach(action -> ActionUtil - .writeActionHeader( - action, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getWriteActionsMiss() + .getAction() + .stream() + .sorted(OrderComparator.build()) + .map(Action::getAction) + .forEach(action -> ActionUtil + .writeActionHeader( + action, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializer.java index 0556941d0d..c0e96fd3ec 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializer.java @@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegist import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions; @@ -24,16 +25,17 @@ public class WriteActionsTablePropertySerializer extends AbstractTablePropertySe @Override protected void serializeProperty(final WriteActions property, final ByteBuf byteBuf) { property - .getWriteActions() - .getAction() - .stream() - .map(Action::getAction) - .forEach(action -> ActionUtil - .writeActionHeader( - action, - EncodeConstants.OF13_VERSION_ID, - registry, - byteBuf)); + .getWriteActions() + .getAction() + .stream() + .sorted(OrderComparator.build()) + .map(Action::getAction) + .forEach(action -> ActionUtil + .writeActionHeader( + action, + EncodeConstants.OF13_VERSION_ID, + registry, + byteBuf)); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/ActionUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/ActionUtil.java index 6478b0e1fb..7cb7188229 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/ActionUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/ActionUtil.java @@ -8,9 +8,7 @@ package org.opendaylight.openflowplugin.impl.protocol.serialization.util; -import com.google.common.collect.Ordering; import io.netty.buffer.ByteBuf; -import java.util.List; import java.util.Optional; import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; @@ -22,7 +20,6 @@ import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava; import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; import org.opendaylight.openflowplugin.extension.api.TypeVersionKey; import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey; @@ -36,18 +33,6 @@ import org.slf4j.LoggerFactory; public class ActionUtil { private static final Logger LOG = LoggerFactory.getLogger(ActionUtil.class); - private static final Ordering ACTION_ORDERING = - Ordering.from(OrderComparator.build()); - - /** - * Sort actions based on order - * @param actions actions - * @return sorted copy of actions - */ - public static List sortActions(final Iterable actions) { - return ACTION_ORDERING.sortedCopy(actions); - } - /** * Serialize OpenFlow action, using extension converter if available * TODO: Remove also extension converters diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/InstructionUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/InstructionUtil.java index bd5de027f4..eb65b15222 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/InstructionUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/util/InstructionUtil.java @@ -14,7 +14,6 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction; /** @@ -37,7 +36,7 @@ public class InstructionUtil { registry.>getSerializer( new MessageTypeKey<>( - EncodeConstants.OF13_VERSION_ID, + version, (Class) instruction.getImplementedInterface())) .serialize(instruction, outBuffer); } @@ -58,7 +57,7 @@ public class InstructionUtil { registry.>getSerializer( new MessageTypeKey<>( - EncodeConstants.OF13_VERSION_ID, + version, (Class) instruction.getImplementedInterface())) .serializeHeader(instruction, outBuffer); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtil.java index a14f565638..ebd788404d 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtil.java @@ -23,8 +23,10 @@ public final class RequestContextUtil { } - public static ListenableFuture> closeRequestContextWithRpcError(final RequestContext requestContext, final String errorMessage) { - RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed().withRpcError(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "", errorMessage)); + public static ListenableFuture> closeRequestContextWithRpcError(final RequestContext requestContext, + final String errorMessage) { + RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed().withRpcError(RpcResultBuilder + .newError(RpcError.ErrorType.APPLICATION, "", errorMessage)); requestContext.setResult(rpcResultBuilder.build()); closeRequestContext(requestContext); return requestContext.getFuture(); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtils.java index 421cecd750..37519bc0cf 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtils.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtils.java @@ -12,9 +12,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; -/** - * Created by Martin Bobak <mbobak@cisco.com> on 26.3.2015. - */ public final class RequestInputUtils { private RequestInputUtils() { @@ -22,7 +19,8 @@ public final class RequestInputUtils { } public static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart, - Long xid, Short version) { + Long xid, + Short version) { MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); mprInput.setType(multipart); mprInput.setVersion(version); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtil.java index 54f2d71318..397c4abce9 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtil.java @@ -72,7 +72,7 @@ public class DeviceInitializationUtil { * @param deviceInfo device info * @param nrOfTables number of tables */ - public static void makeEmptyTables(final TxFacade txFacade, final DeviceInfo deviceInfo, final Short nrOfTables) { + public static void makeEmptyTables(final TxFacade txFacade, final DeviceInfo deviceInfo, final short nrOfTables) { if (LOG.isDebugEnabled()) { LOG.debug("About to create {} empty tables for node {}.", nrOfTables, deviceInfo.getLOGValue()); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java index acf9f1f42e..feb26ec103 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java @@ -29,6 +29,7 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; +import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; @@ -78,15 +79,14 @@ public class OpenFlowPluginProviderImplTest { private static final long BASIC_TIMER_DELAY = 1L; private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false; - private OpenFlowPluginProviderImpl provider; - @Before public void setUp() throws Exception { when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null)); when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration); when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration); - when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null)); + when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true)); + when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true)); when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()), any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION); when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any())).thenReturn(THREAD_POOL_MIN_THREADS); when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any())).thenReturn(THREAD_POOL_MAX_THREADS); @@ -94,21 +94,22 @@ public class OpenFlowPluginProviderImplTest { when(configurationService.getProperty(eq(ConfigurationProperty.RPC_REQUESTS_QUOTA.toString()), any())).thenReturn(RPC_REQUESTS_QUOTA); when(configurationService.getProperty(eq(ConfigurationProperty.GLOBAL_NOTIFICATION_QUOTA.toString()), any())).thenReturn(GLOBAL_NOTIFICATION_QUOTA); when(configurationService.getProperty(eq(ConfigurationProperty.BASIC_TIMER_DELAY.toString()), any())).thenReturn(BASIC_TIMER_DELAY); + } - provider = new OpenFlowPluginProviderImpl( + @Test + public void testInitializeAndClose() throws Exception { + final OpenFlowPluginProvider provider = new OpenFlowPluginProviderFactoryImpl().newInstance( configurationService, - Lists.newArrayList(switchConnectionProvider), dataBroker, rpcProviderRegistry, notificationPublishService, - clusterSingletonServiceProvider, entityOwnershipService, + Lists.newArrayList(switchConnectionProvider), + clusterSingletonServiceProvider, mastershipChangeServiceManager); - } - @Test - public void testInitializeAndClose() throws Exception { - provider.initialize(); verify(switchConnectionProvider).startup(); + provider.close(); + verify(switchConnectionProvider).shutdown(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/common/MultipartReplyTranslatorUtilTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/common/MultipartReplyTranslatorUtilTest.java new file mode 100644 index 0000000000..b84fd961ff --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/common/MultipartReplyTranslatorUtilTest.java @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.common; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.Collections; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; +import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian; +import org.opendaylight.openflowplugin.impl.util.TranslatorLibraryUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder; + +@RunWith(MockitoJUnitRunner.class) +public class MultipartReplyTranslatorUtilTest { + @Mock + private DeviceInfo deviceInfo; + private ConvertorExecutor convertorExecutor = ConvertorManagerFactory.createDefaultManager(); + private TranslatorLibrarian translatorLibrarian; + + @Before + public void setUp() throws Exception { + when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); + + translatorLibrarian = new TranslatorLibrarian() { + private TranslatorLibrary translatorLibrary; + + @Override + public TranslatorLibrary oook() { + return translatorLibrary; + } + + @Override + public void setTranslatorLibrary(final TranslatorLibrary translatorLibrary) { + this.translatorLibrary = translatorLibrary; + } + }; + + TranslatorLibraryUtil.injectBasicTranslatorLibrary(translatorLibrarian, convertorExecutor); + } + + private static MultipartReply buildReply(final MultipartType multipartType, + final MultipartReplyBody multipartReplyBody) { + return new MultipartReplyMessageBuilder() + .setType(multipartType) + .setMultipartReplyBody(multipartReplyBody) + .build(); + } + + private void dummyAssertReply(final MultipartReply multipartReply) { + final Optional translatedReply = MultipartReplyTranslatorUtil + .translate(multipartReply, deviceInfo, convertorExecutor, translatorLibrarian.oook()); + + assertTrue(translatedReply.isPresent()); + } + + @Test + public void translatePortDesc() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPPORTDESC, + new MultipartReplyPortDescCaseBuilder() + .setMultipartReplyPortDesc(new MultipartReplyPortDescBuilder() + .setPorts(Collections.singletonList(new PortsBuilder() + .build())) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateTableFeatures() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPTABLEFEATURES, + new MultipartReplyTableFeaturesCaseBuilder() + .setMultipartReplyTableFeatures(new MultipartReplyTableFeaturesBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateDesc() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPDESC, + new MultipartReplyDescCaseBuilder() + .setMultipartReplyDesc(new MultipartReplyDescBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateFlow() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPFLOW, + new MultipartReplyFlowCaseBuilder() + .setMultipartReplyFlow(new MultipartReplyFlowBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateAggregate() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPAGGREGATE, + new MultipartReplyAggregateCaseBuilder() + .setMultipartReplyAggregate(new MultipartReplyAggregateBuilder() + .setByteCount(BigInteger.ONE) + .setFlowCount(10L) + .setPacketCount(BigInteger.ONE) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translatePortStats() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPPORTSTATS, + new MultipartReplyPortStatsCaseBuilder() + .setMultipartReplyPortStats(new MultipartReplyPortStatsBuilder() + .setPortStats(Collections.singletonList(new PortStatsBuilder() + .build())) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateGroup() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPGROUP, + new MultipartReplyGroupCaseBuilder() + .setMultipartReplyGroup(new MultipartReplyGroupBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateGroupDesc() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPGROUPDESC, + new MultipartReplyGroupDescCaseBuilder() + .setMultipartReplyGroupDesc(new MultipartReplyGroupDescBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateGroupFeatures() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPGROUPFEATURES, + new MultipartReplyGroupFeaturesCaseBuilder() + .setMultipartReplyGroupFeatures(new MultipartReplyGroupFeaturesBuilder() + .setTypes(new GroupTypes(true, false, false, false)) + .setCapabilities(new GroupCapabilities(false, true, true, false)) + .setActionsBitmap(Collections.singletonList(new ActionType( + true, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false))) + + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateMeter() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPMETER, + new MultipartReplyMeterCaseBuilder() + .setMultipartReplyMeter(new MultipartReplyMeterBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateMeterConfig() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPMETERCONFIG, + new MultipartReplyMeterConfigCaseBuilder() + .setMultipartReplyMeterConfig(new MultipartReplyMeterConfigBuilder() + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateMeterFeatures() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPMETERFEATURES, + new MultipartReplyMeterFeaturesCaseBuilder() + .setMultipartReplyMeterFeatures(new MultipartReplyMeterFeaturesBuilder() + .setMaxMeter(10L) + .setCapabilities(new MeterFlags(true, false, false, false)) + .setBandTypes(new MeterBandTypeBitmap(true, false)) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateTable() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPTABLE, + new MultipartReplyTableCaseBuilder() + .setMultipartReplyTable(new MultipartReplyTableBuilder() + .setTableStats(Collections.singletonList(new TableStatsBuilder() + .setActiveCount(10L) + .setLookupCount(BigInteger.ONE) + .setMatchedCount(BigInteger.ONE) + .setTableId((short) 10) + .build())) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } + + @Test + public void translateQueue() { + final MultipartReply multipartReply = buildReply( + MultipartType.OFPMPQUEUE, + new MultipartReplyQueueCaseBuilder() + .setMultipartReplyQueue(new MultipartReplyQueueBuilder() + .setQueueStats(Collections.singletonList(new QueueStatsBuilder() + .setTxErrors(BigInteger.ONE) + .setTxBytes(BigInteger.ONE) + .setTxPackets(BigInteger.ONE) + .setDurationNsec(10L) + .setDurationSec(10L) + .setQueueId(10L) + .build())) + .build()) + .build()); + + dummyAssertReply(multipartReply); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImplTest.java new file mode 100644 index 0000000000..8d938cd963 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImplTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.configuration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableMap; +import java.util.Dictionary; +import java.util.Hashtable; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener; +import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty; +import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigurationServiceFactoryImplTest { + private static final int CONFIG_PROP_COUNT = 16; + private static final boolean IS_STATISTICS_POLLING_ON = true; + private static final int BARRIER_COUNT_LIMIT = 2000; + private static final long BARRIER_INTERVAL_TIMEOUT_LIMIT = 3000; + private static final long ECHO_REPLY_TIMEOUT = 4000; + private static final boolean ENABLE_FLOW_REMOVED_NOTIFICATION = true; + private static final boolean SKIP_TABLE_FEATURES = true; + private static final long BASIC_TIMER_DELAY = 2690; + private static final long MAXIMUM_TIMER_DELAY = 3679; + private static final boolean SWITCH_FEATURES_MANDATORY = false; + private static final boolean IS_STATISTICS_RPC_ENABLED = false; + private static final boolean USE_SINGLE_LAYER_SERIALIZATION = true; + private static final int RPC_REQUESTS_QUOTA = 2500; + private static final long GLOBAL_NOTIFICATION_QUOTA = 9000; + private static final int THREAD_POOL_MIN_THREADS = 3; + private static final int THREAD_POOL_MIN_THREADS_UPDATE = 4; + private static final int THREAD_POOL_MAX_THREADS = 1000; + private static final long THREAD_POOL_TIMEOUT = 60; + + @Mock + private OpenflowProviderConfig config; + + @Mock + private BundleContext bundleContext; + + @Mock + private ConfigurationListener configurationListener; + + @Mock + private ConfigurationAdmin configurationAdmin; + + @Mock + private ServiceReference serviceReference; + + @Mock + private Configuration configuration; + + private ConfigurationService configurationService; + + @Before + public void setUp() throws Exception { + when(config.isIsStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON); + when(config.getBarrierCountLimit()).thenReturn(new NonZeroUint16Type(BARRIER_COUNT_LIMIT)); + when(config.getBarrierIntervalTimeoutLimit()).thenReturn(new NonZeroUint32Type(BARRIER_INTERVAL_TIMEOUT_LIMIT)); + when(config.getEchoReplyTimeout()).thenReturn(new NonZeroUint32Type(ECHO_REPLY_TIMEOUT)); + when(config.isEnableFlowRemovedNotification()).thenReturn(ENABLE_FLOW_REMOVED_NOTIFICATION); + when(config.isSkipTableFeatures()).thenReturn(SKIP_TABLE_FEATURES); + when(config.getBasicTimerDelay()).thenReturn(new NonZeroUint32Type(BASIC_TIMER_DELAY)); + when(config.getMaximumTimerDelay()).thenReturn(new NonZeroUint32Type(MAXIMUM_TIMER_DELAY)); + when(config.isSwitchFeaturesMandatory()).thenReturn(SWITCH_FEATURES_MANDATORY); + when(config.isIsStatisticsRpcEnabled()).thenReturn(IS_STATISTICS_RPC_ENABLED); + when(config.isUseSingleLayerSerialization()).thenReturn(USE_SINGLE_LAYER_SERIALIZATION); + when(config.getRpcRequestsQuota()).thenReturn(new NonZeroUint16Type(RPC_REQUESTS_QUOTA)); + when(config.getGlobalNotificationQuota()).thenReturn(GLOBAL_NOTIFICATION_QUOTA); + when(config.getThreadPoolMinThreads()).thenReturn(THREAD_POOL_MIN_THREADS); + when(config.getThreadPoolMaxThreads()).thenReturn(new NonZeroUint16Type(THREAD_POOL_MAX_THREADS)); + when(config.getThreadPoolTimeout()).thenReturn(THREAD_POOL_TIMEOUT); + + final Dictionary properties = new Hashtable<>(); + properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(), IS_STATISTICS_POLLING_ON); + + when(configuration.getProperties()).thenReturn(properties); + when(configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID)).thenReturn(configuration); + when(bundleContext.getService(serviceReference)).thenReturn(configurationAdmin); + when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(serviceReference); + + configurationService = new ConfigurationServiceFactoryImpl() + .newInstance(config, bundleContext); + } + + @Test + public void update() throws Exception { + final int tpMinThreads = configurationService + .getProperty(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), Integer::valueOf); + + configurationService.update(ImmutableMap + .builder() + .put(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), String + .valueOf(THREAD_POOL_MIN_THREADS_UPDATE)) + .build()); + + final int tpMinThreadsNew = configurationService + .getProperty(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), Integer::valueOf); + + assertNotEquals(tpMinThreadsNew, tpMinThreads); + assertEquals(tpMinThreadsNew, THREAD_POOL_MIN_THREADS_UPDATE); + } + + @Test + public void getProperty() throws Exception { + final int tpMaxThreads = configurationService + .getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf); + + assertEquals(THREAD_POOL_MAX_THREADS, tpMaxThreads); + } + + @Test + public void registerListener() throws Exception { + configurationService.registerListener(configurationListener); + verify(configurationListener, times(CONFIG_PROP_COUNT)).onPropertyChanged(any(), any()); + } + + @Test(expected = NumberFormatException.class) + public void close() throws Exception { + configurationService.close(); + configurationService.getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/OpenFlowProviderConfigImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/OpenFlowProviderConfigImplTest.java new file mode 100644 index 0000000000..9e9076b5ae --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/configuration/OpenFlowProviderConfigImplTest.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.configuration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty; +import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig; + +@RunWith(MockitoJUnitRunner.class) +public class OpenFlowProviderConfigImplTest { + private static final Boolean IS_STATISTICS_POLLING_ON = true; + private static final Integer BARRIER_COUNT_LIMIT = 2000; + private static final Long BARRIER_INTERVAL_TIMEOUT_LIMIT = 3000L; + private static final Long ECHO_REPLY_TIMEOUT = 4000L; + private static final Boolean ENABLE_FLOW_REMOVED_NOTIFICATION = true; + private static final Boolean SKIP_TABLE_FEATURES = true; + private static final Long BASIC_TIMER_DELAY = 2690L; + private static final Long MAXIMUM_TIMER_DELAY = 3679L; + private static final Boolean SWITCH_FEATURES_MANDATORY = false; + private static final Boolean IS_STATISTICS_RPC_ENABLED = false; + private static final Boolean USE_SINGLE_LAYER_SERIALIZATION = true; + private static final Integer RPC_REQUESTS_QUOTA = 2500; + private static final Long GLOBAL_NOTIFICATION_QUOTA = 9000L; + private static final Integer THREAD_POOL_MIN_THREADS = 3; + private static final Integer THREAD_POOL_MAX_THREADS = 1000; + private static final Long THREAD_POOL_TIMEOUT = 60L; + + @Mock + private ConfigurationService configurationService; + private OpenflowProviderConfig openflowProviderConfig; + + @Before + public void setUp() throws Exception { + when(configurationService.getProperty(eq(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString()), any())) + .thenReturn(IS_STATISTICS_POLLING_ON); + when(configurationService.getProperty(eq(ConfigurationProperty.BARRIER_COUNT_LIMIT.toString()), any())) + .thenReturn(BARRIER_COUNT_LIMIT); + when(configurationService.getProperty(eq(ConfigurationProperty.BARRIER_INTERVAL_TIMEOUT_LIMIT.toString()), any())) + .thenReturn(BARRIER_INTERVAL_TIMEOUT_LIMIT); + when(configurationService.getProperty(eq(ConfigurationProperty.ECHO_REPLY_TIMEOUT.toString()), any())) + .thenReturn(ECHO_REPLY_TIMEOUT); + when(configurationService.getProperty(eq(ConfigurationProperty.ENABLE_FLOW_REMOVED_NOTIFICATION.toString()), any())) + .thenReturn(ENABLE_FLOW_REMOVED_NOTIFICATION); + when(configurationService.getProperty(eq(ConfigurationProperty.SKIP_TABLE_FEATURES.toString()), any())) + .thenReturn(SKIP_TABLE_FEATURES); + when(configurationService.getProperty(eq(ConfigurationProperty.BASIC_TIMER_DELAY.toString()), any())) + .thenReturn(BASIC_TIMER_DELAY); + when(configurationService.getProperty(eq(ConfigurationProperty.MAXIMUM_TIMER_DELAY.toString()), any())) + .thenReturn(MAXIMUM_TIMER_DELAY); + when(configurationService.getProperty(eq(ConfigurationProperty.SWITCH_FEATURES_MANDATORY.toString()), any())) + .thenReturn(SWITCH_FEATURES_MANDATORY); + when(configurationService.getProperty(eq(ConfigurationProperty.IS_STATISTICS_RPC_ENABLED.toString()), any())) + .thenReturn(IS_STATISTICS_RPC_ENABLED); + when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()), any())) + .thenReturn(USE_SINGLE_LAYER_SERIALIZATION); + when(configurationService.getProperty(eq(ConfigurationProperty.RPC_REQUESTS_QUOTA.toString()), any())) + .thenReturn(RPC_REQUESTS_QUOTA); + when(configurationService.getProperty(eq(ConfigurationProperty.GLOBAL_NOTIFICATION_QUOTA.toString()), any())) + .thenReturn(GLOBAL_NOTIFICATION_QUOTA); + when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any())) + .thenReturn(THREAD_POOL_MIN_THREADS); + when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any())) + .thenReturn(THREAD_POOL_MAX_THREADS); + when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any())) + .thenReturn(THREAD_POOL_TIMEOUT); + openflowProviderConfig = new OpenFlowProviderConfigImpl(configurationService); + } + + @After + public void tearDown() throws Exception { + configurationService.close(); + } + + @Test + public void getRpcRequestsQuota() throws Exception { + assertEquals(RPC_REQUESTS_QUOTA, openflowProviderConfig.getRpcRequestsQuota().getValue()); + } + + @Test + public void isSwitchFeaturesMandatory() throws Exception { + assertEquals(SWITCH_FEATURES_MANDATORY, openflowProviderConfig.isSwitchFeaturesMandatory()); + } + + @Test + public void getGlobalNotificationQuota() throws Exception { + assertEquals(GLOBAL_NOTIFICATION_QUOTA, openflowProviderConfig.getGlobalNotificationQuota()); + } + + @Test + public void isIsStatisticsPollingOn() throws Exception { + assertEquals(IS_STATISTICS_POLLING_ON, openflowProviderConfig.isIsStatisticsPollingOn()); + } + + @Test + public void isIsStatisticsRpcEnabled() throws Exception { + assertEquals(IS_STATISTICS_RPC_ENABLED, openflowProviderConfig.isIsStatisticsRpcEnabled()); + } + + @Test + public void getBarrierIntervalTimeoutLimit() throws Exception { + assertEquals(BARRIER_INTERVAL_TIMEOUT_LIMIT, openflowProviderConfig.getBarrierIntervalTimeoutLimit().getValue()); + } + + @Test + public void getBarrierCountLimit() throws Exception { + assertEquals(BARRIER_COUNT_LIMIT, openflowProviderConfig.getBarrierCountLimit().getValue()); + } + + @Test + public void getEchoReplyTimeout() throws Exception { + assertEquals(ECHO_REPLY_TIMEOUT, openflowProviderConfig.getEchoReplyTimeout().getValue()); + } + + @Test + public void getThreadPoolMinThreads() throws Exception { + assertEquals(THREAD_POOL_MIN_THREADS, openflowProviderConfig.getThreadPoolMinThreads()); + } + + @Test + public void getThreadPoolMaxThreads() throws Exception { + assertEquals(THREAD_POOL_MAX_THREADS, openflowProviderConfig.getThreadPoolMaxThreads().getValue()); + } + + @Test + public void getThreadPoolTimeout() throws Exception { + assertEquals(THREAD_POOL_TIMEOUT, openflowProviderConfig.getThreadPoolTimeout()); + } + + @Test + public void isEnableFlowRemovedNotification() throws Exception { + assertEquals(ENABLE_FLOW_REMOVED_NOTIFICATION, openflowProviderConfig.isEnableFlowRemovedNotification()); + } + + @Test + public void isSkipTableFeatures() throws Exception { + assertEquals(SKIP_TABLE_FEATURES, openflowProviderConfig.isSkipTableFeatures()); + } + + @Test + public void getBasicTimerDelay() throws Exception { + assertEquals(BASIC_TIMER_DELAY, openflowProviderConfig.getBasicTimerDelay().getValue()); + } + + @Test + public void getMaximumTimerDelay() throws Exception { + assertEquals(MAXIMUM_TIMER_DELAY, openflowProviderConfig.getMaximumTimerDelay().getValue()); + } + + @Test + public void isUseSingleLayerSerialization() throws Exception { + assertEquals(USE_SINGLE_LAYER_SERIALIZATION, openflowProviderConfig.isUseSingleLayerSerialization()); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java index d630006b41..12bff2a6cd 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java @@ -145,7 +145,7 @@ public class TransactionChainManagerTest { */ @Test public void testSubmitTransactionFailed() throws Exception { - Mockito.when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))); + Mockito.when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))); final Node data = new NodeBuilder().setId(nodeId).build(); txChainManager.initialSubmitWriteTransaction(); txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false); @@ -156,6 +156,22 @@ public class TransactionChainManagerTest { Mockito.verify(writeTx).submit(); } + @Test + public void testSubmitTransactionFailed2() throws Exception { + final Node data = new NodeBuilder().setId(nodeId).build(); + txChainManager.initialSubmitWriteTransaction(); + txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false); + txChainManager.submitWriteTransaction(); + + Mockito.when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))); + txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false); + txChainManager.submitWriteTransaction(); + + Mockito.verify(txChain, Mockito.times(2)).newWriteOnlyTransaction(); + Mockito.verify(writeTx, Mockito.times(2)).put(LogicalDatastoreType.CONFIGURATION, path, data, false); + Mockito.verify(writeTx, Mockito.times(2)).submit(); + } + /** * test of {@link TransactionChainManager#enableSubmit()}: no submit - counter is not active * diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/DeviceInitializerProviderTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/DeviceInitializerProviderTest.java new file mode 100644 index 0000000000..fe94f681db --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/DeviceInitializerProviderTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.device.initialization; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowplugin.api.OFConstants; + +@RunWith(MockitoJUnitRunner.class) +public class DeviceInitializerProviderTest { + @Mock + private AbstractDeviceInitializer abstractDeviceInitializer; + private DeviceInitializerProvider provider; + + @Before + public void setUp() throws Exception { + provider = new DeviceInitializerProvider(); + } + + @Test + public void register() throws Exception { + provider.register(OFConstants.OFP_VERSION_1_3, abstractDeviceInitializer); + final Optional lookup = provider.lookup(OFConstants.OFP_VERSION_1_3); + assertTrue(lookup.isPresent()); + assertEquals(abstractDeviceInitializer, lookup.get()); + } + + @Test + public void lookup() throws Exception { + assertFalse(provider.lookup(OFConstants.OFP_VERSION_1_0).isPresent()); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializerTest.java new file mode 100644 index 0000000000..7041f3455e --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializerTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.device.initialization; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.concurrent.Future; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; +import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; +import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; +import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; +import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; +import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; + +@RunWith(MockitoJUnitRunner.class) +public class OF10DeviceInitializerTest { + @Mock + private DeviceContext deviceContext; + @Mock + private MultipartWriterProvider multipartWriterProvider; + @Mock + private ConvertorExecutor convertorExecutor; + @Mock + private ConnectionContext connectionContext; + @Mock + private FeaturesReply featuresReply; + @Mock + private CapabilitiesV10 capabilitiesV10; + @Mock + private DeviceInfo deviceInfo; + @Mock + private DeviceState deviceState; + @Mock + private MessageSpy messageSpy; + @Mock + private TranslatorLibrary translatorLibrary; + @Mock + private MessageTranslator messageTranslator; + @Mock + private RequestContext requestContext; + @Mock + private OutboundQueueProvider outboundQueueProvider; + private AbstractDeviceInitializer deviceInitializer; + + @Before + public void setUp() throws Exception { + final KeyedInstanceIdentifier nodeInstanceIdentifier = DeviceStateUtil + .createNodeInstanceIdentifier(new NodeId("openflow:1")); + + deviceInitializer = new OF10DeviceInitializer(); + when(featuresReply.getCapabilitiesV10()).thenReturn(capabilitiesV10); + when(featuresReply.getPhyPort()).thenReturn(Collections + .singletonList(new PhyPortBuilder() + .setPortNo(42L) + .build())); + when(connectionContext.getFeatures()).thenReturn(featuresReply); + when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider); + when(deviceContext.getDeviceState()).thenReturn(deviceState); + when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier); + when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); + when(deviceContext.getMessageSpy()).thenReturn(messageSpy); + when(translatorLibrary.lookupTranslator(any())).thenReturn(messageTranslator); + when(deviceContext.oook()).thenReturn(translatorLibrary); + when(requestContext.getXid()).thenReturn(new Xid(42L)); + when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture()); + when(deviceContext.createRequestContext()).thenReturn(requestContext); + when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); + } + + @Test + public void initializeSingleLayer() throws Exception { + when(deviceContext.canUseSingleLayerSerialization()).thenReturn(true); + + final Future initialize = deviceInitializer.initialize(deviceContext, + true, + false, + multipartWriterProvider, + convertorExecutor); + + initialize.get(); + verify(messageSpy).spyMessage(eq(MultipartType.class), any()); + verify(requestContext).getFuture(); + verify(featuresReply).getCapabilitiesV10(); + verify(featuresReply).getPhyPort(); + verify(featuresReply).getTables(); + verify(deviceContext, times(3)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } + + @Test + public void initializeMultiLayer() throws Exception { + when(deviceContext.canUseSingleLayerSerialization()).thenReturn(false); + + final Future initialize = deviceInitializer.initialize(deviceContext, + true, + false, + multipartWriterProvider, + convertorExecutor); + + initialize.get(); + verify(messageSpy).spyMessage(eq(MultipartType.class), any()); + verify(requestContext).getFuture(); + verify(featuresReply).getCapabilitiesV10(); + verify(featuresReply).getPhyPort(); + verify(featuresReply).getTables(); + verify(deviceContext, times(3)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF13DeviceInitializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF13DeviceInitializerTest.java new file mode 100644 index 0000000000..52e5f69799 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/initialization/OF13DeviceInitializerTest.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.device.initialization; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.Optional; +import java.util.concurrent.Future; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; +import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; +import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; +import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; +import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; +import org.opendaylight.openflowplugin.impl.datastore.multipart.AbstractMultipartWriter; +import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.multipart.reply.multipart.reply.body.MultipartReplyDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; + +@RunWith(MockitoJUnitRunner.class) +public class OF13DeviceInitializerTest { + @Mock + private DeviceContext deviceContext; + @Mock + private MultipartWriterProvider multipartWriterProvider; + @Mock + private AbstractMultipartWriter abstractMultipartWriter; + @Mock + private ConvertorExecutor convertorExecutor; + @Mock + private ConnectionContext connectionContext; + @Mock + private FeaturesReply featuresReply; + @Mock + private Capabilities capabilities; + @Mock + private DeviceInfo deviceInfo; + @Mock + private DeviceState deviceState; + @Mock + private MessageSpy messageSpy; + @Mock + private TranslatorLibrary translatorLibrary; + @Mock + private MessageTranslator messageTranslator; + @Mock + private RequestContext requestContext; + @Mock + private OutboundQueueProvider outboundQueueProvider; + private AbstractDeviceInitializer deviceInitializer; + + @Before + public void setUp() throws Exception { + final KeyedInstanceIdentifier nodeInstanceIdentifier = DeviceStateUtil + .createNodeInstanceIdentifier(new NodeId("openflow:1")); + + deviceInitializer = new OF13DeviceInitializer(); + when(multipartWriterProvider.lookup(any())).thenReturn(Optional + .of(abstractMultipartWriter)); + when(featuresReply.getCapabilities()).thenReturn(capabilities); + when(connectionContext.getFeatures()).thenReturn(featuresReply); + when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider); + when(deviceContext.getDeviceState()).thenReturn(deviceState); + when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier); + when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); + when(deviceContext.getMessageSpy()).thenReturn(messageSpy); + when(translatorLibrary.lookupTranslator(any())).thenReturn(messageTranslator); + when(deviceContext.oook()).thenReturn(translatorLibrary); + when(requestContext.getXid()).thenReturn(new Xid(42L)); + when(deviceContext.createRequestContext()).thenReturn(requestContext); + when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); + } + + @Test + public void initializeSingleLayer() throws Exception { + when(deviceContext.canUseSingleLayerSerialization()).thenReturn(true); + when(requestContext.getFuture()).thenReturn(RpcResultBuilder + .success(Collections.singletonList(new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyDescBuilder().build()) + .build())) + .buildFuture()); + + final Future initialize = deviceInitializer.initialize(deviceContext, + true, + false, + multipartWriterProvider, + convertorExecutor); + + initialize.get(); + verify(messageSpy, times(5)).spyMessage(eq(MultipartType.class), any()); + verify(requestContext, times(5)).getFuture(); + verify(featuresReply).getCapabilities(); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } + + @Test + public void initializeMultiLayer() throws Exception { + when(deviceContext.canUseSingleLayerSerialization()).thenReturn(false); + when(requestContext.getFuture()).thenReturn(RpcResultBuilder + .success(Collections.singletonList(new MultipartReplyMessageBuilder() + .setType(MultipartType.OFPMPDESC) + .setMultipartReplyBody(new MultipartReplyDescCaseBuilder() + .setMultipartReplyDesc(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow + .protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply + .desc._case.MultipartReplyDescBuilder() + .build()) + .build()) + .build())) + + .buildFuture()); + final Future initialize = deviceInitializer.initialize(deviceContext, + true, + false, + multipartWriterProvider, + convertorExecutor); + + initialize.get(); + verify(messageSpy, times(5)).spyMessage(eq(MultipartType.class), any()); + verify(requestContext, times(5)).getFuture(); + verify(featuresReply).getCapabilities(); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/AbstractDeserializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/AbstractDeserializerTest.java index 19121391aa..0555537ec7 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/AbstractDeserializerTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/AbstractDeserializerTest.java @@ -8,6 +8,7 @@ package org.opendaylight.openflowplugin.impl.protocol.deserialization; +import org.junit.After; import org.junit.Before; import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerExtensionProvider; import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; @@ -44,6 +45,12 @@ public abstract class AbstractDeserializerTest { init(); } + @After + public void tearDown() throws Exception { + DeserializerInjector.revertDeserializers(provider); + MessageDeserializerInjector.revertLegacyDeserializers(provider); + } + protected DeserializationFactory getFactory() { return factory; } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/match/ArpTargetTransportAddressEntryDeserializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/match/ArpTargetTransportAddressEntryDeserializerTest.java new file mode 100644 index 0000000000..67d1b7200c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/match/ArpTargetTransportAddressEntryDeserializerTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.match; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import java.util.Iterator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch; + +public class ArpTargetTransportAddressEntryDeserializerTest extends AbstractMatchEntryDeserializerTest { + + @Test + public void deserializeEntry() throws Exception { + final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer(); + final Ipv4Prefix arpTargetTransportAddress = new Ipv4Prefix("192.168.0.0/24"); + final Ipv4Prefix arpTargetTransportAddressNoMask = new Ipv4Prefix("192.168.0.0/32"); + + writeHeader(in, false); + Iterator addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddressNoMask); + in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next()))); + + assertEquals(arpTargetTransportAddressNoMask.getValue(), + ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpTargetTransportAddress().getValue()); + assertEquals(0, in.readableBytes()); + + writeHeader(in, true); + addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddress); + in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next()))); + in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts)); + + final Ipv4Prefix desAddress = + ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpTargetTransportAddress(); + assertEquals(arpTargetTransportAddress.getValue(), desAddress.getValue()); + assertEquals(0, in.readableBytes()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_TPA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/PacketInMessageDeserializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/PacketInMessageDeserializerTest.java new file mode 100644 index 0000000000..1e2275c1c2 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/messages/PacketInMessageDeserializerTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.messages; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest; +import org.opendaylight.openflowplugin.openflow.md.util.PacketInUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage; + +public class PacketInMessageDeserializerTest extends AbstractDeserializerTest { + private static final byte PADDING_IN_PACKET_IN_HEADER = 2; + private static final short REASON = 0; // no match + private static final short TABLE_ID = 13; + private static final long FLOW_COOKIE = 12; + private static final int XID = 42; + private static final int TYPE = 10; + private static final int OXM_MATCH_TYPE_CODE = 1; + private static final int MPLS_LABEL = 135; + private static final byte[] PAYLOAD = new byte[] { 1, 2, 3, 4, 5 }; + + private ByteBuf buffer; + + @Override + protected void init() { + buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + } + + @Test + public void deserialize() throws Exception { + buffer.writeByte(TYPE); + buffer.writeShort(EncodeConstants.EMPTY_LENGTH); + buffer.writeInt(XID); + buffer.writeInt(EncodeConstants.EMPTY_VALUE); // Buffer id - irrelevant + buffer.writeShort(EncodeConstants.EMPTY_LENGTH); // Total len - irrelevant + buffer.writeByte(REASON); + buffer.writeByte(TABLE_ID); + buffer.writeLong(FLOW_COOKIE); + + // Match header + int matchStartIndex = buffer.writerIndex(); + buffer.writeShort(OXM_MATCH_TYPE_CODE); + int matchLengthIndex = buffer.writerIndex(); + buffer.writeShort(EncodeConstants.EMPTY_LENGTH); + + // MplsLabel match + buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS); + buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1); + buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES); + buffer.writeInt(MPLS_LABEL); + + // Match footer + int matchLength = buffer.writerIndex() - matchStartIndex; + buffer.setShort(matchLengthIndex, matchLength); + int paddingRemainder = matchLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + buffer.writeZero(EncodeConstants.PADDING - paddingRemainder); + } + + buffer.writeZero(PADDING_IN_PACKET_IN_HEADER); + buffer.writeBytes(PAYLOAD); + + final PacketInMessage message = (PacketInMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID); + + assertEquals(XID, message.getXid().intValue()); + assertEquals(PacketInUtil.getMdSalPacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common + .types.rev130731.PacketInReason + .forValue(REASON)), message.getPacketInReason()); + assertEquals(TABLE_ID, message.getTableId().getValue().shortValue()); + assertEquals(FLOW_COOKIE, message.getFlowCookie().getValue().longValue()); + assertEquals(MPLS_LABEL, message.getMatch().getProtocolMatchFields().getMplsLabel().intValue()); + assertArrayEquals(PAYLOAD, message.getPayload()); + assertEquals(buffer.readableBytes(), 0); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestDescSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestDescSerializerTest.java new file mode 100644 index 0000000000..ccd447f4b9 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestDescSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.multipart.request.multipart.request.body.MultipartRequestDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.multipart.request.multipart.request.body.MultipartRequestDescBuilder; + +public class MultipartRequestDescSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestDesc BODY = new MultipartRequestDescBuilder() + .build(); + + private MultipartRequestDescSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestDesc.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowAggregateStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowAggregateStatsSerializerTest.java new file mode 100644 index 0000000000..268ec24b3f --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowAggregateStatsSerializerTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import java.math.BigInteger; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder; + +public class MultipartRequestFlowAggregateStatsSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; + private static final short TABLE_ID = 42; + private static final BigInteger OUT_PORT = BigInteger.ONE; + private static final long OUT_GROUP = 10; + private static final FlowCookie COOKIE = new FlowCookie(BigInteger.valueOf(8)); + private static final FlowCookie COOKIE_MASK = new FlowCookie(BigInteger.TEN); + private static final Short IP_PROTOCOL_MATCH = (short) 17; + private static final Match MATCH = new MatchBuilder() + .setIpMatch(new IpMatchBuilder() + .setIpProtocol(IP_PROTOCOL_MATCH) + .build()) + .build(); + private static final MultipartRequestFlowAggregateStats BODY = new MultipartRequestFlowAggregateStatsBuilder() + .setTableId(TABLE_ID) + .setOutPort(OUT_PORT) + .setOutGroup(OUT_GROUP) + .setCookie(COOKIE) + .setCookieMask(COOKIE_MASK) + .setMatch(MATCH) + .build(); + + private MultipartRequestFlowAggregateStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestFlowAggregateStats.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedByte(), TABLE_ID); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01); + assertEquals(out.readUnsignedInt(), OUT_PORT.longValue()); + assertEquals(out.readUnsignedInt(), OUT_GROUP); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02); + assertEquals(out.readLong(), COOKIE.getValue().longValue()); + assertEquals(out.readLong(), COOKIE_MASK.getValue().longValue()); + + int matchLength = 9; + assertEquals(out.readShort(), 1); // OXM match type + assertEquals(out.readUnsignedShort(), matchLength); // OXM match length + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_PROTO << 1); + assertEquals(out.readUnsignedByte(), EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + assertEquals(out.readUnsignedByte(), IP_PROTOCOL_MATCH.shortValue()); + + int paddingRemainder = matchLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + out.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } + + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowStatsSerializerTest.java new file mode 100644 index 0000000000..7118d09eb6 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowStatsSerializerTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import java.math.BigInteger; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder; + +public class MultipartRequestFlowStatsSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; + private static final short TABLE_ID = 42; + private static final BigInteger OUT_PORT = BigInteger.ONE; + private static final long OUT_GROUP = 10; + private static final FlowCookie COOKIE = new FlowCookie(BigInteger.valueOf(8)); + private static final FlowCookie COOKIE_MASK = new FlowCookie(BigInteger.TEN); + private static final Short IP_PROTOCOL_MATCH = (short) 17; + private static final Match MATCH = new MatchBuilder() + .setIpMatch(new IpMatchBuilder() + .setIpProtocol(IP_PROTOCOL_MATCH) + .build()) + .build(); + private static final MultipartRequestFlowStats BODY = new MultipartRequestFlowStatsBuilder() + .setTableId(TABLE_ID) + .setOutPort(OUT_PORT) + .setOutGroup(OUT_GROUP) + .setCookie(COOKIE) + .setCookieMask(COOKIE_MASK) + .setMatch(MATCH) + .build(); + + private MultipartRequestFlowStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestFlowStats.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedByte(), TABLE_ID); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01); + assertEquals(out.readUnsignedInt(), OUT_PORT.longValue()); + assertEquals(out.readUnsignedInt(), OUT_GROUP); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02); + assertEquals(out.readLong(), COOKIE.getValue().longValue()); + assertEquals(out.readLong(), COOKIE_MASK.getValue().longValue()); + + int matchLength = 9; + assertEquals(out.readShort(), 1); // OXM match type + assertEquals(out.readUnsignedShort(), matchLength); // OXM match length + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_PROTO << 1); + assertEquals(out.readUnsignedByte(), EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + assertEquals(out.readUnsignedByte(), IP_PROTOCOL_MATCH.shortValue()); + + int paddingRemainder = matchLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + out.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } + + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowTableStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowTableStatsSerializerTest.java new file mode 100644 index 0000000000..03ced587e9 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestFlowTableStatsSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.request.multipart.request.body.MultipartRequestFlowTableStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.request.multipart.request.body.MultipartRequestFlowTableStatsBuilder; + +public class MultipartRequestFlowTableStatsSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestFlowTableStats BODY = new MultipartRequestFlowTableStatsBuilder() + .build(); + + private MultipartRequestFlowTableStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestFlowTableStats.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupDescSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupDescSerializerTest.java new file mode 100644 index 0000000000..2c817cbc02 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupDescSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupDescBuilder; + +public class MultipartRequestGroupDescSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestGroupDesc BODY = new MultipartRequestGroupDescBuilder() + .build(); + + private MultipartRequestGroupDescSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestGroupDesc.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupFeaturesSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupFeaturesSerializerTest.java new file mode 100644 index 0000000000..7098b4aa29 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupFeaturesSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesBuilder; + +public class MultipartRequestGroupFeaturesSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestGroupFeatures BODY = new MultipartRequestGroupFeaturesBuilder() + .build(); + + private MultipartRequestGroupFeaturesSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestGroupFeatures.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupStatsSerializerTest.java new file mode 100644 index 0000000000..24b05db280 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestGroupStatsSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; + +public class MultipartRequestGroupStatsSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4; + private static final long GROUP_ID = 42; + private static final MultipartRequestGroupStats BODY = new MultipartRequestGroupStatsBuilder() + .setGroupId(new GroupId(GROUP_ID)) + .build(); + + private MultipartRequestGroupStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestGroupStats.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedInt(), GROUP_ID); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMessageSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMessageSerializerTest.java index 2a60b26f74..43ee847696 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMessageSerializerTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMessageSerializerTest.java @@ -17,27 +17,33 @@ import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowjava.util.ByteBufUtils; import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.multipart.request.multipart.request.body.MultipartRequestDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequestBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStatsBuilder; public class MultipartRequestMessageSerializerTest extends AbstractSerializerTest { // Multipart request message constants private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; - private static final short LENGTH = 16; + private static final short LENGTH = 24; private static final Long XID = 42L; private static final short VERSION = EncodeConstants.OF13_VERSION_ID; private static final boolean IS_REQUEST_MORE = false; - private static final MultipartType MULTIPART_TYPE = MultipartType.OFPMPDESC; + private static final MultipartType MULTIPART_TYPE = MultipartType.OFPMPQUEUE; private static final int MESSAGE_TYPE = 18; + private static final long QUEUE_ID = 44; + private static final long PORT = 12; // Message private static final MultipartRequest MESSAGE = new MultipartRequestBuilder() .setRequestMore(IS_REQUEST_MORE) .setXid(XID) .setVersion(VERSION) - .setMultipartRequestBody(new MultipartRequestDescBuilder() + .setMultipartRequestBody(new MultipartRequestQueueStatsBuilder() + .setNodeConnectorId(new NodeConnectorId("openflow:1:" + PORT)) + .setQueueId(new QueueId(QUEUE_ID)) .build()) .build(); @@ -59,12 +65,14 @@ public class MultipartRequestMessageSerializerTest extends AbstractSerializerTes assertEquals(out.readByte(), MESSAGE_TYPE); assertEquals(out.readUnsignedShort(), LENGTH); assertEquals(out.readInt(), XID.intValue()); - - // Body assertEquals(out.readShort(), MULTIPART_TYPE.getIntValue()); assertEquals(out.readUnsignedShort(), ByteBufUtils.fillBitMask(0, IS_REQUEST_MORE)); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + // Body + assertEquals(out.readUnsignedInt(), PORT); + assertEquals(out.readUnsignedInt(), QUEUE_ID); + assertEquals(out.readableBytes(), 0); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterConfigSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterConfigSerializerTest.java new file mode 100644 index 0000000000..0df02aee8c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterConfigSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; + +public class MultipartRequestMeterConfigSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; + private static final long METER_ID = 42; + private static final MultipartRequestMeterConfig BODY = new MultipartRequestMeterConfigBuilder() + .setMeterId(new MeterId(METER_ID)) + .build(); + + private MultipartRequestMeterConfigSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestMeterConfig.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedInt(), METER_ID); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterFeaturesSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterFeaturesSerializerTest.java new file mode 100644 index 0000000000..b1054451cf --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterFeaturesSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesBuilder; + +public class MultipartRequestMeterFeaturesSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestMeterFeatures BODY = new MultipartRequestMeterFeaturesBuilder() + .build(); + + private MultipartRequestMeterFeaturesSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestMeterFeatures.class)) ; + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterStatsSerializerTest.java new file mode 100644 index 0000000000..a82e516e5b --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestMeterStatsSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; + +public class MultipartRequestMeterStatsSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; + private static final long METER_ID = 42; + private static final MultipartRequestMeterStats BODY = new MultipartRequestMeterStatsBuilder() + .setMeterId(new MeterId(METER_ID)) + .build(); + + private MultipartRequestMeterStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestMeterStats.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedInt(), METER_ID); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_BODY); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortDescSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortDescSerializerTest.java new file mode 100644 index 0000000000..2fc8dea14e --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortDescSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.request.multipart.request.body.MultipartRequestPortDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.request.multipart.request.body.MultipartRequestPortDescBuilder; + +public class MultipartRequestPortDescSerializerTest extends AbstractSerializerTest { + private static final MultipartRequestPortDesc BODY = new MultipartRequestPortDescBuilder() + .build(); + + private MultipartRequestPortDescSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestPortDesc.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortStatsSerializerTest.java new file mode 100644 index 0000000000..ff84abdf86 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestPortStatsSerializerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStatsBuilder; + +public class MultipartRequestPortStatsSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4; + private static final long PORT = 42; + private static final MultipartRequestPortStats BODY = new MultipartRequestPortStatsBuilder() + .setNodeConnectorId(new NodeConnectorId("openflow:1:" + PORT)) + .build(); + + private MultipartRequestPortStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestPortStats.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedInt(), PORT); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestQueueStatsSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestQueueStatsSerializerTest.java new file mode 100644 index 0000000000..7916cf5a08 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestQueueStatsSerializerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStatsBuilder; + +public class MultipartRequestQueueStatsSerializerTest extends AbstractSerializerTest { + private static final long PORT = 42; + private static final long QUEUE_ID = 43; + private static final MultipartRequestQueueStats BODY = new MultipartRequestQueueStatsBuilder() + .setNodeConnectorId(new NodeConnectorId("openflow:1:" + PORT)) + .setQueueId(new QueueId(QUEUE_ID)) + .build(); + + private MultipartRequestQueueStatsSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestQueueStats.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + assertEquals(out.readUnsignedInt(), PORT); + assertEquals(out.readUnsignedInt(), QUEUE_ID); + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestTableFeaturesSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestTableFeaturesSerializerTest.java new file mode 100644 index 0000000000..d89f30c72e --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/MultipartRequestTableFeaturesSerializerTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import java.math.BigInteger; +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.request.multipart.request.body.MultipartRequestTableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.request.multipart.request.body.MultipartRequestTableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.TablesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey; + +public class MultipartRequestTableFeaturesSerializerTest extends AbstractSerializerTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5; + private static final byte MAX_TABLE_NAME_LENGTH = 32; + private static final short TABLE_ID = 42; + private static final String NAME = "table_prop"; + private static final BigInteger METADATA_MATCH = BigInteger.ONE; + private static final BigInteger METADATA_WRITE = BigInteger.TEN; + private static final long MAX_ENTRIES = 12; + private static final boolean IS_DEPRECATED_MASK = true; + private static final short NEXT_TABLE_ID = 43; + + private static final TableFeaturesPropType NEXT_TABLE_TYPE = TableFeaturesPropType.OFPTFPTNEXTTABLES; + private static final NextTable NEXT_TABLE = new NextTableBuilder() + .setTables(new TablesBuilder() + .setTableIds(Collections.singletonList(NEXT_TABLE_ID)) + .build()) + .build(); + private static final MultipartRequestTableFeatures BODY = new MultipartRequestTableFeaturesBuilder() + .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder() + .setTableId(TABLE_ID) + .setName(NAME) + .setMetadataMatch(METADATA_MATCH) + .setMetadataWrite(METADATA_WRITE) + .setConfig(new TableConfig(IS_DEPRECATED_MASK)) + .setMaxEntries(MAX_ENTRIES) + .setTableProperties(new TablePropertiesBuilder() + .setTableFeatureProperties(Collections.singletonList(new TableFeaturePropertiesBuilder() + .setOrder(0) + .setKey(new TableFeaturePropertiesKey(0)) + .setTableFeaturePropType(NEXT_TABLE) + .build())) + .build()) + .build())) + .build(); + + private MultipartRequestTableFeaturesSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + MultipartRequestTableFeatures.class)); + } + + @Test + public void testSerialize() throws Exception { + final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(BODY, out); + + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // skip length + assertEquals(TABLE_ID, out.readUnsignedByte()); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY); + assertEquals(NAME, ByteBufUtils.decodeNullTerminatedString(out, MAX_TABLE_NAME_LENGTH)); + final byte[] match = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + out.readBytes(match); + assertEquals(METADATA_MATCH, new BigInteger(1, match)); + final byte[] write = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + out.readBytes(write); + assertEquals(METADATA_WRITE, new BigInteger(1, write)); + assertEquals(IS_DEPRECATED_MASK, (out.readUnsignedInt() & 3) != 0); + assertEquals(MAX_ENTRIES, out.readUnsignedInt()); + assertEquals(NEXT_TABLE_TYPE.getIntValue(), out.readUnsignedShort()); + final int propLength = out.readUnsignedShort(); + final int paddingRemainder = propLength % EncodeConstants.PADDING; + assertEquals(NEXT_TABLE_ID, out.readUnsignedByte()); + + if (paddingRemainder != 0) { + out.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } + + assertEquals(out.readableBytes(), 0); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/AbstractTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/AbstractTablePropertySerializerTest.java new file mode 100644 index 0000000000..8f5f10cf62 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/AbstractTablePropertySerializerTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import java.util.function.Consumer; +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.openflowplugin.impl.protocol.serialization.AbstractSerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; + +public abstract class AbstractTablePropertySerializerTest extends AbstractSerializerTest { + private OFSerializer serializer; + + @Override + protected void init() { + serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, getClazz())); + } + + protected void assertProperty(final TableFeaturePropType property, final Consumer assertBody) { + // Header and body serialization + final ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(property, buffer); + assertEquals(buffer.readUnsignedShort(), getType()); + final int length = buffer.readUnsignedShort(); + assertBody.accept(buffer); + + int paddingRemainder = length % EncodeConstants.PADDING; + int padding = 0; + + if (paddingRemainder != 0) { + padding = EncodeConstants.PADDING - paddingRemainder; + } + + buffer.skipBytes(padding); + assertEquals(buffer.readableBytes(), 0); + } + + protected OFSerializer getSerializer() { + return serializer; + } + + protected abstract Class getClazz(); + protected abstract int getType(); +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..0452c2384c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsMissTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMissBuilder; + +public class ApplyActionsMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final ApplyActionsMiss property = new ApplyActionsMissBuilder() + .setApplyActionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.apply.actions.miss + .ApplyActionsMissBuilder() + .setAction(Collections.singletonList(new ActionBuilder() + .setOrder(0) + .setAction(new SetNwSrcActionCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return ApplyActionsMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializerTest.java new file mode 100644 index 0000000000..afe5dcf15e --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplyActionsTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsBuilder; + +public class ApplyActionsTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final ApplyActions property = new ApplyActionsBuilder() + .setApplyActions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.apply.actions + .ApplyActionsBuilder() + .setAction(Collections.singletonList(new ActionBuilder() + .setOrder(0) + .setAction(new SetNwSrcActionCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return ApplyActions.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTAPPLYACTIONS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..f05939303c --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldMissTablePropertySerializerTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMissBuilder; + +public class ApplySetfieldMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final ApplySetfieldMiss property = new ApplySetfieldMissBuilder() + .setApplySetfieldMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.apply.setfield.miss + .ApplySetfieldMissBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return ApplySetfieldMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldTablePropertySerializerTest.java new file mode 100644 index 0000000000..dec98fb255 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/ApplySetfieldTablePropertySerializerTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfield; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldBuilder; + +public class ApplySetfieldTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final ApplySetfield property = new ApplySetfieldBuilder() + .setApplySetfield(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.apply.setfield + .ApplySetfieldBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return ApplySetfield.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTAPPLYSETFIELD.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..50a5f102c9 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsMissTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMissBuilder; + +public class InstructionsMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final InstructionsMiss property = new InstructionsMissBuilder() + .setInstructionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.instructions.miss + .InstructionsMissBuilder() + .setInstruction(Collections.singletonList(new InstructionBuilder() + .setOrder(0) + .setInstruction(new ApplyActionsCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), InstructionConstants.APPLY_ACTIONS_TYPE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return InstructionsMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializerTest.java new file mode 100644 index 0000000000..e409b2a216 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/InstructionsTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsBuilder; + +public class InstructionsTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final Instructions property = new InstructionsBuilder() + .setInstructions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.instructions + .InstructionsBuilder() + .setInstruction(Collections.singletonList(new InstructionBuilder() + .setOrder(0) + .setInstruction(new ApplyActionsCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), InstructionConstants.APPLY_ACTIONS_TYPE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return Instructions.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTINSTRUCTIONS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/MatchTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/MatchTablePropertySerializerTest.java new file mode 100644 index 0000000000..d489353dcb --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/MatchTablePropertySerializerTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfieldBuilder; + +public class MatchTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final Match property = new MatchBuilder() + .setMatchSetfield(new MatchSetfieldBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return Match.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTMATCH.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..afd5b86bd3 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMissBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMissBuilder; + +public class NextTableMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final short tableId = 42; + final NextTableMiss property = new NextTableMissBuilder() + .setTablesMiss(new TablesMissBuilder() + .setTableIds(Collections.singletonList(tableId)) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedByte(), tableId); + }); + } + + @Override + protected Class getClazz() { + return NextTableMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTNEXTTABLESMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java new file mode 100644 index 0000000000..098569c482 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.TablesBuilder; + +public class NextTableTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final short tableId = 42; + final NextTable property = new NextTableBuilder() + .setTables(new TablesBuilder() + .setTableIds(Collections.singletonList(tableId)) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedByte(), tableId); + }); + } + + @Override + protected Class getClazz() { + return NextTable.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTNEXTTABLES.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WildcardsTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WildcardsTablePropertySerializerTest.java new file mode 100644 index 0000000000..968bcd9079 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WildcardsTablePropertySerializerTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WildcardsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfieldBuilder; + +public class WildcardsTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final Wildcards property = new WildcardsBuilder() + .setWildcardSetfield(new WildcardSetfieldBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return Wildcards.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTWILDCARDS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..d10a3482cd --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsMissTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMissBuilder; + +public class WriteActionsMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final WriteActionsMiss property = new WriteActionsMissBuilder() + .setWriteActionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.write.actions.miss + .WriteActionsMissBuilder() + .setAction(Collections.singletonList(new ActionBuilder() + .setOrder(0) + .setAction(new SetNwSrcActionCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return WriteActionsMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializerTest.java new file mode 100644 index 0000000000..a080932328 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteActionsTablePropertySerializerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsBuilder; + +public class WriteActionsTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final WriteActions property = new WriteActionsBuilder() + .setWriteActions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.write.actions + .WriteActionsBuilder() + .setAction(Collections.singletonList(new ActionBuilder() + .setOrder(0) + .setAction(new SetNwSrcActionCaseBuilder() + .build()) + .build())) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action + }); + } + + @Override + protected Class getClazz() { + return WriteActions.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTWRITEACTIONS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldMissTablePropertySerializerTest.java new file mode 100644 index 0000000000..35608bee51 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldMissTablePropertySerializerTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMissBuilder; + +public class WriteSetfieldMissTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final WriteSetfieldMiss property = new WriteSetfieldMissBuilder() + .setWriteSetfieldMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.write.setfield.miss + .WriteSetfieldMissBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return WriteSetfieldMiss.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldTablePropertySerializerTest.java new file mode 100644 index 0000000000..cf578cbcd6 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/WriteSetfieldTablePropertySerializerTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldBuilder; + +public class WriteSetfieldTablePropertySerializerTest extends AbstractTablePropertySerializerTest { + + @Test + public void testSerialize() throws Exception { + final WriteSetfield property = new WriteSetfieldBuilder() + .setWriteSetfield(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature + .prop.type.table.feature.prop.type.write.setfield + .WriteSetfieldBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length + }); + } + + @Override + protected Class getClazz() { + return WriteSetfield.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTWRITESETFIELD.getIntValue(); + } + +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/matchfield/MatchFieldSerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/matchfield/MatchFieldSerializerTest.java new file mode 100644 index 0000000000..3508236734 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/matchfield/MatchFieldSerializerTest.java @@ -0,0 +1,418 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.AbstractTablePropertySerializerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfieldBuilder; + +public class MatchFieldSerializerTest extends AbstractTablePropertySerializerTest { + @Test + public void testSerialize() throws Exception { + final Match property = new MatchBuilder() + .setMatchSetfield(new MatchSetfieldBuilder() + .setSetFieldMatch(ImmutableList + .builder() + .add(new SetFieldMatchBuilder() + .setMatchType(ArpOp.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(ArpSha.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(ArpSpa.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(ArpTha.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(ArpTpa.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(EthDst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(EthSrc.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(EthType.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Icmpv4Code.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Icmpv4Type.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Icmpv6Code.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Icmpv6Type.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(InPhyPort.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(InPort.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(IpDscp.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(IpEcn.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(IpProto.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv4Dst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv4Src.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6Dst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6Exthdr.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6Flabel.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6NdSll.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6NdTarget.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6NdTll.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Ipv6Src.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(Metadata.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(MplsBos.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(MplsLabel.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(MplsTc.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(PbbIsid.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(SctpDst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(SctpSrc.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(TcpDst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(TcpFlags.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(TcpSrc.class) + .setHasMask(true) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(TunnelId.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(UdpDst.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(UdpSrc.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(VlanPcp.class) + .setHasMask(false) + .build()) + .add(new SetFieldMatchBuilder() + .setMatchType(VlanVid.class) + .setHasMask(false) + .build()) + .build()) + .build()) + .build(); + + assertProperty(property, out -> { + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_OP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_SHA << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_SPA << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_THA << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ARP_TPA << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ETH_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ETH_SRC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ETH_TYPE << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ICMPV4_CODE << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ICMPV4_TYPE << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ICMPV6_CODE << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.ICMPV6_TYPE << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IN_PHY_PORT << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IN_PORT << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_DSCP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_ECN << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IP_PROTO << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_EXTHDR << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_FLABEL << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_ND_SLL << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_ND_TARGET << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_ND_TLL << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV6_SRC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.METADATA << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.MPLS_BOS << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.MPLS_LABEL << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.MPLS_TC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.PBB_ISID << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.SCTP_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.SCTP_SRC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.TCP_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.EXPERIMENTER_CLASS); + assertEquals(out.readUnsignedByte(), EncodeConstants.ONFOXM_ET_TCP_FLAGS << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte() >>> 1, OxmMatchConstants.TCP_SRC); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.TUNNEL_ID << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.UDP_DST << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.UDP_SRC << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.VLAN_PCP << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + + assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS); + assertEquals(out.readUnsignedByte(), OxmMatchConstants.VLAN_VID << 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + }); + } + + @Override + protected Class getClazz() { + return Match.class; + } + + @Override + protected int getType() { + return TableFeaturesPropType.OFPTFPTMATCH.getIntValue(); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImplTest.java index df6b4863b5..55d07d9d84 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImplTest.java @@ -21,6 +21,7 @@ import com.google.common.util.concurrent.Futures; import java.math.BigInteger; import java.util.Collections; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Assert; @@ -232,6 +233,13 @@ public class DeviceFlowRegistryImplTest { assertTrue(index1 < index2); } + @Test + public void testForEach() throws Exception { + final AtomicInteger counter = new AtomicInteger(0); + deviceFlowRegistry.forEach(key -> counter.incrementAndGet()); + Assert.assertEquals(1, counter.get()); + } + private static Integer parseIndex(String alienFlowIdValue) { final Matcher mach = INDEX_PATTERN.matcher(alienFlowIdValue); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/group/DeviceGroupRegistryImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/group/DeviceGroupRegistryImplTest.java index 6b62e9f169..818c3c8a30 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/group/DeviceGroupRegistryImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/group/DeviceGroupRegistryImplTest.java @@ -8,6 +8,7 @@ package org.opendaylight.openflowplugin.impl.registry.group; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -52,7 +53,6 @@ public class DeviceGroupRegistryImplTest { Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size()); } - @Test public void testClose() throws Exception { deviceGroupRegistry.addMark(groupId); @@ -63,6 +63,13 @@ public class DeviceGroupRegistryImplTest { Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size()); deviceGroupRegistry.processMarks(); Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size()); + } + @Test + public void testForEach() throws Exception { + final AtomicInteger counter = new AtomicInteger(0); + deviceGroupRegistry.store(groupId2); + deviceGroupRegistry.forEach(group -> counter.incrementAndGet()); + Assert.assertEquals(2, counter.get()); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/meter/DeviceMeterRegistryImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/meter/DeviceMeterRegistryImplTest.java index dbc3e3aedc..0aa1df8cfe 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/meter/DeviceMeterRegistryImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/meter/DeviceMeterRegistryImplTest.java @@ -8,6 +8,7 @@ package org.opendaylight.openflowplugin.impl.registry.meter; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -52,7 +53,6 @@ public class DeviceMeterRegistryImplTest { Assert.assertEquals(1, deviceMeterRegistry.getAllMeterIds().size()); } - @Test public void testClose() throws Exception { deviceMeterRegistry.addMark(meterId); @@ -65,4 +65,12 @@ public class DeviceMeterRegistryImplTest { Assert.assertEquals(1, deviceMeterRegistry.getAllMeterIds().size()); } + + @Test + public void testForEach() throws Exception { + final AtomicInteger counter = new AtomicInteger(0); + deviceMeterRegistry.store(meterId2); + deviceMeterRegistry.forEach(meter -> counter.incrementAndGet()); + Assert.assertEquals(2, counter.get()); + } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java index 3f68647244..06e04cf819 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java @@ -7,14 +7,13 @@ */ package org.opendaylight.openflowplugin.impl.rpc; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.verify; import java.util.concurrent.ConcurrentMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mock; @@ -37,7 +36,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder; @@ -77,10 +75,7 @@ public class RpcManagerImplTest { private ConvertorExecutor convertorExecutor; @Mock private NotificationPublishService notificationPublishService; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - + @Mock private KeyedInstanceIdentifier nodePath; private NodeId nodeId = new NodeId("openflow-junit:1"); @@ -90,32 +85,34 @@ public class RpcManagerImplTest { final NodeKey nodeKey = new NodeKey(nodeId); rpcManager = new RpcManagerImpl(new OpenflowProviderConfigBuilder() .setRpcRequestsQuota(new NonZeroUint16Type(QUOTA_VALUE)) - .build(), rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService); + .setIsStatisticsRpcEnabled(false) + .build(), + rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService); - GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder() + FeaturesReply features = new GetFeaturesOutputBuilder() .setVersion(OFConstants.OFP_VERSION_1_3) .build(); - FeaturesReply features = featuresOutput; - - Mockito.when(connectionContext.getFeatures()).thenReturn(features); - Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); - Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); + Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId()); Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath); Mockito.when(connectionContext.getFeatures()).thenReturn(features); + Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); - Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath); + Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy); - Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId()); Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation( Matchers.any(), Matchers.any(RpcService.class))) .thenReturn(routedRpcRegistration); Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts); } + @Test + public void createContext() throws Exception { + final RpcContext context = rpcManager.createContext(deviceContext); + assertEquals(deviceInfo, context.getDeviceInfo()); + } + @Test public void close() { rpcManager.addRecordToContexts(deviceInfo,removedContexts); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtilTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtilTest.java new file mode 100644 index 0000000000..96bf817819 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestContextUtilTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.services.util; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; + +@RunWith(MockitoJUnitRunner.class) +public class RequestContextUtilTest { + @Mock + private RequestContext requestContext; + + @After + public void tearDown() throws Exception { + verifyNoMoreInteractions(requestContext); + } + + @Test + public void closeRequestContextWithRpcError() throws Exception { + final String errorMessage = "Test error"; + RequestContextUtil.closeRequestContextWithRpcError( + requestContext, + errorMessage); + + verify(requestContext).setResult(any()); + verify(requestContext).getFuture(); + verify(requestContext).close(); + } + + @Test + public void closeRequestContext() throws Exception { + doThrow(new IllegalStateException()).when(requestContext).close(); + RequestContextUtil.closeRequestContext(requestContext); + verify(requestContext).close(); + } + +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtilsTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtilsTest.java new file mode 100644 index 0000000000..8686724b8f --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/util/RequestInputUtilsTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.services.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; +import org.opendaylight.openflowplugin.api.OFConstants; +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; + +public class RequestInputUtilsTest { + @Test + public void createMultipartHeader() throws Exception { + final Short version = OFConstants.OFP_VERSION_1_3; + final Long xid = 42L; + final MultipartType type = MultipartType.OFPMPDESC; + + final MultipartRequestInput input = RequestInputUtils + .createMultipartHeader(type, xid, version) + .build(); + + assertEquals(version, input.getVersion()); + assertEquals(xid, input.getXid()); + assertEquals(type, input.getType()); + assertFalse(input.getFlags().isOFPMPFREQMORE()); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsServiceTest.java index f9f367bebe..eee08fe61d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsServiceTest.java @@ -49,7 +49,7 @@ public abstract class AbstractDirectStatisticsServiceTest { protected static final Long PORT_NO = 1L; protected static final BigInteger DATAPATH_ID = BigInteger.TEN; protected static final short OF_VERSION = OFConstants.OFP_VERSION_1_3; - protected static final String NODE_ID = "openflow:1"; + protected static final String NODE_ID = "openflow:10"; @Mock protected RequestContextStack requestContextStack; diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java new file mode 100644 index 0000000000..0abec39cde --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.statistics.services.direct.singlelayer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; + +public class FlowDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { + static final Short TABLE_NO = 1; + private FlowDirectStatisticsService service; + + @Override + public void setUp() throws Exception { + service = new FlowDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); + final DeviceFlowRegistry registry = mock(DeviceFlowRegistry.class); + when(registry.retrieveDescriptor(any())).thenReturn(FlowDescriptorFactory.create(TABLE_NO, new FlowId("1"))); + when(deviceContext.getDeviceFlowRegistry()).thenReturn(registry); + } + + @Override + public void testBuildRequestBody() throws Exception { + final GetFlowStatisticsInput input = mock(GetFlowStatisticsInput.class); + + when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); + when(input.getTableId()).thenReturn(TABLE_NO); + + final MultipartRequestFlowStats body = (MultipartRequestFlowStats) ((MultipartRequest) service + .buildRequest(new Xid(42L), input)) + .getMultipartRequestBody(); + + assertEquals(TABLE_NO, body.getTableId()); + } + + @Override + public void testBuildReply() throws Exception { + final FlowAndStatisticsMapList flowStat = new FlowAndStatisticsMapListBuilder() + .setDuration(new DurationBuilder() + .setSecond(new Counter32(1L)) + .setNanosecond(new Counter32(1L)) + .build()) + .setTableId(TABLE_NO) + .setByteCount(new Counter64(BigInteger.ONE)) + .setPacketCount(new Counter64(BigInteger.ONE)) + .setFlags(new FlowModFlags(true, false, false, false, false)) + .setMatch(new MatchBuilder().build()) + .build(); + + final MultipartReply reply = new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyFlowStatsBuilder() + .setFlowAndStatisticsMapList(Collections.singletonList(flowStat)) + .build()) + .build(); + + final List input = Collections.singletonList(reply); + + final GetFlowStatisticsOutput output = service.buildReply(input, true); + assertTrue(output.getFlowAndStatisticsMapList().size() > 0); + + final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0); + + assertEquals(stats.getTableId(), TABLE_NO); + } + + @Override + public void testStoreStatistics() throws Exception { + final FlowAndStatisticsMapList stat = mock(FlowAndStatisticsMapList.class); + when(stat.getTableId()).thenReturn(TABLE_NO); + when(stat.getMatch()).thenReturn(new MatchBuilder().build()); + + final List stats = Arrays.asList(stat); + final GetFlowStatisticsOutput output = mock(GetFlowStatisticsOutput.class); + when(output.getFlowAndStatisticsMapList()).thenReturn(stats); + + multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).get().write(output, true); + verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java new file mode 100644 index 0000000000..caede136db --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.statistics.services.direct.singlelayer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestGroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; + +public class GroupDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { + static final Long GROUP_NO = 1L; + private GroupDirectStatisticsService service; + + @Override + public void setUp() throws Exception { + service = new GroupDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); + } + + @Override + public void testBuildRequestBody() throws Exception { + final GetGroupStatisticsInput input = mock(GetGroupStatisticsInput.class); + + when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); + when(input.getGroupId()).thenReturn(new GroupId(GROUP_NO)); + + final MultipartRequestGroupStats body = (MultipartRequestGroupStats) ((MultipartRequest) service + .buildRequest(new Xid(42L), input)) + .getMultipartRequestBody(); + + assertEquals(GROUP_NO, body.getGroupId().getValue()); + } + + @Override + public void testBuildReply() throws Exception { + final GroupStats groupStat = new GroupStatsBuilder() + .setGroupId(new GroupId(GROUP_NO)) + .build(); + + final MultipartReply reply = new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyGroupStatsBuilder() + .setGroupStats(Collections.singletonList(groupStat)) + .build()) + .build(); + + final List input = Collections.singletonList(reply); + + final GetGroupStatisticsOutput output = service.buildReply(input, true); + assertTrue(output.getGroupStats().size() > 0); + + final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stats = + output.getGroupStats().get(0); + + assertEquals(stats.getGroupId().getValue(), GROUP_NO); + } + + @Override + public void testStoreStatistics() throws Exception { + final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stat = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats.class); + when(stat.getGroupId()).thenReturn(new GroupId(GROUP_NO)); + + final List stats = Arrays.asList(stat); + final GetGroupStatisticsOutput output = mock(GetGroupStatisticsOutput.class); + when(output.getGroupStats()).thenReturn(stats); + + multipartWriterProvider.lookup(MultipartType.OFPMPGROUP).get().write(output, true); + verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java new file mode 100644 index 0000000000..ecb92b74ae --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.statistics.services.direct.singlelayer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; + +public class MeterDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { + static final Long METER_NO = 1L; + private MeterDirectStatisticsService service; + + @Override + public void setUp() throws Exception { + service = new MeterDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); + } + + @Override + public void testBuildRequestBody() throws Exception { + final GetMeterStatisticsInput input = mock(GetMeterStatisticsInput.class); + + when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); + when(input.getMeterId()).thenReturn(new MeterId(METER_NO)); + + final MultipartRequestMeterStats body = (MultipartRequestMeterStats) ((MultipartRequest) service + .buildRequest(new Xid(42L), input)) + .getMultipartRequestBody(); + + assertEquals(METER_NO, body.getMeterId().getValue()); + } + + @Override + public void testBuildReply() throws Exception { + final MeterStats meterStat = new MeterStatsBuilder() + .setMeterId(new MeterId(METER_NO)) + .setByteInCount(new Counter64(BigInteger.ONE)) + .setPacketInCount(new Counter64(BigInteger.ONE)) + .setDuration(new DurationBuilder() + .setSecond(new Counter32(1L)) + .setNanosecond(new Counter32(1L)) + .build()) + .setFlowCount(new Counter32(0L)) + .setMeterBandStats(new MeterBandStatsBuilder().build()) + .build(); + + final MultipartReply reply = new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyMeterStatsBuilder() + .setMeterStats(Collections.singletonList(meterStat)) + .build()) + .build(); + + final List input = Collections.singletonList(reply); + + final GetMeterStatisticsOutput output = service.buildReply(input, true); + assertTrue(output.getMeterStats().size() > 0); + + final MeterStats stats = output.getMeterStats().get(0); + assertEquals(stats.getMeterId().getValue(), METER_NO); + } + + @Override + public void testStoreStatistics() throws Exception { + final org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats stat = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats.class); + when(stat.getMeterId()).thenReturn(new MeterId(METER_NO)); + + final List stats = Arrays.asList(stat); + final GetMeterStatisticsOutput output = mock(GetMeterStatisticsOutput.class); + when(output.getMeterStats()).thenReturn(stats); + + multipartWriterProvider.lookup(MultipartType.OFPMPMETER).get().write(output, true); + verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java new file mode 100644 index 0000000000..fd501ace21 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.statistics.services.direct.singlelayer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapBuilder; + +public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { + private PortDirectStatisticsService service; + + @Override + public void setUp() throws Exception { + service = new PortDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); + } + + @Override + public void testBuildRequestBody() throws Exception { + final GetNodeConnectorStatisticsInput input = mock(GetNodeConnectorStatisticsInput.class); + + when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); + when(input.getNodeConnectorId()).thenReturn(nodeConnectorId); + + final MultipartRequestPortStats body = (MultipartRequestPortStats) ((MultipartRequest)service + .buildRequest(new Xid(42L), input)) + .getMultipartRequestBody(); + + assertEquals(nodeConnectorId, body.getNodeConnectorId()); + } + + @Override + public void testBuildReply() throws Exception { + final NodeConnectorStatisticsAndPortNumberMap portStat = new NodeConnectorStatisticsAndPortNumberMapBuilder() + .setNodeConnectorId(nodeConnectorId) + .build(); + + final MultipartReply reply = new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyPortStatsBuilder() + .setNodeConnectorStatisticsAndPortNumberMap(Collections.singletonList(portStat)) + .build()) + .build(); + + final List input = Collections.singletonList(reply); + final GetNodeConnectorStatisticsOutput output = service.buildReply(input, true); + assertTrue(output.getNodeConnectorStatisticsAndPortNumberMap().size() > 0); + + final NodeConnectorStatisticsAndPortNumberMap stats = + output.getNodeConnectorStatisticsAndPortNumberMap().get(0); + + assertEquals(stats.getNodeConnectorId(), nodeConnectorId); + } + + @Override + public void testStoreStatistics() throws Exception { + final NodeConnectorStatisticsAndPortNumberMap stat = mock(NodeConnectorStatisticsAndPortNumberMap.class); + when(stat.getNodeConnectorId()).thenReturn(nodeConnectorId); + + final List stats = Arrays.asList(stat); + final GetNodeConnectorStatisticsOutput output = mock(GetNodeConnectorStatisticsOutput.class); + when(output.getNodeConnectorStatisticsAndPortNumberMap()).thenReturn(stats); + + multipartWriterProvider.lookup(MultipartType.OFPMPPORTSTATS).get().write(output, true); + verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java new file mode 100644 index 0000000000..4e32c092db --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.statistics.services.direct.singlelayer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.reply.multipart.reply.body.MultipartReplyQueueStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMapBuilder; + +public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { + static final Long QUEUE_NO = 1L; + private QueueDirectStatisticsService service; + + @Override + public void setUp() throws Exception { + service = new QueueDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); + } + + @Override + public void testBuildRequestBody() throws Exception { + final GetQueueStatisticsInput input = mock(GetQueueStatisticsInput.class); + + when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); + when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(input.getNodeConnectorId()).thenReturn(nodeConnectorId); + + final MultipartRequestQueueStats body = (MultipartRequestQueueStats) ((MultipartRequest) service + .buildRequest(new Xid(42L), input)) + .getMultipartRequestBody(); + + assertEquals(nodeConnectorId, body.getNodeConnectorId()); + assertEquals(QUEUE_NO, body.getQueueId().getValue()); + } + + @Override + public void testBuildReply() throws Exception { + final QueueIdAndStatisticsMap queueStats = new QueueIdAndStatisticsMapBuilder() + .setQueueId(new QueueId(QUEUE_NO)) + .setNodeConnectorId(new NodeConnectorId(PORT_NO.toString())) + .setTransmittedBytes(new Counter64(BigInteger.ONE)) + .setTransmissionErrors(new Counter64(BigInteger.ONE)) + .setTransmittedBytes(new Counter64(BigInteger.ONE)) + .build(); + + final MultipartReply reply = new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyQueueStatsBuilder() + .setQueueIdAndStatisticsMap(Collections.singletonList(queueStats)) + .build()) + .build(); + + final List input = Collections.singletonList(reply); + final GetQueueStatisticsOutput output = service.buildReply(input, true); + assertTrue(output.getQueueIdAndStatisticsMap().size() > 0); + + final QueueIdAndStatisticsMap map = output.getQueueIdAndStatisticsMap().get(0); + assertEquals(map.getQueueId().getValue(), QUEUE_NO); + assertEquals(map.getNodeConnectorId().getValue(), PORT_NO.toString()); + } + + @Override + public void testStoreStatistics() throws Exception { + final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class); + when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + + final List maps = Arrays.asList(map); + final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class); + when(output.getQueueIdAndStatisticsMap()).thenReturn(maps); + + multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).get().write(output, true); + verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } +} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtilTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtilTest.java new file mode 100644 index 0000000000..27da80cf44 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtilTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 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.openflowplugin.impl.util; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.util.concurrent.Futures; +import java.util.Collections; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.TxFacade; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@RunWith(MockitoJUnitRunner.class) +public class DeviceInitializationUtilTest { + @Mock + private DataBroker dataBroker; + @Mock + private WriteTransaction writeTransaction; + @Mock + private TxFacade txFacade; + @Mock + private DeviceInfo deviceInfo; + + @Before + public void setUp() throws Exception { + when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(DeviceStateUtil + .createNodeInstanceIdentifier(new NodeId("openflow:1"))); + when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); + } + + @Test + public void makeEmptyNodes() throws Exception { + DeviceInitializationUtil.makeEmptyNodes(dataBroker); + verify(dataBroker).newWriteOnlyTransaction(); + verify(writeTransaction).merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier + .create(Nodes.class), new NodesBuilder() + .setNode(Collections.emptyList()) + .build()); + verify(writeTransaction).submit(); + } + + @Test + public void makeEmptyTables() throws Exception { + DeviceInitializationUtil.makeEmptyTables(txFacade, deviceInfo, (short) 10); + verify(txFacade, times(10)).writeToTransaction( + eq(LogicalDatastoreType.OPERATIONAL), any(), any()); + } + + @Test + public void getIpAddress() throws Exception { + } + + @Test + public void getPortNumber() throws Exception { + } + + @Test + public void getSwitchFeatures() throws Exception { + } + +} \ No newline at end of file -- 2.36.6