Migrate a few convertors
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / PacketOutConvertorTest.java
index bdfa74df2048d59e03951f83509eaaaa7601b01c..c6ac7bf526116768a36e8347271908a45b31e3d6 100644 (file)
@@ -5,18 +5,15 @@
  * 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;
@@ -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;
@@ -67,8 +67,6 @@ public class PacketOutConvertorTest {
 
         TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
 
-        Long bufferId = null;
-
         String nodeId = "0";
         String port = "0";
 
@@ -77,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);
@@ -97,8 +94,8 @@ 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());
     }
@@ -124,9 +121,9 @@ public class PacketOutConvertorTest {
                 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";
@@ -160,12 +157,12 @@ public class PacketOutConvertorTest {
         final TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
 
         Short version = (short) 0x04;
-        byte[] datapathIdByte = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        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);
 
         XidConvertorData data = new XidConvertorData(version);
         data.setXid(xid);
@@ -173,8 +170,8 @@ public class PacketOutConvertorTest {
         PacketOutInput message = convert(transmitPacketInput, data);
 
         Assert.assertEquals(transmitPacketInput.getBufferId(), message.getBufferId());
-        Assert.assertEquals(Long.valueOf(inPort), message.getInPort().getValue());
-        Assert.assertEquals(version, message.getVersion());
+        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);
@@ -182,7 +179,7 @@ public class PacketOutConvertorTest {
 
         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());
     }
@@ -203,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());
@@ -214,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);
@@ -239,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, XidConvertorData data) {
+    private PacketOutInput convert(final TransmitPacketInput transmitPacketInput, final XidConvertorData data) {
         Optional<PacketOutInput> messageOptional = convertorManager.convert(transmitPacketInput, data);
         return messageOptional.orElse(PacketOutConvertor.defaultResult(data.getVersion()));
     }