osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.59k stars 684 forks source link

Q&A: Is it possible to write a client code for FRR daemon using GoBGP library. #2624

Open sakthishanmugam02 opened 1 year ago

sakthishanmugam02 commented 1 year ago

Is it possible to write a client code for FRR daemon using GoBGP library. If possible, could anyone help, sharing references. I am not able to find the package "github.com/osrg/gobgp/client" based on the sample I got as below in the current version of GoBGP.

Note: I do not want to run GoBGP daemon for BGP - I am running FRR as daemon, would like to connect with FRR using GoBGP packages for ZAPI communication.

package main

import (
    "context"
    "fmt"
    "github.com/osrg/gobgp/client"
)

func main() {
    c, err := client.New("127.0.0.1:50051")
    if err != nil {
        fmt.Println("Error creating GoBGP client:", err)
        return
    }
    defer c.Close()

    routes, err := c.GetRib("", 0, false)
    if err != nil {
        fmt.Println("Error fetching routes:", err)
        return
    }

    for _, route := range routes {
        fmt.Println("Route:", route)
    }
}
floatingstatic commented 1 year ago

@sakthishanmugam02 No, instead you need to compile the proto definition provided by FRR into grpc client stubs in your language of choice using protoc and use that. See the proto definition here: https://github.com/opensourcerouting/frr/blob/master/grpc/frr-northbound.proto

Note, if you are using go the proto definition may need option go_package but you will have to raise that with the folks that maintain frr.

gobgp client is basically a cli/grpc client for gobgp's grpc service only implemented by gobgpd (server). FRR in turn has its own service definition and implementation so the client stub for gobgp is not compatible with FRR.