--- /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.action;
+
+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.nx.api.NiciraConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._4.grouping.NxActionSetNshc4Builder;
+
+public class SetNshc4CodecTest {
+
+ SetNshc4Codec setNshc4Codec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 16;
+ private final byte NXAST_SET_NSC_SUBTYPE = 37;
+ private final int padding = 2;
+
+ @Before
+ public void setUp() {
+ setNshc4Codec = new SetNshc4Codec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ setNshc4Codec.serialize(action, buffer);
+
+ assertEquals(LENGTH, buffer.readableBytes());
+
+ //SerializeHeader part
+ assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ assertEquals(LENGTH, buffer.readUnsignedShort());
+ assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ assertEquals(NXAST_SET_NSC_SUBTYPE, buffer.readUnsignedShort());
+ //Serialize
+ buffer.skipBytes(padding);
+ assertEquals(4, buffer.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = setNshc4Codec.deserialize(buffer);
+
+ ActionSetNshc4 result = (ActionSetNshc4) action.getActionChoice();
+
+ assertEquals(4, result.getNxActionSetNshc4().getNshc().intValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionSetNshc4Builder actionSetNshc4Builder = new ActionSetNshc4Builder();
+ NxActionSetNshc4Builder nxActionSetNshc4Builder = new NxActionSetNshc4Builder();
+
+ nxActionSetNshc4Builder.setNshc((long)4);
+
+ actionSetNshc4Builder.setNxActionSetNshc4(nxActionSetNshc4Builder.build());
+ actionBuilder.setActionChoice(actionSetNshc4Builder.build());
+
+ return actionBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
+ message.writeShort(LENGTH);
+ message.writeInt(NiciraConstants.NX_VENDOR_ID.intValue());
+ message.writeShort(NXAST_SET_NSC_SUBTYPE);
+
+ message.writeZero(padding);
+ message.writeInt(4);
+ }
+
+}
\ 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.action;
+
+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.nx.api.NiciraConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNsi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNsiBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nsi.grouping.NxActionSetNsiBuilder;
+
+public class SetNsiCodecTest {
+
+ SetNsiCodec setNsiCodec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 16;
+ private final byte NXAST_SET_NSC_SUBTYPE = 33;
+ private final int padding = 5;
+
+ @Before
+ public void setUp() {
+ setNsiCodec = new SetNsiCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ setNsiCodec.serialize(action, buffer);
+
+ assertEquals(LENGTH, buffer.readableBytes());
+
+ //SerializeHeader part
+ assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ assertEquals(LENGTH, buffer.readUnsignedShort());
+ assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ assertEquals(NXAST_SET_NSC_SUBTYPE, buffer.readUnsignedShort());
+ //Serialize
+ assertEquals(1, buffer.readUnsignedByte());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = setNsiCodec.deserialize(buffer);
+
+ ActionSetNsi result = (ActionSetNsi) action.getActionChoice();
+
+ assertEquals(1, result.getNxActionSetNsi().getNsi().intValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionSetNsiBuilder actionSetNsiBuilder = new ActionSetNsiBuilder();
+ NxActionSetNsiBuilder nxActionSetNsiBuilder = new NxActionSetNsiBuilder();
+
+ nxActionSetNsiBuilder.setNsi((short)1);
+
+ actionSetNsiBuilder.setNxActionSetNsi(nxActionSetNsiBuilder.build());
+ actionBuilder.setActionChoice(actionSetNsiBuilder.build());
+
+ return actionBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
+ message.writeShort(LENGTH);
+ message.writeInt(NiciraConstants.NX_VENDOR_ID.intValue());
+ message.writeShort(NXAST_SET_NSC_SUBTYPE);
+
+ message.writeByte(1);
+ message.writeZero(padding);
+ }
+
+}
\ 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.action;
+
+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.nx.api.NiciraConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNspBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nsp.grouping.NxActionSetNspBuilder;
+
+public class SetNspCodecTest {
+ SetNspCodec setNspCodec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 16;
+ private final byte NXAST_SET_NSC_SUBTYPE = 32;
+ private final int padding = 2;
+
+ @Before
+ public void setUp() {
+ setNspCodec = new SetNspCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ setNspCodec.serialize(action, buffer);
+
+ assertEquals(LENGTH, buffer.readableBytes());
+
+ //SerializeHeader part
+ assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ assertEquals(LENGTH, buffer.readUnsignedShort());
+ assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ assertEquals(NXAST_SET_NSC_SUBTYPE, buffer.readUnsignedShort());
+ //Serialize
+ buffer.skipBytes(padding);
+ assertEquals(1, buffer.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = setNspCodec.deserialize(buffer);
+
+ ActionSetNsp result = (ActionSetNsp) action.getActionChoice();
+
+ assertEquals(1, result.getNxActionSetNsp().getNsp().intValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionSetNspBuilder actionSetNsiBuilder = new ActionSetNspBuilder();
+ NxActionSetNspBuilder nxActionSetNsiBuilder = new NxActionSetNspBuilder();
+
+ nxActionSetNsiBuilder.setNsp((long)1);
+
+ actionSetNsiBuilder.setNxActionSetNsp(nxActionSetNsiBuilder.build());
+ actionBuilder.setActionChoice(actionSetNsiBuilder.build());
+
+ return actionBuilder.build();
+ }
+
+ private void createBuffer(ByteBuf message) {
+ message.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
+ message.writeShort(LENGTH);
+ message.writeInt(NiciraConstants.NX_VENDOR_ID.intValue());
+ message.writeShort(NXAST_SET_NSC_SUBTYPE);
+
+ message.writeZero(padding);
+ 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.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.NxmOfArpOp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.arp.op.grouping.ArpOpValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpOpCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpOpCaseValueBuilder;
+
+public class ArpOpCodecTest {
+
+ ArpOpCodec arpOpCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int NXM_FIELD_CODE = 15;
+ private static final int VALUE_LENGTH = 2;
+
+
+ @Before
+ public void setUp() {
+ arpOpCodec = new ArpOpCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ arpOpCodec.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 = arpOpCodec.deserialize(buffer);
+
+ ArpOpCaseValue result = ((ArpOpCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm0Class.class, input.getOxmClass());
+ assertEquals(NxmOfArpOp.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(2, result.getArpOpValues().getValue().shortValue());
+ }
+
+
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ ArpOpCaseValueBuilder caseBuilder = new ArpOpCaseValueBuilder();
+ ArpOpValuesBuilder valuesBuilder = new ArpOpValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm0Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmOfArpOp.class);
+ matchEntryBuilder.setHasMask(false);
+
+ valuesBuilder.setValue(1);
+
+ caseBuilder.setArpOpValues(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.writeShort(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.NxmNxArpSha;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.arp.sha.grouping.ArpShaValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValueBuilder;
+
+public class ArpShaCodecTest {
+
+ ArpShaCodec arpShaCodec;
+ ByteBuf buffer;
+ MatchEntry input;
+
+ private static final int VALUE_LENGTH = 6;
+ private static final int NXM_FIELD_CODE = 17;
+
+ private static byte[] resAddress = new byte[VALUE_LENGTH];
+ private static final MacAddress resultAddress = new MacAddress(ByteBufUtils.macAddressToString(resAddress));
+
+
+ @Before
+ public void setUp() {
+ arpShaCodec = new ArpShaCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+
+ @Test
+ public void serializeTest() {
+ input = createMatchEntry();
+ arpShaCodec.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(resultAddress, ByteBufUtils.readIetfMacAddress(buffer));
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ input = arpShaCodec.deserialize(buffer);
+
+ ArpShaCaseValue result = ((ArpShaCaseValue) input.getMatchEntryValue());
+
+ assertEquals(Nxm1Class.class, input.getOxmClass());
+ assertEquals(NxmNxArpSha.class, input.getOxmMatchField());
+ assertEquals(false, input.isHasMask());
+ assertEquals(resultAddress, result.getArpShaValues().getMacAddress());
+ }
+
+
+ private MatchEntry createMatchEntry() {
+ MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+ ArpShaCaseValueBuilder caseBuilder = new ArpShaCaseValueBuilder();
+ ArpShaValuesBuilder valuesBuilder = new ArpShaValuesBuilder();
+
+ matchEntryBuilder.setOxmClass(Nxm1Class.class);
+ matchEntryBuilder.setOxmMatchField(NxmNxArpSha.class);
+ matchEntryBuilder.setHasMask(false);
+
+
+ byte[] address = new byte[VALUE_LENGTH];
+
+ valuesBuilder.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address)));
+
+ caseBuilder.setArpShaValues(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(resAddress);
+ }
+
+}
\ No newline at end of file