Inject match entry serializers into MatchSerializer.
These serializers will serialize these entries to raw bytes:
- EthernetDestination
- EthernetSource
- EthernetType
- InPhyPort
- InPort
- Metadata
- VlanPcp
- VlanVid
- IpDscp
- IpEcn
- IpProto
- TcpSource
- TcpDestination
- UdpSource
- UdpDestination
- SctpSource
- SctpDestination
- Icmpv4Type
- Icmpv4Code
- Icmpv6Type
- Icmpv6Code
- Ipv4ArbitraryBitMaskSource
- Ipv4ArbitraryBitMaskDestination
- Ipv4Source
- Ipv4Destination
- TunnelIpv4Source
- TunnelIpv4Destination
- ArpOp
- ArpSourceTransportAddress
- ArpTargetTransportAddress
- ArpSourceHardwareAddress
- ArpTargetHardwareAddress
- Ipv6ArbitraryBitMaskSource
- Ipv6ArbitraryBitMaskDestination
- Ipv6Source
- Ipv6Destination
- Ipv6Label
- Ipv6NdTarget
- Ipv6NdSll
- Ipv6NdTll
- Ipv6ExtHeader
- MplsLabel
- MplsBos
- MplsTc
- Pbb
- TunnelId
- TcpFlags
Change-Id: I886e990aebc4ce02e5c7b571d06078aaf8033e07
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.tech>
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider;
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
import org.opendaylight.openflowplugin.api.openflow.protocol.serialization.MatchEntrySerializer;
import org.opendaylight.openflowplugin.api.openflow.protocol.serialization.MatchEntrySerializerRegistry;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.ArpOpEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.ArpSourceHardwareAddressEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.ArpSourceTransportAddressEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.ArpTargetHardwareAddressEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.ArpTargetTransportAddressEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.EthernetDestinationEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.EthernetSourceEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.EthernetTypeEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Icmpv4CodeEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Icmpv4TypeEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Icmpv6CodeEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Icmpv6TypeEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.InPhyPortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.InPortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.IpDscpEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.IpEcnEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.IpProtoEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv4DestinationEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv4SourceEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6DestinationEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6ExtHeaderEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6LabelEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6NdSllEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6NdTargetEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6NdTllEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.Ipv6SourceEntrySerializer;
import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MatchEntrySerializerKeyImpl;
import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MatchSerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MetadataEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MplsBosEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MplsLabelEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.MplsTcEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.PbbEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.SctpDestinationPortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.SctpSourcePortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TcpDestinationPortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TcpFlagsEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TcpSourcePortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TunnelIdEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TunnelIpv4DestinationEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.TunnelIpv4SourceEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.UdpDestinationPortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.UdpSourcePortEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.VlanPcpEntrySerializer;
+import org.opendaylight.openflowplugin.impl.protocol.serialization.match.VlanVidEntrySerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
/**
// Inject all match entry serializers to match serializers using injector created by createInjector method
final Function<Integer, Function<Integer, Consumer<MatchEntrySerializer>>> injector =
createInjector(serializer, EncodeConstants.OF13_VERSION_ID);
+
+ final Function<Integer, Consumer<MatchEntrySerializer>> basicInjector =
+ injector.apply(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
+
+ final Function<Integer, Consumer<MatchEntrySerializer>> experInjector =
+ injector.apply(OxmMatchConstants.EXPERIMENTER_CLASS);
+
+ basicInjector.apply(OxmMatchConstants.IN_PORT).accept(new InPortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IN_PHY_PORT).accept(new InPhyPortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.METADATA).accept(new MetadataEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ETH_DST).accept(new EthernetDestinationEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ETH_SRC).accept(new EthernetSourceEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ETH_TYPE).accept(new EthernetTypeEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.VLAN_VID).accept(new VlanVidEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.VLAN_PCP).accept(new VlanPcpEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IP_DSCP).accept(new IpDscpEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IP_ECN).accept(new IpEcnEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IP_PROTO).accept(new IpProtoEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.TCP_SRC).accept(new TcpSourcePortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.TCP_DST).accept(new TcpDestinationPortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.UDP_SRC).accept(new UdpSourcePortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.UDP_DST).accept(new UdpDestinationPortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.SCTP_SRC).accept(new SctpSourcePortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.SCTP_DST).accept(new SctpDestinationPortEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ICMPV4_TYPE).accept(new Icmpv4TypeEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ICMPV4_CODE).accept(new Icmpv4CodeEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ICMPV6_TYPE).accept(new Icmpv6TypeEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ICMPV6_CODE).accept(new Icmpv6CodeEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV4_SRC).accept(new Ipv4SourceEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV4_DST).accept(new Ipv4DestinationEntrySerializer());
+ experInjector.apply(OxmMatchConstants.NXM_NX_TUN_IPV4_SRC).accept(new TunnelIpv4SourceEntrySerializer());
+ experInjector.apply(OxmMatchConstants.NXM_NX_TUN_IPV4_DST).accept(new TunnelIpv4DestinationEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ARP_OP).accept(new ArpOpEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ARP_SPA).accept(new ArpSourceTransportAddressEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ARP_TPA).accept(new ArpTargetTransportAddressEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ARP_SHA).accept(new ArpSourceHardwareAddressEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.ARP_THA).accept(new ArpTargetHardwareAddressEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_SRC).accept(new Ipv6SourceEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_DST).accept(new Ipv6DestinationEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_FLABEL).accept(new Ipv6LabelEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_ND_TARGET).accept(new Ipv6NdTargetEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_ND_SLL).accept(new Ipv6NdSllEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_ND_TLL).accept(new Ipv6NdTllEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.IPV6_EXTHDR).accept(new Ipv6ExtHeaderEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.MPLS_LABEL).accept(new MplsLabelEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.MPLS_BOS).accept(new MplsBosEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.MPLS_TC).accept(new MplsTcEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.PBB_ISID).accept(new PbbEntrySerializer());
+ basicInjector.apply(OxmMatchConstants.TUNNEL_ID).accept(new TunnelIdEntrySerializer());
+ experInjector.apply(EncodeConstants.ONFOXM_ET_TCP_FLAGS).accept(new TcpFlagsEntrySerializer());
}
/**
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._3.match.ArpMatch;
+
+public class ArpOpEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(ArpMatch.class.cast(match.getLayer3Match()).getArpOp());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ ArpMatch.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpOp());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_OP;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.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.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ ArpMatch.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpSourceHardwareAddress());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpSourceHardwareAddress().getMask());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_SHA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getArpSourceTransportAddress(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ ArpMatch.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpSourceTransportAddress());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ ArpMatch.class.cast(match.getLayer3Match()).getArpSourceTransportAddress());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_SPA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._3.match.ArpMatch;
+
+public class ArpTargetHardwareAddressEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ final ArpTargetHardwareAddress arpTargetHardwareAddress =
+ ArpMatch.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ ArpMatch.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpTargetHardwareAddress());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpTargetHardwareAddress().getMask());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_THA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getArpTargetTransportAddress(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ ArpMatch.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpTargetTransportAddress());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ ArpMatch.class.cast(match.getLayer3Match()).getArpTargetTransportAddress());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_TPA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+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 Objects.nonNull(match.getEthernetMatch()) &&
+ Objects.nonNull(match.getEthernetMatch().getEthernetDestination());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getEthernetMatch().getEthernetDestination().getMask());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+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 Objects.nonNull(match.getEthernetMatch()) &&
+ Objects.nonNull(match.getEthernetMatch().getEthernetSource());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getEthernetMatch().getEthernetSource().getMask());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+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 Objects.nonNull(match.getEthernetMatch()) &&
+ Objects.nonNull(match.getEthernetMatch().getEthernetType());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class Icmpv4CodeEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIcmpv4Match().getIcmpv4Code());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIcmpv4Match()) &&
+ Objects.nonNull(match.getIcmpv4Match().getIcmpv4Code());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV4_CODE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class Icmpv4TypeEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIcmpv4Match().getIcmpv4Type());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIcmpv4Match()) &&
+ Objects.nonNull(match.getIcmpv4Match().getIcmpv4Type());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV4_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class Icmpv6CodeEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIcmpv6Match().getIcmpv6Code());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIcmpv6Match()) &&
+ Objects.nonNull(match.getIcmpv6Match().getIcmpv6Code());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV6_CODE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class Icmpv6TypeEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIcmpv6Match().getIcmpv6Type());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIcmpv6Match()) &&
+ Objects.nonNull(match.getIcmpv6Match().getIcmpv6Type());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV6_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.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 Objects.nonNull(match.getInPhyPort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IN_PHY_PORT;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.model.match.types.rev131026.Match;
+
+public class InPortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeInt(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
+ OpenflowVersion.OF13,
+ match.getInPort().getValue()).intValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getInPort());
+ }
+
+ @Override
+ protected boolean getHasMask(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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class IpDscpEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIpMatch().getIpDscp().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIpMatch()) &&
+ Objects.nonNull(match.getIpMatch().getIpDscp());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class IpEcnEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getIpMatch().getIpEcn());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIpMatch()) &&
+ Objects.nonNull(match.getIpMatch().getIpEcn());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IP_ECN;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class IpProtoEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ // TODO: What is getIpMatch().getIpProto()? Fix models probably
+ outBuffer.writeByte(match.getIpMatch().getIpProtocol());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getIpMatch()) &&
+ Objects.nonNull(match.getIpMatch().getIpProtocol());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IP_PROTO;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getIpv4Destination(), outBuffer);
+ } else if (isArbitrary(match)) {
+ final Ipv4MatchArbitraryBitMask ipv4 = Ipv4MatchArbitraryBitMask.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv4Match.class.cast(match.getLayer3Match()).getIpv4Destination());
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv4MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv4DestinationAddressNoMask());
+ }
+
+ return false;
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ if (isPrefix(match)) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ Ipv4Match.class.cast(match.getLayer3Match()).getIpv4Destination());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(Ipv4MatchArbitraryBitMask.class.cast(match.getLayer3Match())
+ .getIpv4DestinationArbitraryBitmask());
+ }
+
+ return false;
+ }
+
+ private static boolean isPrefix(Match match) {
+ return Ipv4Match.class.isInstance(match.getLayer3Match());
+ }
+
+ private static boolean isArbitrary(Match match) {
+ return Ipv4MatchArbitraryBitMask.class.isInstance(match.getLayer3Match());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getIpv4Source(), outBuffer);
+ } else if (isArbitrary(match)) {
+ final Ipv4MatchArbitraryBitMask ipv4 = Ipv4MatchArbitraryBitMask.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv4Match.class.cast(match.getLayer3Match()).getIpv4Source());
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv4MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv4SourceAddressNoMask());
+ }
+
+ return false;
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ if (isPrefix(match)) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ Ipv4Match.class.cast(match.getLayer3Match()).getIpv4Source());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(Ipv4MatchArbitraryBitMask.class.cast(match.getLayer3Match())
+ .getIpv4SourceArbitraryBitmask());
+ }
+
+ return false;
+ }
+
+ private static boolean isPrefix(Match match) {
+ return Ipv4Match.class.isInstance(match.getLayer3Match());
+ }
+
+ private static boolean isArbitrary(Match match) {
+ return Ipv4MatchArbitraryBitMask.class.isInstance(match.getLayer3Match());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.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;
+
+public class Ipv6DestinationEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+
+ if (isPrefix(match)) {
+ writeIpv6Prefix(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Destination(), outBuffer);
+ } else if (isArbitrary(match)) {
+ final Ipv6MatchArbitraryBitMask ipv6 = Ipv6MatchArbitraryBitMask.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Destination());
+ } else if (isArbitrary(match)) {
+
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv6DestinationAddressNoMask());
+ }
+
+ return false;
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ if (isPrefix(match)) {
+ return Objects.nonNull(IpConversionUtil
+ .extractIpv6Prefix(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Destination()));
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(Ipv6MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv6DestinationArbitraryBitmask());
+ }
+
+ return false;
+ }
+
+ private static boolean isPrefix(Match match) {
+ return Ipv6Match.class.isInstance(match.getLayer3Match());
+ }
+
+ private static boolean isArbitrary(Match match) {
+ return Ipv6MatchArbitraryBitMask.class.isInstance(match.getLayer3Match());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.ipv6.match.fields.Ipv6ExtHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
+
+public class Ipv6ExtHeaderEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ final Ipv6ExtHeader ipv6ExtHeader = Ipv6Match.class.cast(match.getLayer3Match()).getIpv6ExtHeader();
+ outBuffer.writeShort(ipv6ExtHeader.getIpv6Exthdr());
+
+ if (getHasMask(match)) {
+ writeMask(ByteUtil.unsignedShortToBytes(
+ ipv6ExtHeader.getIpv6ExthdrMask()),
+ outBuffer,
+ getValueLength());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Ipv6Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6ExtHeader());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6ExtHeader().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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.ipv6.match.fields.Ipv6Label;
+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.class.cast(match.getLayer3Match()).getIpv6Label();
+ outBuffer.writeInt(ipv6Label.getIpv6Flabel().getValue().intValue());
+
+ if (getHasMask(match)) {
+ writeMask(ByteUtil.unsignedIntToBytes(
+ ipv6Label.getFlabelMask().getValue()),
+ outBuffer,
+ getValueLength());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Ipv6Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Label());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Label().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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._3.match.Ipv6Match;
+
+public class Ipv6NdSllEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ writeMacAddress(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdSll(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Ipv6Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdSll());
+ }
+
+ @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;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._3.match.Ipv6Match;
+
+public class Ipv6NdTargetEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ writeIpv6Address(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdTarget(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Ipv6Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdTarget());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_ND_TARGET;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._3.match.Ipv6Match;
+
+public class Ipv6NdTllEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ writeMacAddress(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdTll(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Ipv6Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6NdTll());
+ }
+
+ @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;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.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;
+
+public class Ipv6SourceEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+
+ if (isPrefix(match)) {
+ writeIpv6Prefix(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Source(), outBuffer);
+ } else if (isArbitrary(match)) {
+ final Ipv6MatchArbitraryBitMask ipv6 = Ipv6MatchArbitraryBitMask.class.cast(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 Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Source());
+ } else if (isArbitrary(match)) {
+
+ return Objects.nonNull(match.getLayer3Match()) &&
+ Objects.nonNull(Ipv6MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv6SourceAddressNoMask());
+ }
+
+ return false;
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ if (isPrefix(match)) {
+ return Objects.nonNull(IpConversionUtil
+ .extractIpv6Prefix(Ipv6Match.class.cast(match.getLayer3Match()).getIpv6Source()));
+ } else if (isArbitrary(match)) {
+ return Objects.nonNull(Ipv6MatchArbitraryBitMask.class.cast(match.getLayer3Match()).getIpv6SourceArbitraryBitmask());
+ }
+
+ return false;
+ }
+
+ private static boolean isPrefix(Match match) {
+ return Ipv6Match.class.isInstance(match.getLayer3Match());
+ }
+
+ private static boolean isArbitrary(Match match) {
+ return Ipv6MatchArbitraryBitMask.class.isInstance(match.getLayer3Match());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class MetadataEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeBytes(ByteUtil.convertBigIntegerToNBytes(
+ match.getMetadata().getMetadata(),
+ getValueLength()));
+
+ if (getHasMask(match)) {
+ writeMask(ByteUtil.convertBigIntegerToNBytes(
+ match.getMetadata().getMetadataMask(),
+ getValueLength()),
+ outBuffer,
+ getValueLength());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getMetadata());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getMetadata().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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class MplsBosEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeBoolean(match.getProtocolMatchFields().getMplsBos() != 0);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getProtocolMatchFields()) &&
+ Objects.nonNull(match.getProtocolMatchFields().getMplsBos());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.MPLS_BOS;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+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 Objects.nonNull(match.getProtocolMatchFields()) &&
+ Objects.nonNull(match.getProtocolMatchFields().getMplsLabel());
+ }
+
+ @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;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class MplsTcEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getProtocolMatchFields().getMplsTc());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getProtocolMatchFields()) &&
+ Objects.nonNull(match.getProtocolMatchFields().getMplsTc());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.MPLS_TC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+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());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getProtocolMatchFields()) &&
+ Objects.nonNull(match.getProtocolMatchFields().getPbb());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getProtocolMatchFields().getPbb().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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.SctpMatch;
+
+public class SctpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(SctpMatch.class.cast(match.getLayer4Match()).getSctpDestinationPort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ SctpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(SctpMatch.class.cast(match.getLayer4Match()).getSctpDestinationPort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.SCTP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.SctpMatch;
+
+public class SctpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(SctpMatch.class.cast(match.getLayer4Match()).getSctpSourcePort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ SctpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(SctpMatch.class.cast(match.getLayer4Match()).getSctpSourcePort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.SCTP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.TcpMatch;
+
+public class TcpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(TcpMatch.class.cast(match.getLayer4Match()).getTcpDestinationPort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ TcpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(TcpMatch.class.cast(match.getLayer4Match()).getTcpDestinationPort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TCP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class TcpFlagsEntrySerializer extends AbstractExperimenterMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(match.getTcpFlagsMatch().getTcpFlags());
+
+ if (getHasMask(match)) {
+ writeMask(ByteUtil.unsignedShortToBytes(
+ match.getTcpFlagsMatch().getTcpFlagsMask()),
+ outBuffer,
+ getValueLength());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getTcpFlagsMatch()) &&
+ Objects.nonNull(match.getTcpFlagsMatch().getTcpFlags());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getTcpFlagsMatch().getTcpFlagsMask());
+ }
+
+ @Override
+ protected long getExperimenterId() {
+ return EncodeConstants.ONF_EXPERIMENTER_ID;
+ }
+
+ @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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.TcpMatch;
+
+public class TcpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(TcpMatch.class.cast(match.getLayer4Match()).getTcpSourcePort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ TcpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(TcpMatch.class.cast(match.getLayer4Match()).getTcpSourcePort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TCP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class TunnelIdEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeBytes(ByteUtil.convertBigIntegerToNBytes(match.getTunnel().getTunnelId(), getValueLength()));
+
+ if (getHasMask(match)) {
+ writeMask(ByteUtil.convertBigIntegerToNBytes(
+ match.getTunnel().getTunnelMask(), getValueLength()),
+ outBuffer,
+ getValueLength());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getTunnel()) &&
+ Objects.nonNull(match.getTunnel().getTunnelId());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return Objects.nonNull(match.getTunnel().getTunnelMask());
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TUNNEL_ID;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getTunnelIpv4Destination(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ TunnelIpv4Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Destination());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Destination());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Iterator;
+import java.util.Objects;
+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.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.class.cast(match.getLayer3Match()).getTunnelIpv4Source(), outBuffer);
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer3Match()) &&
+ TunnelIpv4Match.class.isInstance(match.getLayer3Match()) &&
+ Objects.nonNull(TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Source());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ // Split address to IP and mask
+ final Iterator<String> addressParts = IpConversionUtil.splitToParts(
+ TunnelIpv4Match.class.cast(match.getLayer3Match()).getTunnelIpv4Source());
+ addressParts.next();
+
+ // Check if we have mask
+ return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.UdpMatch;
+
+public class UdpDestinationPortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(UdpMatch.class.cast(match.getLayer4Match()).getUdpDestinationPort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ UdpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(UdpMatch.class.cast(match.getLayer4Match()).getUdpDestinationPort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.UDP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.layer._4.match.UdpMatch;
+
+public class UdpSourcePortEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeShort(UdpMatch.class.cast(match.getLayer4Match()).getUdpSourcePort().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getLayer4Match()) &&
+ UdpMatch.class.isInstance(match.getLayer4Match()) &&
+ Objects.nonNull(UdpMatch.class.cast(match.getLayer4Match()).getUdpSourcePort());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.UDP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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;
+
+public class VlanPcpEntrySerializer extends AbstractMatchEntrySerializer {
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ super.serialize(match, outBuffer);
+ outBuffer.writeByte(match.getVlanMatch().getVlanPcp().getValue());
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getVlanMatch()) &&
+ Objects.nonNull(match.getVlanMatch().getVlanPcp());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ return false;
+ }
+
+ @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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 java.util.Objects;
+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.vlan.match.fields.VlanId;
+
+public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer {
+ private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
+
+ @Override
+ public void serialize(Match match, 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 = Objects.nonNull(vlanId) ? vlanId.getValue() : 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());
+ }
+ }
+
+ @Override
+ public boolean matchTypeCheck(Match match) {
+ return Objects.nonNull(match.getVlanMatch()) &&
+ Objects.nonNull(match.getVlanMatch().getVlanId());
+ }
+
+ @Override
+ protected boolean getHasMask(Match match) {
+ final VlanId vlanId = match.getVlanMatch().getVlanId();
+ return Boolean.TRUE.equals(vlanId.isVlanIdPresent()) &&
+ (Objects.isNull(vlanId.getVlanId()) || vlanId.getVlanId().getValue() == 0);
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.VLAN_VID;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+ @Override
+ protected int getValueLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.ArpMatchBuilder;
+
+public class ArpOpEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int arpOp = 42;
+
+ final Match arpOpMatch = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpOp(arpOp)
+ .build())
+ .build();
+
+ assertMatch(arpOpMatch, false, (out) -> assertEquals(out.readShort(), arpOp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_OP;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.ArpSourceHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
+
+public class ArpSourceHardwareAddressEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress address = new MacAddress("00:01:02:03:04:05");
+ final MacAddress mask = new MacAddress("00:00:00:00:00:00");
+
+ final Match arpShaMatch = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpSourceHardwareAddress(new ArpSourceHardwareAddressBuilder()
+ .setAddress(address)
+ .setMask(mask)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(arpShaMatch, true, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+
+ byte[] maskBytes = new byte[6];
+ out.readBytes(maskBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
+ });
+
+ final Match arpShaMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpSourceHardwareAddress(new ArpSourceHardwareAddressBuilder()
+ .setAddress(address)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(arpShaMatchNoMask, false, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_SHA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.ArpMatchBuilder;
+
+public class ArpSourceTransportAddressEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match arpSpaMatch = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpSourceTransportAddress(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(arpSpaMatch, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match arpSpaMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpSourceTransportAddress(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(arpSpaMatchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_SPA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.ArpTargetHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
+
+public class ArpTargetHardwareAddressEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress address = new MacAddress("00:01:02:03:04:05");
+ final MacAddress mask = new MacAddress("00:00:00:00:00:00");
+
+ final Match arpShaMatch = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpTargetHardwareAddress(new ArpTargetHardwareAddressBuilder()
+ .setAddress(address)
+ .setMask(mask)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(arpShaMatch, true, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+
+ byte[] maskBytes = new byte[6];
+ out.readBytes(maskBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
+ });
+
+ final Match arpShaMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpTargetHardwareAddress(new ArpTargetHardwareAddressBuilder()
+ .setAddress(address)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(arpShaMatchNoMask, false, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_THA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.ArpMatchBuilder;
+
+public class ArpTargetTransportAddressEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match arpSpaMatch = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpTargetTransportAddress(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(arpSpaMatch, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match arpSpaMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new ArpMatchBuilder()
+ .setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(arpSpaMatchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ARP_TPA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
+
+public class EthernetDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress address = new MacAddress("00:01:02:03:04:05");
+ final MacAddress mask = new MacAddress("00:00:00:00:00:00");
+
+ final Match match = new MatchBuilder()
+ .setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetDestination(new EthernetDestinationBuilder()
+ .setAddress(address)
+ .setMask(mask)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(match, true, (out) -> {
+ final byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+
+ final byte[] maskBytes = new byte[6];
+ out.readBytes(maskBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
+ });
+
+ final Match matchNoMask = new MatchBuilder()
+ .setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetDestination(new EthernetDestinationBuilder()
+ .setAddress(address)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(matchNoMask, false, (out) -> {
+ final byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
+
+public class EthernetSourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress address = new MacAddress("00:01:02:03:04:05");
+ final MacAddress mask = new MacAddress("00:00:00:00:00:00");
+
+ final Match match = new MatchBuilder()
+ .setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetSource(new EthernetSourceBuilder()
+ .setAddress(address)
+ .setMask(mask)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(match, true, (out) -> {
+ final byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+
+ final byte[] maskBytes = new byte[6];
+ out.readBytes(maskBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
+ });
+
+ final Match matchNoMask = new MatchBuilder()
+ .setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetSource(new EthernetSourceBuilder()
+ .setAddress(address)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(matchNoMask, false, (out) -> {
+ final byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
+
+public class EthernetTypeEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final long ethType = 0xffffL;
+
+ final Match match = new MatchBuilder()
+ .setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetType(new EthernetTypeBuilder()
+ .setType(new EtherType(ethType))
+ .build())
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedShort(), ethType));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ETH_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
+
+public class Icmpv4CodeEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short code = 200;
+
+ final Match match = new MatchBuilder()
+ .setIcmpv4Match(new Icmpv4MatchBuilder()
+ .setIcmpv4Code(code)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), code));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV4_CODE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
+
+public class Icmpv4TypeEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short type = 128;
+
+ final Match match = new MatchBuilder()
+ .setIcmpv4Match(new Icmpv4MatchBuilder()
+ .setIcmpv4Type(type)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), type));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV4_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
+
+public class Icmpv6CodeEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short code = 101;
+
+ final Match match = new MatchBuilder()
+ .setIcmpv6Match(new Icmpv6MatchBuilder()
+ .setIcmpv6Code(code)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), code));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV6_CODE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
+
+public class Icmpv6TypeEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short type = 123;
+
+ final Match match = new MatchBuilder()
+ .setIcmpv6Match(new Icmpv6MatchBuilder()
+ .setIcmpv6Type(type)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), type));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.ICMPV6_TYPE;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+
+public class InPhyPortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int port = 10122;
+
+ final Match match = new MatchBuilder()
+ .setInPhyPort(new NodeConnectorId("openflow:1:" + port))
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedInt(), port));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IN_PHY_PORT;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+
+public class InPortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int port = 42;
+
+ final Match match = new MatchBuilder()
+ .setInPort(new NodeConnectorId("openflow:1:" + port))
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedInt(), port));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IN_PORT;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
+
+public class IpDscpEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short dscp = (short) 58;
+
+ final Match match = new MatchBuilder()
+ .setIpMatch(new IpMatchBuilder()
+ .setIpDscp(new Dscp(dscp))
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), dscp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IP_DSCP;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
+
+public class IpEcnEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short ecn = (short) 58;
+
+ final Match match = new MatchBuilder()
+ .setIpMatch(new IpMatchBuilder()
+ .setIpEcn(ecn)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), ecn));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IP_ECN;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
+
+public class IpProtoEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short proto = (short) 6; // TCP
+
+ final Match match = new MatchBuilder()
+ .setIpMatch(new IpMatchBuilder()
+ .setIpProtocol(proto)
+ .build())
+ .build();
+
+ assertMatch(match, false, (out) -> assertEquals(out.readUnsignedByte(), proto));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IP_PROTO;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Address;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder;
+
+public class Ipv4ArbitraryBitMaskDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
+ final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
+
+ final Match ipv4abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
+ .setIpv4DestinationAddressNoMask(ipv4Address)
+ .setIpv4DestinationArbitraryBitmask(ipv4mask)
+ .build())
+ .build();
+
+ assertMatch(ipv4abmMatch, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4abmMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
+ .setIpv4DestinationAddressNoMask(ipv4Address)
+ .build())
+ .build();
+
+ assertMatch(ipv4abmMatchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Address;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder;
+
+public class Ipv4ArbitraryBitMaskSourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
+ final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
+
+ final Match ipv4abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
+ .setIpv4SourceAddressNoMask(ipv4Address)
+ .setIpv4SourceArbitraryBitmask(ipv4mask)
+ .build())
+ .build();
+
+ assertMatch(ipv4abmMatch, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4abmMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
+ .setIpv4SourceAddressNoMask(ipv4Address)
+ .build())
+ .build();
+
+ assertMatch(ipv4abmMatchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv4MatchBuilder;
+
+public class Ipv4DestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match ipv4match = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchBuilder()
+ .setIpv4Destination(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(ipv4match, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4matchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchBuilder()
+ .setIpv4Destination(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(ipv4matchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv4MatchBuilder;
+
+public class Ipv4SourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match ipv4match = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchBuilder()
+ .setIpv4Source(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(ipv4match, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4matchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv4MatchBuilder()
+ .setIpv4Source(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(ipv4matchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.IetfInetUtil;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
+
+public class Ipv6ArbitraryBitMaskDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv6Address ipv6Address = new Ipv6Address("aaaa:bbbb:1111:2222::");
+ final Ipv6ArbitraryMask ipv6mask = new Ipv6ArbitraryMask("ffff:ffff:ffff:ffff::");
+
+ final Match ipv6abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder()
+ .setIpv6DestinationAddressNoMask(ipv6Address)
+ .setIpv6DestinationArbitraryBitmask(ipv6mask)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatch, true, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
+
+ byte[] mask = new byte[16];
+ out.readBytes(mask);
+ assertArrayEquals(mask, IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(ipv6mask));
+ });
+
+ final Match ipv6abmMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder()
+ .setIpv6DestinationAddressNoMask(ipv6Address)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatchNoMask, false, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.IetfInetUtil;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
+
+public class Ipv6ArbitraryBitMaskSourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv6Address ipv6Address = new Ipv6Address("aaaa:bbbb:1111:2222::");
+ final Ipv6ArbitraryMask ipv6mask = new Ipv6ArbitraryMask("ffff:ffff:ffff:ffff::");
+
+ final Match ipv6abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder()
+ .setIpv6SourceAddressNoMask(ipv6Address)
+ .setIpv6SourceArbitraryBitmask(ipv6mask)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatch, true, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
+
+ byte[] mask = new byte[16];
+ out.readBytes(mask);
+ assertArrayEquals(mask, IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(ipv6mask));
+ });
+
+ final Match ipv6abmMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder()
+ .setIpv6SourceAddressNoMask(ipv6Address)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatchNoMask, false, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.IetfInetUtil;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6DestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv6Prefix ipv6Address = new Ipv6Prefix("2001:db8::/32");
+
+ final Match ipv6abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6Destination(ipv6Address)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatch, true, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(IpConversionUtil.extractIpv6Address(ipv6Address)));
+
+ byte[] mask = new byte[16];
+ out.readBytes(mask);
+ assertArrayEquals(mask, IpConversionUtil.convertIpv6PrefixToByteArray(IpConversionUtil.extractIpv6Prefix(ipv6Address)));
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.Ipv6ExtHeaderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6ExtHeaderEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int ipv6extHdr = 358;
+ final int ipv6extHdrMask = 100;
+
+ final Match ipv6extHdrMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
+ .setIpv6Exthdr(ipv6extHdr)
+ .setIpv6ExthdrMask(ipv6extHdrMask)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(ipv6extHdrMatch, true, (out) -> {
+ assertEquals(out.readUnsignedShort(), ipv6extHdr);
+
+ byte[] mask = new byte[2];
+ out.readBytes(mask);
+ assertArrayEquals(mask, ByteUtil.unsignedShortToBytes(ipv6extHdrMask));
+ });
+
+ final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
+ .setIpv6Exthdr(ipv6extHdr)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedShort(), ipv6extHdr));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_EXTHDR;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.Ipv6LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6LabelEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final long ipv6flowLabel = 358;
+ final long ipv6flowLabelMask = 100;
+
+ final Match ipv6flowLabelMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6Label(new Ipv6LabelBuilder()
+ .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
+ .setFlabelMask(new Ipv6FlowLabel(ipv6flowLabelMask))
+ .build())
+ .build())
+ .build();
+
+ assertMatch(ipv6flowLabelMatch, true, (out) -> {
+ assertEquals(out.readUnsignedInt(), ipv6flowLabel);
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, ByteUtil.unsignedIntToBytes(ipv6flowLabelMask));
+ });
+
+ final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6Label(new Ipv6LabelBuilder()
+ .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
+ .build())
+ .build())
+ .build();
+
+ assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedInt(), ipv6flowLabel));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_FLABEL;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6NdSllEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress ipv6NdSll = new MacAddress("00:01:02:03:04:05");
+
+ final Match ipv6NdSllMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6NdSll(ipv6NdSll)
+ .build())
+ .build();
+
+ assertMatch(ipv6NdSllMatch, false, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), ipv6NdSll.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_ND_SLL;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.IetfInetUtil;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6NdTargetEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv6Address ipv6NdTarget = new Ipv6Address("2001:db8::");
+
+ final Match ipv6NdTargetMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6NdTarget(ipv6NdTarget)
+ .build())
+ .build();
+
+ assertMatch(ipv6NdTargetMatch, false, (out) -> {
+ byte[] addressBytes = new byte[16];
+ out.readBytes(addressBytes);
+ assertArrayEquals(addressBytes, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6NdTarget));
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_ND_TARGET;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6NdTllEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final MacAddress ipv6NdTll = new MacAddress("00:01:02:03:04:05");
+
+ final Match ipv6NdTllMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6NdTll(ipv6NdTll)
+ .build())
+ .build();
+
+ assertMatch(ipv6NdTllMatch, false, (out) -> {
+ byte[] addressBytes = new byte[6];
+ out.readBytes(addressBytes);
+ assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), ipv6NdTll.getValue());
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.MAC_ADDRESS_LENGTH;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_ND_TLL;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.IetfInetUtil;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.Ipv6MatchBuilder;
+
+public class Ipv6SourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Ipv6Prefix ipv6Address = new Ipv6Prefix("2001:db8::/32");
+
+ final Match ipv6abmMatch = new MatchBuilder()
+ .setLayer3Match(new Ipv6MatchBuilder()
+ .setIpv6Source(ipv6Address)
+ .build())
+ .build();
+
+ assertMatch(ipv6abmMatch, true, (out) -> {
+ byte[] address = new byte[16];
+ out.readBytes(address);
+ assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(IpConversionUtil.extractIpv6Address(ipv6Address)));
+
+ byte[] mask = new byte[16];
+ out.readBytes(mask);
+ assertArrayEquals(mask, IpConversionUtil.convertIpv6PrefixToByteArray(IpConversionUtil.extractIpv6Prefix(ipv6Address)));
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV6_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import com.google.common.primitives.Longs;
+import java.math.BigInteger;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.MetadataBuilder;
+
+public class MetadataEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final byte[] metadata = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
+ final byte[] metadataMask = new byte[] { 30, 30, 30, 30, 30, 0, 0, 0 };
+
+
+ final Match metadataMatch = new MatchBuilder()
+ .setMetadata(new MetadataBuilder()
+ .setMetadata(BigInteger.valueOf(Longs.fromByteArray(metadata)))
+ .setMetadataMask(BigInteger.valueOf(Longs.fromByteArray(metadataMask)))
+ .build())
+ .build();
+
+ assertMatch(metadataMatch, true, (out) -> {
+ byte[] addressBytes = new byte[8];
+ out.readBytes(addressBytes);
+ assertArrayEquals(addressBytes, metadata);
+
+ byte[] maskBytes = new byte[8];
+ out.readBytes(maskBytes);
+ assertArrayEquals(maskBytes, metadataMask);
+ });
+
+ final Match metadataMatchNoMask = new MatchBuilder()
+ .setMetadata(new MetadataBuilder()
+ .setMetadata(BigInteger.valueOf(Longs.fromByteArray(metadata)))
+ .build())
+ .build();
+
+ assertMatch(metadataMatchNoMask, false, (out) -> {
+ byte[] addressBytes = new byte[8];
+ out.readBytes(addressBytes);
+ assertArrayEquals(addressBytes, metadata);
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.METADATA;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.ProtocolMatchFieldsBuilder;
+
+public class MplsBosEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short mplsBos = (short) 1;
+
+ final Match mplsBosMatch = new MatchBuilder()
+ .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
+ .setMplsBos(mplsBos)
+ .build())
+ .build();
+
+ // TODO: Why are we using short in models instead of boolean?
+ assertMatch(mplsBosMatch, false, (out) -> assertEquals(out.readBoolean(), mplsBos != 0));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.MPLS_BOS;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.ProtocolMatchFieldsBuilder;
+
+public class MplsLabelEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final long mplsLabel = 10L;
+
+ final Match mplsLabelMatch = new MatchBuilder()
+ .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
+ .setMplsLabel(mplsLabel)
+ .build())
+ .build();
+
+ assertMatch(mplsLabelMatch, false, (out) -> assertEquals(out.readUnsignedInt(), mplsLabel));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.MPLS_LABEL;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.ProtocolMatchFieldsBuilder;
+
+public class MplsTcEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short mplsTc = (short) 1;
+
+ final Match mplsTcMatch = new MatchBuilder()
+ .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
+ .setMplsTc(mplsTc)
+ .build())
+ .build();
+
+ assertMatch(mplsTcMatch, false, (out) -> assertEquals(out.readUnsignedByte(), mplsTc));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.MPLS_TC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.ProtocolMatchFieldsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
+
+public class PbbEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final long pbbId = 6789;
+ final byte[] pbbIdMask = new byte[] { 0, 15, 10 };
+
+ final Match pbbMatch = new MatchBuilder()
+ .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
+ .setPbb(new PbbBuilder()
+ .setPbbIsid(pbbId)
+ .setPbbMask(ByteUtil.bytesToUnsignedMedium(pbbIdMask))
+ .build())
+ .build())
+ .build();
+
+ assertMatch(pbbMatch, true, (out) -> {
+ assertEquals(out.readUnsignedMedium(), pbbId);
+
+ final byte[] mask = new byte[3];
+ out.readBytes(mask);
+ assertArrayEquals(mask, pbbIdMask);
+ });
+
+ final Match pbbMatchNoMask = new MatchBuilder()
+ .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
+ .setPbb(new PbbBuilder()
+ .setPbbIsid(pbbId)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(pbbMatchNoMask, false, (out) -> assertEquals(out.readUnsignedMedium(), pbbId));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_3_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.PBB_ISID;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.SctpMatchBuilder;
+
+public class SctpDestinationPortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int sctp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new SctpMatchBuilder()
+ .setSctpDestinationPort(new PortNumber(sctp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), sctp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.SCTP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.SctpMatchBuilder;
+
+public class SctpSourcePortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int sctp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new SctpMatchBuilder()
+ .setSctpSourcePort(new PortNumber(sctp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), sctp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.SCTP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.TcpMatchBuilder;
+
+public class TcpDestinationPortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int tcp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new TcpMatchBuilder()
+ .setTcpDestinationPort(new PortNumber(tcp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TCP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.TcpFlagsMatchBuilder;
+
+public class TcpFlagsEntrySerializerTest extends AbstractExperimenterMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int tcp = 8;
+ final byte[] tcpMask = new byte[] { 30, 30 };
+
+ final Match tcpFlagsMatch = new MatchBuilder()
+ .setTcpFlagsMatch(new TcpFlagsMatchBuilder()
+ .setTcpFlags(tcp)
+ .setTcpFlagsMask(ByteUtil.bytesToUnsignedShort(tcpMask))
+ .build())
+ .build();
+
+ assertMatch(tcpFlagsMatch, true, (out) -> {
+ assertEquals(out.readUnsignedShort(), tcp);
+
+ byte[] mask = new byte[2];
+ out.readBytes(mask);
+ assertArrayEquals(mask, tcpMask);
+ });
+
+ final Match tcpFlagsMatchNoMask = new MatchBuilder()
+ .setTcpFlagsMatch(new TcpFlagsMatchBuilder()
+ .setTcpFlags(tcp)
+ .build())
+ .build();
+
+ assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return EncodeConstants.ONFOXM_ET_TCP_FLAGS;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.EXPERIMENTER_CLASS;
+ }
+
+ @Override
+ protected long getExperimenterId() {
+ return EncodeConstants.ONF_EXPERIMENTER_ID;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.TcpMatchBuilder;
+
+public class TcpSourcePortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int tcp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new TcpMatchBuilder()
+ .setTcpSourcePort(new PortNumber(tcp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TCP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.TunnelBuilder;
+
+public class TunnelIdEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final long tunnelId = 8;
+ final byte[] tcpMask = new byte[] { 30, 30, 30, 30, 0, 0, 0, 0 };
+
+ final ByteBuffer maskBuff = ByteBuffer.allocate(Long.BYTES);
+ maskBuff.put(tcpMask, 0, tcpMask.length);
+ maskBuff.flip();
+
+ final Match tcpFlagsMatch = new MatchBuilder()
+ .setTunnel(new TunnelBuilder()
+ .setTunnelId(BigInteger.valueOf(tunnelId))
+ .setTunnelMask(BigInteger.valueOf(maskBuff.getLong()))
+ .build())
+ .build();
+
+ assertMatch(tcpFlagsMatch, true, (out) -> {
+ assertEquals(out.readLong(), tunnelId);
+
+ byte[] mask = new byte[8];
+ out.readBytes(mask);
+ assertArrayEquals(mask, tcpMask);
+ });
+
+ final Match tcpFlagsMatchNoMask = new MatchBuilder()
+ .setTunnel(new TunnelBuilder()
+ .setTunnelId(BigInteger.valueOf(tunnelId))
+ .build())
+ .build();
+
+ assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readLong(), tunnelId));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.TUNNEL_ID;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.TunnelIpv4MatchBuilder;
+
+public class TunnelIpv4DestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match ipv4match = new MatchBuilder()
+ .setLayer3Match(new TunnelIpv4MatchBuilder()
+ .setTunnelIpv4Destination(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(ipv4match, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4matchNoMask = new MatchBuilder()
+ .setLayer3Match(new TunnelIpv4MatchBuilder()
+ .setTunnelIpv4Destination(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(ipv4matchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.layer._3.match.TunnelIpv4MatchBuilder;
+
+public class TunnelIpv4SourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final Match ipv4match = new MatchBuilder()
+ .setLayer3Match(new TunnelIpv4MatchBuilder()
+ .setTunnelIpv4Source(new Ipv4Prefix("10.0.2.0/24"))
+ .build())
+ .build();
+
+ assertMatch(ipv4match, true, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
+
+ byte[] mask = new byte[4];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
+ });
+
+ final Match ipv4matchNoMask = new MatchBuilder()
+ .setLayer3Match(new TunnelIpv4MatchBuilder()
+ .setTunnelIpv4Source(new Ipv4Prefix("10.0.0.0/32"))
+ .build())
+ .build();
+
+ assertMatch(ipv4matchNoMask, false, (out) -> {
+ byte[] address = new byte[4];
+ out.readBytes(address);
+ assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.IPV4_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.UdpMatchBuilder;
+
+public class UdpDestinationPortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int tcp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new UdpMatchBuilder()
+ .setUdpDestinationPort(new PortNumber(tcp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.UDP_DST;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.flow.types.rev131026.flow.MatchBuilder;
+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.layer._4.match.UdpMatchBuilder;
+
+public class UdpSourcePortEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int tcp = 10;
+
+ final Match sctpMatch = new MatchBuilder()
+ .setLayer4Match(new UdpMatchBuilder()
+ .setUdpSourcePort(new PortNumber(tcp))
+ .build())
+ .build();
+
+ assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.UDP_SRC;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+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.VlanMatchBuilder;
+
+public class VlanPcpEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final short vlan = (short) 1;
+
+ final Match vlanMatch = new MatchBuilder()
+ .setVlanMatch(new VlanMatchBuilder()
+ .setVlanPcp(new VlanPcp(vlan))
+ .build())
+ .build();
+
+ assertMatch(vlanMatch, false, (out) -> assertEquals(out.readUnsignedByte(), vlan));
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.VLAN_PCP;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+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.VlanMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
+
+public class VlanVidEntrySerializerTest extends AbstractMatchEntrySerializerTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ final int vlan = (short) 1;
+
+ final Match vlanMatch = new MatchBuilder()
+ .setVlanMatch(new VlanMatchBuilder()
+ .setVlanId(new VlanIdBuilder()
+ .setVlanId(new VlanId(vlan))
+ .setVlanIdPresent(true)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(vlanMatch, false, (out) -> assertEquals(out.readShort(), vlan | (1 << 12)));
+
+ final Match vlanMatchMaskOnly = new MatchBuilder()
+ .setVlanMatch(new VlanMatchBuilder()
+ .setVlanId(new VlanIdBuilder()
+ .setVlanIdPresent(true)
+ .build())
+ .build())
+ .build();
+
+ assertMatch(vlanMatchMaskOnly, true, out -> {
+ assertEquals(out.readShort(), (1 << 12));
+
+ byte mask[] = new byte[2];
+ out.readBytes(mask);
+ assertArrayEquals(mask, new byte[] { 16, 0 });
+ });
+ }
+
+ @Override
+ protected short getLength() {
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+ }
+
+ @Override
+ protected int getOxmFieldCode() {
+ return OxmMatchConstants.VLAN_VID;
+ }
+
+ @Override
+ protected int getOxmClassCode() {
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
+ }
+
+}