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

[show]add'show ip bgp summary enhanced' #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ivlee1
Copy link
Contributor

@ivlee1 ivlee1 commented Jul 22, 2018

- What I did
Add Device Name for each BGP peer and number of Advertised-route tp 'show ip bgp summary'

- How I did it

  1. Get a list of bgp peer from 'show ip bgp summary',
  2. Loop through the list of peer to get advertised-route per peer
  3. Find the BGP peer device name from sonic-cfgen
  4. Output all data in a new table format

- How to verify it
run 'show ip bgp summary enhanced'

- Previous command output (if the output of a command-line utility has changed)
None

- New command output (if the output of a command-line utility has changed)
run show ip ( to see the option)

admin@sonic:~$ show ip bgp        
Usage: show ip bgp [OPTIONS] COMMAND [ARGS]...

  Show IPv4 BGP (Border Gateway Protocol) information

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  neighbors  Show IP (IPv4) BGP neighbors
  summary

run show ip bgp summary (No change)

admin@sonic:~$ show ip bgp summary
Command: sudo vtysh -c "show ip bgp summary"
BGP router identifier 10.1.0.32, local AS number 65100
RIB entries 12806, using 1401 KiB of memory
Peers 8, using 36 KiB of memory
Peer groups 2, using 112 bytes of memory

Neighbor        V         AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.57       4 64600   35099   31894        0    0    0 10:10:45     6400
10.0.0.59       4 64600   35093   35093        0    0    0 04:56:52     6400
10.0.0.61       4 64600   35103   41486        0    0    0 4d07h05m     6400
10.0.0.63       4 64600   35815   41486        0    0    0 14:43:58     6400

Total number of neighbors 4

run newly added command 'show ip bgp summary enhanced' ( 2 new columns added at the end)

admin@sonic:~$ show ip bgp summary enhanced
NeighborIP      V     AS    MsgRcvd    MsgSent    TblVer    InQ    OutQ  Up/Down      State/PfxRcd    PfxAdv  Device
------------  ---  -----  ---------  ---------  --------  -----  ------  ---------  --------------  --------  ----------
10.0.0.57       4  64600      35100      31894         0      0       0  10:11:00             6400         5  ARISTA01T1
10.0.0.59       4  64600      35094      35094         0      0       0  04:57:07             6400      6404  ARISTA02T1
10.0.0.61       4  64600      35103      41486         0      0       0  4d07h05m             6400      6404  ARISTA03T1
10.0.0.63       4  64600      35815      41487         0      0       0  14:44:13             6400      6404  ARISTA04T1

-->

from show.main import *

def parse_bgp_summary(summ):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_bgp_summary [](start = 4, length = 17)

Where is the unit test?

from show.main import *

def parse_bgp_summary(summ):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def [](start = 0, length = 3)

Suggest move command functions to https://github.com/Azure/sonic-py-swsssdk, so sonic-snmpagent can also access.

Copy link
Contributor Author

@ivlee1 ivlee1 Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will sync with Joe on this. #Pending

from natsort import natsorted
from tabulate import tabulate
from natsort import natsorted
from tabulate import tabulate
from show.main import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [](start = 22, length = 1)

Don't import wildcard in prod code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not changed wildcard import on this PR. Will sync with Joe on this

proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STDOUT [](start = 50, length = 6)

Why mix it with stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused the logic of the function from main.py, will check with Joe on this

stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result [](start = 8, length = 6)

also check return code and stderr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused the logic of the function from main.py, will check with Joe on this

proc.wait()
result = stdout.rstrip('\n')
except OSError, e:
raise OSError("Error running command")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OSError [](start = 14, length = 7)

raise the same type of exception, no benefit added, and lose the inner exception info.

neighbor_adv_dict = {}
# get advestise prefix per neighbor
for item in neighborIP:
pfxadv = run_command_save('sudo vtysh -c "show ip bgp nei {0} advertised-routes" | grep Total'.format(item))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| [](start = 92, length = 2)

add '| tail -1'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add

neighbor_adv_dict = {}
# get advestise prefix per neighbor
for item in neighborIP:
pfxadv = run_command_save('sudo vtysh -c "show ip bgp nei {0} advertised-routes" | grep Total'.format(item))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_command_save [](start = 21, length = 16)

What if some run_command fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plan to have exception caught on the run_command

neighbor_adv_dict = {}
# get advestise prefix per neighbor
for item in neighborIP:
pfxadv = run_command_save('sudo vtysh -c "show ip bgp nei {0} advertised-routes" | grep Total'.format(item))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pfxadv [](start = 12, length = 6)

Since you invoke the command in sequence, it may have time consistence issue. Does it make sense to collect them and finally show in a table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is indeed the case, the per peer output is stored on neighbor_adv_dict. Then output all togther

p = subprocess.Popen(bgp_neighbor_cmd, shell=True, stdout=subprocess.PIPE)
bgp_neighbor_dict = json.loads(p.stdout.read())

header = ['NeighborIP', 'V', 'AS', 'MsgRcvd', 'MsgSent', 'TblVer', 'InQ', 'OutQ', 'Up/Down', 'State/PfxRcd',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NeighborIP [](start = 19, length = 10)

Suggest keep original name 'Neighbor'. Many vendors use this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will updated

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments

mihirpat1 pushed a commit to mihirpat1/sonic-utilities that referenced this pull request Sep 15, 2023
Description
The heath metric in ssd_generic for innodisk SSDs is too lazy. Fix to match the entire health number rather than just the first digit.

How Has This Been Tested?
Manual testing on Mellanox MSN2100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants