Skip to content

Commit 7982a32

Browse files
rvisnujleveque
authored andcommitted
[show] Add BGP neighbor info to 'show ip/ipv6 interfaces' command output (sonic-net#598)
1 parent 765b27d commit 7982a32

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

doc/Command-Reference.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,23 +2043,18 @@ The type of interfaces include the following.
20432043
- Example:
20442044
```
20452045
admin@sonic:~$ show ip interfaces
2046-
Interface IPv4 address/mask Admin/Oper
2047-
--------------- ------------------- ------------
2048-
Ethernet112 10.1.1.0/31 up/up
2049-
Ethernet116 10.1.1.2/31 up/up
2050-
PortChannel0001 10.0.1.1/31 up/down
2051-
PortChannel0002 10.0.1.3/31 up/down
2052-
Vlan100 1.1.2.2/16 up/down
2053-
docker0 240.127.1.1/24 up/down
2054-
eth0 10.11.162.42/24 up/up
2055-
lo 127.0.0.1/8 up/up
2056-
10.1.0.1/32
2057-
10.1.0.32/32
2058-
10.12.0.102/32
2046+
Interface IPv4 address/mask Admin/Oper BGP Neighbor Neighbor IP
2047+
------------- ------------------- ------------ -------------- -------------
2048+
PortChannel01 10.0.0.56/31 up/down DEVICE1 10.0.0.57
2049+
PortChannel02 10.0.0.58/31 up/down DEVICE2 10.0.0.59
2050+
PortChannel03 10.0.0.60/31 up/down DEVICE3 10.0.0.61
2051+
PortChannel04 10.0.0.62/31 up/down DEVICE4 10.0.0.63
2052+
Vlan1000 192.168.0.1/27 up/up N/A N/A
2053+
docker0 240.127.1.1/24 up/down N/A N/A
2054+
eth0 10.3.147.252/23 up/up N/A N/A
2055+
lo 127.0.0.1/8 up/up N/A N/A
20592056
```
20602057

2061-
2062-
20632058
**show ip protocol**
20642059

20652060
This command displays the route-map that is configured for the routing protocol.
@@ -2156,23 +2151,16 @@ The type of interfaces include the following.
21562151
- Example:
21572152
```
21582153
admin@sonic:~$ show ipv6 interfaces
2159-
Interface IPv6 address/mask Admin/Oper
2160-
--------------- ------------------------------------------- ------------
2161-
Bridge fe80::d494:dcff:fe37:535e%Bridge/64 up/down
2162-
Ethernet112 2018:2001::1/126 up/up
2163-
fe80::3617:ebff:fe38:100%Ethernet112/64
2164-
Ethernet116 2018:2002::1/126 up/up
2165-
fe80::3617:ebff:fe38:100%Ethernet116/64
2166-
PortChannel0001 2018:1002::2/126 up/down
2167-
PortChannel0002 2018:1002::6/126 up/down
2168-
PortChannel0011 fe80::3617:ebff:fe38:100%PortChannel0011/64 up/up
2169-
Vlan100 fe80::3617:ebff:fe38:100%Vlan100/64 up/down
2170-
eth0 fc00:2::102/128 up/up
2171-
fe80::3617:ebff:fe38:100%eth0/64
2172-
lo fc00:1::102/128 up/up
2173-
fc00:1::32/128
2174-
::1/128
2175-
2154+
Interface IPv6 address/mask Admin/Oper BGP Neighbor Neighbor IP
2155+
------------- ---------------------------------------- ------------ -------------- -------------
2156+
Bridge fe80::7c45:1dff:fe08:cdd%Bridge/64 up/up N/A N/A
2157+
PortChannel01 fc00::71/126 up/down DEVICE1 fc00::72
2158+
PortChannel02 fc00::75/126 up/down DEVICE2 fc00::76
2159+
PortChannel03 fc00::79/126 up/down DEVICE3 fc00::7a
2160+
PortChannel04 fc00::7d/126 up/down DEVICE4 fc00::7e
2161+
Vlan100 fe80::eef4:bbff:fefe:880a%Vlan100/64 up/up N/A N/A
2162+
eth0 fe80::eef4:bbff:fefe:880a%eth0/64 up/up N/A N/A
2163+
lo fc00:1::32/128 up/up N/A N/A
21762164
```
21772165

21782166
**show ipv6 protocol**

show/main.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,15 +906,16 @@ def get_if_oper_state(iface):
906906
#
907907
# 'show ip interfaces' command
908908
#
909-
# Display all interfaces with an IPv4 address and their admin/oper states.
909+
# Display all interfaces with an IPv4 address, admin/oper states, their BGP neighbor name and peer ip.
910910
# Addresses from all scopes are included. Interfaces with no addresses are
911911
# excluded.
912912
#
913913
@ip.command()
914914
def interfaces():
915915
"""Show interfaces IPv4 address"""
916-
header = ['Interface', 'IPv4 address/mask', 'Admin/Oper']
916+
header = ['Interface', 'IPv4 address/mask', 'Admin/Oper', 'BGP Neighbor', 'Neighbor IP']
917917
data = []
918+
bgp_peer = get_bgp_peer()
918919

919920
interfaces = natsorted(netifaces.interfaces())
920921

@@ -924,8 +925,16 @@ def interfaces():
924925
if netifaces.AF_INET in ipaddresses:
925926
ifaddresses = []
926927
for ipaddr in ipaddresses[netifaces.AF_INET]:
928+
neighbor_name = 'N/A'
929+
neighbor_ip = 'N/A'
930+
local_ip = str(ipaddr['addr'])
927931
netmask = netaddr.IPAddress(ipaddr['netmask']).netmask_bits()
928-
ifaddresses.append(["", str(ipaddr['addr']) + "/" + str(netmask)])
932+
ifaddresses.append(["", local_ip + "/" + str(netmask)])
933+
try:
934+
neighbor_name = bgp_peer[local_ip][0]
935+
neighbor_ip = bgp_peer[local_ip][1]
936+
except:
937+
pass
929938

930939
if len(ifaddresses) > 0:
931940
admin = get_if_admin_state(iface)
@@ -937,13 +946,32 @@ def interfaces():
937946
if get_interface_mode() == "alias":
938947
iface = iface_alias_converter.name_to_alias(iface)
939948

940-
data.append([iface, ifaddresses[0][1], admin + "/" + oper])
949+
data.append([iface, ifaddresses[0][1], admin + "/" + oper, neighbor_name, neighbor_ip])
941950

942951
for ifaddr in ifaddresses[1:]:
943952
data.append(["", ifaddr[1], ""])
944953

945954
print tabulate(data, header, tablefmt="simple", stralign='left', missingval="")
946955

956+
# get bgp peering info
957+
def get_bgp_peer():
958+
"""
959+
collects local and bgp neighbor ip along with device name in below format
960+
{
961+
'local_addr1':['neighbor_device1_name', 'neighbor_device1_ip'],
962+
'local_addr2':['neighbor_device2_name', 'neighbor_device2_ip']
963+
}
964+
"""
965+
config_db = ConfigDBConnector()
966+
config_db.connect()
967+
data = config_db.get_table('BGP_NEIGHBOR')
968+
bgp_peer = {}
969+
970+
for neighbor_ip in data.keys():
971+
local_addr = data[neighbor_ip]['local_addr']
972+
neighbor_name = data[neighbor_ip]['name']
973+
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
974+
return bgp_peer
947975

948976
#
949977
# 'route' subcommand ("show ip route")
@@ -1002,7 +1030,7 @@ def ipv6():
10021030
#
10031031
# 'show ipv6 interfaces' command
10041032
#
1005-
# Display all interfaces with an IPv6 address and their admin/oper states.
1033+
# Display all interfaces with an IPv6 address, admin/oper states, their BGP neighbor name and peer ip.
10061034
# Addresses from all scopes are included. Interfaces with no addresses are
10071035
# excluded.
10081036
#
@@ -1011,6 +1039,7 @@ def interfaces():
10111039
"""Show interfaces IPv6 address"""
10121040
header = ['Interface', 'IPv6 address/mask', 'Admin/Oper']
10131041
data = []
1042+
bgp_peer = get_bgp_peer()
10141043

10151044
interfaces = natsorted(netifaces.interfaces())
10161045

@@ -1020,8 +1049,16 @@ def interfaces():
10201049
if netifaces.AF_INET6 in ipaddresses:
10211050
ifaddresses = []
10221051
for ipaddr in ipaddresses[netifaces.AF_INET6]:
1052+
neighbor_name = 'N/A'
1053+
neighbor_ip = 'N/A'
1054+
local_ip = str(ipaddr['addr'])
10231055
netmask = ipaddr['netmask'].split('/', 1)[-1]
1024-
ifaddresses.append(["", str(ipaddr['addr']) + "/" + str(netmask)])
1056+
ifaddresses.append(["", local_ip + "/" + str(netmask)])
1057+
try:
1058+
neighbor_name = bgp_peer[local_ip][0]
1059+
neighbor_ip = bgp_peer[local_ip][1]
1060+
except:
1061+
pass
10251062

10261063
if len(ifaddresses) > 0:
10271064
admin = get_if_admin_state(iface)
@@ -1031,7 +1068,7 @@ def interfaces():
10311068
oper = "down"
10321069
if get_interface_mode() == "alias":
10331070
iface = iface_alias_converter.name_to_alias(iface)
1034-
data.append([iface, ifaddresses[0][1], admin + "/" + oper])
1071+
data.append([iface, ifaddresses[0][1], admin + "/" + oper], neighbor_name, neighbor_ip)
10351072
for ifaddr in ifaddresses[1:]:
10361073
data.append(["", ifaddr[1], ""])
10371074

0 commit comments

Comments
 (0)