Added unit tests for NextHopManager
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / NexthopManager.java
index 571cdce3ad91cce5a23fa109fd5d88cb9d46a805..8ea89397fcce4f331d70f43b8fd407fc95b638af 100644 (file)
@@ -106,6 +106,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             .build();
         //TODO: Error handling
         Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
+        LOG.trace("NextHopPointerPool result : {}", result);
 //            try {
 //                LOG.info("Result2: {}",result.get());
 //            } catch (InterruptedException | ExecutionException e) {
@@ -116,7 +117,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     }
 
 
-    private long getVpnId(String vpnName) {
+    protected long getVpnId(String vpnName) {
         InstanceIdentifierBuilder<VpnInstance> idBuilder = InstanceIdentifier.builder(VpnInstances.class)
                 .child(VpnInstance.class, new VpnInstanceKey(vpnName));
 
@@ -125,6 +126,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         Optional<VpnInstance1> vpn = read(LogicalDatastoreType.OPERATIONAL, idx);
 
         if (vpn.isPresent()) {
+            LOG.debug("VPN id returned: {}", vpn.get().getVpnId());
             return vpn.get().getVpnId();
         } else {
             return -1;
@@ -134,10 +136,11 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     private long getDpnId(String ifName) {
         String[] fields = ifName.split(":");
         long dpn = Integer.parseInt(fields[1]);
+        LOG.debug("DpnId: {}", dpn);
         return dpn;
     }
 
-    private int createNextHopPointer(String nexthopKey) {
+    protected int createNextHopPointer(String nexthopKey) {
         GetUniqueIdInput getIdInput = new GetUniqueIdInputBuilder()
             .setPoolName("nextHopPointerPool").setIdKey(nexthopKey)
             .build();
@@ -167,9 +170,10 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             // MAC re-write
             if (macAddress != null) {
                listActionInfo.add(0, new ActionInfo(ActionType.set_field_eth_dest, new String[]{macAddress}));
-               listActionInfo.add(new ActionInfo(ActionType.pop_mpls, new String[]{}));
+               listActionInfo.add(0, new ActionInfo(ActionType.pop_mpls, new String[]{}));
             } else {
                 //FIXME: Log message here.
+                LOG.debug("mac address for new local nexthop is null");
             }
             listBucketInfo.add(bucket);
             GroupEntity groupEntity = MDSALUtil.buildGroupEntity(
@@ -209,7 +213,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         }
     }
 
-    private void addVpnNexthopToDS(long vpnId, String ipPrefix, long egressPointer) {
+    protected void addVpnNexthopToDS(long vpnId, String ipPrefix, long egressPointer) {
 
         InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
                 .child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
@@ -231,7 +235,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
         InstanceIdentifier<VpnNexthop> id1 = idBuilder
                 .child(VpnNexthop.class, new VpnNexthopKey(ipPrefix)).build();
-        LOG.trace("Adding nextHop {} to Operational DS", nh);
+        LOG.trace("Adding vpnnextHop {} to Operational DS", nh);
         asyncWrite(LogicalDatastoreType.OPERATIONAL, id1, nh, DEFAULT_CALLBACK);
 
     }
@@ -249,6 +253,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
                 .setKey(new TunnelNexthopsKey(dpnId))
                 .setDpnId(dpnId)
                 .build();
+            LOG.trace("Adding tunnelnextHop {} to Operational DS for a new node", node);
             asyncWrite(LogicalDatastoreType.OPERATIONAL, id, node, DEFAULT_CALLBACK);
         }
 
@@ -260,12 +265,12 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
         InstanceIdentifier<TunnelNexthop> id1 = idBuilder
                 .child(TunnelNexthop.class, new TunnelNexthopKey(ipPrefix)).build();
-
+        LOG.trace("Adding tunnelnextHop {} to Operational DS for a dpn node", nh);
         asyncWrite(LogicalDatastoreType.OPERATIONAL, id1, nh, DEFAULT_CALLBACK);
 
     }
 
-    private VpnNexthop getVpnNexthop(long vpnId, String ipAddress) {
+    protected VpnNexthop getVpnNexthop(long vpnId, String ipAddress) {
 
         // check if vpn node is there 
         InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
@@ -279,6 +284,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             for (VpnNexthop nexthop : nexthops) {
                 if (nexthop.getIpAddress().equals(ipAddress)) {
                     // return nexthop 
+                    LOG.trace("VpnNextHop : {}",nexthop);
                     return nexthop;
                 }
             }
@@ -299,6 +305,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             List<TunnelNexthop> nexthops = dpnNexthops.get().getTunnelNexthop();
             for (TunnelNexthop nexthop : nexthops) {
                 if (nexthop.getIpAddress().equals(ipAddress)) {
+                    LOG.trace("TunnelNextHop : {}",nexthop);
                     return nexthop;
                 }
             }
@@ -313,6 +320,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             return vpnNextHop.getEgressPointer();
         } else {
             TunnelNexthop tunnelNextHop = getTunnelNexthop(dpnId, nextHopIp);
+            LOG.trace("NExtHopPointer : {}", tunnelNextHop.getEgressPointer());
             return tunnelNextHop.getEgressPointer();
         }
     }
@@ -324,6 +332,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
                 .child(TunnelNexthop.class, new TunnelNexthopKey(ipPrefix));
         InstanceIdentifier<TunnelNexthop> id = idBuilder.build();
         // remove from DS     
+        LOG.trace("Removing tunnel next hop from datastore : {}", id);
         delete(LogicalDatastoreType.OPERATIONAL, id);
     }
 
@@ -334,6 +343,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
                 .child(VpnNexthop.class, new VpnNexthopKey(ipPrefix));
         InstanceIdentifier<VpnNexthop> id = idBuilder.build();
         // remove from DS
+        LOG.trace("Removing vpn next hop from datastore : {}", id);
         delete(LogicalDatastoreType.OPERATIONAL, id);
     }
 
@@ -352,6 +362,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             removeVpnNexthopFromDS(vpnId, ipAddress);
         } else {
             //throw error
+            LOG.error("removal of local next hop failed");
         }
 
     }
@@ -372,6 +383,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             removeTunnelNexthopFromDS(dpnId, ipAddress);
         } else {
             //throw error
+            LOG.error("removal of remote next hop failed : dpnid : {}, ipaddress : {}", dpnId, ipAddress);
         }
 
     }