Skip to content

Commit 929ff7c

Browse files
authored
Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (sonic-net#1224)
- What I did Updates to bgp config and show commands with the movement of internal bgp sessions to a new table BGP_INTERNAL_NEIGHBOR table. With the introduction of BGP_INERNAL_NEIGHBOR table, the user cannot start/stop/remove internal neighbors which I feel is not needed as these internal bgp sessions which are supposed to be UP always. - How I did it Updated the show/bgp util so that it gets the internal bgp sessions from BGP_INTERNAL_NEIGHBOR table. Removed the API's to get the local_as in config/bgp which is not required now. - How to verify it Made sure that the output remain same with the new internal bgp neighbor table.
1 parent 939e331 commit 929ff7c

File tree

5 files changed

+26
-34
lines changed

5 files changed

+26
-34
lines changed

config/main.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -491,28 +491,19 @@ def set_interface_naming_mode(mode):
491491
click.echo("Please logout and log back in for changes take effect.")
492492

493493

494-
# Get the local BGP ASN from DEVICE_METADATA
495-
def get_local_bgp_asn(config_db):
496-
metadata = config_db.get_table('DEVICE_METADATA')
497-
return metadata['localhost']['bgp_asn']
498-
499494
def _is_neighbor_ipaddress(config_db, ipaddress):
500495
"""Returns True if a neighbor has the IP address <ipaddress>, False if not
501496
"""
502497
entry = config_db.get_entry('BGP_NEIGHBOR', ipaddress)
503498
return True if entry else False
504499

505-
def _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts=False):
500+
def _get_all_neighbor_ipaddresses(config_db):
506501
"""Returns list of strings containing IP addresses of all BGP neighbors
507-
if the flag ignore_local_hosts is set to True, additional check to see if
508-
if the BGP neighbor AS number is same as local BGP AS number, if so ignore that neigbor.
509502
"""
510503
addrs = []
511504
bgp_sessions = config_db.get_table('BGP_NEIGHBOR')
512-
local_as = get_local_bgp_asn(config_db)
513505
for addr, session in bgp_sessions.iteritems():
514-
if not ignore_local_hosts or (ignore_local_hosts and local_as != session['asn']):
515-
addrs.append(addr)
506+
addrs.append(addr)
516507
return addrs
517508

518509
def _get_neighbor_ipaddress_list_by_hostname(config_db, hostname):
@@ -1961,19 +1952,17 @@ def all(verbose):
19611952
"""
19621953
log.log_info("'bgp shutdown all' executing...")
19631954
namespaces = [DEFAULT_NAMESPACE]
1964-
ignore_local_hosts = False
19651955

19661956
if multi_asic.is_multi_asic():
19671957
ns_list = multi_asic.get_all_namespaces()
19681958
namespaces = ns_list['front_ns']
1969-
ignore_local_hosts = True
19701959

19711960
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
19721961
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
19731962
for namespace in namespaces:
19741963
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
19751964
config_db.connect()
1976-
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
1965+
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
19771966
for ipaddress in bgp_neighbor_ip_list:
19781967
_change_bgp_session_status_by_addr(config_db, ipaddress, 'down', verbose)
19791968

@@ -2018,19 +2007,17 @@ def all(verbose):
20182007
"""
20192008
log.log_info("'bgp startup all' executing...")
20202009
namespaces = [DEFAULT_NAMESPACE]
2021-
ignore_local_hosts = False
20222010

20232011
if multi_asic.is_multi_asic():
20242012
ns_list = multi_asic.get_all_namespaces()
20252013
namespaces = ns_list['front_ns']
2026-
ignore_local_hosts = True
20272014

20282015
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
20292016
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
20302017
for namespace in namespaces:
20312018
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
20322019
config_db.connect()
2033-
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
2020+
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
20342021
for ipaddress in bgp_neighbor_ip_list:
20352022
_change_bgp_session_status_by_addr(config_db, ipaddress, 'up', verbose)
20362023

show/main.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -774,13 +774,16 @@ def get_bgp_peer():
774774
"""
775775
config_db = ConfigDBConnector()
776776
config_db.connect()
777-
data = config_db.get_table('BGP_NEIGHBOR')
778777
bgp_peer = {}
778+
bgp_neighbor_tables = ['BGP_NEIGHBOR', 'BGP_INTERNAL_NEIGHBOR']
779+
780+
for table in bgp_neighbor_tables:
781+
data = config_db.get_table(table)
782+
for neighbor_ip in data.keys():
783+
local_addr = data[neighbor_ip]['local_addr']
784+
neighbor_name = data[neighbor_ip]['name']
785+
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
779786

780-
for neighbor_ip in data.keys():
781-
local_addr = data[neighbor_ip]['local_addr']
782-
neighbor_name = data[neighbor_ip]['name']
783-
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
784787
return bgp_peer
785788

786789
#

tests/bgp_commands_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
10.0.0.55 4 64012 0 0 0 0 0 never Active ARISTA12T0
3939
10.0.0.57 4 64013 0 0 0 0 0 never Active ARISTA13T0
4040
10.0.0.59 4 64014 0 0 0 0 0 never Active ARISTA14T0
41-
10.0.0.61 4 64015 0 0 0 0 0 never Active ARISTA15T0
42-
10.0.0.63 4 64016 0 0 0 0 0 never Active ARISTA16T0
41+
10.0.0.61 4 64015 0 0 0 0 0 never Active INT_NEIGH0
42+
10.0.0.63 4 64016 0 0 0 0 0 never Active INT_NEIGH1
4343
4444
Total number of neighbors 24
4545
"""
@@ -78,8 +78,8 @@
7878
fc00::62 4 64009 0 0 0 0 0 never Active ARISTA09T0
7979
fc00::66 4 64010 0 0 0 0 0 never Active ARISTA10T0
8080
fc00::72 4 64013 0 0 0 0 0 never Active ARISTA13T0
81-
fc00::76 4 64014 0 0 0 0 0 never Active ARISTA14T0
82-
fc00::a 4 65200 6665 6671 0 0 0 2d09h38m 6402 ARISTA03T2
81+
fc00::76 4 64014 0 0 0 0 0 never Active INT_NEIGH0
82+
fc00::a 4 65200 6665 6671 0 0 0 2d09h38m 6402 INT_NEIGH1
8383
8484
Total number of neighbors 24
8585
"""

tests/mock_tables/config_db.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -988,21 +988,21 @@
988988
"nhopself": "0",
989989
"rrclient": "0"
990990
},
991-
"BGP_NEIGHBOR|10.0.0.61": {
991+
"BGP_INTERNAL_NEIGHBOR|10.0.0.61": {
992992
"asn": "64015",
993993
"holdtime": "10",
994994
"keepalive": "3",
995995
"local_addr": "10.0.0.60",
996-
"name": "ARISTA15T0",
996+
"name": "INT_NEIGH0",
997997
"nhopself": "0",
998998
"rrclient": "0"
999999
},
1000-
"BGP_NEIGHBOR|10.0.0.63": {
1000+
"BGP_INTERNAL_NEIGHBOR|10.0.0.63": {
10011001
"asn": "64016",
10021002
"holdtime": "10",
10031003
"keepalive": "3",
10041004
"local_addr": "10.0.0.62",
1005-
"name": "ARISTA16T0",
1005+
"name": "INT_NEIGH1",
10061006
"nhopself": "0",
10071007
"rrclient": "0"
10081008
},
@@ -1204,21 +1204,21 @@
12041204
"nhopself": "0",
12051205
"rrclient": "0"
12061206
},
1207-
"BGP_NEIGHBOR|fc00::76": {
1207+
"BGP_INTERNAL_NEIGHBOR|fc00::76": {
12081208
"asn": "64014",
12091209
"holdtime": "10",
12101210
"keepalive": "3",
12111211
"local_addr": "fc00::75",
1212-
"name": "ARISTA14T0",
1212+
"name": "INT_NEIGH0",
12131213
"nhopself": "0",
12141214
"rrclient": "0"
12151215
},
1216-
"BGP_NEIGHBOR|fc00::a": {
1216+
"BGP_INTERNAL_NEIGHBOR|fc00::a": {
12171217
"asn": "65200",
12181218
"holdtime": "10",
12191219
"keepalive": "3",
12201220
"local_addr": "fc00::9",
1221-
"name": "ARISTA03T2",
1221+
"name": "INT_NEIGH1",
12221222
"nhopself": "0",
12231223
"rrclient": "0"
12241224
},

utilities_common/bgp_util.py

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def get_bgp_neighbors_dict(namespace=multi_asic.DEFAULT_NAMESPACE):
7070
dynamic_neighbors = {}
7171
config_db = multi_asic.connect_config_db_for_ns(namespace)
7272
static_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_NEIGHBOR')
73+
static_internal_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_INTERNAL_NEIGHBOR')
74+
static_neighbors.update(static_internal_neighbors)
7375
bgp_monitors = get_neighbor_dict_from_table(config_db, 'BGP_MONITORS')
7476
static_neighbors.update(bgp_monitors)
7577
dynamic_neighbors = get_dynamic_neighbor_subnet(config_db)

0 commit comments

Comments
 (0)