Rework MatchEntrySerializer 21/80521/27
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Feb 2019 10:46:00 +0000 (11:46 +0100)
committerArunprakash D <d.arunprakash@ericsson.com>
Mon, 24 Feb 2020 08:25:00 +0000 (08:25 +0000)
MatchEntrySerializer has a filter, which is being applied before
main serialization, and that is the only way it is being used --
we check if the match is present and if it is we run serialize().

This leads to quite a bit of code duplication as well as inefficient
execution, MatchSerializer performs two invocations and each of them
performs at least one traversal of the match.

Change matchTypeCheck() to serializeIfPresent(), which means
MatchSerializer does not invoke two method. This also allows us to
optimize the serialization process in AbstractMatchEntrySerializer
and its subclasses by traversing the match only once. This rework
makes it obvious that MatchEntrySerializer should not be an
OFSerializer, at all, as the inherited methods just confuse the
workflow.

Resulting code structure removes quite a bit of duplicated code
from the individual EntrySerializer classes and lends itself to
sharing functionality through common subclasses -- reducing the
number of possible method implementations at various places, thus
allowing better devirtualization and inlining.

The second part deals with the logic of serializing the header,
as all specific serializers have a constant header, which we can
easily precompute and emit with a single ByteBuf.writeInt() call.
Since external serializers have had the option to dynamically emit
a different header, this capability is retained via HeaderWriter
helper which is attached to each serializer. Since the number of
serializers is limited, this additional object poses little memory
overhead and is partially offset by the reduction of bytecode coming
from the elimination of oxmField/oxmClass/valueLength getters.

Because all our serializers have a constant length, we only provide
one concrete implementation of HeaderWriter, which is
ConstantHeaderWriter. Unless an additional implementation is provided
externally, this means that all header serialization calls are
readily devirtualized via CHA, thus the cost of this indirection
is zero.

JIRA: OPNFLWPLUG-1068
Change-Id: I49b7a3c5770e939d082db8479f6d70a689d4c944
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
60 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/protocol/serialization/MatchEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractExperimenterMatchEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PolymorphicEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PrefixEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv6PolymorphicEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressFilterEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMatchEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPolymorphicEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPortNumberEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPrimitiveEntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint16EntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint32EntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint8EntrySerializer.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/ArpOpEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/ArpSourceHardwareAddressEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/ArpSourceTransportAddressEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/ArpTargetHardwareAddressEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/ArpTargetTransportAddressEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/EthernetDestinationEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/EthernetSourceEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/EthernetTypeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Icmpv4CodeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Icmpv4TypeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Icmpv6CodeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Icmpv6TypeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/InPhyPortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/InPortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/IpDscpEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/IpEcnEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/IpProtoEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv4DestinationEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv4SourceEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6DestinationEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6ExtHeaderEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6LabelEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6NdSllEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6NdTargetEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6NdTllEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/Ipv6SourceEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/MatchSerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/MetadataEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/MplsBosEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/MplsLabelEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/MplsTcEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/PacketTypeEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/PbbEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/SctpDestinationPortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/SctpSourcePortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TcpDestinationPortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TcpFlagsEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TcpSourcePortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TunnelIdEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TunnelIpv4DestinationEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/TunnelIpv4SourceEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/UdpDestinationPortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/UdpSourcePortEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/VlanPcpEntrySerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/VlanVidEntrySerializer.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java

index 1f923aa822076d9dec67ec948f058f4034e84db6..87ee96319400050dc4b2ba5f214a69326d869914 100644 (file)
@@ -5,19 +5,18 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.api.openflow.protocol.serialization;
 
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import io.netty.buffer.ByteBuf;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 
-public interface MatchEntrySerializer extends OFSerializer<Match> {
+public interface MatchEntrySerializer {
 
     /**
-     * Checks if current match is this match type.
+     * Serialize this match entry if it is present in the match.
+     *
      * @param match Openflow match
-     * @return true if matched
+     * @param outBuffer output buffer
      */
-    boolean matchTypeCheck(Match match);
-
+    void serializeIfPresent(Match match, ByteBuf outBuffer);
 }
\ No newline at end of file
index 9f0d1689b939e89def83175f9c0de13d78fe1c92..7556f194f5a2ff8dfc8dbbc9c11a4d2584b1a7b0 100644 (file)
@@ -5,43 +5,40 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
 import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 
-public abstract class AbstractExperimenterMatchEntrySerializer extends AbstractMatchEntrySerializer {
+public abstract class AbstractExperimenterMatchEntrySerializer<E, M> extends AbstractMatchEntrySerializer<E, M> {
+    private final int experimenterId;
 
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeInt(Long.valueOf(getExperimenterId()).intValue());
+    protected AbstractExperimenterMatchEntrySerializer(final HeaderWriter<E, M> headerWriter,
+            final long experimenterId) {
+        super(headerWriter);
+        this.experimenterId = Long.valueOf(experimenterId).intValue();
     }
 
-    @Override
-    public void serializeHeader(Match match, ByteBuf outBuffer) {
-        outBuffer.writeShort(getOxmClassCode());
-
-        int fieldAndMask = getOxmFieldCode() << 1;
-        int length = getValueLength();
-
-        if (getHasMask(match)) {
-            fieldAndMask |= 1;
-            length *= 2;
-        }
-
-        outBuffer.writeByte(fieldAndMask);
+    protected AbstractExperimenterMatchEntrySerializer(final int oxmFieldCode, final int valueLength,
+            final long experimenterId) {
+        this(new ConstantHeaderWriter<>(OxmMatchConstants.EXPERIMENTER_CLASS, oxmFieldCode, valueLength,
+                EncodeConstants.SIZE_OF_INT_IN_BYTES), experimenterId);
+    }
 
-        // Add length of experimenter ID to total length
-        outBuffer.writeByte(length + EncodeConstants.SIZE_OF_INT_IN_BYTES);
+    @Override
+    protected final void serializeEntry(final E entry, final M mask, final ByteBuf outBuffer) {
+        outBuffer.writeInt(experimenterId);
+        serializeEntryContent(entry, mask, outBuffer);
     }
 
     /**
-     * Get experimenter id.
+     * Extract the corresponding entry from a match.
      *
-     * @return experimenter match entry id
+     * @param entry entry to serialize
+     * @param outBuffer output buffer
      */
-    protected abstract long getExperimenterId();
+    protected abstract void serializeEntryContent(@NonNull E entry, @Nullable M mask, @NonNull ByteBuf outBuffer);
 }
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PolymorphicEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PolymorphicEntrySerializer.java
new file mode 100644 (file)
index 0000000..0bef52e
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask;
+
+abstract class AbstractIpv4PolymorphicEntrySerializer
+        extends AbstractPolymorphicEntrySerializer<Ipv4MatchArbitraryBitMask, Ipv4Match, Ipv4Prefix, DottedQuad> {
+
+    AbstractIpv4PolymorphicEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_INT_IN_BYTES, Ipv4MatchArbitraryBitMask.class,
+            Ipv4Match.class, Ipv4Prefix.class, DottedQuad.class);
+    }
+
+    @Override
+    final boolean useArbitraryEntry(final Ipv4MatchArbitraryBitMask arbitraryMatch) {
+        return extractArbitraryEntryAddress(arbitraryMatch) != null;
+    }
+
+    @Override
+    final Integer extractNormalEntryMask(final Ipv4Prefix entry) {
+        return IpConversionUtil.hasIpv4Prefix(entry);
+    }
+
+    @Override
+    final void serializeArbitraryEntry(final Ipv4MatchArbitraryBitMask arbitraryMatch, final DottedQuad mask,
+            final ByteBuf outBuffer) {
+        writeIpv4Address(extractArbitraryEntryAddress(arbitraryMatch), outBuffer);
+        if (mask != null) {
+            writeMask(IpConversionUtil.convertArbitraryMaskToByteArray(mask), outBuffer,
+                EncodeConstants.SIZE_OF_INT_IN_BYTES);
+        }
+    }
+
+    @Override
+    final void serializeNormalEntry(final Ipv4Prefix entry, final Integer mask, final ByteBuf outBuffer) {
+        writeIpv4Prefix(entry, mask, outBuffer);
+    }
+
+    abstract Ipv4Address extractArbitraryEntryAddress(@NonNull Ipv4MatchArbitraryBitMask arbitraryMatch);
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PrefixEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv4PrefixEntrySerializer.java
new file mode 100644 (file)
index 0000000..0490152
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+
+public abstract class AbstractIpv4PrefixEntrySerializer extends AbstractMatchEntrySerializer<Ipv4Prefix, Integer> {
+    protected AbstractIpv4PrefixEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(new ConstantHeaderWriter<>(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_INT_IN_BYTES));
+    }
+
+    @Override
+    protected final Integer extractEntryMask(final Ipv4Prefix entry) {
+        return IpConversionUtil.hasIpv4Prefix(entry);
+    }
+
+    @Override
+    protected final void serializeEntry(final Ipv4Prefix entry, final Integer mask, final ByteBuf outBuffer) {
+        writeIpv4Prefix(entry, mask, outBuffer);
+    }
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv6PolymorphicEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractIpv6PolymorphicEntrySerializer.java
new file mode 100644 (file)
index 0000000..b84f1d2
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
+
+abstract class AbstractIpv6PolymorphicEntrySerializer extends
+        AbstractPolymorphicEntrySerializer<Ipv6MatchArbitraryBitMask, Ipv6Match, Ipv6Prefix, Ipv6ArbitraryMask> {
+
+    AbstractIpv6PolymorphicEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES,
+            Ipv6MatchArbitraryBitMask.class, Ipv6Match.class, Ipv6Prefix.class, Ipv6ArbitraryMask.class);
+    }
+
+    @Override
+    final boolean useArbitraryEntry(final Ipv6MatchArbitraryBitMask arbitraryMatch) {
+        return extractArbitraryEntryAddress(arbitraryMatch) != null;
+    }
+
+    @Override
+    final Integer extractNormalEntryMask(final Ipv6Prefix entry) {
+        return IpConversionUtil.hasIpv6Prefix(entry);
+    }
+
+    @Override
+    final void serializeArbitraryEntry(final Ipv6MatchArbitraryBitMask arbitraryMatch, final Ipv6ArbitraryMask mask,
+            final ByteBuf outBuffer) {
+        writeIpv6Address(extractArbitraryEntryAddress(arbitraryMatch), outBuffer);
+        if (mask != null) {
+            writeMask(IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(mask), outBuffer,
+                EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
+        }
+    }
+
+    @Override
+    final void serializeNormalEntry(final Ipv6Prefix entry, final Integer mask, final ByteBuf outBuffer) {
+        writeIpv6Prefix(entry, mask, outBuffer);
+    }
+
+    abstract Ipv6Address extractArbitraryEntryAddress(@NonNull Ipv6MatchArbitraryBitMask arbitraryMatch);
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressEntrySerializer.java
new file mode 100644 (file)
index 0000000..c5608e6
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+
+public abstract class AbstractMacAddressEntrySerializer extends AbstractPrimitiveEntrySerializer<MacAddress> {
+    protected AbstractMacAddressEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.MAC_ADDRESS_LENGTH);
+    }
+
+    @Override
+    protected final void serializeEntry(final MacAddress entry, final ByteBuf outBuffer) {
+        writeMacAddress(entry, outBuffer);
+    }
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressFilterEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractMacAddressFilterEntrySerializer.java
new file mode 100644 (file)
index 0000000..9694f09
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.MacAddressFilter;
+
+public abstract class AbstractMacAddressFilterEntrySerializer<E extends MacAddressFilter>
+    extends AbstractMatchEntrySerializer<E, MacAddress> {
+
+    protected AbstractMacAddressFilterEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(new ConstantHeaderWriter<>(oxmClassCode, oxmFieldCode, EncodeConstants.MAC_ADDRESS_LENGTH));
+    }
+
+    @Override
+    protected final MacAddress extractEntryMask(final E entry) {
+        return entry.getMask();
+    }
+
+    @Override
+    protected final void serializeEntry(final E entry, final MacAddress mask, final ByteBuf outBuffer) {
+        writeMacAddress(entry.getAddress(), outBuffer);
+        if (mask != null) {
+            writeMask(ByteBufUtils.macAddressToBytes(mask.getValue()), outBuffer, EncodeConstants.MAC_ADDRESS_LENGTH);
+        }
+    }
+}
index 8d31520bcf7488f90393d0fb23657f719ede07d9..2f24ac45773630eb8539c797aabff2a3284fd15c 100644 (file)
@@ -5,16 +5,18 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
+import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.buffer.ByteBuf;
-import java.util.Iterator;
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
+import io.netty.buffer.Unpooled;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.openflow.protocol.serialization.MatchEntrySerializer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -24,27 +26,128 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 
-public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<Match>, MatchEntrySerializer {
+/**
+ * Abstract base class for conveniently implementing {@link MatchEntrySerializer}.
+ *
+ * @param <E> Match entry type
+ * @param <M> Match entry mask type, use Void a mask is not applicable
+ */
+public abstract class AbstractMatchEntrySerializer<E, M> implements MatchEntrySerializer {
+    /**
+     * Base class supporting writing out a particular match entry's header. This class should be subclassed only
+     * in case the header contents depends on the match entry content in a more dynamic fashion than the presence
+     * or absence of the mask. In all other cases using {@link ConstantHeaderWriter} is preferable.
+     *
+     * @param <E> Match entry type
+     * @param <M> Match entry mask type, use Void a mask is not applicable
+     */
+    protected abstract static class HeaderWriter<E, M> {
+
+        /**
+         * Write out the header for a particular entry, containing specified mask, to the provided output buffer.
+         *
+         * @param entry match entry for which to write the header
+         * @param mask mask as extracted from the match entry, may be null
+         * @param outBuffer output buffer
+         */
+        protected abstract void writeHeader(@NonNull E entry, @Nullable M mask, @NonNull ByteBuf outBuffer);
 
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        serializeHeader(match, outBuffer);
+        protected static final void writeHeader(final int oxmClassCode, final int oxmFieldCode, final int valueLength,
+                final boolean hasMask, final ByteBuf outBuffer) {
+            writeHeader(oxmClassCode, oxmFieldCode, valueLength, hasMask, 0, outBuffer);
+        }
+
+        protected static final void writeHeader(final int oxmClassCode, final int oxmFieldCode, final int valueLength,
+                final boolean hasMask, final int extraLength, final ByteBuf outBuffer) {
+            outBuffer.writeShort(oxmClassCode);
+
+            int fieldAndMask = oxmFieldCode << 1;
+            int length = valueLength;
+
+            if (hasMask) {
+                fieldAndMask |= 1;
+                length *= 2;
+            }
+
+            outBuffer.writeByte(fieldAndMask);
+            outBuffer.writeByte(length + extraLength);
+        }
     }
 
-    @Override
-    public void serializeHeader(Match match, ByteBuf outBuffer) {
-        outBuffer.writeShort(getOxmClassCode());
+    /**
+     * Utility {@link HeaderWriter} optimized for cases where the header does not depend on the actual entry content
+     * beyond presence/absence of a mask. This class pre-computes the possible header values for masked/unmasked cases
+     * and stores them internally for reuse.
+     *
+     * @param <E> Match entry type
+     * @param <M> Match entry mask type, use Void a mask is not applicable
+     */
+    /*
+     * Implementation note:
+     *
+     * While it looks like we could save some memory by refactoring this class into two instances for the non-mask
+     * and mask values, that actually would result in increased memory footprint because the JVM object header is
+     * larger than the state we keep. We would also require another reference field in the serializer itself, which
+     * would expand the size of that object, negating the benefit.
+     *
+     * Another refactor would see the case where an entry cannot have a mask split out into a separate class, making
+     * that specialized object smaller and not contain the null check in writeHeader(). This can be considered, but
+     * has to be thoroughly benchmarked with representative data, because introducing another implementation means
+     * calls to writeHeader() are no longer monomorphic and are not as readily devirtualizable -- which has performance
+     * implications which can easily negate any behefits from the specialization.
+     */
+    protected static final class ConstantHeaderWriter<E, M> extends HeaderWriter<E, M> {
+        private final int withMask;
+        private final int withoutMask;
 
-        int fieldAndMask = getOxmFieldCode() << 1;
-        int length = getValueLength();
+        protected ConstantHeaderWriter(final int withMask, final int withoutMask) {
+            this.withMask = withMask;
+            this.withoutMask = withoutMask;
+        }
 
-        if (getHasMask(match)) {
-            fieldAndMask |= 1;
-            length *= 2;
+        protected ConstantHeaderWriter(final int oxmClassCode, final int oxmFieldCode, final int valueLength) {
+            this(oxmClassCode, oxmFieldCode, valueLength, 0);
         }
 
-        outBuffer.writeByte(fieldAndMask);
-        outBuffer.writeByte(length);
+        protected ConstantHeaderWriter(final int oxmClassCode, final int oxmFieldCode, final int valueLength,
+                final int extraLength) {
+            this(constructHeader(oxmClassCode, oxmFieldCode, valueLength, extraLength, true),
+                constructHeader(oxmClassCode, oxmFieldCode, valueLength, extraLength, false));
+        }
+
+        @Override
+        protected void writeHeader(final E entry, final M mask, final ByteBuf outBuffer) {
+            outBuffer.writeInt(mask != null ? withMask : withoutMask);
+        }
+
+        private static int constructHeader(final int oxmClassCode, final int oxmFieldCode, final int valueLength,
+                final int extraLength, final boolean withMask) {
+            final ByteBuf buf = Unpooled.buffer();
+            writeHeader(oxmClassCode, oxmFieldCode, valueLength, withMask, extraLength, buf);
+            final int header = buf.readInt();
+            verify(buf.readableBytes() == 0);
+            return header;
+        }
+    }
+
+    private final HeaderWriter<E, M> headerWriter;
+
+    protected AbstractMatchEntrySerializer(final HeaderWriter<E, M> headerWriter) {
+        this.headerWriter = requireNonNull(headerWriter);
+    }
+
+    protected AbstractMatchEntrySerializer(final int oxmClassCode, final int oxmFieldCode, final int valueLength) {
+        this(new ConstantHeaderWriter<>(oxmClassCode, oxmFieldCode, valueLength));
+    }
+
+    @Override
+    public final void serializeIfPresent(final Match match, final ByteBuf outBuffer) {
+        final E entry = extractEntry(match);
+        if (entry != null) {
+            final M mask = extractEntryMask(entry);
+            headerWriter.writeHeader(entry, mask, outBuffer);
+            serializeEntry(entry, mask, outBuffer);
+        }
     }
 
     /**
@@ -54,17 +157,14 @@ public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<M
      * @param outBuffer output buffer
      * @param length mask length
      */
-    protected static void writeMask(byte[] mask, ByteBuf outBuffer, int length) {
-        if (mask == null) {
-            return;
-        }
-
-        if (mask.length != length) {
-            throw new IllegalArgumentException("incorrect length of mask: "
-                    + mask.length + ", expected: " + length);
+    protected static void writeMask(final byte[] mask, final ByteBuf outBuffer, final int length) {
+        if (mask != null) {
+            if (mask.length != length) {
+                throw new IllegalArgumentException("incorrect length of mask: " + mask.length + ", expected: "
+                        + length);
+            }
+            outBuffer.writeBytes(mask);
         }
-
-        outBuffer.writeBytes(mask);
     }
 
     /**
@@ -94,7 +194,8 @@ public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<M
      * @param outBuffer output buffer
      */
     protected static void writeMacAddress(final MacAddress address, final ByteBuf outBuffer) {
-        outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(address)); // 48 b + mask [OF 1.3.2 spec]
+        // 48 b + mask [OF 1.3.2 spec]
+        outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(address));
     }
 
     /**
@@ -103,17 +204,14 @@ public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<M
      * @param prefix Ipv4 prefix
      * @param outBuffer output buffer
      */
-    protected static void writeIpv4Prefix(final Ipv4Prefix prefix, final ByteBuf outBuffer) {
-        // Split address to IP and mask
-        final Iterator<String> addressParts = IpConversionUtil.splitToParts(prefix);
-
+    protected static void writeIpv4Prefix(final @NonNull Ipv4Prefix prefix, final @Nullable Integer mask,
+            final @NonNull ByteBuf outBuffer) {
         // Write address part of prefix
-        writeIpv4Address(new Ipv4Address(addressParts.next()), outBuffer);
+        writeIpv4Address(IetfInetUtil.INSTANCE.ipv4AddressFrom(prefix), outBuffer);
 
         // If prefix had mask, also write prefix
-        final byte[] mask = MatchConvertorUtil.extractIpv4Mask(addressParts);
         if (mask != null) {
-            writeMask(mask, outBuffer, EncodeConstants.GROUPS_IN_IPV4_ADDRESS);
+            outBuffer.writeInt(IpConversionUtil.maskForIpv4Prefix(mask));
         }
     }
 
@@ -123,12 +221,12 @@ public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<M
      * @param prefix Ipv6 prefix
      * @param outBuffer output buffer
      */
-    protected static void writeIpv6Prefix(final Ipv6Prefix prefix, final ByteBuf outBuffer) {
+    protected static void writeIpv6Prefix(final @NonNull Ipv6Prefix prefix, final @Nullable Integer mask,
+            final @NonNull ByteBuf outBuffer) {
         // Write address part of prefix
         writeIpv6Address(IpConversionUtil.extractIpv6Address(prefix), outBuffer);
 
         // If prefix had mask, also write prefix
-        final Integer mask = IpConversionUtil.hasIpv6Prefix(prefix);
         if (mask != null) {
             writeMask(IpConversionUtil.convertIpv6PrefixToByteArray(mask), outBuffer,
                 EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
@@ -136,31 +234,27 @@ public abstract class AbstractMatchEntrySerializer implements HeaderSerializer<M
     }
 
     /**
-     * Has mask getter.
+     * Extract the corresponding entry from a match.
      *
      * @param match Openflow match
-     * @return if field has or has not mask
+     * @return Entry, null if not present
      */
-    protected abstract boolean getHasMask(Match match);
+    protected abstract @Nullable E extractEntry(Match match);
 
     /**
-     * Oxm field numeric representation.
+     * Extract the mask contained in an entry.
      *
-     * @return numeric representation of oxm_field
+     * @param entry entry to examine
+     * @return Mask, null if not present
      */
-    protected abstract int getOxmFieldCode();
+    protected abstract @Nullable M extractEntryMask(@NonNull E entry);
 
     /**
-     * Oxm class code.
+     * Extract the corresponding entry from a match.
      *
-     * @return numeric representation of oxm_class
-     */
-    protected abstract int getOxmClassCode();
-
-    /**
-     * Get value length.
-     *
-     * @return match entry value length (without mask length)
+     * @param entry entry to serialize
+     * @param mask mask as extracted from entry
+     * @param outBuffer output buffer
      */
-    protected abstract int getValueLength();
+    protected abstract void serializeEntry(@NonNull E entry, @Nullable M mask, @NonNull ByteBuf outBuffer);
 }
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPolymorphicEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPolymorphicEntrySerializer.java
new file mode 100644 (file)
index 0000000..e380dbc
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import static java.util.Objects.requireNonNull;
+
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
+
+/**
+ * Abstract base AbstractMatchEntrySerializer to deal with IPv4/IPv6 source/destination polymorphism.
+ */
+abstract class AbstractPolymorphicEntrySerializer<A extends Layer3Match, N extends Layer3Match, E, M>
+        extends AbstractMatchEntrySerializer<Object, Object> {
+    private final Class<A> arbitraryClass;
+    private final Class<N> normalClass;
+    private final Class<E> entryClass;
+    private final Class<M> arbitraryMaskClass;
+
+    AbstractPolymorphicEntrySerializer(final int oxmClassCode, final int oxmFieldCode, final int valueLength,
+            final Class<A> arbitraryClass, final Class<N> normalClass, final Class<E> entryClass,
+            final Class<M> arbitraryMaskClass) {
+        super(new ConstantHeaderWriter<>(oxmClassCode, oxmFieldCode, valueLength));
+        this.arbitraryClass = requireNonNull(arbitraryClass);
+        this.normalClass = requireNonNull(normalClass);
+        this.entryClass = requireNonNull(entryClass);
+        this.arbitraryMaskClass = requireNonNull(arbitraryMaskClass);
+    }
+
+    @Override
+    protected final Object extractEntry(final Match match) {
+        final Layer3Match layer3Match = match.getLayer3Match();
+        if (normalClass.isInstance(layer3Match)) {
+            return extractNormalEntry(normalClass.cast(layer3Match));
+        } else if (arbitraryClass.isInstance(layer3Match) && useArbitraryEntry(arbitraryClass.cast(layer3Match))) {
+            return layer3Match;
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    protected final Object extractEntryMask(final Object entry) {
+        if (arbitraryClass.isInstance(entry)) {
+            return extractArbitraryEntryMask(arbitraryClass.cast(entry));
+        }
+        return extractNormalEntryMask(entryClass.cast(entry));
+    }
+
+    @Override
+    protected final void serializeEntry(final Object entry, final Object mask, final ByteBuf outBuffer) {
+        if (entryClass.isInstance(entry)) {
+            serializeNormalEntry(entryClass.cast(entry), (Integer) mask, outBuffer);
+        } else {
+            serializeArbitraryEntry(arbitraryClass.cast(entry), arbitraryMaskClass.cast(mask), outBuffer);
+        }
+    }
+
+    abstract boolean useArbitraryEntry(@NonNull A arbitraryMatch);
+
+    abstract @Nullable E extractNormalEntry(@NonNull N normalMatch);
+
+    abstract @Nullable M extractArbitraryEntryMask(@NonNull A arbitraryMatch);
+
+    abstract @Nullable Integer extractNormalEntryMask(@NonNull E entry);
+
+    abstract void serializeArbitraryEntry(@NonNull A arbitraryMatch, @Nullable M mask, @NonNull ByteBuf outBuffer);
+
+    abstract void serializeNormalEntry(@NonNull E entry, @Nullable Integer mask, @NonNull ByteBuf outBuffer);
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPortNumberEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPortNumberEntrySerializer.java
new file mode 100644 (file)
index 0000000..d8f6fa5
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yangtools.yang.common.Uint16;
+
+public abstract class AbstractPortNumberEntrySerializer extends AbstractUint16EntrySerializer {
+    protected AbstractPortNumberEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode);
+    }
+
+    @Override
+    protected final Uint16 extractEntry(final Match match) {
+        final PortNumber port = extractPort(match);
+        return port == null ? null : port.getValue();
+    }
+
+    protected abstract @Nullable PortNumber extractPort(Match match);
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPrimitiveEntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractPrimitiveEntrySerializer.java
new file mode 100644 (file)
index 0000000..9992c21
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+
+public abstract class AbstractPrimitiveEntrySerializer<E> extends AbstractMatchEntrySerializer<E, Void> {
+    protected AbstractPrimitiveEntrySerializer(final HeaderWriter<E, Void> headerWriter) {
+        super(headerWriter);
+    }
+
+    protected AbstractPrimitiveEntrySerializer(final int oxmClassCode, final int oxmFieldCode, final int valueLength) {
+        super(oxmClassCode, oxmFieldCode, valueLength);
+    }
+
+    @Override
+    protected final Void extractEntryMask(final E entry) {
+        return null;
+    }
+
+    @Override
+    protected final void serializeEntry(final E entry, final Void mask, final ByteBuf outBuffer) {
+        serializeEntry(entry, outBuffer);
+    }
+
+    protected abstract void serializeEntry(@NonNull E entry, @NonNull ByteBuf outBuffer);
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint16EntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint16EntrySerializer.java
new file mode 100644 (file)
index 0000000..0daf164
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yangtools.yang.common.Uint16;
+
+public abstract class AbstractUint16EntrySerializer extends AbstractPrimitiveEntrySerializer<Uint16> {
+    protected AbstractUint16EntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+    }
+
+    @Override
+    protected final void serializeEntry(final Uint16 entry, final ByteBuf outBuffer) {
+        outBuffer.writeShort(entry.shortValue());
+    }
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint32EntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint32EntrySerializer.java
new file mode 100644 (file)
index 0000000..8aa5547
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+public abstract class AbstractUint32EntrySerializer extends AbstractPrimitiveEntrySerializer<Uint32> {
+    protected AbstractUint32EntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_INT_IN_BYTES);
+    }
+
+    @Override
+    protected final void serializeEntry(final Uint32 entry, final ByteBuf outBuffer) {
+        outBuffer.writeInt(entry.intValue());
+    }
+}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint8EntrySerializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/match/AbstractUint8EntrySerializer.java
new file mode 100644 (file)
index 0000000..8cf002f
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+public abstract class AbstractUint8EntrySerializer extends AbstractPrimitiveEntrySerializer<Uint8> {
+    protected AbstractUint8EntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
+        super(oxmClassCode, oxmFieldCode, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
+    }
+
+    @Override
+    protected final void serializeEntry(final Uint8 entry, final ByteBuf outBuffer) {
+        outBuffer.writeByte(entry.byteValue());
+    }
+}
index 7766fe199fdba157853b1a2356dc96d79b79222d..4013635b1f8cdfd2fa464ee17a6df654cd572a71 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
-public class ArpOpEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((ArpMatch) match.getLayer3Match()).getArpOp().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof ArpMatch
-                && ((ArpMatch) match.getLayer3Match()).getArpOp() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ARP_OP;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class ArpOpEntrySerializer extends AbstractUint16EntrySerializer {
+    public ArpOpEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected Uint16 extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof ArpMatch ? ((ArpMatch) l3Match).getArpOp() : null;
     }
 }
index c500aca34e9c274c5c34f9e2a8ab1aea268ab0a1..6cb3ade9f64125bf7ad0be4f6aee5d444f09b459 100644 (file)
@@ -7,56 +7,21 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
 
-public class ArpSourceHardwareAddressEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final ArpSourceHardwareAddress arpSourceHardwareAddress =
-                ((ArpMatch) match.getLayer3Match()).getArpSourceHardwareAddress();
-        writeMacAddress(arpSourceHardwareAddress.getAddress(), outBuffer);
-
-        if (getHasMask(match)) {
-            writeMask(ByteBufUtils.macAddressToBytes(
-                    arpSourceHardwareAddress.getMask().getValue()),
-                    outBuffer,
-                    getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof ArpMatch
-                && ((ArpMatch) match.getLayer3Match()).getArpSourceHardwareAddress() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return ((ArpMatch) match.getLayer3Match()).getArpSourceHardwareAddress().getMask() != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ARP_SHA;
+public class ArpSourceHardwareAddressEntrySerializer
+        extends AbstractMacAddressFilterEntrySerializer<ArpSourceHardwareAddress> {
+    public ArpSourceHardwareAddressEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SHA);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected ArpSourceHardwareAddress extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof ArpMatch ? ((ArpMatch) l3Match).getArpSourceHardwareAddress() : null;
     }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
-    }
-
 }
index 57a60c9587f53c9a63b547a475f3544f53cda12e..a0726117d8a4fdf39a697501d50f0080ac2849af 100644 (file)
@@ -7,46 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
 
-public class ArpSourceTransportAddressEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeIpv4Prefix(((ArpMatch) match.getLayer3Match()).getArpSourceTransportAddress(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof ArpMatch
-                && ((ArpMatch) match.getLayer3Match()).getArpSourceTransportAddress() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return IpConversionUtil.hasIpv4Prefix(((ArpMatch) match.getLayer3Match()).getArpSourceTransportAddress())
-                != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ARP_SPA;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class ArpSourceTransportAddressEntrySerializer extends AbstractIpv4PrefixEntrySerializer {
+    public ArpSourceTransportAddressEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SPA);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected Ipv4Prefix extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof ArpMatch ? ((ArpMatch) l3Match).getArpSourceTransportAddress() : null;
     }
 }
index 08e545abfb165b1ede5c4ca287a627420a3b2854..df3ee77136e4573182f15bac656111046824fc45 100644 (file)
@@ -7,55 +7,22 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
 
-public class ArpTargetHardwareAddressEntrySerializer extends AbstractMatchEntrySerializer {
+public class ArpTargetHardwareAddressEntrySerializer
+        extends AbstractMacAddressFilterEntrySerializer<ArpTargetHardwareAddress> {
 
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final ArpTargetHardwareAddress arpTargetHardwareAddress =
-                ((ArpMatch) match.getLayer3Match()).getArpTargetHardwareAddress();
-        writeMacAddress(arpTargetHardwareAddress.getAddress(), outBuffer);
-
-        if (getHasMask(match)) {
-            writeMask(ByteBufUtils.macAddressToBytes(
-                    arpTargetHardwareAddress.getMask().getValue()),
-                    outBuffer,
-                    getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof ArpMatch
-                && ((ArpMatch) match.getLayer3Match()).getArpTargetHardwareAddress() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return ((ArpMatch) match.getLayer3Match()).getArpTargetHardwareAddress().getMask() != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ARP_THA;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    public ArpTargetHardwareAddressEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_THA);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
+    protected ArpTargetHardwareAddress extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof ArpMatch ? ((ArpMatch) l3Match).getArpTargetHardwareAddress() : null;
     }
 }
index f88267553faaa3cb67be6b9db7a9e38b5fe8e41f..d34f49eae81ed909eeeda4765a98ceec72d90287 100644 (file)
@@ -7,46 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
 
-public class ArpTargetTransportAddressEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeIpv4Prefix(((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof ArpMatch
-                && ((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return IpConversionUtil.hasIpv4Prefix(((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress())
-                != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ARP_TPA;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class ArpTargetTransportAddressEntrySerializer extends AbstractIpv4PrefixEntrySerializer {
+    public ArpTargetTransportAddressEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_TPA);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected Ipv4Prefix extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof ArpMatch ? ((ArpMatch) l3Match).getArpTargetTransportAddress() : null;
     }
 }
index c3182a311bdcdcd3e9efb421747483cb9f89da19..9d47034ab52128382101f4776b96f6c6815b6dfb 100644 (file)
@@ -7,49 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
 
-public class EthernetDestinationEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeMacAddress(match.getEthernetMatch().getEthernetDestination().getAddress(), outBuffer);
-
-        if (getHasMask(match)) {
-            writeMask(ByteBufUtils.macAddressToBytes(
-                    match.getEthernetMatch().getEthernetDestination().getMask().getValue()),
-                    outBuffer,
-                    getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getEthernetMatch() != null && match.getEthernetMatch().getEthernetDestination() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return match.getEthernetMatch().getEthernetDestination().getMask() != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ETH_DST;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class EthernetDestinationEntrySerializer extends AbstractMacAddressFilterEntrySerializer<EthernetDestination> {
+    public EthernetDestinationEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_DST);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
+    protected EthernetDestination extractEntry(final Match match) {
+        final EthernetMatch ethMatch = match.getEthernetMatch();
+        return ethMatch == null ? null : ethMatch.getEthernetDestination();
     }
 }
index e8fb86ef0ec65a83bd1b40552c2e6ed7ac9eb400..b915b2d7f0b95ed969d61b9fa98e08679a3e8738 100644 (file)
@@ -7,49 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
 
-public class EthernetSourceEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeMacAddress(match.getEthernetMatch().getEthernetSource().getAddress(), outBuffer);
-
-        if (getHasMask(match)) {
-            writeMask(ByteBufUtils.macAddressToBytes(
-                    match.getEthernetMatch().getEthernetSource().getMask().getValue()),
-                    outBuffer,
-                    getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getEthernetMatch() != null && match.getEthernetMatch().getEthernetSource() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return match.getEthernetMatch().getEthernetSource().getMask() != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ETH_SRC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class EthernetSourceEntrySerializer extends AbstractMacAddressFilterEntrySerializer<EthernetSource> {
+    public EthernetSourceEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_SRC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
+    protected EthernetSource extractEntry(final Match match) {
+        final EthernetMatch ethMatch = match.getEthernetMatch();
+        return ethMatch == null ? null : ethMatch.getEthernetSource();
     }
 }
index 0581d42beac844e6fe65339cb62d5cda33321006..621748440ac556ea34e2c87d650ec22772e6b6e7 100644 (file)
@@ -12,37 +12,23 @@ import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
 
-public class EthernetTypeEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(match.getEthernetMatch().getEthernetType().getType().getValue().shortValue());
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getEthernetMatch() != null && match.getEthernetMatch().getEthernetType() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ETH_TYPE;
+public class EthernetTypeEntrySerializer extends AbstractPrimitiveEntrySerializer<EthernetType> {
+    public EthernetTypeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_TYPE,
+            EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected EthernetType extractEntry(final Match match) {
+        final EthernetMatch ethMatch = match.getEthernetMatch();
+        return ethMatch == null ? null : ethMatch.getEthernetType();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected void serializeEntry(final EthernetType entry, final ByteBuf outBuffer) {
+        outBuffer.writeShort(entry.getType().getValue().shortValue());
     }
 }
index f9d26208b05e83b00f41d844f2b33b5bd9e4593b..76a98729f33156bfaa1060c855226f34cabdf746 100644 (file)
@@ -7,41 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class Icmpv4CodeEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIcmpv4Match().getIcmpv4Code().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIcmpv4Match() != null && match.getIcmpv4Match().getIcmpv4Code() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ICMPV4_CODE;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class Icmpv4CodeEntrySerializer extends AbstractUint8EntrySerializer {
+    public Icmpv4CodeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_CODE);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected Uint8 extractEntry(final Match match) {
+        final Icmpv4Match icmpMatch = match.getIcmpv4Match();
+        return icmpMatch == null ? null : icmpMatch.getIcmpv4Code();
     }
 }
index e2a8f2fefbfdfa910ff192a24c9a7adccd5bfa14..1bece0fbeab912b8ca60bb9d0ec477b0c2db35e8 100644 (file)
@@ -5,45 +5,21 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class Icmpv4TypeEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIcmpv4Match().getIcmpv4Type().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIcmpv4Match() != null && match.getIcmpv4Match().getIcmpv4Type() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ICMPV4_TYPE;
+public class Icmpv4TypeEntrySerializer extends AbstractUint8EntrySerializer {
+    public Icmpv4TypeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_TYPE);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected Uint8 extractEntry(final Match match) {
+        final Icmpv4Match icmpMatch = match.getIcmpv4Match();
+        return icmpMatch == null ? null : icmpMatch.getIcmpv4Type();
     }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
-    }
-
 }
index ad5758c920deec944159be9a2674e90ea1436c87..c3a9b78f69113738fbde781c534b186401d9d211 100644 (file)
@@ -7,41 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class Icmpv6CodeEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIcmpv6Match().getIcmpv6Code().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIcmpv6Match() != null && match.getIcmpv6Match().getIcmpv6Code() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ICMPV6_CODE;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class Icmpv6CodeEntrySerializer extends AbstractUint8EntrySerializer {
+    public Icmpv6CodeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_CODE);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected Uint8 extractEntry(final Match match) {
+        final Icmpv6Match icmpMatch = match.getIcmpv6Match();
+        return icmpMatch == null ? null : icmpMatch.getIcmpv6Code();
     }
 }
index 053957bf714f8770866056189725d9f383fb7266..a59bd71c04af8a00607071a2877f0232d6ab3764 100644 (file)
@@ -7,41 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class Icmpv6TypeEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIcmpv6Match().getIcmpv6Type().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIcmpv6Match() != null && match.getIcmpv6Match().getIcmpv6Type() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.ICMPV6_TYPE;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class Icmpv6TypeEntrySerializer extends AbstractUint8EntrySerializer {
+    public Icmpv6TypeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_TYPE);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected Uint8 extractEntry(final Match match) {
+        final Icmpv6Match icmpMatch = match.getIcmpv6Match();
+        return icmpMatch == null ? null : icmpMatch.getIcmpv6Type();
     }
 }
index ea2c77379b9308b31f6b0f8ecb9c962967470be9..90f8b9d09f3148a861d026709ae4bca2b004faa2 100644 (file)
@@ -12,40 +12,23 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 
-public class InPhyPortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeInt(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
-                OpenflowVersion.OF13,
-                match.getInPhyPort()).intValue());
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getInPhyPort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IN_PHY_PORT;
+public class InPhyPortEntrySerializer extends AbstractPrimitiveEntrySerializer<NodeConnectorId> {
+    public InPhyPortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PHY_PORT,
+            EncodeConstants.SIZE_OF_INT_IN_BYTES);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected NodeConnectorId extractEntry(final Match match) {
+        return match.getInPhyPort();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected void serializeEntry(final NodeConnectorId entry, final ByteBuf outBuffer) {
+        outBuffer.writeInt(
+            InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, entry).intValue());
     }
 }
index 3da5a892ba55368503fa26ff79bf06d02ed66d54..eb962010c9b4c559046152a90dcb118926fdc909 100644 (file)
@@ -12,45 +12,26 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
-public class InPortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        Uint32 value = InventoryDataServiceUtil.portNumberfromNodeConnectorId(
-                OpenflowVersion.OF13,
-                match.getInPort().getValue());
-        if (value == null) {
-            throw new IllegalArgumentException("Not a valid port number: " + match.getInPort().getValue());
-        }
-        outBuffer.writeInt(value.intValue());
+public class InPortEntrySerializer extends AbstractPrimitiveEntrySerializer<NodeConnectorId> {
+    public InPortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PORT,EncodeConstants.SIZE_OF_INT_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getInPort() != null;
+    protected NodeConnectorId extractEntry(final Match match) {
+        return match.getInPort();
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IN_PORT;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected void serializeEntry(final NodeConnectorId entry, final ByteBuf outBuffer) {
+        Uint32 value = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, entry.getValue());
+        if (value == null) {
+            throw new IllegalArgumentException("Not a valid port number: " + entry.getValue());
+        }
+        outBuffer.writeInt(value.intValue());
     }
 }
index 872315f17f9d0d80376807c83e9fae94e0478172..9581db25c7c2a600344f3d18b6b42734bcfae210 100644 (file)
@@ -5,45 +5,28 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
 
-public class IpDscpEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIpMatch().getIpDscp().getValue().toJava());
+public class IpDscpEntrySerializer extends AbstractPrimitiveEntrySerializer<Dscp> {
+    public IpDscpEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_DSCP, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIpMatch() != null && match.getIpMatch().getIpDscp() != null;
+    protected Dscp extractEntry(final Match match) {
+        final IpMatch ipMatch = match.getIpMatch();
+        return ipMatch == null ? null : ipMatch.getIpDscp();
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
+    protected void serializeEntry(final Dscp entry, final ByteBuf outBuffer) {
+        outBuffer.writeByte(entry.getValue().byteValue());
     }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IP_DSCP;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
-    }
-
 }
index b1dc4262a67e17c0251931051fe31a74cf9be957..535702ae7e68b12ef037360f79eecb05dcbe9fea 100644 (file)
@@ -7,42 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class IpEcnEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getIpMatch().getIpEcn().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIpMatch() != null && match.getIpMatch().getIpEcn() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
+public class IpEcnEntrySerializer extends AbstractUint8EntrySerializer {
+    public IpEcnEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_ECN);
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IP_ECN;
+    protected Uint8 extractEntry(final Match match) {
+        final IpMatch ipMatch = match.getIpMatch();
+        return ipMatch == null ? null : ipMatch.getIpEcn();
     }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
-    }
-
 }
index 18c9b99e253b1ca90f1dc8a83efe9969e7e535b9..537483ad7bf8b50a63d5b150087285b3e27fb797 100644 (file)
@@ -7,42 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class IpProtoEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        // TODO: What is getIpMatch().getIpProto()? Fix models probably
-        outBuffer.writeByte(match.getIpMatch().getIpProtocol().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getIpMatch() != null && match.getIpMatch().getIpProtocol() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IP_PROTO;
+public class IpProtoEntrySerializer extends AbstractUint8EntrySerializer {
+    public IpProtoEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_PROTO);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected Uint8 extractEntry(final Match match) {
+        // TODO: What is getIpMatch().getIpProto()? Fix models probably
+        final IpMatch ipMatch = match.getIpMatch();
+        return ipMatch == null ? null : ipMatch.getIpProtocol();
     }
 }
index 33d88a20b8ab40a04c1a3b3c5332a35a6ac2d810..b8030383126d3785527253020495a8b71cc27d7a 100644 (file)
@@ -7,78 +7,30 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask;
 
-public class Ipv4DestinationEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-
-        if (isPrefix(match)) {
-            writeIpv4Prefix(((Ipv4Match) match.getLayer3Match()).getIpv4Destination(), outBuffer);
-        } else if (isArbitrary(match)) {
-            final Ipv4MatchArbitraryBitMask ipv4 = (Ipv4MatchArbitraryBitMask) match.getLayer3Match();
-            writeIpv4Address(ipv4.getIpv4DestinationAddressNoMask(), outBuffer);
-
-            if (getHasMask(match)) {
-                writeMask(IpConversionUtil.convertArbitraryMaskToByteArray(ipv4.getIpv4DestinationArbitraryBitmask()),
-                        outBuffer,
-                        getValueLength());
-            }
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        if (isPrefix(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv4Match) match.getLayer3Match()).getIpv4Destination() != null;
-        } else if (isArbitrary(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv4MatchArbitraryBitMask) match.getLayer3Match()).getIpv4DestinationAddressNoMask() != null;
-        }
-
-        return false;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        if (isPrefix(match)) {
-            return IpConversionUtil.hasIpv4Prefix(((Ipv4Match) match.getLayer3Match()).getIpv4Destination()) != null;
-        } else if (isArbitrary(match)) {
-            return ((Ipv4MatchArbitraryBitMask) match.getLayer3Match()).getIpv4DestinationArbitraryBitmask() != null;
-        }
-
-        return false;
-    }
-
-    private static boolean isPrefix(Match match) {
-        return match.getLayer3Match() instanceof Ipv4Match;
-    }
-
-    private static boolean isArbitrary(Match match) {
-        return match.getLayer3Match() instanceof Ipv4MatchArbitraryBitMask;
+public class Ipv4DestinationEntrySerializer extends AbstractIpv4PolymorphicEntrySerializer {
+    public Ipv4DestinationEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_DST);
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV4_DST;
+    Ipv4Prefix extractNormalEntry(final Ipv4Match normalMatch) {
+        return normalMatch.getIpv4Destination();
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    DottedQuad extractArbitraryEntryMask(final Ipv4MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv4DestinationArbitraryBitmask();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    Ipv4Address extractArbitraryEntryAddress(final Ipv4MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv4DestinationAddressNoMask();
     }
 }
index 2fe043f6257caeef7d7e6f7428c4685d4a20f858..702073fa00e628a9efe2021555582d5e018a7b6a 100644 (file)
@@ -7,78 +7,30 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask;
 
-public class Ipv4SourceEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-
-        if (isPrefix(match)) {
-            writeIpv4Prefix(((Ipv4Match) match.getLayer3Match()).getIpv4Source(), outBuffer);
-        } else if (isArbitrary(match)) {
-            final Ipv4MatchArbitraryBitMask ipv4 = (Ipv4MatchArbitraryBitMask) match.getLayer3Match();
-            writeIpv4Address(ipv4.getIpv4SourceAddressNoMask(), outBuffer);
-
-            if (getHasMask(match)) {
-                writeMask(IpConversionUtil.convertArbitraryMaskToByteArray(ipv4.getIpv4SourceArbitraryBitmask()),
-                        outBuffer,
-                        getValueLength());
-            }
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        if (isPrefix(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv4Match) match.getLayer3Match()).getIpv4Source() != null;
-        } else if (isArbitrary(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv4MatchArbitraryBitMask) match.getLayer3Match()).getIpv4SourceAddressNoMask() != null;
-        }
-
-        return false;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        if (isPrefix(match)) {
-            return IpConversionUtil.hasIpv4Prefix(((Ipv4Match) match.getLayer3Match()).getIpv4Source()) != null;
-        } else if (isArbitrary(match)) {
-            return ((Ipv4MatchArbitraryBitMask) match.getLayer3Match()).getIpv4SourceArbitraryBitmask() != null;
-        }
-
-        return false;
-    }
-
-    private static boolean isPrefix(Match match) {
-        return match.getLayer3Match() instanceof Ipv4Match;
-    }
-
-    private static boolean isArbitrary(Match match) {
-        return match.getLayer3Match() instanceof Ipv4MatchArbitraryBitMask;
+public class Ipv4SourceEntrySerializer extends AbstractIpv4PolymorphicEntrySerializer {
+    public Ipv4SourceEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_SRC);
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV4_SRC;
+    Ipv4Prefix extractNormalEntry(final Ipv4Match normalMatch) {
+        return normalMatch.getIpv4Source();
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    Ipv4Address extractArbitraryEntryAddress(final Ipv4MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv4SourceAddressNoMask();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    DottedQuad extractArbitraryEntryMask(final Ipv4MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv4SourceArbitraryBitmask();
     }
 }
index 8afae89e67b9662718c723fd84059f74e95e0936..f06c09fe6fc8a0c3c4a50fbc653597ee4e9636ca 100644 (file)
@@ -7,82 +7,30 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
 
-public class Ipv6DestinationEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-
-        if (isPrefix(match)) {
-            writeIpv6Prefix(((Ipv6Match) match.getLayer3Match()).getIpv6Destination(), outBuffer);
-        } else if (isArbitrary(match)) {
-            final Ipv6MatchArbitraryBitMask ipv6 = (Ipv6MatchArbitraryBitMask) match.getLayer3Match();
-            writeIpv6Address(ipv6.getIpv6DestinationAddressNoMask(), outBuffer);
-
-            if (getHasMask(match)) {
-                writeMask(IpConversionUtil
-                                .convertIpv6ArbitraryMaskToByteArray(ipv6.getIpv6DestinationArbitraryBitmask()),
-                        outBuffer,
-                        getValueLength());
-            }
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        if (isPrefix(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv6Match) match.getLayer3Match()).getIpv6Destination() != null;
-        } else if (isArbitrary(match)) {
-            return match.getLayer3Match() != null
-                    && ((Ipv6MatchArbitraryBitMask) match.getLayer3Match()).getIpv6DestinationAddressNoMask() != null;
-        }
-
-        return false;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        if (isPrefix(match)) {
-            if (null != IpConversionUtil.hasIpv6Prefix(((Ipv6Match) match.getLayer3Match()).getIpv6Destination())) {
-                return IpConversionUtil.extractIpv6Prefix(
-                    ((Ipv6Match) match.getLayer3Match()).getIpv6Destination()) != null;
-            }
-        } else if (isArbitrary(match)) {
-            return ((Ipv6MatchArbitraryBitMask) match.getLayer3Match()).getIpv6DestinationArbitraryBitmask() != null;
-        }
-
-        return false;
-    }
-
-    private static boolean isPrefix(Match match) {
-        return match.getLayer3Match() instanceof Ipv6Match;
-    }
-
-    private static boolean isArbitrary(Match match) {
-        return match.getLayer3Match() instanceof Ipv6MatchArbitraryBitMask;
+public class Ipv6DestinationEntrySerializer extends AbstractIpv6PolymorphicEntrySerializer {
+    public Ipv6DestinationEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_DST);
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_DST;
+    Ipv6Prefix extractNormalEntry(final Ipv6Match normalMatch) {
+        return normalMatch.getIpv6Destination();
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    Ipv6Address extractArbitraryEntryAddress(final Ipv6MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv6DestinationAddressNoMask();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+    Ipv6ArbitraryMask extractArbitraryEntryMask(final Ipv6MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv6DestinationArbitraryBitmask();
     }
 }
index b4ca63697215e4571faa4ed2cfc6258baebdbfd1..a789b7fda050238d1c2ea86e2167f1a907487e95 100644 (file)
@@ -13,48 +13,32 @@ import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
-public class Ipv6ExtHeaderEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final Ipv6ExtHeader ipv6ExtHeader = ((Ipv6Match) match.getLayer3Match()).getIpv6ExtHeader();
-        outBuffer.writeShort(ipv6ExtHeader.getIpv6Exthdr().toJava());
-
-        if (getHasMask(match)) {
-            writeMask(ByteUtil.unsignedShortToBytes(
-                    ipv6ExtHeader.getIpv6ExthdrMask()),
-                    outBuffer,
-                    getValueLength());
-        }
+public class Ipv6ExtHeaderEntrySerializer extends AbstractMatchEntrySerializer<Ipv6ExtHeader, Uint16> {
+    public Ipv6ExtHeaderEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_EXTHDR,
+            EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof Ipv6Match
-                && ((Ipv6Match) match.getLayer3Match()).getIpv6ExtHeader() != null;
+    protected Ipv6ExtHeader extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6ExtHeader() : null;
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return ((Ipv6Match) match.getLayer3Match()).getIpv6ExtHeader().getIpv6ExthdrMask() != null;
+    protected Uint16 extractEntryMask(final Ipv6ExtHeader entry) {
+        return entry.getIpv6ExthdrMask();
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_EXTHDR;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected void serializeEntry(final Ipv6ExtHeader entry, final Uint16 mask, final ByteBuf outBuffer) {
+        outBuffer.writeShort(entry.getIpv6Exthdr().shortValue());
+        if (mask != null) {
+            writeMask(ByteUtil.unsignedShortToBytes(mask), outBuffer, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+        }
     }
 }
index a07902cdf7c3448d15f1628fa206bf9bd56cd4be..b8a1fd9a172e062ae520fd75a5708372189ed432 100644 (file)
@@ -11,50 +11,34 @@ import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 
-public class Ipv6LabelEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final Ipv6Label ipv6Label = ((Ipv6Match) match.getLayer3Match()).getIpv6Label();
-        outBuffer.writeInt(ipv6Label.getIpv6Flabel().getValue().intValue());
-
-        if (getHasMask(match)) {
-            writeMask(ByteUtil.unsignedIntToBytes(
-                    ipv6Label.getFlabelMask().getValue()),
-                    outBuffer,
-                    getValueLength());
-        }
+public class Ipv6LabelEntrySerializer extends AbstractMatchEntrySerializer<Ipv6Label, Ipv6FlowLabel> {
+    public Ipv6LabelEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_FLABEL,
+            EncodeConstants.SIZE_OF_INT_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof Ipv6Match
-                && ((Ipv6Match) match.getLayer3Match()).getIpv6Label() != null;
+    protected Ipv6Label extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6Label() : null;
     }
 
     @Override
-    protected boolean getHasMask(Match match) {
-        return ((Ipv6Match) match.getLayer3Match()).getIpv6Label().getFlabelMask() != null;
+    protected Ipv6FlowLabel extractEntryMask(final Ipv6Label entry) {
+        return entry.getFlabelMask();
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_FLABEL;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected void serializeEntry(final Ipv6Label entry, final Ipv6FlowLabel mask, final ByteBuf outBuffer) {
+        outBuffer.writeInt(entry.getIpv6Flabel().getValue().intValue());
+        if (mask != null) {
+            writeMask(ByteUtil.unsignedIntToBytes(mask.getValue()), outBuffer, EncodeConstants.SIZE_OF_INT_IN_BYTES);
+        }
     }
 }
index 20d51419c03c3ad78b831d5fe1216d723f8c761d..35b06f2b96515dc77b80d4d8b7e821101d9962c6 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 
-public class Ipv6NdSllEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeMacAddress(((Ipv6Match) match.getLayer3Match()).getIpv6NdSll(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof Ipv6Match
-                && ((Ipv6Match) match.getLayer3Match()).getIpv6NdSll() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_ND_SLL;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class Ipv6NdSllEntrySerializer extends AbstractMacAddressEntrySerializer {
+    public Ipv6NdSllEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_SLL);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
+    protected MacAddress extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6NdSll() : null;
     }
 }
index 4a81510f76e4ddfc31f41f62b76b8fb6f5dadbdf..351958083dc29f59438b2a0dc703fc6b060e057b 100644 (file)
@@ -10,41 +10,25 @@ package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 
-public class Ipv6NdTargetEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeIpv6Address(((Ipv6Match) match.getLayer3Match()).getIpv6NdTarget(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof Ipv6Match
-                && ((Ipv6Match) match.getLayer3Match()).getIpv6NdTarget() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_ND_TARGET;
+public class Ipv6NdTargetEntrySerializer extends AbstractPrimitiveEntrySerializer<Ipv6Address> {
+    public Ipv6NdTargetEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TARGET,
+            EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected Ipv6Address extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6NdTarget() : null;
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+    protected void serializeEntry(final Ipv6Address entry, final ByteBuf outBuffer) {
+        writeIpv6Address(entry, outBuffer);
     }
 }
index c579836c842d83dc574e7ec8a234fe474e939b97..4bf6f75464b54f94f6005df8996845b3bde81620 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 
-public class Ipv6NdTllEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        writeMacAddress(((Ipv6Match) match.getLayer3Match()).getIpv6NdTll(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof Ipv6Match
-                && ((Ipv6Match) match.getLayer3Match()).getIpv6NdTll() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_ND_TLL;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class Ipv6NdTllEntrySerializer extends AbstractMacAddressEntrySerializer {
+    public Ipv6NdTllEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TLL);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.MAC_ADDRESS_LENGTH;
+    protected MacAddress extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6NdTll() : null;
     }
 }
index 5af50a8e70ae16782861e87babe7d9d7dc92b309..9c5f5f7eed7e8b0c8f4c5e781efddaf7ea8079ef 100644 (file)
@@ -7,80 +7,30 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
 
-public class Ipv6SourceEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-
-        if (isPrefix(match)) {
-            writeIpv6Prefix(((Ipv6Match) match.getLayer3Match()).getIpv6Source(), outBuffer);
-        } else if (isArbitrary(match)) {
-            final Ipv6MatchArbitraryBitMask ipv6 = (Ipv6MatchArbitraryBitMask) match.getLayer3Match();
-            writeIpv6Address(ipv6.getIpv6SourceAddressNoMask(), outBuffer);
-
-            if (getHasMask(match)) {
-                writeMask(IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(ipv6.getIpv6SourceArbitraryBitmask()),
-                        outBuffer,
-                        getValueLength());
-            }
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        if (isPrefix(match)) {
-            return match.getLayer3Match() != null && ((Ipv6Match) match.getLayer3Match()).getIpv6Source() != null;
-        } else if (isArbitrary(match)) {
-
-            return match.getLayer3Match() != null
-                    && ((Ipv6MatchArbitraryBitMask) match.getLayer3Match()).getIpv6SourceAddressNoMask() != null;
-        }
-
-        return false;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        if (isPrefix(match)) {
-            if (null != IpConversionUtil.hasIpv6Prefix(((Ipv6Match) match.getLayer3Match()).getIpv6Source())) {
-                return IpConversionUtil.extractIpv6Prefix(((Ipv6Match) match.getLayer3Match()).getIpv6Source()) != null;
-            }
-        } else if (isArbitrary(match)) {
-            return ((Ipv6MatchArbitraryBitMask) match.getLayer3Match()).getIpv6SourceArbitraryBitmask() != null;
-        }
-
-        return false;
-    }
-
-    private static boolean isPrefix(Match match) {
-        return match.getLayer3Match() instanceof Ipv6Match;
-    }
-
-    private static boolean isArbitrary(Match match) {
-        return match.getLayer3Match() instanceof Ipv6MatchArbitraryBitMask;
+public class Ipv6SourceEntrySerializer extends AbstractIpv6PolymorphicEntrySerializer {
+    public Ipv6SourceEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_SRC);
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV6_SRC;
+    Ipv6Prefix extractNormalEntry(final Ipv6Match normalMatch) {
+        return normalMatch.getIpv6Source();
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    Ipv6Address extractArbitraryEntryAddress(final Ipv6MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv6SourceAddressNoMask();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+    Ipv6ArbitraryMask extractArbitraryEntryMask(final Ipv6MatchArbitraryBitMask arbitraryMatch) {
+        return arbitraryMatch.getIpv6SourceArbitraryBitmask();
     }
 }
index d9e1c8dcb9a90ee2ebc30a83fc229565fd9e753a..8586446f1006de9c3a3799886b2a11caaeec8651 100644 (file)
@@ -77,11 +77,7 @@ public class MatchSerializer implements OFSerializer<Match>, HeaderSerializer<Ma
         }
 
         // Serialize match entries
-        entryRegistry.forEach((key, value) -> {
-            if (value.matchTypeCheck(match)) {
-                value.serialize(match, outBuffer);
-            }
-        });
+        entryRegistry.values().forEach(value -> value.serializeIfPresent(match, outBuffer));
 
         // Serialize match extensions
         ExtensionResolvers
index 1f024a89d1632118556d37fd7c8fc66ace73c3aa..87fc469a0482b92d681d60ee429d26f4223cb8bb 100644 (file)
@@ -12,45 +12,30 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
-public class MetadataEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        // TODO: writeLong() should be faster
-        outBuffer.writeBytes(ByteUtil.uint64toBytes(match.getMetadata().getMetadata()));
-
-        if (getHasMask(match)) {
-            // TODO: writeLong() should be faster
-            writeMask(ByteUtil.uint64toBytes(match.getMetadata().getMetadataMask()),
-                    outBuffer,
-                    getValueLength());
-        }
+public class MetadataEntrySerializer extends AbstractMatchEntrySerializer<Metadata, Uint64> {
+    public MetadataEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.METADATA,
+            EncodeConstants.SIZE_OF_LONG_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getMetadata() != null;
+    protected Metadata extractEntry(Match match) {
+        return match.getMetadata();
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return match.getMetadata().getMetadataMask() != null;
+    protected Uint64 extractEntryMask(Metadata entry) {
+        return entry.getMetadataMask();
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.METADATA;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+    protected void serializeEntry(Metadata entry, Uint64 mask, ByteBuf outBuffer) {
+        outBuffer.writeBytes(ByteUtil.uint64toBytes(entry.getMetadata()));
+        if (mask != null) {
+            writeMask(ByteUtil.uint64toBytes(mask), outBuffer, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+        }
     }
 }
index 715fb5135cd0fa5915a4fc5327fcf43c1caaae57..45192ae4c44c9965b70d0f788bd2257796a85d60 100644 (file)
@@ -11,37 +11,23 @@ import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class MplsBosEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeBoolean(match.getProtocolMatchFields().getMplsBos().toJava() != 0);
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getProtocolMatchFields() != null && match.getProtocolMatchFields().getMplsBos() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.MPLS_BOS;
+public class MplsBosEntrySerializer extends AbstractPrimitiveEntrySerializer<Uint8> {
+    public MplsBosEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_BOS,
+            EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+    protected Uint8 extractEntry(final Match match) {
+        final ProtocolMatchFields protoFields = match.getProtocolMatchFields();
+        return protoFields == null ? null : protoFields.getMplsBos();
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected void serializeEntry(final Uint8 entry, final ByteBuf outBuffer) {
+        outBuffer.writeBoolean(entry.byteValue() != 0);
     }
 }
index 833d2238142be035a0ca096532a436a2cbd8b04f..4af3e5ff9ead68e648737af0879ab52d879abdb1 100644 (file)
@@ -7,41 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
-public class MplsLabelEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeInt(match.getProtocolMatchFields().getMplsLabel().intValue());
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getProtocolMatchFields() != null && match.getProtocolMatchFields().getMplsLabel() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.MPLS_LABEL;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class MplsLabelEntrySerializer extends AbstractUint32EntrySerializer {
+    public MplsLabelEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_LABEL);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected Uint32 extractEntry(final Match match) {
+        final ProtocolMatchFields protoFields = match.getProtocolMatchFields();
+        return protoFields == null ? null : protoFields.getMplsLabel();
     }
 }
index cac7e16a1987eccac587cacf91ca1dd58b316269..ece6280669c781e522f967f9b25eff5c2824f86d 100644 (file)
@@ -7,41 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-public class MplsTcEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getProtocolMatchFields().getMplsTc().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getProtocolMatchFields() != null && match.getProtocolMatchFields().getMplsTc() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.MPLS_TC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class MplsTcEntrySerializer extends AbstractUint8EntrySerializer {
+    public MplsTcEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_TC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+    protected Uint8 extractEntry(final Match match) {
+        final ProtocolMatchFields protoFields = match.getProtocolMatchFields();
+        return protoFields == null ? null : protoFields.getMplsTc();
     }
 }
index 7b1268b00c216dff99ef1dfb4b8ed55d8fff745a..78a676bc8c052f561b2032e3950ea7f59f32fc41 100644 (file)
@@ -7,40 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.PacketTypeMatch;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
-public class PacketTypeEntrySerializer extends AbstractMatchEntrySerializer {
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeInt(match.getPacketTypeMatch().getPacketType().intValue());
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.PACKET_TYPE;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+public class PacketTypeEntrySerializer extends AbstractUint32EntrySerializer {
+    public PacketTypeEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.PACKET_TYPE);
     }
 
     @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getPacketTypeMatch() != null && match.getPacketTypeMatch().getPacketType() != null;
+    protected Uint32 extractEntry(final Match match) {
+        final PacketTypeMatch typeMatch = match.getPacketTypeMatch();
+        return typeMatch == null ? null : typeMatch.getPacketType();
     }
 }
index 9f4d86d2362ccbf042bd4c5c29820555a6c185d6..32b8b5177c95531b58733f849e276078f50a31fb 100644 (file)
@@ -12,44 +12,31 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
-public class PbbEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeMedium(match.getProtocolMatchFields().getPbb().getPbbIsid().intValue());
-
-        if (getHasMask(match)) {
-            writeMask(ByteUtil.unsignedMediumToBytes(
-                    match.getProtocolMatchFields().getPbb().getPbbMask()),
-                    outBuffer,
-                    getValueLength());
-        }
+public class PbbEntrySerializer extends AbstractMatchEntrySerializer<Pbb, Uint32> {
+    public PbbEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.PBB_ISID, EncodeConstants.SIZE_OF_3_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getProtocolMatchFields() != null && match.getProtocolMatchFields().getPbb() != null;
+    protected Pbb extractEntry(Match match) {
+        final ProtocolMatchFields protoFields = match.getProtocolMatchFields();
+        return protoFields == null ? null : protoFields.getPbb();
     }
 
     @Override
-    protected boolean getHasMask(Match match) {
-        return match.getProtocolMatchFields().getPbb().getPbbMask() != null;
+    protected Uint32 extractEntryMask(Pbb entry) {
+        return entry.getPbbMask();
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.PBB_ISID;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_3_BYTES;
+    protected void serializeEntry(Pbb entry, Uint32 mask, ByteBuf outBuffer) {
+        outBuffer.writeMedium(entry.getPbbIsid().intValue());
+        if (mask != null) {
+            writeMask(ByteUtil.unsignedMediumToBytes(mask), outBuffer, EncodeConstants.SIZE_OF_3_BYTES);
+        }
     }
 }
index 0b36f6cda3f012e3a68872c01d1abee0ab75fb5d..9d5cd756ee978c3706e60ef1e0c7981f461c2ac4 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
 
-public class SctpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((SctpMatch) match.getLayer4Match()).getSctpDestinationPort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof SctpMatch
-                && ((SctpMatch) match.getLayer4Match()).getSctpDestinationPort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.SCTP_DST;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class SctpDestinationPortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public SctpDestinationPortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_DST);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof SctpMatch ? ((SctpMatch) l4match).getSctpDestinationPort() : null;
     }
 }
index 36b25d96751660991e9c73dd9f691e17f2b12cde..8e67c52ea5a1226a6b028a04074b8962e4c815a9 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
 
-public class SctpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((SctpMatch) match.getLayer4Match()).getSctpSourcePort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof SctpMatch
-                && ((SctpMatch) match.getLayer4Match()).getSctpSourcePort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.SCTP_SRC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class SctpSourcePortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public SctpSourcePortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_SRC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof SctpMatch ? ((SctpMatch) l4match).getSctpSourcePort() : null;
     }
 }
index 312082709cbf58c6c81587ee062994789740c5f2..107b512ad35173a3b8b9f3aa3275636c1c4cba21 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
 
-public class TcpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((TcpMatch) match.getLayer4Match()).getTcpDestinationPort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof TcpMatch
-                && ((TcpMatch) match.getLayer4Match()).getTcpDestinationPort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.TCP_DST;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class TcpDestinationPortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public TcpDestinationPortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_DST);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof TcpMatch ? ((TcpMatch) l4match).getTcpDestinationPort() : null;
     }
 }
index 20cb3700478ddf981b0ee568f55d78bae9bf393c..74e7d9dde6d86eb106fc74afb66fc928c1d39044 100644 (file)
@@ -5,57 +5,37 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
-public class TcpFlagsEntrySerializer extends AbstractExperimenterMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(match.getTcpFlagsMatch().getTcpFlags().toJava());
-
-        if (getHasMask(match)) {
-            writeMask(ByteUtil.unsignedShortToBytes(
-                    match.getTcpFlagsMatch().getTcpFlagsMask()),
-                    outBuffer,
-                    getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getTcpFlagsMatch() != null && match.getTcpFlagsMatch().getTcpFlags() != null;
+public class TcpFlagsEntrySerializer extends AbstractExperimenterMatchEntrySerializer<TcpFlagsMatch, Uint16> {
+    public TcpFlagsEntrySerializer() {
+        super(EncodeConstants.ONFOXM_ET_TCP_FLAGS, EncodeConstants.SIZE_OF_SHORT_IN_BYTES,
+            EncodeConstants.ONF_EXPERIMENTER_ID.toJava());
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return match.getTcpFlagsMatch().getTcpFlagsMask() != null;
+    protected TcpFlagsMatch extractEntry(Match match) {
+        final TcpFlagsMatch flagsMatch = match.getTcpFlagsMatch();
+        return flagsMatch == null || flagsMatch.getTcpFlags() == null ? null : flagsMatch;
     }
 
     @Override
-    protected long getExperimenterId() {
-        return EncodeConstants.ONF_EXPERIMENTER_ID.toJava();
+    protected Uint16 extractEntryMask(TcpFlagsMatch entry) {
+        return entry.getTcpFlagsMask();
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return EncodeConstants.ONFOXM_ET_TCP_FLAGS;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.EXPERIMENTER_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected void serializeEntryContent(TcpFlagsMatch entry, Uint16 mask, ByteBuf outBuffer) {
+        outBuffer.writeShort(entry.getTcpFlags().shortValue());
+        if (mask != null) {
+            writeMask(ByteUtil.unsignedShortToBytes(mask), outBuffer, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+        }
     }
 }
index 2eb35a8d4b3d3da07e226744c832f9c431284d3e..2fdfb93c0937d1ddb9cf96b6321edfd00553edb3 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
 
-public class TcpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((TcpMatch) match.getLayer4Match()).getTcpSourcePort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof TcpMatch
-                && ((TcpMatch) match.getLayer4Match()).getTcpSourcePort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.TCP_SRC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class TcpSourcePortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public TcpSourcePortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_SRC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof TcpMatch ? ((TcpMatch) l4match).getTcpSourcePort() : null;
     }
 }
index a3c753aed68c45c4da79cdfb50db1720167f0a6c..7eda87076838f8b07bf3b9e693725322514875fe 100644 (file)
@@ -12,41 +12,31 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
-public class TunnelIdEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        // TODO: writeLong() should be faster
-        outBuffer.writeBytes(ByteUtil.uint64toBytes(match.getTunnel().getTunnelId()));
-        if (getHasMask(match)) {
-            writeMask(ByteUtil.uint64toBytes(match.getTunnel().getTunnelMask()), outBuffer, getValueLength());
-        }
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getTunnel() != null && match.getTunnel().getTunnelId() != null;
+public class TunnelIdEntrySerializer extends AbstractMatchEntrySerializer<Tunnel, Uint64> {
+    public TunnelIdEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TUNNEL_ID,
+            EncodeConstants.SIZE_OF_LONG_IN_BYTES);
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return match.getTunnel().getTunnelMask() != null;
+    protected Tunnel extractEntry(Match match) {
+        final Tunnel tunnel = match.getTunnel();
+        return tunnel == null || tunnel.getTunnelId() == null ? null : tunnel;
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.TUNNEL_ID;
+    protected Uint64 extractEntryMask(Tunnel entry) {
+        return entry.getTunnelMask();
     }
 
     @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+    protected void serializeEntry(Tunnel entry, Uint64 mask, ByteBuf outBuffer) {
+        outBuffer.writeBytes(ByteUtil.uint64toBytes(entry.getTunnelId()));
+        if (mask != null) {
+            writeMask(ByteUtil.uint64toBytes(mask), outBuffer, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+        }
     }
 }
index 5f073dbcf4dab6d760ad0fcca6e757ebda9cb47c..bad84e3afb4209e91e32fd8953c61aebb0945271 100644 (file)
@@ -7,47 +7,21 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
 
-public class TunnelIpv4DestinationEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        // TODO: Why is this serialization exactly same as in Ipv4DestinationEntrySerializer?
-        writeIpv4Prefix(((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Destination(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof TunnelIpv4Match
-                && ((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Destination() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return IpConversionUtil.hasIpv4Prefix(((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Destination())
-                != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV4_DST;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+// TODO: Why is this serialization exactly same as in Ipv4DestinationEntrySerializer?
+public class TunnelIpv4DestinationEntrySerializer extends AbstractIpv4PrefixEntrySerializer {
+    public TunnelIpv4DestinationEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_DST);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected Ipv4Prefix extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof TunnelIpv4Match ? ((TunnelIpv4Match) l3Match).getTunnelIpv4Destination() : null;
     }
 }
index 9e0220fb28e7cedfa8cf11fc20c2b5f265293025..58268ce60b72c69ead66ab7f07dbae00ddbad739 100644 (file)
@@ -7,46 +7,21 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
 
-public class TunnelIpv4SourceEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        // TODO: Why is this serialization exactly same as in Ipv4SourceEntrySerializer?
-        writeIpv4Prefix(((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Source(), outBuffer);
-    }
-
-    @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getLayer3Match() != null
-                && match.getLayer3Match() instanceof TunnelIpv4Match
-                && ((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Source() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(Match match) {
-        return IpConversionUtil.hasIpv4Prefix(((TunnelIpv4Match) match.getLayer3Match()).getTunnelIpv4Source()) != null;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.IPV4_SRC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+// TODO: Why is this serialization exactly same as in Ipv4SourceEntrySerializer?
+public class TunnelIpv4SourceEntrySerializer extends AbstractIpv4PrefixEntrySerializer {
+    public TunnelIpv4SourceEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_SRC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+    protected Ipv4Prefix extractEntry(final Match match) {
+        final Layer3Match l3Match = match.getLayer3Match();
+        return l3Match instanceof TunnelIpv4Match ? ((TunnelIpv4Match) l3Match).getTunnelIpv4Source() : null;
     }
 }
index 627e9644d8df0ecd177d67b092dc3485c97c752d..4190c24c31944721672a9bd056a894af1d5e37e4 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
 
-public class UdpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((UdpMatch) match.getLayer4Match()).getUdpDestinationPort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof UdpMatch
-                && ((UdpMatch) match.getLayer4Match()).getUdpDestinationPort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.UDP_DST;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class UdpDestinationPortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public UdpDestinationPortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_DST);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof UdpMatch ? ((UdpMatch) l4match).getUdpDestinationPort() : null;
     }
 }
index 2f12572fbfdb84c29a074440d99bbb28ad3852cc..0c92163468109e28b23515d4509a7fdba57283b6 100644 (file)
@@ -7,44 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
 
-public class UdpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeShort(((UdpMatch) match.getLayer4Match()).getUdpSourcePort().getValue().toJava());
-    }
-
-    @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getLayer4Match() != null
-                && match.getLayer4Match() instanceof UdpMatch
-                && ((UdpMatch) match.getLayer4Match()).getUdpSourcePort() != null;
-    }
-
-    @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
-    }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.UDP_SRC;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+public class UdpSourcePortEntrySerializer extends AbstractPortNumberEntrySerializer {
+    public UdpSourcePortEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_SRC);
     }
 
     @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+    protected PortNumber extractPort(final Match match) {
+        final Layer4Match l4match = match.getLayer4Match();
+        return l4match instanceof UdpMatch ? ((UdpMatch) l4match).getUdpSourcePort() : null;
     }
 }
index 519438c79da713d49491b8a1678c335b9eda811c..1b30ab3211de3a829fbafb77ed5c40cdbd7f4d29 100644 (file)
@@ -5,45 +5,29 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
 
-public class VlanPcpEntrySerializer extends AbstractMatchEntrySerializer {
-
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        outBuffer.writeByte(match.getVlanMatch().getVlanPcp().getValue().toJava());
+public class VlanPcpEntrySerializer extends AbstractPrimitiveEntrySerializer<VlanPcp> {
+    public VlanPcpEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_PCP,
+            EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getVlanMatch() != null && match.getVlanMatch().getVlanPcp() != null;
+    protected VlanPcp extractEntry(final Match match) {
+        final VlanMatch vlanMatch = match.getVlanMatch();
+        return vlanMatch == null ? null : vlanMatch.getVlanPcp();
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        return false;
+    protected void serializeEntry(final VlanPcp entry, final ByteBuf outBuffer) {
+        outBuffer.writeByte(entry.getValue().byteValue());
     }
-
-    @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.VLAN_PCP;
-    }
-
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
-
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
-    }
-
 }
index e053c12b353933b5b9c3514c85b778ce60b7cdef..8be40e504a5ce258e3bb99cfb8066d265f57d6ed 100644 (file)
@@ -11,55 +11,45 @@ import io.netty.buffer.ByteBuf;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
+import org.opendaylight.yangtools.yang.common.Empty;
 
-public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer {
+public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer<VlanId, Empty> {
     private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
 
-    @Override
-    public void serialize(final Match match, final ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId =
-                match.getVlanMatch().getVlanId().getVlanId();
-
-        int vlanVidValue = vlanId != null ? vlanId.getValue().toJava() : 0;
-
-        if (Boolean.TRUE.equals(match.getVlanMatch().getVlanId().isVlanIdPresent())) {
-            short cfi = 1 << 12;
-            vlanVidValue = vlanVidValue | cfi;
-        }
-
-        outBuffer.writeShort(vlanVidValue);
-
-        if (getHasMask(match)) {
-            writeMask(VLAN_VID_MASK, outBuffer, getValueLength());
-        }
+    public VlanVidEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_VID,
+            EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(final Match match) {
-        return match.getVlanMatch() != null && match.getVlanMatch().getVlanId() != null;
+    protected VlanId extractEntry(Match match) {
+        final VlanMatch vlanMatch = match.getVlanMatch();
+        return vlanMatch == null ? null : vlanMatch.getVlanId();
     }
 
     @Override
-    protected boolean getHasMask(final Match match) {
-        final VlanId vlanId = match.getVlanMatch().getVlanId();
-        return Boolean.TRUE.equals(vlanId.isVlanIdPresent())
-                && (vlanId.getVlanId() == null || vlanId.getVlanId().getValue().toJava() == 0);
+    protected Empty extractEntryMask(VlanId entry) {
+        return Boolean.TRUE.equals(entry.isVlanIdPresent())
+                && (entry.getVlanId() == null || entry.getVlanId().getValue().shortValue() == 0) ? Empty.getInstance()
+                        : null;
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.VLAN_VID;
-    }
+    protected void serializeEntry(VlanId entry, Empty mask, ByteBuf outBuffer) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId = entry.getVlanId();
 
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
+        int vlanVidValue = vlanId != null ? vlanId.getValue().toJava() : 0;
 
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+        if (Boolean.TRUE.equals(entry.isVlanIdPresent())) {
+            short cfi = 1 << 12;
+            vlanVidValue = vlanVidValue | cfi;
+        }
+        outBuffer.writeShort(vlanVidValue);
+
+        if (mask != null) {
+            writeMask(VLAN_VID_MASK, outBuffer, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+        }
     }
 }
index 564f24122224f737a7b653ed97e45b6fa31ceff2..7dc896f3633c88841f78f8a1259d1d76a44f8838 100644 (file)
@@ -78,7 +78,7 @@ public final class IpConversionUtil {
         final DottedQuad[] quads = new DottedQuad[IPV4_ADDRESS_LENGTH + 1];
 
         for (int i = 0; i <= IPV4_ADDRESS_LENGTH; ++i) {
-            final int maskBits = (int) (0xffffffffL << IPV4_ADDRESS_LENGTH - i);
+            final int maskBits = maskForIpv4Prefix(i);
             quads[i] = new DottedQuad(new StringBuilder(15)
                 .append(maskBits >>> 24).append('.')
                 .append(maskBits >>> 16 & 0xff).append('.')
@@ -236,6 +236,10 @@ public final class IpConversionUtil {
         return prefix != null && prefix < addressLength ? prefix : null;
     }
 
+    public static int maskForIpv4Prefix(final int prefixLength) {
+        return (int) (0xffffffffL << IPV4_ADDRESS_LENGTH - prefixLength);
+    }
+
     /*
      * BIG FAT WARNING!!!
      * Read all of the following before you touch any v6 code or decide to