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

bgp: Add command for retrieving bgp routes #2201

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

rastislavs
Copy link
Contributor

@rastislavs rastislavs commented Dec 20, 2023

This change introduces a new BGP status command: cilium bgp routes. BGP routes can be retrieved from either all or a specific node; in json or summary formats.

The implementation follows the existing patterns of the cilium bgp peers command and mirrors the cilium-dbg bgp routes CLI added in cilium/cilium#27182 .

The change also adds an alias for the existing cilium bgp peers command (cilium bgp neighbors) to align with cilium-dbg.

Vendor updates as part of the change is mostly due to the necessary BGP packet types from GoBGP.

Examples:

Help:

$ cilium bgp routes -h                                                                                                                                   
Lists BGP routes from all nodes in the cluster - requires cilium >= v1.15.0

Usage:
  cilium bgp routes <available | advertised> <afi> <safi> [vrouter <asn>] [peer|neighbor <address>] [flags]

Examples:
  Get all IPv4 unicast routes available:
    cilium bgp routes available ipv4 unicast

  Get all IPv6 unicast routes available for a specific vrouter:
    cilium bgp routes available ipv6 unicast vrouter 65001

  Get IPv4 unicast routes advertised to a specific peer:
    cilium bgp routes advertised ipv4 unicast peer 10.0.0.1

Flags:
      --agent-pod-selector string   Label on cilium-agent pods to select with (default "k8s-app=cilium")
  -h, --help                        help for routes
      --node string                 Node from which BGP routes will be fetched, omit to select all nodes
  -o, --output string               Output format. One of: json, summary (default "summary")
      --wait-duration duration      Maximum time to wait for result, default 1 minute (default 1m0s)

Global Flags:
      --context string     Kubernetes configuration context
  -n, --namespace string   Namespace Cilium is running in (default "kube-system")

Simplest use:

$ cilium bgp routes                                                                                                                                                                     
(Defaulting to `available ipv4 unicast` routes, please see help for more options)

Node                              VRouter   Prefix        NextHop    Age   Attrs
bgp-cplane-dev-v4-control-plane   65001     10.1.0.0/24   0.0.0.0    55s   [{Origin: i} {Nexthop: 0.0.0.0}]                          
                                  65001     10.1.1.0/24   10.0.1.1   55s   [{Origin: i} {AsPath: 65000 65002} {Nexthop: 10.0.1.1}]   
bgp-cplane-dev-v4-worker          65002     10.1.0.0/24   10.0.2.1   55s   [{Origin: i} {AsPath: 65000 65001} {Nexthop: 10.0.2.1}]   
                                  65002     10.1.1.0/24   0.0.0.0    55s   [{Origin: i} {Nexthop: 0.0.0.0}]                     

Advertised routes to a specific peer of a specific node:

$ cilium bgp routes advertised ipv4 unicast peer 10.0.2.1 --node bgp-cplane-dev-v4-worker                                                                         
Node                       VRouter   Prefix        NextHop    Age     Attrs
bgp-cplane-dev-v4-worker   65002     10.1.1.0/24   10.0.2.2   1m37s   [{Origin: i} {AsPath: 65002} {Nexthop: 10.0.2.2}] 

The same as json:

$ cilium bgp routes advertised ipv4 unicast peer 10.0.2.1 --node bgp-cplane-dev-v4-worker -o json                                                                    
{
 "bgp-cplane-dev-v4-worker": [
  {
   "paths": [
    {
     "age-nanoseconds": 138734627807,
     "family": {
      "afi": "ipv4",
      "safi": "unicast"
     },
     "nlri": {
      "base64": "GAoBAQ=="
     },
     "path-attributes": [
      {
       "base64": "QAEBAA=="
      },
      {
       "base64": "QAIGAgEAAP3q"
      },
      {
       "base64": "QAMECgACAg=="
      }
     ]
    }
   ],
   "prefix": "10.1.1.0/24",
   "router-asn": 65002
  }
 ]
}

Copy link
Contributor

@harsimran-pabla harsimran-pabla left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM.

bgp/routes.go Show resolved Hide resolved
Copy link
Contributor

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@rastislavs Nice work!

bgp/routes.go Outdated Show resolved Hide resolved
Copy link
Contributor

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@rastislavs Thank you for the updates!

This change introduces a new BGP status command: `cilium bgp routes`.
BGP routes can be retrieved from all or a specific node in json
or summary formats.

Vendor update as part of the change is due to the necessary
BGP packet types from GoBGP.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
The change adds an alias for the existing `cilium bgp peers`
command (`cilium bgp neighbors`) to align with `cilium-dbg`.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
@rastislavs
Copy link
Contributor Author

@sayboras could you please take a look at this PR? It is now missing only vendor review.

Copy link
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

LGTM ✔️

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jan 12, 2024
@dylandreimerink dylandreimerink merged commit b7f9b99 into cilium:main Jan 15, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants