From 1af28ce842ef5a96ad1293c8db0a6cb494c1fbdc Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Wed, 9 Apr 2014 08:19:47 +0200 Subject: [PATCH] Extensibility support (deserialization part) Signed-off-by: Michal Polkorab Change-Id: Ic73091b01614e76087b30ad79dbf9b6f8b39545c --- .../extensibility/DeserializerRegistry.java | 34 ++ .../DeserializerRegistryInjector.java | 21 + .../extensibility/EnhancedMessageCodeKey.java | 48 ++ .../api/extensibility/HeaderDeserializer.java | 27 + .../api/extensibility/MessageCodeKey.java | 65 +++ .../api/extensibility}/OFDeserializer.java | 17 +- .../extensibility/OFGeneralDeserializer.java | 17 + .../SwitchConnectionProviderImpl.java | 18 + .../protocol/impl/core/OFDecoder.java | 11 +- .../core/PublishingChannelInitializer.java | 14 +- .../protocol/impl/core/TcpHandler.java | 11 +- .../impl/deserialization/DecoderTable.java | 144 ----- .../DeserializationFactory.java | 53 +- .../DeserializerRegistryImpl.java | 86 +++ .../MatchEntryDeserializerInitializer.java | 111 ++++ .../MessageDerializerInitializer.java | 97 ++++ .../deserialization/MessageTypeCodeKey.java | 2 +- .../impl/deserialization/TypeToClassKey.java | 52 ++ .../TypeToClassMapInitializer.java | 75 +++ .../factories/BarrierReplyMessageFactory.java | 27 +- .../factories/EchoReplyMessageFactory.java | 23 +- .../factories/EchoRequestMessageFactory.java | 23 +- .../factories/ErrorMessageFactory.java | 25 +- .../factories/ExperimenterMessageFactory.java | 54 -- .../FeaturesReplyMessageFactory.java | 24 +- .../factories/FlowRemovedMessageFactory.java | 41 +- .../GetAsyncReplyMessageFactory.java | 24 +- .../GetConfigReplyMessageFactory.java | 23 +- .../factories/HelloMessageFactory.java | 22 +- .../MultipartReplyMessageFactory.java | 95 ++-- .../OF10BarrierReplyMessageFactory.java | 32 ++ .../OF10EchoReplyMessageFactory.java | 37 ++ .../OF10EchoRequestMessageFactory.java | 33 ++ .../factories/OF10ErrorMessageFactory.java | 27 +- .../OF10FeaturesReplyMessageFactory.java | 22 +- .../OF10FlowRemovedMessageFactory.java | 41 +- .../OF10GetConfigReplyMessageFactory.java | 35 ++ .../factories/OF10HelloMessageFactory.java | 25 +- .../factories/OF10PacketInMessageFactory.java | 23 +- .../OF10PortStatusMessageFactory.java | 22 +- ...OF10QueueGetConfigReplyMessageFactory.java | 25 +- .../OF10StatsReplyMessageFactory.java | 51 +- .../factories/OF10VendorMessageFactory.java | 51 -- .../factories/PacketInMessageFactory.java | 39 +- .../factories/PortStatusMessageFactory.java | 24 +- .../QueueGetConfigReplyMessageFactory.java | 24 +- .../factories/RoleReplyMessageFactory.java | 24 +- .../AbstractOxmIpv4AddressDeserializer.java | 52 ++ .../AbstractOxmIpv6AddressDeserializer.java | 53 ++ .../AbstractOxmMacAddressDeserializer.java | 45 ++ .../AbstractOxmMatchEntryDeserializer.java | 64 +++ .../AbstractOxmMetadataDeserializer.java | 43 ++ .../match/AbstractOxmPortDeserializer.java | 38 ++ .../AbstractOxmPortNumberDeserializer.java | 34 ++ .../match/OxmArpOpDeserializer.java | 51 ++ .../match/OxmArpShaDeserializer.java | 30 + .../match/OxmArpSpaDeserializer.java | 30 + .../match/OxmArpThaDeserializer.java | 30 + .../match/OxmArpTpaDeserializer.java | 30 + .../match/OxmEthDstDeserializer.java | 31 ++ .../match/OxmEthSrcDeserializer.java | 31 ++ .../match/OxmEthTypeDeserializer.java | 52 ++ .../match/OxmIcmpv4CodeDeserializer.java | 53 ++ .../match/OxmIcmpv4TypeDeserializer.java | 52 ++ .../match/OxmIcmpv6CodeDeserializer.java | 52 ++ .../match/OxmIcmpv6TypeDeserializer.java | 47 ++ .../match/OxmInPhyPortDeserializer.java | 30 + .../match/OxmInPortDeserializer.java | 30 + .../match/OxmIpDscpDeserializer.java | 52 ++ .../match/OxmIpEcnDeserializer.java | 51 ++ .../match/OxmIpProtoDeserializer.java | 51 ++ .../match/OxmIpv4DstDeserializer.java | 30 + .../match/OxmIpv4SrcDeserializer.java | 30 + .../match/OxmIpv6DstDeserializer.java | 30 + .../match/OxmIpv6ExtHdrDeserializer.java | 67 +++ .../match/OxmIpv6FlabelDeserializer.java | 58 ++ .../match/OxmIpv6NdSllDeserializer.java | 30 + .../match/OxmIpv6NdTargetDeserializer.java | 30 + .../match/OxmIpv6NdTllDeserializer.java | 31 ++ .../match/OxmIpv6SrcDeserializer.java | 30 + .../match/OxmMaskDeserializer.java | 36 ++ .../match/OxmMetadataDeserializer.java | 30 + .../match/OxmMplsBosDeserializer.java | 57 ++ .../match/OxmMplsLabelDeserializer.java | 52 ++ .../match/OxmMplsTcDeserializer.java | 52 ++ .../match/OxmPbbIsidDeserializer.java | 57 ++ .../match/OxmSctpDstDeserializer.java | 30 + .../match/OxmSctpSrcDeserializer.java | 30 + .../match/OxmTcpDstDeserializer.java | 30 + .../match/OxmTcpSrcDeserializer.java | 30 + .../match/OxmTunnelIdDeserializer.java | 30 + .../match/OxmUdpDstDeserializer.java | 30 + .../match/OxmUdpSrcDeserializer.java | 30 + .../match/OxmVlanPcpDeserializer.java | 51 ++ .../match/OxmVlanVidDeserializer.java | 57 ++ .../impl/util/ActionsDeserializer.java | 338 +++++------ .../protocol/impl/util/DecodingUtils.java | 116 ++++ .../protocol/impl/util/EncodeConstants.java | 3 + .../impl/util/InstructionsDeserializer.java | 206 ++++--- .../protocol/impl/util/MatchDeserializer.java | 524 +----------------- .../MatchEntryDeserializerRegistryHelper.java | 47 ++ .../MessageDeserializerRegistryHelper.java | 43 ++ .../impl/util/OF10ActionsDeserializer.java | 62 +-- .../impl/util/OF10MatchDeserializer.java | 46 +- .../protocol/impl/util/OxmMatchConstants.java | 4 +- .../impl/util/TypeToClassInitHelper.java | 42 ++ .../BarrierReplyMessageFactoryTest.java | 33 +- .../EchoReplyMessageFactoryTest.java | 53 +- .../EchoRequestMessageFactoryTest.java | 53 +- .../factories/ErrorMessageFactoryTest.java | 31 +- .../ExperimenterMessageFactoryTest.java | 38 -- .../FeaturesReplyMessageFactoryTest.java | 22 +- .../FlowRemovedMessageFactoryTest.java | 21 +- .../GetAsyncReplyMessageFactoryTest.java | 22 +- .../GetConfigReplyMessageFactoryTest.java | 22 +- .../factories/HelloMessageFactoryTest.java | 25 +- .../MultipartReplyMessageFactoryTest.java | 55 +- .../OF10BarrierReplyMessageFactoryTest.java | 54 ++ .../OF10EchoReplyMessageFactoryTest.java | 67 +++ .../OF10EchoRequestMessageFactoryTest.java | 66 +++ .../OF10ErrorMessageFactoryTest.java | 32 +- .../OF10FeaturesReplyMessageFactoryTest.java | 28 +- .../OF10FlowRemovedMessageFactoryTest.java | 23 +- .../OF10GetConfigReplyMessageFactoryTest.java | 57 ++ .../OF10HelloMessageFactoryTest.java | 29 +- .../OF10PacketInMessageFactoryTest.java | 26 +- .../OF10PortStatusMessageFactoryTest.java | 21 +- ...QueueGetConfigReplyMessageFactoryTest.java | 23 +- .../OF10StatsReplyMessageFactoryTest.java | 33 +- .../OF10VendorMessageFactoryTest.java | 35 -- .../factories/PacketInMessageFactoryTest.java | 26 +- .../PortStatusMessageFactoryTest.java | 21 +- ...GetConfigReplyMessageFactoryMultiTest.java | 23 +- ...QueueGetConfigReplyMessageFactoryTest.java | 21 +- .../RoleReplyMessageFactoryTest.java | 21 +- .../impl/util/ActionsDeserializerTest.java | 34 +- .../protocol/impl/util/BufferHelper.java | 24 +- .../protocol/impl/util/ByteBufUtilsTest.java | 8 +- .../util/InstructionsDeserializerTest.java | 25 +- .../impl/util/MatchDeserializerTest.java | 52 +- .../util/OF10ActionsDeserializerTest.java | 33 +- .../impl/util/OF10MatchDeserializerTest.java | 22 +- .../impl/integration/IntegrationTest.java | 1 - .../connection/SwitchConnectionProvider.java | 10 + 144 files changed, 4506 insertions(+), 1904 deletions(-) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistry.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistryInjector.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageCodeKey.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderDeserializer.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageCodeKey.java rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization => openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility}/OFDeserializer.java (59%) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralDeserializer.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MatchEntryDeserializerInitializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageDerializerInitializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKey.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializer.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10BarrierReplyMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10GetConfigReplyMessageFactory.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv4AddressDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv6AddressDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMacAddressDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMatchEntryDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMetadataDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortNumberDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpOpDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpShaDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpSpaDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpThaDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpTpaDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthDstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthSrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthTypeDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4CodeDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4TypeDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6CodeDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6TypeDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPhyPortDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPortDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpDscpDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpEcnDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpProtoDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4DstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4SrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6DstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6ExtHdrDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6FlabelDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdSllDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTargetDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTllDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6SrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMaskDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMetadataDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsBosDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsLabelDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsTcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmPbbIsidDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpDstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpSrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpDstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpSrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTunnelIdDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpDstDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpSrcDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanPcpDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanVidDeserializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/DecodingUtils.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntryDeserializerRegistryHelper.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MessageDeserializerRegistryHelper.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeToClassInitHelper.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10BarrierReplyMessageFactoryTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactoryTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactoryTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10GetConfigReplyMessageFactoryTest.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistry.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistry.java new file mode 100644 index 00000000..665fa574 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistry.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + + +/** + * @author michal.polkorab + * + */ +public interface DeserializerRegistry { + + /** + * Initializes deserializers + */ + public void init(); + + /** + * @param key used for deserializer lookup + * @return deserializer found + */ + public + SERIALIZER_TYPE getDeserializer(MessageCodeKey key); + + /** + * @param key used to registry lookup + * @param deserializer deserializer instance + */ + public void registerDeserializer(MessageCodeKey key, OFGeneralDeserializer deserializer); +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistryInjector.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistryInjector.java new file mode 100644 index 00000000..5f029a2d --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerRegistryInjector.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + +/** + * Injects registry + * @author michal.polkorab + */ +public interface DeserializerRegistryInjector { + + /** + * Injects deserializer registry into deserializer + * @param deserializerRegistry + */ + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry); +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageCodeKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageCodeKey.java new file mode 100644 index 00000000..509c3863 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageCodeKey.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + +/** + * @author michal.polkorab + * + */ +public class EnhancedMessageCodeKey extends MessageCodeKey { + + private int msgType2; + + /** + * Constructor + * @param version wire protocol version + * @param value used as distinguisher + * @param value2 used as detailed distinguisher + * @param clazz class of object that is going to be deserialized + */ + public EnhancedMessageCodeKey(short version, int value, int value2, Class clazz) { + super(version, value, clazz); + this.msgType2 = value2; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + EnhancedMessageCodeKey other = (EnhancedMessageCodeKey) obj; + if (msgType2 != other.msgType2) + return false; + return true; + } + + @Override + public String toString() { + return super.toString() + " msgType2: " + msgType2; + } +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderDeserializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderDeserializer.java new file mode 100644 index 00000000..205c7692 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderDeserializer.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * @param + */ +public interface HeaderDeserializer extends OFGeneralDeserializer { + + /** + * Deserializes byte message headers + * + * @param rawMessage message as bytes in ByteBuf + * @return POJO/DTO + */ + public E deserializeHeader(ByteBuf rawMessage); +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageCodeKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageCodeKey.java new file mode 100644 index 00000000..5ebcde21 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageCodeKey.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + +/** + * @author michal.polkorab + */ +public class MessageCodeKey { + + private short msgVersion; + private int msgType; + private Class clazz; + + /** + * Constructor + * @param version wire protocol version + * @param value used as distinguisher + * @param clazz class of object that is going to be deserialized + */ + public MessageCodeKey(short version, int value, Class clazz) { + this.msgVersion = version; + this.msgType = value; + this.clazz = clazz; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + msgType; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MessageCodeKey other = (MessageCodeKey) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (msgType != other.msgType) + return false; + if (msgVersion != other.msgVersion) + return false; + return true; + } + + @Override + public String toString() { + return "msgVersion: " + msgVersion + " class: " + clazz.getName() + " msgType: " + msgType; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java similarity index 59% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java rename to openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java index c4df5df0..a514e00f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFDeserializer.java @@ -6,28 +6,25 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; - -import org.opendaylight.yangtools.yang.binding.DataObject; +package org.opendaylight.openflowjava.protocol.api.extensibility; import io.netty.buffer.ByteBuf; +import org.opendaylight.yangtools.yang.binding.DataObject; + /** * Uniform interface for deserializing factories * @author michal.polkorab * @author timotej.kubas * @param message code type */ -public interface OFDeserializer { +public interface OFDeserializer extends OFGeneralDeserializer { /** * Transforms byte message into POJO/DTO (of type E). - * Assumes that input ByteBuf's readerIndex is pointing on length in OpenFlow header * - * @param rawMessage message as bytes in ByteBuf - * @param version version of used OF Protocol - * @return HelloMessage as DataObject + * @param message message as bytes in ByteBuf + * @return POJO/DTO */ - public abstract E bufferToMessage(ByteBuf rawMessage, short version); - + public E deserialize(ByteBuf message); } diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralDeserializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralDeserializer.java new file mode 100644 index 00000000..bedb267a --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralDeserializer.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.api.extensibility; + + +/** + * @author michal.polkorab + */ +public interface OFGeneralDeserializer { + + // empty unifying interface +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index a8bceeea..e1dabb49 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -15,9 +15,14 @@ import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHan import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; @@ -40,6 +45,8 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { private ConnectionConfiguration connConfig; private SerializationFactory serializationFactory; private SerializerRegistry serializerRegistry; + private DeserializerRegistry deserializerRegistry; + private DeserializationFactory deserializationFactory; /** Constructor */ public SwitchConnectionProviderImpl() { @@ -47,6 +54,10 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { serializerRegistry.init(); serializationFactory = new SerializationFactory(); serializationFactory.setSerializerTable(serializerRegistry); + deserializerRegistry = new DeserializerRegistryImpl(); + deserializerRegistry.init(); + deserializationFactory = new DeserializationFactory(); + deserializationFactory.setRegistry(deserializerRegistry); } @Override @@ -106,6 +117,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport()); server.setEncryption(tlsSupported); server.setSerializationFactory(serializationFactory); + server.setDeserializationFactory(deserializationFactory); return server; } @@ -122,6 +134,12 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { serializerRegistry.registerSerializer(key, serializer); } + @Override + public void registerDeserializer(MessageCodeKey key, + OFGeneralDeserializer deserializer) { + deserializerRegistry.registerDeserializer(key, deserializer); + } + @Override public void close() throws Exception { shutdown(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java index 9c706a88..a1f9fb94 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; public class OFDecoder extends MessageToMessageDecoder { private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class); + private DeserializationFactory deserializationFactory; /** * Constructor of class @@ -43,7 +44,7 @@ public class OFDecoder extends MessageToMessageDecoder { } DataObject dataObject = null; try { - dataObject = DeserializationFactory.bufferToMessage(msg.getMessageBuffer(), + dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(), msg.getVersion()); } catch(Exception e) { LOGGER.error("Message deserialization failed"); @@ -57,4 +58,12 @@ public class OFDecoder extends MessageToMessageDecoder { msg.getMessageBuffer().release(); out.add(dataObject); } + + /** + * @param deserializationFactory + */ + public void setDeserializationFactory(DeserializationFactory deserializationFactory) { + this.deserializationFactory = deserializationFactory; + } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java index 5a35864b..184aec13 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java @@ -22,6 +22,7 @@ import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterF import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade; import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +39,7 @@ public class PublishingChannelInitializer extends ChannelInitializer - * Type Message - * 0: HELLO - * 1: ERROR - * 2: ECHO_REQUEST - * 3: ECHO_REPLY - * 4: EXPERIMENTER - * 5: FEATURES_REQUEST - * 6: FEATURES_REPLY - * 7: GET_CONFIG_REQUEST - * 8: GET_CONFIG_REPLY - * 9: SET_CONFIG - * 10: PACKET_IN - * 11: FLOW_REMOVED - * 12: PORT_STATUS - * 13: PACKET_OUT - * 14: FLOW_MOD - * 15: GROUP_MOD - * 16: PORT_MOD - * 17: TABLE_MOD - * 18: MULTIPART_REQUEST - * 19: MULTIPART_REPLY - * 20: BARRIER_REQUEST - * 21: BARRIER_REPLY - * 22: QUEUE_GET_CONFIG_REQUEST - * 23: QUEUE_GET_CONFIG_REPLY - * 24: ROLE_REQUEST - * 25: ROLE_REPLY - * 26: GET_ASYNC_REQUEST - * 27: GET_ASYNC_REPLY - * 28: SET_ASYNC - * 29: METER_MOD - * - */ -public class DecoderTable { - - private static final short OF10 = EncodeConstants.OF10_VERSION_ID; - private static final short OF13 = EncodeConstants.OF13_VERSION_ID; - private Map> table; - private static DecoderTable instance; - - - private DecoderTable() { - // do nothing - } - - /** - * @return singleton instance - */ - public static synchronized DecoderTable getInstance() { - if (instance == null) { - instance = new DecoderTable(); - instance.init(); - } - return instance; - } - - /** - * Decoder table provisioning - */ - public void init() { - table = new HashMap<>(); - table.put(new MessageTypeCodeKey(OF10, (short) 0), OF10HelloMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 2), EchoRequestMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 3), EchoReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 8), GetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 17), OF10StatsReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 19), BarrierReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 21), OF10QueueGetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance()); - } - - /** - * @param msgTypeKey - * @return decoder for given message types - */ - public OFDeserializer getDecoder(MessageTypeCodeKey msgTypeKey) { - return table.get(msgTypeKey); - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java index 4daadffc..1d827c0f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java @@ -10,38 +10,59 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization; import io.netty.buffer.ByteBuf; +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author michal.polkorab * @author timotej.kubas */ -public abstract class DeserializationFactory { - - private static final Logger LOGGER = LoggerFactory - .getLogger(DeserializationFactory.class); +public class DeserializationFactory { + + private DeserializerRegistry registry; + private Map> messageClassMap; + + /** + * Constructor + */ + public DeserializationFactory() { + messageClassMap = new HashMap<>(); + initTypeToClassMapping(); + } /** * Transforms ByteBuf into correct POJO message - * @param rawMessage + * @param rawMessage * @param version version decoded from OpenFlow protocol message * @return correct POJO as DataObject */ - public static DataObject bufferToMessage(ByteBuf rawMessage, short version) { + public DataObject deserialize(ByteBuf rawMessage, short version) { DataObject dataObject = null; - short type = rawMessage.readUnsignedByte(); + int type = rawMessage.readUnsignedByte(); + Class clazz = messageClassMap.get(new TypeToClassKey(version, type)); rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - - MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type); - OFDeserializer decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey); - if (decoder != null) { - dataObject = decoder.bufferToMessage(rawMessage, version); - } else { - LOGGER.warn("No correct decoder found in DecoderTable for arguments: " + msgTypeCodeKey.toString()); + OFDeserializer deserializer = registry.getDeserializer( + new MessageCodeKey(version, type, clazz)); + if (deserializer != null) { + dataObject = deserializer.deserialize(rawMessage); } return dataObject; } + + /** + * @param registry + */ + public void setRegistry(DeserializerRegistry registry) { + this.registry = registry; + } + + private void initTypeToClassMapping() { + TypeToClassMapInitializer.initializeTypeToClassMap(messageClassMap); + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java new file mode 100644 index 00000000..80397310 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; + +/** + * Stores and registers deserializers + * @author michal.polkorab + */ +public class DeserializerRegistryImpl implements DeserializerRegistry { + + private Map registry; + + /** + * Decoder table provisioning + */ + @Override + public void init() { + registry = new HashMap<>(); + // register message deserializers + MessageDerializerInitializer.registerMessageDeserializers(this); + + // register common structure deserializers + registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, + EncodeConstants.EMPTY_VALUE, MatchV10.class), new OF10MatchDeserializer()); + registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Action.class), new OF10ActionsDeserializer()); + registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Match.class), new MatchDeserializer()); + registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Action.class), new ActionsDeserializer()); + registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Instruction.class), new InstructionsDeserializer()); + + // register match entry deserializers + MatchEntryDeserializerInitializer.registerMatchEntryDeserializers(this); + } + + @Override + @SuppressWarnings("unchecked") + public DESERIALIZER_TYPE getDeserializer( + MessageCodeKey key) { + OFGeneralDeserializer deserializer = registry.get(key); + if (deserializer == null) { + throw new NullPointerException("Deserializer for key: " + key.toString() + + " was not found"); + } + return (DESERIALIZER_TYPE) deserializer; + } + + @Override + public void registerDeserializer(MessageCodeKey key, + OFGeneralDeserializer deserializer) { + if ((key == null) || (deserializer == null)) { + throw new NullPointerException("MessageCodeKey or Deserializer is null"); + } + if (deserializer instanceof DeserializerRegistryInjector) { + ((DeserializerRegistryInjector) deserializer).injectDeserializerRegistry(this); + } + registry.put(key, deserializer); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MatchEntryDeserializerInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MatchEntryDeserializerInitializer.java new file mode 100644 index 00000000..8d904ded --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MatchEntryDeserializerInitializer.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmArpOpDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmArpShaDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmArpSpaDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmArpThaDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmArpTpaDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmEthDstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmEthSrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmEthTypeDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIcmpv4CodeDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIcmpv4TypeDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIcmpv6CodeDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIcmpv6TypeDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmInPhyPortDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmInPortDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpDscpDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpEcnDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpProtoDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv4DstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv4SrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6DstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6ExtHdrDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6FlabelDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6NdSllDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6NdTargetDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6NdTllDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6SrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMetadataDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMplsBosDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMplsLabelDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMplsTcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmPbbIsidDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmSctpDstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmSctpSrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmTcpDstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmTcpSrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmTunnelIdDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmUdpDstDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmUdpSrcDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmVlanPcpDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmVlanVidDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.MatchEntryDeserializerRegistryHelper; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class MatchEntryDeserializerInitializer { + + /** + * Registers match entry deserializers + * @param registry registry to be filled with deserializers + */ + public static void registerMatchEntryDeserializers(DeserializerRegistry registry) { + // register OpenflowBasicClass match entry deserializers + MatchEntryDeserializerRegistryHelper helper = + new MatchEntryDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, + OxmMatchConstants.OPENFLOW_BASIC_CLASS, registry); + helper.register(OxmMatchConstants.IN_PORT, new OxmInPortDeserializer()); + helper.register(OxmMatchConstants.IN_PHY_PORT, new OxmInPhyPortDeserializer()); + helper.register(OxmMatchConstants.METADATA, new OxmMetadataDeserializer()); + helper.register(OxmMatchConstants.ETH_DST, new OxmEthDstDeserializer()); + helper.register(OxmMatchConstants.ETH_SRC, new OxmEthSrcDeserializer()); + helper.register(OxmMatchConstants.ETH_TYPE, new OxmEthTypeDeserializer()); + helper.register(OxmMatchConstants.VLAN_VID, new OxmVlanVidDeserializer()); + helper.register(OxmMatchConstants.VLAN_PCP, new OxmVlanPcpDeserializer()); + helper.register(OxmMatchConstants.IP_DSCP, new OxmIpDscpDeserializer()); + helper.register(OxmMatchConstants.IP_ECN, new OxmIpEcnDeserializer()); + helper.register(OxmMatchConstants.IP_PROTO, new OxmIpProtoDeserializer()); + helper.register(OxmMatchConstants.IPV4_SRC, new OxmIpv4SrcDeserializer()); + helper.register(OxmMatchConstants.IPV4_DST, new OxmIpv4DstDeserializer()); + helper.register(OxmMatchConstants.TCP_SRC, new OxmTcpSrcDeserializer()); + helper.register(OxmMatchConstants.TCP_DST, new OxmTcpDstDeserializer()); + helper.register(OxmMatchConstants.UDP_SRC, new OxmUdpSrcDeserializer()); + helper.register(OxmMatchConstants.UDP_DST, new OxmUdpDstDeserializer()); + helper.register(OxmMatchConstants.SCTP_SRC, new OxmSctpSrcDeserializer()); + helper.register(OxmMatchConstants.SCTP_DST, new OxmSctpDstDeserializer()); + helper.register(OxmMatchConstants.ICMPV4_TYPE, new OxmIcmpv4TypeDeserializer()); + helper.register(OxmMatchConstants.ICMPV4_CODE, new OxmIcmpv4CodeDeserializer()); + helper.register(OxmMatchConstants.ARP_OP, new OxmArpOpDeserializer()); + helper.register(OxmMatchConstants.ARP_SPA, new OxmArpSpaDeserializer()); + helper.register(OxmMatchConstants.ARP_TPA, new OxmArpTpaDeserializer()); + helper.register(OxmMatchConstants.ARP_SHA, new OxmArpShaDeserializer()); + helper.register(OxmMatchConstants.ARP_THA, new OxmArpThaDeserializer()); + helper.register(OxmMatchConstants.IPV6_SRC, new OxmIpv6SrcDeserializer()); + helper.register(OxmMatchConstants.IPV6_DST, new OxmIpv6DstDeserializer()); + helper.register(OxmMatchConstants.IPV6_FLABEL, new OxmIpv6FlabelDeserializer()); + helper.register(OxmMatchConstants.ICMPV6_TYPE, new OxmIcmpv6TypeDeserializer()); + helper.register(OxmMatchConstants.ICMPV6_CODE, new OxmIcmpv6CodeDeserializer()); + helper.register(OxmMatchConstants.IPV6_ND_TARGET, new OxmIpv6NdTargetDeserializer()); + helper.register(OxmMatchConstants.IPV6_ND_SLL, new OxmIpv6NdSllDeserializer()); + helper.register(OxmMatchConstants.IPV6_ND_TLL, new OxmIpv6NdTllDeserializer()); + helper.register(OxmMatchConstants.MPLS_LABEL, new OxmMplsLabelDeserializer()); + helper.register(OxmMatchConstants.MPLS_TC, new OxmMplsTcDeserializer()); + helper.register(OxmMatchConstants.MPLS_BOS, new OxmMplsBosDeserializer()); + helper.register(OxmMatchConstants.PBB_ISID, new OxmPbbIsidDeserializer()); + helper.register(OxmMatchConstants.TUNNEL_ID, new OxmTunnelIdDeserializer()); + helper.register(OxmMatchConstants.IPV6_EXTHDR, new OxmIpv6ExtHdrDeserializer()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageDerializerInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageDerializerInitializer.java new file mode 100644 index 00000000..1ccd04b1 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageDerializerInitializer.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10BarrierReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10GetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.MessageDeserializerRegistryHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; + +/** + * @author michal.polkorab + * + */ +public class MessageDerializerInitializer { + + /** + * Registers message deserializers + * @param registry registry to be filled with deserializers + */ + public static void registerMessageDeserializers(DeserializerRegistry registry) { + // register OF v1.0 message deserializers + MessageDeserializerRegistryHelper helper = + new MessageDeserializerRegistryHelper(EncodeConstants.OF10_VERSION_ID, registry); + helper.registerMessageDeserializer(0, HelloMessage.class, new OF10HelloMessageFactory()); + helper.registerMessageDeserializer(1, ErrorMessage.class, new OF10ErrorMessageFactory()); + helper.registerMessageDeserializer(2, EchoRequestMessage.class, new OF10EchoRequestMessageFactory()); + helper.registerMessageDeserializer(3, EchoOutput.class, new OF10EchoReplyMessageFactory()); + helper.registerMessageDeserializer(6, GetFeaturesOutput.class, new OF10FeaturesReplyMessageFactory()); + helper.registerMessageDeserializer(8, GetConfigOutput.class, new OF10GetConfigReplyMessageFactory()); + helper.registerMessageDeserializer(10, PacketInMessage.class, new OF10PacketInMessageFactory()); + helper.registerMessageDeserializer(11, FlowRemovedMessage.class, new OF10FlowRemovedMessageFactory()); + helper.registerMessageDeserializer(12, PortStatusMessage.class, new OF10PortStatusMessageFactory()); + helper.registerMessageDeserializer(17, MultipartReplyMessage.class, new OF10StatsReplyMessageFactory()); + helper.registerMessageDeserializer(19, BarrierOutput.class, new OF10BarrierReplyMessageFactory()); + helper.registerMessageDeserializer(21, GetQueueConfigOutput.class, new OF10QueueGetConfigReplyMessageFactory()); + // register Of v1.3 message deserializers + helper = new MessageDeserializerRegistryHelper(EncodeConstants.OF13_VERSION_ID, registry); + helper.registerMessageDeserializer(0, HelloMessage.class, new HelloMessageFactory()); + helper.registerMessageDeserializer(1, ErrorMessage.class, new ErrorMessageFactory()); + helper.registerMessageDeserializer(2, EchoRequestMessage.class, new EchoRequestMessageFactory()); + helper.registerMessageDeserializer(3, EchoOutput.class, new EchoReplyMessageFactory()); + helper.registerMessageDeserializer(6, GetFeaturesOutput.class, new FeaturesReplyMessageFactory()); + helper.registerMessageDeserializer(8, GetConfigOutput.class, new GetConfigReplyMessageFactory()); + helper.registerMessageDeserializer(10, PacketInMessage.class, new PacketInMessageFactory()); + helper.registerMessageDeserializer(11, FlowRemovedMessage.class, new FlowRemovedMessageFactory()); + helper.registerMessageDeserializer(12, PortStatusMessage.class, new PortStatusMessageFactory()); + helper.registerMessageDeserializer(19, MultipartReplyMessage.class, new MultipartReplyMessageFactory()); + helper.registerMessageDeserializer(21, BarrierOutput.class, new BarrierReplyMessageFactory()); + helper.registerMessageDeserializer(23, GetQueueConfigOutput.class, new QueueGetConfigReplyMessageFactory()); + helper.registerMessageDeserializer(25, RoleRequestOutput.class, new RoleReplyMessageFactory()); + helper.registerMessageDeserializer(27, GetAsyncOutput.class, new GetAsyncReplyMessageFactory()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java index 96fb3e70..bb4368ab 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java @@ -10,7 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization; /** - * Class used as a key in {@link DecoderTable} + * Class used as a key in {@link DeserializerRegistryImpl} * @author michal.polkorab * @author timotej.kubas */ diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKey.java new file mode 100644 index 00000000..8be2df3e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKey.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +/** + * @author michal.polkorab + * + */ +public class TypeToClassKey { + + private short version; + private int type; + + /** + * Constructor + * @param version wire protocol version + * @param type message type / code + */ + public TypeToClassKey(short version, int type) { + this.version = version; + this.type = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + type; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TypeToClassKey other = (TypeToClassKey) obj; + if (type != other.type) + return false; + if (version != other.version) + return false; + return true; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializer.java new file mode 100644 index 00000000..6e193e24 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializer.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.TypeToClassInitHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; + +/** + * @author michal.polkorab + * + */ +public class TypeToClassMapInitializer { + + /** + * Initializes type to class map + * @param messageClassMap + */ + public static void initializeTypeToClassMap(Map> messageClassMap) { + // init OF v1.0 mapping + TypeToClassInitHelper helper = + new TypeToClassInitHelper(EncodeConstants.OF10_VERSION_ID, messageClassMap); + helper.registerTypeToClass((short) 0, HelloMessage.class); + helper.registerTypeToClass((short) 1, ErrorMessage.class); + helper.registerTypeToClass((short) 2, EchoRequestMessage.class); + helper.registerTypeToClass((short) 3, EchoOutput.class); + helper.registerTypeToClass((short) 4, ExperimenterMessage.class); + helper.registerTypeToClass((short) 6, GetFeaturesOutput.class); + helper.registerTypeToClass((short) 8, GetConfigOutput.class); + helper.registerTypeToClass((short) 10, PacketInMessage.class); + helper.registerTypeToClass((short) 11, FlowRemovedMessage.class); + helper.registerTypeToClass((short) 12, PortStatusMessage.class); + helper.registerTypeToClass((short) 17, MultipartReplyMessage.class); + helper.registerTypeToClass((short) 19, BarrierOutput.class); + helper.registerTypeToClass((short) 21, GetQueueConfigOutput.class); + // init OF v1.0 mapping + helper = new TypeToClassInitHelper(EncodeConstants.OF13_VERSION_ID, messageClassMap); + helper.registerTypeToClass((short) 0, HelloMessage.class); + helper.registerTypeToClass((short) 1, ErrorMessage.class); + helper.registerTypeToClass((short) 2, EchoRequestMessage.class); + helper.registerTypeToClass((short) 3, EchoOutput.class); + helper.registerTypeToClass((short) 4, ExperimenterMessage.class); + helper.registerTypeToClass((short) 6, GetFeaturesOutput.class); + helper.registerTypeToClass((short) 8, GetConfigOutput.class); + helper.registerTypeToClass((short) 10, PacketInMessage.class); + helper.registerTypeToClass((short) 11, FlowRemovedMessage.class); + helper.registerTypeToClass((short) 12, PortStatusMessage.class); + helper.registerTypeToClass((short) 19, MultipartReplyMessage.class); + helper.registerTypeToClass((short) 21, BarrierOutput.class); + helper.registerTypeToClass((short) 23, GetQueueConfigOutput.class); + helper.registerTypeToClass((short) 25, RoleRequestOutput.class); + helper.registerTypeToClass((short) 27, GetAsyncOutput.class); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java index 51c305cf..7ac99c4f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutputBuilder; @@ -19,31 +20,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab * @author timotej.kubas */ -public class BarrierReplyMessageFactory implements - OFDeserializer { - - private static BarrierReplyMessageFactory instance; - - private BarrierReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized BarrierReplyMessageFactory getInstance() { - if (instance == null) { - instance = new BarrierReplyMessageFactory(); - } - return instance; - } +public class BarrierReplyMessageFactory implements OFDeserializer { @Override - public BarrierOutput bufferToMessage(ByteBuf rawMessage, short version) { + public BarrierOutput deserialize(ByteBuf rawMessage) { BarrierOutputBuilder builder = new BarrierOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); return builder.build(); } - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java index c5d5ab79..5aca519f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder; @@ -21,26 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoReplyMessageFactory implements OFDeserializer { - private static EchoReplyMessageFactory instance; - - private EchoReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoReplyMessageFactory getInstance() { - if (instance == null) { - instance = new EchoReplyMessageFactory(); - } - return instance; - } - @Override - public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) { + public EchoOutput deserialize(ByteBuf rawMessage) { EchoOutputBuilder builder = new EchoOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); int remainingBytes = rawMessage.readableBytes(); if (remainingBytes > 0) { diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java index 2ba5884d..6d2b767e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; @@ -21,26 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoRequestMessageFactory implements OFDeserializer{ - private static EchoRequestMessageFactory instance; - - private EchoRequestMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoRequestMessageFactory getInstance() { - if (instance == null) { - instance = new EchoRequestMessageFactory(); - } - return instance; - } - @Override - public EchoRequestMessage bufferToMessage(ByteBuf rawMessage, short version) { + public EchoRequestMessage deserialize(ByteBuf rawMessage) { EchoRequestMessageBuilder builder = new EchoRequestMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); return builder.build(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java index 09ec1088..c3fdf8ba 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterErrorBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCode; @@ -40,27 +41,11 @@ public class ErrorMessageFactory implements OFDeserializer { private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; - - private static ErrorMessageFactory instance; - - private ErrorMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized ErrorMessageFactory getInstance() { - if (instance == null) { - instance = new ErrorMessageFactory(); - } - return instance; - } - + @Override - public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { + public ErrorMessage deserialize(ByteBuf rawMessage) { ErrorMessageBuilder builder = new ErrorMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); int type = rawMessage.readUnsignedShort(); ErrorType errorType = ErrorType.forValue(type); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java deleted file mode 100644 index f6dc0ea1..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder; - -/** - * Translates Experimenter messages - * @author michal.polkorab, - * @author timotej.kubas - */ -public class ExperimenterMessageFactory implements OFDeserializer{ - - private static ExperimenterMessageFactory instance; - - private ExperimenterMessageFactory() { - //singleton - } - - - /** - * @return singleton factory - */ - public static synchronized ExperimenterMessageFactory getInstance(){ - if (instance == null){ - instance = new ExperimenterMessageFactory(); - } - return instance; - } - - @Override - public ExperimenterMessage bufferToMessage(ByteBuf rawMessage, short version) { - ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setExperimenter(rawMessage.readUnsignedInt()); - builder.setExpType(rawMessage.readUnsignedInt()); - int remainingBytes = rawMessage.readableBytes(); - if (remainingBytes > 0) { - builder.setData(rawMessage.readBytes(remainingBytes).array()); - } - return builder.build(); - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java index 388a6e77..ad08dc12 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java @@ -12,7 +12,7 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; @@ -24,29 +24,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas */ public class FeaturesReplyMessageFactory implements OFDeserializer{ - + private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2; - - private static FeaturesReplyMessageFactory instance; - private FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new FeaturesReplyMessageFactory(); - } - return instance; - } - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { + public GetFeaturesOutput deserialize(ByteBuf rawMessage) { GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(datapathId); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java index 69d71d8d..bfe552b9 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java @@ -12,11 +12,14 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder; @@ -25,28 +28,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab * @author timotej.kubas */ -public class FlowRemovedMessageFactory implements OFDeserializer { - - private static FlowRemovedMessageFactory instance; - - private FlowRemovedMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized FlowRemovedMessageFactory getInstance(){ - if(instance == null){ - instance = new FlowRemovedMessageFactory(); - } - return instance; - } +public class FlowRemovedMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { + + private DeserializerRegistry registry; @Override - public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) { + public FlowRemovedMessage deserialize(ByteBuf rawMessage) { FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); @@ -64,7 +54,14 @@ public class FlowRemovedMessageFactory implements OFDeserializer matchDeserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); + builder.setMatch(matchDeserializer.deserialize(rawMessage)); return builder.build(); } + + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java index 2f482cf7..c6156a0b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java @@ -13,7 +13,8 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; @@ -32,28 +33,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab */ public class GetAsyncReplyMessageFactory implements OFDeserializer { - - private static GetAsyncReplyMessageFactory instance; + private static final byte SEPARATE_ROLES = 2; - - private GetAsyncReplyMessageFactory() { - // singleton - } - /** - * @return singleton factory - */ - public static synchronized GetAsyncReplyMessageFactory getInstance() { - if (instance == null) { - instance = new GetAsyncReplyMessageFactory(); - } - return instance; - } - @Override - public GetAsyncOutput bufferToMessage(ByteBuf rawMessage, short version) { + public GetAsyncOutput deserialize(ByteBuf rawMessage) { GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setPacketInMask(decodePacketInMask(rawMessage)); builder.setPortStatusMask(decodePortStatusMask(rawMessage)); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java index 95329132..5d193161 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutputBuilder; @@ -22,26 +23,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetConfigReplyMessageFactory implements OFDeserializer { - private static GetConfigReplyMessageFactory instance; - - private GetConfigReplyMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetConfigReplyMessageFactory getInstance(){ - if(instance == null){ - instance = new GetConfigReplyMessageFactory(); - } - return instance; - } - @Override - public GetConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { + public GetConfigOutput deserialize(ByteBuf rawMessage) { GetConfigOutputBuilder builder = new GetConfigOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setFlags(SwitchConfigFlag.forValue(rawMessage.readUnsignedShort())); builder.setMissSendLen(rawMessage.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java index 00e37b06..f721ad12 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java @@ -13,7 +13,7 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; @@ -28,27 +28,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class HelloMessageFactory implements OFDeserializer { - private static HelloMessageFactory instance; private static final byte HELLO_ELEMENT_HEADER_SIZE = 4; - - private HelloMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized HelloMessageFactory getInstance() { - if (instance == null) { - instance = new HelloMessageFactory(); - } - return instance; - } - @Override - public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { + public HelloMessage deserialize(ByteBuf rawMessage) { HelloMessageBuilder builder = new HelloMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); if (rawMessage.readableBytes() > 0) { builder.setElements(readElement(rawMessage)); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java index 3ef96147..002e979e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java @@ -14,12 +14,14 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.DecodingUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder; @@ -34,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities; @@ -52,6 +55,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList; @@ -141,7 +145,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class MultipartReplyMessageFactory implements OFDeserializer { +public class MultipartReplyMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4; private static final int DESC_STR_LEN = 256; @@ -173,28 +178,12 @@ public class MultipartReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); @@ -292,8 +281,14 @@ public class MultipartReplyMessageFactory implements OFDeserializer matchDeserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); + flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput)); + OFDeserializer insDeserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Instruction.class)); + List instructions = DecodingUtils.deserializeList( + subInput.readableBytes(), subInput, insDeserializer); + flowStatsBuilder.setInstruction(instructions); flowStatsList.add(flowStatsBuilder.build()); } flowBuilder.setFlowStats(flowStatsList); @@ -347,7 +342,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer features = new ArrayList<>(); @@ -379,7 +374,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer createTableFeaturesProperties(ByteBuf input, int length) { + private List createTableFeaturesProperties(ByteBuf input, int length) { List properties = new ArrayList<>(); int tableFeaturesLength = length; while (tableFeaturesLength > 0) { @@ -392,7 +387,11 @@ public class MultipartReplyMessageFactory implements OFDeserializer insDeserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Instruction.class)); + List instructions = DecodingUtils.deserializeHeaders( + propertyLength - COMMON_PROPERTY_LENGTH, input, insDeserializer); + insBuilder.setInstruction(instructions); builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES) || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { @@ -412,7 +411,11 @@ public class MultipartReplyMessageFactory implements OFDeserializer deserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class)); + List actions = DecodingUtils.deserializeHeaders( + propertyLength - COMMON_PROPERTY_LENGTH, input, deserializer); + actionBuilder.setAction(actions); builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH) || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS) @@ -421,20 +424,19 @@ public class MultipartReplyMessageFactory implements OFDeserializer 0) { - byte[] data = new byte[dataLength]; - input.readBytes(data); - expBuilder.setData(data); - } - builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); + OFDeserializer propDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + type.getIntValue(), ExperimenterRelatedTableFeatureProperty.class)); + ExperimenterRelatedTableFeatureProperty expProp = propDeserializer.deserialize(input); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expProp); } if (paddingRemainder != 0) { input.skipBytes(EncodeConstants.PADDING - paddingRemainder); @@ -827,7 +829,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer groupDescsList = new ArrayList<>(); @@ -846,8 +848,10 @@ public class MultipartReplyMessageFactory implements OFDeserializer actionsList = ActionsDeserializer - .createActions(input, bucketsLength - BUCKETS_HEADER_LENGTH); + OFDeserializer deserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class)); + List actionsList = DecodingUtils.deserializeList( + bucketsLength - BUCKETS_HEADER_LENGTH, input, deserializer); bucketsBuilder.setAction(actionsList); bucketsList.add(bucketsBuilder.build()); actualLength += bucketsLength; @@ -859,5 +863,10 @@ public class MultipartReplyMessageFactory implements OFDeserializer { + + @Override + public BarrierOutput deserialize(ByteBuf rawMessage) { + BarrierOutputBuilder builder = new BarrierOutputBuilder(); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactory.java new file mode 100644 index 00000000..a6b0bd1d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactory.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder; + +/** + * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10EchoReplyMessageFactory implements OFDeserializer { + + @Override + public EchoOutput deserialize(ByteBuf rawMessage) { + EchoOutputBuilder builder = new EchoOutputBuilder(); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + int remainingBytes = rawMessage.readableBytes(); + if (remainingBytes > 0) { + builder.setData(rawMessage.readBytes(remainingBytes).array()); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactory.java new file mode 100644 index 00000000..cd83b039 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactory.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; + +/** + * Translates EchoRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10EchoRequestMessageFactory implements OFDeserializer{ + + @Override + public EchoRequestMessage deserialize(ByteBuf rawMessage) { + EchoRequestMessageBuilder builder = new EchoRequestMessageBuilder(); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java index 5d3f874f..d5b8a7fe 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCodeV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadRequestCodeV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10; @@ -27,29 +28,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10ErrorMessageFactory implements OFDeserializer { - private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; + private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; - - private static OF10ErrorMessageFactory instance; - - private OF10ErrorMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10ErrorMessageFactory getInstance() { - if (instance == null) { - instance = new OF10ErrorMessageFactory(); - } - return instance; - } - + @Override - public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { + public ErrorMessage deserialize(ByteBuf rawMessage) { ErrorMessageBuilder builder = new ErrorMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); int type = rawMessage.readUnsignedShort(); ErrorTypeV10 errorType = ErrorTypeV10.forValue(type); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java index ea859a2d..dc61607b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java @@ -14,7 +14,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; @@ -35,27 +35,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class OF10FeaturesReplyMessageFactory implements OFDeserializer { private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3; - - private static OF10FeaturesReplyMessageFactory instance; - private OF10FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new OF10FeaturesReplyMessageFactory(); - } - return instance; - } - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { + public GetFeaturesOutput deserialize(ByteBuf rawMessage) { GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(datapathId); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java index dad45419..32e09c4f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java @@ -12,10 +12,13 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder; @@ -23,34 +26,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * Translates FlowRemoved messages (OpenFlow v1.0) * @author michal.polkorab */ -public class OF10FlowRemovedMessageFactory implements OFDeserializer { +public class OF10FlowRemovedMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1; private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2; - - - private static OF10FlowRemovedMessageFactory instance; - - private OF10FlowRemovedMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FlowRemovedMessageFactory getInstance(){ - if(instance == null){ - instance = new OF10FlowRemovedMessageFactory(); - } - return instance; - } + private DeserializerRegistry registry; @Override - public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) { + public FlowRemovedMessage deserialize(ByteBuf rawMessage) { FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); - builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage)); + OFDeserializer matchDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); + builder.setMatchV10(matchDeserializer.deserialize(rawMessage)); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); @@ -70,5 +60,8 @@ public class OF10FlowRemovedMessageFactory implements OFDeserializer { + + @Override + public GetConfigOutput deserialize(ByteBuf rawMessage) { + GetConfigOutputBuilder builder = new GetConfigOutputBuilder(); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setFlags(SwitchConfigFlag.forValue(rawMessage.readUnsignedShort())); + builder.setMissSendLen(rawMessage.readUnsignedShort()); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java index cefb7f1a..a71dddbc 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder; @@ -19,27 +20,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab */ public class OF10HelloMessageFactory implements OFDeserializer { - -private static OF10HelloMessageFactory instance; - - private OF10HelloMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10HelloMessageFactory getInstance() { - if (instance == null) { - instance = new OF10HelloMessageFactory(); - } - return instance; - } - + @Override - public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { + public HelloMessage deserialize(ByteBuf rawMessage) { HelloMessageBuilder builder = new HelloMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); if (rawMessage.readableBytes() > 0) { rawMessage.skipBytes(rawMessage.readableBytes()); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java index 814bd502..8302fa37 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java @@ -10,7 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; @@ -23,26 +24,10 @@ public class OF10PacketInMessageFactory implements OFDeserializer { +public class OF10StatsReplyMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { private static final int DESC_STR_LEN = 256; private static final int SERIAL_NUM_LEN = 32; @@ -70,27 +76,12 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); @@ -152,7 +143,9 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer matchDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); + flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input)); flowStatsBuilder.setDurationSec(input.readUnsignedInt()); flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); flowStatsBuilder.setPriority(input.readUnsignedShort()); @@ -168,8 +161,11 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer deserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class)); + List actions = DecodingUtils.deserializeList(length - LENGTH_OF_FLOW_STATS, + input, deserializer); + flowStatsBuilder.setAction(actions); flowStatsList.add(flowStatsBuilder.build()); } flowBuilder.setFlowStats(flowStatsList); @@ -308,4 +304,9 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer { - -private static OF10VendorMessageFactory instance; - - private OF10VendorMessageFactory() { - //singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10VendorMessageFactory getInstance(){ - if (instance == null){ - instance = new OF10VendorMessageFactory(); - } - return instance; - } - - @Override - public ExperimenterMessage bufferToMessage(ByteBuf rawMessage, short version) { - ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setExperimenter(rawMessage.readUnsignedInt()); - int remainingBytes = rawMessage.readableBytes(); - if (remainingBytes > 0) { - builder.setData(rawMessage.readBytes(remainingBytes).array()); - } - return builder.build(); - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java index d9f29963..819e1568 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java @@ -12,11 +12,14 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; @@ -25,29 +28,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab * @author timotej.kubas */ -public class PacketInMessageFactory implements OFDeserializer { +public class PacketInMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { - private static PacketInMessageFactory instance; private static final byte PADDING_IN_PACKET_IN_HEADER = 2; - - private PacketInMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static synchronized PacketInMessageFactory getInstance(){ - if(instance == null){ - instance = new PacketInMessageFactory(); - } - return instance; - } + private DeserializerRegistry registry; @Override - public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) { + public PacketInMessage deserialize(ByteBuf rawMessage) { PacketInMessageBuilder builder = new PacketInMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setTotalLen(rawMessage.readUnsignedShort()); @@ -56,9 +46,16 @@ public class PacketInMessageFactory implements OFDeserializer { byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); - builder.setMatch(MatchDeserializer.createMatch(rawMessage)); + OFDeserializer matchDeserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); + builder.setMatch(matchDeserializer.deserialize(rawMessage)); rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); return builder.build(); } + + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java index cb046947..80c6d27c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java @@ -10,7 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; @@ -28,29 +28,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class PortStatusMessageFactory implements OFDeserializer { - private static PortStatusMessageFactory instance; private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4; private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2; - - private PortStatusMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static synchronized PortStatusMessageFactory getInstance(){ - if(instance == null){ - instance = new PortStatusMessageFactory(); - } - return instance; - } - + @Override - public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) { + public PortStatusMessage deserialize(ByteBuf rawMessage) { PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte())); rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER); @@ -107,5 +92,4 @@ public class PortStatusMessageFactory implements OFDeserializer{ - private static RoleReplyMessageFactory instance; + private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4; - - private RoleReplyMessageFactory() { - // singleton - } - - /** - * - * @return singleton factory - */ - public static synchronized RoleReplyMessageFactory getInstance(){ - if(instance == null){ - instance = new RoleReplyMessageFactory(); - } - return instance; - } @Override - public RoleRequestOutput bufferToMessage(ByteBuf rawMessage, short version) { + public RoleRequestOutput deserialize(ByteBuf rawMessage) { RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt())); rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv4AddressDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv4AddressDeserializer.java new file mode 100644 index 00000000..7e19d9c8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv4AddressDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +import com.google.common.base.Joiner; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmIpv4AddressDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpv4AddressAugmentation(builder, input); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + return builder.build(); + } + + private static void addIpv4AddressAugmentation(MatchEntriesBuilder builder, ByteBuf input) { + Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + groups.add(Short.toString(input.readUnsignedByte())); + } + Joiner joiner = Joiner.on("."); + ipv4AddressBuilder.setIpv4Address(new Ipv4Address(joiner.join(groups))); + builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv6AddressDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv6AddressDeserializer.java new file mode 100644 index 00000000..bd9f3b8b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmIpv6AddressDeserializer.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import java.util.ArrayList; +import java.util.List; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +import com.google.common.base.Joiner; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmIpv6AddressDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpv6AddressAugmentation(builder, input); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, + EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } + return builder.build(); + } + + private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf input) { + Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) { + groups.add(String.format("%04X", input.readUnsignedShort())); + } + Joiner joiner = Joiner.on(":"); + ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups))); + builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMacAddressDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMacAddressDeserializer.java new file mode 100644 index 00000000..58b431bf --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMacAddressDeserializer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmMacAddressDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addMacAddressAugmentation(builder, input); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.MAC_ADDRESS_LENGTH); + } + return builder.build(); + } + + private static void addMacAddressAugmentation(MatchEntriesBuilder builder, ByteBuf input) { + MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder(); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + input.readBytes(address); + macAddress.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); + builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMatchEntryDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMatchEntryDeserializer.java new file mode 100644 index 00000000..99c0f8cd --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMatchEntryDeserializer.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer { + + @Override + public MatchEntries deserializeHeader(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + return builder.build(); + } + + /** + * @return oxm_field class + */ + protected abstract Class getOxmField(); + + /** + * @return oxm_class class + */ + protected abstract Class getOxmClass(); + + /** + * Prepares match entry header - sets oxm_class, oxm_field, hasMask + * + sets the buffer.readerIndex() to the end of match entry + * - where augmentation starts + * @param oxm_class oxm class type + * @param oxm_field oxm field type + * @param input input bytebuf + * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation + */ + protected MatchEntriesBuilder processHeader(Class oxm_class, + Class oxm_field, ByteBuf input) { + MatchEntriesBuilder builder = new MatchEntriesBuilder(); + builder.setOxmClass(oxm_class); + // skip oxm_class (provided) + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + builder.setOxmMatchField(oxm_field); + boolean hasMask = (input.readUnsignedByte() & 1) != 0; + builder.setHasMask(hasMask); + // skip match entry length - not needed + input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + return builder; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMetadataDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMetadataDeserializer.java new file mode 100644 index 00000000..abf757f8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmMetadataDeserializer.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmMetadataDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addMetadataAugmentation(builder, input); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + return builder.build(); + } + + private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf input) { + MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder(); + byte[] metadataBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + input.readBytes(metadataBytes); + metadata.setMetadata(metadataBytes); + builder.addAugmentation(MetadataMatchEntry.class, metadata.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortDeserializer.java new file mode 100644 index 00000000..43203006 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortDeserializer.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmPortDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addPortAugmentation(builder, input); + return builder.build(); + } + + private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf input) { + PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); + portBuilder.setPort(new PortNumber(input.readUnsignedShort())); + builder.addAugmentation(PortMatchEntry.class, portBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortNumberDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortNumberDeserializer.java new file mode 100644 index 00000000..bd88623c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/AbstractOxmPortNumberDeserializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public abstract class AbstractOxmPortNumberDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder(); + port.setPortNumber(new PortNumber(input.readUnsignedInt())); + builder.addAugmentation(PortNumberMatchEntry.class, port.build()); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpOpDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpOpDeserializer.java new file mode 100644 index 00000000..dc01fbc8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpOpDeserializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmArpOpDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addArpOpAugmentation(input, builder); + return builder.build(); + } + + private static void addArpOpAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder(); + opcodeBuilder.setOpCode(input.readUnsignedShort()); + builder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build()); + } + + @Override + protected Class getOxmField() { + return ArpOp.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpShaDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpShaDeserializer.java new file mode 100644 index 00000000..a4f97508 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpShaDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmArpShaDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return ArpSha.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpSpaDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpSpaDeserializer.java new file mode 100644 index 00000000..8c750fec --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpSpaDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmArpSpaDeserializer extends AbstractOxmIpv4AddressDeserializer { + + @Override + protected Class getOxmField() { + return ArpSpa.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpThaDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpThaDeserializer.java new file mode 100644 index 00000000..c3c7771e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpThaDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmArpThaDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return ArpTha.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpTpaDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpTpaDeserializer.java new file mode 100644 index 00000000..a8039f56 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmArpTpaDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmArpTpaDeserializer extends AbstractOxmIpv4AddressDeserializer { + + @Override + protected Class getOxmField() { + return ArpTpa.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthDstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthDstDeserializer.java new file mode 100644 index 00000000..bb80686b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthDstDeserializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmEthDstDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return EthDst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthSrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthSrcDeserializer.java new file mode 100644 index 00000000..216b7bf3 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthSrcDeserializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmEthSrcDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return EthSrc.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthTypeDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthTypeDeserializer.java new file mode 100644 index 00000000..e1c4eb74 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmEthTypeDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmEthTypeDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addEthTypeAugmentation(input, builder); + return builder.build(); + } + + private static void addEthTypeAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder(); + ethertypeBuilder.setEthType(new EtherType(input.readUnsignedShort())); + builder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build()); + } + + @Override + protected Class getOxmField() { + return EthType.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4CodeDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4CodeDeserializer.java new file mode 100644 index 00000000..a52885a5 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4CodeDeserializer.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv4CodeDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIcmpv4CodeAugmentation(input, builder); + return builder.build(); + } + + private static void addIcmpv4CodeAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); + icmpv4CodeBuilder.setIcmpv4Code(input.readUnsignedByte()); + builder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); + } + + @Override + protected Class getOxmField() { + return Icmpv4Code.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4TypeDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4TypeDeserializer.java new file mode 100644 index 00000000..5b3c3dbe --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv4TypeDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv4TypeDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIcmpv4TypeAugmentation(input, builder); + return builder.build(); + } + + private static void addIcmpv4TypeAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder(); + icmpv4TypeBuilder.setIcmpv4Type(input.readUnsignedByte()); + builder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build()); + } + + @Override + protected Class getOxmField() { + return Icmpv4Type.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6CodeDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6CodeDeserializer.java new file mode 100644 index 00000000..2c3bd5fc --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6CodeDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv6CodeDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIcmpv6CodeAugmentation(input, builder); + return builder.build(); + } + + private static void addIcmpv6CodeAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); + icmpv6CodeBuilder.setIcmpv6Code(input.readUnsignedByte()); + builder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); + } + + @Override + protected Class getOxmField() { + return Icmpv6Code.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6TypeDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6TypeDeserializer.java new file mode 100644 index 00000000..5d47823c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIcmpv6TypeDeserializer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv6TypeDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); + icmpv6TypeBuilder.setIcmpv6Type(input.readUnsignedByte()); + builder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); + return builder.build(); + } + + @Override + protected Class getOxmField() { + return Icmpv6Type.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPhyPortDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPhyPortDeserializer.java new file mode 100644 index 00000000..dfb050a1 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPhyPortDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmInPhyPortDeserializer extends AbstractOxmPortNumberDeserializer { + + @Override + protected Class getOxmField() { + return InPhyPort.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPortDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPortDeserializer.java new file mode 100644 index 00000000..3bc97ee8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmInPortDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmInPortDeserializer extends AbstractOxmPortNumberDeserializer { + + @Override + protected Class getOxmField() { + return InPort.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpDscpDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpDscpDeserializer.java new file mode 100644 index 00000000..decbe54f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpDscpDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; + +/** + * @author michal.polkorab + * + */ +public class OxmIpDscpDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpDscpAugmentation(input, builder); + return builder.build(); + } + + private static void addIpDscpAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); + dscpBuilder.setDscp(new Dscp(input.readUnsignedByte())); + builder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); + } + + @Override + protected Class getOxmField() { + return IpDscp.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpEcnDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpEcnDeserializer.java new file mode 100644 index 00000000..de06e65f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpEcnDeserializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIpEcnDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpEcnAugmentation(input, builder); + return builder.build(); + } + + private static void addIpEcnAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); + ecnBuilder.setEcn(input.readUnsignedByte()); + builder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); + } + + @Override + protected Class getOxmField() { + return IpEcn.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpProtoDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpProtoDeserializer.java new file mode 100644 index 00000000..52314f5f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpProtoDeserializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIpProtoDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpProtoAugmentation(input, builder); + return builder.build(); + } + + private static void addIpProtoAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder(); + protoNumberBuilder.setProtocolNumber(input.readUnsignedByte()); + builder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build()); + } + + @Override + protected Class getOxmField() { + return IpProto.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4DstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4DstDeserializer.java new file mode 100644 index 00000000..98b924d8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4DstDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv4DstDeserializer extends AbstractOxmIpv4AddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv4Dst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4SrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4SrcDeserializer.java new file mode 100644 index 00000000..e24720e0 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv4SrcDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv4SrcDeserializer extends AbstractOxmIpv4AddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv4Src.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6DstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6DstDeserializer.java new file mode 100644 index 00000000..e4599a0e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6DstDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6DstDeserializer extends AbstractOxmIpv6AddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv6Dst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6ExtHdrDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6ExtHdrDeserializer.java new file mode 100644 index 00000000..eb8b6d73 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6ExtHdrDeserializer.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6ExtHdrDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpv6ExtHdrAugmentation(input, builder); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } + return builder.build(); + } + + private static void addIpv6ExtHdrAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); + int bitmap = input.readUnsignedShort(); + final Boolean NONEXT = ((bitmap) & (1<<0)) != 0; + final Boolean ESP = ((bitmap) & (1<<1)) != 0; + final Boolean AUTH = ((bitmap) & (1<<2)) != 0; + final Boolean DEST = ((bitmap) & (1<<3)) != 0; + final Boolean FRAG = ((bitmap) & (1<<4)) != 0; + final Boolean ROUTER = ((bitmap) & (1<<5)) != 0; + final Boolean HOP = ((bitmap) & (1<<6)) != 0; + final Boolean UNREP = ((bitmap) & (1<<7)) != 0; + final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0; + pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ)); + builder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); + } + + @Override + protected Class getOxmField() { + return Ipv6Exthdr.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6FlabelDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6FlabelDeserializer.java new file mode 100644 index 00000000..3b96a6fe --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6FlabelDeserializer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6FlabelDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addIpv6FlabelAugmentation(input, builder); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + return builder.build(); + } + + private static void addIpv6FlabelAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder(); + ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(input.readUnsignedInt())); + builder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build()); + } + + @Override + protected Class getOxmField() { + return Ipv6Flabel.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdSllDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdSllDeserializer.java new file mode 100644 index 00000000..053b36fd --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdSllDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdSllDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv6NdSll.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTargetDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTargetDeserializer.java new file mode 100644 index 00000000..0a47593b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTargetDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdTargetDeserializer extends AbstractOxmIpv6AddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv6NdTarget.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTllDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTllDeserializer.java new file mode 100644 index 00000000..ea7d4c62 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6NdTllDeserializer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdTllDeserializer extends AbstractOxmMacAddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv6NdTll.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6SrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6SrcDeserializer.java new file mode 100644 index 00000000..8135b81e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmIpv6SrcDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6SrcDeserializer extends AbstractOxmIpv6AddressDeserializer { + + @Override + protected Class getOxmField() { + return Ipv6Src.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMaskDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMaskDeserializer.java new file mode 100644 index 00000000..d4246fd2 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMaskDeserializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmMaskDeserializer { + + /** + * Appends mask to match entry (match entry builder) + * @param builder builder which the mask will append to + * @param input input ByteBuf + * @param matchEntryLength mask length + */ + public static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf input, + int matchEntryLength) { + MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); + byte[] mask = new byte[matchEntryLength]; + input.readBytes(mask); + maskBuilder.setMask(mask); + builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMetadataDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMetadataDeserializer.java new file mode 100644 index 00000000..7bbc6ebb --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMetadataDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; + +/** + * @author michal.polkorab + * + */ +public class OxmMetadataDeserializer extends AbstractOxmMetadataDeserializer { + + @Override + protected Class getOxmField() { + return Metadata.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsBosDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsBosDeserializer.java new file mode 100644 index 00000000..ad39e04e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsBosDeserializer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsBosDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addMplsBosDeserializer(input, builder); + return builder.build(); + } + + + private static void addMplsBosDeserializer(ByteBuf input, + MatchEntriesBuilder builder) { + BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); + if (input.readUnsignedByte() != 0) { + bosBuilder.setBos(true); + } else { + bosBuilder.setBos(false); + } + builder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); + } + + @Override + protected Class getOxmField() { + return MplsBos.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsLabelDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsLabelDeserializer.java new file mode 100644 index 00000000..794f6ea7 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsLabelDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsLabelDeserializer extends AbstractOxmMatchEntryDeserializer +implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addMplsLabelAugmentation(input, builder); + return builder.build(); + } + + private static void addMplsLabelAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder(); + mplsLabelBuilder.setMplsLabel(input.readUnsignedInt()); + builder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build()); + } + + @Override + protected Class getOxmField() { + return MplsLabel.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsTcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsTcDeserializer.java new file mode 100644 index 00000000..22ed95ed --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmMplsTcDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsTcDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addMplsTcAugmentation(input, builder); + return builder.build(); + } + + private static void addMplsTcAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); + tcBuilder.setTc(input.readUnsignedByte()); + builder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); + } + + @Override + protected Class getOxmField() { + return MplsTc.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmPbbIsidDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmPbbIsidDeserializer.java new file mode 100644 index 00000000..1dfdd711 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmPbbIsidDeserializer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmPbbIsidDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addPbbIsidAugmentation(input, builder); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_3_BYTES); + } + return builder.build(); + } + + private static void addPbbIsidAugmentation(ByteBuf input, + MatchEntriesBuilder builder) { + IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); + Integer isid = input.readUnsignedMedium(); + isidBuilder.setIsid(isid.longValue()); + builder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); + } + + @Override + protected Class getOxmField() { + return PbbIsid.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpDstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpDstDeserializer.java new file mode 100644 index 00000000..074eaf3d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpDstDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; + +/** + * @author michal.polkorab + * + */ +public class OxmSctpDstDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return SctpDst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpSrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpSrcDeserializer.java new file mode 100644 index 00000000..ea5e3b4f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmSctpSrcDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; + +/** + * @author michal.polkorab + * + */ +public class OxmSctpSrcDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return SctpSrc.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpDstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpDstDeserializer.java new file mode 100644 index 00000000..cb8faba9 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpDstDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; + +/** + * @author michal.polkorab + * + */ +public class OxmTcpDstDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return TcpDst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpSrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpSrcDeserializer.java new file mode 100644 index 00000000..9d357c94 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTcpSrcDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; + +/** + * @author michal.polkorab + * + */ +public class OxmTcpSrcDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return TcpSrc.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTunnelIdDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTunnelIdDeserializer.java new file mode 100644 index 00000000..0947e513 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmTunnelIdDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; + +/** + * @author michal.polkorab + * + */ +public class OxmTunnelIdDeserializer extends AbstractOxmMetadataDeserializer { + + @Override + protected Class getOxmField() { + return TunnelId.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpDstDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpDstDeserializer.java new file mode 100644 index 00000000..f95e4b5c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpDstDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; + +/** + * @author michal.polkorab + * + */ +public class OxmUdpDstDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return UdpDst.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpSrcDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpSrcDeserializer.java new file mode 100644 index 00000000..6690268b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmUdpSrcDeserializer.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; + +/** + * @author michal.polkorab + * + */ +public class OxmUdpSrcDeserializer extends AbstractOxmPortDeserializer { + + @Override + protected Class getOxmField() { + return UdpSrc.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanPcpDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanPcpDeserializer.java new file mode 100644 index 00000000..35bd4201 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanPcpDeserializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmVlanPcpDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addVlanPcpAugmentation(input, builder); + return builder.build(); + } + + private static void addVlanPcpAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder(); + vlanPcpBuilder.setVlanPcp(input.readUnsignedByte()); + builder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build()); + } + + @Override + protected Class getOxmField() { + return VlanPcp.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanVidDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanVidDeserializer.java new file mode 100644 index 00000000..e5156fe9 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/match/OxmVlanVidDeserializer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmVlanVidDeserializer extends AbstractOxmMatchEntryDeserializer + implements OFDeserializer { + + @Override + public MatchEntries deserialize(ByteBuf input) { + MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input); + addVlanVidAugmentation(input, builder); + if (builder.isHasMask()) { + OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } + return builder.build(); + } + + private static void addVlanVidAugmentation(ByteBuf input, MatchEntriesBuilder builder) { + VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder(); + int vidEntryValue = input.readUnsignedShort(); + vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit + vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit + builder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build()); + } + + @Override + protected Class getOxmField() { + return VlanVid.class; + } + + @Override + protected Class getOxmClass() { + return OpenflowBasicClass.class; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java index 42e6a74d..16e9808f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java @@ -13,10 +13,15 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; @@ -53,176 +58,161 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; /** * Deserializes ofp_actions (OpenFlow v1.3) * @author timotej.kubas * @author michal.polkorab */ -public class ActionsDeserializer { +public class ActionsDeserializer implements OFDeserializer, + HeaderDeserializer, DeserializerRegistryInjector { - private static final byte ACTION_HEADER_LENGTH = 4; private static final byte PADDING_IN_ACTIONS_HEADER = 4; private static final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6; private static final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3; private static final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2; private static final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3; - private static final byte EXPERIMENTER_ACTION_HEADER_LENGTH = 8; - - /** - * Creates list of actions (OpenFlow v1.3) - * @param input input ByteBuf - * @param actionsLength length of buckets - * @return ActionsList - */ - public static List createActions(ByteBuf input, int actionsLength) { - List actions = new ArrayList<>(); - int length = 0; - while (length < actionsLength) { - int type = input.readUnsignedShort(); - int currentActionLength = input.readUnsignedShort(); - ActionBuilder actionBuilder = new ActionBuilder(); - switch(type) { - case 0: - actions.add(createOutputAction(input, actionBuilder)); - break; - case 11: - actions.add(createCopyTtlOutAction(input, actionBuilder)); - break; - case 12: - actions.add(createCopyTtlInAction(input, actionBuilder)); - break; - case 15: - actions.add(createSetMplsTtlAction(input, actionBuilder)); - break; - case 16: - actions.add(createDecMplsTtlOutAction(input, actionBuilder)); - break; - case 17: - actions.add(createPushVlanAction(input, actionBuilder)); - break; - case 18: - actions.add(createPopVlanAction(input, actionBuilder)); - break; - case 19: - actions.add(createPushMplsAction(input, actionBuilder)); - break; - case 20: - actions.add(createPopMplsAction(input, actionBuilder)); - break; - case 21: - actions.add(createSetQueueAction(input, actionBuilder)); - break; - case 22: - actions.add(createGroupAction(input, actionBuilder)); - break; - case 23: - actions.add(createSetNwTtlAction(input, actionBuilder)); - break; - case 24: - actions.add(createDecNwTtlAction(input, actionBuilder)); - break; - case 25: - actions.add(createSetFieldAction(input, actionBuilder, currentActionLength)); - break; - case 26: - actions.add(createPushPbbAction(input, actionBuilder)); - break; - case 27: - actions.add(createPopPbbAction(input, actionBuilder)); - break; - case 0xFFFF: - actions.add(createExperimenterAction(input, actionBuilder, currentActionLength)); - break; - default: - break; - } - length += currentActionLength; - } - return actions; + private DeserializerRegistry registry; + + @Override + public Action deserialize(ByteBuf input) { + Action action = null; + ActionBuilder actionBuilder = new ActionBuilder(); + int type = input.getUnsignedShort(input.readerIndex()); + switch(type) { + case 0: + action = createOutputAction(input, actionBuilder); + break; + case 11: + action = createCopyTtlOutAction(input, actionBuilder); + break; + case 12: + action = createCopyTtlInAction(input, actionBuilder); + break; + case 15: + action = createSetMplsTtlAction(input, actionBuilder); + break; + case 16: + action = createDecMplsTtlOutAction(input, actionBuilder); + break; + case 17: + action = createPushVlanAction(input, actionBuilder); + break; + case 18: + action = createPopVlanAction(input, actionBuilder); + break; + case 19: + action = createPushMplsAction(input, actionBuilder); + break; + case 20: + action = createPopMplsAction(input, actionBuilder); + break; + case 21: + action = createSetQueueAction(input, actionBuilder); + break; + case 22: + action = createGroupAction(input, actionBuilder); + break; + case 23: + action = createSetNwTtlAction(input, actionBuilder); + break; + case 24: + action = createDecNwTtlAction(input, actionBuilder); + break; + case 25: + action = createSetFieldAction(input, actionBuilder); + break; + case 26: + action = createPushPbbAction(input, actionBuilder); + break; + case 27: + action = createPopPbbAction(input, actionBuilder); + break; + case 0xFFFF: + OFDeserializer expDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0xFFFF, ExperimenterAction.class)); + ExperimenterAction expAction = expDeserializer.deserialize(input); + actionBuilder.addAugmentation(ExperimenterAction.class, expAction); + break; + default: + break; + } + return action; } - /** - * Creates action ids - actions without values (OpenFlow v1.3) - * @param input input ByteBuf - * @param actionsLength length of actions - * @return ActionsList - */ - public static List createActionIds(ByteBuf input, int actionsLength) { - List actionsList = new ArrayList<>(); - int length = 0; + @Override + public Action deserializeHeader(ByteBuf input) { ActionBuilder builder; - while (length < actionsLength) { - builder = new ActionBuilder(); - int type = input.readUnsignedShort(); - int currentActionLength = input.readUnsignedShort(); - switch(type) { - case 0: - builder.setType(Output.class); - break; - case 11: - builder.setType(CopyTtlOut.class); - break; - case 12: - builder.setType(CopyTtlIn.class); - break; - case 15: - builder.setType(SetMplsTtl.class); - break; - case 16: - builder.setType(DecMplsTtl.class); - break; - case 17: - builder.setType(PushVlan.class); - break; - case 18: - builder.setType(PopVlan.class); - break; - case 19: - builder.setType(PushMpls.class); - break; - case 20: - builder.setType(PopMpls.class); - break; - case 21: - builder.setType(SetQueue.class); - break; - case 22: - builder.setType(Group.class); - break; - case 23: - builder.setType(SetNwTtl.class); - break; - case 24: - builder.setType(DecNwTtl.class); - break; - case 25: - builder.setType(SetField.class); - break; - case 26: - builder.setType(PushPbb.class); - break; - case 27: - builder.setType(PopPbb.class); - break; - case 0xFFFF: - builder.setType(Experimenter.class); - ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); - experimenter.setExperimenter(input.readUnsignedInt()); - builder.addAugmentation(ExperimenterAction.class, experimenter.build()); - break; - default: - break; - } - actionsList.add(builder.build()); - length += currentActionLength; - } - return actionsList; + builder = new ActionBuilder(); + int type = input.readUnsignedShort(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + switch(type) { + case 0: + builder.setType(Output.class); + break; + case 11: + builder.setType(CopyTtlOut.class); + break; + case 12: + builder.setType(CopyTtlIn.class); + break; + case 15: + builder.setType(SetMplsTtl.class); + break; + case 16: + builder.setType(DecMplsTtl.class); + break; + case 17: + builder.setType(PushVlan.class); + break; + case 18: + builder.setType(PopVlan.class); + break; + case 19: + builder.setType(PushMpls.class); + break; + case 20: + builder.setType(PopMpls.class); + break; + case 21: + builder.setType(SetQueue.class); + break; + case 22: + builder.setType(Group.class); + break; + case 23: + builder.setType(SetNwTtl.class); + break; + case 24: + builder.setType(DecNwTtl.class); + break; + case 25: + builder.setType(SetField.class); + break; + case 26: + builder.setType(PushPbb.class); + break; + case 27: + builder.setType(PopPbb.class); + break; + case 0xFFFF: + HeaderDeserializer expDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0xFFFF, ExperimenterAction.class)); + ExperimenterAction expAction = expDeserializer.deserializeHeader(input); + builder.setType(Experimenter.class); + builder.addAugmentation(ExperimenterAction.class, expAction); + break; + default: + break; + } + return builder.build(); } private static Action createEmptyHeader(Class action, ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(action); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); in.skipBytes(PADDING_IN_ACTIONS_HEADER); return actionBuilder.build(); } @@ -253,6 +243,7 @@ public class ActionsDeserializer { private static Action createOutputAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(Output.class); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); PortActionBuilder port = new PortActionBuilder(); port.setPort(new PortNumber(in.readUnsignedInt())); actionBuilder.addAugmentation(PortAction.class, port.build()); @@ -265,6 +256,7 @@ public class ActionsDeserializer { private static Action createSetMplsTtlAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetMplsTtl.class); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); mplsTtl.setMplsTtl(in.readUnsignedByte()); actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); @@ -275,6 +267,7 @@ public class ActionsDeserializer { private static Action createPushAction(Class action, ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(action); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); EthertypeActionBuilder etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(in.readUnsignedShort())); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); @@ -300,6 +293,7 @@ public class ActionsDeserializer { private static Action createSetQueueAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetQueue.class); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); QueueIdActionBuilder queueId = new QueueIdActionBuilder(); queueId.setQueueId(in.readUnsignedInt()); actionBuilder.addAugmentation(QueueIdAction.class, queueId.build()); @@ -308,28 +302,16 @@ public class ActionsDeserializer { private static Action createGroupAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(Group.class); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); GroupIdActionBuilder group = new GroupIdActionBuilder(); group.setGroupId(in.readUnsignedInt()); actionBuilder.addAugmentation(GroupIdAction.class, group.build()); return actionBuilder.build(); } - - private static Action createExperimenterAction(ByteBuf in, ActionBuilder actionBuilder, int actionLength) { - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); - experimenter.setExperimenter(in.readUnsignedInt()); - int dataLength = actionLength - EXPERIMENTER_ACTION_HEADER_LENGTH; - if (dataLength > 0) { - byte[] data = new byte[dataLength]; - in.readBytes(data); - experimenter.setData(data); - } - actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); - return actionBuilder.build(); - } - + private static Action createSetNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetNwTtl.class); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); nwTtl.setNwTtl(in.readUnsignedByte()); actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); @@ -337,11 +319,31 @@ public class ActionsDeserializer { return actionBuilder.build(); } - private static Action createSetFieldAction(ByteBuf in, ActionBuilder actionBuilder, int actionLength) { + private Action createSetFieldAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetField.class); + int startIndex = in.readerIndex(); + in.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES); OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); - matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH)); + int oxmClass = in.getUnsignedShort(in.readerIndex()); + // get oxm_field & hasMask byte and extract the field value + int oxmField = in.getUnsignedByte(in.readerIndex() + + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1; + OFDeserializer matchDeserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass, + oxmField, MatchEntries.class)); + List entry = new ArrayList<>(); + entry.add(matchDeserializer.deserialize(in)); + matchEntries.setMatchEntries(entry); actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); + int paddingRemainder = (in.readerIndex() - startIndex) % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + in.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } return actionBuilder.build(); } + + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/DecodingUtils.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/DecodingUtils.java new file mode 100644 index 00000000..1f032950 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/DecodingUtils.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * + */ +public abstract class DecodingUtils { + + /** + * Deserializes lists of actions or instructions + * @param length length of list (in bytes) + * @param input input bytebuf + * @param deserializer + * false in case of whole body deserialization + * @return List of actions or instructions + */ + @SuppressWarnings("unchecked") + public static List deserializeList(int length, ByteBuf input, + OFGeneralDeserializer deserializer) { + List list = new ArrayList<>(); + int startIndex = input.readerIndex(); + OFDeserializer actionsDeserializer = (OFDeserializer) deserializer; + while ((input.readerIndex() - startIndex) < length) { + list.add(actionsDeserializer.deserialize(input)); + } + return list; + } + + /** + * Deserializes action or instruction headers + * @param length length of list (in bytes) + * @param input input bytebuf + * @param deserializer + * false in case of whole body deserialization + * @return List of action or instruction headers + */ + @SuppressWarnings("unchecked") + public static List deserializeHeaders(int length, ByteBuf input, + OFGeneralDeserializer deserializer) { + List list = new ArrayList<>(); + int startIndex = input.readerIndex(); + HeaderDeserializer instructionsDeserializer = (HeaderDeserializer) deserializer; + while ((input.readerIndex() - startIndex) < length) { + list.add(instructionsDeserializer.deserializeHeader(input)); + } + return list; + } + + /** + * Deserializes match entry headers + * @param length length of list (in bytes) + * @param input input bytebuf + * @param registry registry with deserializers + * false in case of whole body deserialization + * @return List of match entry headers + */ + public static List deserializeMatchEntryHeaders(int length, ByteBuf input, + DeserializerRegistry registry) { + List list = new ArrayList<>(); + int startIndex = input.readerIndex(); + while ((input.readerIndex() - startIndex) < length) { + int oxmClass = input.getUnsignedShort(input.readerIndex()); + int oxmField = input.getUnsignedByte(input.readerIndex() + + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >> 1; + HeaderDeserializer deserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass, + oxmField, MatchEntries.class)); + list.add(deserializer.deserializeHeader(input)); + } + return list; + } + + /** + * Deserializes list of match entries + * @param length length of list (in bytes) + * @param input input bytebuf + * @param registry registry with deserializers + * false in case of whole body deserialization + * @return List of match entries + */ + public static List deserializeMatchEntries(int length, ByteBuf input, + DeserializerRegistry registry) { + List list = new ArrayList<>(); + int startIndex = input.readerIndex(); + while ((input.readerIndex() - startIndex) < length) { + int oxmClass = input.getUnsignedShort(input.readerIndex()); + int oxmField = input.getUnsignedByte(input.readerIndex() + + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >> 1; + OFDeserializer deserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, oxmClass, + oxmField, MatchEntries.class)); + list.add(deserializer.deserialize(input)); + } + return list; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java index 7097b0c9..65631fcd 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java @@ -47,6 +47,9 @@ public abstract class EncodeConstants { /** Length of 3 bytes */ public static final byte SIZE_OF_3_BYTES = 3; + /** Empty (zero) int value */ + public static final int EMPTY_VALUE = 0; + /** OF v1.0 maximal port name length */ public static final byte MAX_PORT_NAME_LENGTH = 16; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java index f678d87f..820c7fa7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java @@ -10,9 +10,13 @@ package org.opendaylight.openflowjava.protocol.impl.util; import io.netty.buffer.ByteBuf; -import java.util.ArrayList; import java.util.List; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; @@ -23,6 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; @@ -38,127 +43,97 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction * @author michal.polkorab * @author timotej.kubas */ -public abstract class InstructionsDeserializer { +public class InstructionsDeserializer implements OFDeserializer, + HeaderDeserializer, DeserializerRegistryInjector { private static final byte WRITE_APPLY_CLEAR_ACTION_LENGTH = 8; - private static final byte EXPERIMENTER_HEADER_LENGTH = 8; private static final byte GOTO_TABLE_PADDING = 3; private static final byte WRITE_METADATA_PADDING = 4; private static final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4; + private DeserializerRegistry registry; - /** - * Creates list of instructions - * @param input - * @param length - * @return list of ofp_instruction - */ - public static List createInstructions(ByteBuf input, int length) { - List instructions = new ArrayList<>(); - if (input.readableBytes() != 0) { - int lengthOfInstructions = length; - while (lengthOfInstructions > 0) { - InstructionBuilder builder = new InstructionBuilder(); - int type = input.readUnsignedShort(); - int instructionLength = input.readUnsignedShort(); - lengthOfInstructions -= instructionLength; - switch (type) { - case 1: - createGotoTableInstruction(builder, input); - break; - case 2: - createMetadataInstruction(builder, input); - break; - case 3: - builder.setType(WriteActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 4: - builder.setType(ApplyActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 5: - builder.setType(ClearActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 6: - builder.setType(Meter.class); - MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder(); - meterBuilder.setMeterId(input.readUnsignedInt()); - builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build()); - break; - case 65535: - builder.setType(Experimenter.class); - ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - int dataLength = instructionLength - EXPERIMENTER_HEADER_LENGTH; - if (dataLength > 0) { - byte[] data = new byte[dataLength]; - input.readBytes(data); - expBuilder.setData(data); - } - builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); - break; - default: - break; - } - instructions.add(builder.build()); - } + @Override + public Instruction deserialize(ByteBuf input) { + InstructionBuilder builder = new InstructionBuilder(); + int type = input.readUnsignedShort(); + switch (type) { + case 1: + createGotoTableInstruction(builder, input); + break; + case 2: + createMetadataInstruction(builder, input); + break; + case 3: + builder.setType(WriteActions.class); + createActionRelatedInstruction(input, builder); + break; + case 4: + builder.setType(ApplyActions.class); + createActionRelatedInstruction(input, builder); + break; + case 5: + builder.setType(ClearActions.class); + createActionRelatedInstruction(input, builder); + break; + case 6: + builder.setType(Meter.class); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder(); + meterBuilder.setMeterId(input.readUnsignedInt()); + builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build()); + break; + case 65535: + builder.setType(Experimenter.class); + OFDeserializer deserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, type, ExperimenterInstruction.class)); + ExperimenterInstruction expInstruction = deserializer.deserialize(input); + builder.addAugmentation(ExperimenterInstruction.class, expInstruction); + break; + default: + break; } - return instructions; + return builder.build(); } - /** - * Creates instruction ids (instructions without values) - * @param input - * @param length - * @return list of ofp_instruction without values - */ - public static List createInstructionIds(ByteBuf input, int length) { - List instructions = new ArrayList<>(); - if (input.readableBytes() != 0) { - int lengthOfInstructions = length; - while (lengthOfInstructions > 0) { - InstructionBuilder builder = new InstructionBuilder(); - int type = input.readUnsignedShort(); - int instructionLength = input.readUnsignedShort(); - lengthOfInstructions -= instructionLength; - switch (type) { - case 1: - builder.setType(GotoTable.class); - break; - case 2: - builder.setType(WriteMetadata.class); - break; - case 3: - builder.setType(WriteActions.class); - break; - case 4: - builder.setType(ApplyActions.class); - break; - case 5: - builder.setType(ClearActions.class); - break; - case 6: - builder.setType(Meter.class); - break; - case 65535: - builder.setType(Experimenter.class); - ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); - break; - default: - break; - } - instructions.add(builder.build()); - } + @Override + public Instruction deserializeHeader(ByteBuf input) { + InstructionBuilder builder = new InstructionBuilder(); + int type = input.readUnsignedShort(); + switch (type) { + case 1: + builder.setType(GotoTable.class); + break; + case 2: + builder.setType(WriteMetadata.class); + break; + case 3: + builder.setType(WriteActions.class); + break; + case 4: + builder.setType(ApplyActions.class); + break; + case 5: + builder.setType(ClearActions.class); + break; + case 6: + builder.setType(Meter.class); + break; + case 65535: + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + break; + default: + break; } - return instructions; + return builder.build(); } private static void createGotoTableInstruction(InstructionBuilder builder, ByteBuf input) { builder.setType(GotoTable.class); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder(); tableBuilder.setTableId(input.readUnsignedByte()); builder.addAugmentation(TableIdInstruction.class, tableBuilder.build()); @@ -167,8 +142,9 @@ public abstract class InstructionsDeserializer { private static void createMetadataInstruction(InstructionBuilder builder, ByteBuf input) { - input.skipBytes(WRITE_METADATA_PADDING); builder.setType(WriteMetadata.class); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + input.skipBytes(WRITE_METADATA_PADDING); MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder(); byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(metadata); @@ -179,12 +155,20 @@ public abstract class InstructionsDeserializer { builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build()); } - private static void createActionRelatedInstruction(ByteBuf input, - InstructionBuilder builder, int actionsLength) { + private void createActionRelatedInstruction(ByteBuf input, InstructionBuilder builder) { + int instructionLength = input.readUnsignedShort(); input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING); ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder(); - actionsBuilder.setAction(ActionsDeserializer.createActions(input, actionsLength)); + OFDeserializer deserializer = registry.getDeserializer(new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Action.class)); + List actions = DecodingUtils.deserializeList( + instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH, input, deserializer); + actionsBuilder.setAction(actions); builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build()); } + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java index fe05bf92..0128c997 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java @@ -10,135 +10,30 @@ package org.opendaylight.openflowjava.protocol.impl.util; import io.netty.buffer.ByteBuf; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; - -import com.google.common.base.Joiner; /** * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures * @author timotej.kubas * @author michal.polkorab */ -public abstract class MatchDeserializer { +public class MatchDeserializer implements OFDeserializer, + DeserializerRegistryInjector { + + private DeserializerRegistry registry; - /** - * Creates match - * @param in input ByteBuf - * @return ofp_match (OpenFlow v1.3) - */ - public static Match createMatch(ByteBuf in) { - if (in.readableBytes() > 0) { + @Override + public Match deserialize(ByteBuf input) { + if (input.readableBytes() > 0) { MatchBuilder builder = new MatchBuilder(); - int type = in.readUnsignedShort(); - int length = in.readUnsignedShort(); + int type = input.readUnsignedShort(); + int length = input.readUnsignedShort(); switch (type) { case 0: builder.setType(StandardMatchType.class); @@ -149,402 +44,19 @@ public abstract class MatchDeserializer { default: break; } - builder.setMatchEntries(createMatchEntries(in, length - 2 * (EncodeConstants.SIZE_OF_SHORT_IN_BYTES))); + builder.setMatchEntries(DecodingUtils.deserializeMatchEntries( + length - 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES, input, registry)); int paddingRemainder = length % EncodeConstants.PADDING; if (paddingRemainder != 0) { - in.skipBytes(EncodeConstants.PADDING - paddingRemainder); + input.skipBytes(EncodeConstants.PADDING - paddingRemainder); } return builder.build(); } return null; } - /** - * Deserializes single match entry (oxm_field) - * @param in input ByteBuf - * @param matchLength length of match entry - * @return MatchEntriesList list containing one match entry - */ - public static List createMatchEntry(ByteBuf in, int matchLength) { - return createMatchEntriesInternal(in, matchLength, true); - } - - /** - * @param in input ByteBuf - * @param matchLength length of match entries - * @return MatchEntriesList list of match entries - */ - public static List createMatchEntries(ByteBuf in, int matchLength) { - return createMatchEntriesInternal(in, matchLength, false); - } - - private static List createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) { - List matchEntriesList = new ArrayList<>(); - int currLength = 0; - while(currLength < matchLength) { - MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); - switch (in.readUnsignedShort()) { - case 0x0000: - matchEntriesBuilder.setOxmClass(Nxm0Class.class); - break; - case 0x0001: - matchEntriesBuilder.setOxmClass(Nxm1Class.class); - break; - case 0x8000: - matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); - break; - case 0xFFFF: - matchEntriesBuilder.setOxmClass(ExperimenterClass.class); - break; - default: - break; - } - - int fieldAndMask = in.readUnsignedByte(); - boolean hasMask = (fieldAndMask & 1) != 0; - matchEntriesBuilder.setHasMask(hasMask); - int matchField = fieldAndMask >> 1; - int matchEntryLength = in.readUnsignedByte(); - currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES + - (2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES) + matchEntryLength; - - switch(matchField) { - case 0: - matchEntriesBuilder.setOxmMatchField(InPort.class); - PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder(); - port.setPortNumber(new PortNumber(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build()); - break; - case 1: - matchEntriesBuilder.setOxmMatchField(InPhyPort.class); - PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder(); - phyPort.setPortNumber(new PortNumber(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build()); - break; - case 2: - matchEntriesBuilder.setOxmMatchField(Metadata.class); - addMetadataAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 3: - matchEntriesBuilder.setOxmMatchField(EthDst.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH); - } - break; - case 4: - matchEntriesBuilder.setOxmMatchField(EthSrc.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH); - } - break; - case 5: - matchEntriesBuilder.setOxmMatchField(EthType.class); - EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder(); - ethertypeBuilder.setEthType(new EtherType(in.readUnsignedShort())); - matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build()); - break; - case 6: - matchEntriesBuilder.setOxmMatchField(VlanVid.class); - VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder(); - int vidEntryValue = in.readUnsignedShort(); - vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit - vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit - matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - break; - case 7: - matchEntriesBuilder.setOxmMatchField(VlanPcp.class); - VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder(); - vlanPcpBuilder.setVlanPcp(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build()); - break; - case 8: - matchEntriesBuilder.setOxmMatchField(IpDscp.class); - DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); - dscpBuilder.setDscp(new Dscp(in.readUnsignedByte())); - matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); - break; - case 9: - matchEntriesBuilder.setOxmMatchField(IpEcn.class); - EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); - ecnBuilder.setEcn(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); - break; - case 10: - matchEntriesBuilder.setOxmMatchField(IpProto.class); - ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder(); - protoNumberBuilder.setProtocolNumber(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build()); - break; - case 11: - matchEntriesBuilder.setOxmMatchField(Ipv4Src.class); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 12: - matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 13: - matchEntriesBuilder.setOxmMatchField(TcpSrc.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 14: - matchEntriesBuilder.setOxmMatchField(TcpDst.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 15: - matchEntriesBuilder.setOxmMatchField(UdpSrc.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 16: - matchEntriesBuilder.setOxmMatchField(UdpDst.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 17: - matchEntriesBuilder.setOxmMatchField(SctpSrc.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 18: - matchEntriesBuilder.setOxmMatchField(SctpDst.class); - addPortAugmentation(matchEntriesBuilder, in); - break; - case 19: - matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class); - Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder(); - icmpv4TypeBuilder.setIcmpv4Type(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build()); - break; - case 20: - matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class); - Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); - icmpv4CodeBuilder.setIcmpv4Code(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); - break; - case 21: - matchEntriesBuilder.setOxmMatchField(ArpOp.class); - OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder(); - opcodeBuilder.setOpCode(in.readUnsignedShort()); - matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build()); - break; - case 22: - matchEntriesBuilder.setOxmMatchField(ArpSpa.class); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 23: - matchEntriesBuilder.setOxmMatchField(ArpTpa.class); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 24: - matchEntriesBuilder.setOxmMatchField(ArpSha.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH); - } - break; - case 25: - matchEntriesBuilder.setOxmMatchField(ArpTha.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH); - } - break; - case 26: - matchEntriesBuilder.setOxmMatchField(Ipv6Src.class); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } - break; - case 27: - matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } - break; - case 28: - matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class); - Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder(); - ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 29: - matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class); - Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); - icmpv6TypeBuilder.setIcmpv6Type(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); - break; - case 30: - matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class); - Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); - icmpv6CodeBuilder.setIcmpv6Code(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); - break; - case 31: - matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - break; - case 32: - matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - break; - case 33: - matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - break; - case 34: - matchEntriesBuilder.setOxmMatchField(MplsLabel.class); - MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder(); - mplsLabelBuilder.setMplsLabel(in.readUnsignedInt()); - matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build()); - break; - case 35: - matchEntriesBuilder.setOxmMatchField(MplsTc.class); - TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); - tcBuilder.setTc(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); - break; - case 36: - matchEntriesBuilder.setOxmMatchField(MplsBos.class); - BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); - if (in.readUnsignedByte() != 0) { - bosBuilder.setBos(true); - } else { - bosBuilder.setBos(false); - } - matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); - break; - case 37: - matchEntriesBuilder.setOxmMatchField(PbbIsid.class); - IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); - Integer isid = in.readUnsignedMedium(); - isidBuilder.setIsid(isid.longValue()); - matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_3_BYTES); - } - break; - case 38: - matchEntriesBuilder.setOxmMatchField(TunnelId.class); - addMetadataAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 39: - matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class); - PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); - int bitmap = in.readUnsignedShort(); - final Boolean NONEXT = ((bitmap) & (1<<0)) != 0; - final Boolean ESP = ((bitmap) & (1<<1)) != 0; - final Boolean AUTH = ((bitmap) & (1<<2)) != 0; - final Boolean DEST = ((bitmap) & (1<<3)) != 0; - final Boolean FRAG = ((bitmap) & (1<<4)) != 0; - final Boolean ROUTER = ((bitmap) & (1<<5)) != 0; - final Boolean HOP = ((bitmap) & (1<<6)) != 0; - final Boolean UNREP = ((bitmap) & (1<<7)) != 0; - final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0; - pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ)); - matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - break; - default: - break; - } - matchEntriesList.add(matchEntriesBuilder.build()); - if (oneEntry) { - break; - } - } - if ((matchLength - currLength) > 0) { - in.skipBytes(matchLength - currLength); - } - return matchEntriesList; - } - - /** Decodes oxm ids - * @param in input ByteBuf - * @param matchLength match entries length - * @return list of match ids - */ - public static List createMatchIds(ByteBuf in, int matchLength) { - return MatchIdsDeserializer.createOxmIds(in, matchLength); - } - - private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) { - MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); - byte[] mask = new byte[matchEntryLength]; - in.readBytes(mask); - maskBuilder.setMask(mask); - builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); - } - - private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) { - groups.add(String.format("%04X", in.readUnsignedShort())); - } - Joiner joiner = Joiner.on(":"); - ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups))); - builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build()); - } - - private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder(); - byte[] metadataBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - in.readBytes(metadataBytes); - metadata.setMetadata(metadataBytes); - builder.addAugmentation(MetadataMatchEntry.class, metadata.build()); - } - - private static void addIpv4AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - groups.add(Short.toString(in.readUnsignedByte())); - } - Joiner joiner = Joiner.on("."); - ipv4AddressBuilder.setIpv4Address(new Ipv4Address(joiner.join(groups))); - builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build()); - } - - private static void addMacAddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder(); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - in.readBytes(address); - macAddress.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); - builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build()); - } - - private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); - portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params. - xml.ns.yang.ietf.inet.types.rev100924.PortNumber(in.readUnsignedShort())); - builder.addAugmentation(PortMatchEntry.class, portBuilder.build()); + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + this.registry = deserializerRegistry; } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntryDeserializerRegistryHelper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntryDeserializerRegistryHelper.java new file mode 100644 index 00000000..102d1f08 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchEntryDeserializerRegistryHelper.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.util; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class MatchEntryDeserializerRegistryHelper { + + private short version; + private DeserializerRegistry registry; + private int oxmClass; + + /** + * @param version wire protocol version + * @param oxmClass oxm_class that will be used for match entry deserializer + * registration + * @param deserializerRegistry registry to be filled with message deserializers + */ + public MatchEntryDeserializerRegistryHelper(short version, int oxmClass, + DeserializerRegistry deserializerRegistry) { + this.version = version; + this.oxmClass = oxmClass; + this.registry = deserializerRegistry; + } + + /** + * Registers match entry deserializer under provided oxmfield () + * @param oxmField oxm_field value/code + * @param deserializer deserializer instance + */ + public void register(int oxmField, OFGeneralDeserializer deserializer) { + registry.registerDeserializer(new EnhancedMessageCodeKey(version, oxmClass, + oxmField, MatchEntries.class), deserializer); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MessageDeserializerRegistryHelper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MessageDeserializerRegistryHelper.java new file mode 100644 index 00000000..e31dea31 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MessageDeserializerRegistryHelper.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.util; + +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; + +/** + * @author michal.polkorab + * + */ +public class MessageDeserializerRegistryHelper { + + private short version; + private DeserializerRegistry registry; + + /** + * @param version wire protocol version + * @param deserializerRegistry registry to be filled with message deserializers + */ + public MessageDeserializerRegistryHelper(short version, DeserializerRegistry deserializerRegistry) { + this.version = version; + this.registry = deserializerRegistry; + } + + /** + * @param code code / value to distinguish between deserializers + * @param deserializedObjectClass class of object that will be deserialized + * by given deserializer + * @param deserializer deserializer instance + */ + public void registerMessageDeserializer(int code, + Class deserializedObjectClass, OFGeneralDeserializer deserializer) { + registry.registerDeserializer(new MessageCodeKey(version, code, + deserializedObjectClass), deserializer); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java index 64372b1e..75be481a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java @@ -13,12 +13,15 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; @@ -34,7 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; @@ -57,7 +59,8 @@ import com.google.common.base.Joiner; * Deserializes ofp_action (OpenFlow v1.0) structures * @author michal.polkorab */ -public abstract class OF10ActionsDeserializer { +public class OF10ActionsDeserializer implements OFDeserializer, + DeserializerRegistryInjector { private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; @@ -66,41 +69,12 @@ public abstract class OF10ActionsDeserializer { private static final byte PADDING_IN_NW_TOS_ACTION = 3; private static final byte PADDING_IN_TP_ACTION = 2; private static final byte PADDING_IN_ENQUEUE_ACTION = 6; + private DeserializerRegistry registry; - /** - * Creates list of actions (OpenFlow v1.0) from ofp_action structures - * @param input input ByteBuf - * @return ActionsList list of actions - */ - public static List createActionsList(ByteBuf input) { - List actions = new ArrayList<>(); - while (input.readableBytes() > 0) { - int type = input.readUnsignedShort(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - actions.add(decodeAction(input, type)); - } - return actions; - } - - /** - * Creates list of actions (OpenFlow v1.0) from ofp_action structures, which are not the last structure - * in message - * @param input input ByteBuf - * @param actionsLength length of actions - * @return ActionsList list of actions - */ - public static List createActionsList(ByteBuf input, int actionsLength) { - List actions = new ArrayList<>(); - int currentLength = 0; - while (currentLength < actionsLength) { - int type = input.readUnsignedShort(); - currentLength += input.readUnsignedShort(); - actions.add(decodeAction(input, type)); - } - return actions; - } - - private static Action decodeAction(ByteBuf input, int type) { + @Override + public Action deserialize(ByteBuf input) { + int type = input.readUnsignedShort(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); ActionBuilder actionsBuilder = new ActionBuilder(); Action actionsList = null; switch(type) { @@ -141,7 +115,9 @@ public abstract class OF10ActionsDeserializer { actionsList = createEnqueueAction(input, actionsBuilder); break; case 0xFFFF: - actionsList = createExperimenterAction(input, actionsBuilder); + OFDeserializer expDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 0xFFFF, ExperimenterAction.class)); + expDeserializer.deserialize(input); break; default: break; @@ -270,12 +246,8 @@ public abstract class OF10ActionsDeserializer { return builder.build(); } - private static Action createExperimenterAction(ByteBuf input, ActionBuilder builder) { - builder.setType(Experimenter.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - builder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - return builder.build(); + @Override + public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; } - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java index 88fc3129..393f42ba 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java @@ -13,6 +13,7 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; @@ -25,8 +26,8 @@ import com.google.common.base.Joiner; * Deserializes ofp_match (OpenFlow v1.0) structure * @author michal.polkorab */ -public abstract class OF10MatchDeserializer { - +public class OF10MatchDeserializer implements OFDeserializer { + private static final byte PADDING_IN_MATCH = 1; private static final byte PADDING_IN_MATCH_2 = 2; private static final byte NW_SRC_BITS = 6; @@ -36,48 +37,44 @@ public abstract class OF10MatchDeserializer { private static final byte NW_DST_SHIFT = 14; private static final int NW_DST_MASK = ((1 << NW_DST_BITS) - 1) << NW_DST_SHIFT; - /** - * Creates ofp_match (OpenFlow v1.0) structure - * @param rawMessage ByteBuf with input data - * @return ofp_match (OpenFlow v1.0) - */ - public static MatchV10 createMatchV10(ByteBuf rawMessage) { + @Override + public MatchV10 deserialize(ByteBuf input) { MatchV10Builder builder = new MatchV10Builder(); - long wildcards = rawMessage.readUnsignedInt(); + long wildcards = input.readUnsignedInt(); builder.setWildcards(createWildcards(wildcards)); builder.setNwSrcMask(decodeNwSrcMask(wildcards)); builder.setNwDstMask(decodeNwDstMask(wildcards)); - builder.setInPort(rawMessage.readUnsignedShort()); + builder.setInPort(input.readUnsignedShort()); byte[] dlSrc = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(dlSrc); + input.readBytes(dlSrc); builder.setDlSrc(new MacAddress(ByteBufUtils.macAddressToString(dlSrc))); byte[] dlDst = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(dlDst); + input.readBytes(dlDst); builder.setDlDst(new MacAddress(ByteBufUtils.macAddressToString(dlDst))); - builder.setDlVlan(rawMessage.readUnsignedShort()); - builder.setDlVlanPcp(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_MATCH); - builder.setDlType(rawMessage.readUnsignedShort()); - builder.setNwTos(rawMessage.readUnsignedByte()); - builder.setNwProto(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_MATCH_2); + builder.setDlVlan(input.readUnsignedShort()); + builder.setDlVlanPcp(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_MATCH); + builder.setDlType(input.readUnsignedShort()); + builder.setNwTos(input.readUnsignedByte()); + builder.setNwProto(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_MATCH_2); List srcGroups = new ArrayList<>(); for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - srcGroups.add(Short.toString(rawMessage.readUnsignedByte())); + srcGroups.add(Short.toString(input.readUnsignedByte())); } Joiner joiner = Joiner.on("."); builder.setNwSrc(new Ipv4Address(joiner.join(srcGroups))); List dstGroups = new ArrayList<>(); for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - dstGroups.add(Short.toString(rawMessage.readUnsignedByte())); + dstGroups.add(Short.toString(input.readUnsignedByte())); } builder.setNwDst(new Ipv4Address(joiner.join(dstGroups))); - builder.setTpSrc(rawMessage.readUnsignedShort()); - builder.setTpDst(rawMessage.readUnsignedShort()); + builder.setTpSrc(input.readUnsignedShort()); + builder.setTpDst(input.readUnsignedShort()); return builder.build(); } - + /** * Decodes FlowWildcards * @param input input ByteBuf @@ -115,5 +112,4 @@ public abstract class OF10MatchDeserializer { public static short decodeNwDstMask(long input) { return (short) Math.max(32 - ((input & NW_DST_MASK) >> NW_DST_SHIFT), 0); } - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java index 9e3f829d..408cbb69 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java @@ -22,7 +22,7 @@ public abstract class OxmMatchConstants { public static final int OPENFLOW_BASIC_CLASS = 0x8000; /** Experimenter class */ public static final int EXPERIMENTER_CLASS = 0xFFFF; - + /** Switch input port */ public static final int IN_PORT = 0; /** Switch physical input port */ @@ -103,4 +103,4 @@ public abstract class OxmMatchConstants { public static final int TUNNEL_ID = 38; /** IPv6 Extension Header pseudo-field */ public static final int IPV6_EXTHDR = 39; -} +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeToClassInitHelper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeToClassInitHelper.java new file mode 100644 index 00000000..246c4105 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/TypeToClassInitHelper.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.util; + +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.TypeToClassKey; + +/** + * @author michal.polkorab + * + */ +public class TypeToClassInitHelper { + + private short version; + private Map> messageClassMap; + + /** + * Constructor + * @param version protocol wire version + * @param messageClassMap map which stores type to class mapping + */ + public TypeToClassInitHelper(short version, Map> messageClassMap) { + this.version = version; + this.messageClassMap = messageClassMap; + } + + /** + * Registers Class int the type to class mapping + * @param type code value for message type / class + * @param clazz corresponding code -> class + */ + public void registerTypeToClass(short type, Class clazz) { + messageClassMap.put(new TypeToClassKey(version, type), clazz); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java index 51c700e7..8bc381a8 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java @@ -10,8 +10,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; /** @@ -20,27 +26,28 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class BarrierReplyMessageFactoryTest { + private OFDeserializer barrierFactory; + /** - * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO + * Initializes deserializer registry and lookups correct deserializer */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer(); - BarrierOutput builtByFactory = BufferHelper.decodeV13( - BarrierReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + barrierFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 21, BarrierOutput.class)); } - + /** * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO */ @Test - public void testV10() { + public void test() { ByteBuf bb = BufferHelper.buildBuffer(); - BarrierOutput builtByFactory = BufferHelper.decodeV10( - BarrierReplyMessageFactory.getInstance(), bb); + BarrierOutput builtByFactory = BufferHelper.deserialize( + barrierFactory, bb); - BufferHelper.checkHeaderV10(builtByFactory); + BufferHelper.checkHeaderV13(builtByFactory); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java index b257d9d7..ae184295 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java @@ -11,9 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; /** @@ -22,56 +27,40 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoReplyMessageFactoryTest { - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); + private OFDeserializer echoFactory; - BufferHelper.checkHeaderV13(builtByFactory); - } - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + * Initializes deserializer registry and lookups correct deserializer */ - @Test - public void testWithDataFieldSet() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + echoFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 3, EchoOutput.class)); } - + /** * Testing {@link EchoReplyMessageFactory} for correct translation into POJO */ @Test - public void testWithEmptyDataFieldV10() { + public void testWithEmptyDataField() { ByteBuf bb = BufferHelper.buildBuffer(); - EchoOutput builtByFactory = BufferHelper.decodeV10( - EchoReplyMessageFactory.getInstance(), bb); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); - BufferHelper.checkHeaderV10(builtByFactory); + BufferHelper.checkHeaderV13(builtByFactory); } /** * Testing {@link EchoReplyMessageFactory} for correct translation into POJO */ @Test - public void testWithDataFieldSetV10() { + public void testWithDataFieldSet() { byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; ByteBuf bb = BufferHelper.buildBuffer(data); - EchoOutput builtByFactory = BufferHelper.decodeV10( - EchoReplyMessageFactory.getInstance(), bb); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); - BufferHelper.checkHeaderV10(builtByFactory); + BufferHelper.checkHeaderV13(builtByFactory); Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); } - } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java index bcb12534..7b6a6305 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java @@ -11,9 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; /** @@ -22,56 +27,40 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoRequestMessageFactoryTest { - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.getInstance(), bb); + private OFDeserializer echoFactory; - BufferHelper.checkHeaderV13(builtByFactory); - } - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + * Initializes deserializer registry and lookups correct deserializer */ - @Test - public void testWithDataFieldSet() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + echoFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 2, EchoRequestMessage.class)); } - + /** * Testing {@link EchoRequestMessageFactory} for correct translation into POJO */ @Test - public void testWithEmptyDataFieldV10() { + public void testWithEmptyDataField() { ByteBuf bb = BufferHelper.buildBuffer(); - EchoRequestMessage builtByFactory = BufferHelper.decodeV10( - EchoRequestMessageFactory.getInstance(), bb); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); - BufferHelper.checkHeaderV10(builtByFactory); + BufferHelper.checkHeaderV13(builtByFactory); } /** * Testing {@link EchoRequestMessageFactory} for correct translation into POJO */ @Test - public void testWithDataFieldSetV10() { + public void testWithDataFieldSet() { byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; ByteBuf bb = BufferHelper.buildBuffer(data); - EchoRequestMessage builtByFactory = BufferHelper.decodeV10( - EchoRequestMessageFactory.getInstance(), bb); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); - BufferHelper.checkHeaderV10(builtByFactory); + BufferHelper.checkHeaderV13(builtByFactory); Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); } - } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java index e139a77a..5df6b771 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; /** @@ -21,14 +27,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class ErrorMessageFactoryTest { + private OFDeserializer errorFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + errorFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 1, ErrorMessage.class)); + } + /** * Test of {@link ErrorMessageFactory} for correct translation into POJO */ @Test public void testWithoutData() { ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02"); - ErrorMessage builtByFactory = BufferHelper.decodeV13( - ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue()); @@ -44,8 +62,7 @@ public class ErrorMessageFactoryTest { @Test public void testWithData() { ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV13( - ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue()); @@ -61,8 +78,7 @@ public class ErrorMessageFactoryTest { @Test public void testWithIncorrectTypeEnum() { ByteBuf bb = BufferHelper.buildBuffer("00 20 00 05 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV13( - ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 32, builtByFactory.getType().intValue()); @@ -78,8 +94,7 @@ public class ErrorMessageFactoryTest { @Test public void testWithIncorrectCodeEnum() { ByteBuf bb = BufferHelper.buildBuffer("00 03 00 10 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV13( - ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java deleted file mode 100644 index 3f861bb9..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; - -/** - * @author michal.polkorab - * - */ -public class ExperimenterMessageFactoryTest { - - /** - * Testing {@link ExperimenterMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04"); - ExperimenterMessage builtByFactory = BufferHelper.decodeV13( - ExperimenterMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); - Assert.assertEquals("Wrong expType", 0x01020304L, builtByFactory.getExpType().longValue()); - } - -} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java index be6dc48c..c12a4ec6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; @@ -22,6 +28,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class FeaturesReplyMessageFactoryTest { + private OFDeserializer featuresFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + featuresFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 6, GetFeaturesOutput.class)); + } + /** * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO */ @@ -29,8 +48,7 @@ public class FeaturesReplyMessageFactoryTest { public void test() { ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" + " 00 01 41 00 01 02 03"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV13( - FeaturesReplyMessageFactory.getInstance(), bb); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java index 4682c147..cc5709d1 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; @@ -22,6 +28,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class FlowRemovedMessageFactoryTest { + private OFDeserializer flowFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + flowFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 11, FlowRemovedMessage.class)); + } + /** * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO */ @@ -29,7 +48,7 @@ public class FlowRemovedMessageFactoryTest { public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02" + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07"); - FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb); + FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java index 0326720d..8cc9f8cd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java @@ -14,8 +14,14 @@ import java.util.ArrayList; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; @@ -32,7 +38,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * */ public class GetAsyncReplyMessageFactoryTest { - + + private OFDeserializer asyncFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + asyncFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 27, GetAsyncOutput.class)); + } /** * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO @@ -45,7 +63,7 @@ public class GetAsyncReplyMessageFactoryTest { "00 00 00 00 "+ "00 00 00 03 "+ "00 00 00 0A"); - GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb); + GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong packetInMask",createPacketInMask(), diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java index 3e39ecb7..13bbb2a8 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; /** @@ -21,14 +27,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetConfigReplyMessageFactoryTest { + private OFDeserializer configFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + configFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 8, GetConfigOutput.class)); + } + /** * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO */ @Test public void test() { ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03"); - GetConfigOutput builtByFactory = BufferHelper.decodeV13( - GetConfigReplyMessageFactory.getInstance(), bb); + GetConfigOutput builtByFactory = BufferHelper.deserialize(configFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong switchConfigFlag", 0x01, builtByFactory.getFlags().getIntValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java index 0ab67a9a..d8bd93ee 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java @@ -8,14 +8,20 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; +import io.netty.buffer.ByteBuf; + import java.util.ArrayList; import java.util.List; -import io.netty.buffer.ByteBuf; - import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; @@ -29,6 +35,18 @@ public class HelloMessageFactoryTest { /** Number of currently supported version / codec */ public static final Short VERSION_YET_SUPPORTED = 0x04; + private OFDeserializer helloFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + helloFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0, HelloMessage.class)); + } /** * Testing {@link HelloMessageFactory} for correct translation into POJO @@ -41,8 +59,7 @@ public class HelloMessageFactoryTest { + "00 00 00 00 " // bitmap 2 + "00 00 00 00" // padding ); - HelloMessage builtByFactory = BufferHelper.decodeV13( - HelloMessageFactory.getInstance(), bb); + HelloMessage builtByFactory = BufferHelper.deserialize(helloFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); List element = createElement(); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java index db08791a..cf39f0fd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java @@ -13,9 +13,15 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; @@ -94,6 +100,19 @@ import org.slf4j.LoggerFactory; */ public class MultipartReplyMessageFactoryTest { + private OFDeserializer multipartFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + multipartFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 19, MultipartReplyMessage.class)); + } + private static final Logger LOGGER = LoggerFactory .getLogger(MultipartReplyMessageFactoryTest.class); @@ -136,7 +155,7 @@ public class MultipartReplyMessageFactoryTest { bb.writeBytes(dpDescBytes); ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x00, builtByFactory.getType().getIntValue()); @@ -189,7 +208,7 @@ public class MultipartReplyMessageFactoryTest { "00 01 00 08 06 00 00 00 "+ "00 01 00 08 06 00 00 00"); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue()); @@ -229,7 +248,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 00"//pad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue()); @@ -260,7 +279,7 @@ public class MultipartReplyMessageFactoryTest { "AF 01 01 01 01 01 01 01"//matchedCount ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue()); @@ -302,7 +321,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 04"//durationNsec ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue()); @@ -365,7 +384,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 04"//durationNsec ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue()); @@ -421,7 +440,7 @@ public class MultipartReplyMessageFactoryTest { "FF 02 02 02 02 02 02 02"//byteCountBucket_2.2 ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue()); @@ -489,7 +508,7 @@ public class MultipartReplyMessageFactoryTest { "00 00"//pad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 11, builtByFactory.getType().getIntValue()); @@ -526,7 +545,7 @@ public class MultipartReplyMessageFactoryTest { "FF 03 03 03 03 03 03 03"//byteBandCount_03 ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); @@ -603,7 +622,7 @@ public class MultipartReplyMessageFactoryTest { "FF 03 03 03 03 03 03 03"//byteBandCount_13 ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); @@ -704,7 +723,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 04"//meterBandExperimenter.experimenter ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); @@ -774,7 +793,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00"//meterBandDscp01.pad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); @@ -832,7 +851,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 01 01 00 00 01 01" ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 0xFFFF, builtByFactory.getType().getIntValue()); @@ -874,7 +893,7 @@ public class MultipartReplyMessageFactoryTest { ); bb.writeBytes(bb2.copy(4, bb2.readableBytes()-4));//excluding version and xid - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue()); @@ -945,7 +964,7 @@ public class MultipartReplyMessageFactoryTest { "00 08 "+//copyTTLIntLen "00 00 00 00"//copyTTLInPad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); @@ -1024,7 +1043,7 @@ public class MultipartReplyMessageFactoryTest { "00 00"//pushPbbPad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); @@ -1111,7 +1130,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 00"//decNwTtlPad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); @@ -1187,7 +1206,7 @@ public class MultipartReplyMessageFactoryTest { "00 00 00 00" ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10BarrierReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10BarrierReplyMessageFactoryTest.java new file mode 100644 index 00000000..2d7ee042 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10BarrierReplyMessageFactoryTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10BarrierReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10BarrierReplyMessageFactoryTest { + + private OFDeserializer barrierFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + barrierFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 19, BarrierOutput.class)); + } + + /** + * Testing of {@link OF10BarrierReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + BarrierOutput builtByFactory = BufferHelper.deserialize( + barrierFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactoryTest.java new file mode 100644 index 00000000..cdfd644f --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoReplyMessageFactoryTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10EchoReplyMessageFactoryTest { + + private OFDeserializer echoFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + echoFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 3, EchoOutput.class)); + } + + /** + * Testing {@link OF10EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataFieldV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } + + /** + * Testing {@link OF10EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSetV10() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactoryTest.java new file mode 100644 index 00000000..efcd8aff --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10EchoRequestMessageFactoryTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10EchoRequestMessageFactoryTest { + + private OFDeserializer echoFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + echoFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 2, EchoRequestMessage.class)); + } + + /** + * Testing {@link OF10EchoReplyMessageFactoryTest} for correct translation into POJO + */ + @Test + public void testWithEmptyDataFieldV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } + + /** + * Testing {@link OF10EchoReplyMessageFactoryTest} for correct translation into POJO + */ + @Test + public void testWithDataFieldSetV10() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java index 43e6d37d..68a49b2c 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java @@ -11,23 +11,40 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; /** * @author michal.polkorab */ public class OF10ErrorMessageFactoryTest { + private OFDeserializer errorFactory; - /** + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + errorFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 1, ErrorMessage.class)); + } + + /** * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO */ @Test public void testWithoutData() { ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue()); @@ -43,8 +60,7 @@ public class OF10ErrorMessageFactoryTest { @Test public void testWithData() { ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue()); @@ -60,8 +76,7 @@ public class OF10ErrorMessageFactoryTest { @Test public void testWithIncorrectTypeEnum() { ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue()); @@ -77,8 +92,7 @@ public class OF10ErrorMessageFactoryTest { @Test public void testWithIncorrectCodeEnum() { ByteBuf bb = BufferHelper.buildBuffer("00 03 00 06 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); + ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java index bb955efd..d9b50ee8 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; @@ -28,6 +34,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10FeaturesReplyMessageFactoryTest { + private OFDeserializer featuresFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + featuresFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, GetFeaturesOutput.class)); + } + /** * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO */ @@ -37,8 +56,7 @@ public class OF10FeaturesReplyMessageFactoryTest { + "00 00 00 8B 00 00 03 B5 " + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); @@ -77,8 +95,7 @@ public class OF10FeaturesReplyMessageFactoryTest { + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 " + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size()); @@ -91,8 +108,7 @@ public class OF10FeaturesReplyMessageFactoryTest { public void testWithTwoPortsSet() { ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " + "00 00 00 8B 00 00 03 B5"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java index 3a9ec1a6..fc99ebb3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java @@ -10,8 +10,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; /** @@ -19,7 +25,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10FlowRemovedMessageFactoryTest { - /** + private OFDeserializer flowFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + flowFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 11, FlowRemovedMessage.class)); + } + + /** * Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO */ @Test @@ -29,7 +48,7 @@ public class OF10FlowRemovedMessageFactoryTest { + "50 50 20 20 "// match + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 " + "00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");//41 - FlowRemovedMessage builtByFactory = BufferHelper.decodeV10(OF10FlowRemovedMessageFactory.getInstance(), bb); + FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10GetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10GetConfigReplyMessageFactoryTest.java new file mode 100644 index 00000000..727ea082 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10GetConfigReplyMessageFactoryTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10GetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF10GetConfigReplyMessageFactoryTest { + + private OFDeserializer configFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + configFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 8, GetConfigOutput.class)); + } + + /** + * Testing {@link OF10GetConfigReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03"); + GetConfigOutput builtByFactory = BufferHelper.deserialize(configFactory, bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong switchConfigFlag", 0x01, builtByFactory.getFlags().getIntValue()); + Assert.assertEquals("Wrong missSendLen", 0x03, builtByFactory.getMissSendLen().intValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java index 5c08bf4d..0015f3fd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; /** @@ -20,14 +26,27 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10HelloMessageFactoryTest { - /** + private OFDeserializer helloFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + helloFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 0, HelloMessage.class)); + } + + /** * Testing {@link OF10HelloMessageFactory} for correct translation into POJO */ @Test public void testWithoutElements() { ByteBuf bb = BufferHelper.buildBuffer(); - HelloMessage builtByFactory = BufferHelper.decodeV10( - OF10HelloMessageFactory.getInstance(), bb); + HelloMessage builtByFactory = BufferHelper.deserialize( + helloFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertNull("Wrong elements", builtByFactory.getElements()); @@ -44,8 +63,8 @@ public class OF10HelloMessageFactoryTest { + "00 00 00 00 " // bitmap 2 + "00 00 00 00" // padding ); - HelloMessage builtByFactory = BufferHelper.decodeV10( - OF10HelloMessageFactory.getInstance(), bb); + HelloMessage builtByFactory = BufferHelper.deserialize( + helloFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertNull("Wrong elements", builtByFactory.getElements()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java index 51f5cdcf..aac06253 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java @@ -10,21 +10,43 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +/** + * @author michal.polkorab + */ public class OF10PacketInMessageFactoryTest { - /** + private OFDeserializer packetInFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + packetInFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 10, PacketInMessage.class)); + } + + /** * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO */ @Test public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); - PacketInMessage builtByFactory = BufferHelper.decodeV10(OF10PacketInMessageFactory.getInstance(), bb); + PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java index d4fa28bf..42458413 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; @@ -26,6 +32,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10PortStatusMessageFactoryTest { + private OFDeserializer statusFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + statusFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 12, PortStatusMessage.class)); + } + /** * Testing {@link OF10PortStatusMessageFactory} for correct translation into POJO */ @@ -34,7 +53,7 @@ public class OF10PortStatusMessageFactoryTest { ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 " + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); - PortStatusMessage builtByFactory = BufferHelper.decodeV10(OF10PortStatusMessageFactory.getInstance(), bb); + PortStatusMessage builtByFactory = BufferHelper.deserialize(statusFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong reason", PortReason.OFPPRADD, builtByFactory.getReason()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java index 216e5d37..0e9b7f53 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; @@ -24,6 +30,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10QueueGetConfigReplyMessageFactoryTest { + private OFDeserializer queueFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + queueFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 21, GetQueueConfigOutput.class)); + } + /** * Testing of {@link OF10QueueGetConfigReplyMessageFactory} for correct * translation into POJO @@ -34,8 +53,8 @@ public class OF10QueueGetConfigReplyMessageFactoryTest { + "00 00 00 08 00 10 00 00 00 00 00 08 00 00 00 00 " + "00 00 00 02 00 28 00 00 00 01 00 10 00 00 00 00 00 20 00 00 00 00 00 00 " + "00 01 00 10 00 00 00 00 00 30 00 00 00 00 00 00"); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV10( - OF10QueueGetConfigReplyMessageFactory.getInstance(), bb); + GetQueueConfigOutput builtByFactory = BufferHelper.deserialize( + queueFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong port", 1, builtByFactory.getPort().getValue().intValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactoryTest.java index 553ac79f..bc6b996e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactoryTest.java @@ -12,9 +12,15 @@ import io.netty.buffer.ByteBuf; import java.math.BigInteger; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; @@ -42,6 +48,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10StatsReplyMessageFactoryTest { + private OFDeserializer statsFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + statsFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 17, MultipartReplyMessage.class)); + } + /** * Testing OF10StatsReplyMessageFactory (Desc) for correct deserialization */ @@ -81,7 +100,7 @@ public class OF10StatsReplyMessageFactoryTest { bb.writeBytes(dpDescBytes); ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0, builtByFactory.getType().getIntValue()); @@ -108,8 +127,7 @@ public class OF10StatsReplyMessageFactoryTest { + "FF 01 02 03 04 05 06 07 FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 " + "00 00 00 08 00 01 00 02 00 01 00 08 00 03 00 00"); - MultipartReplyMessage builtByFactory = - BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue()); @@ -152,8 +170,7 @@ public class OF10StatsReplyMessageFactoryTest { ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 " + "FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 00 00 00 30 00 00 00 00"); - MultipartReplyMessage builtByFactory = - BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue()); @@ -180,7 +197,7 @@ public class OF10StatsReplyMessageFactoryTest { + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 30 00 00 00 10 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00"); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue()); @@ -219,7 +236,7 @@ public class OF10StatsReplyMessageFactoryTest { + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 " + "FF 02 03 02 03 02 03 02 "); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue()); @@ -277,7 +294,7 @@ public class OF10StatsReplyMessageFactoryTest { + "FF 02 02 02 02 02 02 02 " + "FF 02 03 02 03 02 03 02 "); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV10(OF10StatsReplyMessageFactory.getInstance(), bb); + MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java deleted file mode 100644 index 7dc2e863..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; - -/** - * @author michal.polkorab - */ -public class OF10VendorMessageFactoryTest { - - /** - * Testing {@link OF10VendorMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04"); - ExperimenterMessage builtByFactory = BufferHelper.decodeV10( - OF10VendorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); - } -} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java index 6a3a35f0..21889a08 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java @@ -11,14 +11,18 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author timotej.kubas @@ -26,9 +30,19 @@ import org.slf4j.LoggerFactory; */ public class PacketInMessageFactoryTest { - private static final Logger LOGGER = LoggerFactory - .getLogger(PacketInMessageFactoryTest.class); - + private OFDeserializer packetInFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + packetInFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 10, PacketInMessage.class)); + } + /** * Testing {@link PacketInMessageFactory} for correct translation into POJO */ @@ -36,7 +50,7 @@ public class PacketInMessageFactoryTest { public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C" + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04"); - PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); + PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java index accefd27..647fd9e2 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java @@ -12,8 +12,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; @@ -26,6 +32,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class PortStatusMessageFactoryTest { + private OFDeserializer statusFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + statusFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 12, PortStatusMessage.class)); + } + /** * Testing {@link PortStatusMessageFactory} for correct translation into POJO */ @@ -48,7 +67,7 @@ public class PortStatusMessageFactoryTest { "00 00 00 80" //max speed ); - PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb); + PortStatusMessage builtByFactory = BufferHelper.deserialize(statusFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java index 4d8cb228..048e2371 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java @@ -14,8 +14,14 @@ import java.util.ArrayList; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; @@ -33,6 +39,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class QueueGetConfigReplyMessageFactoryMultiTest { + private OFDeserializer queueFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + queueFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class)); + } + /** * Testing of {@link QueueGetConfigReplyMessageFactory} for correct * translation into POJO @@ -61,8 +80,8 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { "00 00 00 00 00 00 " // pad ); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13( - QueueGetConfigReplyMessageFactory.getInstance(), bb); + GetQueueConfigOutput builtByFactory = BufferHelper.deserialize( + queueFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java index 157e8d7f..6e9099d3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java @@ -14,8 +14,14 @@ import java.util.ArrayList; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; @@ -33,13 +39,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class QueueGetConfigReplyMessageFactoryTest { + private OFDeserializer queueFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + queueFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class)); + } + /** * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO */ @Test public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00"); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); + GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(queueFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue()); Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java index 2d7ff94e..70795848 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java @@ -11,8 +11,14 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; /** @@ -21,13 +27,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class RoleReplyMessageFactoryTest { + private OFDeserializer roleFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + roleFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 25, RoleRequestOutput.class)); + } + /** * Testing of {@link RoleReplyMessageFactory} for correct translation into POJO */ @Test public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 00 01 02 03 04 05 06 07"); - RoleRequestOutput builtByFactory = BufferHelper.decodeV13(RoleReplyMessageFactory.getInstance(), bb); + RoleRequestOutput builtByFactory = BufferHelper.deserialize(roleFactory, bb); BufferHelper.checkHeaderV13(builtByFactory); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java index a63edea9..02aaabb2 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializerTest.java @@ -12,9 +12,13 @@ import io.netty.buffer.ByteBuf; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; @@ -36,6 +40,20 @@ public class ActionsDeserializerTest { private static final Logger LOGGER = LoggerFactory .getLogger(ActionsDeserializerTest.class); + private OFDeserializer actionDeserializer; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + actionDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Action.class)); + } + /** * Testing actions deserialization */ @@ -56,12 +74,14 @@ public class ActionsDeserializerTest { + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " - + "00 1B 00 08 00 00 00 00 " - + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07"); + + "00 1B 00 08 00 00 00 00"); message.skipBytes(4); // skip XID LOGGER.info("bytes: " + message.readableBytes()); - List actions = ActionsDeserializer.createActions(message, message.readableBytes()); + + + List actions = DecodingUtils.deserializeList(message.readableBytes(), + message, actionDeserializer); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName()); Assert.assertEquals("Wrong action port", 1, @@ -123,12 +143,6 @@ public class ActionsDeserializerTest { actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName()); - Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." - + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName()); - Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class) - .getExperimenter().intValue()); - Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16) - .getAugmentation(ExperimenterAction.class).getData()); Assert.assertTrue("Unread data in message", message.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java index 92777a8e..8a40cf2a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java @@ -15,7 +15,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.junit.Assert; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -125,29 +125,15 @@ public abstract class BufferHelper { Method m2 = builder.getClass().getMethod("setXid", Long.class); m2.invoke(builder, BufferHelper.DEFAULT_XID); } - - /** - * Use version 1.3 for decoding message - * @param decoder decoder instance - * @param bb data input buffer - * @return message decoded pojo - */ - public static E decodeV13(OFDeserializer decoder, ByteBuf bb) { - return bufferToMessage(decoder, EncodeConstants.OF13_VERSION_ID, bb); - } - + /** - * Use version 1.0 for decoding message + * Decode message * @param decoder decoder instance * @param bb data input buffer * @return message decoded pojo */ - public static E decodeV10(OFDeserializer decoder, ByteBuf bb) { - return bufferToMessage(decoder, EncodeConstants.OF10_VERSION_ID, bb); - } - - private static E bufferToMessage(OFDeserializer decoder, short version, ByteBuf bb) { - return decoder.bufferToMessage(bb, version); + public static E deserialize(OFDeserializer decoder, ByteBuf bb) { + return decoder.deserialize(bb); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java index c7a5ee97..61282953 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java @@ -142,7 +142,7 @@ public class ByteBufUtilsTest { } /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + * Test of {@link ByteBufUtils#fillBitMaskFromList(List)} */ @Test public void testFillBitmaskByEmptyList() { @@ -162,7 +162,7 @@ public class ByteBufUtilsTest { } /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + * Test of {@link ByteBufUtils#fillBitMaskFromList(List)} */ @Test public void testFillBitmaskByFullList() { @@ -177,7 +177,7 @@ public class ByteBufUtilsTest { } /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + * Test of {@link ByteBufUtils#fillBitMaskFromList(List)} */ @Test public void testFillBitmaskByZeroList() { @@ -192,7 +192,7 @@ public class ByteBufUtilsTest { } /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + * Test of {@link ByteBufUtils#fillBitMaskFromList(List)} */ @Test public void testFillBitmaskFromRandomList() { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializerTest.java index d65b9552..53e95088 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializerTest.java @@ -12,7 +12,12 @@ import io.netty.buffer.ByteBuf; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; @@ -30,7 +35,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction * */ public class InstructionsDeserializerTest { - + + private OFDeserializer insDeserializer; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + insDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Instruction.class)); + } + /** * Testing instructions translation */ @@ -42,7 +61,9 @@ public class InstructionsDeserializerTest { + "00 16 00 08 00 00 00 50 00 04 00 18 00 00 00 00 00 15 00 08 00 00 00 25 00 0F 00 08 05 00 00 00"); message.skipBytes(4); // skip XID - List instructions = InstructionsDeserializer.createInstructions(message, message.readableBytes()); + + List instructions = DecodingUtils.deserializeList( + message.readableBytes(), message, insDeserializer); Instruction i1 = instructions.get(0); Assert.assertEquals("Wrong type - i1", "org.opendaylight.yang.gen.v1.urn." + "opendaylight.openflow.common.instruction.rev130731.GotoTable", i1.getType().getName()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java index 4de1c3a8..d4cdc802 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java @@ -12,7 +12,13 @@ import io.netty.buffer.ByteBuf; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; @@ -49,7 +55,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpT import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; @@ -72,8 +77,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Meta import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; @@ -94,16 +97,32 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. * */ public class MatchDeserializerTest { - + + private OFDeserializer matchDeserializer; + private DeserializerRegistry registry; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + registry = new DeserializerRegistryImpl(); + registry.init(); + matchDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, + EncodeConstants.EMPTY_VALUE, Match.class)); + } + /** * Testing Ipv4 address deserialization */ @Test public void testIpv4Address() { ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03"); - - List list = MatchDeserializer.createMatchEntry(buffer, 8); - MatchEntries entry = list.get(0); + + OFDeserializer entryDeserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0x8000, 12, MatchEntries.class)); + MatchEntries entry = entryDeserializer.deserialize(buffer); Assert.assertEquals("Wrong Ipv4 address format", new Ipv4Address("0.1.2.3"), entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address()); } @@ -115,8 +134,9 @@ public class MatchDeserializerTest { public void testIpv6Address() { ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 34 10 00 00 00 01 00 02 00 03 00 04 00 05 00 06 0F 07"); - List list = MatchDeserializer.createMatchEntry(buffer, 20); - MatchEntries entry = list.get(0); + OFDeserializer entryDeserializer = registry.getDeserializer( + new EnhancedMessageCodeKey(EncodeConstants.OF13_VERSION_ID, 0x8000, 26, MatchEntries.class)); + MatchEntries entry = entryDeserializer.deserialize(buffer); Assert.assertEquals("Wrong Ipv6 address format", new Ipv6Address("0000:0001:0002:0003:0004:0005:0006:0F07"), entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address()); } @@ -128,9 +148,9 @@ public class MatchDeserializerTest { public void testMatch() { ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 01 AC " + "80 00 00 04 00 00 00 01 " - + "00 00 02 04 00 00 00 02 " - + "00 01 05 10 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 04 " - + "FF FF 07 0C 00 00 00 00 00 05 00 00 00 00 00 06 " + + "80 00 02 04 00 00 00 02 " + + "80 00 05 10 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 04 " + + "80 00 07 0C 00 00 00 00 00 05 00 00 00 00 00 06 " + "80 00 09 0C 00 00 00 00 00 07 00 00 00 00 00 08 " + "80 00 0A 02 00 09 " + "80 00 0D 04 00 0A 00 0B " @@ -171,7 +191,7 @@ public class MatchDeserializerTest { + "80 00 4F 04 01 66 03 04 " + "00 00 00 00"); - Match match = MatchDeserializer.createMatch(buffer); + Match match = matchDeserializer.deserialize(buffer); Assert.assertEquals("Wrong match type", OxmMatchType.class, match.getType()); Assert.assertEquals("Wrong match entries size", 40, match.getMatchEntries().size()); List entries = match.getMatchEntries(); @@ -182,13 +202,13 @@ public class MatchDeserializerTest { Assert.assertEquals("Wrong entry value", 1, entry0.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); MatchEntries entry1 = entries.get(1); - Assert.assertEquals("Wrong entry class", Nxm0Class.class, entry1.getOxmClass()); + Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry1.getOxmClass()); Assert.assertEquals("Wrong entry field", InPhyPort.class, entry1.getOxmMatchField()); Assert.assertEquals("Wrong entry hasMask", false, entry1.isHasMask()); Assert.assertEquals("Wrong entry value", 2, entry1.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); MatchEntries entry2 = entries.get(2); - Assert.assertEquals("Wrong entry class", Nxm1Class.class, entry2.getOxmClass()); + Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry2.getOxmClass()); Assert.assertEquals("Wrong entry field", Metadata.class, entry2.getOxmMatchField()); Assert.assertEquals("Wrong entry hasMask", true, entry2.isHasMask()); Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 03"), @@ -196,7 +216,7 @@ public class MatchDeserializerTest { Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 04"), entry2.getAugmentation(MaskMatchEntry.class).getMask()); MatchEntries entry3 = entries.get(3); - Assert.assertEquals("Wrong entry class", ExperimenterClass.class, entry3.getOxmClass()); + Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry3.getOxmClass()); Assert.assertEquals("Wrong entry field", EthDst.class, entry3.getOxmMatchField()); Assert.assertEquals("Wrong entry hasMask", true, entry3.isHasMask()); Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:05"), diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializerTest.java index 62b00a8f..af7ee7aa 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializerTest.java @@ -12,10 +12,14 @@ import io.netty.buffer.ByteBuf; import java.util.List; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; @@ -31,6 +35,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 */ public class OF10ActionsDeserializerTest { + private OFDeserializer actionsDeserializer; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + actionsDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, + Action.class)); + } + /** * Testing correct deserialization of actions (OF v1.0) */ @@ -47,12 +65,12 @@ public class OF10ActionsDeserializerTest { + "00 08 00 08 01 00 00 00 " + "00 09 00 08 00 02 00 00 " + "00 0A 00 08 00 03 00 00 " - + "00 0B 00 10 00 04 00 00 00 00 00 00 00 00 00 30 " - + "FF FF 00 08 00 00 12 34"); + + "00 0B 00 10 00 04 00 00 00 00 00 00 00 00 00 30"); message.skipBytes(4); // skip XID - List actions = OF10ActionsDeserializer.createActionsList(message); - Assert.assertEquals("Wrong number of actions", 13, actions.size()); + List actions = DecodingUtils.deserializeList(message.readableBytes(), + message, actionsDeserializer); + Assert.assertEquals("Wrong number of actions", 12, actions.size()); Action action1 = actions.get(0); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight" + ".openflow.common.action.rev130731.Output", action1.getType().getName()); @@ -114,11 +132,6 @@ public class OF10ActionsDeserializerTest { .getPort().getValue().intValue()); Assert.assertEquals("Wrong queue-id", 48, action12.getAugmentation(QueueIdAction.class).getQueueId().intValue()); - Action action13 = actions.get(12); - Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight" - + ".openflow.common.action.rev130731.Experimenter", action13.getType().getName()); - Assert.assertEquals("Wrong port", 4660, action13.getAugmentation(ExperimenterAction.class) - .getExperimenter().intValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java index 61da809f..55e129e6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.util; import io.netty.buffer.ByteBuf; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; @@ -23,6 +28,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc */ public class OF10MatchDeserializerTest { + private OFDeserializer matchDeserializer; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + matchDeserializer = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); + } + /** * Testing correct deserialization of ofp_match */ @@ -32,7 +50,7 @@ public class OF10MatchDeserializerTest { + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " + "50 50 20 20"); message.skipBytes(4); // skip XID - MatchV10 match = OF10MatchDeserializer.createMatchV10(message); + MatchV10 match = matchDeserializer.deserialize(message); Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false, false, true, false, true, true, false), match.getWildcards()); Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue()); @@ -60,7 +78,7 @@ public class OF10MatchDeserializerTest { + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " + "50 50 20 20"); message.skipBytes(4); // skip XID - MatchV10 match = OF10MatchDeserializer.createMatchV10(message); + MatchV10 match = matchDeserializer.deserialize(message); Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true), match.getWildcards()); Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue()); diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java index 2a7a8976..7cbae3f0 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java @@ -18,7 +18,6 @@ import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory; diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java index 8b4b958a..a61f1033 100644 --- a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java +++ b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java @@ -13,6 +13,8 @@ import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfigura import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer; import org.opendaylight.yangtools.yang.binding.DataObject; import com.google.common.util.concurrent.ListenableFuture; @@ -54,4 +56,12 @@ public interface SwitchConnectionProvider extends AutoCloseable { */ public void registerCustomSerializer(MessageTypeKey key, OFSerializer serializer); + + /** + * Registers custom deserializer + * @param key used for deserializer lookup + * @param deserializer deserializer instance + */ + public void registerDeserializer(MessageCodeKey key, OFGeneralDeserializer deserializer); + } -- 2.36.6