NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / test / java / org / opendaylight / netvirt / elanmanager / tests / Verifications.java
index 0b6b35ac0785f381101914c500b49548e43f20f9..4946d88404aaef289f3f0710cc4cb863af423f4c 100644 (file)
@@ -7,10 +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,15 +20,16 @@ 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;
@@ -63,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))
@@ -187,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();
@@ -225,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);
@@ -275,17 +277,17 @@ public class Verifications {
                 .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);
@@ -300,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 {
@@ -324,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 {
@@ -356,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);
@@ -368,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);
@@ -401,7 +399,7 @@ public class Verifications {
         }
     }
 
-    private static 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);
@@ -413,13 +411,15 @@ public class Verifications {
                 .child(Table.class, new TableKey(tableId)).child(Flow.class, flowKey).build();
     }
 
-    private static 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 static 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));
     }
 }