Misc fixes in vpnservice
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / NexthopManager.java
index ce11c4d4b19367b93502dac4193f2c93b98d2318..571cdce3ad91cce5a23fa109fd5d88cb9d46a805 100644 (file)
@@ -64,7 +64,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     private static final FutureCallback<Void> DEFAULT_CALLBACK =
         new FutureCallback<Void>() {
             public void onSuccess(Void result) {
-                LOG.info("Success in Datastore write operation");
+                LOG.debug("Success in Datastore write operation");
             }
             public void onFailure(Throwable error) {
                 LOG.error("Error in Datastore write operation", error);
@@ -159,13 +159,15 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         long vpnId = getVpnId(vpnName);
         long dpnId = interfaceManager.getDpnForInterface(ifName);
         VpnNexthop nexthop = getVpnNexthop(vpnId, ipAddress);
+        LOG.trace("nexthop: {}", nexthop);
         if (nexthop == null) {
             List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
             List<ActionInfo> listActionInfo = interfaceManager.getInterfaceEgressActions(ifName);
             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.
             }
@@ -229,7 +231,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);
         asyncWrite(LogicalDatastoreType.OPERATIONAL, id1, nh, DEFAULT_CALLBACK);
 
     }
@@ -336,17 +338,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 +364,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 {
@@ -378,6 +383,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         GetEgressPointerOutputBuilder output = new GetEgressPointerOutputBuilder();
 
         String endpointIp = interfaceManager.getEndpointIpForDpn(input.getDpnId());
+        LOG.trace("getEgressPointer: input {}, endpointIp {}", input, endpointIp);
         if (input.getNexthopIp().equals(endpointIp)) {
             VpnNexthop vpnNextHop = getVpnNexthop(input.getVpnId(), input.getIpPrefix());
             output.setEgressPointer(vpnNextHop.getEgressPointer());
@@ -424,4 +430,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());
+    }
+
 }