Exa-Networks / exabgp

The BGP swiss army knife of networking
Other
2.05k stars 440 forks source link

How to ANNOUNCE large scale BGP route with ExaBGP's API #1187

Closed goodluck68 closed 8 months ago

goodluck68 commented 8 months ago

Hello team,

I am currently working with a script where I am using the ExaBGP API to announce BGP routes. Here's what I've got:

import requests
url = "http://10.10.10.10:99"
data = {"command": "ANNOUNCE route 91.0.1.0/24 next-hop self"}
requests.post(url, data=data)

I'm facing a challenge. I need to announce about 10,000 BGP routes in a short time, and running the above piece of code repeatedly isn't the most efficient.

  1. Is there a way to include multiple "ANNOUNCE route" commands in one go, using the data variable? Does the API support this kind of batch operation?

  2. If yes, what's the right way to structure the data? I've thought of a couple of formats:

    • This one:
      data = {
       "command": "ANNOUNCE route 10.0.0.1/24 next-hop self",
       "command": "ANNOUNCE route 10.0.0.2/24 next-hop self",
       "command": "ANNOUNCE route 10.0.0.3/24 next-hop self"
      }
    • Or maybe this?
      data = {
       "command": [
           "ANNOUNCE route 10.0.0.1/24 next-hop self",
           "ANNOUNCE route 10.0.0.2/24 next-hop self",
           "ANNOUNCE route 10.0.0.3/24 next-hop self"
       ]
      }

      Could you help confirm?

  3. Any other suggestions or methods you'd recommend for efficiently announcing a large number of BGP routes?

Really appreciate your help on this. Thank you!

thomas-mangin commented 8 months ago

There is no HTTP API with ExaBGP so whatever you are using is not part of any code we support.

All annoucements are single line text based, so I have no idea how you get to use HTTP but it must pass the HTTP payload via the ExaAPI API which is two unix pipes connected to STDIN and STDOUT.

If you need to improve this code, please look for post using announce attribute ... ... ... nlri ... ... ... which allows to announce multiple NLRIs which share the same attributes.

goodluck68 commented 8 months ago

There is no HTTP API with ExaBGP so whatever you are using is not part of any code we support.

All annoucements are single line text based, so I have no idea how you get to use HTTP but it must pass the HTTP payload via the ExaAPI API which is two unix pipes connected to STDIN and STDOUT.

If you need to improve this code, please look for post using announce attribute ... ... ... nlri ... ... ... which allows to announce multiple NLRIs which share the same attributes.

Thanks your suggestion! I have found an example ANNOUNCE attribute next-hop self nlri 10.0.1.0/24 10.0.1.1/24 10.0.1.2/24. I will base on this to update my case

Another question need your help. If I withdraw multiple BGP NLRI, does the command work? like this WITHDRAW attribute next-hop self nlri 10.0.1.0/24 10.0.1.1/24 10.0.1.2/24 In the BGP protocol, the UPDATE message does not require path attribute info when withdrawing a route, so I want to know whether the withdraw command is correct?

thomas-mangin commented 8 months ago

It is plural, but I just allowed singular on the main branch.

https://github.com/Exa-Networks/exabgp/blob/c299fdb73198c3a1946e733f8db8187b8e6fe1b8/src/exabgp/reactor/api/command/announce.py#L257

Unless you are using PATH_INFO or VPLS/MPLS, it may not require the attribute data. I would need to check the RFC and the code to be sure what the code does and if it is right ...