Skip to content

Commit c0df635

Browse files
authored
Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (#1224) (#1237)
1 parent d683bb4 commit c0df635

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
@@ -381,28 +381,19 @@ def get_interface_naming_mode():
381381
mode = "default"
382382
return mode
383383

384-
# Get the local BGP ASN from DEVICE_METADATA
385-
def get_local_bgp_asn(config_db):
386-
metadata = config_db.get_table('DEVICE_METADATA')
387-
return metadata['localhost']['bgp_asn']
388-
389384
def _is_neighbor_ipaddress(config_db, ipaddress):
390385
"""Returns True if a neighbor has the IP address <ipaddress>, False if not
391386
"""
392387
entry = config_db.get_entry('BGP_NEIGHBOR', ipaddress)
393388
return True if entry else False
394389

395-
def _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts=False):
390+
def _get_all_neighbor_ipaddresses(config_db):
396391
"""Returns list of strings containing IP addresses of all BGP neighbors
397-
if the flag ignore_local_hosts is set to True, additional check to see if
398-
if the BGP neighbor AS number is same as local BGP AS number, if so ignore that neigbor.
399392
"""
400393
addrs = []
401394
bgp_sessions = config_db.get_table('BGP_NEIGHBOR')
402-
local_as = get_local_bgp_asn(config_db)
403395
for addr, session in bgp_sessions.iteritems():
404-
if not ignore_local_hosts or (ignore_local_hosts and local_as != session['asn']):
405-
addrs.append(addr)
396+
addrs.append(addr)
406397
return addrs
407398

408399
def _get_neighbor_ipaddress_list_by_hostname(config_db, hostname):
@@ -1797,19 +1788,17 @@ def all(verbose):
17971788
"""
17981789
log.log_info("'bgp shutdown all' executing...")
17991790
namespaces = [DEFAULT_NAMESPACE]
1800-
ignore_local_hosts = False
18011791

18021792
if multi_asic.is_multi_asic():
18031793
ns_list = multi_asic.get_all_namespaces()
18041794
namespaces = ns_list['front_ns']
1805-
ignore_local_hosts = True
18061795

18071796
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
18081797
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
18091798
for namespace in namespaces:
18101799
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
18111800
config_db.connect()
1812-
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
1801+
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
18131802
for ipaddress in bgp_neighbor_ip_list:
18141803
_change_bgp_session_status_by_addr(config_db, ipaddress, 'down', verbose)
18151804

@@ -1854,19 +1843,17 @@ def all(verbose):
18541843
"""
18551844
log.log_info("'bgp startup all' executing...")
18561845
namespaces = [DEFAULT_NAMESPACE]
1857-
ignore_local_hosts = False
18581846

18591847
if multi_asic.is_multi_asic():
18601848
ns_list = multi_asic.get_all_namespaces()
18611849
namespaces = ns_list['front_ns']
1862-
ignore_local_hosts = True
18631850

18641851
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
18651852
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
18661853
for namespace in namespaces:
18671854
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
18681855
config_db.connect()
1869-
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
1856+
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
18701857
for ipaddress in bgp_neighbor_ip_list:
18711858
_change_bgp_session_status_by_addr(config_db, ipaddress, 'up', verbose)
18721859

show/main.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1315,13 +1315,16 @@ def get_bgp_peer():
13151315
"""
13161316
config_db = ConfigDBConnector()
13171317
config_db.connect()
1318-
data = config_db.get_table('BGP_NEIGHBOR')
13191318
bgp_peer = {}
1319+
bgp_neighbor_tables = ['BGP_NEIGHBOR', 'BGP_INTERNAL_NEIGHBOR']
1320+
1321+
for table in bgp_neighbor_tables:
1322+
data = config_db.get_table(table)
1323+
for neighbor_ip in data.keys():
1324+
local_addr = data[neighbor_ip]['local_addr']
1325+
neighbor_name = data[neighbor_ip]['name']
1326+
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
13201327

1321-
for neighbor_ip in data.keys():
1322-
local_addr = data[neighbor_ip]['local_addr']
1323-
neighbor_name = data[neighbor_ip]['name']
1324-
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
13251328
return bgp_peer
13261329

13271330
#

sonic-utilities-tests/bgp_commands_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
10.0.0.55 4 64012 0 0 0 0 0 never Active ARISTA12T0
3636
10.0.0.57 4 64013 0 0 0 0 0 never Active ARISTA13T0
3737
10.0.0.59 4 64014 0 0 0 0 0 never Active ARISTA14T0
38-
10.0.0.61 4 64015 0 0 0 0 0 never Active ARISTA15T0
39-
10.0.0.63 4 64016 0 0 0 0 0 never Active ARISTA16T0
38+
10.0.0.61 4 64015 0 0 0 0 0 never Active INT_NEIGH0
39+
10.0.0.63 4 64016 0 0 0 0 0 never Active INT_NEIGH1
4040
4141
Total number of neighbors 24
4242
"""
@@ -75,8 +75,8 @@
7575
fc00::62 4 64009 0 0 0 0 0 never Active ARISTA09T0
7676
fc00::66 4 64010 0 0 0 0 0 never Active ARISTA10T0
7777
fc00::72 4 64013 0 0 0 0 0 never Active ARISTA13T0
78-
fc00::76 4 64014 0 0 0 0 0 never Active ARISTA14T0
79-
fc00::a 4 65200 6665 6671 0 0 0 2d09h38m 6402 ARISTA03T2
78+
fc00::76 4 64014 0 0 0 0 0 never Active INT_NEIGH0
79+
fc00::a 4 65200 6665 6671 0 0 0 2d09h38m 6402 INT_NEIGH1
8080
8181
Total number of neighbors 24
8282
"""

sonic-utilities-tests/mock_tables/config_db.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,21 @@
409409
"nhopself": "0",
410410
"rrclient": "0"
411411
},
412-
"BGP_NEIGHBOR|10.0.0.61": {
412+
"BGP_INTERNAL_NEIGHBOR|10.0.0.61": {
413413
"asn": "64015",
414414
"holdtime": "10",
415415
"keepalive": "3",
416416
"local_addr": "10.0.0.60",
417-
"name": "ARISTA15T0",
417+
"name": "INT_NEIGH0",
418418
"nhopself": "0",
419419
"rrclient": "0"
420420
},
421-
"BGP_NEIGHBOR|10.0.0.63": {
421+
"BGP_INTERNAL_NEIGHBOR|10.0.0.63": {
422422
"asn": "64016",
423423
"holdtime": "10",
424424
"keepalive": "3",
425425
"local_addr": "10.0.0.62",
426-
"name": "ARISTA16T0",
426+
"name": "INT_NEIGH1",
427427
"nhopself": "0",
428428
"rrclient": "0"
429429
},
@@ -625,21 +625,21 @@
625625
"nhopself": "0",
626626
"rrclient": "0"
627627
},
628-
"BGP_NEIGHBOR|fc00::76": {
628+
"BGP_INTERNAL_NEIGHBOR|fc00::76": {
629629
"asn": "64014",
630630
"holdtime": "10",
631631
"keepalive": "3",
632632
"local_addr": "fc00::75",
633-
"name": "ARISTA14T0",
633+
"name": "INT_NEIGH0",
634634
"nhopself": "0",
635635
"rrclient": "0"
636636
},
637-
"BGP_NEIGHBOR|fc00::a": {
637+
"BGP_INTERNAL_NEIGHBOR|fc00::a": {
638638
"asn": "65200",
639639
"holdtime": "10",
640640
"keepalive": "3",
641641
"local_addr": "fc00::9",
642-
"name": "ARISTA03T2",
642+
"name": "INT_NEIGH1",
643643
"nhopself": "0",
644644
"rrclient": "0"
645645
},

utilities_common/bgp_util.py

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

0 commit comments

Comments
 (0)