github.com/osrg/gobgp/v3@v3.30.0/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++](#c)
    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./ --python_out=. --grpc_python_out=. *.proto
    23  $ ls *.py
    24  attribute_pb2.py  attribute_pb2_grpc.py  capability_pb2.py  capability_pb2_grpc.py  gobgp_pb2.py  gobgp_pb2_grpc.py
    25  ```
    26  
    27  ### Adding Path
    28  
    29  [`tools/grpc/python/add_path.py`](https://github.com/osrg/gobgp/blob/master/tools/grpc/python/add_path.py)
    30  shows an example for adding a route.
    31  Let's run this script.
    32  
    33  ```bash
    34  $ PYTHONPATH=$PYTHONPATH:. python add_path.py
    35  ```
    36  
    37  See if the route was added to the global rib.
    38  
    39  ```bash
    40  $ gobgp g r
    41     Network              Next Hop             AS_PATH              Age        Attrs
    42  *> 10.0.0.0/24          1.1.1.1              100 200              00:08:02   [{Origin: ?}]
    43  ```
    44  
    45  ### Adding BGP-SR policy
    46  
    47  [`tools/grpc/python/sr_policy.py`](https://github.com/osrg/gobgp/blob/master/tools/grpc/python/sr_policy.py)
    48  shows an example for adding a bgp-sr route.
    49  Let's run this script.
    50  
    51  ```bash
    52  $ PYTHONPATH=$PYTHONPATH:. python sr_policy.py
    53  ```
    54  
    55  ## Result of injecting the SR policy
    56  
    57  Once the sr policy is injected, gobgp will advertise it to the peers with SR Policy enabled address family. Below is the output collect
    58  ed from Nokia SROS router with enabled SR policy address family.
    59  
    60  ```log
    61  A:R1# show router segment-routing sr-policies all color 100
    62  
    63  ===============================================================================
    64  SR-Policies Path
    65  ===============================================================================
    66  -------------------------------------------------------------------------------
    67  Active          : Yes                   Owner           : bgp
    68  Color           : 100
    69  Head            : 0.0.0.0               Endpoint Addr   : 10.6.6.6
    70  RD              : 2                     Preference      : 11
    71  BSID            : 300004
    72  TunnelId        : 917525                Age             : 7
    73  Origin ASN      : 800                   Origin          : 10.100.1.201
    74  NumReEval       : 0                     ReEvalReason    : none
    75  NumActPathChange: 0                     Last Change     : 03/23/2022 11:05:48
    76  Maintenance Policy: N/A
    77  
    78  Path Segment Lists:
    79  Segment-List    : 1                     Weight          : 12
    80  S-BFD State     : Down                  S-BFD Transitio*: 0
    81  Num Segments    : 2                     Last Change     : 03/22/2022 14:09:33
    82    Seg 1 Label   : 200002                State           : resolved-up
    83    Seg 2 Label   : 200006                State           : N/A
    84  
    85  ===============================================================================
    86  * indicates that the corresponding row element may have been truncated.
    87  ```
    88  
    89  ## C++
    90  
    91  ### Generating Interface and Binary
    92  
    93  Use [`tools/grpc/cpp/Makefile`](https://github.com/osrg/gobgp/blob/master/tools/grpc/cpp/Makefile).
    94  
    95  ```bash
    96  $ cd tools/grpc/cpp
    97  $ make
    98   ```
    99  
   100  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).
   101  
   102  ### Adding Path
   103  
   104  Let's run the binary.
   105  
   106  ```bash
   107  $ ./add_path
   108  ```
   109  
   110  See if he route was added to the global rib.
   111  
   112  ```bash
   113  $ gobgp g r
   114     Network              Next Hop             AS_PATH              Age        Attrs
   115  *> 10.0.0.0/24          1.1.1.1                                   00:13:26   [{Origin: i} {Communities: 0:100}]
   116  ```