@@ -906,15 +906,16 @@ def get_if_oper_state(iface):
906
906
#
907
907
# 'show ip interfaces' command
908
908
#
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 .
910
910
# Addresses from all scopes are included. Interfaces with no addresses are
911
911
# excluded.
912
912
#
913
913
@ip .command ()
914
914
def interfaces ():
915
915
"""Show interfaces IPv4 address"""
916
- header = ['Interface' , 'IPv4 address/mask' , 'Admin/Oper' ]
916
+ header = ['Interface' , 'IPv4 address/mask' , 'Admin/Oper' , 'BGP Neighbor' , 'Neighbor IP' ]
917
917
data = []
918
+ bgp_peer = get_bgp_peer ()
918
919
919
920
interfaces = natsorted (netifaces .interfaces ())
920
921
@@ -924,8 +925,16 @@ def interfaces():
924
925
if netifaces .AF_INET in ipaddresses :
925
926
ifaddresses = []
926
927
for ipaddr in ipaddresses [netifaces .AF_INET ]:
928
+ neighbor_name = 'N/A'
929
+ neighbor_ip = 'N/A'
930
+ local_ip = str (ipaddr ['addr' ])
927
931
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
929
938
930
939
if len (ifaddresses ) > 0 :
931
940
admin = get_if_admin_state (iface )
@@ -937,13 +946,32 @@ def interfaces():
937
946
if get_interface_mode () == "alias" :
938
947
iface = iface_alias_converter .name_to_alias (iface )
939
948
940
- data .append ([iface , ifaddresses [0 ][1 ], admin + "/" + oper ])
949
+ data .append ([iface , ifaddresses [0 ][1 ], admin + "/" + oper , neighbor_name , neighbor_ip ])
941
950
942
951
for ifaddr in ifaddresses [1 :]:
943
952
data .append (["" , ifaddr [1 ], "" ])
944
953
945
954
print tabulate (data , header , tablefmt = "simple" , stralign = 'left' , missingval = "" )
946
955
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
947
975
948
976
#
949
977
# 'route' subcommand ("show ip route")
@@ -1002,7 +1030,7 @@ def ipv6():
1002
1030
#
1003
1031
# 'show ipv6 interfaces' command
1004
1032
#
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 .
1006
1034
# Addresses from all scopes are included. Interfaces with no addresses are
1007
1035
# excluded.
1008
1036
#
@@ -1011,6 +1039,7 @@ def interfaces():
1011
1039
"""Show interfaces IPv6 address"""
1012
1040
header = ['Interface' , 'IPv6 address/mask' , 'Admin/Oper' ]
1013
1041
data = []
1042
+ bgp_peer = get_bgp_peer ()
1014
1043
1015
1044
interfaces = natsorted (netifaces .interfaces ())
1016
1045
@@ -1020,8 +1049,16 @@ def interfaces():
1020
1049
if netifaces .AF_INET6 in ipaddresses :
1021
1050
ifaddresses = []
1022
1051
for ipaddr in ipaddresses [netifaces .AF_INET6 ]:
1052
+ neighbor_name = 'N/A'
1053
+ neighbor_ip = 'N/A'
1054
+ local_ip = str (ipaddr ['addr' ])
1023
1055
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
1025
1062
1026
1063
if len (ifaddresses ) > 0 :
1027
1064
admin = get_if_admin_state (iface )
@@ -1031,7 +1068,7 @@ def interfaces():
1031
1068
oper = "down"
1032
1069
if get_interface_mode () == "alias" :
1033
1070
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 )
1035
1072
for ifaddr in ifaddresses [1 :]:
1036
1073
data .append (["" , ifaddr [1 ], "" ])
1037
1074
0 commit comments