NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / test / java / org / opendaylight / netvirt / elanmanager / tests / Verifications.java
index 9c364f0dbe528d9843402b1051e43a9d36525626..4946d88404aaef289f3f0710cc4cb863af423f4c 100644 (file)
@@ -7,11 +7,9 @@
  */
 package org.opendaylight.netvirt.elanmanager.tests;
 
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
 
 import com.google.common.collect.Sets;
-
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -21,17 +19,17 @@ import java.util.concurrent.ExecutionException;
 import java.util.function.BiPredicate;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-
 import org.awaitility.core.ConditionFactory;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
 import org.opendaylight.genius.testutils.interfacemanager.TunnelInterfaceDetails;
 import org.opendaylight.mdsal.binding.testutils.AssertDataObjects;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -65,12 +63,14 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 public class Verifications {
 
     private static final boolean CHECK_FOR_EXISTS = true;
     private static final boolean CHECK_FOR_DELETED = false;
-    private static final Function<BigInteger, NodeId> GET_OPENFLOW_NODE_ID = (dpnId) -> new NodeId("openflow:" + dpnId);
+    private static final Function<Uint64, NodeId> GET_OPENFLOW_NODE_ID = (dpnId) -> new NodeId("openflow:" + dpnId);
     private static final InstanceIdentifier<ElanInstance> ELAN_IID = InstanceIdentifier
             .builder(ElanInstances.class)
             .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1))
@@ -117,7 +117,7 @@ public class Verifications {
     private boolean checkForRemoteMcastMac(InstanceIdentifier<Node> torNodeId, String tepIp, boolean checkForExists) {
         try {
             Node node = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, torNodeId);
-            HwvtepGlobalAugmentation augmentation = node.getAugmentation(HwvtepGlobalAugmentation.class);
+            HwvtepGlobalAugmentation augmentation = node.augmentation(HwvtepGlobalAugmentation.class);
             if (augmentation == null || augmentation.getRemoteMcastMacs() == null
                     || augmentation.getRemoteMcastMacs().isEmpty()) {
                 if (checkForExists) {
@@ -137,9 +137,9 @@ public class Verifications {
                 }
             }
             if (checkForExists) {
-                return (remoteMcastFoundFlag == true);
+                return remoteMcastFoundFlag == true;
             } else {
-                return (remoteMcastFoundFlag == false);
+                return remoteMcastFoundFlag == false;
             }
         } catch (ReadFailedException e) {
             return false;
@@ -161,7 +161,7 @@ public class Verifications {
     public boolean checkForRemoteUcastMac(InstanceIdentifier<Node> torNodeId, String dpnMac, boolean checkForExists) {
         try {
             Node node = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, torNodeId);
-            HwvtepGlobalAugmentation augmentation = node.getAugmentation(HwvtepGlobalAugmentation.class);
+            HwvtepGlobalAugmentation augmentation = node.augmentation(HwvtepGlobalAugmentation.class);
             if (augmentation == null || augmentation.getRemoteUcastMacs() == null
                     || augmentation.getRemoteUcastMacs().isEmpty()) {
                 if (checkForExists) {
@@ -179,9 +179,9 @@ public class Verifications {
                 }
             }
             if (checkForExists) {
-                return (remoteUcastFoundFlag == true);
+                return remoteUcastFoundFlag == true;
             } else {
-                return (remoteUcastFoundFlag == false);
+                return remoteUcastFoundFlag == false;
             }
         } catch (ReadFailedException e) {
             return false;
@@ -189,17 +189,17 @@ public class Verifications {
     }
 
     private List<Bucket> buildRemoteBcGroupBuckets(ElanInstance elanInfo,
-                                                  List<BigInteger> otherDpns,
+                                                  List<Uint64> otherDpns,
                                                   List<String> otherTors,
-                                                  BigInteger dpnId,
+                                                  Uint64 dpnId,
                                                   int bucketId)
             throws ExecutionException, InterruptedException {
         List<Bucket> listBucketInfo = new ArrayList<>();
         if (otherDpns != null) {
-            for (BigInteger otherDpn : otherDpns) {
+            for (Uint64 otherDpn : otherDpns) {
                 GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
                         .setIntfName(extnIntfs.get(dpnId + ":" + otherDpn).getInterfaceInfo().getInterfaceName())
-                        .setTunnelKey(elanInfo.getElanTag()).build();
+                        .setTunnelKey(elanInfo.getElanTag().longValue() + ElanConstants.ELAN_TAG_ADDEND).build();
                 List<Action> actionsList =
                         odlInterfaceRpcService.getEgressActionsForInterface(getEgressActInput).get().getResult()
                                 .getAction();
@@ -227,28 +227,28 @@ public class Verifications {
         return listBucketInfo;
     }
 
-    private Group buildStandardElanBroadcastGroups(ElanInstance elanInfo, BigInteger dpnId, List<BigInteger> otherdpns,
+    private Group buildStandardElanBroadcastGroups(ElanInstance elanInfo, Uint64 dpnId, List<Uint64> otherdpns,
                                                   List<String> tepIps)
             throws ExecutionException, InterruptedException {
         List<Bucket> listBucket = new ArrayList<>();
         int bucketId = 0;
         int actionKey = 0;
-        Long elanTag = elanInfo.getElanTag();
+        Uint32 elanTag = elanInfo.getElanTag();
         List<Action> listAction = new ArrayList<>();
-        listAction.add(new ActionGroup(ElanUtils.getElanLocalBCGId(elanTag)).buildAction(++actionKey));
+        listAction.add(new ActionGroup(ElanUtils.getElanLocalBCGId(elanTag.longValue())).buildAction(++actionKey));
         listBucket.add(MDSALUtil.buildBucket(listAction, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT,
                 MDSALUtil.WATCH_GROUP));
         bucketId++;
         listBucket.addAll(buildRemoteBcGroupBuckets(elanInfo, otherdpns, tepIps, dpnId, bucketId));
-        long groupId = ElanUtils.getElanRemoteBCGId(elanTag);
+        long groupId = ElanUtils.getElanRemoteBCGId(elanTag.longValue());
         Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll,
                 MDSALUtil.buildBucketLists(listBucket));
         return group;
     }
 
     private boolean validateGroup(ElanInstance actualElanInstances,
-                                 BigInteger dpnId,
-                                 List<BigInteger> otherdpns,
+                                 Uint64 dpnId,
+                                 List<Uint64> otherdpns,
                                  List<String> torips)
             throws ExecutionException, InterruptedException, ReadFailedException, TransactionCommitFailedException {
         Group expected = buildStandardElanBroadcastGroups(actualElanInstances, dpnId, otherdpns, torips);
@@ -270,24 +270,24 @@ public class Verifications {
         return true;
     }
 
-    private Set<Bucket> modifyBucketId(List<Bucket> input) {
+    private static Set<Bucket> modifyBucketId(List<Bucket> input) {
         return input.stream()
                 .map(bucket -> new BucketBuilder(bucket).setBucketId(new BucketId(1L))
-                        .setKey(new BucketKey(new BucketId(1L))).build())
+                        .withKey(new BucketKey(new BucketId(1L))).build())
                 .collect(Collectors.toSet());
     }
 
-    public void verifyThatDpnGroupUpdated(BigInteger dpnId, List<BigInteger> otherdpns, List<String> othertors)
+    public void verifyThatDpnGroupUpdated(Uint64 dpnId, List<Uint64> otherdpns, List<String> othertors)
             throws ReadFailedException, TransactionCommitFailedException, ExecutionException, InterruptedException {
         verifyDPNGroup(dpnId, otherdpns, othertors, CHECK_FOR_EXISTS);
     }
 
-    public void verifyThatDpnGroupDeleted(BigInteger dpnId)
+    public void verifyThatDpnGroupDeleted(Uint64 dpnId)
             throws ReadFailedException, TransactionCommitFailedException, ExecutionException, InterruptedException {
         verifyDPNGroup(dpnId, Collections.emptyList(), Collections.emptyList(), CHECK_FOR_DELETED);
     }
 
-    public void verifyLocalBcGroup(BigInteger dpnId, int expectedNoBuckets)
+    public void verifyLocalBcGroup(Uint64 dpnId, int expectedNoBuckets)
             throws ReadFailedException, TransactionCommitFailedException, ExecutionException, InterruptedException {
         awaiter.until(() -> {
             ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, ELAN_IID);
@@ -302,15 +302,15 @@ public class Verifications {
         });
     }
 
-    public void verifyThatLocalBcGroupDeleted(BigInteger dpnId)
+    public void verifyThatLocalBcGroupDeleted(Uint64 dpnId)
             throws ReadFailedException, TransactionCommitFailedException, ExecutionException, InterruptedException {
         ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, ELAN_IID);
         InstanceIdentifier<Group> grpIid = buildLocalGroupIid(actualElanInstances, dpnId);
         awaitForDataDelete(CONFIGURATION, grpIid);
     }
 
-    public void verifyDPNGroup(BigInteger dpnId,
-                               List<BigInteger> otherdpns,
+    public void verifyDPNGroup(Uint64 dpnId,
+                               List<Uint64> otherdpns,
                                List<String> othertors,
                                boolean checkForExists)
             throws ReadFailedException, TransactionCommitFailedException, ExecutionException, InterruptedException {
@@ -326,27 +326,27 @@ public class Verifications {
         }
     }
 
-    public void verifyThatDmacFlowOfTORCreated(List<BigInteger> dpns,
+    public void verifyThatDmacFlowOfTORCreated(List<Uint64> dpns,
                                                InstanceIdentifier<Node> torNodeId,
                                                List<String> macs) throws ReadFailedException {
         for (String mac : macs) {
-            for (BigInteger srcDpnId : dpns) {
+            for (Uint64 srcDpnId : dpns) {
                 verifyDmacFlowOfTOR(srcDpnId, torNodeId, mac, CHECK_FOR_EXISTS);
             }
         }
     }
 
-    public void verifyThatDmacFlowOfTORDeleted(List<BigInteger> dpns,
+    public void verifyThatDmacFlowOfTORDeleted(List<Uint64> dpns,
                                                InstanceIdentifier<Node> torNodeId,
                                                List<String> macs) throws ReadFailedException {
         for (String mac : macs) {
-            for (BigInteger srcDpnId : dpns) {
+            for (Uint64 srcDpnId : dpns) {
                 verifyDmacFlowOfTOR(srcDpnId, torNodeId, mac, CHECK_FOR_DELETED);
             }
         }
     }
 
-    public void verifyDmacFlowOfTOR(BigInteger srcDpnId,
+    public void verifyDmacFlowOfTOR(Uint64 srcDpnId,
                                     InstanceIdentifier<Node> torNodeIid,
                                     String mac,
                                     boolean checkForExists) throws ReadFailedException {
@@ -358,7 +358,7 @@ public class Verifications {
                         srcDpnId,
                         torNodeId,
                         mac,
-                        actualElanInstances.getElanTag(),
+                        actualElanInstances.getElanTag().toJava(),
                         false));
 
         InstanceIdentifier<Flow> flowIid = getFlowIid(NwConstants.ELAN_DMAC_TABLE, flowId, srcDpnId);
@@ -370,31 +370,27 @@ public class Verifications {
         }
     }
 
-    public void  verifyThatDmacOfOtherDpnCreated(BigInteger srcDpnId, BigInteger dpnId, List<String> dpnMacs)
+    public void  verifyThatDmacOfOtherDpnCreated(Uint64 srcDpnId, Uint64 dpnId, List<String> dpnMacs)
             throws ReadFailedException, InterruptedException {
         for (String dpnMac : dpnMacs) {
             verifyDmacFlowOfOtherDPN(srcDpnId, dpnId, dpnMac, CHECK_FOR_EXISTS);
         }
     }
 
-    public void  verifyThatDmacOfOtherDPNDeleted(BigInteger srcDpnId, BigInteger dpnId, List<String> dpnMacs)
+    public void  verifyThatDmacOfOtherDPNDeleted(Uint64 srcDpnId, Uint64 dpnId, List<String> dpnMacs)
             throws ReadFailedException, InterruptedException {
         for (String dpnMac : dpnMacs) {
             verifyDmacFlowOfOtherDPN(srcDpnId, dpnId, dpnMac, CHECK_FOR_DELETED);
         }
     }
 
-    private void  verifyDmacFlowOfOtherDPN(BigInteger srcDpnId, BigInteger dpnId, String dpnMac, boolean createFlag)
+    private void  verifyDmacFlowOfOtherDPN(Uint64 srcDpnId, Uint64 dpnId, String dpnMac, boolean createFlag)
             throws ReadFailedException, InterruptedException {
         InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
                 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
         ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
         FlowId flowId = new FlowId(
-                ElanUtils.getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE,
-                        srcDpnId,
-                        dpnId,
-                        dpnMac,
-                        actualElanInstances.getElanTag()));
+                ElanUtils.getKnownDynamicmacFlowRef(actualElanInstances.getElanTag(), dpnMac));
         InstanceIdentifier<Flow> flowInstanceIidDst = getFlowIid(NwConstants.ELAN_DMAC_TABLE, flowId, srcDpnId);
         if (createFlag) {
             awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidDst);
@@ -403,25 +399,27 @@ public class Verifications {
         }
     }
 
-    private InstanceIdentifier<Flow> getFlowIid(short tableId, FlowId flowid, BigInteger dpnId) {
+    private static InstanceIdentifier<Flow> getFlowIid(short tableId, FlowId flowid, Uint64 dpnId) {
 
         FlowKey flowKey = new FlowKey(new FlowId(flowid));
         NodeId nodeId = GET_OPENFLOW_NODE_ID.apply(dpnId);
         org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node nodeDpn =
-                new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
+                new NodeBuilder().setId(nodeId).withKey(new NodeKey(nodeId)).build();
         return InstanceIdentifier.builder(Nodes.class)
                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
-                        nodeDpn.getKey()).augmentation(FlowCapableNode.class)
+                        nodeDpn.key()).augmentation(FlowCapableNode.class)
                 .child(Table.class, new TableKey(tableId)).child(Flow.class, flowKey).build();
     }
 
-    private InstanceIdentifier<Group> buildGroupIid(ElanInstance actualElanInstances, BigInteger dpnId) {
+    private static InstanceIdentifier<Group> buildGroupIid(ElanInstance actualElanInstances, Uint64 dpnId) {
         return DpnNodeBuilders.buildGroupInstanceIdentifier(
-                ElanUtils.getElanRemoteBCGId(actualElanInstances.getElanTag()), DpnNodeBuilders.buildDpnNode(dpnId));
+                ElanUtils.getElanRemoteBCGId(actualElanInstances.getElanTag().toJava()),
+                DpnNodeBuilders.buildDpnNode(dpnId));
     }
 
-    private InstanceIdentifier<Group> buildLocalGroupIid(ElanInstance actualElanInstances, BigInteger dpnId) {
+    private static InstanceIdentifier<Group> buildLocalGroupIid(ElanInstance actualElanInstances, Uint64 dpnId) {
         return DpnNodeBuilders.buildGroupInstanceIdentifier(
-                ElanUtils.getElanLocalBCGId(actualElanInstances.getElanTag()), DpnNodeBuilders.buildDpnNode(dpnId));
+                ElanUtils.getElanLocalBCGId(actualElanInstances.getElanTag().toJava()),
+                DpnNodeBuilders.buildDpnNode(dpnId));
     }
 }