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

Extend ShowBgpAddressFamily class to parse additional BGP commands #822

Conversation

Kani999
Copy link
Contributor

@Kani999 Kani999 commented Feb 21, 2024

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:

  • I have updated the changelog.
  • I have updated the documentation (If applicable).
  • I have added tests to cover my changes (If applicable).
  • All new and existing tests passed.
  • All new code passed compilation.

@Kani999 Kani999 requested a review from a team as a code owner February 21, 2024 13:09
@Kani999
Copy link
Contributor Author

Kani999 commented Feb 23, 2024

  • Your regex pattern did not work correctly for IPv6 addresses. The regex in the address ignored the format [a-f].

Additionally, your code does not handle IPv6 outputs from BGP correctly.
Example:

s>i2001:718::2:99/128 195.113.156.4            0    100      0 i
s i                   195.113.156.4            0    100      0 i
s>i2001:718::2:101/128
                      10.2.8.1                 0    100      0 i
s i                   10.2.8.1                 0    100      0 i
s>i2001:718::2:116/128
                      195.113.156.9         1000    205      0 65086 i
s i                   195.113.156.9         1000    205      0 65086 i
s i                   2001:718:0:600:0:1a:1a:11
                                            1000    110      0 65086 i

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:

s>i2001:718::2:99/128 195.113.156.4            0    100      0 i
s i                   195.113.156.4            0    100      0 i
s>i2001:718::2:101/128                      10.2.8.1                 0    100      0 i
s i                   10.2.8.1                 0    100      0 i
s>i2001:718::2:116/128                      195.113.156.9         1000    205      0 65086 i
s i                   195.113.156.9         1000    205      0 65086 i
s i                   2001:718:0:600:0:1a:1a:11                                            1000    110      0 65086 i

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.

Copy link
Collaborator

@ThomasJRyan ThomasJRyan left a 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

src/genie/libs/parser/iosxr/show_bgp.py Show resolved Hide resolved
src/genie/libs/parser/iosxr/show_bgp.py Show resolved Hide resolved
@Kani999 Kani999 force-pushed the extend-show-bgp-address-family-class branch 2 times, most recently from b1dd253 to c70ae10 Compare April 4, 2024 07:26
@Kani999 Kani999 requested a review from ThomasJRyan April 4, 2024 08:44
@Kani999 Kani999 force-pushed the extend-show-bgp-address-family-class branch from ac86c04 to 4bd7234 Compare April 12, 2024 10:06
Copy link
Collaborator

@ThomasJRyan ThomasJRyan left a 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

Copy link
Contributor

@domachad domachad left a 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

src/genie/libs/parser/iosxr/show_bgp.py Show resolved Hide resolved
src/genie/libs/parser/iosxr/show_bgp.py Show resolved Hide resolved
@Kani999
Copy link
Contributor Author

Kani999 commented Apr 29, 2024

please add at least one unit test to support your changes

Tests were added

Copy link
Contributor Author

@Kani999 Kani999 left a 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

omehrabi and others added 9 commits May 21, 2024 12:06
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
@Kani999 Kani999 force-pushed the extend-show-bgp-address-family-class branch from 6f4c741 to c4c26cf Compare May 21, 2024 10:24
@Kani999 Kani999 force-pushed the extend-show-bgp-address-family-class branch from a958071 to 55bba54 Compare May 23, 2024 04:34
@ThomasJRyan ThomasJRyan merged commit 529dba9 into CiscoTestAutomation:master Jun 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants