Skip to content

Commit 1b21201

Browse files
authored
[show_bfd] add local discriminator in show bfd command (sonic-net#2625)
1 parent 0d5e68f commit 1b21201

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

show/main.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ def bfd():
20052005
def summary(db):
20062006
"""Show bfd session information"""
20072007
bfd_headers = ["Peer Addr", "Interface", "Vrf", "State", "Type", "Local Addr",
2008-
"TX Interval", "RX Interval", "Multiplier", "Multihop"]
2008+
"TX Interval", "RX Interval", "Multiplier", "Multihop", "Local Discriminator"]
20092009

20102010
bfd_keys = db.db.keys(db.db.STATE_DB, "BFD_SESSION_TABLE|*")
20112011

@@ -2016,8 +2016,10 @@ def summary(db):
20162016
for key in bfd_keys:
20172017
key_values = key.split('|')
20182018
values = db.db.get_all(db.db.STATE_DB, key)
2019+
if "local_discriminator" not in values.keys():
2020+
values["local_discriminator"] = "NA"
20192021
bfd_body.append([key_values[3], key_values[2], key_values[1], values["state"], values["type"], values["local_addr"],
2020-
values["tx_interval"], values["rx_interval"], values["multiplier"], values["multihop"]])
2022+
values["tx_interval"], values["rx_interval"], values["multiplier"], values["multihop"], values["local_discriminator"]])
20212023

20222024
click.echo(tabulate(bfd_body, bfd_headers))
20232025

@@ -2029,7 +2031,7 @@ def summary(db):
20292031
def peer(db, peer_ip):
20302032
"""Show bfd session information for BFD peer"""
20312033
bfd_headers = ["Peer Addr", "Interface", "Vrf", "State", "Type", "Local Addr",
2032-
"TX Interval", "RX Interval", "Multiplier", "Multihop"]
2034+
"TX Interval", "RX Interval", "Multiplier", "Multihop", "Local Discriminator"]
20332035

20342036
bfd_keys = db.db.keys(db.db.STATE_DB, "BFD_SESSION_TABLE|*|{}".format(peer_ip))
20352037
delimiter = db.db.get_db_separator(db.db.STATE_DB)
@@ -2045,8 +2047,10 @@ def peer(db, peer_ip):
20452047
for key in bfd_keys:
20462048
key_values = key.split(delimiter)
20472049
values = db.db.get_all(db.db.STATE_DB, key)
2050+
if "local_discriminator" not in values.keys():
2051+
values["local_discriminator"] = "NA"
20482052
bfd_body.append([key_values[3], key_values[2], key_values[1], values.get("state"), values.get("type"), values.get("local_addr"),
2049-
values.get("tx_interval"), values.get("rx_interval"), values.get("multiplier"), values.get("multihop")])
2053+
values.get("tx_interval"), values.get("rx_interval"), values.get("multiplier"), values.get("multihop"), values.get("local_discriminator")])
20502054

20512055
click.echo(tabulate(bfd_body, bfd_headers))
20522056

tests/show_bfd_test.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_bfd_show(self):
2929
"tx_interval" :"300", "rx_interval" : "500", "multiplier" : "3", "multihop": "true"})
3030
self.set_db_values(dbconnector, "BFD_SESSION_TABLE|default|Ethernet12|10.0.2.1",
3131
{"state": "UP", "type": "async_active", "local_addr" : "10.0.0.1",
32-
"tx_interval" :"200", "rx_interval" : "600", "multiplier" : "3", "multihop": "false"})
32+
"tx_interval" :"200", "rx_interval" : "600", "multiplier" : "3", "multihop": "false", "local_discriminator": "88"})
3333
self.set_db_values(dbconnector, "BFD_SESSION_TABLE|default|default|2000::10:1",
3434
{"state": "UP", "type": "async_active", "local_addr" : "2000::1",
3535
"tx_interval" :"100", "rx_interval" : "700", "multiplier" : "3", "multihop": "false"})
@@ -39,14 +39,14 @@ def test_bfd_show(self):
3939

4040
expected_output = """\
4141
Total number of BFD sessions: 6
42-
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop
43-
--------------------- ----------- ------- ------- ------------ --------------------- ------------- ------------- ------------ ----------
44-
100.251.7.1 default default Up async_active 10.0.0.1 300 500 3 true
45-
fddd:a101:a251::a10:1 default default Down async_active fddd:c101:a251::a10:2 300 500 3 true
46-
10.0.1.1 default default DOWN async_active 10.0.0.1 300 500 3 true
47-
10.0.2.1 Ethernet12 default UP async_active 10.0.0.1 200 600 3 false
48-
2000::10:1 default default UP async_active 2000::1 100 700 3 false
49-
10.0.1.1 default VrfRed UP async_active 10.0.0.1 400 500 5 false
42+
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop Local Discriminator
43+
--------------------- ----------- ------- ------- ------------ --------------------- ------------- ------------- ------------ ---------- ---------------------
44+
100.251.7.1 default default Up async_active 10.0.0.1 300 500 3 true NA
45+
fddd:a101:a251::a10:1 default default Down async_active fddd:c101:a251::a10:2 300 500 3 true NA
46+
10.0.1.1 default default DOWN async_active 10.0.0.1 300 500 3 true NA
47+
10.0.2.1 Ethernet12 default UP async_active 10.0.0.1 200 600 3 false 88
48+
2000::10:1 default default UP async_active 2000::1 100 700 3 false NA
49+
10.0.1.1 default VrfRed UP async_active 10.0.0.1 400 500 5 false NA
5050
"""
5151

5252
result = runner.invoke(show.cli.commands['bfd'].commands['summary'], [], obj=db)
@@ -55,10 +55,10 @@ def test_bfd_show(self):
5555

5656
expected_output = """\
5757
Total number of BFD sessions for peer IP 10.0.1.1: 2
58-
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop
59-
----------- ----------- ------- ------- ------------ ------------ ------------- ------------- ------------ ----------
60-
10.0.1.1 default default DOWN async_active 10.0.0.1 300 500 3 true
61-
10.0.1.1 default VrfRed UP async_active 10.0.0.1 400 500 5 false
58+
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop Local Discriminator
59+
----------- ----------- ------- ------- ------------ ------------ ------------- ------------- ------------ ---------- ---------------------
60+
10.0.1.1 default default DOWN async_active 10.0.0.1 300 500 3 true NA
61+
10.0.1.1 default VrfRed UP async_active 10.0.0.1 400 500 5 false NA
6262
"""
6363

6464
result = runner.invoke(show.cli.commands['bfd'].commands['peer'], ['10.0.1.1'], obj=db)
@@ -67,9 +67,9 @@ def test_bfd_show(self):
6767

6868
expected_output = """\
6969
Total number of BFD sessions for peer IP 10.0.2.1: 1
70-
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop
71-
----------- ----------- ------- ------- ------------ ------------ ------------- ------------- ------------ ----------
72-
10.0.2.1 Ethernet12 default UP async_active 10.0.0.1 200 600 3 false
70+
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop Local Discriminator
71+
----------- ----------- ------- ------- ------------ ------------ ------------- ------------- ------------ ---------- ---------------------
72+
10.0.2.1 Ethernet12 default UP async_active 10.0.0.1 200 600 3 false 88
7373
"""
7474

7575
result = runner.invoke(show.cli.commands['bfd'].commands['peer'], ['10.0.2.1'], obj=db)
@@ -91,10 +91,10 @@ def test_bfd_show_no_session(self):
9191

9292
expected_output = """\
9393
Total number of BFD sessions: 2
94-
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop
95-
--------------------- ----------- ------- ------- ------------ --------------------- ------------- ------------- ------------ ----------
96-
100.251.7.1 default default Up async_active 10.0.0.1 300 500 3 true
97-
fddd:a101:a251::a10:1 default default Down async_active fddd:c101:a251::a10:2 300 500 3 true
94+
Peer Addr Interface Vrf State Type Local Addr TX Interval RX Interval Multiplier Multihop Local Discriminator
95+
--------------------- ----------- ------- ------- ------------ --------------------- ------------- ------------- ------------ ---------- ---------------------
96+
100.251.7.1 default default Up async_active 10.0.0.1 300 500 3 true NA
97+
fddd:a101:a251::a10:1 default default Down async_active fddd:c101:a251::a10:2 300 500 3 true NA
9898
"""
9999

100100
result = runner.invoke(show.cli.commands['bfd'].commands['summary'], [], obj=db)

0 commit comments

Comments
 (0)