From 3b490fc2c64b8ca02b45a97f8b150c06fe55c1cd Mon Sep 17 00:00:00 2001 From: Baorong Liu <96146196+baorliu@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:44:19 -0800 Subject: [PATCH] [show_bfd] add local discriminator in show bfd command --- show/main.py | 12 ++++++++---- tests/show_bfd_test.py | 40 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/show/main.py b/show/main.py index 505768e643..091b2d1a36 100755 --- a/show/main.py +++ b/show/main.py @@ -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|*") @@ -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)) @@ -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) @@ -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)) diff --git a/tests/show_bfd_test.py b/tests/show_bfd_test.py index bd2df5f58b..c92fb7690b 100644 --- a/tests/show_bfd_test.py +++ b/tests/show_bfd_test.py @@ -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"}) @@ -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) @@ -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) @@ -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) @@ -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)