--- /dev/null
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.nx.codec.match;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Src;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.src.grouping.TunIpv4SrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValueBuilder;
+
+public class TunIpv4SrcCodecTest {
+
+ TunIpv4SrcCodec tunIpv4SrcCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 31;
+
+ @Before
+ public void setUp() {
+ tunIpv4SrcCodec = new TunIpv4SrcCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ tunIpv4SrcCodec.serialize(input, buffer);
+
+ assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+ short fieldMask = buffer.readUnsignedByte();
+ assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+ assertEquals(0, fieldMask & 1);
+ assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+ assertEquals(1, buffer.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = tunIpv4SrcCodec.deserialize(buffer);
+
+ TunIpv4SrcCaseValue result = ((TunIpv4SrcCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxTunIpv4Src.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getTunIpv4SrcValues().getValue().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TunIpv4SrcCaseValueBuilder caseBuilder = new TunIpv4SrcCaseValueBuilder();
+ TunIpv4SrcValuesBuilder valuesBuilder = new TunIpv4SrcValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxTunIpv4Src.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setTunIpv4SrcValues(valuesBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+ return matchEntryBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(OxmMatchConstants.NXM_1_CLASS);
+
+ int fieldMask = (NXM_FIELD_CODE << 1);
+ message.writeByte(fieldMask);
+ message.writeByte(VALUE_LENGTH);
+ message.writeInt(1);
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.nx.codec.match;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfUdpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.dst.grouping.UdpDstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValueBuilder;
+
+public class UdpDstCodecTest {
+
+ UdpDstCodec udpDstCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 12;
+
+ @Before
+ public void setUp() {
+ udpDstCodec = new UdpDstCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ udpDstCodec.serialize(input, buffer);
+
+ assertEquals(OxmMatchConstants.NXM_0_CLASS, buffer.readUnsignedShort());
+ short fieldMask = buffer.readUnsignedByte();
+ assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+ assertEquals(0, fieldMask & 1);
+ assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+ assertEquals(1, buffer.readUnsignedShort());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = udpDstCodec.deserialize(buffer);
+
+ UdpDstCaseValue result = ((UdpDstCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfUdpDst.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getUdpDstValues().getPort().getValue().shortValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ UdpDstCaseValueBuilder caseBuilder = new UdpDstCaseValueBuilder();
+ UdpDstValuesBuilder valuesBuilder = new UdpDstValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfUdpDst.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setPort(new PortNumber(1));
+
+ caseBuilder.setUdpDstValues(valuesBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+ return matchEntryBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(OxmMatchConstants.NXM_0_CLASS);
+
+ int fieldMask = (NXM_FIELD_CODE << 1);
+ message.writeByte(fieldMask);
+ message.writeByte(VALUE_LENGTH);
+ byte[] value = new byte[VALUE_LENGTH];
+ //Port num = 1
+ message.writeShort(1);
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.nx.codec.match;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfUdpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.src.grouping.UdpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValueBuilder;
+
+public class UdpSrcCodecTest {
+
+ UdpSrcCodec udpSrcCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 11;
+
+ @Before
+ public void setUp() {
+ udpSrcCodec = new UdpSrcCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ udpSrcCodec.serialize(input, buffer);
+
+ assertEquals(OxmMatchConstants.NXM_0_CLASS, buffer.readUnsignedShort());
+ short fieldMask = buffer.readUnsignedByte();
+ assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+ assertEquals(0, fieldMask & 1);
+ assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+ assertEquals(1, buffer.readUnsignedShort());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = udpSrcCodec.deserialize(buffer);
+
+ UdpSrcCaseValue result = ((UdpSrcCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfUdpSrc.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getUdpSrcValues().getPort().getValue().shortValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ UdpSrcCaseValueBuilder caseBuilder = new UdpSrcCaseValueBuilder();
+ UdpSrcValuesBuilder valuesBuilder = new UdpSrcValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfUdpSrc.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setPort(new PortNumber(1));
+
+ caseBuilder.setUdpSrcValues(valuesBuilder.build());
+ matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
+ return matchEntryBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(OxmMatchConstants.NXM_0_CLASS);
+
+ int fieldMask = (NXM_FIELD_CODE << 1);
+ message.writeByte(fieldMask);
+ message.writeByte(VALUE_LENGTH);
+ byte[] value = new byte[VALUE_LENGTH];
+ //Port num = 1
+ message.writeShort(1);
+ }
+
+}
\ No newline at end of file