Extensibility support (serialization part) 77/5777/6
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 3 Apr 2014 12:59:20 +0000 (14:59 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 17 Apr 2014 11:54:02 +0000 (13:54 +0200)
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
Change-Id: I51778a009f9a20d6ba1f29b74ca1e3fc1350d8bd

145 files changed:
openflow-protocol-api/pom.xml
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/HeaderSerializer.java [new file with mode: 0644]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageTypeKey.java [moved from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java with 89% similarity]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFGeneralSerializer.java [new file with mode: 0644]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/OFSerializer.java [new file with mode: 0644]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/RegistryInjector.java [new file with mode: 0644]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/EnhancedMessageTypeKey.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MatchEntriesInitializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv4AddressSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMacAddressSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMatchEntrySerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmMetadataSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortNumberSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmPortSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPhyPortSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmInPortSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpEcnSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6DstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6FlabelSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTargetSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6SrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CodingUtils.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/CommonMessageRegistryHelper.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchIdsSerializer.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java [deleted file]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializer.java [moved from openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java with 52% similarity]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchEntriesRegistryHelper.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OxmMatchConstants.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java [deleted file]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java [deleted file]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/multipart/TableFeaturesTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializerTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13ActionsSerializerTest.java [moved from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializerTest.java with 90% similarity]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13InstructionsSerializerTest.java [moved from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializerTest.java with 90% similarity]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest.java [moved from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java with 91% similarity]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF13MatchSerializerTest2.java [moved from openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest2.java with 95% similarity]
openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java
pom.xml

index 099ca0a84469c12e1f90f86e24b2aa8033e63e39..9670e71e05feb3d63a88f92b67fe985efc85f169 100644 (file)
             <groupId>org.opendaylight.controller.model</groupId>
             <artifactId>model-flow-service</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-buffer</artifactId>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
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 (file)
index 0000000..3392f81
--- /dev/null
@@ -0,0 +1,27 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+/**\r
+ * Does only-header serialization (such as oxm_ids, action_ids, instruction_ids)\r
+ * @author michal.polkorab\r
+ * @param <SERIALIZER_TYPE>\r
+ */\r
+public interface HeaderSerializer<SERIALIZER_TYPE extends DataObject> extends OFGeneralSerializer {\r
+\r
+    /**\r
+     * Serializes object headers (e.g. for Multipart message - Table Features)\r
+     * @param input object whose headers should be serialized\r
+     * @param outBuffer output buffer\r
+     */\r
+    public void serializeHeader(SERIALIZER_TYPE input, ByteBuf outBuffer);\r
+}\r
@@ -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 <E> message type (class)
  */
-public class MessageTypeKey<E extends DataObject> {
+public class MessageTypeKey<E> {
 
     private final Class<E> 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 (file)
index 0000000..0001c3e
--- /dev/null
@@ -0,0 +1,17 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+/**\r
+ * Unifying superinterface\r
+ * @author michal.polkorab\r
+ * */\r
+public interface OFGeneralSerializer {\r
+\r
+    // empty unifying superinterface\r
+}\r
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 (file)
index 0000000..2572a6f
--- /dev/null
@@ -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 <SERIALIZER_TYPE> message type
+ */
+public interface OFSerializer <SERIALIZER_TYPE extends DataObject> 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 (file)
index 0000000..9c1b537
--- /dev/null
@@ -0,0 +1,22 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+/**\r
+ * Serializer registry injector\r
+ * @author michal.polkorab\r
+ */\r
+public interface RegistryInjector {\r
+\r
+    /**\r
+     * Injects serializer registry\r
+     * @param serializerRegistry registry instance\r
+     */\r
+    public void injectSerializerRegistry(SerializerRegistry serializerRegistry);\r
+\r
+}\r
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 (file)
index 0000000..b5eec47
--- /dev/null
@@ -0,0 +1,37 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+\r
+/**\r
+ * Stores and handles serializers \r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public interface SerializerRegistry {\r
+\r
+    /**\r
+     * Serializer registry provisioning\r
+     */\r
+    public void init();\r
+\r
+    /**\r
+     * @param msgTypeKey lookup key\r
+     * @return serializer or NullPointerException if no serializer was found\r
+     */\r
+    public <KEY_TYPE, SERIALIZER_TYPE extends OFGeneralSerializer> SERIALIZER_TYPE \r
+        getSerializer(MessageTypeKey<KEY_TYPE> msgTypeKey);\r
+\r
+    /**\r
+     * Registers serializer under key\r
+     * @param msgTypeKey lookup key\r
+     * @param serializer serializer implementation\r
+     */\r
+    public <KEY_TYPE> void\r
+        registerSerializer(MessageTypeKey<KEY_TYPE> msgTypeKey, OFGeneralSerializer serializer);\r
+}\r
index 3e45b174623e7e2cbf3ec183fda1bc99f649db63..a8bceeeac2156806be8331f72bc8173579a07d3d 100644 (file)
@@ -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 <E extends DataObject> void registerCustomSerializer(MessageTypeKey<E> key,
+            OFSerializer<E> serializer) {
+        serializerRegistry.registerSerializer(key, serializer);
+    }
+
     @Override
     public void close() throws Exception {
         shutdown();
index 62972b7093cd376e7537830416bc6ea23ae749cd..38cb88937b91e354e2d797095763f535c9ae002c 100644 (file)
@@ -25,18 +25,19 @@ import org.slf4j.LoggerFactory;
 public class OFEncoder extends MessageToByteEncoder<OfHeader> {
 
     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<OfHeader> {
         }
     }
 
+    /**
+     * @param serializationFactory
+     */
+    public void setSerializationFactory(SerializationFactory serializationFactory) {
+        this.serializationFactory = serializationFactory;
+    }
+
 }
index 9b35e14ea4198342f09385a2622b5a9963882f82..5a35864b4184f429daa3585dbdb7208090ba5fd3 100644 (file)
@@ -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<SocketChann
     private SwitchConnectionHandler switchConnectionHandler;
     private long switchIdleTimeout;
     private boolean encryption;
-    
+    private SerializationFactory serializationFactory;
+
     /**
      * default ctor
      */
@@ -74,7 +76,9 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
             ch.pipeline().addLast(COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OFFrameDecoder());
             ch.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
             ch.pipeline().addLast(COMPONENT_NAMES.OF_DECODER.name(), new OFDecoder());
-            ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), new OFEncoder());
+            OFEncoder ofEncoder = new OFEncoder();
+            ofEncoder.setSerializationFactory(serializationFactory);
+            ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), ofEncoder);
             ch.pipeline().addLast(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionFacade));
             if (!encryption) {
                 connectionFacade.fireConnectionReadyNotification();
@@ -119,5 +123,11 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
     public void setEncryption(boolean tlsSupported) {
         encryption = tlsSupported;
     }
-    
+
+    /**
+     * @param serializationFactory
+     */
+    public void setSerializationFactory(SerializationFactory serializationFactory) {
+        this.serializationFactory = serializationFactory;
+    }
 }
index 941518d69c8de81600ec4582f1c5635a04971f2a..4e9b2bfd3e946c4b28bfda7dc9244fad903c7e11 100644 (file)
@@ -22,6 +22,7 @@ import java.net.InetSocketAddress;
 
 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowjava.protocol.impl.connection.ServerFacade;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -224,4 +225,10 @@ public class TcpHandler implements ServerFacade {
         channelInitializer.setEncryption(tlsSupported);
     }
     
+    /**
+     * @param sf serialization factory
+     */
+    public void setSerializationFactory(SerializationFactory sf) {
+        channelInitializer.setSerializationFactory(sf);
+    }
 }
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/EnhancedMessageTypeKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/EnhancedMessageTypeKey.java
new file mode 100644 (file)
index 0000000..f16987d
--- /dev/null
@@ -0,0 +1,62 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+\r
+/**\r
+ * More specific key for {@link SerializerRegistry}\r
+ * @author michal.polkorab\r
+ * @param <E> main type\r
+ * @param <F> specific type\r
+ */\r
+public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {\r
+\r
+    private final Class<F> msgType2;\r
+\r
+    /**\r
+     * @param msgVersion\r
+     * @param msgType\r
+     * @param msgType2\r
+     */\r
+    public EnhancedMessageTypeKey(short msgVersion, Class<E> msgType, Class<F> msgType2) {\r
+        super(msgVersion, msgType);\r
+        this.msgType2 = msgType2;\r
+    }\r
+\r
+    /**\r
+     * @return more specific type\r
+     */\r
+    public Class<F> getMsgType2() {\r
+        return msgType2;\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (!super.equals(obj))\r
+            return false;\r
+        if (getClass() != obj.getClass())\r
+            return false;\r
+        @SuppressWarnings("rawtypes")\r
+        EnhancedMessageTypeKey other = (EnhancedMessageTypeKey) obj;\r
+        if (msgType2 == null) {\r
+            if (other.msgType2 != null)\r
+                return false;\r
+        } else if (!msgType2.equals(other.msgType2))\r
+            return false;\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return super.toString() + " msgType2: " + msgType2.getName();\r
+    }\r
+}\r
index eeb9893e29cbe50f1700aa64d2599b47d89c85b9..00e37b06ee0a30b67d18e5d80593c1938f04f666 100644 (file)
@@ -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<HelloMessage> {
 
     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<HelloMessage> {
             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 (file)
index 3a1e0d0..0000000
+++ /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<MessageTypeKey<?>, 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 <E extends DataObject> OFSerializer<E> getEncoder(MessageTypeKey<E> msgTypeKey) {
-        return (OFSerializer<E>) 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 (file)
index 0000000..094b6f2
--- /dev/null
@@ -0,0 +1,151 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpOpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpShaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpSpaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpThaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpTpaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthTypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4CodeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4TypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6CodeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6TypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPhyPortSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPortSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpDscpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpEcnSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpProtoSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4DstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4SrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6DstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6ExtHdrSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6FlabelSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdSllSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTargetSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTllSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6SrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMetadataSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsBosSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsLabelSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsTcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmPbbIsidSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTunnelIdSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanPcpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanVidSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchEntriesRegistryHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
+\r
+/**\r
+ * Initializes serializer registry with match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public class MatchEntriesInitializer {\r
+\r
+    /**\r
+     * Registers match entry serializers into provided registry\r
+     * @param serializerRegistry registry to be initialized with match entry serializers\r
+     */\r
+    public static void registerMatchEntrySerializers(SerializerRegistry serializerRegistry) {\r
+        // register OF v1.3 OpenflowBasicClass match entry serializers\r
+        Class<OpenflowBasicClass> oxmClass = OpenflowBasicClass.class;\r
+        OF13MatchEntriesRegistryHelper<OpenflowBasicClass> registryHelper =\r
+                new OF13MatchEntriesRegistryHelper<>(EncodeConstants.OF13_VERSION_ID, oxmClass, serializerRegistry);\r
+        registryHelper.registerSerializer(InPort.class, new OxmInPortSerializer());\r
+        registryHelper.registerSerializer(InPhyPort.class, new OxmInPhyPortSerializer());\r
+        registryHelper.registerSerializer(Metadata.class, new OxmMetadataSerializer());\r
+        registryHelper.registerSerializer(EthDst.class, new OxmEthDstSerializer());\r
+        registryHelper.registerSerializer(EthSrc.class, new OxmEthSrcSerializer());\r
+        registryHelper.registerSerializer(EthType.class, new OxmEthTypeSerializer());\r
+        registryHelper.registerSerializer(VlanVid.class, new OxmVlanVidSerializer());\r
+        registryHelper.registerSerializer(VlanPcp.class, new OxmVlanPcpSerializer());\r
+        registryHelper.registerSerializer(IpDscp.class, new OxmIpDscpSerializer());\r
+        registryHelper.registerSerializer(IpEcn.class, new OxmIpEcnSerializer());\r
+        registryHelper.registerSerializer(IpProto.class, new OxmIpProtoSerializer());\r
+        registryHelper.registerSerializer(Ipv4Src.class, new OxmIpv4SrcSerializer());\r
+        registryHelper.registerSerializer(Ipv4Dst.class, new OxmIpv4DstSerializer());\r
+        registryHelper.registerSerializer(TcpSrc.class, new OxmTcpSrcSerializer());\r
+        registryHelper.registerSerializer(TcpDst.class, new OxmTcpDstSerializer());\r
+        registryHelper.registerSerializer(UdpSrc.class, new OxmUdpSrcSerializer());\r
+        registryHelper.registerSerializer(UdpDst.class, new OxmUdpDstSerializer());\r
+        registryHelper.registerSerializer(SctpSrc.class, new OxmSctpSrcSerializer());\r
+        registryHelper.registerSerializer(SctpDst.class, new OxmSctpDstSerializer());\r
+        registryHelper.registerSerializer(Icmpv4Type.class, new OxmIcmpv4TypeSerializer());\r
+        registryHelper.registerSerializer(Icmpv4Code.class, new OxmIcmpv4CodeSerializer());\r
+        registryHelper.registerSerializer(ArpOp.class, new OxmArpOpSerializer());\r
+        registryHelper.registerSerializer(ArpSpa.class, new OxmArpSpaSerializer());\r
+        registryHelper.registerSerializer(ArpTpa.class, new OxmArpTpaSerializer());\r
+        registryHelper.registerSerializer(ArpSha.class, new OxmArpShaSerializer());\r
+        registryHelper.registerSerializer(ArpTha.class, new OxmArpThaSerializer());\r
+        registryHelper.registerSerializer(Ipv6Src.class, new OxmIpv6SrcSerializer());\r
+        registryHelper.registerSerializer(Ipv6Dst.class, new OxmIpv6DstSerializer());\r
+        registryHelper.registerSerializer(Ipv6Flabel.class, new OxmIpv6FlabelSerializer());\r
+        registryHelper.registerSerializer(Icmpv6Type.class, new OxmIcmpv6TypeSerializer());\r
+        registryHelper.registerSerializer(Icmpv6Code.class, new OxmIcmpv6CodeSerializer());\r
+        registryHelper.registerSerializer(Ipv6NdTarget.class, new OxmIpv6NdTargetSerializer());\r
+        registryHelper.registerSerializer(Ipv6NdSll.class, new OxmIpv6NdSllSerializer());\r
+        registryHelper.registerSerializer(Ipv6NdTll.class, new OxmIpv6NdTllSerializer());\r
+        registryHelper.registerSerializer(MplsLabel.class, new OxmMplsLabelSerializer());\r
+        registryHelper.registerSerializer(MplsTc.class, new OxmMplsTcSerializer());\r
+        registryHelper.registerSerializer(MplsBos.class, new OxmMplsBosSerializer());\r
+        registryHelper.registerSerializer(PbbIsid.class, new OxmPbbIsidSerializer());\r
+        registryHelper.registerSerializer(TunnelId.class, new OxmTunnelIdSerializer());\r
+        registryHelper.registerSerializer(Ipv6Exthdr.class, new OxmIpv6ExtHdrSerializer());\r
+    }\r
+}\r
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 (file)
index 0000000..c8d035a
--- /dev/null
@@ -0,0 +1,105 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.CommonMessageRegistryHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class MessageFactoryInitializer {\r
+\r
+    /**\r
+     * Registers message serializers into provided registry\r
+     * @param serializerRegistry registry to be initialized with message serializers\r
+     */\r
+    public static void registerMessageSerializers(SerializerRegistry serializerRegistry) {\r
+        // register OF v1.0 message serializers\r
+        short version = EncodeConstants.OF10_VERSION_ID;\r
+        CommonMessageRegistryHelper registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry);\r
+        registryHelper.registerSerializer(BarrierInput.class, new OF10BarrierInputMessageFactory());\r
+        registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory());\r
+        registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory());\r
+        registryHelper.registerSerializer(FlowModInput.class, new OF10FlowModInputMessageFactory());\r
+        registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory());\r
+        registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory());\r
+        registryHelper.registerSerializer(GetQueueConfigInput.class, new OF10QueueGetConfigInputMessageFactory());\r
+        registryHelper.registerSerializer(HelloInput.class, new OF10HelloInputMessageFactory());\r
+        registryHelper.registerSerializer(MultipartRequestInput.class, new OF10StatsRequestInputFactory());\r
+        registryHelper.registerSerializer(PacketOutInput.class, new OF10PacketOutInputMessageFactory());\r
+        registryHelper.registerSerializer(PortModInput.class, new OF10PortModInputMessageFactory());\r
+        registryHelper.registerSerializer(SetConfigInput.class, new SetConfigMessageFactory());\r
+        // register OF v1.0 message serializers\r
+        version = EncodeConstants.OF13_VERSION_ID;\r
+        registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry);\r
+        registryHelper.registerSerializer(BarrierInput.class, new BarrierInputMessageFactory());\r
+        registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory());\r
+        registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory());\r
+        registryHelper.registerSerializer(FlowModInput.class, new FlowModInputMessageFactory());\r
+        registryHelper.registerSerializer(GetAsyncInput.class, new GetAsyncRequestMessageFactory());\r
+        registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory());\r
+        registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory());\r
+        registryHelper.registerSerializer(GetQueueConfigInput.class, new GetQueueConfigInputMessageFactory());\r
+        registryHelper.registerSerializer(GroupModInput.class, new GroupModInputMessageFactory());\r
+        registryHelper.registerSerializer(HelloInput.class, new HelloInputMessageFactory());\r
+        registryHelper.registerSerializer(MeterModInput.class, new MeterModInputMessageFactory());\r
+        registryHelper.registerSerializer(MultipartRequestInput.class, new MultipartRequestInputFactory());\r
+        registryHelper.registerSerializer(PacketOutInput.class, new PacketOutInputMessageFactory());\r
+        registryHelper.registerSerializer(PortModInput.class, new PortModInputMessageFactory());\r
+        registryHelper.registerSerializer(RoleRequestInput.class, new RoleRequestInputMessageFactory());\r
+        registryHelper.registerSerializer(SetAsyncInput.class, new SetAsyncInputMessageFactory());\r
+        registryHelper.registerSerializer( SetConfigInput.class, new SetConfigMessageFactory());\r
+        registryHelper.registerSerializer(TableModInput.class, new TableModInputMessageFactory());\r
+    }\r
+}\r
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 (file)
index f514f14..0000000
+++ /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 <E> message type
- */
-public interface OFSerializer <E extends DataObject> {
-
-    /**
-     * 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();
-}
index 18449f70a38096b0d89008edd63b70ff7e5a1021..d9ad3abc2ec79eb92e8a91d580b197fa604edd03 100644 (file)
@@ -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 <E extends DataObject> void messageToBuffer(short version, ByteBuf out, E message) {
-        @SuppressWarnings("unchecked")
-        MessageTypeKey<E> msgTypeKey = new MessageTypeKey<>(version, (Class<E>) message.getClass());
-        OFSerializer<E> 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<DataObject> 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 (file)
index 0000000..9a9a1b0
--- /dev/null
@@ -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<MessageTypeKey<?>, 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 <KEY_TYPE, SERIALIZER_TYPE extends OFGeneralSerializer> SERIALIZER_TYPE getSerializer(
+            MessageTypeKey<KEY_TYPE> msgTypeKey) {
+        OFGeneralSerializer serializer = registry.get(msgTypeKey);
+        if (serializer == null) {
+            if (msgTypeKey instanceof EnhancedMessageTypeKey) {
+                EnhancedMessageTypeKey<KEY_TYPE, ?> key =  (EnhancedMessageTypeKey<KEY_TYPE, ?>) 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 <KEY_TYPE> void registerSerializer(
+            MessageTypeKey<KEY_TYPE> 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);
+    }
+}
index def001427fed9ba7e16e284a6a45a4db3409ac82..e10249a2f9db91e58d9e0708e80461a1a545ddc3 100644 (file)
@@ -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<BarrierInput> {
 
     /** 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;
-    }
 }
index 9e1cfa5b95fca06918ad9feef7b6d9e60bedfcf2..06ba06206abd59e10bf67f341cd79dd1e066322b 100644 (file)
@@ -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<EchoInput> {
 
     /** 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;
-    }
-    
 }
index 3e76f8c03e332fc47f11b49e83aefbb39ad2501e..5273a7b9aa643f598dda77a4c1706c5c6f09f753 100644 (file)
@@ -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<EchoReplyInput>{
 
     /** 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 (file)
index ff24b6e..0000000
+++ /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<ExperimenterInput>{
-
-    /** 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;
-    }
-    
-}
index ba4f97088e375efe7fa14980af28e1687474df95..683a301ce119388cd83ca2b08087c26d6dcdce54 100644 (file)
@@ -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<FlowModInput> {
+public class FlowModInputMessageFactory implements OFSerializer<FlowModInput>, 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.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class))
+            .serialize(message.getMatch(), outBuffer);
+        OFSerializer<Instruction> 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<FlowModInput> {
         flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
         return flowModFlagBitmask;
     }
-    
-    
+
 }
index a4a1a59e06a5045d21ab4648fae7ee7469e308fb..3dfd5dccf5fe33406e693957d98eee8157c4cefb 100644 (file)
@@ -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<GetAsyncInput> {
     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);
     }
 
 }
index 23898ff89f7c18fb3ceb901ba6090920e7c19d1e..3867e33cca1c86b64855b1d7f75fdc8f1f298513 100644 (file)
@@ -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<GetConfigInput> {
 
     /** 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);
     }
 
 }
index d1f82df2c01271413881bfca4c96fb4422bceccf..b04997d2d88290c329b4683daf9da0b281993d99 100644 (file)
@@ -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<GetFeaturesInput>{
 
     /** 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);
     }
 
 }
index 5a87ec368e70f5dd97f6ab40cf3940f8b150dee1..f154125dc18357adf2e72b1ec85a8e488a7571f3 100644 (file)
@@ -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<GetQueueC
 
     private static final byte MESSAGE_TYPE = 22;
     private static final byte PADDING_IN_GET_QUEUE_CONFIG_MESSAGE = 4;
-    private static final int MESSAGE_LENGTH = 16;
-    
-    private static GetQueueConfigInputMessageFactory instance;
-    
-    private GetQueueConfigInputMessageFactory() {
-        // singleton
-    }
-    
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized GetQueueConfigInputMessageFactory getInstance(){
-        if(instance == null){
-            instance = new GetQueueConfigInputMessageFactory();
-        }
-        return instance;
-    }
-    
-    @Override
-    public void messageToBuffer(short version, ByteBuf out, GetQueueConfigInput message){
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeInt(message.getPort().getValue().intValue());
-        ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, out);
-    }
 
     @Override
-    public int computeLength(GetQueueConfigInput message){
-        return MESSAGE_LENGTH;
+    public void serialize(GetQueueConfigInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+        outBuffer.writeInt(message.getPort().getValue().intValue());
+        ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, outBuffer);
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
 }
index c92db9886d2a3571f01cfc2655f5f874be72d679..287ac2c0e2a9ce08bb7c91b0325be2bc3f667e88 100644 (file)
@@ -12,9 +12,14 @@ import io.netty.buffer.ByteBuf;
 
 import java.util.List;
 
-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.GroupModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
 
@@ -23,81 +28,43 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * @author timotej.kubas
  * @author michal.polkorab
  */
-public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {
+public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>, 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<BucketsList> buckets, ByteBuf outBuffer) {
+    private void serializerBuckets(List<BucketsList> 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<Action> 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<BucketsList> 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;
     }
 
-    
 }
index 04abc4ebca26621d47f600c55530c47a24fc19c0..b2918dcde067424832af3231bd18aff84657c990 100644 (file)
@@ -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<HelloInput>{
 
     /** 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> 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);
     }
+
 }
index 92219661ae8a8d38c1afe6905fc1af63b3645355..60c4d14f233b7783d3e38905d5bac05ce89d6935 100644 (file)
@@ -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<MeterModInput> {
     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<MeterModInput>
         return meterFlagBitmask;
     }
     
-    private static void encodeBands(List<Bands> bands, ByteBuf outBuffer) {
+    private static void serializeBands(List<Bands> bands, ByteBuf outBuffer) {
         if (bands != null) {
             for (Bands currentBand : bands) {
                 MeterBand meterBand = currentBand.getMeterBand();
@@ -122,5 +93,5 @@ public class MeterModInputMessageFactory implements OFSerializer<MeterModInput>
         outBuffer.writeInt(meterBand.getRate().intValue());
         outBuffer.writeInt(meterBand.getBurstSize().intValue());
     }
-    
+
 }
index 0fdeff1cdc19b5f4341964cb42ff1b3def8beea2..caf857c4e4d322539ff549d9ca232fe58dedefc0 100644 (file)
@@ -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<MultipartRequestInput> {
+public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput>, 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<MultipartReque
     private static final byte APPLY_SETFIELD_MISS_CODE = 15;
     private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE
     private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF
-    private static final byte FLOW_BODY_LENGTH = 32;
-    private static final byte AGGREGATE_BODY_LENGTH = 32;
-    private static final byte PORT_STATS_BODY_LENGTH = 8;
-    private static final byte QUEUE_BODY_LENGTH = 8;
-    private static final byte GROUP_BODY_LENGTH = 8;
-    private static final byte METER_BODY_LENGTH = 8;
-    private static final byte METER_CONFIG_BODY_LENGTH = 8;
-    private static final byte EXPERIMENTER_BODY_LENGTH = 8;
-    private static final byte TABLE_FEATURES_LENGTH = 64;
     private static final byte STRUCTURE_HEADER_LENGTH = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
     private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
@@ -109,171 +99,47 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
     private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4;
     private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5;
-    
-
-
-    private MultipartRequestInputFactory() {
-        // singleton
-    }
-
-    /**
-     * @return singleton factory
-     */
-    public static synchronized MultipartRequestInputFactory getInstance() {
-        if (instance == null) {
-            instance = new MultipartRequestInputFactory();
-        }
-        return instance;
-    }
+    private SerializerRegistry registry;
 
     @Override
-    public void messageToBuffer(short version, ByteBuf out,
-            MultipartRequestInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeShort(message.getType().getIntValue());
-        out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
-        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out);
+    public void serialize(MultipartRequestInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+        outBuffer.writeShort(message.getType().getIntValue());
+        outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
+        ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, outBuffer);
 
         if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase){
-            encodeDescBody(message.getMultipartRequestBody(), out);
+            serializeDescBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
-            encodeFlowBody(message.getMultipartRequestBody(), out);
+            serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
-            encodeAggregateBody(message.getMultipartRequestBody(), out);
+            serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
-            encodeTableBody(message.getMultipartRequestBody(), out);
+            serializeTableBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
-            encodePortStatsBody(message.getMultipartRequestBody(), out);
+            serializePortStatsBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
-            encodeQueueBody(message.getMultipartRequestBody(), out);
+            serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupCase) {
-            encodeGroupStatsBody(message.getMultipartRequestBody(), out);
+            serializeeGroupStatsBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDescCase) {
-            encodeGroupDescBody(message.getMultipartRequestBody(), out);
+            serializeGroupDescBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeaturesCase) {
-            encodeGroupFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeGroupFeaturesBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterCase) {
-            encodeMeterBody(message.getMultipartRequestBody(), out);
+            serializeMeterBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfigCase) {
-            encodeMeterConfigBody(message.getMultipartRequestBody(), out);
+            serializeMeterConfigBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeaturesCase) {
-            encodeMeterFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeMeterFeaturesBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeaturesCase) {
-            encodeTableFeaturesBody(message.getMultipartRequestBody(), out);
+            serializeTableFeaturesBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDescCase) {
-            encodePortDescBody(message.getMultipartRequestBody(), out);
-        } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
-            encodeExperimenterBody(message.getMultipartRequestBody(), out);
-        }
-    }
-
-    @Override
-    public int computeLength(MultipartRequestInput message) {
-        return MESSAGE_LENGTH + computeBodyLength(message);
-    }
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-
-    /**
-     *
-     * @param message
-     * @return length of MultipartRequestMessage
-     */
-    public int computeBodyLength(MultipartRequestInput message) {
-        int length = 0;
-        MultipartType type = message.getType();
-        if (type.equals(MultipartType.OFPMPFLOW)) {
-            MultipartRequestFlowCase bodyCase = (MultipartRequestFlowCase) message.getMultipartRequestBody();
-            MultipartRequestFlow body = bodyCase.getMultipartRequestFlow();
-            length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
-        } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {
-            MultipartRequestAggregateCase bodyCase = (MultipartRequestAggregateCase) message.getMultipartRequestBody();
-            MultipartRequestAggregate body = bodyCase.getMultipartRequestAggregate();
-            length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
-        } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {
-            length += PORT_STATS_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPQUEUE)) {
-            length += QUEUE_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPGROUP)) {
-            length += GROUP_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPMETER)) {
-            length += METER_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) {
-            length += METER_CONFIG_BODY_LENGTH;
-        } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) {
-            MultipartRequestTableFeaturesCase bodyCase = (MultipartRequestTableFeaturesCase) message.getMultipartRequestBody();
-            MultipartRequestTableFeatures body = bodyCase.getMultipartRequestTableFeatures();
-            length += computeTableFeaturesLength(body);
-        } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {
-            MultipartRequestExperimenterCase bodyCase = (MultipartRequestExperimenterCase) message.getMultipartRequestBody();
-            MultipartRequestExperimenter body = bodyCase.getMultipartRequestExperimenter();
-            length += EXPERIMENTER_BODY_LENGTH;
-            if (body.getData() != null) {
-                length += body.getData().length;
-            }
+            serializePortDescBody(message.getMultipartRequestBody(), outBuffer);
         }
-        return length;
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {
-        int length = 0;
-        if (body != null && body.getTableFeatures() != null) {
-            List<TableFeatures> 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<TableFeatureProperties> 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<Integer, Boolean> multipartRequestFlagsMap = new HashMap<>();
@@ -287,7 +153,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param output
      */
-    private void encodeDescBody(MultipartRequestBody multipartRequestBody,
+    private void serializeDescBody(MultipartRequestBody multipartRequestBody,
             ByteBuf output) {
         // The body of MultiPartRequestDesc is empty
     }
@@ -296,7 +162,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeTableBody(MultipartRequestBody multipartRequestBody,
+    private void serializeTableBody(MultipartRequestBody multipartRequestBody,
             ByteBuf out) {
      // The body of MultiPartTable is empty
     }
@@ -305,7 +171,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeGroupDescBody(MultipartRequestBody multipartRequestBody,
+    private void serializeGroupDescBody(MultipartRequestBody multipartRequestBody,
             ByteBuf out) {
      // The body of MultiPartRequestGroupDesc is empty
     }
@@ -314,7 +180,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeGroupFeaturesBody(
+    private void serializeGroupFeaturesBody(
             MultipartRequestBody multipartRequestBody, ByteBuf out) {
      // The body of MultiPartRequestGroupFeatures is empty
     }
@@ -323,7 +189,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeMeterFeaturesBody(
+    private void serializeMeterFeaturesBody(
             MultipartRequestBody multipartRequestBody, ByteBuf out) {
      // The body of MultiPartMeterFeatures is empty
     }
@@ -332,12 +198,12 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodePortDescBody(MultipartRequestBody multipartRequestBody,
+    private void serializePortDescBody(MultipartRequestBody multipartRequestBody,
             ByteBuf out) {
      // The body of MultiPartPortDesc is empty
     }
 
-    private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+    private void serializeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
         MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
         MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
         output.writeByte(flow.getTableId().byteValue());
@@ -347,10 +213,12 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
         ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02, output);
         output.writeLong(flow.getCookie().longValue());
         output.writeLong(flow.getCookieMask().longValue());
-        MatchSerializer.encodeMatch(flow.getMatch(), output);
+        OFSerializer<Match> 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<MultipartReque
         ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02, output);
         output.writeLong(aggregate.getCookie().longValue());
         output.writeLong(aggregate.getCookieMask().longValue());
-        MatchSerializer.encodeMatch(aggregate.getMatch(), output);
+        OFSerializer<Match> 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<MultipartReque
                     output.writeInt(createTableConfigBitmask(currTableFeature.getConfig()));
                     output.writeInt(currTableFeature.getMaxEntries().intValue());
                     writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties());
+                    output.setShort(tableFeatureLengthIndex, output.writerIndex() - tableFeatureLengthIndex);
                 }
             }
         }
     }
 
-    private static void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
+    private void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
         if (props != null) {
             for (TableFeatureProperties property : props) {
                 TableFeaturesPropType type = property.getType();
@@ -473,7 +332,7 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
         }
     }
 
-    private static void writeInstructionRelatedTableProperty(ByteBuf output,
+    private void writeInstructionRelatedTableProperty(ByteBuf output,
             TableFeatureProperties property, byte code) {
         output.writeShort(code);
         List<Instruction> instructions = property.
@@ -490,7 +349,9 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
             }
             padding = paddingNeeded(length);
             output.writeShort(length);
-            InstructionsSerializer.encodeInstructionIds(instructions, output);
+            HeaderSerializer<Instruction> 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<MultipartReque
         return result;
     }
 
-    private static void writeActionsRelatedTableProperty(ByteBuf output,
+    private void writeActionsRelatedTableProperty(ByteBuf output,
             TableFeatureProperties property, byte code) {
         output.writeShort(code);
         List<Action> actions = property.
@@ -546,7 +407,9 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
             length += actions.size() * STRUCTURE_HEADER_LENGTH;
             padding += paddingNeeded(length);
             output.writeShort(length);
-            ActionsSerializer.encodeActionIds(actions, output);
+            HeaderSerializer<Action> 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<MultipartReque
         ByteBufUtils.padBuffer(padding, output);
     }
 
-    private static void writeOxmRelatedTableProperty(ByteBuf output,
+    private void writeOxmRelatedTableProperty(ByteBuf output,
             TableFeatureProperties property, byte code) {
         output.writeShort(code);
         List<MatchEntries> entries = property.
@@ -566,7 +429,13 @@ public class MultipartRequestInputFactory implements OFSerializer<MultipartReque
             length += entries.size() * STRUCTURE_HEADER_LENGTH;
             padding = paddingNeeded(length);
             output.writeShort(length);
-            MatchSerializer.encodeMatchIds(entries, output);
+            
+            for (MatchEntries entry : entries) {
+                HeaderSerializer<MatchEntries> 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<MultipartReque
         tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap);
         return tableConfigBitmask;
     }
+
+    @Override
+    public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+        this.registry = serializerRegistry;
+    }
 }
index e37adc61c001daee8a99d5546f0ecd3f539f8788..3a3e7eae1ca748dd37afa12a36aaac0edb49206b 100644 (file)
@@ -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;
 
 /**
@@ -21,36 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class OF10BarrierInputMessageFactory implements OFSerializer<BarrierInput> {
 
     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;
-    }
 }
index 7fe217a6a5e725bd3f55074eed4358a1671808d5..d43104cf0013944fd7e43b5dc291a7fb39e2e993 100644 (file)
@@ -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<FlowModInput> {
+public class OF10FlowModInputMessageFactory implements OFSerializer<FlowModInput>, 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<MatchV10> 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<Action> 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<FlowModInput
         flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
         return flowModFlagBitmask;
     }
+
+    @Override
+    public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+        this.registry = serializerRegistry;
+    }
 }
index 68f1a2d4ed11f53a0eaa22bbe879e8632c6ffb8e..47f84b54b937533eba3abbf2184f54504566a9e1 100644 (file)
@@ -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.HelloInput;
 
 /**
@@ -21,35 +22,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class OF10HelloInputMessageFactory implements OFSerializer<HelloInput> {
 
     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;
-    }
 }
index 6684afaa0b360e7fbf979a3d477e09f9d442524f..ad49758b519a6acd7a0d1eaa39f7cabe0add9a49 100644 (file)
@@ -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<PacketOutInput> {
+public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, 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<Action> 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;
     }
 
 }
index 6cb8606b427998155ada8ee4d2c1b52488b416b6..bc38b0ddfd8210a9f8f0eb85d0d809083ad192bc 100644 (file)
@@ -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<PortModInput
 
     private static final byte MESSAGE_TYPE = 15;
     private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4;
-    private static final int MESSAGE_LENGTH = 32;
-    
-    private static OF10PortModInputMessageFactory instance;
-    
-    private OF10PortModInputMessageFactory() {
-        // singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized OF10PortModInputMessageFactory getInstance() {
-        if (instance == null) {
-            instance = new OF10PortModInputMessageFactory();
-        }
-        return instance;
-    }
-    
-    @Override
-    public void messageToBuffer(short version, ByteBuf out, PortModInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeShort(message.getPortNo().getValue().intValue());
-        out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
-        out.writeInt(createPortConfigBitmask(message.getConfigV10()));
-        out.writeInt(createPortConfigBitmask(message.getMaskV10()));
-        out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
-        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, 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.writeShort(message.getPortNo().getValue().intValue());
+        outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
+        outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10()));
+        outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10()));
+        outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
+        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, outBuffer);
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-   
-    
     /**
      * @param config
      * @return port config bitmask 
@@ -104,4 +78,5 @@ public class OF10PortModInputMessageFactory implements OFSerializer<PortModInput
         configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
         return configBitmask;
     }
+
 }
index 462cbabfdd15b0227aa9ae4124fd8b56f0cc8f7d..34e6b85b0f537c9ac5b88016ea67434917ef2fd2 100644 (file)
@@ -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;
 
 /**
@@ -22,39 +23,13 @@ public class OF10QueueGetConfigInputMessageFactory implements OFSerializer<GetQu
     
     private static final byte MESSAGE_TYPE = 20;
     private static final byte PADDING_IN_GET_QUEUE_CONFIG_MESSAGE = 2;
-    private static final int MESSAGE_LENGTH = 12;
-    
-    private static OF10QueueGetConfigInputMessageFactory instance;
-    
-    private OF10QueueGetConfigInputMessageFactory() {
-        // singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized OF10QueueGetConfigInputMessageFactory getInstance(){
-        if(instance == null){
-            instance = new OF10QueueGetConfigInputMessageFactory();
-        }
-        return instance;
-    }
-    
-    @Override
-    public void messageToBuffer(short version, ByteBuf out, GetQueueConfigInput message){
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeShort(message.getPort().getValue().intValue());
-        ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, out);
-    }
-
-    @Override
-    public int computeLength(GetQueueConfigInput message){
-        return MESSAGE_LENGTH;
-    }
 
     @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
+    public void serialize(GetQueueConfigInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+        outBuffer.writeShort(message.getPort().getValue().intValue());
+        ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, outBuffer);
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
 }
index ac8afbe42077716cbbfb00ce85124df986215d45..24c876fa09ed96063ec517a14450555368ac8182 100644 (file)
@@ -13,11 +13,15 @@ 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.OF10MatchSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
 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.oxm.rev130731.match.v10.grouping.MatchV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase;
@@ -37,10 +41,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * Translates StatsRequest messages
  * @author michal.polkorab
  */
-public class OF10StatsRequestInputFactory implements OFSerializer<MultipartRequestInput> {
+public class OF10StatsRequestInputFactory implements OFSerializer<MultipartRequestInput>, 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<MultipartReque
     private static final byte PADDING_IN_MULTIPART_REQUEST_PORT_BODY = 6;
     private static final byte PADING_IN_QUEUE_BODY = 2;
 
-    private static OF10StatsRequestInputFactory instance; 
-    
-    private OF10StatsRequestInputFactory() {
-        // singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized OF10StatsRequestInputFactory getInstance() {
-        if (instance == null) {
-            instance = new OF10StatsRequestInputFactory();
-        }
-        return instance;
-    }
-    
+    private SerializerRegistry registry;
+
     @Override
-    public void messageToBuffer(short version, ByteBuf out,
-            MultipartRequestInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeShort(message.getType().getIntValue());
-        out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
+    public void serialize(MultipartRequestInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
+        outBuffer.writeShort(message.getType().getIntValue());
+        outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
         if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase) {
-            encodeDescBody(message.getMultipartRequestBody(), out);
+            serializeDescBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
-            encodeFlowBody(message.getMultipartRequestBody(), out);
+            serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
-            encodeAggregateBody(message.getMultipartRequestBody(), out);
+            serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
-            encodeTableBody(message.getMultipartRequestBody(), out);
+            serializeTableBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
-            encodePortBody(message.getMultipartRequestBody(), out);
+            serializePortBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
-            encodeQueueBody(message.getMultipartRequestBody(), out);
+            serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
         } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
-            encodeExperimenterBody(message.getMultipartRequestBody(), out);
+            serializeExperimenterBody(message.getMultipartRequestBody(), outBuffer);
         }
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
-    
-    @Override
-    public int computeLength(MultipartRequestInput message) {
-        return MESSAGE_LENGTH + computeBodyLength(message);
-    }
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-    
+
     /**
      * 
      * @param message
@@ -138,7 +118,7 @@ public class OF10StatsRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody  
      * @param output 
      */
-    private void encodeDescBody(MultipartRequestBody multipartRequestBody,
+    private void serializeDescBody(MultipartRequestBody multipartRequestBody,
             ByteBuf output) {
         // The body of MultiPartRequestDesc is empty
     }
@@ -147,37 +127,41 @@ public class OF10StatsRequestInputFactory implements OFSerializer<MultipartReque
      * @param multipartRequestBody
      * @param out
      */
-    private void encodeTableBody(MultipartRequestBody multipartRequestBody,
+    private void serializeTableBody(MultipartRequestBody multipartRequestBody,
             ByteBuf out) {
      // The body of MultiPartTable is empty
     }
     
-    private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+    private void serializeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
         MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
         MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
-        OF10MatchSerializer.encodeMatchV10(output, flow.getMatchV10());
+        OFSerializer<MatchV10> 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<MatchV10> 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<MultipartReque
         output.writeInt(queue.getQueueId().intValue());
     }
     
-    private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+    private static void serializeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
         MultipartRequestExperimenterCase experimenterCase = (MultipartRequestExperimenterCase) multipartRequestBody;
         MultipartRequestExperimenter experimenter = experimenterCase.getMultipartRequestExperimenter();
         output.writeInt(experimenter.getExperimenter().intValue());
         output.writeBytes(experimenter.getData());
     }
+
+    @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/OF10VendorInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java
deleted file mode 100644 (file)
index 49363c9..0000000
+++ /dev/null
@@ -1,69 +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 Vendor messages
- * @author michal.polkorab
- */
-public class OF10VendorInputMessageFactory implements OFSerializer<ExperimenterInput> {
-
-    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;
-    }
-    
-}
index 443830bd388327ed92fe850674741aa9c9abc4c3..2b14b19d7332e1d226b80355c62a990b844d6f2e 100644 (file)
@@ -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<PacketOutInput>{
+public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, 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<Action> 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;
     }
 
 }
index 3a576660afb4e085fbedefac647d3f5ba807ad7e..61632cf7902440a3f2f2c3888d867b9ffbf5e13d 100644 (file)
@@ -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<PortModInput> {
     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<PortModInput> {
         configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
         return configBitmask;
     }
+
 }
index 285932d25a6c89c52f9276148c114fd3ca890f34..8f8c82e768888649f832239837ff360f63f063e8 100644 (file)
@@ -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<RoleRequestInput> {
 
     /** 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
index c647aaf708b53b605a9312d3e10b8eb59f498be6..b903e83bb8d5386cdcb2db9e263a82a4c10795e6 100644 (file)
@@ -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<SetAsyncInput> {
     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> packetInMask, ByteBuf outBuffer) {
+    private static void serializePacketInMask(List<PacketInMask> packetInMask, ByteBuf outBuffer) {
         if (packetInMask != null) {
             for (PacketInMask currentPacketMask : packetInMask) {
                 List<PacketInReason> mask = currentPacketMask.getMask();
@@ -89,7 +63,7 @@ public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput>
         }
     }
     
-    private static void encodePortStatusMask(List<PortStatusMask> portStatusMask, ByteBuf outBuffer) {
+    private static void serializePortStatusMask(List<PortStatusMask> portStatusMask, ByteBuf outBuffer) {
         if (portStatusMask != null) {
             for (PortStatusMask currentPortStatusMask : portStatusMask) {
                 List<PortReason> mask = currentPortStatusMask.getMask();
@@ -110,7 +84,7 @@ public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput>
         }
     }
     
-    private static void encodeFlowRemovedMask(List<FlowRemovedMask> flowRemovedMask, ByteBuf outBuffer) {
+    private static void serializerFlowRemovedMask(List<FlowRemovedMask> flowRemovedMask, ByteBuf outBuffer) {
         if (flowRemovedMask != null) {
             for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) {
                 List<FlowRemovedReason> mask = currentFlowRemovedMask.getMask();
@@ -132,5 +106,5 @@ public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput>
             }
         }
     }
-    
+
 }
\ No newline at end of file
index 5e7e628327bcd60e4e2a3b20862dd89b3f9c1792..a1407a01b57c7413a4e77123f3c677c00b306600 100644 (file)
@@ -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<SetConfigInput> {
 
     /** 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);
     }
 
 }
index 9c4e3b24f984c259822819fd9e8c34f3632e60f3..c9fb2b67cab64707f09e94fcc36f0e9f79a5c9ab 100644 (file)
@@ -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<TableModInput> {
     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<TableModInput>
         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 (file)
index 0000000..7f07d81
--- /dev/null
@@ -0,0 +1,36 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for Ipv4 address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmIpv4AddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        writeIpv4Address(entry, outBuffer);\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    private static void writeIpv4Address(MatchEntries entry, ByteBuf out) {\r
+        String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class)\r
+                .getIpv4Address().getValue().split("\\.");\r
+        for (int i = 0; i < addressGroups.length; i++) {\r
+            out.writeByte(Integer.parseInt(addressGroups[i]));\r
+        }\r
+    }\r
+\r
+}\r
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 (file)
index 0000000..d5491c8
--- /dev/null
@@ -0,0 +1,77 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.Arrays;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for Ipv6 address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();\r
+        String[] address;\r
+        if (textAddress.equals("::")) {\r
+            address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+            Arrays.fill(address, "0");\r
+        } else {\r
+            address = parseIpv6Address(textAddress.split(":"));\r
+        }\r
+        for (int i = 0; i < address.length; i++) {\r
+            outBuffer.writeShort(Integer.parseInt(address[i], 16));\r
+        }\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    private static String[] parseIpv6Address(String[] addressGroups) {\r
+        int countEmpty = 0;\r
+        for (int i = 0; i < addressGroups.length; i++) {\r
+            if (addressGroups[i].equals("")){\r
+                countEmpty++;\r
+            }\r
+        }\r
+        String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+        switch (countEmpty) {\r
+        case 0:\r
+            ready = addressGroups;\r
+            break;\r
+        case 1:\r
+            int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1;\r
+            int index = 0;\r
+            for (int i = 0; i < addressGroups.length; i++) {\r
+                if (addressGroups[i].equals("")) {\r
+                    for (int j = 0; j < zerosToBePushed; j++) {\r
+                        ready[index] = "0";\r
+                        index++;\r
+                    }\r
+                } else {\r
+                    ready[index] = addressGroups[i];\r
+                    index++;\r
+                }\r
+            }\r
+            break;\r
+        case 2:\r
+            Arrays.fill(ready, "0");\r
+            ready[ready.length - 1] = addressGroups[addressGroups.length - 1];\r
+            break;\r
+        default:\r
+            throw new IllegalStateException("Incorrect ipv6 address");\r
+        }\r
+        return ready;\r
+    }\r
+}\r
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 (file)
index 0000000..94df9f0
--- /dev/null
@@ -0,0 +1,29 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for MAC address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMacAddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue();\r
+        outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); // 48 b + mask [OF 1.3.2 spec]\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+}\r
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 (file)
index 0000000..8b84a88
--- /dev/null
@@ -0,0 +1,73 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for all match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMatchEntrySerializer\r
+    implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        serializeHeader(entry, outBuffer);\r
+    }\r
+\r
+    @Override\r
+    public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {\r
+        outBuffer.writeShort(getOxmClassCode());\r
+        writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),\r
+                getValueLength());\r
+    }\r
+\r
+    protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {\r
+        if (entry.isHasMask()) {\r
+            byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+            if (mask != null && mask.length != length) {\r
+                throw new IllegalArgumentException("incorrect length of mask: "+\r
+                        mask.length + ", expected: " + length);\r
+            }\r
+            out.writeBytes(mask);\r
+        }\r
+    }\r
+\r
+    protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {\r
+        int fieldAndMask = fieldValue << 1;\r
+        int length = lengthArg;\r
+        if (hasMask) {\r
+            fieldAndMask |= 1;\r
+            length *= 2;\r
+        }\r
+        out.writeByte(fieldAndMask);\r
+        out.writeByte(length);\r
+    }\r
+\r
+    /**\r
+     * @return numeric representation of oxm_field\r
+     */\r
+    protected abstract int getOxmFieldCode();\r
+\r
+    /**\r
+     * @return numeric representation of oxm_class\r
+     */\r
+    protected abstract int getOxmClassCode();\r
+\r
+    /**\r
+     * @return match entry value length (without mask length)\r
+     */\r
+    protected abstract int getValueLength();\r
+\r
+}\r
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 (file)
index 0000000..0218beb
--- /dev/null
@@ -0,0 +1,27 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for metadata based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMetadataSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata());\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+}\r
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 (file)
index 0000000..ce97203
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for port(32-bit) based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmPortNumberSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
+    }\r
+}\r
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 (file)
index 0000000..b1c4671
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for port(16-bit) based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmPortSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+    }\r
+}\r
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 (file)
index 0000000..84aefe1
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpOpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ARP_OP;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..4198f96
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpShaSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ARP_SHA;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+}\r
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 (file)
index 0000000..d51adb7
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpSpaSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ARP_SPA;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..83e67c9
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpThaSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ARP_THA;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+}\r
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 (file)
index 0000000..b0af989
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpTpaSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ARP_TPA;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..12b2bcf
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthDstSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ETH_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+}\r
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 (file)
index 0000000..b4995d6
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthSrcSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ETH_SRC;\r
+    }\r
+}\r
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 (file)
index 0000000..da60d72
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthTypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ETH_TYPE;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..901be66
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv4CodeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ICMPV4_CODE;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..b391ef1
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv4TypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ICMPV4_TYPE;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..4e267cb
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv6CodeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ICMPV6_CODE;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..09a943d
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv6TypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.ICMPV6_TYPE;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..541ba0f
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmInPhyPortSerializer extends AbstractOxmPortNumberSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IN_PHY_PORT;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..f809621
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmInPortSerializer extends AbstractOxmPortNumberSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IN_PORT;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..eacaf49
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpDscpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IP_DSCP;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..193e3f7
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpEcnSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IP_ECN;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..7a99f7b
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpProtoSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IP_PROTO;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..b8a53b9
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv4DstSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV4_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..494a6fa
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv4SrcSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV4_SRC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..5111b83
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6DstSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..9ee6601
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6ExtHdrSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();\r
+        Map<Integer, Boolean> map = new HashMap<>();\r
+        map.put(0, pseudoField.isNonext());\r
+        map.put(1, pseudoField.isEsp());\r
+        map.put(2, pseudoField.isAuth());\r
+        map.put(3, pseudoField.isDest());\r
+        map.put(4, pseudoField.isFrag());\r
+        map.put(5, pseudoField.isRouter());\r
+        map.put(6, pseudoField.isHop());\r
+        map.put(7, pseudoField.isUnrep());\r
+        map.put(8, pseudoField.isUnseq());\r
+        int bitmap = ByteBufUtils.fillBitMaskFromMap(map);\r
+        outBuffer.writeShort(bitmap);\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_EXTHDR;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..4805b26
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6FlabelSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue());\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_FLABEL;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..66cb9f4
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdSllSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_ND_SLL;\r
+    }\r
+}\r
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 (file)
index 0000000..a9cd13e
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdTargetSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_ND_TARGET;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..3e4d057
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdTllSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_ND_TLL;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+    }\r
+}\r
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 (file)
index 0000000..0b70ffc
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6SrcSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.IPV6_SRC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..3a009f2
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMetadataSerializer extends AbstractOxmMetadataSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.METADATA;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_LONG_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..8685c46
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsBosSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.MPLS_BOS;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..3c5de38
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsLabelSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.MPLS_LABEL;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..4e3af75
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsTcSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.MPLS_TC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..0d5db30
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmPbbIsidSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue());\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.PBB_ISID;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_3_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..6fd507a
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmSctpDstSerializer extends AbstractOxmPortSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.SCTP_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..82703f6
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmSctpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.SCTP_SRC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..0933cdb
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTcpDstSerializer extends AbstractOxmPortSerializer{\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.TCP_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..8a80861
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTcpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.TCP_SRC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..ac9a5de
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTunnelIdSerializer extends AbstractOxmMetadataSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.TUNNEL_ID;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_LONG_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..7397997
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmUdpDstSerializer extends AbstractOxmPortSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.UDP_DST;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+}\r
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 (file)
index 0000000..96022e6
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmUdpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.UDP_SRC;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+\r
+}\r
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 (file)
index 0000000..4f4fca2
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmVlanPcpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        outBuffer.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.VLAN_PCP;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+    }\r
+\r
+}\r
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 (file)
index 0000000..6afa159
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmVlanVidSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+    @Override\r
+    public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+        super.serialize(entry, outBuffer);\r
+        VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);\r
+        int vlanVidValue = vlanVid.getVlanVid();\r
+        if (vlanVid.isCfiBit()) {\r
+            short cfi = 1 << 12; // 13-th bit\r
+            vlanVidValue = vlanVidValue | cfi;\r
+        }\r
+\r
+        outBuffer.writeShort(vlanVidValue);\r
+        writeMask(entry, outBuffer, getValueLength());\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmClassCode() {\r
+        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+    }\r
+\r
+    @Override\r
+    protected int getOxmFieldCode() {\r
+        return OxmMatchConstants.VLAN_VID;\r
+    }\r
+\r
+    @Override\r
+    protected int getValueLength() {\r
+        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+    }\r
+\r
+}\r
index ab5d084783ee6951edd31efdb27281967eb12b04..42e6a74d02cf0ec47d63ab2529780232b0834617 100644 (file)
@@ -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;
index cb88aef5ea5a045b62bde5e82e4807a3f90c9768..0e7654d12c47a82986fbcf891ace44e05c8d2540 100644 (file)
@@ -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 <E extends OfHeader> void writeOFHeader(OFSerializer<E> factory, E message, ByteBuf out) { 
+    public static <E extends OfHeader> 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<String> 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 (file)
index 0000000..37405cc
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * Class for common serialization & deserialization operations\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class CodingUtils {\r
+\r
+    /**\r
+     * Serializes list\r
+     * @param list list of items to be serialized\r
+     * @param serializer serializer that can serialize list items\r
+     * @param outBuffer output buffer\r
+     */\r
+    public static <T extends DataObject> void serializeList(List<T> list, OFSerializer<T> serializer, ByteBuf outBuffer){\r
+        if (list != null) {\r
+            for (T item : list) {\r
+                serializer.serialize(item, outBuffer);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Serializes header fields for all objects in a list\r
+     * @param list list of items to be serialized\r
+     * @param serializer serializer that can serialize list items\r
+     * @param outBuffer output buffer\r
+     */\r
+    public static <T extends DataObject> void serializeHeaders(List<T> list, HeaderSerializer<T> serializer, ByteBuf outBuffer){\r
+        if (list != null) {\r
+            for (T item : list) {\r
+                serializer.serializeHeader(item, outBuffer);\r
+            }\r
+        }\r
+    }\r
+}\r
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 (file)
index 0000000..0ce8d54
--- /dev/null
@@ -0,0 +1,39 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class CommonMessageRegistryHelper {\r
+\r
+    private short version;\r
+    private SerializerRegistry serializerRegistry;\r
+\r
+    /**\r
+     * @param version\r
+     * @param serializerRegistry\r
+     */\r
+    public CommonMessageRegistryHelper(short version, SerializerRegistry serializerRegistry) {\r
+        this.version = version;\r
+        this.serializerRegistry = serializerRegistry;\r
+    }\r
+\r
+    /**\r
+     * @param msgType\r
+     * @param serializer\r
+     */\r
+    public void registerSerializer(Class<?> msgType, OFGeneralSerializer serializer) {\r
+        serializerRegistry.registerSerializer(new MessageTypeKey<>(version, msgType), serializer);\r
+    }\r
+}\r
index 0615b182960b8b77fa3ac21c88f8bc1666387d1e..7097b0c9f09ecea1bf186c020c7ea7b7dcabc147 100644 (file)
@@ -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 (file)
index b652432..0000000
+++ /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<Instruction> instructions, ByteBuf out) {
-        if (instructions != null) {
-            for (Instruction instruction : instructions) {
-                Class<? extends InstructionBase> 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<Instruction> instructions, ByteBuf out) {
-        if (instructions != null) {
-            for (Instruction instruction : instructions) {
-                Class<? extends InstructionBase> 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<Action> 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<Instruction> instructions) {
-        int length = 0;
-        if (instructions != null) {
-            for (Instruction instruction : instructions) {
-                Class<? extends InstructionBase> 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 (file)
index eea0844..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-\r
-/**\r
- * Encodes match ids (oxm_ids) needed in Multipart-TableFeatures messages\r
- * @author michal.polkorab\r
- */\r
-public abstract class MatchIdsSerializer {\r
-\r
-    /**\r
-     * Encodes oxm headers (without values) \r
-     * @param entry match entry\r
-     * @param out output ByteBuf\r
-     */\r
-    public static void encodeIdsRest(MatchEntries entry, ByteBuf out) {\r
-        int fieldValue = 0;\r
-        Class<? extends MatchField> field = entry.getOxmMatchField();\r
-        if (field.isAssignableFrom(InPort.class)) {\r
-            fieldValue = 0;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(InPhyPort.class)) {\r
-            fieldValue = 1;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Metadata.class)) {\r
-            fieldValue = 2;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_LONG_IN_BYTES);\r
-        } else if (field.isAssignableFrom(EthDst.class)) {\r
-            fieldValue = 3;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(EthSrc.class)) {\r
-            fieldValue = 4;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(EthType.class)) {\r
-            fieldValue = 5;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(VlanVid.class)) {\r
-            fieldValue = 6;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(VlanPcp.class)) {\r
-            fieldValue = 7;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(IpDscp.class)) {\r
-            fieldValue = 8;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(IpEcn.class)) {\r
-            fieldValue = 9;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(IpProto.class)) {\r
-            fieldValue = 10;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv4Src.class)) {\r
-            fieldValue = 11;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv4Dst.class)) {\r
-            fieldValue = 12;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(TcpSrc.class)) {\r
-            fieldValue = 13;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(TcpDst.class)) {\r
-            fieldValue = 14;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(UdpSrc.class)) {\r
-            fieldValue = 15;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(UdpDst.class)) {\r
-            fieldValue = 16;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(SctpSrc.class)) {\r
-            fieldValue = 17;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(SctpDst.class)) {\r
-            fieldValue = 18;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Icmpv4Type.class)) {\r
-            fieldValue = 19;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Icmpv4Code.class)) {\r
-            fieldValue = 20;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(ArpOp.class)) {\r
-            fieldValue = 21;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(ArpSpa.class)) {\r
-            fieldValue = 22;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(ArpTpa.class)) {\r
-            fieldValue = 23;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(ArpSha.class)) {\r
-            fieldValue = 24;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(ArpTha.class)) {\r
-            fieldValue = 25;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(Ipv6Src.class)) {\r
-            fieldValue = 26;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv6Dst.class)) {\r
-            fieldValue = 27;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv6Flabel.class)) {\r
-            fieldValue = 28;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Icmpv6Type.class)) {\r
-            fieldValue = 29;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Icmpv6Code.class)) {\r
-            fieldValue = 30;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv6NdTarget.class)) {\r
-            fieldValue = 31;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv6NdSll.class)) {\r
-            fieldValue = 32;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(Ipv6NdTll.class)) {\r
-            fieldValue = 33;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.MAC_ADDRESS_LENGTH);\r
-        } else if (field.isAssignableFrom(MplsLabel.class)) {\r
-            fieldValue = 34;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
-        } else if (field.isAssignableFrom(MplsTc.class)) {\r
-            fieldValue = 35;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(MplsBos.class)) {\r
-            fieldValue = 36;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
-        } else if (field.isAssignableFrom(PbbIsid.class)) {\r
-            fieldValue = 37;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES);\r
-        } else if (field.isAssignableFrom(TunnelId.class)) {\r
-            fieldValue = 38;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_LONG_IN_BYTES);\r
-        } else if (field.isAssignableFrom(Ipv6Exthdr.class)) {\r
-            fieldValue = 39;\r
-            MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
-                    EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
-        }\r
-    }\r
-\r
-}\r
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 (file)
index 8443ed4..0000000
+++ /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> 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> 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<? extends Clazz> 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<? extends MatchField> 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<Integer, Boolean> 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> matchEntries) {
-        int length = 0;
-        if (matchEntries != null) {
-            for (MatchEntries entry : matchEntries) {
-                length += MATCH_ENTRY_HEADER_LENGTH;
-                Class<? extends MatchField> 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;
-    }
-
-}
index eaaa6de86afb9daea123ca0395fb57a12af7946d..3ec867d737fff41ae1c6538867f6431d87e27590 100644 (file)
@@ -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<Action>, 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<Action> 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<Action> 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<ExperimenterAction> serializer = registry.getSerializer(
+                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+        serializer.serialize((ExperimenterAction) action, outBuffer);
     }
 
 }
index 33f31971e89d7ae40c17adc47f9bd6cb8b3168c4..d934e4c75e129f47b35cfb24d12cfe626cbeefea 100644 (file)
@@ -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<MatchV10> {
 
     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<Integer, Boolean> wildcardsMap = new HashMap<>();
@@ -74,5 +76,5 @@ public abstract class OF10MatchSerializer {
         bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
         return bitmask;
     }
-    
+
 }
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 5490bdbb7c9b3f890ac19178fa9a4530bb4751e0..e1f4ec6f937cfca13d5fee6c1c109a23dc4c9141 100644 (file)
@@ -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<Action>,
+        HeaderSerializer<Action>, 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<Action> 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<Action> 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<MatchEntries> 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<ExperimenterAction> 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<Action> 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<MatchEntries> 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<ExperimenterAction> 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 (file)
index 0000000..84beb0b
--- /dev/null
@@ -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<Instruction>,
+        HeaderSerializer<Instruction>, 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<Action> actions = instruction.getAugmentation(ActionsInstruction.class).getAction();
+            int instructionLengthIndex = out.writerIndex();
+            out.writeShort(EncodeConstants.EMPTY_LENGTH);
+            ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
+            OFSerializer<Action> 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<? extends InstructionBase> 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<ExperimenterInstruction> 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<? extends InstructionBase> 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<ExperimenterInstruction> 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 (file)
index 0000000..3a5b6a7
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @param <T> OXM class\r
+ */\r
+public class OF13MatchEntriesRegistryHelper<T> {\r
+\r
+    private short version;\r
+    private Class<T> oxmClass;\r
+    private SerializerRegistry serializerRegistry;\r
+\r
+    /**\r
+     * @param version Openflow wire version\r
+     * @param oxmClass\r
+     * @param serializerRegistry\r
+     */\r
+    public OF13MatchEntriesRegistryHelper(short version, Class<T> oxmClass, SerializerRegistry serializerRegistry) {\r
+        this.version = version;\r
+        this.oxmClass = oxmClass;\r
+        this.serializerRegistry = serializerRegistry;\r
+    }\r
+\r
+    /**\r
+     * Registers given serializer\r
+     * @param oxmField\r
+     * @param serializer\r
+     */\r
+    public void registerSerializer(Class<?> oxmField, OFGeneralSerializer serializer) {\r
+        serializerRegistry.registerSerializer(new EnhancedMessageTypeKey<>(version, oxmClass, oxmField),\r
+            serializer);\r
+    }\r
+}\r
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 (file)
index 0000000..a90e77b
--- /dev/null
@@ -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<Match>, 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> matchEntries, ByteBuf out) {
+        if (matchEntries == null) {
+            LOGGER.debug("Match entries are null");
+            return;
+        }
+        for (MatchEntries entry : matchEntries) {
+            OFSerializer<MatchEntries> 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 (file)
index 0000000..9e3f829
--- /dev/null
@@ -0,0 +1,106 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+/**\r
+ * Stores oxm_match constants\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class OxmMatchConstants {\r
+\r
+    /** Backward compatibility with NXM */\r
+    public static final int NXM_0_CLASS = 0x0000;\r
+    /** Backward compatibility with NXM */\r
+    public static final int NXM_1_CLASS = 0x0001;\r
+    /** Basic class for OpenFlow */\r
+    public static final int OPENFLOW_BASIC_CLASS = 0x8000;\r
+    /** Experimenter class */\r
+    public static final int EXPERIMENTER_CLASS = 0xFFFF;\r
+    \r
+    /** Switch input port */\r
+    public static final int IN_PORT = 0;\r
+    /** Switch physical input port */\r
+    public static final int IN_PHY_PORT = 1;\r
+    /** Metadata passed between tables */\r
+    public static final int METADATA = 2;\r
+    /** Ethernet destination address */\r
+    public static final int ETH_DST = 3;\r
+    /** Ethernet source address */\r
+    public static final int ETH_SRC = 4;\r
+    /** Ethernet frame type */\r
+    public static final int ETH_TYPE = 5;\r
+    /** VLAN id. */\r
+    public static final int VLAN_VID = 6;\r
+    /** VLAN priority. */\r
+    public static final int VLAN_PCP = 7;\r
+    /** IP DSCP (6 bits in ToS field). */\r
+    public static final int IP_DSCP = 8;\r
+    /** IP ECN (2 bits in ToS field). */\r
+    public static final int IP_ECN = 9;\r
+    /** IP protocol. */\r
+    public static final int IP_PROTO = 10;\r
+    /** IPv4 source address. */\r
+    public static final int IPV4_SRC = 11;\r
+    /** IPv4 destination address. */\r
+    public static final int IPV4_DST = 12;\r
+    /** TCP source port. */\r
+    public static final int TCP_SRC = 13;\r
+    /** TCP destination port. */\r
+    public static final int TCP_DST = 14;\r
+    /** UDP source port. */\r
+    public static final int UDP_SRC = 15;\r
+    /** UDP destination port. */\r
+    public static final int UDP_DST = 16;\r
+    /** SCTP source port. */\r
+    public static final int SCTP_SRC = 17;\r
+    /** SCTP destination port. */\r
+    public static final int SCTP_DST = 18;\r
+    /** ICMP type. */\r
+    public static final int ICMPV4_TYPE = 19;\r
+    /** ICMP code. */\r
+    public static final int ICMPV4_CODE = 20;\r
+    /** ARP opcode. */\r
+    public static final int ARP_OP = 21;\r
+    /** ARP source IPv4 address. */\r
+    public static final int ARP_SPA = 22;\r
+    /** ARP target IPv4 address. */\r
+    public static final int ARP_TPA = 23;\r
+    /** ARP source hardware address. */\r
+    public static final int ARP_SHA = 24;\r
+    /** ARP target hardware address. */\r
+    public static final int ARP_THA = 25;\r
+    /** IPv6 source address. */\r
+    public static final int IPV6_SRC = 26;\r
+    /** IPv6 destination address. */\r
+    public static final int IPV6_DST = 27;\r
+    /** IPv6 Flow Label */\r
+    public static final int IPV6_FLABEL = 28;\r
+    /** ICMPv6 type. */\r
+    public static final int ICMPV6_TYPE = 29;\r
+    /** ICMPv6 code. */\r
+    public static final int ICMPV6_CODE = 30;\r
+    /** Target address for ND. */\r
+    public static final int IPV6_ND_TARGET = 31;\r
+    /** Source link-layer for ND. */\r
+    public static final int IPV6_ND_SLL = 32;\r
+    /** Target link-layer for ND. */\r
+    public static final int IPV6_ND_TLL = 33;\r
+    /** MPLS label. */\r
+    public static final int MPLS_LABEL = 34;\r
+    /** MPLS TC. */\r
+    public static final int MPLS_TC = 35;\r
+    /** MPLS BoS bit. */\r
+    public static final int MPLS_BOS = 36;\r
+    /** PBB I-SID. */\r
+    public static final int PBB_ISID = 37;\r
+    /** Logical Port Metadata. */\r
+    public static final int TUNNEL_ID = 38;\r
+    /** IPv6 Extension Header pseudo-field */\r
+    public static final int IPV6_EXTHDR = 39;\r
+}\r
index 6f119eb3a7e9b77632e022826bd1bf18163e11c8..c7d21f6a062280dfb2f209422f15dc0a7404197b 100644 (file)
@@ -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<BarrierInput> 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);
     }
index bb2ee8e33bb1638162a61a71d419d59df59ab562..158557b7aeaaf8d27b95ac2290f619e1630bf010 100644 (file)
@@ -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<EchoInput> 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);
     }
index a5a504e1e6cb013bdc7b14a71eeebccfc69d666f..8107fb68a6e24889740462cbd802db1b57997816 100644 (file)
@@ -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<EchoReplyInput> 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 (file)
index ebea194..0000000
+++ /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;
-    }
-}
index 7dbd6bf237328a8a9cc10e64f2ea483e94ba4f72..a2b23054c5155ee44a690a0bd24ee2c7bb946afb 100644 (file)
@@ -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<FlowModInput> 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<Action> 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);
     }
     
index 0c3c5a62667f547afab0b6482689fc9779c9ff8f..31d5247f30fbc24b4ed89507029a9b99f5bb0d54 100644 (file)
@@ -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<GetConfigInput> 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);
     }
index a99dab67b64cfda8e3e73c1afbded1208a9b5e8a..644dc352649985396fcf54d3472e4470bac6f0c7 100644 (file)
@@ -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<GetFeaturesInput> 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);
     }
 }
index 77ab3af65b3faa005284a5101965f636db95d5aa..924702e187097e26af7340cd28100ffa526a3221 100644 (file)
@@ -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<GetQueueConfigInput> 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);
index 0f4fb9f48fd99065ed6fa60f3774fb9e38359b10..594246e1af601914169b313ff01b470d4372f8fa 100644 (file)
@@ -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<GetAsyncInput> 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);
     }
index eceb0d6630dd3a1356518527033aa8b80c7fc8c9..ba129d3f2e4fb07e6d29034f8a46c9300f4ee6f0 100644 (file)
@@ -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<GroupModInput> 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);
index 888476d4df9c90ff61f4ee622210a1c3a69294a1..3a299a634ca9ce7afae863282bb79be3185f6e34 100644 (file)
@@ -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<HelloInput> 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();
                 }
index 31893adbec468a565a2c2746ad6ee158b7b6d54e..f7f72518e1a2f628075721c64d7a3c1a39e5947b 100644 (file)
@@ -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<MeterModInput> 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());
index fe50e8789d07094e661cd6bb3317b865989e1952..b5459c406382a439c7bb5574730615726663d84f 100644 (file)
@@ -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<MultipartRequestInput> 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()));
     }
index 7e50fa8bbbd270b9dcf49e7a3b482726c4782c47..f1a70c8ee561aafeb667ca3fac989ee65abbf149 100644 (file)
@@ -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<BarrierInput> 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);
     }
index 12b2a945ebbac490b82113815a531d1b21d7fb8a..7a3effc866671ab3197f2c22486b4a0016d6bd04 100644 (file)
@@ -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<FlowModInput> 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];
index 7575be116b38476f389a1f8889f1bd52f07c80d3..4de13d3105d52932cf0462f3f9f1d0f2343f3398 100644 (file)
@@ -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<HelloInput> 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);
     }
index 9176b31eddcf199e61f3c4d699727e4b54658f72..3138892848826872db6101c38ac9ff5d1e3bde46 100644 (file)
@@ -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<PacketOutInput> 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());
index c49b7b26228cff71fa947256f932f1754d8defc2..9a71288b1c8a8e702061b6141367eefcb0a04550 100644 (file)
@@ -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<PortModInput> 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());
index 5b78232ec00dea70776e23c524f63b4a8b0cde9a..29f9c7b09aa9ef2fcde85b75118a3556e765a9be 100644 (file)
@@ -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<GetQueueConfigInput> 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());
index c8141a7b58f439ae3053c180493eb8fff5149537..845d7c2a462473919f6eebaa0ee2c6aec80e1e6e 100644 (file)
@@ -11,7 +11,12 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
@@ -40,6 +45,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class OF10StatsRequestInputFactoryTest {\r
 \r
+    private SerializerRegistry registry;\r
+    private OFSerializer<MultipartRequestInput> multipartFactory;\r
+\r
+    /**\r
+     * Initializes serializer registry and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        multipartFactory = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartRequestInput.class));\r
+    }\r
+\r
     /**\r
      * Testing OF10StatsRequestInputFactory (Desc) for correct serialization\r
      * @throws Exception\r
@@ -57,10 +76,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
         Assert.assertEquals("Wrong type", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -103,10 +121,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong wildcards", 3414271, out.readUnsignedInt());\r
@@ -128,7 +145,7 @@ public class OF10StatsRequestInputFactoryTest {
         Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
         Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong table-id", 1, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong registry-id", 1, out.readUnsignedByte());\r
         out.skipBytes(1);\r
         Assert.assertEquals("Wrong out-port", 42, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -171,10 +188,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
         Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt());\r
@@ -196,7 +212,7 @@ public class OF10StatsRequestInputFactoryTest {
         Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
         Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong registry-id", 42, out.readUnsignedByte());\r
         out.skipBytes(1);\r
         Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -219,10 +235,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
         Assert.assertEquals("Wrong type", 3, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
@@ -246,10 +261,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
         Assert.assertEquals("Wrong type", 4, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r
@@ -276,10 +290,9 @@ public class OF10StatsRequestInputFactoryTest {
         MultipartRequestInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+        multipartFactory.serialize(message, out);\r
         \r
-        BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+        BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
         Assert.assertEquals("Wrong type", 5, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r
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 (file)
index 540801a..0000000
+++ /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);
-    }
-
-}
index 292bca15d4dc56e47ee9e5db47fc6f988cc0e3ec..89f4e31ad23d8c4a2c7c1a67d955c34bc0fb87d3 100644 (file)
@@ -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<PacketOutInput> 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());
index f55be957fb0bad937f615e6c664b8efaab40d838..332a5c4fb73ad549fdbb0944106a5353f9d5978c 100644 (file)
@@ -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<PortModInput> 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());
index 4de2c4a84e5dd13fcb2c459fe41df03c125e4b01..a07715c6eb8f231e3e2acb1a86eedfb7a8c364ae 100644 (file)
@@ -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<RoleRequestInput> 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());
index efaf1ae9cadfe1dab48275ea86b5f0a03bce27f3..9a50f3262e49329a77a16768373783b6c77e2902 100644 (file)
@@ -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<SetAsyncInput> 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());
index 2d5de55b467b5f45ca4c6ae484bc866831e85679..d6c2725b8085246229aafa3d5c10c04e766979c6 100644 (file)
@@ -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<SetConfigInput> 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());
index 1daa581ab71ffdca0df6b314053d623bc8984606..8fde1ce8afd615533c8d9a927bc1e3162c76df68 100644 (file)
@@ -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<TableModInput> 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());
index eb64df70ca5f05cfb1a5b7fdcedacf018e16cb84..8ca6f174fbc7cbf9acc125490493cc2c4c60fed4 100644 (file)
@@ -15,8 +15,12 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory;\r
 import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
@@ -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;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;\r
@@ -67,6 +69,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class TableFeaturesTest {\r
     private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE =\r
             MultipartRequestInputFactoryTest.PADDING_IN_MULTIPART_REQUEST_MESSAGE;\r
+    private SerializerRegistry registry;\r
+    private OFSerializer<MultipartRequestInput> multipartFactory;\r
+\r
+    /**\r
+     * Initializes serializer registry and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        multipartFactory = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestInput.class));\r
+    }\r
 \r
     /**\r
      * @throws Exception\r
@@ -163,7 +178,7 @@ public class TableFeaturesTest {
         entriesBuilder.setHasMask(false);\r
         entries.add(entriesBuilder.build());\r
         entriesBuilder = new MatchEntriesBuilder();\r
-        entriesBuilder.setOxmClass(Nxm0Class.class);\r
+        entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entriesBuilder.setOxmMatchField(InPort.class);\r
         entriesBuilder.setHasMask(false);\r
         entries.add(entriesBuilder.build());\r
@@ -180,7 +195,7 @@ public class TableFeaturesTest {
         entriesBuilder.setHasMask(false);\r
         entries.add(entriesBuilder.build());\r
         entriesBuilder = new MatchEntriesBuilder();\r
-        entriesBuilder.setOxmClass(Nxm1Class.class);\r
+        entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entriesBuilder.setOxmMatchField(IpEcn.class);\r
         entriesBuilder.setHasMask(false);\r
         entries.add(entriesBuilder.build());\r
@@ -195,15 +210,14 @@ public class TableFeaturesTest {
         MultipartRequestInput message = builder.build();\r
 \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();\r
-        factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
+        multipartFactory.serialize(message, out);\r
 \r
-        BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));\r
+        BufferHelper.checkHeaderV13(out, (byte) 18, 232);\r
         Assert.assertEquals("Wrong type", 12, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());\r
         out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);\r
         Assert.assertEquals("Wrong length", 120, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte());\r
         out.skipBytes(5);\r
         Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
                 ByteBufUtils.decodeNullTerminatedString(out, 32));\r
@@ -219,12 +233,12 @@ public class TableFeaturesTest {
         Assert.assertEquals("Wrong max-entries", 65, out.readUnsignedInt());\r
         Assert.assertEquals("Wrong property type", 2, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong property length", 6, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong next-table-id", 1, out.readUnsignedByte());\r
-        Assert.assertEquals("Wrong next-table-id", 2, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong next-registry-id", 1, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong next-registry-id", 2, out.readUnsignedByte());\r
         out.skipBytes(2);\r
         Assert.assertEquals("Wrong property type", 3, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong property length", 5, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong next-table-id", 3, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong next-registry-id", 3, out.readUnsignedByte());\r
         out.skipBytes(3);\r
         Assert.assertEquals("Wrong property type", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort());\r
@@ -246,7 +260,7 @@ public class TableFeaturesTest {
         Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong length", 96, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte());\r
         out.skipBytes(5);\r
         Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
                 ByteBufUtils.decodeNullTerminatedString(out, 32));\r
@@ -265,7 +279,7 @@ public class TableFeaturesTest {
         Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match field&mask", 2, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
-        Assert.assertEquals("Wrong match class", 0, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match field&mask", 0, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
         out.skipBytes(4);\r
@@ -274,7 +288,7 @@ public class TableFeaturesTest {
         Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match field&mask", 20, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
-        Assert.assertEquals("Wrong match class", 1, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
         out.skipBytes(4);\r
index 787c1d7e35165628c32ec3eb317c68cd8eddbe89..92777a8e9167ceb73119ed3c622b13f698d77c5b 100644 (file)
@@ -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 extends DataObject> E bufferToMessage(OFDeserializer<E> 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 <E extends DataObject> void encodeV13(OFSerializer<E> encoder, ByteBuf out, E pojo) {
-        messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);
-    }
-    
-    private static <E extends DataObject> void messageToBuffer(
-            OFSerializer<E> encoder, ByteBuf out, E pojo, Short version) {
-        encoder.messageToBuffer(version, out, pojo);
-    }
+
 }
index 0c1706db0d3d39fb1b6b9a6ad80eec7d58a0a15c..a5c9099053e4643f9a350012627c91538f97cc1a 100644 (file)
@@ -14,13 +14,16 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
@@ -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;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc;\r
@@ -58,6 +60,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
  */\r
 public class OF10ActionsSerializerTest {\r
 \r
+    private SerializerRegistry registry;\r
+    private OFSerializer<Action> actionSerializer;\r
+\r
+    /**\r
+     * Initializes serializer table and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        actionSerializer = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class));\r
+    }\r
+\r
     /**\r
      * Testing correct serialization of actions (OF v1.0) \r
      */\r
@@ -139,15 +155,9 @@ public class OF10ActionsSerializerTest {
         queueBuilder.setQueueId(400L);\r
         actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build());\r
         actions.add(actionBuilder.build());\r
-        actionBuilder = new ActionBuilder();\r
-        actionBuilder.setType(Experimenter.class);\r
-        ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder();\r
-        expBuilder.setExperimenter(500L);\r
-        actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
-        actions.add(actionBuilder.build());\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        OF10ActionsSerializer.encodeActionsV10(out, actions);\r
+        CodingUtils.serializeList(actions, actionSerializer, out);\r
         \r
         Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
@@ -205,9 +215,6 @@ public class OF10ActionsSerializerTest {
         Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort());\r
         out.skipBytes(6);\r
         Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong vendor-id", 500, out.readUnsignedInt());\r
         Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0);\r
     }\r
     \r
index 19d745be585af48feb30fbf1b18a3e66590da45f..a225db308d716bb1e141f22384e622203120e935 100644 (file)
@@ -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<MatchV10> 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());
@@ -14,11 +14,14 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
@@ -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;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;\r
@@ -65,7 +67,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.
  * @author michal.polkorab\r
  * \r
  */\r
-public class ActionsSerializerTest {\r
+public class OF13ActionsSerializerTest {\r
+\r
+    private SerializerRegistry registry;\r
+    private OFSerializer<Action> actionSerializer;\r
+\r
+    /**\r
+     * Initializes serializer table and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        actionSerializer = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));\r
+    }\r
 \r
     /**\r
      * Testing correct serialization of actions\r
@@ -163,16 +179,9 @@ public class ActionsSerializerTest {
         actionBuilder = new ActionBuilder();\r
         actionBuilder.setType(PopPbb.class);\r
         actions.add(actionBuilder.build());\r
-        actionBuilder = new ActionBuilder();\r
-        actionBuilder.setType(Experimenter.class);\r
-        ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();\r
-        experimenter.setExperimenter(4L);\r
-        experimenter.setData(new byte[]{0, 1, 2, 3, 4, 5, 6, 7});\r
-        actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());\r
-        actions.add(actionBuilder.build());\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        ActionsSerializer.encodeActions(actions, out);\r
+        CodingUtils.serializeList(actions, actionSerializer, out);\r
         \r
         Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
@@ -234,12 +243,6 @@ public class ActionsSerializerTest {
         Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
         out.skipBytes(4);\r
-        Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt());\r
-        byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
-        out.readBytes(data);\r
-        Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, data);\r
         Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
     }\r
 \r
@@ -14,7 +14,12 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
@@ -52,7 +57,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
  * @author michal.polkorab\r
  *\r
  */\r
-public class InstructionsSerializerTest {\r
+public class OF13InstructionsSerializerTest {\r
+\r
+    private SerializerRegistry registry;\r
+    private OFSerializer<Instruction> instructionSerializer;\r
+\r
+    /**\r
+     * Initializes serializer table and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        instructionSerializer = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Instruction.class));\r
+    }\r
 \r
     /**\r
      * Testing instructions translation\r
@@ -128,7 +147,7 @@ public class InstructionsSerializerTest {
         instructions.add(builder.build());\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        InstructionsSerializer.encodeInstructions(instructions, out);\r
+        CodingUtils.serializeList(instructions, instructionSerializer, out);\r
         \r
         Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());\r
@@ -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<Match> 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
@@ -14,7 +14,12 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
@@ -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;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
@@ -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;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
@@ -125,7 +127,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.
  * @author michal.polkorab\r
  *\r
  */\r
-public class MatchSerializerTest2 {\r
+public class OF13MatchSerializerTest2 {\r
+\r
+    private SerializerRegistry registry;\r
+    private OFSerializer<Match> matchSerializer;\r
+\r
+    /**\r
+     * Initializes serializer table and stores correct factory in field\r
+     */\r
+    @Before\r
+    public void startUp() {\r
+        registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        matchSerializer = registry.getSerializer(\r
+                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));\r
+    }\r
 \r
     /**\r
      * Testing serialization of match\r
@@ -137,7 +153,7 @@ public class MatchSerializerTest2 {
         Match match = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        MatchSerializer.encodeMatch(match, out);\r
+        matchSerializer.serialize(match, out);\r
         \r
         Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match length", 4, out.readUnsignedShort());\r
@@ -153,7 +169,7 @@ public class MatchSerializerTest2 {
         builder.setType(OxmMatchType.class);\r
         List<MatchEntries> entries = new ArrayList<>();\r
         MatchEntriesBuilder entryBuilder = new MatchEntriesBuilder();\r
-        entryBuilder.setOxmClass(Nxm0Class.class);\r
+        entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entryBuilder.setOxmMatchField(InPort.class);\r
         entryBuilder.setHasMask(false);\r
         PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder();\r
@@ -161,7 +177,7 @@ public class MatchSerializerTest2 {
         entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());\r
         entries.add(entryBuilder.build());\r
         entryBuilder = new MatchEntriesBuilder();\r
-        entryBuilder.setOxmClass(Nxm1Class.class);\r
+        entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entryBuilder.setOxmMatchField(InPhyPort.class);\r
         entryBuilder.setHasMask(false);\r
         portNumberBuilder = new PortNumberMatchEntryBuilder();\r
@@ -180,7 +196,7 @@ public class MatchSerializerTest2 {
         entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
         entries.add(entryBuilder.build());\r
         entryBuilder = new MatchEntriesBuilder();\r
-        entryBuilder.setOxmClass(ExperimenterClass.class);\r
+        entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entryBuilder.setOxmMatchField(EthDst.class);\r
         entryBuilder.setHasMask(true);\r
         MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder();\r
@@ -224,7 +240,7 @@ public class MatchSerializerTest2 {
         entryBuilder = new MatchEntriesBuilder();\r
         entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entryBuilder.setOxmMatchField(VlanPcp.class);\r
-        entryBuilder.setHasMask(true);\r
+        entryBuilder.setHasMask(false);\r
         VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder();\r
         pcpBuilder.setVlanPcp((short) 14);\r
         entryBuilder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build());\r
@@ -454,7 +470,7 @@ public class MatchSerializerTest2 {
         entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build());\r
         entries.add(entryBuilder.build());\r
         entryBuilder = new MatchEntriesBuilder();\r
-        entryBuilder.setOxmClass(ExperimenterClass.class);\r
+        entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
         entryBuilder.setOxmMatchField(Ipv6NdSll.class);\r
         entryBuilder.setHasMask(false);\r
         macBuilder = new MacAddressMatchEntryBuilder();\r
@@ -536,15 +552,15 @@ public class MatchSerializerTest2 {
         Match match = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
-        MatchSerializer.encodeMatch(match, out);\r
+        matchSerializer.serialize(match, out);\r
         \r
         Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match length", 428, out.readUnsignedShort());\r
-        Assert.assertEquals("Wrong match entry class", 0, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong match entry class", 1, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt());\r
@@ -553,7 +569,7 @@ public class MatchSerializerTest2 {
         Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry value", 1L, out.readLong());\r
         Assert.assertEquals("Wrong match entry mask", 2L, out.readLong());\r
-        Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte());\r
         byte[] array = new byte[6];\r
@@ -727,7 +743,7 @@ public class MatchSerializerTest2 {
         array = new byte[16];\r
         out.readBytes(array);\r
         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);\r
-        Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
         Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte());\r
         Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte());\r
         array = new byte[6];\r
index 56766a7bfd2258ab6fb5ef4ffea289e60399f8cc..8b4b958aee25793c8ebb176f7231e7fd35381111 100644 (file)
@@ -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  <E extends DataObject> void registerCustomSerializer(MessageTypeKey<E> key,
+            OFSerializer<E> serializer);
 }
diff --git a/pom.xml b/pom.xml
index 63b57378b8c9f563e72aea883480221a02cf6b88..623e85a768bf7a7a60786235707d8bfb0b8c0262 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                 <artifactId>slf4j-api</artifactId>
                 <version>${slf4j.version}</version>
             </dependency>
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-buffer</artifactId>
+                <version>${netty.version}</version>
+            </dependency>
             <dependency>
                 <groupId>io.netty</groupId>
                 <artifactId>netty-handler</artifactId>