--- /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.NxmOfArpSpa;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.arp.spa.grouping.ArpSpaValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpSpaCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpSpaCaseValueBuilder;
+
+public class ArpSpaCodecTest {
+
+ ArpSpaCodec arpSpaCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 16;
+
+
+ @Before
+ public void setUp() {
+ arpSpaCodec = new ArpSpaCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ arpSpaCodec.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 = arpSpaCodec.deserialize(buffer);
+
+ ArpSpaCaseValue result = ((ArpSpaCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfArpSpa.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getArpSpaValues().getValue().shortValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ ArpSpaCaseValueBuilder caseBuilder = new ArpSpaCaseValueBuilder();
+ ArpSpaValuesBuilder valuesBuilder = new ArpSpaValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfArpSpa.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setArpSpaValues(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.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+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.NxmNxArpTha;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.arp.tha.grouping.ArpThaValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpThaCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpThaCaseValueBuilder;
+
+public class ArpThaCodecTest {
+
+ ArpThaCodec arpThaCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 6;
+ private static final int NXM_FIELD_CODE = 18;
+
+ private static final byte[] testAddr = new byte[VALUE_LENGTH];
+ private static final MacAddress testAddress = new MacAddress(ByteBufUtils.macAddressToString(testAddr));
+
+ @Before
+ public void setUp() {
+ arpThaCodec = new ArpThaCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ arpThaCodec.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(testAddress, ByteBufUtils.readIetfMacAddress(buffer));
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+ input = arpThaCodec.deserialize(buffer);
+
+ ArpThaCaseValue result = ((ArpThaCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxArpTha.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(testAddress, result.getArpThaValues().getMacAddress());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ ArpThaCaseValueBuilder caseBuilder = new ArpThaCaseValueBuilder();
+ ArpThaValuesBuilder valuesBuilder = new ArpThaValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxArpTha.class);
+ matchEntryBuilder.setHasMask(false);
+
+ byte[] address = new byte[VALUE_LENGTH];
+
+ valuesBuilder.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address)));
+
+ caseBuilder.setArpThaValues(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.writeBytes(testAddr);
+ }
+}
\ 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.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.NxmOfArpTpa;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.arp.tpa.grouping.ArpTpaValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpTpaCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpTpaCaseValueBuilder;
+
+public class ArpTpaCodecTest {
+
+ ArpTpaCodec arpTpaCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 4;
+ private static final int NXM_FIELD_CODE = 17;
+
+ @Before
+ public void setUp() {
+ arpTpaCodec = new ArpTpaCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ arpTpaCodec.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 = arpTpaCodec.deserialize(buffer);
+
+ ArpTpaCaseValue result = ((ArpTpaCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfArpTpa.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getArpTpaValues().getValue().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ ArpTpaCaseValueBuilder caseBuilder = new ArpTpaCaseValueBuilder();
+ ArpTpaValuesBuilder valuesBuilder = new ArpTpaValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfArpTpa.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue((long)1);
+
+ caseBuilder.setArpTpaValues(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.NxmNxCtState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValueBuilder;
+
+public class CtStateCodecTest {
+
+ CtStateCodec ctStateCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 8;
+ private static final int NXM_FIELD_CODE = 105;
+
+ @Before
+ public void setUp() {
+ ctStateCodec = new CtStateCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ ctStateCodec.serialize(input, buffer);
+
+ assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
+ short fieldMask = buffer.readUnsignedByte();
+ assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
+ assertEquals(1, fieldMask & 1);
+ assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
+ assertEquals(1, buffer.readUnsignedInt());
+ assertEquals(2, buffer.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+ input = ctStateCodec.deserialize(buffer);
+
+ CtStateCaseValue result = ((CtStateCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxCtState.class, input.getOxmMatchField());
+ assertEquals(true, input.isHasMask());
+ assertEquals(1, result.getCtStateValues().getCtState().intValue());
+ assertEquals(2, result.getCtStateValues().getMask().intValue());
+ }
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ CtStateCaseValueBuilder caseBuilder = new CtStateCaseValueBuilder();
+ CtStateValuesBuilder valuesBuilder = new CtStateValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxCtState.class);
+ matchEntryBuilder.setHasMask(true);
+
+ valuesBuilder.setCtState((long)1);
+ valuesBuilder.setMask((long)2);
+
+ caseBuilder.setCtStateValues(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);
+ //CtState = 1
+ message.writeInt(1);
+ //Mask = 2
+ 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.NxmNxCtZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.zone.grouping.CtZoneValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
+
+public class CtZoneCodecTest {
+
+ CtZoneCodec ctZoneCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 2;
+ private static final int NXM_FIELD_CODE = 106;
+
+
+
+ @Before
+ public void setUp() {
+ ctZoneCodec = new CtZoneCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ ctZoneCodec.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.readUnsignedShort());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+ input = ctZoneCodec.deserialize(buffer);
+
+ CtZoneCaseValue result = ((CtZoneCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxCtZone.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getCtZoneValues().getCtZone().shortValue());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ CtZoneCaseValueBuilder caseBuilder = new CtZoneCaseValueBuilder();
+ CtZoneValuesBuilder valuesBuilder = new CtZoneValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxCtZone.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setCtZone(1);
+
+ caseBuilder.setCtZoneValues(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.writeShort(2);
+ }
+}
\ No newline at end of file