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)
commit25112035c416cf177626b7030edf9e890ce26ceb
tree8541b065b42e16b3bad49a24e0414dfaa39bf12f
parentc48e6882b7a8b6d60abbb924b8198cd5aa4885ed
Rework MatchEntrySerializer

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