-
Notifications
You must be signed in to change notification settings - Fork 388
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
Extend ShowBgpAddressFamily class to parse additional BGP commands #822
Extend ShowBgpAddressFamily class to parse additional BGP commands #822
Conversation
Additionally, your code does not handle IPv6 outputs from BGP correctly.
In this state, it completely ignores that the next hop and metrics are listed on the next line. My regex corrects this, however, there is a flaw in your code: you use a multiline regex but execute it on individual lines, which does not make sense. To make the code work correctly now, I need to modify the device output to this format:
This is achieved with the following code: raw_result = device.execute(command)
raw_result = raw_result.replace('\r\n', '\n')
lines = raw_result.split('\n')
result = [lines[0]]
for line in lines[1:]:
if line.startswith(' '):
result[-1] += line
else:
result.append(line)
formatted_text = '\n'.join(result)
# Run GENIE with preprocessed formatted text
device.parse(command, output=formatted_text) This code concatenates lines that start with a space to the previous line. With this output modification and my changes in the pull request, the "show bgp" command works for both IPv4 and IPv6 addresses. Currently, your implementation for IPv6 is not functional. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! Sorry for the delay in reviewing. This looks good. However, we'll need a changelog file and unittest included before we can merge it in. You can view other merged PRs for examples of them! Be sure to request a re-review once you've added them in
b1dd253
to
c70ae10
Compare
ac86c04
to
4bd7234
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I'm sorry, but I cannot approve this without an accompanying unittest. Please have a look at other PRs to see how to add one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add at least one unit test to support your changes
Tests were added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test were added in the last commit
This commit extends the ShowBgpAddressFamily class to include parsing logic for the following additional BGP commands: - show bgp {address_family} community {community} - show bgp {address_family} community {community} {exact_match} The parsing logic ensures that the output format of these new commands aligns with the format of 'show bgp', maintaining compatibility with existing parsing logic. Unit tests have been added to validate the correctness of parsing for the new commands.
Fixed the regex pattern in the ShowBgpAddressFamily class to properly match IPv6 addresses in the prefix field. The previous pattern was missing support for hexadecimal characters. This update ensures accurate parsing of IPv6 addresses. Refactored the regex pattern in the ShowBgpAddressFamily class to improve readability and ensure correct matching of next hop and number fields. Added explicit newline matching for better pattern coverage. This enhances the reliability of parsing BGP address family information.
- include IPv6 addresses - handle newline characters
6f4c741
to
c4c26cf
Compare
a958071
to
55bba54
Compare
Description
Currently, the ShowBgpAddressFamily class in this file parses commands show bgp and show bgp {address_family}. However, it needs to be extended to parse additional commands:
show bgp {address_family} community {community}
show bgp {address_family} community {community} {exact_match}
The objective is to ensure that the output of these new commands is compatible with the existing logic for parsing show bgp.
Motivation and Context
Extend the ShowBgpAddressFamily class to parse the additional commands mentioned above.
Ensure that the output format of the new commands aligns with the output format of show bgp for compatibility with existing parsing logic.
Impact (If any)
Screenshots:
Related:
Checklist: