From 1adc52b6fedfc7ecdb03cb6cab5ae7da3bfb52e4 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Thu, 3 Apr 2014 14:59:20 +0200 Subject: [PATCH] Extensibility support (serialization part) Signed-off-by: Michal Polkorab Change-Id: I51778a009f9a20d6ba1f29b74ca1e3fc1350d8bd --- openflow-protocol-api/pom.xml | 4 + .../api/extensibility/HeaderSerializer.java | 27 + .../api/extensibility}/MessageTypeKey.java | 7 +- .../extensibility/OFGeneralSerializer.java | 17 + .../api/extensibility/OFSerializer.java | 30 + .../api/extensibility/RegistryInjector.java | 22 + .../api/extensibility/SerializerRegistry.java | 37 ++ .../SwitchConnectionProviderImpl.java | 28 +- .../protocol/impl/core/OFEncoder.java | 14 +- .../core/PublishingChannelInitializer.java | 16 +- .../protocol/impl/core/TcpHandler.java | 7 + .../EnhancedMessageTypeKey.java | 62 ++ .../factories/HelloMessageFactory.java | 10 +- .../impl/serialization/EncoderTable.java | 139 ---- .../MatchEntriesInitializer.java | 151 +++++ .../MessageFactoryInitializer.java | 105 +++ .../impl/serialization/OFSerializer.java | 42 -- .../serialization/SerializationFactory.java | 30 +- .../serialization/SerializerRegistryImpl.java | 91 +++ .../factories/BarrierInputMessageFactory.java | 34 +- .../factories/EchoInputMessageFactory.java | 43 +- .../EchoReplyInputMessageFactory.java | 43 +- .../ExperimenterInputMessageFactory.java | 71 -- .../factories/FlowModInputMessageFactory.java | 79 +-- .../GetAsyncRequestMessageFactory.java | 36 +- .../GetConfigInputMessageFactory.java | 36 +- .../GetFeaturesInputMessageFactory.java | 36 +- .../GetQueueConfigInputMessageFactory.java | 40 +- .../GroupModInputMessageFactory.java | 89 +-- .../factories/HelloInputMessageFactory.java | 86 +-- .../MeterModInputMessageFactory.java | 51 +- .../MultipartRequestInputFactory.java | 276 +++----- .../OF10BarrierInputMessageFactory.java | 33 +- .../OF10FlowModInputMessageFactory.java | 75 +-- .../OF10HelloInputMessageFactory.java | 32 +- .../OF10PacketOutInputMessageFactory.java | 64 +- .../OF10PortModInputMessageFactory.java | 49 +- ...OF10QueueGetConfigInputMessageFactory.java | 39 +- .../OF10StatsRequestInputFactory.java | 91 ++- .../OF10VendorInputMessageFactory.java | 69 -- .../PacketOutInputMessageFactory.java | 68 +- .../factories/PortModInputMessageFactory.java | 52 +- .../RoleRequestInputMessageFactory.java | 45 +- .../SetAsyncInputMessageFactory.java | 50 +- .../factories/SetConfigMessageFactory.java | 41 +- .../TableModInputMessageFactory.java | 41 +- .../AbstractOxmIpv4AddressSerializer.java | 36 ++ .../AbstractOxmIpv6AddressSerializer.java | 77 +++ .../AbstractOxmMacAddressSerializer.java | 29 + .../AbstractOxmMatchEntrySerializer.java | 73 +++ .../match/AbstractOxmMetadataSerializer.java | 27 + .../AbstractOxmPortNumberSerializer.java | 26 + .../match/AbstractOxmPortSerializer.java | 26 + .../match/OxmArpOpSerializer.java | 43 ++ .../match/OxmArpShaSerializer.java | 33 + .../match/OxmArpSpaSerializer.java | 33 + .../match/OxmArpThaSerializer.java | 33 + .../match/OxmArpTpaSerializer.java | 33 + .../match/OxmEthDstSerializer.java | 33 + .../match/OxmEthSrcSerializer.java | 33 + .../match/OxmEthTypeSerializer.java | 43 ++ .../match/OxmIcmpv4CodeSerializer.java | 43 ++ .../match/OxmIcmpv4TypeSerializer.java | 43 ++ .../match/OxmIcmpv6CodeSerializer.java | 43 ++ .../match/OxmIcmpv6TypeSerializer.java | 43 ++ .../match/OxmInPhyPortSerializer.java | 33 + .../match/OxmInPortSerializer.java | 33 + .../match/OxmIpDscpSerializer.java | 43 ++ .../match/OxmIpEcnSerializer.java | 43 ++ .../match/OxmIpProtoSerializer.java | 43 ++ .../match/OxmIpv4DstSerializer.java | 33 + .../match/OxmIpv4SrcSerializer.java | 33 + .../match/OxmIpv6DstSerializer.java | 33 + .../match/OxmIpv6ExtHdrSerializer.java | 61 ++ .../match/OxmIpv6FlabelSerializer.java | 44 ++ .../match/OxmIpv6NdSllSerializer.java | 33 + .../match/OxmIpv6NdTargetSerializer.java | 33 + .../match/OxmIpv6NdTllSerializer.java | 33 + .../match/OxmIpv6SrcSerializer.java | 33 + .../match/OxmMetadataSerializer.java | 33 + .../match/OxmMplsBosSerializer.java | 43 ++ .../match/OxmMplsLabelSerializer.java | 43 ++ .../match/OxmMplsTcSerializer.java | 43 ++ .../match/OxmPbbIsidSerializer.java | 44 ++ .../match/OxmSctpDstSerializer.java | 33 + .../match/OxmSctpSrcSerializer.java | 33 + .../match/OxmTcpDstSerializer.java | 33 + .../match/OxmTcpSrcSerializer.java | 33 + .../match/OxmTunnelIdSerializer.java | 33 + .../match/OxmUdpDstSerializer.java | 33 + .../match/OxmUdpSrcSerializer.java | 34 + .../match/OxmVlanPcpSerializer.java | 44 ++ .../match/OxmVlanVidSerializer.java | 52 ++ .../impl/util/ActionsDeserializer.java | 2 +- .../protocol/impl/util/ByteBufUtils.java | 22 +- .../protocol/impl/util/CodingUtils.java | 51 ++ .../util/CommonMessageRegistryHelper.java | 39 ++ .../protocol/impl/util/EncodeConstants.java | 11 +- .../impl/util/InstructionsSerializer.java | 185 ------ .../impl/util/MatchIdsSerializer.java | 210 ------ .../protocol/impl/util/MatchSerializer.java | 609 ------------------ .../impl/util/OF10ActionsSerializer.java | 138 ++-- .../impl/util/OF10MatchSerializer.java | 52 +- ...alizer.java => OF13ActionsSerializer.java} | 259 +++----- .../impl/util/OF13InstructionsSerializer.java | 143 ++++ .../util/OF13MatchEntriesRegistryHelper.java | 44 ++ .../impl/util/OF13MatchSerializer.java | 88 +++ .../protocol/impl/util/OxmMatchConstants.java | 106 +++ .../BarrierInputMessageFactoryTest.java | 26 +- .../EchoInputMessageFactoryTest.java | 28 +- .../EchoReplyInputMessageFactoryTest.java | 28 +- .../ExperimenterInputMessageFactoryTest.java | 58 -- .../FlowModInputMessageFactoryTest.java | 65 +- .../GetConfigInputMessageFactoryTest.java | 30 +- .../GetFeaturesInputMessageFactoryTest.java | 32 +- ...GetQueueConfigInputMessageFactoryTest.java | 26 +- .../GetaAsyncRequestMessageFactoryTest.java | 24 +- .../GroupModInputMessageFactoryTest.java | 29 +- .../HelloInputMessageFactoryTest.java | 38 +- .../MeterModInputMessageFactoryTest.java | 25 +- .../MultipartRequestInputFactoryTest.java | 113 ++-- .../OF10BarrierInputMessageFactoryTest.java | 22 +- .../OF10FlowModInputMessageFactoryTest.java | 24 +- .../OF10HelloInputMessageFactoryTest.java | 22 +- .../OF10PacketOutInputMessageFactoryTest.java | 23 +- .../OF10PortModInputMessageFactoryTest.java | 22 +- ...QueueGetConfigInputMessageFactoryTest.java | 22 +- .../OF10StatsRequestInputFactoryTest.java | 53 +- .../OF10VendorInputMessageFactoryTest.java | 50 -- .../PacketOutInputMessageFactoryTest.java | 24 +- .../PortModInputMessageFactoryTest.java | 24 +- .../RoleRequestInputMessageFactoryTest.java | 24 +- .../SetAsyncInputMessageFactoryTest.java | 25 +- .../SetConfigMessageFactoryTest.java | 26 +- .../TableModInputMessageFactoryTest.java | 24 +- .../multipart/TableFeaturesTest.java | 44 +- .../protocol/impl/util/BufferHelper.java | 18 +- .../impl/util/OF10ActionsSerializerTest.java | 33 +- .../impl/util/OF10MatchSerializerTest.java | 25 +- ...st.java => OF13ActionsSerializerTest.java} | 39 +- ...va => OF13InstructionsSerializerTest.java} | 23 +- ...Test.java => OF13MatchSerializerTest.java} | 48 +- ...st2.java => OF13MatchSerializerTest2.java} | 46 +- .../connection/SwitchConnectionProvider.java | 12 +- pom.xml | 5 + 145 files changed, 4312 insertions(+), 3170 deletions(-) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderSerializer.java rename {openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization => openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility}/MessageTypeKey.java (89%) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralSerializer.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/RegistryInjector.java create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/EnhancedMessageTypeKey.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MatchEntriesInitializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv4AddressSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMacAddressSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMatchEntrySerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMetadataSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortNumberSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPhyPortSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPortSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpEcnSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6DstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6FlabelSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTargetSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6SrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodingUtils.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CommonMessageRegistryHelper.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchIdsSerializer.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java rename openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/{ActionsSerializer.java => OF13ActionsSerializer.java} (52%) create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchEntriesRegistryHelper.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializer.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java rename openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/{ActionsSerializerTest.java => OF13ActionsSerializerTest.java} (90%) rename openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/{InstructionsSerializerTest.java => OF13InstructionsSerializerTest.java} (90%) rename openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/{MatchSerializerTest.java => OF13MatchSerializerTest.java} (91%) rename openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/{MatchSerializerTest2.java => OF13MatchSerializerTest2.java} (95%) diff --git a/openflow-protocol-api/pom.xml b/openflow-protocol-api/pom.xml index 099ca0a8..9670e71e 100644 --- a/openflow-protocol-api/pom.xml +++ b/openflow-protocol-api/pom.xml @@ -138,6 +138,10 @@ org.opendaylight.controller.model model-flow-service + + io.netty + netty-buffer + junit junit diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderSerializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderSerializer.java new file mode 100644 index 00000000..3392f817 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderSerializer.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 org.opendaylight.yangtools.yang.binding.DataObject; + +import io.netty.buffer.ByteBuf; + +/** + * Does only-header serialization (such as oxm_ids, action_ids, instruction_ids) + * @author michal.polkorab + * @param + */ +public interface HeaderSerializer extends OFGeneralSerializer { + + /** + * Serializes object headers (e.g. for Multipart message - Table Features) + * @param input object whose headers should be serialized + * @param outBuffer output buffer + */ + public void serializeHeader(SERIALIZER_TYPE input, ByteBuf outBuffer); +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageTypeKey.java similarity index 89% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java rename to openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageTypeKey.java index 38cdcda9..65d3823d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageTypeKey.java @@ -6,17 +6,16 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowjava.protocol.impl.serialization; +package org.opendaylight.openflowjava.protocol.api.extensibility; -import org.opendaylight.yangtools.yang.binding.DataObject; /** - * Class used as a key in {@link EncoderTable} + * Class used as a key in {@link SerializerRegistry} * @author michal.polkorab * @author timotej.kubas * @param message type (class) */ -public class MessageTypeKey { +public class MessageTypeKey { private final Class msgType; private final short msgVersion; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralSerializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralSerializer.java new file mode 100644 index 00000000..0001c3e9 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralSerializer.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; + +/** + * Unifying superinterface + * @author michal.polkorab + * */ +public interface OFGeneralSerializer { + + // empty unifying superinterface +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java new file mode 100644 index 00000000..2572a6f2 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.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.api.extensibility; + +import org.opendaylight.yangtools.yang.binding.DataObject; + +import io.netty.buffer.ByteBuf; + +/** + * Uniform interface for serializers + * @author michal.polkorab + * @author timotej.kubas + * @param message type + */ +public interface OFSerializer extends OFGeneralSerializer { + + /** + * Transforms POJO/DTO into byte message (ByteBuf). + * @param input object to be serialized + * @param outBuffer output buffer + */ + public void serialize(SERIALIZER_TYPE input, ByteBuf outBuffer); + +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/RegistryInjector.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/RegistryInjector.java new file mode 100644 index 00000000..9c1b5373 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/RegistryInjector.java @@ -0,0 +1,22 @@ +/* + * 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; + +/** + * Serializer registry injector + * @author michal.polkorab + */ +public interface RegistryInjector { + + /** + * Injects serializer registry + * @param serializerRegistry registry instance + */ + public void injectSerializerRegistry(SerializerRegistry serializerRegistry); + +} diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.java new file mode 100644 index 00000000..b5eec47f --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.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.api.extensibility; + + +/** + * Stores and handles serializers + * @author michal.polkorab + * + */ +public interface SerializerRegistry { + + /** + * Serializer registry provisioning + */ + public void init(); + + /** + * @param msgTypeKey lookup key + * @return serializer or NullPointerException if no serializer was found + */ + public SERIALIZER_TYPE + getSerializer(MessageTypeKey msgTypeKey); + + /** + * Registers serializer under key + * @param msgTypeKey lookup key + * @param serializer serializer implementation + */ + public void + registerSerializer(MessageTypeKey msgTypeKey, OFGeneralSerializer serializer); +} 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 3e45b174..a8bceeea 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 @@ -9,13 +9,17 @@ package org.opendaylight.openflowjava.protocol.impl.connection; -import java.util.concurrent.Future; - import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; 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.SerializerRegistry; 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.spi.connection.SwitchConnectionProvider; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,12 +32,22 @@ import com.google.common.util.concurrent.SettableFuture; * @author michal.polkorab */ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { - + private static final Logger LOGGER = LoggerFactory .getLogger(SwitchConnectionProviderImpl.class); private SwitchConnectionHandler switchConnectionHandler; private ServerFacade serverFacade; private ConnectionConfiguration connConfig; + private SerializationFactory serializationFactory; + private SerializerRegistry serializerRegistry; + + /** Constructor */ + public SwitchConnectionProviderImpl() { + serializerRegistry = new SerializerRegistryImpl(); + serializerRegistry.init(); + serializationFactory = new SerializationFactory(); + serializationFactory.setSerializerTable(serializerRegistry); + } @Override public void setConfiguration(ConnectionConfiguration connConfig) { @@ -91,7 +105,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { server.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout()); boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport()); server.setEncryption(tlsSupported); - + server.setSerializationFactory(serializationFactory); return server; } @@ -102,6 +116,12 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { return serverFacade; } + @Override + public void registerCustomSerializer(MessageTypeKey key, + OFSerializer serializer) { + serializerRegistry.registerSerializer(key, serializer); + } + @Override public void close() throws Exception { shutdown(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java index 62972b70..38cb8893 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java @@ -25,18 +25,19 @@ import org.slf4j.LoggerFactory; public class OFEncoder extends MessageToByteEncoder { private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class); - + private SerializationFactory serializationFactory; + /** Constructor of class */ public OFEncoder() { LOGGER.trace("Creating OF13Encoder"); } - + @Override protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out) throws Exception { LOGGER.trace("Encoding"); try { - SerializationFactory.messageToBuffer(msg.getVersion(), out, msg); + serializationFactory.messageToBuffer(msg.getVersion(), out, msg); } catch(Exception e) { LOGGER.error("Message serialization failed"); LOGGER.error(e.getMessage(), e); @@ -51,4 +52,11 @@ public class OFEncoder extends MessageToByteEncoder { } } + /** + * @param serializationFactory + */ + public void setSerializationFactory(SerializationFactory serializationFactory) { + this.serializationFactory = serializationFactory; + } + } 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 9b35e14e..5a35864b 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 @@ -21,6 +21,7 @@ import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHan import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +37,8 @@ public class PublishingChannelInitializer extends ChannelInitializer main type + * @param specific type + */ +public class EnhancedMessageTypeKey extends MessageTypeKey { + + private final Class msgType2; + + /** + * @param msgVersion + * @param msgType + * @param msgType2 + */ + public EnhancedMessageTypeKey(short msgVersion, Class msgType, Class msgType2) { + super(msgVersion, msgType); + this.msgType2 = msgType2; + } + + /** + * @return more specific type + */ + public Class getMsgType2() { + return msgType2; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + @SuppressWarnings("rawtypes") + EnhancedMessageTypeKey other = (EnhancedMessageTypeKey) obj; + if (msgType2 == null) { + if (other.msgType2 != null) + return false; + } else if (!msgType2.equals(other.msgType2)) + return false; + return true; + } + + @Override + public String toString() { + return super.toString() + " msgType2: " + msgType2.getName(); + } +} 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 eeb9893e..00e37b06 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 @@ -8,13 +8,12 @@ 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.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; 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; @@ -30,7 +29,8 @@ 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 } @@ -64,7 +64,7 @@ public class HelloMessageFactory implements OFDeserializer { int elementLength = input.readUnsignedShort(); if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { elementsBuilder.setType(HelloElementType.forValue(type)); - int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; + int[] versionBitmap = new int[(elementLength - HELLO_ELEMENT_HEADER_SIZE) / 4]; for (int i = 0; i < versionBitmap.length; i++) { versionBitmap[i] = (int) input.readUnsignedInt(); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java deleted file mode 100644 index 3a1e0d06..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java +++ /dev/null @@ -1,139 +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.serialization; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.ExperimenterInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10VendorInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * Stores and provides correct encoders for received messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class EncoderTable { - - private static final short OF10 = EncodeConstants.OF10_VERSION_ID; - private static final short OF13 = EncodeConstants.OF13_VERSION_ID; - private static EncoderTable instance; - private Map, OFSerializer> table; - - - private EncoderTable() { - // do nothing - } - - /** - * @return singleton instance - */ - public static synchronized EncoderTable getInstance() { - if (instance == null) { - instance = new EncoderTable(); - instance.init(); - } - return instance; - } - - /** - * Encoder table provisioning - */ - public void init() { - table = new HashMap<>(); - table.put(new MessageTypeKey<>(OF10, BarrierInput.class), OF10BarrierInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, EchoInput.class), EchoInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, ExperimenterInput.class), OF10VendorInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, FlowModInput.class), OF10FlowModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetQueueConfigInput.class), OF10QueueGetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, HelloInput.class), OF10HelloInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, MultipartRequestInput.class), OF10StatsRequestInputFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, PacketOutInput.class), OF10PacketOutInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, PortModInput.class), OF10PortModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, SetConfigInput.class), SetConfigMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, BarrierInput.class), BarrierInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, EchoInput.class), EchoInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, ExperimenterInput.class), ExperimenterInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, FlowModInput.class), FlowModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetAsyncInput.class), GetAsyncRequestMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetQueueConfigInput.class), GetQueueConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GroupModInput.class), GroupModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, HelloInput.class), HelloInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, MeterModInput.class), MeterModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, MultipartRequestInput.class), MultipartRequestInputFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, PacketOutInput.class), PacketOutInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, PortModInput.class), PortModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, RoleRequestInput.class), RoleRequestInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, SetAsyncInput.class), SetAsyncInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, SetConfigInput.class), SetConfigMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, TableModInput.class), TableModInputMessageFactory.getInstance()); - } - - /** - * @param msgTypeKey - * @return encoder for current type of message (msgTypeKey) - */ - @SuppressWarnings("unchecked") - public OFSerializer getEncoder(MessageTypeKey msgTypeKey) { - return (OFSerializer) table.get(msgTypeKey); - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MatchEntriesInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MatchEntriesInitializer.java new file mode 100644 index 00000000..094b6f26 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MatchEntriesInitializer.java @@ -0,0 +1,151 @@ +/* + * 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.serialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpOpSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpShaSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpSpaSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpThaSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpTpaSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthDstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthSrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthTypeSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4CodeSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4TypeSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6CodeSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6TypeSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPhyPortSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPortSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpDscpSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpEcnSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpProtoSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4DstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4SrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6DstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6ExtHdrSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6FlabelSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdSllSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTargetSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTllSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6SrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMetadataSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsBosSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsLabelSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsTcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmPbbIsidSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpDstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpSrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpDstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpSrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTunnelIdSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpDstSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpSrcSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanPcpSerializer; +import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanVidSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchEntriesRegistryHelper; +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.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.OpenflowBasicClass; +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; + +/** + * Initializes serializer registry with match entry serializers + * @author michal.polkorab + */ +public class MatchEntriesInitializer { + + /** + * Registers match entry serializers into provided registry + * @param serializerRegistry registry to be initialized with match entry serializers + */ + public static void registerMatchEntrySerializers(SerializerRegistry serializerRegistry) { + // register OF v1.3 OpenflowBasicClass match entry serializers + Class oxmClass = OpenflowBasicClass.class; + OF13MatchEntriesRegistryHelper registryHelper = + new OF13MatchEntriesRegistryHelper<>(EncodeConstants.OF13_VERSION_ID, oxmClass, serializerRegistry); + registryHelper.registerSerializer(InPort.class, new OxmInPortSerializer()); + registryHelper.registerSerializer(InPhyPort.class, new OxmInPhyPortSerializer()); + registryHelper.registerSerializer(Metadata.class, new OxmMetadataSerializer()); + registryHelper.registerSerializer(EthDst.class, new OxmEthDstSerializer()); + registryHelper.registerSerializer(EthSrc.class, new OxmEthSrcSerializer()); + registryHelper.registerSerializer(EthType.class, new OxmEthTypeSerializer()); + registryHelper.registerSerializer(VlanVid.class, new OxmVlanVidSerializer()); + registryHelper.registerSerializer(VlanPcp.class, new OxmVlanPcpSerializer()); + registryHelper.registerSerializer(IpDscp.class, new OxmIpDscpSerializer()); + registryHelper.registerSerializer(IpEcn.class, new OxmIpEcnSerializer()); + registryHelper.registerSerializer(IpProto.class, new OxmIpProtoSerializer()); + registryHelper.registerSerializer(Ipv4Src.class, new OxmIpv4SrcSerializer()); + registryHelper.registerSerializer(Ipv4Dst.class, new OxmIpv4DstSerializer()); + registryHelper.registerSerializer(TcpSrc.class, new OxmTcpSrcSerializer()); + registryHelper.registerSerializer(TcpDst.class, new OxmTcpDstSerializer()); + registryHelper.registerSerializer(UdpSrc.class, new OxmUdpSrcSerializer()); + registryHelper.registerSerializer(UdpDst.class, new OxmUdpDstSerializer()); + registryHelper.registerSerializer(SctpSrc.class, new OxmSctpSrcSerializer()); + registryHelper.registerSerializer(SctpDst.class, new OxmSctpDstSerializer()); + registryHelper.registerSerializer(Icmpv4Type.class, new OxmIcmpv4TypeSerializer()); + registryHelper.registerSerializer(Icmpv4Code.class, new OxmIcmpv4CodeSerializer()); + registryHelper.registerSerializer(ArpOp.class, new OxmArpOpSerializer()); + registryHelper.registerSerializer(ArpSpa.class, new OxmArpSpaSerializer()); + registryHelper.registerSerializer(ArpTpa.class, new OxmArpTpaSerializer()); + registryHelper.registerSerializer(ArpSha.class, new OxmArpShaSerializer()); + registryHelper.registerSerializer(ArpTha.class, new OxmArpThaSerializer()); + registryHelper.registerSerializer(Ipv6Src.class, new OxmIpv6SrcSerializer()); + registryHelper.registerSerializer(Ipv6Dst.class, new OxmIpv6DstSerializer()); + registryHelper.registerSerializer(Ipv6Flabel.class, new OxmIpv6FlabelSerializer()); + registryHelper.registerSerializer(Icmpv6Type.class, new OxmIcmpv6TypeSerializer()); + registryHelper.registerSerializer(Icmpv6Code.class, new OxmIcmpv6CodeSerializer()); + registryHelper.registerSerializer(Ipv6NdTarget.class, new OxmIpv6NdTargetSerializer()); + registryHelper.registerSerializer(Ipv6NdSll.class, new OxmIpv6NdSllSerializer()); + registryHelper.registerSerializer(Ipv6NdTll.class, new OxmIpv6NdTllSerializer()); + registryHelper.registerSerializer(MplsLabel.class, new OxmMplsLabelSerializer()); + registryHelper.registerSerializer(MplsTc.class, new OxmMplsTcSerializer()); + registryHelper.registerSerializer(MplsBos.class, new OxmMplsBosSerializer()); + registryHelper.registerSerializer(PbbIsid.class, new OxmPbbIsidSerializer()); + registryHelper.registerSerializer(TunnelId.class, new OxmTunnelIdSerializer()); + registryHelper.registerSerializer(Ipv6Exthdr.class, new OxmIpv6ExtHdrSerializer()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java new file mode 100644 index 00000000..c8d035a6 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java @@ -0,0 +1,105 @@ +/* + * 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.serialization; + +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.CommonMessageRegistryHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; + +/** + * @author michal.polkorab + * + */ +public class MessageFactoryInitializer { + + /** + * Registers message serializers into provided registry + * @param serializerRegistry registry to be initialized with message serializers + */ + public static void registerMessageSerializers(SerializerRegistry serializerRegistry) { + // register OF v1.0 message serializers + short version = EncodeConstants.OF10_VERSION_ID; + CommonMessageRegistryHelper registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry); + registryHelper.registerSerializer(BarrierInput.class, new OF10BarrierInputMessageFactory()); + registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory()); + registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory()); + registryHelper.registerSerializer(FlowModInput.class, new OF10FlowModInputMessageFactory()); + registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory()); + registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory()); + registryHelper.registerSerializer(GetQueueConfigInput.class, new OF10QueueGetConfigInputMessageFactory()); + registryHelper.registerSerializer(HelloInput.class, new OF10HelloInputMessageFactory()); + registryHelper.registerSerializer(MultipartRequestInput.class, new OF10StatsRequestInputFactory()); + registryHelper.registerSerializer(PacketOutInput.class, new OF10PacketOutInputMessageFactory()); + registryHelper.registerSerializer(PortModInput.class, new OF10PortModInputMessageFactory()); + registryHelper.registerSerializer(SetConfigInput.class, new SetConfigMessageFactory()); + // register OF v1.0 message serializers + version = EncodeConstants.OF13_VERSION_ID; + registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry); + registryHelper.registerSerializer(BarrierInput.class, new BarrierInputMessageFactory()); + registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory()); + registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory()); + registryHelper.registerSerializer(FlowModInput.class, new FlowModInputMessageFactory()); + registryHelper.registerSerializer(GetAsyncInput.class, new GetAsyncRequestMessageFactory()); + registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory()); + registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory()); + registryHelper.registerSerializer(GetQueueConfigInput.class, new GetQueueConfigInputMessageFactory()); + registryHelper.registerSerializer(GroupModInput.class, new GroupModInputMessageFactory()); + registryHelper.registerSerializer(HelloInput.class, new HelloInputMessageFactory()); + registryHelper.registerSerializer(MeterModInput.class, new MeterModInputMessageFactory()); + registryHelper.registerSerializer(MultipartRequestInput.class, new MultipartRequestInputFactory()); + registryHelper.registerSerializer(PacketOutInput.class, new PacketOutInputMessageFactory()); + registryHelper.registerSerializer(PortModInput.class, new PortModInputMessageFactory()); + registryHelper.registerSerializer(RoleRequestInput.class, new RoleRequestInputMessageFactory()); + registryHelper.registerSerializer(SetAsyncInput.class, new SetAsyncInputMessageFactory()); + registryHelper.registerSerializer( SetConfigInput.class, new SetConfigMessageFactory()); + registryHelper.registerSerializer(TableModInput.class, new TableModInputMessageFactory()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java deleted file mode 100644 index f514f140..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java +++ /dev/null @@ -1,42 +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.serialization; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * Uniform interface for serializing factories - * @author michal.polkorab - * @author timotej.kubas - * @param message type - */ -public interface OFSerializer { - - /** - * Transforms POJO/DTO into byte message (ByteBuf). - * @param version version of used OF Protocol - * @param out ByteBuf used for output - * @param message message that will be transformed into ByteBuf - */ - public abstract void messageToBuffer(short version, ByteBuf out, E message); - - /** - * Compute length of received message - * @param message - * @return computed length - */ - public abstract int computeLength(E message); - - /** - * @return message code type - */ - public byte getMessageType(); -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java index 18449f70..d9ad3abc 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java @@ -10,9 +10,10 @@ package org.opendaylight.openflowjava.protocol.impl.serialization; import io.netty.buffer.ByteBuf; +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.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author michal.polkorab @@ -20,22 +21,27 @@ import org.slf4j.LoggerFactory; */ public class SerializationFactory { - private static final Logger LOGGER = LoggerFactory - .getLogger(SerializationFactory.class); + private SerializerRegistry registry; + /** * Transforms POJO message into ByteBuf * @param version version used for encoding received message * @param out ByteBuf for storing and sending transformed message * @param message POJO message */ - public static void messageToBuffer(short version, ByteBuf out, E message) { - @SuppressWarnings("unchecked") - MessageTypeKey msgTypeKey = new MessageTypeKey<>(version, (Class) message.getClass()); - OFSerializer encoder = EncoderTable.getInstance().getEncoder(msgTypeKey); - if (encoder != null) { - encoder.messageToBuffer(version, out, message); - } else { - LOGGER.warn("No correct encoder found in EncoderTable for arguments: " + msgTypeKey.toString()); + public void messageToBuffer(short version, ByteBuf out, DataObject message) { + OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(version, message.getClass())); + if (serializer != null) { + serializer.serialize(message, out); } } + + /** + * @param serializerRegistry registry with serializers + */ + public void setSerializerTable(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; + } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java new file mode 100644 index 00000000..9a9a1b0c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java @@ -0,0 +1,91 @@ +/* + * 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.serialization; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF13ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF13InstructionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializer; +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 handles serializers + * @author michal.polkorab + * @author timotej.kubas + */ +public class SerializerRegistryImpl implements SerializerRegistry { + + private static final short OF10 = EncodeConstants.OF10_VERSION_ID; + private static final short OF13 = EncodeConstants.OF13_VERSION_ID; + private Map, OFGeneralSerializer> registry; + + + @Override + public void init() { + registry = new HashMap<>(); + // Openflow message type serializers + MessageFactoryInitializer.registerMessageSerializers(this); + + // common structure serializers + registerSerializer(new MessageTypeKey<>(OF10, MatchV10.class), new OF10MatchSerializer()); + registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer()); + registerSerializer(new MessageTypeKey<>(OF10, Action.class), new OF10ActionsSerializer()); + registerSerializer(new MessageTypeKey<>(OF13, Action.class), new OF13ActionsSerializer()); + registerSerializer(new MessageTypeKey<>(OF13, Instruction.class), new OF13InstructionsSerializer()); + + // match entry serializers + MatchEntriesInitializer.registerMatchEntrySerializers(this); + } + + /** + * @param msgTypeKey + * @return encoder for current type of message (msgTypeKey) + */ + @Override + @SuppressWarnings("unchecked") + public SERIALIZER_TYPE getSerializer( + MessageTypeKey msgTypeKey) { + OFGeneralSerializer serializer = registry.get(msgTypeKey); + if (serializer == null) { + if (msgTypeKey instanceof EnhancedMessageTypeKey) { + EnhancedMessageTypeKey key = (EnhancedMessageTypeKey) msgTypeKey; + throw new NullPointerException("Serializer for key: " + key.toString() + + " was not found"); + } + throw new NullPointerException("Serializer for key: " + msgTypeKey.toString() + + " was not found"); + } + return (SERIALIZER_TYPE) serializer; + } + + @Override + public void registerSerializer( + MessageTypeKey msgTypeKey, OFGeneralSerializer serializer) { + if ((msgTypeKey == null) || (serializer == null)) { + throw new NullPointerException("MessageTypeKey or Serializer is null"); + } + if (serializer instanceof RegistryInjector) { + ((RegistryInjector) serializer).injectSerializerRegistry(this); + } + registry.put(msgTypeKey, serializer); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java index def00142..e10249a2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.BarrierInput; /** @@ -22,36 +23,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class BarrierInputMessageFactory implements OFSerializer { /** Code type of BarrierRequest message */ - public static final byte MESSAGE_TYPE = 20; - private static BarrierInputMessageFactory instance; - private static final int MESSAGE_LENGTH = 8; - - private BarrierInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized BarrierInputMessageFactory getInstance() { - if (instance == null) { - instance = new BarrierInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } + private static final byte MESSAGE_TYPE = 20; @Override - public int computeLength(BarrierInput message) { - return MESSAGE_LENGTH; + public void serialize(BarrierInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java index 9e1cfa5b..06ba0620 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.EchoInput; /** @@ -22,46 +23,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class EchoInputMessageFactory implements OFSerializer { /** Code type of EchoRequest message */ - public static final byte MESSAGE_TYPE = 2; - private static EchoInputMessageFactory instance; - private static final int MESSAGE_LENGTH = 8; - - private EchoInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoInputMessageFactory getInstance() { - if (instance == null) { - instance = new EchoInputMessageFactory(); - } - return instance; - } + private static final byte MESSAGE_TYPE = 2; @Override - public void messageToBuffer(short version, ByteBuf out, EchoInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); + public void serialize(EchoInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); byte[] data = message.getData(); if (data != null) { - out.writeBytes(data); + outBuffer.writeBytes(data); } + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public int computeLength(EchoInput message) { - int length = MESSAGE_LENGTH; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java index 3e76f8c0..5273a7b9 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.EchoReplyInput; /** @@ -22,46 +23,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class EchoReplyInputMessageFactory implements OFSerializer{ /** Code type of EchoReply message */ - public static final byte MESSAGE_TYPE = 3; - private static final int MESSAGE_LENGTH = 8; - private static EchoReplyInputMessageFactory instance; - - private EchoReplyInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoReplyInputMessageFactory getInstance() { - if (instance == null) { - instance = new EchoReplyInputMessageFactory(); - } - return instance; - } + private static final byte MESSAGE_TYPE = 3; @Override - public void messageToBuffer(short version, ByteBuf out, - EchoReplyInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); + public void serialize(EchoReplyInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); byte[] data = message.getData(); if (data != null) { - out.writeBytes(data); + outBuffer.writeBytes(data); + ByteBufUtils.updateOFHeaderLength(outBuffer); } } - @Override - public int computeLength(EchoReplyInput message) { - int length = MESSAGE_LENGTH; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java deleted file mode 100644 index ff24b6e0..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java +++ /dev/null @@ -1,71 +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.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -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.protocol.rev130731.ExperimenterInput; - -/** - * Translates Experimenter messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class ExperimenterInputMessageFactory implements OFSerializer{ - - /** Code type of Experimenter message */ - public static final byte MESSAGE_TYPE = 4; - private static final byte MESSAGE_LENGTH = 8; - private static ExperimenterInputMessageFactory instance; - - private ExperimenterInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized ExperimenterInputMessageFactory getInstance() { - if (instance == null) { - instance = new ExperimenterInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - ExperimenterInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getExperimenter().intValue()); - out.writeInt(message.getExpType().intValue()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(ExperimenterInput message) { - int length = MESSAGE_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java index ba4f9708..683a301c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java @@ -13,11 +13,16 @@ import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.FlowModFlags; +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.FlowModInput; /** @@ -25,54 +30,37 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class FlowModInputMessageFactory implements OFSerializer { +public class FlowModInputMessageFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 14; private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; - private static final int MESSAGE_LENGTH = 48; - private static FlowModInputMessageFactory instance; - - private FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeLong(message.getCookie().longValue()); - out.writeLong(message.getCookieMask().longValue()); - out.writeByte(message.getTableId().getValue().byteValue()); - out.writeByte(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeInt(message.getOutPort().getValue().intValue()); - out.writeInt(message.getOutGroup().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlags())); - ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out); - MatchSerializer.encodeMatch(message.getMatch(), out); - InstructionsSerializer.encodeInstructions(message.getInstruction(), out); - } + private SerializerRegistry registry; @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch()) - + InstructionsSerializer.computeInstructionsLength(message.getInstruction()); + public void serialize(FlowModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeLong(message.getCookie().longValue()); + outBuffer.writeLong(message.getCookieMask().longValue()); + outBuffer.writeByte(message.getTableId().getValue().byteValue()); + outBuffer.writeByte(message.getCommand().getIntValue()); + outBuffer.writeShort(message.getIdleTimeout().intValue()); + outBuffer.writeShort(message.getHardTimeout().intValue()); + outBuffer.writeShort(message.getPriority()); + outBuffer.writeInt(message.getBufferId().intValue()); + outBuffer.writeInt(message.getOutPort().getValue().intValue()); + outBuffer.writeInt(message.getOutGroup().intValue()); + outBuffer.writeShort(createFlowModFlagsBitmask(message.getFlags())); + ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, outBuffer); + registry.>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)) + .serialize(message.getMatch(), outBuffer); + OFSerializer instructionSerializer = + registry.getSerializer(new MessageTypeKey<>(message.getVersion(), Instruction.class)); + CodingUtils.serializeList(message.getInstruction(), instructionSerializer, outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } private static int createFlowModFlagsBitmask(FlowModFlags flags) { @@ -87,6 +75,5 @@ public class FlowModInputMessageFactory implements OFSerializer { flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); return flowModFlagBitmask; } - - + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java index a4a1a59e..3dfd5dcc 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.GetAsyncInput; /** @@ -21,37 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetAsyncRequestMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 26; - private static final int MESSAGE_LENGTH = 8; - private static GetAsyncRequestMessageFactory instance; - - private GetAsyncRequestMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetAsyncRequestMessageFactory getInstance() { - if (instance == null) { - instance = new GetAsyncRequestMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetAsyncInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetAsyncInput message) { - return MESSAGE_LENGTH; - } - + @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(GetAsyncInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java index 23898ff8..3867e33c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.GetConfigInput; /** @@ -22,38 +23,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class GetConfigInputMessageFactory implements OFSerializer { /** Code type of GetConfigRequest message */ - public static final byte MESSAGE_TYPE = 7; - private static final int MESSAGE_LENGTH = 8; - private static GetConfigInputMessageFactory instance; - - private GetConfigInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetConfigInputMessageFactory getInstance() { - if (instance == null) { - instance = new GetConfigInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetConfigInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetConfigInput message) { - return MESSAGE_LENGTH; - } + private static final byte MESSAGE_TYPE = 7; @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(GetConfigInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java index d1f82df2..b04997d2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.GetFeaturesInput; /** @@ -22,38 +23,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class GetFeaturesInputMessageFactory implements OFSerializer{ /** Code type of FeaturesRequest message */ - public static final byte MESSAGE_TYPE = 5; - private static final int MESSAGE_LENGTH = 8; - private static GetFeaturesInputMessageFactory instance; - - private GetFeaturesInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetFeaturesInputMessageFactory getInstance() { - if (instance == null) { - instance = new GetFeaturesInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetFeaturesInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetFeaturesInput message) { - return MESSAGE_LENGTH; - } + private static final byte MESSAGE_TYPE = 5; @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(GetFeaturesInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java index 5a87ec36..f154125d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.GetQueueConfigInput; /** @@ -23,40 +24,13 @@ public class GetQueueConfigInputMessageFactory implements OFSerializer { +public class GroupModInputMessageFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 15; - private static final int MESSAGE_LENGTH = 16; private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; - private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16; private static final byte PADDING_IN_BUCKET = 4; - private static GroupModInputMessageFactory instance; - - private GroupModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GroupModInputMessageFactory getInstance() { - if (instance == null) { - instance = new GroupModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GroupModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getCommand().getIntValue()); - out.writeByte(message.getType().getIntValue()); - ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out); - out.writeInt(message.getGroupId().getValue().intValue()); - encodeBuckets(message.getBucketsList(), out); - } + private SerializerRegistry registry; @Override - public int computeLength(GroupModInput message) { - return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList()); + public void serialize(GroupModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(message.getCommand().getIntValue()); + outBuffer.writeByte(message.getType().getIntValue()); + ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, outBuffer); + outBuffer.writeInt(message.getGroupId().getValue().intValue()); + serializerBuckets(message.getBucketsList(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodeBuckets(List buckets, ByteBuf outBuffer) { + private void serializerBuckets(List buckets, ByteBuf outBuffer) { if (buckets != null) { for (BucketsList currentBucket : buckets) { - outBuffer.writeShort(computeLengthOfBucket(currentBucket)); + int bucketLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(currentBucket.getWeight().shortValue()); outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer); - ActionsSerializer.encodeActions(currentBucket.getAction(), outBuffer); + OFSerializer actionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class)); + CodingUtils.serializeList(currentBucket.getAction(), actionSerializer, outBuffer); + outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex); } } } - - private static int computeLengthOfBucket(BucketsList bucket) { - int lengthOfBuckets = 0; - if (bucket != null) { - lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE - + ActionsSerializer.computeLengthOfActions(bucket.getAction()); - } - return lengthOfBuckets; - } - - private static int computeLengthOfBuckets(List buckets) { - int lengthOfBuckets = 0; - if (buckets != null) { - for (BucketsList currentBucket : buckets) { - lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE - + ActionsSerializer.computeLengthOfActions(currentBucket.getAction()); - } - } - return lengthOfBuckets; + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } - } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java index 04abc4eb..b2918dcd 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java @@ -10,9 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.HelloElementType; @@ -28,83 +26,41 @@ public class HelloInputMessageFactory implements OFSerializer{ /** Code type of Hello message */ private static final byte MESSAGE_TYPE = 0; - private static int MESSAGE_LENGTH = 8; - /** Size of hello element header (in bytes) */ - public static final byte HELLO_ELEMENT_HEADER_SIZE = 4; - private static HelloInputMessageFactory instance; - - private HelloInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized HelloInputMessageFactory getInstance() { - if (instance == null) { - instance = new HelloInputMessageFactory(); - } - return instance; - } + private static final byte HELLO_ELEMENT_HEADER_SIZE = 4; - @Override - public void messageToBuffer(short version, ByteBuf out, HelloInput message) { - int startWriterIndex = out.writerIndex(); - ByteBufUtils.writeOFHeader(instance, message, out); - encodeElementsList(message, out); - int endWriterIndex = out.writerIndex(); - int writtenBytesDiff = computeLength(message) - (endWriterIndex - startWriterIndex); - ByteBufUtils.padBuffer(writtenBytesDiff, out); - } - - @Override - public int computeLength(HelloInput message) { - int length = MESSAGE_LENGTH; - List elements = message.getElements(); - if (elements != null) { - for (Elements element : elements) { - if (HelloElementType.VERSIONBITMAP.equals(element.getType())) { - int bitmapLength = computeVersionBitmapLength(element); - int paddingRemainder = bitmapLength % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - bitmapLength += EncodeConstants.PADDING - paddingRemainder; - } - length += bitmapLength; - } - } - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodeElementsList(HelloInput message, ByteBuf output) { + private static void serializeElementsList(HelloInput message, ByteBuf output) { int[] versionBitmap; if (message.getElements() != null) { for (Elements currElement : message.getElements()) { + int elementStartIndex = output.writerIndex(); output.writeShort(currElement.getType().getIntValue()); if (currElement.getType().equals(HelloElementType.VERSIONBITMAP)) { - short bitmapLength = computeVersionBitmapLength(currElement); - output.writeShort(bitmapLength); + int elementLengthIndex = output.writerIndex(); + output.writeShort(EncodeConstants.EMPTY_LENGTH); versionBitmap = ByteBufUtils.fillBitMaskFromList(currElement.getVersionBitmap()); for (int i = 0; i < versionBitmap.length; i++) { output.writeInt(versionBitmap[i]); } - int padding = bitmapLength - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE; + int length = output.writerIndex() - elementStartIndex; + int padding = length - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE; ByteBufUtils.padBuffer(padding , output); + output.setShort(elementLengthIndex, output.writerIndex() - elementStartIndex); } } } } - - private static short computeVersionBitmapLength(Elements element) { - short elementlength = HELLO_ELEMENT_HEADER_SIZE; - if (!element.getVersionBitmap().isEmpty()) { - elementlength += ((element.getVersionBitmap().size() - 1) / Integer.SIZE + 1) * (EncodeConstants.SIZE_OF_INT_IN_BYTES); + + @Override + public void serialize(HelloInput message, ByteBuf outBuffer) { + int startWriterIndex = outBuffer.writerIndex(); + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + serializeElementsList(message, outBuffer); + int endWriterIndex = outBuffer.writerIndex(); + int paddingRemainder = (endWriterIndex - startWriterIndex) % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer); } - return elementlength; + ByteBufUtils.updateOFHeaderLength(outBuffer); } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java index 92219661..60c4d14f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java @@ -14,8 +14,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.MeterFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterBandCommons; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; @@ -35,48 +36,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class MeterModInputMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 29; - private static final int MESSAGE_LENGTH = 16; private static final short LENGTH_OF_METER_BANDS = 16; private static final short PADDING_IN_METER_BAND_DROP = 4; private static final short PADDING_IN_METER_BAND_DSCP_REMARK = 3; - private static MeterModInputMessageFactory instance; - - private MeterModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized MeterModInputMessageFactory getInstance() { - if (instance == null) { - instance = new MeterModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - MeterModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getCommand().getIntValue()); - out.writeShort(createMeterFlagsBitmask(message.getFlags())); - out.writeInt(message.getMeterId().getValue().intValue()); - encodeBands(message.getBands(), out); - } @Override - public int computeLength(MeterModInput message) { - int length = MESSAGE_LENGTH; - if (message.getBands() != null) { - length += message.getBands().size() * LENGTH_OF_METER_BANDS; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(MeterModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(message.getCommand().getIntValue()); + outBuffer.writeShort(createMeterFlagsBitmask(message.getFlags())); + outBuffer.writeInt(message.getMeterId().getValue().intValue()); + serializeBands(message.getBands(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } private static int createMeterFlagsBitmask(MeterFlags flags) { @@ -91,7 +62,7 @@ public class MeterModInputMessageFactory implements OFSerializer return meterFlagBitmask; } - private static void encodeBands(List bands, ByteBuf outBuffer) { + private static void serializeBands(List bands, ByteBuf outBuffer) { if (bands != null) { for (Bands currentBand : bands) { MeterBand meterBand = currentBand.getMeterBand(); @@ -122,5 +93,5 @@ public class MeterModInputMessageFactory implements OFSerializer outBuffer.writeInt(meterBand.getRate().intValue()); outBuffer.writeInt(meterBand.getBurstSize().intValue()); } - + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java index 0fdeff1c..caf857c4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java @@ -14,12 +14,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; @@ -30,15 +33,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; 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.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; 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.oxm.rev130731.oxm.fields.grouping.MatchEntries; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCase; @@ -52,7 +54,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeter; @@ -68,12 +69,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class MultipartRequestInputFactory implements OFSerializer { +public class MultipartRequestInputFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 18; - private static final int MESSAGE_LENGTH = 16; private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; private static final byte TABLE_FEAT_HEADER_LENGTH = 4; - private static MultipartRequestInputFactory instance; private static final byte INSTRUCTIONS_CODE = 0; private static final byte INSTRUCTIONS_MISS_CODE = 1; private static final byte NEXT_TABLE_CODE = 2; @@ -90,15 +89,6 @@ public class MultipartRequestInputFactory implements OFSerializer tableFeatures = body.getTableFeatures(); - for (TableFeatures feature : tableFeatures) { - length += computeSingleTableFeatureLength(feature); - } - } - return length; - } - - private static int computeSingleTableFeatureLength(TableFeatures feature) { - return TABLE_FEATURES_LENGTH + computeTableFeatPropsLength(feature); - } - - private static int computeTableFeatPropsLength(TableFeatures feature) { - int length = 0; - List featureProperties = feature.getTableFeatureProperties(); - if (featureProperties != null) { - for (TableFeatureProperties featProp : featureProperties) { - length += TABLE_FEAT_HEADER_LENGTH; - if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) { - InstructionRelatedTableFeatureProperty property = - featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class); - length += property.getInstruction().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) { - NextTableRelatedTableFeatureProperty property = - featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class); - length += property.getNextTableIds().size(); - length += paddingNeeded(length); - } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) { - ActionRelatedTableFeatureProperty property = - featProp.getAugmentation(ActionRelatedTableFeatureProperty.class); - length += property.getAction().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) { - OxmRelatedTableFeatureProperty property = - featProp.getAugmentation(OxmRelatedTableFeatureProperty.class); - length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH; - length += paddingNeeded(length); - } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) { - ExperimenterRelatedTableFeatureProperty property = - featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); - length += 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - if (property.getData() != null) { - length += property.getData().length; - } - length += paddingNeeded(length); - } - } - } - return length; - } - - - private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { int multipartRequestFlagsBitmask = 0; Map multipartRequestFlagsMap = new HashMap<>(); @@ -287,7 +153,7 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Match.class)); + serializer.serialize(flow.getMatch(), output); } - private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private void serializeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody; MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate(); output.writeByte(aggregate.getTableId().byteValue()); @@ -360,64 +228,54 @@ public class MultipartRequestInputFactory implements OFSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Match.class)); + serializer.serialize(aggregate.getMatch(), output); } - private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody; MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats(); output.writeInt(portstats.getPortNo().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output); } - private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody; MultipartRequestQueue queue = queueCase.getMultipartRequestQueue(); output.writeInt(queue.getPortNo().intValue()); output.writeInt(queue.getQueueId().intValue()); } - private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestGroupCase groupStatsCase = (MultipartRequestGroupCase) multipartRequestBody; MultipartRequestGroup groupStats = groupStatsCase.getMultipartRequestGroup(); output.writeInt(groupStats.getGroupId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output); } - private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestMeterCase meterCase = (MultipartRequestMeterCase) multipartRequestBody; MultipartRequestMeter meter = meterCase.getMultipartRequestMeter(); output.writeInt(meter.getMeterId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output); } - private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestMeterConfigCase meterConfigCase = (MultipartRequestMeterConfigCase) multipartRequestBody; MultipartRequestMeterConfig meterConfig = meterConfigCase.getMultipartRequestMeterConfig(); output.writeInt(meterConfig.getMeterId().getValue().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output); } - private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestExperimenterCase experimenterCase = (MultipartRequestExperimenterCase) multipartRequestBody; - MultipartRequestExperimenter experimenter = experimenterCase.getMultipartRequestExperimenter(); - output.writeInt(experimenter.getExperimenter().intValue()); - output.writeInt(experimenter.getExpType().intValue()); - byte[] data = experimenter.getData(); - if (data != null) { - output.writeBytes(data); - } - } - - private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private void serializeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { if (multipartRequestBody != null) { MultipartRequestTableFeaturesCase tableFeaturesCase = (MultipartRequestTableFeaturesCase) multipartRequestBody; MultipartRequestTableFeatures tableFeatures = tableFeaturesCase.getMultipartRequestTableFeatures(); if(tableFeatures.getTableFeatures() != null) { for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) { - int length = computeSingleTableFeatureLength(currTableFeature); - length += paddingNeeded(length); - output.writeShort(length); + int tableFeatureLengthIndex = output.writerIndex(); + output.writeShort(EncodeConstants.EMPTY_LENGTH); output.writeByte(currTableFeature.getTableId()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output); output.writeBytes(currTableFeature.getName().getBytes()); @@ -427,12 +285,13 @@ public class MultipartRequestInputFactory implements OFSerializer props) { + private void writeTableFeatureProperties(ByteBuf output, List props) { if (props != null) { for (TableFeatureProperties property : props) { TableFeaturesPropType type = property.getType(); @@ -473,7 +332,7 @@ public class MultipartRequestInputFactory implements OFSerializer instructions = property. @@ -490,7 +349,9 @@ public class MultipartRequestInputFactory implements OFSerializer instructionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Instruction.class)); + CodingUtils.serializeHeaders(instructions, instructionSerializer, output); } else { padding = paddingNeeded(length); output.writeShort(length); @@ -528,7 +389,7 @@ public class MultipartRequestInputFactory implements OFSerializer actions = property. @@ -546,7 +407,9 @@ public class MultipartRequestInputFactory implements OFSerializer actionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class)); + CodingUtils.serializeHeaders(actions, actionSerializer, output); } else { padding = paddingNeeded(length); output.writeShort(length); @@ -554,7 +417,7 @@ public class MultipartRequestInputFactory implements OFSerializer entries = property. @@ -566,7 +429,13 @@ public class MultipartRequestInputFactory implements OFSerializer entrySerializer = registry.getSerializer( + new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, + entry.getOxmClass(), entry.getOxmMatchField())); + entrySerializer.serializeHeader(entry, output); + } } else { padding = paddingNeeded(length); output.writeShort(length); @@ -605,4 +474,9 @@ public class MultipartRequestInputFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 18; - private static final int MESSAGE_LENGTH = 8; - private static OF10BarrierInputMessageFactory instance; - - private OF10BarrierInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10BarrierInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10BarrierInputMessageFactory(); - } - return instance; - } - @Override - public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); + public void serialize(BarrierInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } - @Override - public int computeLength(BarrierInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java index 7fe217a6..d43104cf 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java @@ -13,61 +13,45 @@ import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.types.rev130731.FlowModFlagsV10; +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.FlowModInput; /** * Translates FlowMod messages * @author michal.polkorab */ -public class OF10FlowModInputMessageFactory implements OFSerializer { +public class OF10FlowModInputMessageFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 14; - private static final int MESSAGE_LENGTH = 72; - - private static OF10FlowModInputMessageFactory instance; - - private OF10FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new OF10FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10()); - out.writeLong(message.getCookie().longValue()); - out.writeShort(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeShort(message.getOutPort().getValue().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); - OF10ActionsSerializer.encodeActionsV10(out, message.getAction()); - } - - @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction()); - } + private SerializerRegistry registry; @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(FlowModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + OFSerializer matchSerializer = registry.getSerializer(new MessageTypeKey<>( + message.getVersion(), MatchV10.class)); + matchSerializer.serialize(message.getMatchV10(), outBuffer); + outBuffer.writeLong(message.getCookie().longValue()); + outBuffer.writeShort(message.getCommand().getIntValue()); + outBuffer.writeShort(message.getIdleTimeout().intValue()); + outBuffer.writeShort(message.getHardTimeout().intValue()); + outBuffer.writeShort(message.getPriority()); + outBuffer.writeInt(message.getBufferId().intValue()); + outBuffer.writeShort(message.getOutPort().getValue().intValue()); + outBuffer.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); + OFSerializer actionSerializer = registry.getSerializer( + new MessageTypeKey<>(message.getVersion(), Action.class)); + CodingUtils.serializeList(message.getAction(), actionSerializer, outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) { @@ -79,4 +63,9 @@ public class OF10FlowModInputMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 0; - private static int MESSAGE_LENGTH = 8; - private static OF10HelloInputMessageFactory instance; - - private OF10HelloInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10HelloInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10HelloInputMessageFactory(); - } - return instance; - } @Override - public void messageToBuffer(short version, ByteBuf out, HelloInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); + public void serialize(HelloInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE); } - @Override - public int computeLength(HelloInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java index 6684afaa..ad49758b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java @@ -10,63 +10,47 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; /** * Translates PacketOut messages * @author michal.polkorab */ -public class OF10PacketOutInputMessageFactory implements OFSerializer { +public class OF10PacketOutInputMessageFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 13; - private static final int MESSAGE_LENGTH = 16; - - private static OF10PacketOutInputMessageFactory instance; - - private OF10PacketOutInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PacketOutInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10PacketOutInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - PacketOutInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getBufferId().intValue()); - out.writeShort(message.getInPort().getValue().intValue()); - out.writeShort(OF10ActionsSerializer.computeActionsLength(message.getAction())); - OF10ActionsSerializer.encodeActionsV10(out, message.getAction()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } + private SerializerRegistry registry; @Override - public int computeLength(PacketOutInput message) { - int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction()); + public void serialize(PacketOutInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeInt(message.getBufferId().intValue()); + outBuffer.writeShort(message.getInPort().getValue().intValue()); + int actionsLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + int actionsStartIndex = outBuffer.writerIndex(); + OFSerializer serializer = + registry.getSerializer(new MessageTypeKey<>(message.getVersion(), Action.class)); + CodingUtils.serializeList(message.getAction(), serializer, outBuffer); + outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex); byte[] data = message.getData(); if (data != null) { - length += data.length; + outBuffer.writeBytes(data); } - return length; + ByteBufUtils.updateOFHeaderLength(outBuffer); } @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java index 6cb8606b..bc38b0dd 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java @@ -13,8 +13,9 @@ import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.PortConfigV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; @@ -27,46 +28,19 @@ public class OF10PortModInputMessageFactory implements OFSerializer { +public class OF10StatsRequestInputFactory implements OFSerializer, RegistryInjector { private static final byte MESSAGE_TYPE = 16; - private static final int MESSAGE_LENGTH = 12; private static final byte FLOW_BODY_LENGTH = 44; private static final byte AGGREGATE_BODY_LENGTH = 44; private static final byte PORT_STATS_BODY_LENGTH = 8; @@ -51,54 +54,31 @@ public class OF10StatsRequestInputFactory implements OFSerializer matchSerializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF10_VERSION_ID, MatchV10.class)); + matchSerializer.serialize(flow.getMatchV10(), output); output.writeByte(flow.getTableId().shortValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY, output); output.writeShort(flow.getOutPort().intValue()); } - private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private void serializeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody; MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate(); - OF10MatchSerializer.encodeMatchV10(output, aggregate.getMatchV10()); + OFSerializer matchSerializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF10_VERSION_ID, MatchV10.class)); + matchSerializer.serialize(aggregate.getMatchV10(), output); output.writeByte(aggregate.getTableId().shortValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY, output); output.writeShort(aggregate.getOutPort().intValue()); } - private static void encodePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody; MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats(); output.writeShort(portstats.getPortNo().intValue()); ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORT_BODY, output); } - private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + private static void serializeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody; MultipartRequestQueue queue = queueCase.getMultipartRequestQueue(); output.writeShort(queue.getPortNo().intValue()); @@ -185,11 +169,16 @@ public class OF10StatsRequestInputFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 4; - private static final byte MESSAGE_LENGTH = 8; - - private static OF10VendorInputMessageFactory instance; - - private OF10VendorInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10VendorInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10VendorInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - ExperimenterInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getExperimenter().intValue()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(ExperimenterInput message) { - int length = MESSAGE_LENGTH + EncodeConstants.SIZE_OF_INT_IN_BYTES; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java index 443830bd..2b14b19d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java @@ -10,9 +10,14 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; /** @@ -20,57 +25,36 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab * @author timotej.kubas */ -public class PacketOutInputMessageFactory implements OFSerializer{ +public class PacketOutInputMessageFactory implements OFSerializer, RegistryInjector { /** Code type of PacketOut message */ - public static final byte MESSAGE_TYPE = 13; - private static final int MESSAGE_LENGTH = 24; + private static final byte MESSAGE_TYPE = 13; private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; - private static PacketOutInputMessageFactory instance; - - private PacketOutInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized PacketOutInputMessageFactory getInstance() { - if (instance == null) { - instance = new PacketOutInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - PacketOutInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getBufferId().intValue()); - out.writeInt(message.getInPort().getValue().intValue()); - out.writeShort(ActionsSerializer.computeLengthOfActions(message.getAction())); - ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out); - ActionsSerializer.encodeActions(message.getAction(), out); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } + private SerializerRegistry registry; @Override - public int computeLength(PacketOutInput message) { - int length = MESSAGE_LENGTH; - length += ActionsSerializer.computeLengthOfActions(message.getAction()); + public void serialize(PacketOutInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeInt(message.getBufferId().intValue()); + outBuffer.writeInt(message.getInPort().getValue().intValue()); + int actionsLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, outBuffer); + int actionsStartIndex = outBuffer.writerIndex(); + OFSerializer actionSerializer = registry.getSerializer( + new MessageTypeKey<>(message.getVersion(), Action.class)); + CodingUtils.serializeList(message.getAction(), actionSerializer, outBuffer); + outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex); byte[] data = message.getData(); if (data != null) { - length += data.length; + outBuffer.writeBytes(data); } - return length; + ByteBufUtils.updateOFHeaderLength(outBuffer); } @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java index 3a576660..61632cf7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java @@ -13,8 +13,9 @@ import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; @@ -29,47 +30,21 @@ public class PortModInputMessageFactory implements OFSerializer { private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4; private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; - private static final int MESSAGE_LENGTH = 40; - private static PortModInputMessageFactory instance; - - private PortModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized PortModInputMessageFactory getInstance() { - if (instance == null) { - instance = new PortModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, PortModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getPortNo().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, out); - out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, out); - out.writeInt(createPortConfigBitmask(message.getConfig())); - out.writeInt(createPortConfigBitmask(message.getMask())); - out.writeInt(createPortFeaturesBitmask(message.getAdvertise())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, out); - } @Override - public int computeLength(PortModInput message) { - return MESSAGE_LENGTH; + public void serialize(PortModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeInt(message.getPortNo().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, outBuffer); + outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, outBuffer); + outBuffer.writeInt(createPortConfigBitmask(message.getConfig())); + outBuffer.writeInt(createPortConfigBitmask(message.getMask())); + outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertise())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - /** * @param config * @return port config bitmask @@ -109,4 +84,5 @@ public class PortModInputMessageFactory implements OFSerializer { configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); return configBitmask; } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java index 285932d2..8f8c82e7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.RoleRequestInput; /** @@ -22,42 +23,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class RoleRequestInputMessageFactory implements OFSerializer { /** Code type of RoleRequest message */ - public static final byte MESSAGE_TYPE = 24; - private static final int MESSAGE_LENGTH = 24; + private static final byte MESSAGE_TYPE = 24; private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; - private static RoleRequestInputMessageFactory instance; - - private RoleRequestInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized RoleRequestInputMessageFactory getInstance() { - if (instance == null) { - instance = new RoleRequestInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - RoleRequestInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getRole().getIntValue()); - ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, out); - out.writeLong(message.getGenerationId().longValue()); - } - - @Override - public int computeLength(RoleRequestInput message) { - return MESSAGE_LENGTH; - } @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(RoleRequestInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeInt(message.getRole().getIntValue()); + ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, outBuffer); + outBuffer.writeLong(message.getGenerationId().longValue()); + ByteBufUtils.updateOFHeaderLength(outBuffer); } -} +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java index c647aaf7..b903e83b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java @@ -14,8 +14,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.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; @@ -31,44 +32,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class SetAsyncInputMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 28; - private static final int MESSAGE_LENGTH = 32; - private static SetAsyncInputMessageFactory instance; - - - private SetAsyncInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized SetAsyncInputMessageFactory getInstance() { - if (instance == null) { - instance = new SetAsyncInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - SetAsyncInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - encodePacketInMask(message.getPacketInMask(), out); - encodePortStatusMask(message.getPortStatusMask(), out); - encodeFlowRemovedMask(message.getFlowRemovedMask(), out); - } @Override - public int computeLength(SetAsyncInput message) { - return MESSAGE_LENGTH; + public void serialize(SetAsyncInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + serializePacketInMask(message.getPacketInMask(), outBuffer); + serializePortStatusMask(message.getPortStatusMask(), outBuffer); + serializerFlowRemovedMask(message.getFlowRemovedMask(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodePacketInMask(List packetInMask, ByteBuf outBuffer) { + private static void serializePacketInMask(List packetInMask, ByteBuf outBuffer) { if (packetInMask != null) { for (PacketInMask currentPacketMask : packetInMask) { List mask = currentPacketMask.getMask(); @@ -89,7 +63,7 @@ public class SetAsyncInputMessageFactory implements OFSerializer } } - private static void encodePortStatusMask(List portStatusMask, ByteBuf outBuffer) { + private static void serializePortStatusMask(List portStatusMask, ByteBuf outBuffer) { if (portStatusMask != null) { for (PortStatusMask currentPortStatusMask : portStatusMask) { List mask = currentPortStatusMask.getMask(); @@ -110,7 +84,7 @@ public class SetAsyncInputMessageFactory implements OFSerializer } } - private static void encodeFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { + private static void serializerFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { if (flowRemovedMask != null) { for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) { List mask = currentFlowRemovedMask.getMask(); @@ -132,5 +106,5 @@ public class SetAsyncInputMessageFactory implements OFSerializer } } } - + } \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java index 5e7e6283..a1407a01 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java @@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.protocol.rev130731.SetConfigInput; /** @@ -22,40 +23,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class SetConfigMessageFactory implements OFSerializer { /** Code type of SetConfig message */ - public static final byte MESSAGE_TYPE = 9; - private static final int MESSAGE_LENGTH = 12; - private static SetConfigMessageFactory instance; - - private SetConfigMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized SetConfigMessageFactory getInstance() { - if (instance == null) { - instance = new SetConfigMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - SetConfigInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getFlags().getIntValue()); - out.writeShort(message.getMissSendLen()); - } - - @Override - public int computeLength(SetConfigInput message) { - return MESSAGE_LENGTH; - } + private static final byte MESSAGE_TYPE = 9; @Override - public byte getMessageType() { - return MESSAGE_TYPE; + public void serialize(SetConfigInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(message.getFlags().getIntValue()); + outBuffer.writeShort(message.getMissSendLen()); + ByteBufUtils.updateOFHeaderLength(outBuffer); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java index 9c4e3b24..c9fb2b67 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java @@ -13,8 +13,9 @@ import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; 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.TableConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; @@ -26,41 +27,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class TableModInputMessageFactory implements OFSerializer { private static final byte MESSAGE_TYPE = 17; private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; - private static final int MESSAGE_LENGTH = 16; - private static TableModInputMessageFactory instance; - - private TableModInputMessageFactory() { - // just singleton - } - - /** - * @return singleton factory - */ - public static synchronized TableModInputMessageFactory getInstance() { - if(instance == null){ - instance = new TableModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, TableModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeByte(message.getTableId().getValue().byteValue()); - ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, out); - out.writeInt(createConfigBitmask(message.getConfig())); - } @Override - public int computeLength(TableModInput message) { - return MESSAGE_LENGTH; + public void serialize(TableModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeByte(message.getTableId().getValue().byteValue()); + ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, outBuffer); + outBuffer.writeInt(createConfigBitmask(message.getConfig())); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - /** * @param tableConfig * @return port config bitmask @@ -71,4 +47,5 @@ public class TableModInputMessageFactory implements OFSerializer int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); return configBitmask; } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv4AddressSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv4AddressSerializer.java new file mode 100644 index 00000000..7f07d819 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv4AddressSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for Ipv4 address based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmIpv4AddressSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + writeIpv4Address(entry, outBuffer); + writeMask(entry, outBuffer, getValueLength()); + } + + private static void writeIpv4Address(MatchEntries entry, ByteBuf out) { + String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class) + .getIpv4Address().getValue().split("\\."); + for (int i = 0; i < addressGroups.length; i++) { + out.writeByte(Integer.parseInt(addressGroups[i])); + } + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java new file mode 100644 index 00000000..d5491c83 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java @@ -0,0 +1,77 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import java.util.Arrays; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for Ipv6 address based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); + String[] address; + if (textAddress.equals("::")) { + address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + Arrays.fill(address, "0"); + } else { + address = parseIpv6Address(textAddress.split(":")); + } + for (int i = 0; i < address.length; i++) { + outBuffer.writeShort(Integer.parseInt(address[i], 16)); + } + writeMask(entry, outBuffer, getValueLength()); + } + + private static String[] parseIpv6Address(String[] addressGroups) { + int countEmpty = 0; + for (int i = 0; i < addressGroups.length; i++) { + if (addressGroups[i].equals("")){ + countEmpty++; + } + } + String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + switch (countEmpty) { + case 0: + ready = addressGroups; + break; + case 1: + int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1; + int index = 0; + for (int i = 0; i < addressGroups.length; i++) { + if (addressGroups[i].equals("")) { + for (int j = 0; j < zerosToBePushed; j++) { + ready[index] = "0"; + index++; + } + } else { + ready[index] = addressGroups[i]; + index++; + } + } + break; + case 2: + Arrays.fill(ready, "0"); + ready[ready.length - 1] = addressGroups[addressGroups.length - 1]; + break; + default: + throw new IllegalStateException("Incorrect ipv6 address"); + } + return ready; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMacAddressSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMacAddressSerializer.java new file mode 100644 index 00000000..94df9f08 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMacAddressSerializer.java @@ -0,0 +1,29 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for MAC address based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmMacAddressSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); + outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); // 48 b + mask [OF 1.3.2 spec] + writeMask(entry, outBuffer, getValueLength()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMatchEntrySerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMatchEntrySerializer.java new file mode 100644 index 00000000..8b84a88c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMatchEntrySerializer.java @@ -0,0 +1,73 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for all match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmMatchEntrySerializer + implements OFSerializer, HeaderSerializer{ + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + serializeHeader(entry, outBuffer); + } + + @Override + public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) { + outBuffer.writeShort(getOxmClassCode()); + writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(), + getValueLength()); + } + + protected static void writeMask(MatchEntries entry, ByteBuf out, int length) { + if (entry.isHasMask()) { + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + if (mask != null && mask.length != length) { + throw new IllegalArgumentException("incorrect length of mask: "+ + mask.length + ", expected: " + length); + } + out.writeBytes(mask); + } + } + + protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) { + int fieldAndMask = fieldValue << 1; + int length = lengthArg; + if (hasMask) { + fieldAndMask |= 1; + length *= 2; + } + out.writeByte(fieldAndMask); + out.writeByte(length); + } + + /** + * @return numeric representation of oxm_field + */ + protected abstract int getOxmFieldCode(); + + /** + * @return numeric representation of oxm_class + */ + protected abstract int getOxmClassCode(); + + /** + * @return match entry value length (without mask length) + */ + protected abstract int getValueLength(); + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMetadataSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMetadataSerializer.java new file mode 100644 index 00000000..0218beb8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMetadataSerializer.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.impl.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for metadata based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmMetadataSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); + writeMask(entry, outBuffer, getValueLength()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortNumberSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortNumberSerializer.java new file mode 100644 index 00000000..ce972033 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortNumberSerializer.java @@ -0,0 +1,26 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for port(32-bit) based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmPortNumberSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortSerializer.java new file mode 100644 index 00000000..b1c4671c --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortSerializer.java @@ -0,0 +1,26 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * Parent for port(16-bit) based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmPortSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializer.java new file mode 100644 index 00000000..84aefe11 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmArpOpSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_OP; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializer.java new file mode 100644 index 00000000..4198f96f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmArpShaSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_SHA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializer.java new file mode 100644 index 00000000..d51adb70 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmArpSpaSerializer extends AbstractOxmIpv4AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_SPA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializer.java new file mode 100644 index 00000000..83e67c9f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmArpThaSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_THA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializer.java new file mode 100644 index 00000000..b0af9891 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmArpTpaSerializer extends AbstractOxmIpv4AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ARP_TPA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializer.java new file mode 100644 index 00000000..12b2bcf4 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmEthDstSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ETH_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializer.java new file mode 100644 index 00000000..b4995d61 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmEthSrcSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ETH_SRC; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializer.java new file mode 100644 index 00000000..da60d720 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmEthTypeSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ETH_TYPE; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializer.java new file mode 100644 index 00000000..901be666 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv4CodeSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ICMPV4_CODE; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializer.java new file mode 100644 index 00000000..b391ef1d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv4TypeSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ICMPV4_TYPE; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializer.java new file mode 100644 index 00000000..4e267cbb --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv6CodeSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ICMPV6_CODE; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializer.java new file mode 100644 index 00000000..09a943d1 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv6TypeSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.ICMPV6_TYPE; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPhyPortSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPhyPortSerializer.java new file mode 100644 index 00000000..541ba0f6 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPhyPortSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmInPhyPortSerializer extends AbstractOxmPortNumberSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IN_PHY_PORT; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPortSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPortSerializer.java new file mode 100644 index 00000000..f8096219 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPortSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmInPortSerializer extends AbstractOxmPortNumberSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IN_PORT; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializer.java new file mode 100644 index 00000000..eacaf491 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIpDscpSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IP_DSCP; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpEcnSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpEcnSerializer.java new file mode 100644 index 00000000..193e3f71 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpEcnSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIpEcnSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IP_ECN; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializer.java new file mode 100644 index 00000000..7a99f7b6 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIpProtoSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IP_PROTO; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializer.java new file mode 100644 index 00000000..b8a53b9b --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv4DstSerializer extends AbstractOxmIpv4AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV4_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializer.java new file mode 100644 index 00000000..494a6fa4 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv4SrcSerializer extends AbstractOxmIpv4AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV4_SRC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6DstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6DstSerializer.java new file mode 100644 index 00000000..5111b832 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6DstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6DstSerializer extends AbstractOxmIpv6AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializer.java new file mode 100644 index 00000000..9ee6601a --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializer.java @@ -0,0 +1,61 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6ExtHdrSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField(); + Map map = new HashMap<>(); + map.put(0, pseudoField.isNonext()); + map.put(1, pseudoField.isEsp()); + map.put(2, pseudoField.isAuth()); + map.put(3, pseudoField.isDest()); + map.put(4, pseudoField.isFrag()); + map.put(5, pseudoField.isRouter()); + map.put(6, pseudoField.isHop()); + map.put(7, pseudoField.isUnrep()); + map.put(8, pseudoField.isUnseq()); + int bitmap = ByteBufUtils.fillBitMaskFromMap(map); + outBuffer.writeShort(bitmap); + writeMask(entry, outBuffer, getValueLength()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_EXTHDR; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6FlabelSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6FlabelSerializer.java new file mode 100644 index 00000000..4805b264 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6FlabelSerializer.java @@ -0,0 +1,44 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6FlabelSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); + writeMask(entry, outBuffer, getValueLength()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_FLABEL; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializer.java new file mode 100644 index 00000000..66cb9f4e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdSllSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_ND_SLL; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTargetSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTargetSerializer.java new file mode 100644 index 00000000..a9cd13e4 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTargetSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdTargetSerializer extends AbstractOxmIpv6AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_ND_TARGET; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializer.java new file mode 100644 index 00000000..3e4d0579 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6NdTllSerializer extends AbstractOxmMacAddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_ND_TLL; + } + + @Override + protected int getValueLength() { + return EncodeConstants.MAC_ADDRESS_LENGTH; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6SrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6SrcSerializer.java new file mode 100644 index 00000000..0b70ffc6 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6SrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmIpv6SrcSerializer extends AbstractOxmIpv6AddressSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.IPV6_SRC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializer.java new file mode 100644 index 00000000..3a009f2f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmMetadataSerializer extends AbstractOxmMetadataSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.METADATA; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_LONG_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializer.java new file mode 100644 index 00000000..8685c464 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsBosSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.MPLS_BOS; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializer.java new file mode 100644 index 00000000..3c5de383 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsLabelSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.MPLS_LABEL; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_INT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializer.java new file mode 100644 index 00000000..4e3af758 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmMplsTcSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.MPLS_TC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializer.java new file mode 100644 index 00000000..0d5db302 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializer.java @@ -0,0 +1,44 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmPbbIsidSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); + writeMask(entry, outBuffer, getValueLength()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.PBB_ISID; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_3_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializer.java new file mode 100644 index 00000000..6fd507ab --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmSctpDstSerializer extends AbstractOxmPortSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.SCTP_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializer.java new file mode 100644 index 00000000..82703f69 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmSctpSrcSerializer extends AbstractOxmPortSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.SCTP_SRC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializer.java new file mode 100644 index 00000000..0933cdb6 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmTcpDstSerializer extends AbstractOxmPortSerializer{ + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.TCP_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializer.java new file mode 100644 index 00000000..8a808618 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmTcpSrcSerializer extends AbstractOxmPortSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.TCP_SRC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializer.java new file mode 100644 index 00000000..ac9a5de9 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmTunnelIdSerializer extends AbstractOxmMetadataSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.TUNNEL_ID; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_LONG_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializer.java new file mode 100644 index 00000000..73979972 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmUdpDstSerializer extends AbstractOxmPortSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.UDP_DST; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializer.java new file mode 100644 index 00000000..96022e67 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializer.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.serialization.match; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; + +/** + * @author michal.polkorab + * + */ +public class OxmUdpSrcSerializer extends AbstractOxmPortSerializer { + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.UDP_SRC; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializer.java new file mode 100644 index 00000000..4f4fca28 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializer.java @@ -0,0 +1,44 @@ +/* + * 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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmVlanPcpSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + outBuffer.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.VLAN_PCP; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializer.java new file mode 100644 index 00000000..6afa1592 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializer.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.serialization.match; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class OxmVlanVidSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(MatchEntries entry, ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class); + int vlanVidValue = vlanVid.getVlanVid(); + if (vlanVid.isCfiBit()) { + short cfi = 1 << 12; // 13-th bit + vlanVidValue = vlanVidValue | cfi; + } + + outBuffer.writeShort(vlanVidValue); + writeMask(entry, outBuffer, getValueLength()); + } + + @Override + protected int getOxmClassCode() { + return OxmMatchConstants.OPENFLOW_BASIC_CLASS; + } + + @Override + protected int getOxmFieldCode() { + return OxmMatchConstants.VLAN_VID; + } + + @Override + protected int getValueLength() { + return EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } + +} 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 ab5d0847..42e6a74d 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 @@ -59,7 +59,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 * @author timotej.kubas * @author michal.polkorab */ -public abstract class ActionsDeserializer { +public class ActionsDeserializer { private static final byte ACTION_HEADER_LENGTH = 4; private static final byte PADDING_IN_ACTIONS_HEADER = 4; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java index cb88aef5..0e7654d1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; 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.protocol.rev130731.OfHeader; @@ -102,18 +101,27 @@ public abstract class ByteBufUtils { } } + /** * Create standard OF header - * @param factory serialization factory + * @param msgType message code * @param message POJO * @param out writing buffer + * @param length ofheader length */ - public static void writeOFHeader(OFSerializer factory, E message, ByteBuf out) { + public static void writeOFHeader(byte msgType, E message, ByteBuf out, int length) { out.writeByte(message.getVersion()); - out.writeByte(factory.getMessageType()); - out.writeShort(factory.computeLength(message)); + out.writeByte(msgType); + out.writeShort(length); out.writeInt(message.getXid().intValue()); - + } + + /** + * Write length standard OF header + * @param out writing buffer + */ + public static void updateOFHeaderLength(ByteBuf out) { + out.setShort(EncodeConstants.OFHEADER_LENGTH_INDEX, out.readableBytes()); } /** @@ -175,6 +183,7 @@ public abstract class ByteBufUtils { * @return byte representation of mac address * @see {@link MacAddress} */ + @SuppressWarnings("javadoc") public static byte[] macAddressToBytes(String macAddress) { String[] sequences = macAddress.split(":"); byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; @@ -190,6 +199,7 @@ public abstract class ByteBufUtils { * @return String representation of mac address * @see {@link MacAddress} */ + @SuppressWarnings("javadoc") public static String macAddressToString(byte[] address) { List groups = new ArrayList<>(); for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){ diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodingUtils.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodingUtils.java new file mode 100644 index 00000000..37405cca --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodingUtils.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.util; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Class for common serialization & deserialization operations + * @author michal.polkorab + */ +public abstract class CodingUtils { + + /** + * Serializes list + * @param list list of items to be serialized + * @param serializer serializer that can serialize list items + * @param outBuffer output buffer + */ + public static void serializeList(List list, OFSerializer serializer, ByteBuf outBuffer){ + if (list != null) { + for (T item : list) { + serializer.serialize(item, outBuffer); + } + } + } + + /** + * Serializes header fields for all objects in a list + * @param list list of items to be serialized + * @param serializer serializer that can serialize list items + * @param outBuffer output buffer + */ + public static void serializeHeaders(List list, HeaderSerializer serializer, ByteBuf outBuffer){ + if (list != null) { + for (T item : list) { + serializer.serializeHeader(item, outBuffer); + } + } + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CommonMessageRegistryHelper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CommonMessageRegistryHelper.java new file mode 100644 index 00000000..0ce8d54e --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CommonMessageRegistryHelper.java @@ -0,0 +1,39 @@ +/* + * 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; + +/** + * @author michal.polkorab + * + */ +public class CommonMessageRegistryHelper { + + private short version; + private SerializerRegistry serializerRegistry; + + /** + * @param version + * @param serializerRegistry + */ + public CommonMessageRegistryHelper(short version, SerializerRegistry serializerRegistry) { + this.version = version; + this.serializerRegistry = serializerRegistry; + } + + /** + * @param msgType + * @param serializer + */ + public void registerSerializer(Class msgType, OFGeneralSerializer serializer) { + serializerRegistry.registerSerializer(new MessageTypeKey<>(version, msgType), serializer); + } +} 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 0615b182..7097b0c9 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 @@ -15,12 +15,18 @@ package org.opendaylight.openflowjava.protocol.impl.util; public abstract class EncodeConstants { /** Default OF padding (in bytes) */ - public static final byte PADDING = EncodeConstants.SIZE_OF_LONG_IN_BYTES; + public static final byte PADDING = 8; /** OpenFlow v1.0 wire protocol number */ public static final byte OF10_VERSION_ID = 0x01; /** OpenFlow v1.0 wire protocol number */ public static final byte OF13_VERSION_ID = 0x04; - + /** Index of length in Openflow header */ + public static final int OFHEADER_LENGTH_INDEX = 2; + /** Size of Openflow header */ + public static final int OFHEADER_SIZE = 8; + /** Zero length - used when the length is updated later */ + public static final int EMPTY_LENGTH = 0; + /** Length of mac address */ public static final byte MAC_ADDRESS_LENGTH = 6; /** Number of groups in ipv4 address */ @@ -46,4 +52,5 @@ public abstract class EncodeConstants { public static final byte MAX_PORT_NAME_LENGTH = 16; /** OF v1.3 lenght of experimenter_ids - see Multipart TableFeatures (properties) message */ public static final byte EXPERIMENTER_IDS_LENGTH = 8; + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java deleted file mode 100644 index b652432c..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java +++ /dev/null @@ -1,185 +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.util; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; -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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; -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.InstructionBase; - -/** - * Serializes ofp_instruction (OpenFlow v 1.3) structure - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class InstructionsSerializer { - - private static final byte GOTO_TABLE_TYPE = 1; - private static final byte WRITE_METADATA_TYPE = 2; - private static final byte WRITE_ACTIONS_TYPE = 3; - private static final byte APPLY_ACTIONS_TYPE = 4; - private static final byte CLEAR_ACTIONS_TYPE = 5; - private static final byte METER_TYPE = 6; - private static final byte EXPERIMENTER_TYPE = 7; - private static final byte GOTO_TABLE_LENGTH = 8; - private static final byte WRITE_METADATA_LENGTH = 24; - private static final byte METER_LENGTH = 8; - private static final byte EXPERIMENTER_LENGTH = 8; - private static final byte ACTIONS_INSTRUCTION_LENGTH = 8; - private static final byte PADDING_IN_GOTO_TABLE = 3; - private static final byte PADDING_IN_WRITE_METADATA = 4; - private static final byte PADDING_IN_CLEAR_ACTIONS = 4; - private static final byte INSTRUCTION_IDS_LENGTH = 4; - private static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4; - - /** - * Encodes instructions - * @param instructions List of instructions - * @param out output buffer - */ - public static void encodeInstructions(List instructions, ByteBuf out) { - if (instructions != null) { - for (Instruction instruction : instructions) { - Class type = instruction.getType(); - if (type.isAssignableFrom(GotoTable.class)) { - writeTypeAndLength(out, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH); - out.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId()); - ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, out); - } else if (type.isAssignableFrom(WriteMetadata.class)) { - writeTypeAndLength(out, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, out); - MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class); - out.writeBytes(metadata.getMetadata()); - out.writeBytes(metadata.getMetadataMask()); - } else if (type.isAssignableFrom(WriteActions.class)) { - writeActionsInstruction(out, instruction, WRITE_ACTIONS_TYPE); - } else if (type.isAssignableFrom(ApplyActions.class)) { - writeActionsInstruction(out, instruction, APPLY_ACTIONS_TYPE); - } else if (type.isAssignableFrom(ClearActions.class)) { - writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, ACTIONS_INSTRUCTION_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, out); - } else if (type.isAssignableFrom(Meter.class)) { - writeTypeAndLength(out, METER_TYPE, METER_LENGTH); - out.writeInt(instruction.getAugmentation(MeterIdInstruction.class).getMeterId().intValue()); - } else if (type.isAssignableFrom(Experimenter.class)) { - ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); - byte[] data = experimenter.getData(); - writeTypeAndLength(out, EXPERIMENTER_TYPE, EXPERIMENTER_LENGTH + data.length); - out.writeInt(experimenter.getExperimenter().intValue()); - out.writeBytes(data); - } - } - } - - } - - /** - * Encodes instruction ids (for Multipart - TableFeatures messages) - * @param instructions List of instruction identifiers (without values) - * @param out output buffer - */ - public static void encodeInstructionIds(List instructions, ByteBuf out) { - if (instructions != null) { - for (Instruction instruction : instructions) { - Class type = instruction.getType(); - if (type.isAssignableFrom(GotoTable.class)) { - writeTypeAndLength(out, GOTO_TABLE_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(WriteMetadata.class)) { - writeTypeAndLength(out, WRITE_METADATA_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(WriteActions.class)) { - writeTypeAndLength(out, WRITE_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(ApplyActions.class)) { - writeTypeAndLength(out, APPLY_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(ClearActions.class)) { - writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(Meter.class)) { - writeTypeAndLength(out, METER_TYPE, INSTRUCTION_IDS_LENGTH); - } else if (type.isAssignableFrom(Experimenter.class)) { - ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); - writeTypeAndLength(out, EXPERIMENTER_TYPE, EncodeConstants.EXPERIMENTER_IDS_LENGTH); - out.writeInt(experimenter.getExperimenter().intValue()); - } - } - } - } - - private static void writeTypeAndLength(ByteBuf out, int type, int length) { - out.writeShort(type); - out.writeShort(length); - } - - private static void writeActionsInstruction(ByteBuf out, - Instruction instruction, int type) { - out.writeShort(type); - if (instruction.getAugmentation(ActionsInstruction.class) != null) { - List actions = instruction.getAugmentation(ActionsInstruction.class).getAction(); - out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions)); - ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); - ActionsSerializer.encodeActions(actions, out); - } else { - out.writeShort(ACTIONS_INSTRUCTION_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); - } - } - - /** - * Computes length of instructions - * @param instructions List of instructions - * @return length of instructions (in bytes) - */ - public static int computeInstructionsLength(List instructions) { - int length = 0; - if (instructions != null) { - for (Instruction instruction : instructions) { - Class type = instruction.getType(); - if (type.isAssignableFrom(GotoTable.class)) { - length += GOTO_TABLE_LENGTH; - } else if (type.isAssignableFrom(WriteMetadata.class)) { - length += WRITE_METADATA_LENGTH; - } else if (type.isAssignableFrom(WriteActions.class)) { - length += ACTIONS_INSTRUCTION_LENGTH; - if (instruction.getAugmentation(ActionsInstruction.class) != null) { - length += ActionsSerializer.computeLengthOfActions( - instruction.getAugmentation(ActionsInstruction.class).getAction()); - } - } else if (type.isAssignableFrom(ApplyActions.class)) { - length += ACTIONS_INSTRUCTION_LENGTH; - if (instruction.getAugmentation(ActionsInstruction.class) != null) { - length += ActionsSerializer.computeLengthOfActions( - instruction.getAugmentation(ActionsInstruction.class).getAction()); - } - } else if (type.isAssignableFrom(ClearActions.class)) { - length += ACTIONS_INSTRUCTION_LENGTH; - } else if (type.isAssignableFrom(Meter.class)) { - length += METER_LENGTH; - } else if (type.isAssignableFrom(Experimenter.class)) { - ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); - byte[] data = experimenter.getData(); - length += EXPERIMENTER_LENGTH + data.length; - } - } - } - return length; - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchIdsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchIdsSerializer.java deleted file mode 100644 index eea0844d..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchIdsSerializer.java +++ /dev/null @@ -1,210 +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.util; - -import io.netty.buffer.ByteBuf; - -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.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.MatchField; -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.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.oxm.fields.grouping.MatchEntries; - -/** - * Encodes match ids (oxm_ids) needed in Multipart-TableFeatures messages - * @author michal.polkorab - */ -public abstract class MatchIdsSerializer { - - /** - * Encodes oxm headers (without values) - * @param entry match entry - * @param out output ByteBuf - */ - public static void encodeIdsRest(MatchEntries entry, ByteBuf out) { - int fieldValue = 0; - Class field = entry.getOxmMatchField(); - if (field.isAssignableFrom(InPort.class)) { - fieldValue = 0; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(InPhyPort.class)) { - fieldValue = 1; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Metadata.class)) { - fieldValue = 2; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(EthDst.class)) { - fieldValue = 3; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthSrc.class)) { - fieldValue = 4; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthType.class)) { - fieldValue = 5; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(VlanVid.class)) { - fieldValue = 6; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(VlanPcp.class)) { - fieldValue = 7; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(IpDscp.class)) { - fieldValue = 8; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(IpEcn.class)) { - fieldValue = 9; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(IpProto.class)) { - fieldValue = 10; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(Ipv4Src.class)) { - fieldValue = 11; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Ipv4Dst.class)) { - fieldValue = 12; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(TcpSrc.class)) { - fieldValue = 13; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(TcpDst.class)) { - fieldValue = 14; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(UdpSrc.class)) { - fieldValue = 15; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(UdpDst.class)) { - fieldValue = 16; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(SctpSrc.class)) { - fieldValue = 17; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(SctpDst.class)) { - fieldValue = 18; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv4Type.class)) { - fieldValue = 19; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv4Code.class)) { - fieldValue = 20; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(ArpOp.class)) { - fieldValue = 21; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(ArpSpa.class)) { - fieldValue = 22; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(ArpTpa.class)) { - fieldValue = 23; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(ArpSha.class)) { - fieldValue = 24; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(ArpTha.class)) { - fieldValue = 25; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6Src.class)) { - fieldValue = 26; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Dst.class)) { - fieldValue = 27; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Flabel.class)) { - fieldValue = 28; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv6Type.class)) { - fieldValue = 29; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv6Code.class)) { - fieldValue = 30; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { - fieldValue = 31; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6NdSll.class)) { - fieldValue = 32; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6NdTll.class)) { - fieldValue = 33; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(MplsLabel.class)) { - fieldValue = 34; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(MplsTc.class)) { - fieldValue = 35; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(MplsBos.class)) { - fieldValue = 36; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - } else if (field.isAssignableFrom(PbbIsid.class)) { - fieldValue = 37; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES); - } else if (field.isAssignableFrom(TunnelId.class)) { - fieldValue = 38; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { - fieldValue = 39; - MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java deleted file mode 100644 index 8443ed48..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java +++ /dev/null @@ -1,609 +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.util; - -import io.netty.buffer.ByteBuf; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; -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.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.Clazz; -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.MatchField; -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.oxm.fields.grouping.MatchEntries; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Serializes ofp_match (OpenFlow v1.3) and its oxm_fields structures - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class MatchSerializer { - private static final Logger LOGGER = LoggerFactory.getLogger(MatchSerializer.class); - private static final byte STANDARD_MATCH_TYPE_CODE = 0; - private static final byte OXM_MATCH_TYPE_CODE = 1; - private static final int NXM0_CLASS_CODE = 0x0000; - private static final int NXM1_CLASS_CODE = 0x0001; - private static final int OPENFLOW_BASIC_CLASS_CODE = 0x8000; - private static final int EXPERIMENTER_CLASS_CODE = 0xFFFF; - private static final byte MATCH_TYPE_AND_LENGTH_SIZE = 4; - private static final byte MATCH_ENTRY_HEADER_LENGTH = 4; - - /** - * Encodes match (OpenFlow v1.3) - * @param match ofp_match object - * @param out output ByteBuf - */ - public static void encodeMatch(Match match, ByteBuf out) { - if (match == null) { - LOGGER.debug("Match is null"); - return; - } - encodeType(match, out); - // Length of ofp_match (excluding padding) - int length = computeMatchLengthInternal(match); - out.writeShort(length); - encodeMatchEntries(match.getMatchEntries(), out); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, out); - } - } - - private static void encodeType(Match match, ByteBuf out) { - if (match.getType().isAssignableFrom(StandardMatchType.class)) { - out.writeShort(STANDARD_MATCH_TYPE_CODE); - } else if (match.getType().isAssignableFrom(OxmMatchType.class)) { - out.writeShort(OXM_MATCH_TYPE_CODE); - } - } - - /** - * Encodes MatchEntries - * @param matchEntries list of match entries (oxm_fields) - * @param out output ByteBuf - */ - public static void encodeMatchEntries(List matchEntries, ByteBuf out) { - if (matchEntries == null) { - LOGGER.debug("Match entries are null"); - return; - } - for (MatchEntries entry : matchEntries) { - encodeClass(entry.getOxmClass(), out); - encodeRest(entry, out); - } - } - - /** - * Encodes OXM ids (for Multipart - TableFeatures messages) - * @param matchEntries list of match entries (oxm_fields) - * @param out output ByteBuf - */ - public static void encodeMatchIds(List matchEntries, ByteBuf out) { - if (matchEntries == null) { - LOGGER.debug("Match entries are null"); - return; - } - for (MatchEntries entry : matchEntries) { - encodeClass(entry.getOxmClass(), out); - MatchIdsSerializer.encodeIdsRest(entry, out); - } - } - - private static void encodeClass(Class clazz, ByteBuf out) { - if (clazz.isAssignableFrom(Nxm0Class.class)) { - out.writeShort(NXM0_CLASS_CODE); - } else if (clazz.isAssignableFrom(Nxm1Class.class)) { - out.writeShort(NXM1_CLASS_CODE); - } else if (clazz.isAssignableFrom(OpenflowBasicClass.class)) { - out.writeShort(OPENFLOW_BASIC_CLASS_CODE); - } else if (clazz.isAssignableFrom(ExperimenterClass.class)) { - out.writeShort(EXPERIMENTER_CLASS_CODE); - } - } - - private static void encodeRest(MatchEntries entry, ByteBuf out) { - int fieldValue = 0; - Class field = entry.getOxmMatchField(); - if (field.isAssignableFrom(InPort.class)) { - fieldValue = 0; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - } else if (field.isAssignableFrom(InPhyPort.class)) { - fieldValue = 1; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - } else if (field.isAssignableFrom(Metadata.class)) { - fieldValue = 2; - writeMetadataRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthDst.class)) { - fieldValue = 3; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthSrc.class)) { - fieldValue = 4; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthType.class)) { - fieldValue = 5; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue()); - } else if (field.isAssignableFrom(VlanVid.class)) { - fieldValue = 6; - VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class); - int vlanVidValue = vlanVid.getVlanVid(); - if (vlanVid.isCfiBit()) { - short cfi = 1 << 12; // 13-th bit - vlanVidValue = vlanVidValue | cfi; - } - - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(vlanVidValue); - writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(VlanPcp.class)) { - fieldValue = 7; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue()); - } else if (field.isAssignableFrom(IpDscp.class)) { - fieldValue = 8; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue()); - } else if (field.isAssignableFrom(IpEcn.class)) { - fieldValue = 9; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn()); - } else if (field.isAssignableFrom(IpProto.class)) { - fieldValue = 10; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()); - } else if (field.isAssignableFrom(Ipv4Src.class)) { - fieldValue = 11; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv4Dst.class)) { - fieldValue = 12; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(TcpSrc.class)) { - fieldValue = 13; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(TcpDst.class)) { - fieldValue = 14; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(UdpSrc.class)) { - fieldValue = 15; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(UdpDst.class)) { - fieldValue = 16; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(SctpSrc.class)) { - fieldValue = 17; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(SctpDst.class)) { - fieldValue = 18; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(Icmpv4Type.class)) { - fieldValue = 19; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type()); - } else if (field.isAssignableFrom(Icmpv4Code.class)) { - fieldValue = 20; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code()); - } else if (field.isAssignableFrom(ArpOp.class)) { - fieldValue = 21; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode()); - } else if (field.isAssignableFrom(ArpSpa.class)) { - fieldValue = 22; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpTpa.class)) { - fieldValue = 23; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpSha.class)) { - fieldValue = 24; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpTha.class)) { - fieldValue = 25; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Src.class)) { - fieldValue = 26; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Dst.class)) { - fieldValue = 27; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Flabel.class)) { - fieldValue = 28; - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); - writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv6Type.class)) { - fieldValue = 29; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type()); - } else if (field.isAssignableFrom(Icmpv6Code.class)) { - fieldValue = 30; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code()); - } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { - fieldValue = 31; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6NdSll.class)) { - fieldValue = 32; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6NdTll.class)) { - fieldValue = 33; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(MplsLabel.class)) { - fieldValue = 34; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); - } else if (field.isAssignableFrom(MplsTc.class)) { - fieldValue = 35; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc()); - } else if (field.isAssignableFrom(MplsBos.class)) { - fieldValue = 36; - writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue()); - } else if (field.isAssignableFrom(PbbIsid.class)) { - fieldValue = 37; - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES); - out.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); - writeMask(entry, out, EncodeConstants.SIZE_OF_3_BYTES); - } else if (field.isAssignableFrom(TunnelId.class)) { - fieldValue = 38; - writeMetadataRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { - fieldValue = 39; - Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField(); - Map map = new HashMap<>(); - map.put(0, pseudoField.isNonext()); - map.put(1, pseudoField.isEsp()); - map.put(2, pseudoField.isAuth()); - map.put(3, pseudoField.isDest()); - map.put(4, pseudoField.isFrag()); - map.put(5, pseudoField.isRouter()); - map.put(6, pseudoField.isHop()); - map.put(7, pseudoField.isUnrep()); - map.put(8, pseudoField.isUnseq()); - int bitmap = ByteBufUtils.fillBitMaskFromMap(map); - - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(bitmap); - writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - } - - private static void writeMask(MatchEntries entry, ByteBuf out, int length) { - if (entry.isHasMask()) { - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - if (mask != null && mask.length != length) { - throw new IllegalArgumentException("incorrect length of mask: "+ - mask.length + ", expected: " + length); - } - out.writeBytes(mask); - } - } - - protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) { - int fieldAndMask = fieldValue << 1; - int length = lengthArg; - if (hasMask) { - fieldAndMask |= 1; - length *= 2; - } - - out.writeByte(fieldAndMask); - out.writeByte(length); - - } - - private static void writeMetadataRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value; - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_LONG_IN_BYTES); - out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); - writeMask(entry, out, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - - private static void writeMacAddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value; - - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.MAC_ADDRESS_LENGTH); - String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); - out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); // 48 b + mask [OF 1.3.2 spec] - writeMask(entry, out, EncodeConstants.MAC_ADDRESS_LENGTH); - } - - private static void writeIpv4AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value; - - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_INT_IN_BYTES); - writeIpv4Address(entry, out); - writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - - private static void writeIpv4Address(MatchEntries entry, ByteBuf out) { - String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().getValue().split("\\."); - for (int i = 0; i < addressGroups.length; i++) { - out.writeByte(Integer.parseInt(addressGroups[i])); - } - } - - private static void writeIpv6AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value; - String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); - String[] address; - if (textAddress.equals("::")) { - address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - Arrays.fill(address, "0"); - } else { - address = parseIpv6Address(textAddress.split(":")); - } - - writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), - EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - for (int i = 0; i < address.length; i++) { - out.writeShort(Integer.parseInt(address[i], 16)); - } - writeMask(entry, out, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } - - private static String[] parseIpv6Address(String[] addressGroups) { - int countEmpty = 0; - for (int i = 0; i < addressGroups.length; i++) { - if (addressGroups[i].equals("")){ - countEmpty++; - } - } - String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - switch (countEmpty) { - case 0: - ready = addressGroups; - break; - case 1: - int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1; - int index = 0; - for (int i = 0; i < addressGroups.length; i++) { - if (addressGroups[i].equals("")) { - for (int j = 0; j < zerosToBePushed; j++) { - ready[index] = "0"; - index++; - } - } else { - ready[index] = addressGroups[i]; - index++; - } - } - break; - case 2: - Arrays.fill(ready, "0"); - ready[ready.length - 1] = addressGroups[addressGroups.length - 1]; - break; - default: - throw new IllegalStateException("Incorrect ipv6 address"); - } - return ready; - } - - /** - * Computes length of match (in bytes) - * @param match - * @return length of ofp_match (excluding padding) - */ - public static int computeMatchLengthInternal(Match match) { - int length = 0; - if (match != null) { - length += MATCH_TYPE_AND_LENGTH_SIZE + computeMatchEntriesLength(match.getMatchEntries()); - } - return length; - } - - /** - * Computes length of match (in bytes) - * @param match - * @return length of ofp_match (excluding padding) - */ - public static int computeMatchLength(Match match) { - int length = computeMatchLengthInternal(match); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - length += EncodeConstants.PADDING - paddingRemainder; - } - return length; - } - - /** - * Computes length of MatchEntries (in bytes) - * @param matchEntries list of match entries (oxm_fields) - * @return length of MatchEntries - */ - public static int computeMatchEntriesLength(List matchEntries) { - int length = 0; - if (matchEntries != null) { - for (MatchEntries entry : matchEntries) { - length += MATCH_ENTRY_HEADER_LENGTH; - Class field = entry.getOxmMatchField(); - if (field.isAssignableFrom(InPort.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(InPhyPort.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(Metadata.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(EthDst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthSrc.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthType.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(VlanVid.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(VlanPcp.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpDscp.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpEcn.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpProto.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Ipv4Src.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Ipv4Dst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(TcpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(TcpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(UdpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(UdpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(SctpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(SctpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv4Type.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv4Code.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(ArpOp.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(ArpSpa.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(ArpTpa.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(ArpSha.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(ArpTha.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6Src.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Dst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Flabel.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv6Type.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv6Code.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6NdSll.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6NdTll.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(MplsLabel.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(MplsTc.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(MplsBos.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(PbbIsid.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_3_BYTES); - } else if (field.isAssignableFrom(TunnelId.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - } - } - return length; - } - - private static int computePossibleMaskEntryLength(MatchEntries entry, int length) { - int entryLength = length; - if (entry.isHasMask()) { - entryLength *= 2; - } - return entryLength; - } - -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java index eaaa6de8..3ec867d7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java @@ -10,8 +10,10 @@ package org.opendaylight.openflowjava.protocol.impl.util; import io.netty.buffer.ByteBuf; -import java.util.List; - +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; 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; @@ -40,7 +42,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 * Serializes ofp_action (OpenFlow v1.0) structures * @author michal.polkorab */ -public abstract class OF10ActionsSerializer { +public class OF10ActionsSerializer implements OFSerializer, RegistryInjector { private static final byte OUTPUT_CODE = 0; private static final byte SET_VLAN_VID_CODE = 1; @@ -54,7 +56,6 @@ public abstract class OF10ActionsSerializer { private static final byte SET_TP_SRC_CODE = 9; private static final byte SET_TP_DST_CODE = 10; private static final byte ENQUEUE_CODE = 11; - private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF private static final byte GENERIC_ACTION_LENGTH = 8; private static final byte PADDING_IN_GENERIC_ACTION = 4; private static final byte OUTPUT_LENGTH = 8; @@ -71,55 +72,50 @@ public abstract class OF10ActionsSerializer { private static final byte PADDING_IN_TP_PORT_ACTION = 2; private static final byte ENQUEUE_LENGTH = 16; private static final byte PADDING_IN_ENQUEUE_ACTION = 6; - private static final byte EXPERIMENTER_LENGTH = 8; + private SerializerRegistry registry; - - /** - * Encodes ofp_action (OpenFlow v1.0) structures - * @param out output ByteBuf that actions will be written into - * @param actions actions to be encoded - */ - public static void encodeActionsV10(ByteBuf out, List actions) { - if (actions == null) { - return; - } - for (Action action : actions) { - if (action.getType().equals(Output.class)) { - encodeOutputAction(action, out); - } else if (action.getType().equals(SetVlanVid.class)) { - encodeSetVlanVidAction(action, out); - } else if (action.getType().equals(SetVlanPcp.class)) { - encodeSetVlanPcpAction(action, out); - } else if (action.getType().equals(StripVlan.class)) { - encodeGenericAction(STRIP_VLAN_CODE, out); - } else if (action.getType().equals(SetDlSrc.class)) { - encodeDlAddressAction(action, out, SET_DL_SRC_CODE); - } else if (action.getType().equals(SetDlDst.class)) { - encodeDlAddressAction(action, out, SET_DL_DST_CODE); - } else if (action.getType().equals(SetNwSrc.class)) { - encodeIpAddressAction(action, out, SET_NW_SRC_CODE); - } else if (action.getType().equals(SetNwDst.class)) { - encodeIpAddressAction(action, out, SET_NW_DST_CODE); - } else if (action.getType().equals(SetNwTos.class)) { - encodeNwTosAction(action, out); - } else if (action.getType().equals(SetTpSrc.class)) { - encodeTpPortAction(action, out, SET_TP_SRC_CODE); - } else if (action.getType().equals(SetTpDst.class)) { - encodeTpPortAction(action, out, SET_TP_DST_CODE); - } else if (action.getType().equals(Enqueue.class)) { - encodeEnqueueAction(action, out); - } else if (action.getType().equals(Experimenter.class)) { - encodeExperimenterAction(action, out); - } + @Override + public void serialize(Action action, ByteBuf outBuffer) { + if (action.getType().equals(Output.class)) { + encodeOutputAction(action, outBuffer); + } else if (action.getType().equals(SetVlanVid.class)) { + encodeSetVlanVidAction(action, outBuffer); + } else if (action.getType().equals(SetVlanPcp.class)) { + encodeSetVlanPcpAction(action, outBuffer); + } else if (action.getType().equals(StripVlan.class)) { + encodeGenericAction(STRIP_VLAN_CODE, outBuffer); + } else if (action.getType().equals(SetDlSrc.class)) { + encodeDlAddressAction(action, outBuffer, SET_DL_SRC_CODE); + } else if (action.getType().equals(SetDlDst.class)) { + encodeDlAddressAction(action, outBuffer, SET_DL_DST_CODE); + } else if (action.getType().equals(SetNwSrc.class)) { + encodeIpAddressAction(action, outBuffer, SET_NW_SRC_CODE); + } else if (action.getType().equals(SetNwDst.class)) { + encodeIpAddressAction(action, outBuffer, SET_NW_DST_CODE); + } else if (action.getType().equals(SetNwTos.class)) { + encodeNwTosAction(action, outBuffer); + } else if (action.getType().equals(SetTpSrc.class)) { + encodeTpPortAction(action, outBuffer, SET_TP_SRC_CODE); + } else if (action.getType().equals(SetTpDst.class)) { + encodeTpPortAction(action, outBuffer, SET_TP_DST_CODE); + } else if (action.getType().equals(Enqueue.class)) { + encodeEnqueueAction(action, outBuffer); + } else if (action.getType().equals(Experimenter.class)) { + encodeExperimenterAction(action, outBuffer); } } - + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; + } + private static void encodeGenericAction(byte code, ByteBuf out) { out.writeShort(code); out.writeShort(GENERIC_ACTION_LENGTH); ByteBufUtils.padBuffer(PADDING_IN_GENERIC_ACTION, out); } - + private static void encodeOutputAction(Action action, ByteBuf out) { out.writeShort(OUTPUT_CODE); out.writeShort(OUTPUT_LENGTH); @@ -185,53 +181,11 @@ public abstract class OF10ActionsSerializer { QueueIdAction queueId = action.getAugmentation(QueueIdAction.class); out.writeInt(queueId.getQueueId().intValue()); } - - private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(EXPERIMENTER_CODE); - outBuffer.writeShort(EXPERIMENTER_LENGTH); - ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - } - - /** - * Computes length of actions - * @param actions - * @return length of actions (OpenFlow v1.0) - */ - public static int computeActionsLength(List actions) { - int length = 0; - if (actions != null) { - for (Action action : actions) { - if (action.getType().equals(Output.class)) { - length += 8; - } else if (action.getType().equals(SetVlanVid.class)) { - length += 8; - } else if (action.getType().equals(SetVlanPcp.class)) { - length += 8; - } else if (action.getType().equals(StripVlan.class)) { - length += 8; - } else if (action.getType().equals(SetDlSrc.class)) { - length += 16; - } else if (action.getType().equals(SetDlDst.class)) { - length += 16; - } else if (action.getType().equals(SetNwSrc.class)) { - length += 8; - } else if (action.getType().equals(SetNwDst.class)) { - length += 8; - } else if (action.getType().equals(SetNwTos.class)) { - length += 8; - } else if (action.getType().equals(SetTpSrc.class)) { - length += 8; - } else if (action.getType().equals(SetTpDst.class)) { - length += 8; - } else if (action.getType().equals(Enqueue.class)) { - length += 16; - } else if (action.getType().equals(Experimenter.class)) { - length += 8; - } - } - } - return length; + + private void encodeExperimenterAction(Action action, ByteBuf outBuffer) { + OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class)); + serializer.serialize((ExperimenterAction) action, outBuffer); } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java index 33f31971..d934e4c7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java @@ -8,11 +8,12 @@ package org.opendaylight.openflowjava.protocol.impl.util; +import io.netty.buffer.ByteBuf; + import java.util.HashMap; import java.util.Map; -import io.netty.buffer.ByteBuf; - +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; @@ -20,42 +21,43 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc * Serializes ofp_match (OpenFlow v1.0) structure * @author michal.polkorab */ -public abstract class OF10MatchSerializer { +public class OF10MatchSerializer implements OFSerializer { private static final byte PADDING_IN_MATCH = 1; private static final byte PADDING_IN_MATCH_2 = 2; private static final byte NW_SRC_SHIFT = 8; private static final byte NW_DST_SHIFT = 14; - + /** - * Encodes ofp_match (OpenFlow v1.0) - * @param out output ByteBuf that match will be written into - * @param match match to be encoded + * Serializes ofp_match (OpenFlow v1.0) + * @param outBuffer output ByteBuf + * @param match match to be serialized */ - public static void encodeMatchV10(ByteBuf out, MatchV10 match) { - out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask())); - out.writeShort(match.getInPort()); - out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue())); - out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue())); - out.writeShort(match.getDlVlan()); - out.writeByte(match.getDlVlanPcp()); - ByteBufUtils.padBuffer(PADDING_IN_MATCH, out); - out.writeShort(match.getDlType()); - out.writeByte(match.getNwTos()); - out.writeByte(match.getNwProto()); - ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, out); + @Override + public void serialize(MatchV10 match, ByteBuf outBuffer) { + outBuffer.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask())); + outBuffer.writeShort(match.getInPort()); + outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue())); + outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue())); + outBuffer.writeShort(match.getDlVlan()); + outBuffer.writeByte(match.getDlVlanPcp()); + ByteBufUtils.padBuffer(PADDING_IN_MATCH, outBuffer); + outBuffer.writeShort(match.getDlType()); + outBuffer.writeByte(match.getNwTos()); + outBuffer.writeByte(match.getNwProto()); + ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, outBuffer); String[] srcGroups = match.getNwSrc().getValue().split("\\."); for (int i = 0; i < srcGroups.length; i++) { - out.writeByte(Integer.parseInt(srcGroups[i])); + outBuffer.writeByte(Integer.parseInt(srcGroups[i])); } String[] dstGroups = match.getNwDst().getValue().split("\\."); for (int i = 0; i < dstGroups.length; i++) { - out.writeByte(Integer.parseInt(dstGroups[i])); + outBuffer.writeByte(Integer.parseInt(dstGroups[i])); } - out.writeShort(match.getTpSrc()); - out.writeShort(match.getTpDst()); + outBuffer.writeShort(match.getTpSrc()); + outBuffer.writeShort(match.getTpDst()); } - + private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) { int bitmask = 0; Map wildcardsMap = new HashMap<>(); @@ -74,5 +76,5 @@ public abstract class OF10MatchSerializer { bitmask |= ((32 - dstMask) << NW_DST_SHIFT); return bitmask; } - + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializer.java similarity index 52% rename from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java rename to openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializer.java index 5490bdbb..e1f4ec6f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializer.java @@ -10,8 +10,12 @@ package org.opendaylight.openflowjava.protocol.impl.util; import io.netty.buffer.ByteBuf; -import java.util.List; - +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey; 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; @@ -46,7 +50,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. * @author michal.polkorab * @author timotej.kubas */ -public abstract class ActionsSerializer { +public class OF13ActionsSerializer implements OFSerializer, + HeaderSerializer, RegistryInjector { private static final byte OUTPUT_CODE = 0; private static final byte COPY_TTL_OUT_CODE = 11; @@ -64,123 +69,60 @@ public abstract class ActionsSerializer { private static final int SET_FIELD_CODE = 25; private static final byte PUSH_PBB_CODE = 26; private static final byte POP_PBB_CODE = 27; - private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF private static final byte OUTPUT_LENGTH = 16; private static final byte SET_MPLS_TTL_LENGTH = 8; private static final byte SET_QUEUE_LENGTH = 8; private static final byte GROUP_LENGTH = 8; private static final byte SET_NW_TTL_LENGTH = 8; - private static final byte EXPERIMENTER_ACTION_HEADER_LENGTH = 8; private static final byte ACTION_HEADER_LENGTH = 8; private static final byte LENGTH_OF_ETHERTYPE_ACTION = 8; - private static final byte LENGTH_OF_OTHER_ACTIONS = 8; - private static final byte SET_FIELD_HEADER_LENGTH = 4; // only type and length private static final byte OUTPUT_PADDING = 6; private static final byte SET_MPLS_TTL_PADDING = 3; private static final byte SET_NW_TTL_PADDING = 3; private static final byte PADDING_IN_ACTION_HEADER = 4; private static final byte ETHERTYPE_ACTION_PADDING = 2; private static final byte ACTION_IDS_LENGTH = 4; + private SerializerRegistry registry; - - /** - * Encodes actions to ByteBuf - * @param actionsList list of actions to be encoded - * @param outBuffer output ByteBuf - */ - public static void encodeActions(List actionsList, ByteBuf outBuffer) { - if (actionsList == null) { - return; - } - for (Action action : actionsList) { - if (action.getType().isAssignableFrom(Output.class)) { - encodeOutputAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { - encodeCopyTtlOutAction(outBuffer); - } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { - encodeCopyTtlInAction(outBuffer); - } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { - encodeSetMplsTtltAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { - encodeDecMplsTtlAction(outBuffer); - } else if (action.getType().isAssignableFrom(PushVlan.class)) { - encodePushVlanAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopVlan.class)) { - encodePopVlanAction(outBuffer); - } else if (action.getType().isAssignableFrom(PushMpls.class)) { - encodePushMplsAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopMpls.class)) { - encodePopMplsAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(SetQueue.class)) { - encodeSetQueueAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(Group.class)) { - encodeGroupAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { - encodeSetNwTtlAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { - encodeDecNwTtlAction(outBuffer); - } else if (action.getType().isAssignableFrom(SetField.class)) { - encodeSetFieldAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PushPbb.class)) { - encodePushPbbAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopPbb.class)) { - encodePopPbbAction(outBuffer); - } else if (action.getType().isAssignableFrom(Experimenter.class)) { - encodeExperimenterAction(action, outBuffer); - } - } - } - - /** - * Encodes action ids to ByteBuf (for Multipart - TableFeatures messages) - * @param actionsList list of actions to be encoded - * @param outBuffer output ByteBuf - */ - public static void encodeActionIds(List actionsList, ByteBuf outBuffer) { - if (actionsList == null) { - return; - } - for (Action action : actionsList) { - if (action.getType().isAssignableFrom(Output.class)) { - writeTypeAndLength(outBuffer, OUTPUT_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { - writeTypeAndLength(outBuffer, COPY_TTL_OUT_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { - writeTypeAndLength(outBuffer, COPY_TTL_IN_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { - writeTypeAndLength(outBuffer, SET_MPLS_TTL_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { - writeTypeAndLength(outBuffer, DEC_MPLS_TTL_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PushVlan.class)) { - writeTypeAndLength(outBuffer, PUSH_VLAN_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PopVlan.class)) { - writeTypeAndLength(outBuffer, POP_VLAN_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PushMpls.class)) { - writeTypeAndLength(outBuffer, PUSH_MPLS_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PopMpls.class)) { - writeTypeAndLength(outBuffer, POP_MPLS_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(SetQueue.class)) { - writeTypeAndLength(outBuffer, SET_QUEUE_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(Group.class)) { - writeTypeAndLength(outBuffer, GROUP_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { - writeTypeAndLength(outBuffer, SET_NW_TTL_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { - writeTypeAndLength(outBuffer, DEC_NW_TTL_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(SetField.class)) { - writeTypeAndLength(outBuffer, SET_FIELD_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PushPbb.class)) { - writeTypeAndLength(outBuffer, PUSH_PBB_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(PopPbb.class)) { - writeTypeAndLength(outBuffer, POP_PBB_CODE, ACTION_IDS_LENGTH); - } else if (action.getType().isAssignableFrom(Experimenter.class)) { - writeTypeAndLength(outBuffer, EXPERIMENTER_CODE, EncodeConstants.EXPERIMENTER_IDS_LENGTH); - ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - } + @Override + public void serialize(Action action, ByteBuf outBuffer) { + if (action.getType().isAssignableFrom(Output.class)) { + encodeOutputAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { + encodeCopyTtlOutAction(outBuffer); + } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { + encodeCopyTtlInAction(outBuffer); + } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { + encodeSetMplsTtltAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { + encodeDecMplsTtlAction(outBuffer); + } else if (action.getType().isAssignableFrom(PushVlan.class)) { + encodePushVlanAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopVlan.class)) { + encodePopVlanAction(outBuffer); + } else if (action.getType().isAssignableFrom(PushMpls.class)) { + encodePushMplsAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopMpls.class)) { + encodePopMplsAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(SetQueue.class)) { + encodeSetQueueAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(Group.class)) { + encodeGroupAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { + encodeSetNwTtlAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { + encodeDecNwTtlAction(outBuffer); + } else if (action.getType().isAssignableFrom(SetField.class)) { + encodeSetFieldAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PushPbb.class)) { + encodePushPbbAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopPbb.class)) { + encodePopPbbAction(outBuffer); + } else if (action.getType().isAssignableFrom(Experimenter.class)) { + encodeExperimenterAction(action, outBuffer); } } - + private static void writeTypeAndLength(ByteBuf out, int type, int length) { out.writeShort(type); out.writeShort(length); @@ -265,20 +207,22 @@ public abstract class ActionsSerializer { outBuffer.writeShort(DEC_NW_TTL_CODE); encodeRestOfActionHeader(outBuffer); } - - private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) { + + private void encodeSetFieldAction(Action action, ByteBuf outBuffer) { OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class); - int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH; + int setFieldStartIndex = outBuffer.writerIndex(); outBuffer.writeShort(SET_FIELD_CODE); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - length += EncodeConstants.PADDING - paddingRemainder; - } - outBuffer.writeShort(length); - MatchSerializer.encodeMatchEntries(oxmField.getMatchEntries(), outBuffer); + int setFieldLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + MatchEntries entry = oxmField.getMatchEntries().get(0); + OFSerializer serializer = registry.getSerializer(new EnhancedMessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField())); + serializer.serialize(entry, outBuffer); + int paddingRemainder = (outBuffer.writerIndex() - setFieldStartIndex) % EncodeConstants.PADDING; if (paddingRemainder != 0) { ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer); } + outBuffer.setShort(setFieldLengthIndex, outBuffer.writerIndex() - setFieldStartIndex); } private static void encodePushPbbAction(Action action, ByteBuf outBuffer) { @@ -291,17 +235,10 @@ public abstract class ActionsSerializer { encodeRestOfActionHeader(outBuffer); } - private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(EXPERIMENTER_CODE); - ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); - if (experimenter.getData() != null) { - outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH + experimenter.getData().length); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - outBuffer.writeBytes(experimenter.getData()); - } else { - outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - } + private void encodeExperimenterAction(Action action, ByteBuf outBuffer) { + OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class)); + serializer.serialize((ExperimenterAction) action, outBuffer); } private static void encodeRestOfActionHeader(ByteBuf outBuffer) { @@ -315,35 +252,51 @@ public abstract class ActionsSerializer { outBuffer.writeShort(ethertype.getEthertype().getValue()); ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer); } - - /** - * Computes length of actions - * @param actionsList list of actions - * @return actions length - */ - public static int computeLengthOfActions(List actionsList) { - int lengthOfActions = 0; - if (actionsList != null) { - for (Action action : actionsList) { - if (action.getType().isAssignableFrom(Output.class)) { - lengthOfActions += OUTPUT_LENGTH; - } else if (action.getType().isAssignableFrom(SetField.class)){ - List entries = action.getAugmentation(OxmFieldsAction.class).getMatchEntries(); - int actionLength = (2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES) + MatchSerializer.computeMatchEntriesLength(entries); - lengthOfActions += actionLength; - int paddingRemainder = actionLength % EncodeConstants.PADDING; - if ((paddingRemainder) != 0) { - lengthOfActions += EncodeConstants.PADDING - paddingRemainder; - } - } else if (action.getType().isAssignableFrom(Experimenter.class)) { - ExperimenterAction experimenterAction = action.getAugmentation(ExperimenterAction.class); - lengthOfActions += experimenterAction.getData().length; - lengthOfActions += EncodeConstants.SIZE_OF_LONG_IN_BYTES; - } else { - lengthOfActions += LENGTH_OF_OTHER_ACTIONS; - } - } + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; + } + + @Override + public void serializeHeader(Action action, ByteBuf outBuffer) { + if (action.getType().isAssignableFrom(Output.class)) { + writeTypeAndLength(outBuffer, OUTPUT_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { + writeTypeAndLength(outBuffer, COPY_TTL_OUT_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { + writeTypeAndLength(outBuffer, COPY_TTL_IN_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { + writeTypeAndLength(outBuffer, SET_MPLS_TTL_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { + writeTypeAndLength(outBuffer, DEC_MPLS_TTL_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PushVlan.class)) { + writeTypeAndLength(outBuffer, PUSH_VLAN_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PopVlan.class)) { + writeTypeAndLength(outBuffer, POP_VLAN_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PushMpls.class)) { + writeTypeAndLength(outBuffer, PUSH_MPLS_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PopMpls.class)) { + writeTypeAndLength(outBuffer, POP_MPLS_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(SetQueue.class)) { + writeTypeAndLength(outBuffer, SET_QUEUE_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(Group.class)) { + writeTypeAndLength(outBuffer, GROUP_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { + writeTypeAndLength(outBuffer, SET_NW_TTL_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { + writeTypeAndLength(outBuffer, DEC_NW_TTL_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(SetField.class)) { + writeTypeAndLength(outBuffer, SET_FIELD_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PushPbb.class)) { + writeTypeAndLength(outBuffer, PUSH_PBB_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(PopPbb.class)) { + writeTypeAndLength(outBuffer, POP_PBB_CODE, ACTION_IDS_LENGTH); + } else if (action.getType().isAssignableFrom(Experimenter.class)) { + HeaderSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class)); + serializer.serializeHeader((ExperimenterAction) action, outBuffer); } - return lengthOfActions; } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializer.java new file mode 100644 index 00000000..84beb0b0 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializer.java @@ -0,0 +1,143 @@ +/* + * 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.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; +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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; +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.InstructionBase; + +/** + * Serializes ofp_instruction (OpenFlow v 1.3) structure + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF13InstructionsSerializer implements OFSerializer, + HeaderSerializer, RegistryInjector { + + private static final byte GOTO_TABLE_TYPE = 1; + private static final byte WRITE_METADATA_TYPE = 2; + private static final byte WRITE_ACTIONS_TYPE = 3; + private static final byte APPLY_ACTIONS_TYPE = 4; + private static final byte CLEAR_ACTIONS_TYPE = 5; + private static final byte METER_TYPE = 6; + private static final byte GOTO_TABLE_LENGTH = 8; + private static final byte WRITE_METADATA_LENGTH = 24; + private static final byte METER_LENGTH = 8; + private static final byte ACTIONS_INSTRUCTION_LENGTH = 8; + private static final byte PADDING_IN_GOTO_TABLE = 3; + private static final byte PADDING_IN_WRITE_METADATA = 4; + private static final byte PADDING_IN_CLEAR_ACTIONS = 4; + private static final byte INSTRUCTION_IDS_LENGTH = 4; + private static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4; + private SerializerRegistry registry; + + private static void writeTypeAndLength(ByteBuf out, int type, int length) { + out.writeShort(type); + out.writeShort(length); + } + + private void writeActionsInstruction(ByteBuf out, + Instruction instruction, int type) { + int instructionStartIndex = out.writerIndex(); + out.writeShort(type); + if (instruction.getAugmentation(ActionsInstruction.class) != null) { + List actions = instruction.getAugmentation(ActionsInstruction.class).getAction(); + int instructionLengthIndex = out.writerIndex(); + out.writeShort(EncodeConstants.EMPTY_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); + OFSerializer serializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class)); + CodingUtils.serializeList(actions, serializer, out); + int instructionLength = out.writerIndex() - instructionStartIndex; + out.setShort(instructionLengthIndex, instructionLength); + } else { + out.writeShort(ACTIONS_INSTRUCTION_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); + } + } + + @Override + public void serialize(Instruction instruction, ByteBuf outBuffer) { + Class type = instruction.getType(); + if (type.isAssignableFrom(GotoTable.class)) { + writeTypeAndLength(outBuffer, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH); + outBuffer.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId()); + ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, outBuffer); + } else if (type.isAssignableFrom(WriteMetadata.class)) { + writeTypeAndLength(outBuffer, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, outBuffer); + MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class); + outBuffer.writeBytes(metadata.getMetadata()); + outBuffer.writeBytes(metadata.getMetadataMask()); + } else if (type.isAssignableFrom(WriteActions.class)) { + writeActionsInstruction(outBuffer, instruction, WRITE_ACTIONS_TYPE); + } else if (type.isAssignableFrom(ApplyActions.class)) { + writeActionsInstruction(outBuffer, instruction, APPLY_ACTIONS_TYPE); + } else if (type.isAssignableFrom(ClearActions.class)) { + writeTypeAndLength(outBuffer, CLEAR_ACTIONS_TYPE, ACTIONS_INSTRUCTION_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, outBuffer); + } else if (type.isAssignableFrom(Meter.class)) { + writeTypeAndLength(outBuffer, METER_TYPE, METER_LENGTH); + outBuffer.writeInt(instruction.getAugmentation(MeterIdInstruction.class).getMeterId().intValue()); + } else if (type.isAssignableFrom(Experimenter.class)) { + OFSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Experimenter.class)); + serializer.serialize((ExperimenterInstruction) instruction, outBuffer); + } + } + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; + } + + @Override + public void serializeHeader(Instruction instruction, ByteBuf outBuffer) { + Class type = instruction.getType(); + if (type.isAssignableFrom(GotoTable.class)) { + writeTypeAndLength(outBuffer, GOTO_TABLE_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(WriteMetadata.class)) { + writeTypeAndLength(outBuffer, WRITE_METADATA_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(WriteActions.class)) { + writeTypeAndLength(outBuffer, WRITE_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(ApplyActions.class)) { + writeTypeAndLength(outBuffer, APPLY_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(ClearActions.class)) { + writeTypeAndLength(outBuffer, CLEAR_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(Meter.class)) { + writeTypeAndLength(outBuffer, METER_TYPE, INSTRUCTION_IDS_LENGTH); + } else if (type.isAssignableFrom(Experimenter.class)) { + HeaderSerializer serializer = registry.getSerializer(new MessageTypeKey<>( + EncodeConstants.OF13_VERSION_ID, Experimenter.class)); + serializer.serializeHeader((ExperimenterInstruction) instruction, outBuffer); + } + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchEntriesRegistryHelper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchEntriesRegistryHelper.java new file mode 100644 index 00000000..3a5b6a7f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchEntriesRegistryHelper.java @@ -0,0 +1,44 @@ +/* + * 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.OFGeneralSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey; + +/** + * @author michal.polkorab + * @param OXM class + */ +public class OF13MatchEntriesRegistryHelper { + + private short version; + private Class oxmClass; + private SerializerRegistry serializerRegistry; + + /** + * @param version Openflow wire version + * @param oxmClass + * @param serializerRegistry + */ + public OF13MatchEntriesRegistryHelper(short version, Class oxmClass, SerializerRegistry serializerRegistry) { + this.version = version; + this.oxmClass = oxmClass; + this.serializerRegistry = serializerRegistry; + } + + /** + * Registers given serializer + * @param oxmField + * @param serializer + */ + public void registerSerializer(Class oxmField, OFGeneralSerializer serializer) { + serializerRegistry.registerSerializer(new EnhancedMessageTypeKey<>(version, oxmClass, oxmField), + serializer); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializer.java new file mode 100644 index 00000000..a90e77bc --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializer.java @@ -0,0 +1,88 @@ +/* + * 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.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +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.oxm.fields.grouping.MatchEntries; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Serializes ofp_match (OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class OF13MatchSerializer implements OFSerializer, RegistryInjector { + private static final Logger LOGGER = LoggerFactory.getLogger(OF13MatchSerializer.class); + private static final byte STANDARD_MATCH_TYPE_CODE = 0; + private static final byte OXM_MATCH_TYPE_CODE = 1; + private SerializerRegistry registry; + + @Override + public void serialize(Match match, ByteBuf outBuffer) { + if (match == null) { + LOGGER.debug("Match is null"); + return; + } + int matchStartIndex = outBuffer.writerIndex(); + serializeType(match, outBuffer); + int matchLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); + serializeMatchEntries(match.getMatchEntries(), outBuffer); + // Length of ofp_match (excluding padding) + int matchLength = outBuffer.writerIndex() - matchStartIndex; + outBuffer.setShort(matchLengthIndex, matchLength); + int paddingRemainder = matchLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer); + } + } + + private static void serializeType(Match match, ByteBuf out) { + if (match.getType().isAssignableFrom(StandardMatchType.class)) { + out.writeShort(STANDARD_MATCH_TYPE_CODE); + } else if (match.getType().isAssignableFrom(OxmMatchType.class)) { + out.writeShort(OXM_MATCH_TYPE_CODE); + } + } + + /** + * Serializes MatchEntries + * @param matchEntries list of match entries (oxm_fields) + * @param out output ByteBuf + */ + public void serializeMatchEntries(List matchEntries, ByteBuf out) { + if (matchEntries == null) { + LOGGER.debug("Match entries are null"); + return; + } + for (MatchEntries entry : matchEntries) { + OFSerializer entrySerializer = registry.getSerializer( + new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), + entry.getOxmMatchField())); + entrySerializer.serialize(entry, out); + } + } + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; + } + +} 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 new file mode 100644 index 00000000..9e3f829d --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java @@ -0,0 +1,106 @@ +/* + * 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; + +/** + * Stores oxm_match constants + * @author michal.polkorab + * + */ +public abstract class OxmMatchConstants { + + /** Backward compatibility with NXM */ + public static final int NXM_0_CLASS = 0x0000; + /** Backward compatibility with NXM */ + public static final int NXM_1_CLASS = 0x0001; + /** Basic class for OpenFlow */ + 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 */ + public static final int IN_PHY_PORT = 1; + /** Metadata passed between tables */ + public static final int METADATA = 2; + /** Ethernet destination address */ + public static final int ETH_DST = 3; + /** Ethernet source address */ + public static final int ETH_SRC = 4; + /** Ethernet frame type */ + public static final int ETH_TYPE = 5; + /** VLAN id. */ + public static final int VLAN_VID = 6; + /** VLAN priority. */ + public static final int VLAN_PCP = 7; + /** IP DSCP (6 bits in ToS field). */ + public static final int IP_DSCP = 8; + /** IP ECN (2 bits in ToS field). */ + public static final int IP_ECN = 9; + /** IP protocol. */ + public static final int IP_PROTO = 10; + /** IPv4 source address. */ + public static final int IPV4_SRC = 11; + /** IPv4 destination address. */ + public static final int IPV4_DST = 12; + /** TCP source port. */ + public static final int TCP_SRC = 13; + /** TCP destination port. */ + public static final int TCP_DST = 14; + /** UDP source port. */ + public static final int UDP_SRC = 15; + /** UDP destination port. */ + public static final int UDP_DST = 16; + /** SCTP source port. */ + public static final int SCTP_SRC = 17; + /** SCTP destination port. */ + public static final int SCTP_DST = 18; + /** ICMP type. */ + public static final int ICMPV4_TYPE = 19; + /** ICMP code. */ + public static final int ICMPV4_CODE = 20; + /** ARP opcode. */ + public static final int ARP_OP = 21; + /** ARP source IPv4 address. */ + public static final int ARP_SPA = 22; + /** ARP target IPv4 address. */ + public static final int ARP_TPA = 23; + /** ARP source hardware address. */ + public static final int ARP_SHA = 24; + /** ARP target hardware address. */ + public static final int ARP_THA = 25; + /** IPv6 source address. */ + public static final int IPV6_SRC = 26; + /** IPv6 destination address. */ + public static final int IPV6_DST = 27; + /** IPv6 Flow Label */ + public static final int IPV6_FLABEL = 28; + /** ICMPv6 type. */ + public static final int ICMPV6_TYPE = 29; + /** ICMPv6 code. */ + public static final int ICMPV6_CODE = 30; + /** Target address for ND. */ + public static final int IPV6_ND_TARGET = 31; + /** Source link-layer for ND. */ + public static final int IPV6_ND_SLL = 32; + /** Target link-layer for ND. */ + public static final int IPV6_ND_TLL = 33; + /** MPLS label. */ + public static final int MPLS_LABEL = 34; + /** MPLS TC. */ + public static final int MPLS_TC = 35; + /** MPLS BoS bit. */ + public static final int MPLS_BOS = 36; + /** PBB I-SID. */ + public static final int PBB_ISID = 37; + /** Logical Port Metadata. */ + public static final int TUNNEL_ID = 38; + /** IPv6 Extension Header pseudo-field */ + public static final int IPV6_EXTHDR = 39; +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java index 6f119eb3..c7d21f6a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java @@ -11,8 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.BarrierInput; @@ -24,8 +28,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class BarrierInputMessageFactoryTest { - private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = BarrierInputMessageFactory.MESSAGE_TYPE; - + private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = 20; + private SerializerRegistry registry; + private OFSerializer barrierFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + barrierFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, BarrierInput.class)); + } + /** * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO * @throws Exception @@ -37,8 +54,7 @@ public class BarrierInputMessageFactoryTest { BarrierInput bi = bib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance(); - bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi); + barrierFactory.serialize(bi, out); BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java index bb2ee8e3..158557b7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.EchoInput; @@ -23,8 +28,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoInputMessageFactoryTest { - private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = EchoInputMessageFactory.MESSAGE_TYPE; - + private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2; + private SerializerRegistry registry; + private OFSerializer echoFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + echoFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, EchoInput.class)); + } + /** * Testing of {@link EchoInputMessageFactory} for correct translation from POJO * @throws Exception @@ -36,8 +54,7 @@ public class EchoInputMessageFactoryTest { EchoInput ei = eib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, ei); + echoFactory.serialize(ei, out); BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); } @@ -53,8 +70,7 @@ public class EchoInputMessageFactoryTest { EchoInput ei = eib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, ei); + echoFactory.serialize(ei, out); BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java index a5a504e1..8107fb68 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.EchoReplyInput; @@ -23,8 +28,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoReplyInputMessageFactoryTest { - private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = EchoReplyInputMessageFactory.MESSAGE_TYPE; - + private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = 3; + private SerializerRegistry registry; + private OFSerializer echoFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + echoFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, EchoReplyInput.class)); + } + /** * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO * @throws Exception @@ -36,8 +54,7 @@ public class EchoReplyInputMessageFactoryTest { EchoReplyInput eri = erib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, eri); + echoFactory.serialize(eri, out); BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); } @@ -53,8 +70,7 @@ public class EchoReplyInputMessageFactoryTest { EchoReplyInput eri = erib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, eri); + echoFactory.serialize(eri, out); BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java deleted file mode 100644 index ebea1948..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java +++ /dev/null @@ -1,58 +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.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -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.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class ExperimenterInputMessageFactoryTest { - - private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setExpType(0x0001020304L); - builder.setData(new byte[] {0x01, 0x02, 0x03}); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message)); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); - Assert.assertArrayEquals("Wrong data", message.getData(), readData(out)); - } - - private static byte[] readData(ByteBuf input) { - byte[] data = new byte[input.readableBytes()]; - input.readBytes(data); - return data; - } -} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java index 7dbd6bf2..a2b23054 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java @@ -16,18 +16,31 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.ActionsInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder; 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.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; 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.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.Output; +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.action.rev130731.actions.grouping.ActionBuilder; 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.GotoTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; @@ -39,7 +52,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; 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.match.grouping.MatchBuilder; @@ -54,7 +66,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class FlowModInputMessageFactoryTest { private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; - + private SerializerRegistry registry; + private OFSerializer flowModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + flowModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, FlowModInput.class)); + } + /** * @throws Exception * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO @@ -87,7 +112,7 @@ public class FlowModInputMessageFactoryTest { portNumberBuilder.setPortNumber(new PortNumber(42L)); entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entriesBuilder.build()); - entriesBuilder.setOxmClass(Nxm0Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(IpEcn.class); entriesBuilder.setHasMask(false); EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); @@ -111,16 +136,27 @@ public class FlowModInputMessageFactoryTest { instructions.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(ApplyActions.class); - insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); + List actions = new ArrayList<>(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Output.class); + PortActionBuilder port = new PortActionBuilder(); + port.setPort(new PortNumber(42L)); + actionBuilder.addAugmentation(PortAction.class, port.build()); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(52); + actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); + actions.add(actionBuilder.build()); + ActionsInstructionBuilder actionInstructionBuilder = new ActionsInstructionBuilder(); + actionInstructionBuilder.setAction(actions); + insBuilder.addAugmentation(ActionsInstruction.class, actionInstructionBuilder.build()); instructions.add(insBuilder.build()); builder.setInstruction(instructions); FlowModInput message = builder.build(); - + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + flowModFactory.serialize(message, out); + + BufferHelper.checkHeaderV13(out,(byte) 14, 128); cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(cookie); Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie)); @@ -145,7 +181,7 @@ public class FlowModInputMessageFactoryTest { Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt()); - Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort()); fieldAndMask = out.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); @@ -166,8 +202,13 @@ public class FlowModInputMessageFactoryTest { Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead); Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort()); - Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort()); out.skipBytes(4); + Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong port", 42, out.readUnsignedInt()); + Assert.assertEquals("Wrong max-length", 52, out.readUnsignedShort()); + out.skipBytes(6); Assert.assertTrue("Unread data", out.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java index 0c3c5a62..31d5247f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.GetConfigInput; @@ -23,8 +28,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetConfigInputMessageFactoryTest { - private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = GetConfigInputMessageFactory.MESSAGE_TYPE; - + private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7; + private SerializerRegistry registry; + private OFSerializer getConfigFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + getConfigFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetConfigInput.class)); + } + /** * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO * @throws Exception @@ -36,9 +54,8 @@ public class GetConfigInputMessageFactoryTest { GetConfigInput gci = gcib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); - gcimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gci); - + getConfigFactory.serialize(gci, out); + BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); } @@ -53,8 +70,7 @@ public class GetConfigInputMessageFactoryTest { GetConfigInput gci = gcib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); - gcimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gci); + getConfigFactory.serialize(gci, out); BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java index a99dab67..644dc352 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.GetFeaturesInput; @@ -23,8 +28,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetFeaturesInputMessageFactoryTest { - private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = GetFeaturesInputMessageFactory.MESSAGE_TYPE; - + private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = 5; + private SerializerRegistry registry; + private OFSerializer featuresFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + featuresFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetFeaturesInput.class)); + } + /** * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO * @throws Exception @@ -36,9 +54,8 @@ public class GetFeaturesInputMessageFactoryTest { GetFeaturesInput gfi = gfib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); - gfimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gfi); - + featuresFactory.serialize(gfi, out); + BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); } @@ -53,9 +70,8 @@ public class GetFeaturesInputMessageFactoryTest { GetFeaturesInput gfi = gfib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); - gfimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gfi); - + featuresFactory.serialize(gfi, out); + BufferHelper.checkHeaderV10(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java index 77ab3af6..924702e1 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java @@ -12,8 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.PortNumber; @@ -27,7 +31,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class GetQueueConfigInputMessageFactoryTest { private static final byte GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE = 22; private static final byte PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE = 4; - + private SerializerRegistry registry; + private OFSerializer getQueueFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + getQueueFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetQueueConfigInput.class)); + } + /** * Testing of {@link GetQueueConfigInputMessageFactory} for correct translation from POJO * @throws Exception @@ -40,9 +57,8 @@ public class GetQueueConfigInputMessageFactoryTest { GetQueueConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetQueueConfigInputMessageFactory factory = GetQueueConfigInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - + getQueueFactory.serialize(message, out); + BufferHelper.checkHeaderV13(out, GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE, 16); Assert.assertEquals("Wrong port", 0x00010203, out.readUnsignedInt()); out.skipBytes(PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java index 0f4fb9f4..594246e1 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java @@ -11,8 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.GetAsyncInput; @@ -25,7 +29,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class GetaAsyncRequestMessageFactoryTest { private static final byte MESSAGE_TYPE = 26; private static final int MESSAGE_LENGTH = 8; - + private SerializerRegistry registry; + private OFSerializer getAsyncFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + getAsyncFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetAsyncInput.class)); + } + /** * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO * @throws Exception @@ -37,8 +54,7 @@ public class GetaAsyncRequestMessageFactoryTest { GetAsyncInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetAsyncRequestMessageFactory factory = GetAsyncRequestMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + getAsyncFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java index eceb0d66..ba129d3f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.GroupId; @@ -33,8 +37,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * */ public class GroupModInputMessageFactoryTest { + private static final byte MESSAGE_TYPE = 15; private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; - + private SerializerRegistry registry; + private OFSerializer groupModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + groupModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GroupModInput.class)); + } + /** * @throws Exception * Testing of {@link GroupModInputMessageFactory} for correct translation from POJO @@ -51,10 +69,9 @@ public class GroupModInputMessageFactoryTest { GroupModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GroupModInputMessageFactory factory = GroupModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + groupModFactory.serialize(message, out); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 32); Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte()); out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java index 888476d4..3a299a63 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -35,7 +39,20 @@ import org.slf4j.LoggerFactory; public class HelloInputMessageFactoryTest { private static final Logger LOGGER = LoggerFactory.getLogger(HelloInputMessageFactoryTest.class); - + private SerializerRegistry registry; + private OFSerializer helloFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + helloFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, HelloInput.class)); + } + /** * Testing of {@link HelloInputMessageFactory} for correct translation from POJO * @throws Exception @@ -47,10 +64,9 @@ public class HelloInputMessageFactoryTest { HelloInput hi = hib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance(); - himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi); + helloFactory.serialize(hi, out); - BufferHelper.checkHeaderV13(out, himf.getMessageType(), himf.computeLength(hi)); + BufferHelper.checkHeaderV13(out,(byte) 0, EncodeConstants.OFHEADER_SIZE); } /** @@ -67,11 +83,10 @@ public class HelloInputMessageFactoryTest { HelloInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + helloFactory.serialize(message, out); LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 0, 16); Elements element = readElement(out).get(0); Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); Elements comparation = createComparationElement(lengthOfBitmap).get(0); @@ -92,11 +107,10 @@ public class HelloInputMessageFactoryTest { HelloInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + helloFactory.serialize(message, out); LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 0, 24); Elements element = readElement(out).get(0); Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); Elements comparation = createComparationElement(lengthOfBitmap).get(0); @@ -143,7 +157,7 @@ public class HelloInputMessageFactoryTest { int elementLength = input.readUnsignedShort(); if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { elementsBuilder.setType(HelloElementType.forValue(type)); - int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; + int[] versionBitmap = new int[(elementLength - 4) / 4]; for (int i = 0; i < versionBitmap.length; i++) { versionBitmap[i] = (int) input.readUnsignedInt(); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java index 31893adb..f7f72518 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java @@ -16,8 +16,12 @@ import java.util.List; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.MeterBandType; @@ -41,6 +45,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class MeterModInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer meterModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + meterModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MeterModInput.class)); + } + /** * @throws Exception * Testing of {@link MeterModInputMessageFactory} for correct translation from POJO @@ -56,10 +74,9 @@ public class MeterModInputMessageFactoryTest { MeterModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MeterModInputMessageFactory factory = MeterModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + meterModFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), 64); + BufferHelper.checkHeaderV13(out, (byte) 29, 64); Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort())); Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java index fe50e878..b5459c40 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java @@ -14,8 +14,12 @@ import io.netty.buffer.UnpooledByteBufAllocator; import java.math.BigInteger; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.GroupId; @@ -28,8 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase; @@ -44,7 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.desc._case.MultipartRequestDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder; @@ -59,13 +60,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class MultipartRequestInputFactoryTest { /** padding in MultipartRequest message */ public static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; + private SerializerRegistry registry; + private OFSerializer multipartFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + multipartFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestInput.class)); + } /** * @throws Exception * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test - public void testMultipartRequestInputFactory() throws Exception { + public void testMultipartRequestFlowInputFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(1)); @@ -74,10 +88,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 48); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -133,10 +146,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 48); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -194,14 +206,13 @@ public class MultipartRequestInputFactoryTest { BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(3)); builder.setFlags(new MultipartRequestFlags(true)); - //multipart request for table does not have body + //multipart request for registry does not have body MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 16); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -221,10 +232,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -263,10 +273,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -305,10 +314,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -347,10 +355,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -389,10 +396,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 24); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); @@ -417,48 +423,6 @@ public class MultipartRequestInputFactoryTest { return caseBuilder.build(); } - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestExperimenterMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(0xffff)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestExperimenter()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong experimenterBody", message.getMultipartRequestBody(), decodeRequestExperimenter(out)); - } - - private static MultipartRequestExperimenterCase createRequestExperimenter() { - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); - builder.setExperimenter(1133L); - builder.setExpType(1135L); - caseBuilder.setMultipartRequestExperimenter(builder.build()); - return caseBuilder.build(); - } - - private static MultipartRequestExperimenterCase decodeRequestExperimenter(ByteBuf output) { - MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); - MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); - builder.setExperimenter(output.readUnsignedInt()); - builder.setExpType(output.readUnsignedInt()); - caseBuilder.setMultipartRequestExperimenter(builder.build()); - return caseBuilder.build(); - } - /** * @throws Exception * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO @@ -473,10 +437,9 @@ public class MultipartRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 16); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java index 7e50fa8b..f1a70c8e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.BarrierInput; @@ -23,6 +28,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10BarrierInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer barrierFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + barrierFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class)); + } + /** * Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO * @throws Exception @@ -34,8 +53,7 @@ public class OF10BarrierInputMessageFactoryTest { BarrierInput bi = bib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance(); - bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi); + barrierFactory.serialize(bi, out); BufferHelper.checkHeaderV10(out, (byte) 18, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java index 12b2a945..7a3effc8 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java @@ -16,7 +16,12 @@ 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -44,6 +49,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10FlowModInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer flowModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + flowModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, FlowModInput.class)); + } + /** * @throws Exception * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO @@ -95,10 +114,9 @@ public class OF10FlowModInputMessageFactoryTest { FlowModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + flowModFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV10(out, (byte) 14, 88); Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt()); Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort()); byte[] dlSrc = new byte[6]; diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java index 7575be11..4de13d31 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java @@ -11,7 +11,12 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.HelloInput; @@ -23,6 +28,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10HelloInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer helloFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + helloFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, HelloInput.class)); + } + /** * Testing of {@link OF10HelloInputMessageFactory} for correct translation from POJO * @throws Exception @@ -34,8 +53,7 @@ public class OF10HelloInputMessageFactoryTest { HelloInput hi = hib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10HelloInputMessageFactory himf = OF10HelloInputMessageFactory.getInstance(); - himf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, hi); + helloFactory.serialize(hi, out); BufferHelper.checkHeaderV10(out, (byte) 0, 8); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java index 9176b31e..31388928 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -38,6 +42,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10PacketOutInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer packetOutFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + packetOutFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PacketOutInput.class)); + } + /** * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO * @throws Exception @@ -67,8 +85,7 @@ public class OF10PacketOutInputMessageFactoryTest { PacketOutInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + packetOutFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, (byte) 13, 48); Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java index c49b7b26..9a71288b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java @@ -12,7 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -29,6 +34,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10PortModInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer portModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + portModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PortModInput.class)); + } + /** * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO * @throws Exception @@ -46,8 +65,7 @@ public class OF10PortModInputMessageFactoryTest { PortModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + portModFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, (byte) 15, 32); Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java index 5b78232e..29f9c7b0 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java @@ -12,7 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.PortNumber; @@ -25,6 +30,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10QueueGetConfigInputMessageFactoryTest { + private SerializerRegistry registry; + private OFSerializer queueFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + queueFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, GetQueueConfigInput.class)); + } + /** * Testing of {@link OF10QueueGetConfigInputMessageFactory} for correct translation from POJO * @throws Exception @@ -37,8 +56,7 @@ public class OF10QueueGetConfigInputMessageFactoryTest { GetQueueConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10QueueGetConfigInputMessageFactory factory = OF10QueueGetConfigInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + queueFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, (byte) 20, 12); Assert.assertEquals("Wrong port", 6653L, out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java index c8141a7b..845d7c2a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java @@ -11,7 +11,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -40,6 +45,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class OF10StatsRequestInputFactoryTest { + private SerializerRegistry registry; + private OFSerializer multipartFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + multipartFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartRequestInput.class)); + } + /** * Testing OF10StatsRequestInputFactory (Desc) for correct serialization * @throws Exception @@ -57,10 +76,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12); + BufferHelper.checkHeaderV10(out, (byte) 16, 12); Assert.assertEquals("Wrong type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); @@ -103,10 +121,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56); + BufferHelper.checkHeaderV10(out, (byte) 16, 56); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong wildcards", 3414271, out.readUnsignedInt()); @@ -128,7 +145,7 @@ public class OF10StatsRequestInputFactoryTest { Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt()); Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort()); Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort()); - Assert.assertEquals("Wrong table-id", 1, out.readUnsignedByte()); + Assert.assertEquals("Wrong registry-id", 1, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong out-port", 42, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); @@ -171,10 +188,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56); + BufferHelper.checkHeaderV10(out, (byte) 16, 56); Assert.assertEquals("Wrong type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt()); @@ -196,7 +212,7 @@ public class OF10StatsRequestInputFactoryTest { Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt()); Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort()); Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort()); - Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte()); + Assert.assertEquals("Wrong registry-id", 42, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); @@ -219,10 +235,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12); + BufferHelper.checkHeaderV10(out, (byte) 16, 12); Assert.assertEquals("Wrong type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); @@ -246,10 +261,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20); + BufferHelper.checkHeaderV10(out, (byte) 16, 20); Assert.assertEquals("Wrong type", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort()); @@ -276,10 +290,9 @@ public class OF10StatsRequestInputFactoryTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20); + BufferHelper.checkHeaderV10(out, (byte) 16, 20); Assert.assertEquals("Wrong type", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java deleted file mode 100644 index 540801a9..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java +++ /dev/null @@ -1,50 +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.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Test; -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.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10VendorInputMessageFactoryTest { - - /** - * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04}); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message)); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - byte[] data = new byte[4]; - out.readBytes(data); - Assert.assertArrayEquals("Wrong data", message.getData(), data); - } - -} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java index 292bca15..89f4e31a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -39,7 +43,20 @@ public class PacketOutInputMessageFactoryTest { private static final byte MESSAGE_TYPE = 13; private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; private static final int PADDING_IN_ACTION_HEADER = 4; - + private SerializerRegistry registry; + private OFSerializer packetOutFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + packetOutFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, PacketOutInput.class)); + } + /** * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO * @throws Exception @@ -65,8 +82,7 @@ public class PacketOutInputMessageFactoryTest { PacketOutInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + packetOutFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56); Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java index f55be957..332a5c4f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java @@ -12,8 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -34,7 +38,20 @@ public class PortModInputMessageFactoryTest { private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; private static final int MESSAGE_LENGTH = 40; - + private SerializerRegistry registry; + private OFSerializer portModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + portModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, PortModInput.class)); + } + /** * Testing of {@link PortModInputMessageFactory} for correct translation from POJO * @throws Exception @@ -54,8 +71,7 @@ public class PortModInputMessageFactoryTest { PortModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - PortModInputMessageFactory factory = PortModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + portModFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java index 4de2c4a8..a07715c6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java @@ -15,8 +15,12 @@ import java.math.BigInteger; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.ControllerRole; @@ -31,7 +35,20 @@ public class RoleRequestInputMessageFactoryTest { private static final byte MESSAGE_TYPE = 24; private static final int MESSAGE_LENGTH = 24; private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; - + private SerializerRegistry registry; + private OFSerializer roleFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + roleFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, RoleRequestInput.class)); + } + /** * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO * @throws Exception @@ -46,8 +63,7 @@ public class RoleRequestInputMessageFactoryTest { RoleRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + roleFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java index efaf1ae9..9a50f326 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; @@ -41,6 +45,20 @@ import org.slf4j.LoggerFactory; public class SetAsyncInputMessageFactoryTest { private static final Logger LOGGER = LoggerFactory .getLogger(SetAsyncInputMessageFactoryTest.class); + private SerializerRegistry registry; + private OFSerializer setAsyncFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + setAsyncFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetAsyncInput.class)); + } + /** * @throws Exception * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO @@ -55,10 +73,9 @@ public class SetAsyncInputMessageFactoryTest { SetAsyncInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + setAsyncFactory.serialize(message, out); LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out)); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out,(byte) 28, 32); Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt()); Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java index 2d5de55b..d6c2725b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java @@ -12,7 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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.SwitchConfigFlag; @@ -26,7 +31,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class SetConfigMessageFactoryTest { private static final byte MESSAGE_TYPE = 9; private static final int MESSAGE_LENGTH = 12; - + private SerializerRegistry registry; + private OFSerializer setConfigFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + setConfigFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetConfigInput.class)); + } + /** * Testing of {@link SetConfigMessageFactory} for correct translation from POJO * @throws Exception @@ -41,8 +59,7 @@ public class SetConfigMessageFactoryTest { SetConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + setConfigFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort()); @@ -63,8 +80,7 @@ public class SetConfigMessageFactoryTest { SetConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + setConfigFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java index 1daa581a..8fde1ce8 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java @@ -12,8 +12,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; 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.TableConfig; @@ -28,7 +32,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class TableModInputMessageFactoryTest { private static final byte MESSAGE_TYPE = 17; private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; - + private SerializerRegistry registry; + private OFSerializer tableModFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + tableModFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableModInput.class)); + } + /** * Testing of {@link TableModInputMessageFactory} for correct translation from POJO * @throws Exception @@ -42,8 +59,7 @@ public class TableModInputMessageFactoryTest { TableModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + tableModFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16); Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java index eb64df70..8ca6f174 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java @@ -15,8 +15,12 @@ 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.impl.deserialization.factories.HelloMessageFactoryTest; +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.impl.serialization.SerializerRegistryImpl; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; @@ -46,8 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPh import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; 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.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.oxm.fields.grouping.MatchEntries; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; @@ -67,6 +69,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class TableFeaturesTest { private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = MultipartRequestInputFactoryTest.PADDING_IN_MULTIPART_REQUEST_MESSAGE; + private SerializerRegistry registry; + private OFSerializer multipartFactory; + + /** + * Initializes serializer registry and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + multipartFactory = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestInput.class)); + } /** * @throws Exception @@ -163,7 +178,7 @@ public class TableFeaturesTest { entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm0Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(InPort.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); @@ -180,7 +195,7 @@ public class TableFeaturesTest { entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm1Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(IpEcn.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); @@ -195,15 +210,14 @@ public class TableFeaturesTest { MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + multipartFactory.serialize(message, out); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + BufferHelper.checkHeaderV13(out, (byte) 18, 232); Assert.assertEquals("Wrong type", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort()); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong length", 120, out.readUnsignedShort()); - Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte()); + Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte()); out.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(out, 32)); @@ -219,12 +233,12 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong max-entries", 65, out.readUnsignedInt()); Assert.assertEquals("Wrong property type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 6, out.readUnsignedShort()); - Assert.assertEquals("Wrong next-table-id", 1, out.readUnsignedByte()); - Assert.assertEquals("Wrong next-table-id", 2, out.readUnsignedByte()); + Assert.assertEquals("Wrong next-registry-id", 1, out.readUnsignedByte()); + Assert.assertEquals("Wrong next-registry-id", 2, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong property type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 5, out.readUnsignedShort()); - Assert.assertEquals("Wrong next-table-id", 3, out.readUnsignedByte()); + Assert.assertEquals("Wrong next-registry-id", 3, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong property type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort()); @@ -246,7 +260,7 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong length", 96, out.readUnsignedShort()); - Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte()); + Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte()); out.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(out, 32)); @@ -265,7 +279,7 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte()); - Assert.assertEquals("Wrong match class", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte()); out.skipBytes(4); @@ -274,7 +288,7 @@ public class TableFeaturesTest { Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 20, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte()); - Assert.assertEquals("Wrong match class", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte()); out.skipBytes(4); 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 787c1d7e..92777a8e 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 @@ -16,8 +16,6 @@ import java.lang.reflect.Method; import org.junit.Assert; import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -151,19 +149,5 @@ public abstract class BufferHelper { private static E bufferToMessage(OFDeserializer decoder, short version, ByteBuf bb) { return decoder.bufferToMessage(bb, version); } - - /** - * Use OF-protocol version 1.3 - * @param encoder serialize factory - * @param out buffer the result will be written into - * @param pojo input message - */ - public static void encodeV13(OFSerializer encoder, ByteBuf out, E pojo) { - messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED); - } - - private static void messageToBuffer( - OFSerializer encoder, ByteBuf out, E pojo, Short version) { - encoder.messageToBuffer(version, out, pojo); - } + } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java index 0c1706db..a5c90990 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java @@ -14,13 +14,16 @@ 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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; @@ -36,7 +39,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; @@ -58,6 +60,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 */ public class OF10ActionsSerializerTest { + private SerializerRegistry registry; + private OFSerializer actionSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + actionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class)); + } + /** * Testing correct serialization of actions (OF v1.0) */ @@ -139,15 +155,9 @@ public class OF10ActionsSerializerTest { queueBuilder.setQueueId(400L); actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build()); actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(500L); - actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build()); - actions.add(actionBuilder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10ActionsSerializer.encodeActionsV10(out, actions); + CodingUtils.serializeList(actions, actionSerializer, out); Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); @@ -205,9 +215,6 @@ public class OF10ActionsSerializerTest { Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort()); out.skipBytes(6); Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt()); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong vendor-id", 500, out.readUnsignedInt()); Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java index 19d745be..a225db30 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java @@ -8,11 +8,16 @@ package org.opendaylight.openflowjava.protocol.impl.util; -import junit.framework.Assert; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; +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.impl.serialization.SerializerRegistryImpl; 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,6 +30,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc */ public class OF10MatchSerializerTest { + private SerializerRegistry registry; + private OFSerializer matchSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + matchSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class)); + } + /** * Testing correct serialization of ofp_match */ @@ -49,7 +68,7 @@ public class OF10MatchSerializerTest { builder.setTpSrc(2048); builder.setTpDst(4096); MatchV10 match = builder.build(); - OF10MatchSerializer.encodeMatchV10(out, match); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt()); Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); @@ -96,7 +115,7 @@ public class OF10MatchSerializerTest { builder.setTpSrc(2048); builder.setTpDst(4096); MatchV10 match = builder.build(); - OF10MatchSerializer.encodeMatchV10(out, match); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt()); Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java similarity index 90% rename from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java rename to openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java index 14f50d0b..64caf95d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java @@ -14,11 +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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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; @@ -39,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; -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.Group; 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.PopMpls; @@ -65,7 +67,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. * @author michal.polkorab * */ -public class ActionsSerializerTest { +public class OF13ActionsSerializerTest { + + private SerializerRegistry registry; + private OFSerializer actionSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + actionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class)); + } /** * Testing correct serialization of actions @@ -163,16 +179,9 @@ public class ActionsSerializerTest { actionBuilder = new ActionBuilder(); actionBuilder.setType(PopPbb.class); actions.add(actionBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); - experimenter.setExperimenter(4L); - experimenter.setData(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}); - actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); - actions.add(actionBuilder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - ActionsSerializer.encodeActions(actions, out); + CodingUtils.serializeList(actions, actionSerializer, out); Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); @@ -234,12 +243,6 @@ public class ActionsSerializerTest { Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); - Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt()); - byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - out.readBytes(data); - Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, data); Assert.assertTrue("Unread data", out.readableBytes() == 0); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializerTest.java similarity index 90% rename from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializerTest.java rename to openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializerTest.java index 192d1950..1af814ac 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializerTest.java @@ -14,7 +14,12 @@ 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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.EthertypeAction; @@ -52,7 +57,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 * @author michal.polkorab * */ -public class InstructionsSerializerTest { +public class OF13InstructionsSerializerTest { + + private SerializerRegistry registry; + private OFSerializer instructionSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + instructionSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Instruction.class)); + } /** * Testing instructions translation @@ -128,7 +147,7 @@ public class InstructionsSerializerTest { instructions.add(builder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - InstructionsSerializer.encodeInstructions(instructions, out); + CodingUtils.serializeList(instructions, instructionSerializer, out); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest.java similarity index 91% rename from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java rename to openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest.java index 2a74162a..746bb625 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest.java @@ -15,7 +15,12 @@ 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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; @@ -32,8 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; -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.match.grouping.Match; @@ -47,10 +50,23 @@ import org.slf4j.LoggerFactory; * @author michal.polkorab * */ -public class MatchSerializerTest { - +public class OF13MatchSerializerTest { + private static final Logger LOG = LoggerFactory - .getLogger(MatchSerializerTest.class); + .getLogger(OF13MatchSerializerTest.class); + private SerializerRegistry registry; + private OFSerializer matchSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + matchSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class)); + } /** * Test for correct serialization of Ipv4Address match entry @@ -72,7 +88,7 @@ public class MatchSerializerTest { Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); @@ -113,7 +129,7 @@ public class MatchSerializerTest { entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm1Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); @@ -122,7 +138,7 @@ public class MatchSerializerTest { entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm1Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); @@ -131,7 +147,7 @@ public class MatchSerializerTest { entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm0Class.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); @@ -150,7 +166,7 @@ public class MatchSerializerTest { builder.setMatchEntries(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); @@ -176,7 +192,7 @@ public class MatchSerializerTest { Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); @@ -187,7 +203,7 @@ public class MatchSerializerTest { Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); @@ -198,7 +214,7 @@ public class MatchSerializerTest { Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0000, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); @@ -230,7 +246,7 @@ public class MatchSerializerTest { Match match = buildIpv6FLabelMatch(0x0f9e8dL, false, null); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); @@ -252,7 +268,7 @@ public class MatchSerializerTest { Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0, 0x0c, 0x7b, 0x6a}); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); @@ -276,7 +292,7 @@ public class MatchSerializerTest { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); try { - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.fail("incorrect length of mask ignored"); } catch (IllegalArgumentException e) { //expected diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest2.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest2.java similarity index 95% rename from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest2.java rename to openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest2.java index 4b459d5c..35ec8e5b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest2.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest2.java @@ -14,7 +14,12 @@ 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.MessageTypeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl; 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; @@ -79,7 +84,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; @@ -102,8 +106,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; @@ -125,7 +127,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. * @author michal.polkorab * */ -public class MatchSerializerTest2 { +public class OF13MatchSerializerTest2 { + + private SerializerRegistry registry; + private OFSerializer matchSerializer; + + /** + * Initializes serializer table and stores correct factory in field + */ + @Before + public void startUp() { + registry = new SerializerRegistryImpl(); + registry.init(); + matchSerializer = registry.getSerializer( + new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class)); + } /** * Testing serialization of match @@ -137,7 +153,7 @@ public class MatchSerializerTest2 { Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match length", 4, out.readUnsignedShort()); @@ -153,7 +169,7 @@ public class MatchSerializerTest2 { builder.setType(OxmMatchType.class); List entries = new ArrayList<>(); MatchEntriesBuilder entryBuilder = new MatchEntriesBuilder(); - entryBuilder.setOxmClass(Nxm0Class.class); + entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPort.class); entryBuilder.setHasMask(false); PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); @@ -161,7 +177,7 @@ public class MatchSerializerTest2 { entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); - entryBuilder.setOxmClass(Nxm1Class.class); + entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPhyPort.class); entryBuilder.setHasMask(false); portNumberBuilder = new PortNumberMatchEntryBuilder(); @@ -180,7 +196,7 @@ public class MatchSerializerTest2 { entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); - entryBuilder.setOxmClass(ExperimenterClass.class); + entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthDst.class); entryBuilder.setHasMask(true); MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder(); @@ -224,7 +240,7 @@ public class MatchSerializerTest2 { entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanPcp.class); - entryBuilder.setHasMask(true); + entryBuilder.setHasMask(false); VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder(); pcpBuilder.setVlanPcp((short) 14); entryBuilder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build()); @@ -454,7 +470,7 @@ public class MatchSerializerTest2 { entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); - entryBuilder.setOxmClass(ExperimenterClass.class); + entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdSll.class); entryBuilder.setHasMask(false); macBuilder = new MacAddressMatchEntryBuilder(); @@ -536,15 +552,15 @@ public class MatchSerializerTest2 { Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); + matchSerializer.serialize(match, out); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match length", 428, out.readUnsignedShort()); - Assert.assertEquals("Wrong match entry class", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt()); - Assert.assertEquals("Wrong match entry class", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt()); @@ -553,7 +569,7 @@ public class MatchSerializerTest2 { Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); - Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort()); + Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); byte[] array = new byte[6]; @@ -727,7 +743,7 @@ public class MatchSerializerTest2 { array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[]{0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, array); - Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort()); + Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; 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 56766a7b..8b4b958a 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 @@ -11,6 +11,9 @@ package org.opendaylight.openflowjava.protocol.spi.connection; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; 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.yangtools.yang.binding.DataObject; import com.google.common.util.concurrent.ListenableFuture; @@ -43,5 +46,12 @@ public interface SwitchConnectionProvider extends AutoCloseable { * @param switchConHandler instance being informed when new switch connects */ void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler); - + + /** + * Registers custom serializer + * @param key used for serializer lookup + * @param serializer serializer implementation + */ + public void registerCustomSerializer(MessageTypeKey key, + OFSerializer serializer); } diff --git a/pom.xml b/pom.xml index 63b57378..623e85a7 100644 --- a/pom.xml +++ b/pom.xml @@ -112,6 +112,11 @@ slf4j-api ${slf4j.version} + + io.netty + netty-buffer + ${netty.version} + io.netty netty-handler -- 2.36.6