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 d8e387eaf58e52478b4e2d215045a37b2bf8bcf3..55085413eecf3c775373a8bc1af0a1c43d79a338 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 496f3cfa847b356c4cd9090373a8eac090177ca1..0a0415fde9a555e8486684d4c5e412ba702f2821 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) {