--- /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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+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.ActionBuilder;
+
+public class AbstractActionCodecTest {
+
+
+ private ByteBuf buffer;
+ private byte[] bytes = new byte[10];
+
+ private final int msgLength = 10;
+ private final byte subType = 5;
+
+
+ @Before
+ public void setUp() {
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+
+ @Test
+ public void serializeHeaderTest() {
+ AbstractActionCodec.serializeHeader(msgLength, subType, buffer);
+ assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ assertEquals(msgLength, buffer.readUnsignedShort());
+ assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ assertEquals(subType, buffer.readUnsignedShort());
+ }
+
+ @Test
+ public void deserializeHeaderTest() {
+ buffer.writeBytes(bytes);
+ int readerIndex = buffer.readerIndex();
+ ActionBuilder actionBuilder = AbstractActionCodec.deserializeHeader(buffer);
+ assertNotNull(actionBuilder);
+ assertEquals(NiciraConstants.NX_VENDOR_ID, actionBuilder.getExperimenterId().getValue());
+ assertTrue(buffer.readerIndex() - readerIndex == 10);
+ }
+
+}
\ 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 io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.junit.Assert;
+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.ActionConntrack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrackBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.NxActionConntrackBuilder;
+
+public class ConntrackCodecTest {
+
+ private ConntrackCodec conntrackCodec;
+
+ private ByteBuf buffer;
+ private Action action;
+
+ private final int LENGTH = 24;
+ private final byte NXAST_CONNTRACK_SUBTYPE = 35;
+
+ @Before
+ public void setUp() {
+ conntrackCodec = new ConntrackCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ conntrackCodec.serialize(action, buffer);
+
+ Assert.assertEquals(24, buffer.readableBytes());
+ Assert.assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ Assert.assertEquals(LENGTH, buffer.readUnsignedShort());
+ Assert.assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ Assert.assertEquals(NXAST_CONNTRACK_SUBTYPE, buffer.readUnsignedShort());
+ Assert.assertEquals(1, buffer.readUnsignedShort());
+ Assert.assertEquals(2, buffer.readUnsignedInt());
+ Assert.assertEquals(3, buffer.readUnsignedShort());
+ Assert.assertEquals(4, buffer.readByte());
+ buffer.skipBytes(5);
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBufer(buffer);
+ action = conntrackCodec.deserialize(buffer);
+
+ ActionConntrack result = ((ActionConntrack) action.getActionChoice());
+
+ Assert.assertEquals(1, result.getNxActionConntrack().getFlags().shortValue());
+ Assert.assertEquals(2, result.getNxActionConntrack().getZoneSrc().intValue());
+ Assert.assertEquals(3, result.getNxActionConntrack().getConntrackZone().shortValue());
+ Assert.assertEquals(4, result.getNxActionConntrack().getRecircTable().byteValue());
+ Assert.assertEquals(0, buffer.readableBytes());
+
+ }
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder();
+
+ NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder();
+ nxActionConntrackBuilder.setFlags(1);
+ nxActionConntrackBuilder.setZoneSrc((long) 2);
+ nxActionConntrackBuilder.setConntrackZone(3);
+ nxActionConntrackBuilder.setRecircTable((short) 4);
+ actionConntrackBuilder.setNxActionConntrack(nxActionConntrackBuilder.build());
+ actionBuilder.setActionChoice(actionConntrackBuilder.build());
+
+ return actionBuilder.build();
+ }
+
+ private void createBufer(ByteBuf message) {
+ message.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
+ message.writeShort(LENGTH);
+ message.writeInt(NiciraConstants.NX_VENDOR_ID.intValue());
+ message.writeShort(NXAST_CONNTRACK_SUBTYPE);
+ //FLAG = 1
+ message.writeShort(1);
+ //ZONE_SRC = 2
+ message.writeInt(2);
+ //CONNTRACK_ZONE = 3
+ message.writeShort(3);
+ //RECIRC_TABLE = 4
+ message.writeByte(4);
+ //ADDS 5 empty bytes
+ message.writeZero(5);
+ }
+}
\ 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.OfjNxHashFields;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxMpAlgorithm;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionMultipath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionMultipathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.multipath.grouping.NxActionMultipathBuilder;
+
+public class MultipathCodecTest {
+
+ MultipathCodec multipathCodec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 32;
+ private final byte NXAST_MULTIPATH_SUBTYPE = 10;
+
+
+ @Before
+ public void setUp() {
+ multipathCodec = new MultipathCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ multipathCodec.serialize(action, buffer);
+
+ assertEquals(LENGTH, buffer.readableBytes());
+ //SerializeHeaders part
+ assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
+ assertEquals(LENGTH, buffer.readUnsignedShort());
+ assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
+ assertEquals(NXAST_MULTIPATH_SUBTYPE, buffer.readUnsignedShort());
+
+ //Serialize part
+ assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC.ordinal(), buffer.readUnsignedShort());
+ assertEquals(2, buffer.readUnsignedShort());
+ buffer.skipBytes(2);
+ assertEquals(OfjNxMpAlgorithm.NXMPALGMODULON.ordinal(), buffer.readUnsignedShort());
+ assertEquals(4, buffer.readUnsignedShort());
+ assertEquals(5, buffer.readUnsignedInt());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = multipathCodec.deserialize(buffer);
+
+ ActionMultipath result = (ActionMultipath) action.getActionChoice();
+
+ assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC, result.getNxActionMultipath().getFields());
+ assertEquals(1, result.getNxActionMultipath().getBasis().intValue());
+ assertEquals(OfjNxMpAlgorithm.NXMPALGMODULON, result.getNxActionMultipath().getAlgorithm());
+ assertEquals(2, result.getNxActionMultipath().getMaxLink().shortValue());
+ assertEquals(3, result.getNxActionMultipath().getArg().intValue());
+ assertEquals(4, result.getNxActionMultipath().getOfsNbits().shortValue());
+ assertEquals(5, result.getNxActionMultipath().getDst().intValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionMultipathBuilder actionMultipathBuilder = new ActionMultipathBuilder();
+ NxActionMultipathBuilder nxActionMultipathBuilder = new NxActionMultipathBuilder();
+
+ nxActionMultipathBuilder.setFields(OfjNxHashFields.NXHASHFIELDSETHSRC);
+ nxActionMultipathBuilder.setBasis(2);
+
+ nxActionMultipathBuilder.setAlgorithm(OfjNxMpAlgorithm.NXMPALGMODULON);
+ nxActionMultipathBuilder.setMaxLink(4);
+ nxActionMultipathBuilder.setArg((long)5);
+
+
+ nxActionMultipathBuilder.setOfsNbits(6);
+ nxActionMultipathBuilder.setDst((long)7);
+
+
+ actionMultipathBuilder.setNxActionMultipath(nxActionMultipathBuilder.build());
+ actionBuilder.setActionChoice(actionMultipathBuilder.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_MULTIPATH_SUBTYPE);
+
+ //FIELDS = OfjNxHashFields.NXHASHFIELDSETHSRC
+ message.writeShort(OfjNxHashFields.NXHASHFIELDSETHSRC.getIntValue());
+ //BASIS = 1
+ message.writeShort(1);
+ //place 2 empty bytes
+ message.writeZero(2);
+ //Algorithm = OfjNxMpAlgorithm.NXMPALGMODULON
+ message.writeShort(OfjNxMpAlgorithm.NXMPALGMODULON.getIntValue());
+ //MaxLink = 2
+ message.writeShort(2);
+ //Arg = 3
+ message.writeInt(3);
+ //place 2 empty bytes
+ message.writeZero(2);
+ //OfsNbits = 4
+ message.writeShort(4);
+ //Dst = 5
+ message.writeInt(5);
+ }
+}
\ 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.ActionOutputReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.output.reg.grouping.NxActionOutputRegBuilder;
+
+public class OutputRegCodecTest {
+
+ OutputRegCodec outRegCodec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 24;
+ private final byte SUBTYPE = 15;
+ private final byte PADDING = 6;
+
+
+ @Before
+ public void setUp() {
+ outRegCodec = new OutputRegCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ outRegCodec.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(SUBTYPE, buffer.readUnsignedShort());
+
+ //Serialize part
+ assertEquals(1, buffer.readUnsignedShort());
+ assertEquals(2, buffer.readUnsignedInt());
+ assertEquals(3, buffer.readUnsignedShort());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = outRegCodec.deserialize(buffer);
+
+ ActionOutputReg result = (ActionOutputReg) action.getActionChoice();
+
+ assertEquals(1, result.getNxActionOutputReg().getNBits().shortValue());
+ assertEquals(2, result.getNxActionOutputReg().getSrc().intValue());
+ assertEquals(3, result.getNxActionOutputReg().getMaxLen().shortValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionOutputRegBuilder actionOutputRegBuilder = new ActionOutputRegBuilder();
+ NxActionOutputRegBuilder nxActionOutputBuilder = new NxActionOutputRegBuilder();
+
+ nxActionOutputBuilder.setNBits(1);
+ nxActionOutputBuilder.setSrc((long)2);
+ nxActionOutputBuilder.setMaxLen(3);
+
+ actionOutputRegBuilder.setNxActionOutputReg(nxActionOutputBuilder.build());
+ actionBuilder.setActionChoice(actionOutputRegBuilder.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(SUBTYPE);
+
+ message.writeShort(1);
+ message.writeInt(2);
+ message.writeShort(3);
+ 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 java.math.BigInteger;
+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.ActionRegLoad;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegLoadBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.NxActionRegLoadBuilder;
+
+public class RegLoadCodecTest {
+
+ RegLoadCodec regLoadCodec;
+ ByteBuf buffer;
+ Action action;
+
+ private final int LENGTH = 24;
+ private final byte SUBTYPE = 7;
+
+ @Before
+ public void setUp() {
+ regLoadCodec = new RegLoadCodec();
+ buffer = ByteBufAllocator.DEFAULT.buffer();
+ }
+
+ @Test
+ public void serializeTest() {
+ action = createAction();
+ regLoadCodec.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(SUBTYPE, buffer.readUnsignedShort());
+ //Serialize part
+ assertEquals(1, buffer.readUnsignedShort());
+ assertEquals(2, buffer.readUnsignedInt());
+ assertEquals(3, buffer.readLong());
+ }
+
+ @Test
+ public void deserializeTest() {
+ createBuffer(buffer);
+
+ action = regLoadCodec.deserialize(buffer);
+
+ ActionRegLoad result = (ActionRegLoad) action.getActionChoice();
+
+ assertEquals(1, result.getNxActionRegLoad().getOfsNbits().shortValue());
+ assertEquals(2, result.getNxActionRegLoad().getDst().longValue());
+ assertEquals(3, result.getNxActionRegLoad().getValue().longValue());
+ assertEquals(0, buffer.readableBytes());
+ }
+
+ private Action createAction() {
+ ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setExperimenterId(experimenterId);
+ ActionRegLoadBuilder actionRegLoadBuilder = new ActionRegLoadBuilder();
+ NxActionRegLoadBuilder nxActionRegLoadBuilder = new NxActionRegLoadBuilder();
+
+ nxActionRegLoadBuilder.setOfsNbits(1);
+ nxActionRegLoadBuilder.setDst((long)2);
+ nxActionRegLoadBuilder.setValue(BigInteger.valueOf(3));
+
+ actionRegLoadBuilder.setNxActionRegLoad(nxActionRegLoadBuilder.build());
+ actionBuilder.setActionChoice(actionRegLoadBuilder.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(SUBTYPE);
+
+ message.writeShort(1);
+ message.writeInt(2);
+ message.writeLong(3);
+ }
+
+}
\ No newline at end of file