Changes to NextHopManager
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / NexthopManager.java
index c9fee48716f391c0717b0f77db162d4be176c28f..a8f411c7ddb301a471b71d0bb1da7476daaa921d 100644 (file)
@@ -165,7 +165,8 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             BucketInfo bucket = new BucketInfo(listActionInfo);
             // MAC re-write
             if (macAddress != null) {
-                listActionInfo.add(new ActionInfo(ActionType.set_field_eth_dest, new String[]{macAddress}));
+               listActionInfo.add(0, new ActionInfo(ActionType.set_field_eth_dest, new String[]{macAddress}));
+               listActionInfo.add(new ActionInfo(ActionType.pop_mpls, new String[]{}));
             } else {
                 //FIXME: Log message here.
             }
@@ -214,7 +215,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
         // check if vpn node is there or to be created
         InstanceIdentifier<VpnNexthops> id = idBuilder.build();
-        Optional<VpnNexthops> nexthops = read(LogicalDatastoreType.CONFIGURATION, id);
+        Optional<VpnNexthops> nexthops = read(LogicalDatastoreType.OPERATIONAL, id);
         if (!nexthops.isPresent()) {
             // create a new node
             VpnNexthops node = new VpnNexthopsBuilder().setKey(new VpnNexthopsKey(vpnId)).setVpnId(vpnId).build();
@@ -240,7 +241,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
         // check if dpn node is there or to be created
         InstanceIdentifier<TunnelNexthops> id = idBuilder.build();
-        Optional<TunnelNexthops> nexthops = read(LogicalDatastoreType.CONFIGURATION, id);
+        Optional<TunnelNexthops> nexthops = read(LogicalDatastoreType.OPERATIONAL, id);
         if (!nexthops.isPresent()) {
             // create a new node
             TunnelNexthops node = new TunnelNexthopsBuilder()
@@ -269,8 +270,8 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
                 .child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
         InstanceIdentifier<VpnNexthops> id = idBuilder.build();
-        Optional<VpnNexthops> vpnNexthops = read(LogicalDatastoreType.CONFIGURATION, id);
-        if (!vpnNexthops.isPresent()) {
+        Optional<VpnNexthops> vpnNexthops = read(LogicalDatastoreType.OPERATIONAL, id);
+        if (vpnNexthops.isPresent()) {
 
             // get nexthops list for vpn
             List<VpnNexthop> nexthops = vpnNexthops.get().getVpnNexthop();
@@ -292,8 +293,8 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
         // check if vpn node is there 
         InstanceIdentifier<TunnelNexthops> id = idBuilder.build();
-        Optional<TunnelNexthops> dpnNexthops = read(LogicalDatastoreType.CONFIGURATION, id);
-        if (!dpnNexthops.isPresent()) {
+        Optional<TunnelNexthops> dpnNexthops = read(LogicalDatastoreType.OPERATIONAL, id);
+        if (dpnNexthops.isPresent()) {
             List<TunnelNexthop> nexthops = dpnNexthops.get().getTunnelNexthop();
             for (TunnelNexthop nexthop : nexthops) {
                 if (nexthop.getIpAddress().equals(ipAddress)) {
@@ -336,17 +337,16 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     }
 
  
-    public void removeLocalNextHop(String vpnName, String ipAddress) {
-
-        long vpnId = getVpnId(vpnName);
+    public void removeLocalNextHop(Long dpId, Long vpnId, String ipAddress) {
 
         VpnNexthop nh = getVpnNexthop(vpnId, ipAddress);
         if (nh != null) {
             // how to inform and remove dependent FIB entries??
             // we need to do it before the group is removed
-            
+            GroupEntity groupEntity = MDSALUtil.buildGroupEntity(
+                    dpId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupIndirect, null);
             // remove Group ...
-            
+            mdsalManager.removeGroup(groupEntity);
             //update MD-SAL DS
             removeVpnNexthopFromDS(vpnId, ipAddress);
         } else {
@@ -363,6 +363,10 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             // we need to do it before the group is removed
 
             // remove Group ...
+            GroupEntity groupEntity = MDSALUtil.buildGroupEntity(
+                    dpnId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupIndirect, null);
+            // remove Group ...
+            mdsalManager.removeGroup(groupEntity);
             //update MD-SAL DS
             removeTunnelNexthopFromDS(dpnId, ipAddress);
         } else {
@@ -424,4 +428,20 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         Futures.addCallback(tx.submit(), DEFAULT_CALLBACK);
     }
 
+    @Override
+    public Future<RpcResult<Void>> removeLocalNextHop(RemoveLocalNextHopInput input) {
+        VpnNexthop vpnNextHop = getVpnNexthop(input.getVpnId(), input.getIpPrefix());
+        RpcResultBuilder<Void> rpcResultBuilder;
+        LOG.debug("vpnnexthop is: {}", vpnNextHop);
+        try {
+            removeLocalNextHop(input.getDpnId(),input.getVpnId(), input.getIpPrefix());
+            rpcResultBuilder = RpcResultBuilder.success();
+        }
+        catch(Exception e){
+            LOG.error("Removal of local next hop for vpnNextHop {} failed {}" ,vpnNextHop, e);
+            rpcResultBuilder = RpcResultBuilder.failed();
+        }
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
 }