BGP forward porting & Update source enhancement. 00/86800/7
authormanjunath.hethur <manjunath.hethur@gmail.com>
Wed, 8 Jan 2020 04:53:58 +0000 (10:23 +0530)
committerChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Wed, 1 Apr 2020 11:01:39 +0000 (11:01 +0000)
JIRA: NETVIRT-1657

Signed-off-by: manjunath.hethur <manjunath.hethur@gmail.com>
Change-Id: If472fe4a0c20b6137c02684de0c3899f1d2e4007

bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/BgpConfigurationManager.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpAlarms.java

index 6ddf2370300aef2615d6c9ea1ce91b5018033467..32bfdd2fc1fc699e367dac71e688290e1bac26ff 100755 (executable)
@@ -61,6 +61,7 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.infrautils.metrics.MetricProvider;
@@ -200,6 +201,7 @@ public class BgpConfigurationManager implements EbgpService {
     private static final String UPD_WARN = "Update operation not supported; Config store updated;"
             + " restore with another Update if needed.";
     private static long bgp_as_num = 0;
+    private static List<Neighbors> nbrList = new ArrayList<>();
     private int bgpKaTime = 0;
     private int bgpHoldTime = 0;
     private int bgpGrRestartTime = 0;
@@ -877,12 +879,21 @@ public class BgpConfigurationManager implements EbgpService {
 
         @Override
         protected void add(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+            if (nbrList != null && !nbrList.contains(val)) {
+                LOG.trace("Adding nbr {} to nbrlist", val.getAddress().getValue());
+                nbrList.add(val);
+            }
             if (!isBGPEntityOwner()) {
                 return;
             }
             LOG.debug("received add Neighbors config val {}", val.getAddress().getValue());
             synchronized (BgpConfigurationManager.this) {
                 String peerIp = val.getAddress().getValue();
+                String sourceIp = (val.getUpdateSource() == null) ? null :
+                                    val.getUpdateSource().getSourceIp().getValue();
+                int nhops = (val.getEbgpMultihop() == null) ? 0 :
+                                    val.getEbgpMultihop().getNhops().intValue();
+                List<AddressFamilies> afs = val.getAddressFamilies();
                 long as = val.getRemoteAs().toJava();
                 final String md5Secret = extractMd5Secret(val);
                 BgpRouter br = getClient(YANG_OBJ);
@@ -894,6 +905,19 @@ public class BgpConfigurationManager implements EbgpService {
                 try {
                     //itmProvider.buildTunnelsToDCGW(new IpAddress(peerIp.toCharArray()));
                     br.addNeighbor(peerIp, as, md5Secret);
+                    if (nhops != 0) {
+                        br.addEbgpMultihop(peerIp, nhops);
+                    }
+                    if (sourceIp != null) {
+                        br.addUpdateSource(peerIp, sourceIp);
+                    }
+                    if (afs != null) {
+                        for (AddressFamilies af : afs) {
+                            af_afi afi = af_afi.findByValue(af.getAfi().intValue());
+                            af_safi safi = af_safi.findByValue(af.getSafi().intValue());
+                            br.addAddressFamily(af.getPeerIp().getValue(), afi, safi);
+                        }
+                    }
 
                 } catch (TException | BgpRouterException e) {
                     LOG.error("{} Add received exception; {}", YANG_OBJ, ADD_WARN, e);
@@ -913,6 +937,10 @@ public class BgpConfigurationManager implements EbgpService {
 
         @Override
         protected void remove(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+            if (nbrList != null && nbrList.contains(val)) {
+                LOG.trace("Removing nbr {} from nbr list", val.getAddress().getValue());
+                nbrList.remove(val);
+            }
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1823,7 +1851,13 @@ public class BgpConfigurationManager implements EbgpService {
     public long getStalePathtime(int defValue, AsId asId) {
         long spt = 0;
         try {
-            spt = getConfig().getGracefulRestart().getStalepathTime().toJava();
+            InstanceIdentifier<GracefulRestart> id =
+                    InstanceIdentifier.create(Bgp.class).child(GracefulRestart.class);
+            Optional<GracefulRestart> gracefulRestartOptional = MDSALUtil.read(dataBroker,
+                    LogicalDatastoreType.CONFIGURATION, id);
+            if (gracefulRestartOptional.isPresent()) {
+                spt = gracefulRestartOptional.get().getStalepathTime().toJava();
+            }
         } catch (NullPointerException e) {
             try {
                 spt = asId.getStalepathTime().toJava();
@@ -3198,6 +3232,10 @@ public class BgpConfigurationManager implements EbgpService {
         return totalCleared;
     }
 
+    public static List<Neighbors> getNbrList() {
+        return nbrList;
+    }
+
     public BgpCounters getBgpCounters() {
         return bgpCountersReference.get();
     }
index 02ca736050b680c3bf5549883da258a1410a5bf8..fa0a3719080156e468aa156ee1b1c0fa96856667 100644 (file)
@@ -26,6 +26,7 @@ public class BgpAlarms implements Runnable, AutoCloseable {
     private final BgpJMXAlarmAgent alarmAgent = new BgpJMXAlarmAgent();
     private final BgpConfigurationManager bgpMgr;
     private final Map<String, BgpAlarmStatus> neighborsRaisedAlarmStatusMap = new ConcurrentHashMap<>();
+    private volatile List<Neighbors> nbrList = null;
 
     public BgpAlarms(BgpConfigurationManager bgpManager) {
         bgpMgr = Objects.requireNonNull(bgpManager);
@@ -53,7 +54,6 @@ public class BgpAlarms implements Runnable, AutoCloseable {
 
     @Override
     public void run() {
-        List<Neighbors> nbrList = null;
         LOG.debug("Fetching neighbor status' from BGP");
         BgpCounters.resetFile(BgpCounters.BGP_VPNV4_SUMMARY_FILE);
         BgpCounters.resetFile(BgpCounters.BGP_VPNV6_SUMMARY_FILE);