--- /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.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.NxmOfIpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.ip.src.grouping.IpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IpSrcCaseValueBuilder;
+
+public class IpSrcCodecTest {
+
+ IpSrcCodec ipSrcCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 7;
+
+ @Before
+ public void setUp() {
+ ipSrcCodec = new IpSrcCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ ipSrcCodec.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.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = ipSrcCodec.deserialize(buffer);
+
+ IpSrcCaseValue result = ((IpSrcCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfIpSrc.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getIpSrcValues().getValue().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ IpSrcCaseValueBuilder caseBuilder = new IpSrcCaseValueBuilder();
+ IpSrcValuesBuilder valuesBuilder = new IpSrcValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfIpSrc.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setIpSrcValues(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);
+ message.writeInt(2);
+ }
+
+}
\ 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.NxmNxNshc1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._1.grouping.Nshc1ValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc1CaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc1CaseValueBuilder;
+
+public class Nshc1CodecTest {
+
+ Nshc1Codec nshc1Codec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 39;
+
+ @Before
+ public void setUp(){
+ nshc1Codec = new Nshc1Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ nshc1Codec.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 = nshc1Codec.deserialize(buffer);
+
+ Nshc1CaseValue result = ((Nshc1CaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxNshc1.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getNshc1Values().getNshc().intValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ Nshc1CaseValueBuilder caseBuilder = new Nshc1CaseValueBuilder();
+ Nshc1ValuesBuilder valuesBuilder = new Nshc1ValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxNshc1.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setNshc((long)1);
+
+ caseBuilder.setNshc1Values(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(2);
+ }
+
+}
\ 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.NxmNxNshc2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._2.grouping.Nshc2ValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc2CaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc2CaseValueBuilder;
+
+public class Nshc2CodecTest {
+
+ Nshc2Codec nshc2Codec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 40;
+
+
+ @Before
+ public void setUp() {
+ nshc2Codec = new Nshc2Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ nshc2Codec.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 = nshc2Codec.deserialize(buffer);
+
+ Nshc2CaseValue result = ((Nshc2CaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxNshc2.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getNshc2Values().getNshc().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ Nshc2CaseValueBuilder caseBuilder = new Nshc2CaseValueBuilder();
+ Nshc2ValuesBuilder valuesBuilder = new Nshc2ValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxNshc2.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setNshc((long)1);
+
+ caseBuilder.setNshc2Values(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(2);
+ }
+}
\ 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.NxmNxNshc3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._3.grouping.Nshc3ValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValueBuilder;
+
+public class Nshc3CodecTest {
+
+ Nshc3Codec nshc3Codec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 41;
+
+ @Before
+ public void setUp() {
+ nshc3Codec = new Nshc3Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ nshc3Codec.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 = nshc3Codec.deserialize(buffer);
+
+ Nshc3CaseValue result = ((Nshc3CaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxNshc3.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getNshc3Values().getNshc().intValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ Nshc3CaseValueBuilder caseBuilder = new Nshc3CaseValueBuilder();
+ Nshc3ValuesBuilder valuesBuilder = new Nshc3ValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxNshc3.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setNshc((long)1);
+
+ caseBuilder.setNshc3Values(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(2);
+ }
+}
\ 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.NxmNxNshc4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._4.grouping.Nshc4ValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValueBuilder;
+
+public class Nshc4CodecTest {
+
+ Nshc4Codec nshc4Codec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 42;
+
+ @Before
+ public void setUp() {
+ nshc4Codec = new Nshc4Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ nshc4Codec.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 = nshc4Codec.deserialize(buffer);
+
+ Nshc4CaseValue result = ((Nshc4CaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxNshc4.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getNshc4Values().getNshc().intValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ Nshc4CaseValueBuilder caseBuilder = new Nshc4CaseValueBuilder();
+ Nshc4ValuesBuilder valuesBuilder = new Nshc4ValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxNshc4.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setNshc((long)1);
+
+ caseBuilder.setNshc4Values(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(2);
+ }
+}
\ No newline at end of file