github.com/osrg/gobgp@v2.0.0+incompatible/docs/sources/grpc-client.md (about)

     1  # Managing GoBGP with Your Favorite Language
     2  
     3  This page explains how to managing GoBGP with your favorite Language. You can use any language supported by [gRPC](http://www.grpc.io/) (10 languages are supported now). This page gives an example in Python and C++.
     4  
     5  ## Contents
     6  
     7  - [Prerequisite](#prerequisite)
     8  - [Python](#python)
     9  - [C++](#cpp)
    10  
    11  ## Prerequisite
    12  
    13  We assumes that you have the relevant tools installed to generate the server and client interface for your favorite language from proto files. Please refer to [the official docs of gRPC](http://www.grpc.io/docs/) for details.
    14  
    15  ## Python
    16  
    17  ### Generating Interface
    18  
    19  You need to generate the server and client interface from GoBGP proto files at first.
    20  
    21  ```bash
    22  $ python -m grpc_tools.protoc -I./api --python_out=. --grpc_python_out=. api/gobgp.proto api/attribute.proto api/capability.proto
    23  ```
    24  
    25  ### Adding Path
    26  
    27  [`tools/grpc/python/add_path.py`](https://github.com/osrg/gobgp/blob/master/tools/grpc/python/add_path.py)
    28  shows an example for adding a route.
    29  Let's run this script.
    30  
    31  ```bash
    32  $ PYTHONPATH=$PYTHONPATH:. python add_path.py
    33  ```
    34  
    35  See if the route was added to the global rib.
    36  
    37  ```bash
    38  $ gobgp g r
    39     Network              Next Hop             AS_PATH              Age        Attrs
    40  *> 10.0.0.0/24          1.1.1.1              100 200              00:08:02   [{Origin: ?}]
    41  ```
    42  
    43  ## C++
    44  
    45  ### Generating Interface and Binary
    46  
    47  Use [`tools/grpc/cpp/Makefile`](https://github.com/osrg/gobgp/blob/master/tools/grpc/cpp/Makefile).
    48  
    49  ```bash
    50  $ cd tools/grpc/cpp
    51  $ make
    52   ```
    53  
    54  The above to generate the server and client interface and the binary to add a route by using `AddPath` API, ['tools/grpc/cpp/add_path.cc'](https://github.com/osrg/gobgp/blob/master/tools/grpc/cpp/add_path.cc).
    55  
    56  ### Adding Path
    57  
    58  Let's run the binary.
    59  
    60  ```bash
    61  $ ./add_path
    62  ```
    63  
    64  See if he route was added to the global rib.
    65  
    66  ```bash
    67  $ gobgp g r
    68     Network              Next Hop             AS_PATH              Age        Attrs
    69  *> 10.0.0.0/24          1.1.1.1                                   00:13:26   [{Origin: i} {Communities: 0:100}]
    70  ```