Merge "Fix for Bug 3387 - Delete VPN should clear corresponding VrfTable in FIB DS"
authorVivek Srivastava <vivek.v.srivastava@ericsson.com>
Tue, 2 Jun 2015 14:32:49 +0000 (14:32 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 2 Jun 2015 14:32:49 +0000 (14:32 +0000)
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/BgpManager.java
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/FibDSWriter.java

index d8e387e..5508541 100644 (file)
@@ -238,12 +238,15 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
     @Override
     public void deleteVrf(String rd) throws Exception {
-        if(bgpThriftClient == null) {
-            LOGGER.info("Delete BGP vrf - bgpThriftClient is null. Unable to delete BGP vrf.");
+        if(bgpThriftClient == null || !hasBgpServiceStarted) {
+            LOGGER.debug("Delete BGP vrf - Unable to delete BGP vrf in BGP Server. Removing Vrf from local DS");
+            fibDSWriter.removeVrfFromDS(rd);
             return;
         }
+
         try {
             bgpThriftClient.delVrf(rd);
+            fibDSWriter.removeVrfFromDS(rd);
         } catch (BgpRouterException b) {
             LOGGER.error("Failed to delete BGP vrf " + rd + "due to BgpRouter Exception number " + b.getErrorCode());
             LOGGER.debug("BgpRouterException trace ", b);
index 496f3cf..0a0415f 100644 (file)
@@ -71,6 +71,18 @@ public class FibDSWriter {
 
     }
 
+    public synchronized void removeVrfFromDS(String rd) {
+        logger.debug("Removing vrf table for rd {}", rd);
+
+        InstanceIdentifierBuilder<VrfTables> idBuilder =
+                InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
+        InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
+
+        delete(LogicalDatastoreType.CONFIGURATION, vrfTableId);
+
+    }
+
+
     private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
                                                     InstanceIdentifier<T> path) {