@@ -188,7 +188,7 @@ def set_bfd_session_into_appl_db(self, key, data):
188
188
log_debug ("set bfd session to appl_db, key %s, data %s" % (key , str (data )))
189
189
190
190
def del_bfd_session_from_appl_db (self , key ):
191
- self .appl_db .delete ("BFD_SESSION_TABLE:{}" . format ( key ) )
191
+ self .bfd_appl_tbl .delete (key )
192
192
193
193
def interface_set_handler (self , key , data ):
194
194
valid , is_ipv4 , if_name , ip = self .get_ip_from_key (key )
@@ -202,7 +202,7 @@ def interface_set_handler(self, key, data):
202
202
self .set_local_db (LOCAL_INTERFACE_TABLE , if_name , value )
203
203
return True
204
204
205
- def interface_del_handler (self , key , data ):
205
+ def interface_del_handler (self , key ):
206
206
valid , is_ipv4 , if_name , ip = self .get_ip_from_key (key )
207
207
if not valid :
208
208
return True
@@ -304,6 +304,28 @@ def check_skip(self, bfd_enable):
304
304
return False
305
305
return True
306
306
307
+ def refresh_active_nh (self , route_cfg_key ):
308
+ data = self .get_local_db (LOCAL_CONFIG_TABLE , route_cfg_key )
309
+
310
+ arg_list = lambda v : v .split (',' ) if len (v .strip ()) != 0 else None
311
+ nh_list = arg_list (data ['nexthop' ]) if 'nexthop' in data else None
312
+ nh_vrf_list = arg_list (data ['nexthop-vrf' ]) if 'nexthop-vrf' in data else None
313
+
314
+ for index in range (len (nh_list )):
315
+ nh_ip = nh_list [index ]
316
+ nh_vrf = nh_vrf_list [index ]
317
+ nh_key = nh_vrf + "|" + nh_ip
318
+ bfd_key = nh_vrf + ":default:" + nh_ip
319
+
320
+ bfd_session = self .get_local_db (LOCAL_BFD_TABLE , bfd_key )
321
+ if len (bfd_session ) == 0 :
322
+ continue
323
+ if "state" in bfd_session and bfd_session ["state" ].upper () == "UP" :
324
+ self .append_to_sr_table_entry (route_cfg_key , (nh_vrf , nh_ip ))
325
+
326
+ new_config = self .reconstruct_static_route_config (data , self .get_local_db (LOCAL_SR_TABLE , route_cfg_key ))
327
+ self .set_static_route_into_appl_db (route_cfg_key .replace ("|" , ":" ), new_config )
328
+
307
329
def static_route_set_handler (self , key , data ):
308
330
global ROUTE_ADVERTISE_ENABLE_TAG
309
331
global ROUTE_ADVERTISE_DISABLE_TAG
@@ -313,7 +335,7 @@ def static_route_set_handler(self, key, data):
313
335
return True
314
336
315
337
valid , vrf , ip_prefix = static_route_split_key (key )
316
- local_db_key = vrf + "|" + ip_prefix
338
+ route_cfg_key = vrf + "|" + ip_prefix
317
339
if not valid :
318
340
return True
319
341
@@ -343,7 +365,7 @@ def static_route_set_handler(self, key, data):
343
365
return True
344
366
345
367
346
- data_exist = self .get_local_db (LOCAL_CONFIG_TABLE , local_db_key )
368
+ data_exist = self .get_local_db (LOCAL_CONFIG_TABLE , route_cfg_key )
347
369
if data_exist :
348
370
# route with the prefix already exist, remove the deleted nexthops
349
371
nh_list_exist = arg_list (data_exist ['nexthop' ]) if 'nexthop' in data else None
@@ -361,13 +383,14 @@ def static_route_set_handler(self, key, data):
361
383
nh_vrf = nh [0 ]
362
384
nh_ip = nh [2 ]
363
385
nh_key = nh_vrf + "|" + nh_ip
364
- self .remove_from_nh_table_entry (nh_key , vrf + "|" + ip_prefix )
386
+ self .remove_from_sr_table_entry (route_cfg_key , (nh_vrf , nh_ip ))
387
+ self .remove_from_nh_table_entry (nh_key , route_cfg_key )
365
388
if len (self .get_local_db (LOCAL_NEXTHOP_TABLE , nh_key )) == 0 :
366
389
bfd_key = nh_vrf + ":default:" + nh_ip
367
390
self .remove_from_local_db (LOCAL_BFD_TABLE , bfd_key )
368
391
self .del_bfd_session_from_appl_db (bfd_key )
369
392
370
- self .set_local_db (LOCAL_CONFIG_TABLE , local_db_key , data )
393
+ self .set_local_db (LOCAL_CONFIG_TABLE , route_cfg_key , data )
371
394
for index in range (len (nh_list )):
372
395
nh_ip = nh_list [index ]
373
396
intf = intf_list [index ]
@@ -383,7 +406,7 @@ def static_route_set_handler(self, key, data):
383
406
if len (self .get_local_db (LOCAL_NEXTHOP_TABLE , nh_key )) == 0 and len (bfd_session ) == 0 :
384
407
valid , local_addr = self .find_interface_ip (intf , nh_ip )
385
408
if not valid :
386
- log_warn ("cannot find ip for interface: " , intf )
409
+ log_warn ("cannot find ip for interface: %s" % intf )
387
410
continue
388
411
bfd_entry_cfg = self .BFD_DEFAULT_CFG .copy ()
389
412
bfd_entry_cfg ["local_addr" ] = local_addr
@@ -393,21 +416,23 @@ def static_route_set_handler(self, key, data):
393
416
394
417
self .append_to_nh_table_entry (nh_key , vrf + "|" + ip_prefix )
395
418
419
+ self .refresh_active_nh (route_cfg_key )
420
+
396
421
return True
397
422
398
423
def static_route_del_handler (self , key ):
399
- valid , vrf , ip_prefix = self . static_route_split_key (key )
424
+ valid , vrf , ip_prefix = static_route_split_key (key )
400
425
if not valid :
401
426
return True
402
- local_db_key = vrf + "|" + ip_prefix
427
+ route_cfg_key = vrf + "|" + ip_prefix
403
428
404
429
valid , is_ipv4 , ip = check_ip (ip_prefix )
405
430
if not valid :
406
431
return True
407
432
408
- data = self .get_local_db (LOCAL_CONFIG_TABLE , local_db_key )
433
+ data = self .get_local_db (LOCAL_CONFIG_TABLE , route_cfg_key )
409
434
if len (data ) == 0 :
410
- # this route is not handled by StaticRouteBfd, skip
435
+ # this route is not handled by StaticRouteBfd, skip
411
436
return True
412
437
413
438
arg_list = lambda v : v .split (',' ) if len (v .strip ()) != 0 else None
@@ -417,20 +442,23 @@ def static_route_del_handler(self, key):
417
442
nh_ip = nh_list [index ]
418
443
nh_vrf = nh_vrf_list [index ]
419
444
nh_key = nh_vrf + "|" + nh_ip
420
- self .remove_from_nh_table_entry (nh_key , vrf + "|" + ip_prefix )
445
+ self .remove_from_nh_table_entry (nh_key , route_cfg_key )
421
446
422
447
if len (self .get_local_db (LOCAL_NEXTHOP_TABLE , nh_key )) == 0 :
423
448
bfd_key = nh_vrf + ":default:" + nh_ip
424
449
self .remove_from_local_db (LOCAL_BFD_TABLE , bfd_key )
425
450
self .del_bfd_session_from_appl_db (bfd_key )
426
451
452
+ self .del_static_route_from_appl_db (route_cfg_key .replace ("|" , ":" ))
453
+ self .remove_from_local_db (LOCAL_INTERFACE_TABLE , route_cfg_key )
454
+
427
455
return True
428
456
429
457
def interface_callback (self , key , op , data ):
430
458
if op == swsscommon .SET_COMMAND :
431
459
self .interface_set_handler (key , data )
432
460
elif op == swsscommon .DEL_COMMAND :
433
- self .interface_del_handler (key , data )
461
+ self .interface_del_handler (key )
434
462
else :
435
463
log_err ("Invalid operation '%s' for key '%s'" % (op , key ))
436
464
@@ -520,8 +548,10 @@ def reconstruct_static_route_config(self, original_config, reachable_nexthops):
520
548
521
549
return new_config
522
550
551
+
523
552
def bfd_state_set_handler (self , key , data ):
524
- #key are diff in state db and appl_db
553
+ #key are diff in state db and appl_db,
554
+ #intf is always default for multihop bfd
525
555
vrf , intf , peer_ip = self .bfd_state_split_key (key )
526
556
bfd_key = vrf + ":" + intf + ":" + peer_ip
527
557
@@ -534,6 +564,8 @@ def bfd_state_set_handler(self, key, data):
534
564
state = data ['state' ] if 'state' in data else "DOWN"
535
565
log_info ("bfd seesion %s state %s" % (bfd_key , state ))
536
566
567
+ self .local_db [LOCAL_BFD_TABLE ][bfd_key ]["state" ] = state
568
+
537
569
if state .upper () == "UP" :
538
570
for prefix in self .get_local_db (LOCAL_NEXTHOP_TABLE , nh_key ):
539
571
sr_key = prefix
@@ -556,22 +588,17 @@ def bfd_state_set_handler(self, key, data):
556
588
self .set_static_route_into_appl_db (sr_key .replace ("|" , ":" ), new_config )
557
589
558
590
559
- def bfd_state_del_handler (self , key , data ):
591
+ def bfd_state_del_handler (self , key ):
560
592
vrf , intf , peer_ip = self .bfd_state_split_key (key )
561
593
bfd_key = vrf + ":" + intf + ":" + peer_ip
562
594
563
- #check if the BFD session is in local table
564
- bfd_session = self .get_local_db (LOCAL_BFD_TABLE , bfd_key )
565
- if len (bfd_session ) == 0 :
566
- return True
567
-
568
595
nh_key = vrf + "|" + peer_ip
569
596
570
597
for prefix in self .get_local_db (LOCAL_NEXTHOP_TABLE , nh_key ):
571
598
sr_key = prefix
572
599
config_key = prefix
573
600
self .remove_from_sr_table_entry (sr_key , (vrf , peer_ip ))
574
- if len (self .get_local_db (LOCAL_SR_TABLE , bfd_key )) == 0 :
601
+ if len (self .get_local_db (LOCAL_SR_TABLE , sr_key )) == 0 :
575
602
self .del_static_route_from_appl_db (sr_key .replace ("|" , ":" ))
576
603
else :
577
604
config_data = self .get_local_db (LOCAL_CONFIG_TABLE , config_key )
@@ -582,7 +609,7 @@ def bfd_state_callback(self, key, op, data):
582
609
if op == swsscommon .SET_COMMAND :
583
610
self .bfd_state_set_handler (key , data )
584
611
elif op == swsscommon .DEL_COMMAND :
585
- self .bfd_state_route_del_handler (key )
612
+ self .bfd_state_del_handler (key )
586
613
else :
587
614
log_err ("Invalid operation '%s' for key '%s'" % (op , key ))
588
615
0 commit comments