Migrate a few convertors
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / PacketOutConvertorTest.java
index 99c12884766ba7b6b3d0b5bf4b08d01e33c17eb9..c6ac7bf526116768a36e8347271908a45b31e3d6 100644 (file)
@@ -5,22 +5,19 @@
  * 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.openflowplugin.openflow.md.core.sal.convertor;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.XidConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
@@ -44,11 +41,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.Co
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Created by Jakub Toth jatoth@cisco.com on 9/23/14.
  */
-
 public class PacketOutConvertorTest {
 
     private ConvertorManager convertorManager;
@@ -59,15 +59,14 @@ public class PacketOutConvertorTest {
     }
 
     /**
-     * Test for {@link PacketOutConvertor} with null parameters.
+     * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor}
+     *  with null parameters.
      */
     @Test
     public void toPacketOutInputAllParmNullTest() {
 
         TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
 
-        Long bufferId = null;
-
         String nodeId = "0";
         String port = "0";
 
@@ -76,9 +75,8 @@ public class PacketOutConvertorTest {
         NodeConnectorRef egressConfRef = new NodeConnectorRef(
                 createNodeConnRef(nodeId, nodeConnKey));
 
-        transmitPacketInputBuilder.setBufferId(bufferId);
+        transmitPacketInputBuilder.setBufferId((Uint32) null);
         transmitPacketInputBuilder.setConnectionCookie(null);
-        transmitPacketInputBuilder.setAction(null);
         transmitPacketInputBuilder.setNode(ref);
         transmitPacketInputBuilder.setPayload(null);
         transmitPacketInputBuilder.setEgress(egressConfRef);
@@ -88,7 +86,7 @@ public class PacketOutConvertorTest {
 
         Short version = (short) 0x04;
         Long xid = null;
-        PacketOutConvertorData data = new PacketOutConvertorData(version);
+        XidConvertorData data = new XidConvertorData(version);
         PacketOutInput message = convert(transmitPacketInput, data);
 
         //FIXME : this has to be fixed along with actions changed in openflowjava
@@ -96,14 +94,14 @@ public class PacketOutConvertorTest {
         Assert.assertEquals(buildActionForNullTransmitPacketInputAction(nodeConnKey, version), message.getAction());
 
         Assert.assertEquals(OFConstants.OFP_NO_BUFFER, message.getBufferId());
-        Assert.assertEquals(new PortNumber(0xfffffffdL), message.getInPort());
-        Assert.assertEquals(version, message.getVersion());
+        Assert.assertEquals(new PortNumber(Uint32.valueOf(0xfffffffdL)), message.getInPort());
+        Assert.assertEquals(Uint8.valueOf(version), message.getVersion());
         Assert.assertEquals(xid, message.getXid());
         Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
     }
 
     /**
-     * Test for PacketOutConvertor.
+     * Test for XidConvertorData.
      */
     @Test
     public void toPacketOutInputAllParmTest() {
@@ -117,15 +115,15 @@ public class PacketOutConvertorTest {
         ab.setAction(new OutputActionCaseBuilder().setOutputAction(
                 output.build()).build());
         ab.setOrder(0);
-        ab.setKey(new ActionKey(0));
+        ab.withKey(new ActionKey(0));
 
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList =
                 new ArrayList<>();
         actionList.add(ab.build());
 
-        Long bufferId = 0xfL;
+        final Uint32 bufferId = Uint32.valueOf(0xf);
 
-        Long valueForCookie = 0xeL;
+        final Uint32 valueForCookie = Uint32.valueOf(0xe);
         ConnectionCookie connCook = new ConnectionCookie(valueForCookie);
 
         String nodeId = "node:1";
@@ -158,34 +156,30 @@ public class PacketOutConvertorTest {
 
         final TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
 
-        short version = (short) 0x04;
-        byte[] datapathIdByte = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        Short version = (short) 0x04;
+        byte[] datapathIdByte = new byte[Long.BYTES];
         for (int i = 0; i < datapathIdByte.length; i++) {
             datapathIdByte[i] = 1;
         }
-        BigInteger datapathId = new BigInteger(1, datapathIdByte);
-        Long xid = 0xfffffL;
+        Uint64 datapathId = Uint64.valueOf(new BigInteger(1, datapathIdByte));
+        Uint32 xid = Uint32.valueOf(0xfffffL);
 
-        PacketOutConvertorData data = new PacketOutConvertorData(version);
+        XidConvertorData data = new XidConvertorData(version);
         data.setXid(xid);
         data.setDatapathId(datapathId);
         PacketOutInput message = convert(transmitPacketInput, data);
 
-        Assert.assertEquals(transmitPacketInput.getBufferId(),
-                message.getBufferId());
-        Assert.assertEquals("PortNumber [_value=" + inPort + "]", message
-                .getInPort().toString());
-        Assert.assertEquals((Object) version,
-                Short.valueOf(message.getVersion()));
+        Assert.assertEquals(transmitPacketInput.getBufferId(), message.getBufferId());
+        Assert.assertEquals(Uint32.valueOf(inPort), message.getInPort().getValue());
+        Assert.assertEquals(Uint8.valueOf(version), message.getVersion());
         Assert.assertEquals(xid, message.getXid());
 
         ActionConvertorData actionConvertorData = new ActionConvertorData(version);
         actionConvertorData.setDatapathId(datapathId);
 
-        Optional<List<Action>> actionsOptional = convertorManager.convert(
-                actionList, actionConvertorData);
+        Optional<List<Action>> actionsOptional = convertorManager.convert(actionList, actionConvertorData);
 
-        List<Action> actions = actionsOptional.orElse(Collections.emptyList());
+        List<Action> actions = actionsOptional.orElse(null);
         Assert.assertEquals(actions, message.getAction());
         Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
     }
@@ -206,7 +200,7 @@ public class PacketOutConvertorTest {
                     .action.choice.output.action._case.OutputActionBuilder();
 
         outputActionBuilder.setPort(outPort);
-        outputActionBuilder.setMaxLength(0xffff);
+        outputActionBuilder.setMaxLength(Uint16.MAX_VALUE);
         outputActionCaseBuilder.setOutputAction(outputActionBuilder.build());
         ActionBuilder actionBuilder = new ActionBuilder();
         actionBuilder.setActionChoice(outputActionCaseBuilder.build());
@@ -217,17 +211,17 @@ public class PacketOutConvertorTest {
     }
 
     private static PortNumber getPortNumber(final NodeConnectorKey nodeConKey, final Short ofVersion) {
-        Long port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.get(ofVersion),
+        Uint32 port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.get(ofVersion),
                 nodeConKey.getId());
         return new PortNumber(port);
     }
 
     private static NodeConnectorRef createNodeConnRef(final String nodeId, final NodeConnectorKey nodeConKey) {
         InstanceIdentifier<NodeConnector> path = InstanceIdentifier
-                .<Nodes>builder(Nodes.class)
-                .<Node, NodeKey>child(Node.class,
+                .builder(Nodes.class)
+                .child(Node.class,
                         new NodeKey(new NodeId(nodeId)))
-                .<NodeConnector, NodeConnectorKey>child(NodeConnector.class,
+                .child(NodeConnector.class,
                         nodeConKey).build();
 
         return new NodeConnectorRef(path);
@@ -242,12 +236,12 @@ public class PacketOutConvertorTest {
     private static NodeRef createNodeRef(final String nodeId) {
         NodeKey key = new NodeKey(new NodeId(nodeId));
         InstanceIdentifier<Node> path = InstanceIdentifier
-                .<Nodes>builder(Nodes.class)
-                .<Node, NodeKey>child(Node.class, key).build();
+                .builder(Nodes.class)
+                .child(Node.class, key).build();
         return new NodeRef(path);
     }
 
-    private PacketOutInput convert(TransmitPacketInput transmitPacketInput, PacketOutConvertorData data) {
+    private PacketOutInput convert(final TransmitPacketInput transmitPacketInput, final XidConvertorData data) {
         Optional<PacketOutInput> messageOptional = convertorManager.convert(transmitPacketInput, data);
         return messageOptional.orElse(PacketOutConvertor.defaultResult(data.getVersion()));
     }