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

fix errors of "show ip bgp summary" and "show ip bgp neigh" under alias #3457

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

Conversation

JoshYangEC
Copy link

What I did

After setting alias mode, the output of "show ip/ipv6 bgp summary" and "show ip/ipv6 bgp neighbors" return errors. This PR fixes the issue to support alias mode for these bgp commands.

Reproduce steps

  1. "show ip bgp summary": return errors
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ip bgp summary
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/bgp_frr_v4.py", line 36, in summary
    bgp_summary = bgp_util.get_bgp_summary_from_all_bgp_instances(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/utilities_common/bgp_util.py", line 257, in get_bgp_summary_from_all_bgp_instances
    cmd_output = run_bgp_show_command(vtysh_cmd, ns)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/utilities_common/bgp_util.py", line 229, in run_bgp_show_command
    if 'nexthops' in info[i]:
                     ~~~~^^^
KeyError: 0
  1. "show ipv6 bgp summary": return json format and end with errors
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ipv6 bgp summary
{
"ipv6Unicast":{
  "routerId":"10.1.0.32",
  "as":65100,
  "vrfId":0,
  "vrfName":"default",
  "tableVersion":1,
  "ribCount":1,
  "ribMemory":192,
  "peerCount":2,
  "peerMemory":1483952,
  "peerGroupCount":2,
  "peerGroupMemory":128,
  "peers":{
    "fc00::2":{
      "remoteAs":65200,
      "localAs":65100,
      "version":4,
      "msgRcvd":0,
      "msgSent":0,
      "tableVersion":0,
      "outq":0,
      "inq":0,
      "peerUptime":"never",
      "peerUptimeMsec":0,
      "pfxRcd":0,
      "pfxSnt":0,
      "state":"Active",
      "peerState":"OK",
      "connectionsEstablished":0,
      "connectionsDropped":0,
      "desc":"ARISTA01T2",
      "idType":"ipv6"
    },
    "fc00::4a":{
      "remoteAs":64003,
      "localAs":65100,
      "version":4,
      "msgRcvd":0,
      "tableVersion":0,
      "outq":0,
      "inq":0,
      "peerUptime":"never",
      "peerUptimeMsec":0,
      "pfxRcd":0,
      "pfxSnt":0,
      "state":"Active",
      "peerState":"OK",
      "connectionsEstablished":0,
      "connectionsDropped":0,
      "desc":"ARISTA03T0",
      "idType":"ipv6"
    }
  },
  "failedPeers":2,
  "displayedPeers":2,
  "totalPeers":2,
  "dynamicPeers":0,
  "bestPath":{
    "multiPathRelax":"true"
  }
}
}
Usage: show ipv6 bgp summary [OPTIONS]
Try "show ipv6 bgp summary -h" for help.

Error: Unable to get summary from bgp []
  1. "show ip bgp neighbors": return errors
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ip bgp neighbors
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/bgp_frr_v4.py", line 87, in neighbors
    output += bgp_util.run_bgp_show_command(command, ns)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/utilities_common/bgp_util.py", line 226, in run_bgp_show_command
    route_info =json.loads(output)
                ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  1. "show ipv6 bgp neighbors": return vtysh output and end with errors
admin@sonic:~$ show ipv6 bgp neighbors
admin@as7726-32x-3:~$ show ipv6 bgp neighbors | more
BGP neighbor is fc00::2, remote AS 65200, local AS 65100, external link
  Local Role: undefined
  Remote Role: undefined
 Description: ARISTA01T2
 Member of peer-group PEER_V6 for session parameters
  BGP version 4, remote router ID 0.0.0.0, local router ID 10.1.0.32
  BGP state = Connect
  Last read 00:10:22, Last write never
  Hold time is 10 seconds, keepalive interval is 3 seconds
  Configured hold time is 10 seconds, keepalive interval is 3 seconds
  Configured conditional advertisements interval is 60 seconds
  Graceful restart information:
    Local GR Mode: Helper*

    Remote GR Mode: NotApplicable

    R bit: False
    N bit: False
    Timers:
      Configured Restart Time(sec): 120
      Received Restart Time(sec): 0
  Message statistics:
  Inq depth is 0
    Outq depth is 0
                         Sent       Rcvd
    Opens:                  0          0
    Notifications:          0          0
    Updates:                0          0
    Keepalives:             0          0
    Route Refresh:          0          0
    Capability:             0          0
    Total:                  0          0
  Minimum time between advertisement runs is 0 seconds
  ......
  For address family: IPv6 Unicast
  PEER_V6 peer-group member
  Not part of any update group
  Inbound soft reconfiguration allowed
  Community attribute sent to this neighbor(all)
  Inbound path policy configured
  Outbound path policy configured
  Route map for incoming advertisements is *FROM_BGP_PEER_V6
  Route map for outgoing advertisements is *TO_BGP_PEER_V6
  0 accepted prefixes

  Connections established 0; dropped 0
  Last reset 00:12:03,  Waiting for peer OPEN
  External BGP neighbor may be up to 1 hops away.
BGP Connect Retry Timer in Seconds: 10
Next connect timer due in 2 seconds
Read thread: off  Write thread: off  FD used: -1


Usage: show ipv6 bgp neighbors [OPTIONS] [IPADDRESS] [[routes|advertised-
                               routes|received-routes]]
Try "show ipv6 bgp neighbors -h" for help.

Error: Unable to get summary from bgp []

How I did it

enhance the function run_bgp_show_command in bgp_util.py to support alias mode for the following commands:

  • show ip|ipv6 bgp summary
  • show ip|ipv6 bgp neighbors

In the original function run_bgp_show_command, it only handles the command show ip|ipv6 route. Here, we define a new dict structure to map the vtysh commands, as these commands require specific functions to handle the output of the vtysh command. Additionally, the function needs to convert interface names to alias names in the output of the vtysh command.

How to verify it

  1. execute "show ip bgp summary" to verify
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ip bgp summary

IPv4 Unicast Summary:
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 1
RIB entries 1, using 192 bytes of memory
Peers 2, using 1483952 KiB of memory
Peer groups 2, using 128 bytes of memory


Neighbhor      V     AS    MsgRcvd    MsgSent    TblVer    InQ    OutQ  Up/Down    State/PfxRcd    NeighborName
-----------  ---  -----  ---------  ---------  --------  -----  ------  ---------  --------------  --------------
10.0.0.1       4  65200          0          0         0      0       0  never      Active          ARISTA01T2
10.0.0.3       4  65200          0          0         0      0       0  never      Active          ARISTA02T2

Total number of neighbors 2
  1. execute "show ipv6 bgp summary" to verify
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ipv6 bgp summary

IPv6 Unicast Summary:
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 1
RIB entries 1, using 192 bytes of memory
Peers 2, using 1483952 KiB of memory
Peer groups 2, using 128 bytes of memory


Neighbhor      V     AS    MsgRcvd    MsgSent    TblVer    InQ    OutQ  Up/Down    State/PfxRcd    NeighborName
-----------  ---  -----  ---------  ---------  --------  -----  ------  ---------  --------------  --------------
fc00::2        4  65200          0          0         0      0       0  never      Active          ARISTA01T2
fc00::4a       4  64003          0          0         0      0       0  never      Active          ARISTA03T0

Total number of neighbors 2
  1. execute "show ip bgp neighbors" to verify
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ip bgp neighbors
BGP neighbor is 10.0.0.1, remote AS 65200, local AS 65100, external link
  Local Role: undefined
  Remote Role: undefined
 Description: ARISTA01T2
 Member of peer-group PEER_V4 for session parameters
  BGP version 4, remote router ID 0.0.0.0, local router ID 10.1.0.32
  BGP state = Active
  Last read 00:18:03, Last write never
  Hold time is 10 seconds, keepalive interval is 3 seconds
  Configured hold time is 10 seconds, keepalive interval is 3 seconds
  Configured conditional advertisements interval is 60 seconds
  Graceful restart information:
    Local GR Mode: Helper*

    Remote GR Mode: NotApplicable

    R bit: False
    N bit: False
    Timers:
      Configured Restart Time(sec): 120
      Received Restart Time(sec): 0
  Message statistics:
    Inq depth is 0
    Outq depth is 0
                         Sent       Rcvd
    Opens:                  0          0
    Notifications:          0          0
    Updates:                0          0
    .......
    
    Keepalives:             0          0
    Route Refresh:          0          0
    Capability:             0          0
    Total:                  0          0
  Minimum time between advertisement runs is 0 seconds

 For address family: IPv6 Unicast
  PEER_V6 peer-group member
  Not part of any update group
  Inbound soft reconfiguration allowed
  Community attribute sent to this neighbor(all)
  Inbound path policy configured
  Outbound path policy configured
  Route map for incoming advertisements is *FROM_BGP_PEER_V6
  Route map for outgoing advertisements is *TO_BGP_PEER_V6
  0 accepted prefixes

  Connections established 0; dropped 0
  Last reset 00:18:03,  Waiting for peer OPEN
  External BGP neighbor may be up to 1 hops away.
BGP Connect Retry Timer in Seconds: 10
Next connect timer due in 5 seconds
Read thread: off  Write thread: off  FD used: -1
  1. execute "show ipv6 bgp neighbors" to verify
admin@sonic:~$ SONIC_CLI_IFACE_MODE=alias show ipv6 bgp neighbors
BGP neighbor is 10.0.0.1, remote AS 65200, local AS 65100, external link
  Local Role: undefined
  Remote Role: undefined
 Description: ARISTA01T2
 Member of peer-group PEER_V4 for session parameters
  BGP version 4, remote router ID 0.0.0.0, local router ID 10.1.0.32
  BGP state = Active
  Last read 00:18:03, Last write never
  Hold time is 10 seconds, keepalive interval is 3 seconds
  Configured hold time is 10 seconds, keepalive interval is 3 seconds
  Configured conditional advertisements interval is 60 seconds
  Graceful restart information:
    Local GR Mode: Helper*

    Remote GR Mode: NotApplicable

    R bit: False
    N bit: False
    Timers:
      Configured Restart Time(sec): 120
      Received Restart Time(sec): 0
  Message statistics:
    Inq depth is 0
    Outq depth is 0
                         Sent       Rcvd
    Opens:                  0          0
    Notifications:          0          0
    Updates:                0          0
    .......
    
    Keepalives:             0          0
    Route Refresh:          0          0
    Capability:             0          0
    Total:                  0          0
  Minimum time between advertisement runs is 0 seconds

 For address family: IPv6 Unicast
  PEER_V6 peer-group member
  Not part of any update group
  Inbound soft reconfiguration allowed
  Community attribute sent to this neighbor(all)
  Inbound path policy configured
  Outbound path policy configured
  Route map for incoming advertisements is *FROM_BGP_PEER_V6
  Route map for outgoing advertisements is *TO_BGP_PEER_V6
  0 accepted prefixes

  Connections established 0; dropped 0
  Last reset 00:18:03,  Waiting for peer OPEN
  External BGP neighbor may be up to 1 hops away.
BGP Connect Retry Timer in Seconds: 10
Next connect timer due in 5 seconds
Read thread: off  Write thread: off  FD used: -1

Copy link

linux-foundation-easycla bot commented Jul 30, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: JoshYangEC / name: Josh Yang (ff90185)

In alias mode, the output of "show ip/ipv6 bgp summary" and "show ip/ipv6
bgp neigh" return errors. This PR is used to fix these errors.
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.

1 participant