===== GoBGP ===== ====GoBGP containerlab definition==== gobgp1: kind: linux image: mygobgp:4.2.0_v1 binds: - gobgp1/gobgp.toml:/etc/gobgp/gobgp.toml exec: - ip -6 addr add 2001:db8:8101::2/64 dev eth1 - ip -6 addr add 2001:db8:9101::2/64 dev eth2 - ip link set dev eth1 up - ip link set dev eth2 up cmd: gobgpd -f /etc/gobgp/gobgp.toml -l info -a --api-hosts 0.0.0.0:50051 [global.config] as = 65577 router-id = "172.16.0.103" [[neighbors]] [neighbors.config] neighbor-address = "2001:db8:8101::1" peer-as = 65577 [[neighbors.afi-safis]] [neighbors.afi-safis.config] afi-safi-name = "l3vpn-ipv4-unicast" [[neighbors]] [neighbors.config] neighbor-address = "2001:db8:9101::1" peer-as = 65577 [[neighbors.afi-safis]] [neighbors.afi-safis.config] afi-safi-name = "l3vpn-ipv4-unicast" ====GoBGP commands==== ubuntu@containerlab1:~/jonathan/srv6-mixed5$ docker exec -ti clab-srv6-mixed5-gobgp1 bash gobgp1:/# gobgp global rib -a ipv4-l3vpn Network Labels Next Hop AS_PATH Age Attrs * 172.16.0.14:65500:192.168.34.0/24 [917744] 2001:db8:e::1 20:28:00 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.14} {ClusterList: [172.16.0.101]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:e:: Flag: 0 Endpoint Behavior: 64 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.14:65500:192.168.34.0/24 [917744] 2001:db8:e::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.14} {ClusterList: [172.16.0.102]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:e:: Flag: 0 Endpoint Behavior: 64 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.14:65500:192.168.44.0/24 [917760] 2001:db8:e::1 20:28:00 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.14} {ClusterList: [172.16.0.101]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:e:: Flag: 0 Endpoint Behavior: 64 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.14:65500:192.168.44.0/24 [917760] 2001:db8:e::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.14} {ClusterList: [172.16.0.102]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:e:: Flag: 0 Endpoint Behavior: 64 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.16:65500:192.168.36.0/24 [32] 2001:db8:10::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.16} {ClusterList: [172.16.0.101]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:10:: Flag: 0 Endpoint Behavior: 20 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 24, Locator Node Length: 24, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.16:65500:192.168.36.0/24 [32] 2001:db8:10::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.16} {ClusterList: [172.16.0.102]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:10:: Flag: 0 Endpoint Behavior: 20 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 24, Locator Node Length: 24, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.16:65501:192.168.46.0/24 [48] 2001:db8:10::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.16} {ClusterList: [172.16.0.101]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:10:: Flag: 0 Endpoint Behavior: 20 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 24, Locator Node Length: 24, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.16:65501:192.168.46.0/24 [48] 2001:db8:10::1 20:27:59 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.16} {ClusterList: [172.16.0.102]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:10:: Flag: 0 Endpoint Behavior: 20 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 24, Locator Node Length: 24, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.11:65500:192.168.31.0/24 [917520] 2001:db8:b::1 00:36:53 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.11} {ClusterList: [172.16.0.101]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:b:: Flag: 0 Endpoint Behavior: 63 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.11:65500:192.168.31.0/24 [917520] 2001:db8:b::1 00:36:53 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.11} {ClusterList: [172.16.0.102]} {Extcomms: [65000:101]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:b:: Flag: 0 Endpoint Behavior: 63 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.11:65500:192.168.41.0/24 [917552] 2001:db8:b::1 00:36:53 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.11} {ClusterList: [172.16.0.101]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:b:: Flag: 0 Endpoint Behavior: 63 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] * 172.16.0.11:65500:192.168.41.0/24 [917552] 2001:db8:b::1 00:36:53 [{Origin: ?} {Med: 0} {LocalPref: 100} {Originator: 172.16.0.11} {ClusterList: [172.16.0.102]} {Extcomms: [65000:102]} {Prefix SID attributes: {SRv6 L3 Service Attribute: {SRv6 Information Sub TLV: SID: 2001:db8:b:: Flag: 0 Endpoint Behavior: 63 {SRv6 Structure Sub Sub TLV: [ Locator Block Length: 32, Locator Node Length: 16, Function Length: 16, Argument Length: 0, Transposition Length: 16, Transposition Offset: 48] } } } }] ====GoBGP API client==== FROM python:3.12-slim RUN pip install --no-cache-dir grpcio grpcio-tools WORKDIR /app COPY proto/ /app/proto/ COPY gobgp_client.py /app/ RUN mkdir -p /app/gobgpapi && \ python -m grpc_tools.protoc \ -I/app/proto \ --python_out=/app/gobgpapi \ --grpc_python_out=/app/gobgpapi \ /app/proto/api/*.proto && \ # IMPORTANT: Créer les __init__.py pour que Python traite ces dossiers comme des modules touch /app/gobgpapi/__init__.py && \ touch /app/gobgpapi/api/__init__.py # On ajoute /app et /app/gobgpapi au path ENV PYTHONPATH=$PYTHONPATH:/app:/app/gobgpapi CMD ["python", "gobgp_client.py"] import grpc from api import gobgp_pb2, gobgp_pb2_grpc # Connexion channel = grpc.insecure_channel('gobgp1:50051') stub = gobgp_pb2_grpc.GoBgpServiceStub(channel) try: # Dans l'API GoBgpService, la méthode est GetBgp # Elle prend un message GetBgpRequest vide response = stub.GetBgp(gobgp_pb2.GetBgpRequest()) print("--- BGP Global Info ---") print(response) except grpc.RpcError as e: print(f"Erreur gRPC : {e.code()} - {e.details()}") except AttributeError: # Si GetBgp n'existe pas, essayons GetGlobal (ancienne version) print("GetBgp non trouvé, essai de GetGlobal...") response = stub.GetGlobal(gobgp_pb2.GetGlobalRequest()) print(response) ubuntu@containerlab1:~/jonathan/gobgp-client$ ls -ls total 20 4 -rw-rw-r-- 1 ubuntu ubuntu 628 Feb 3 17:19 Dockerfile 4 -rw-rw-r-- 1 ubuntu ubuntu 223 Feb 3 17:08 Dockerfile.bak 4 drwxrwxr-x 12 ubuntu ubuntu 4096 Feb 2 21:49 gobgp 4 -rw-rw-r-- 1 ubuntu ubuntu 689 Feb 3 17:24 gobgp_client.py 4 drwxrwxr-x 3 ubuntu ubuntu 4096 Feb 3 17:12 proto ubuntu@containerlab1:~/jonathan/gobgp-client$ ubuntu@containerlab1:~/jonathan/gobgp-client$ ubuntu@containerlab1:~/jonathan/gobgp-client$ ubuntu@containerlab1:~/jonathan/gobgp-client$ ls -ls proto total 4 4 drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 3 17:12 api ubuntu@containerlab1:~/jonathan/gobgp-client$ ls -ls proto/api total 72 16 -rw-rw-r-- 1 ubuntu ubuntu 13276 Feb 3 17:12 attribute.proto 4 -rw-rw-r-- 1 ubuntu ubuntu 3428 Feb 3 17:12 capability.proto 4 -rw-rw-r-- 1 ubuntu ubuntu 1225 Feb 3 17:12 common.proto 4 -rw-rw-r-- 1 ubuntu ubuntu 3364 Feb 3 17:12 extcom.proto 32 -rw-rw-r-- 1 ubuntu ubuntu 31016 Feb 3 17:12 gobgp.proto 12 -rw-rw-r-- 1 ubuntu ubuntu 8940 Feb 3 17:12 nlri.proto ubuntu@containerlab1:~/jonathan/gobgp-client$ ubuntu@containerlab1:~/jonathan/gobgp-client$ docker run --rm -it --network clab-mgmt-net gobgp-client:v8 --- BGP Global Info --- global { asn: 65577 router_id: "172.16.0.103" listen_port: 179 listen_addresses: "0.0.0.0" listen_addresses: "::" }