--- /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.NxmNxReg7;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.reg.grouping.RegValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.RegCaseValueBuilder;
+
+public class Reg7CodecTest {
+
+ Reg7Codec reg7Codec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int NXM_FIELD_CODE = 7;
+ private static final int VALUE_LENGTH = 4;
+
+ @Before
+ public void setUp() {
+ reg7Codec = new Reg7Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ reg7Codec.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 = reg7Codec.deserialize(buffer);
+
+ RegCaseValue result = ((RegCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxReg7.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getRegValues().getValue().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ RegCaseValueBuilder caseBuilder = new RegCaseValueBuilder();
+ RegValuesBuilder valuesBuilder = new RegValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxReg7.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setRegValues(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.NxmOfTcpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.dst.grouping.TcpDstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
+
+public class TcpDstCodecTest {
+
+ TcpDstCodec tcpDstCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 10;
+
+ @Before
+ public void setUp() {
+ tcpDstCodec = new TcpDstCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ tcpDstCodec.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 = tcpDstCodec.deserialize(buffer);
+
+ TcpDstCaseValue result = ((TcpDstCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfTcpDst.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getTcpDstValues().getPort().getValue().shortValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TcpDstCaseValueBuilder caseBuilder = new TcpDstCaseValueBuilder();
+ TcpDstValuesBuilder valuesBuilder = new TcpDstValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfTcpDst.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setPort(new PortNumber(1));
+
+ caseBuilder.setTcpDstValues(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);
+ //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.NxmOfTcpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.src.grouping.TcpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValueBuilder;
+
+public class TcpSrcCodecTest {
+
+ TcpSrcCodec tcpSrcCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 9;
+
+ @Before
+ public void setUp(){
+ tcpSrcCodec = new TcpSrcCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ tcpSrcCodec.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 = tcpSrcCodec.deserialize(buffer);
+
+ TcpSrcCaseValue result = ((TcpSrcCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfTcpSrc.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getTcpSrcValues().getPort().getValue().shortValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TcpSrcCaseValueBuilder caseBuilder = new TcpSrcCaseValueBuilder();
+ TcpSrcValuesBuilder valuesBuilder = new TcpSrcValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfTcpSrc.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setPort(new PortNumber(1));
+
+ caseBuilder.setTcpSrcValues(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);
+ //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 java.math.BigInteger;
+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.NxmNxTunId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValueBuilder;
+
+public class TunIdCodecTest {
+
+ TunIdCodec tunIdCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 8;
+ private static final int NXM_FIELD_CODE = 16;
+
+ @Before
+ public void setUp() {
+ tunIdCodec = new TunIdCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ tunIdCodec.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(0, buffer.readLong());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = tunIdCodec.deserialize(buffer);
+
+ TunIdCaseValue result = ((TunIdCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxTunId.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(0, result.getTunIdValues().getValue().longValue());
+ }
+
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TunIdCaseValueBuilder caseBuilder = new TunIdCaseValueBuilder();
+ TunIdValuesBuilder valuesBuilder = new TunIdValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxTunId.class);
+ matchEntryBuilder.setHasMask(false);
+
+ byte[] value = new byte[VALUE_LENGTH];
+ valuesBuilder.setValue(new BigInteger(value));
+
+ caseBuilder.setTunIdValues(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);
+ byte[] value = new byte[VALUE_LENGTH];
+ message.writeLong(new BigInteger(value).longValue());
+ }
+
+}
\ 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.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.NxmNxTunIpv4Dst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.dst.grouping.TunIpv4DstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValueBuilder;
+
+public class TunIpv4DstCodecTest {
+
+ TunIpv4DstCodec tunIpv4DstCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 32;
+
+ @Before
+ public void setUp() {
+ tunIpv4DstCodec = new TunIpv4DstCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ tunIpv4DstCodec.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 = tunIpv4DstCodec.deserialize(buffer);
+
+ TunIpv4DstCaseValue result = ((TunIpv4DstCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxTunIpv4Dst.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(1, result.getTunIpv4DstValues().getValue().intValue());
+ }
+
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ TunIpv4DstCaseValueBuilder caseBuilder = new TunIpv4DstCaseValueBuilder();
+ TunIpv4DstValuesBuilder valuesBuilder = new TunIpv4DstValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxTunIpv4Dst.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setTunIpv4DstValues(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