Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show_bfd] add local discriminator in show bfd command #2625

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ def bfd():
def summary(db):
"""Show bfd session information"""
bfd_headers = ["Peer Addr", "Interface", "Vrf", "State", "Type", "Local Addr",
"TX Interval", "RX Interval", "Multiplier", "Multihop"]
"TX Interval", "RX Interval", "Multiplier", "Multihop", "Local Discriminator"]

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

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

click.echo(tabulate(bfd_body, bfd_headers))

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

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

click.echo(tabulate(bfd_body, bfd_headers))

Expand Down
40 changes: 20 additions & 20 deletions tests/show_bfd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_bfd_show(self):
"tx_interval" :"300", "rx_interval" : "500", "multiplier" : "3", "multihop": "true"})
self.set_db_values(dbconnector, "BFD_SESSION_TABLE|default|Ethernet12|10.0.2.1",
{"state": "UP", "type": "async_active", "local_addr" : "10.0.0.1",
"tx_interval" :"200", "rx_interval" : "600", "multiplier" : "3", "multihop": "false"})
"tx_interval" :"200", "rx_interval" : "600", "multiplier" : "3", "multihop": "false", "local_discriminator": "88"})
self.set_db_values(dbconnector, "BFD_SESSION_TABLE|default|default|2000::10:1",
{"state": "UP", "type": "async_active", "local_addr" : "2000::1",
"tx_interval" :"100", "rx_interval" : "700", "multiplier" : "3", "multihop": "false"})
Expand All @@ -39,14 +39,14 @@ def test_bfd_show(self):

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

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

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

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

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

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

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

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