Git Product home page Git Product logo

pygobgp's Introduction

PyGoBGP

PyGoBGP is a simple python package to interact with GOBGP (currently briefly tested on only GoBGP v1.25). GoBGP uses gRPC as the API, however for many network engineers gRPC is a black magic. PyGoBGP handles the gRPC calls for you. However it only supports very basic calls for the moment.

Install

Using pip it's a breeze

pip install pygobgp

or get the latest version (may not stable)

pip install git+https://github.com/oneryalcin/PyGoBGP.git

Usage

PyGoBGP comes with protocol buffers generated py files gobgp_pb2.py abd gobgp_pb2_grpc.py for GoBGP v1.25 only.

Example Topology:

Check PyGoBGP-Example repo for docker based setup for sandboxing

GoBGP address: 10.0.255.2
GoBGP Local AS: 65412

Remote address: 10.0.255.3
Remote Peer AS: 65001

Connect to GoBGP instance, default port is 50051 if not specified

from gobgp import PyGoBGP
gobgp = PyGoBGP(address="10.0.255.2")

Get Neighbor Params

neigbor = gobgp.get_neigbor(address="10.0.255.3")
print(neighbor)

families: 65537
...
conf {
  local_as: 64512
  neighbor_address: "10.0.255.3"
  peer_as: 65001
  ...
  local_address: "10.0.255.2"
}
info {
  ...
  bgp_state: "established"
}
...

Get Global BGP RIB-IN

Assume remote peer has following route and will advertise to GoBGP:

{
    'prefix': '50.30.16.0/20',
    'as_path': [5607, 1000],
    'next_hop': '60.1.2.3',
    'community': ['1000:2000', '3000:4000'],
    'med': 20
}  
routes = gobgp.get_rib()
print(routes)

[{'prefix': '50.30.16.0/20',
  'as_path': [65001, 5607, 1000],
  'next_hop': '60.1.2.3',
  'community': ['1000:2000', '3000:4000'],
  'med': 20}]

Note that AS 65001 is prepended as it is an eBGP session.

Remove Neighbor

gobgp.delete_neighbor(address="10.0.255.3")
neigbor = gobgp.get_neigbor(address="10.0.255.3")
print(neigbor)

None

Add neighbor back

First define neigbor params

neighbor = {
    "local_address": "10.0.255.2",
    "neighbor_address": "10.0.255.3",
    "local_as": 64512,
    "peer_as": 65001,
}
gobgp.add_neighbor(**neighbor)
neigbor = gobgp.get_neigbor(address="10.0.255.3")
print(neighbor)

families: 65537
...
conf {
  local_as: 64512
  neighbor_address: "10.0.255.3"
  peer_as: 65001
  ...
  local_address: "10.0.255.2"
}
info {
  ...
  bgp_state: "established"
}
...

Route Injection

Upcoming

NOTES

This library is not definitely a production grade library yet and not tested properly. Under development and highly likely I will only develop the needed features. Having said that all contributions are welcomed.

Appendix A (Populating Python GoBGP gRPC files)

Download GOBGP proto file

wget https://raw.githubusercontent.com/osrg/gobgp/v1.25/api/gobgp.proto

Install Python GRPC libs

pip install grpcio grpcio-tools googleapis-common-protos

Populate python GRPC API classes to interact with GOBGP

python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. gobgp.proto

Now we have the following files available

    gobgp_pb2_grpc.py
    gobgp_pb2.py

pygobgp's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.