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

Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table #1224

Merged
merged 3 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 4 additions & 17 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,28 +490,19 @@ def set_interface_naming_mode(mode):
click.echo("Please logout and log back in for changes take effect.")


# Get the local BGP ASN from DEVICE_METADATA
def get_local_bgp_asn(config_db):
metadata = config_db.get_table('DEVICE_METADATA')
return metadata['localhost']['bgp_asn']

def _is_neighbor_ipaddress(config_db, ipaddress):
"""Returns True if a neighbor has the IP address <ipaddress>, False if not
"""
entry = config_db.get_entry('BGP_NEIGHBOR', ipaddress)
return True if entry else False

def _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts=False):
def _get_all_neighbor_ipaddresses(config_db):
"""Returns list of strings containing IP addresses of all BGP neighbors
if the flag ignore_local_hosts is set to True, additional check to see if
if the BGP neighbor AS number is same as local BGP AS number, if so ignore that neigbor.
"""
addrs = []
bgp_sessions = config_db.get_table('BGP_NEIGHBOR')
local_as = get_local_bgp_asn(config_db)
for addr, session in bgp_sessions.iteritems():
if not ignore_local_hosts or (ignore_local_hosts and local_as != session['asn']):
addrs.append(addr)
addrs.append(addr)
return addrs

def _get_neighbor_ipaddress_list_by_hostname(config_db, hostname):
Expand Down Expand Up @@ -1960,19 +1951,17 @@ def all(verbose):
"""
log.log_info("'bgp shutdown all' executing...")
namespaces = [DEFAULT_NAMESPACE]
ignore_local_hosts = False

if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns']
ignore_local_hosts = True

# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
for ipaddress in bgp_neighbor_ip_list:
_change_bgp_session_status_by_addr(config_db, ipaddress, 'down', verbose)

Expand Down Expand Up @@ -2017,19 +2006,17 @@ def all(verbose):
"""
log.log_info("'bgp startup all' executing...")
namespaces = [DEFAULT_NAMESPACE]
ignore_local_hosts = False

if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns']
ignore_local_hosts = True

# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db, ignore_local_hosts)
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
for ipaddress in bgp_neighbor_ip_list:
_change_bgp_session_status_by_addr(config_db, ipaddress, 'up', verbose)

Expand Down
13 changes: 8 additions & 5 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,16 @@ def get_bgp_peer():
"""
config_db = ConfigDBConnector()
config_db.connect()
data = config_db.get_table('BGP_NEIGHBOR')
bgp_peer = {}
bgp_neighbor_tables = ['BGP_NEIGHBOR', 'BGP_INTERNAL_NEIGHBOR']

for table in bgp_neighbor_tables:
data = config_db.get_table(table)
for neighbor_ip in data.keys():
local_addr = data[neighbor_ip]['local_addr']
neighbor_name = data[neighbor_ip]['name']
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])

for neighbor_ip in data.keys():
local_addr = data[neighbor_ip]['local_addr']
neighbor_name = data[neighbor_ip]['name']
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
return bgp_peer

#
Expand Down
2 changes: 2 additions & 0 deletions utilities_common/bgp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def get_bgp_neighbors_dict(namespace=multi_asic.DEFAULT_NAMESPACE):
dynamic_neighbors = {}
config_db = multi_asic.connect_config_db_for_ns(namespace)
static_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_NEIGHBOR')
static_internal_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_INTERNAL_NEIGHBOR')
static_neighbors.update(static_internal_neighbors)
bgp_monitors = get_neighbor_dict_from_table(config_db, 'BGP_MONITORS')
static_neighbors.update(bgp_monitors)
dynamic_neighbors = get_dynamic_neighbor_subnet(config_db)
Expand Down