diff --git a/cmd/riscli/dump_loc_rib.go b/cmd/riscli/dump_loc_rib.go new file mode 100644 index 0000000000000000000000000000000000000000..f8bff16192fc9ec63f410935866c503c1a37ad5b --- /dev/null +++ b/cmd/riscli/dump_loc_rib.go @@ -0,0 +1,60 @@ +package main + +import ( + "context" + "os" + + pb "github.com/bio-routing/bio-rd/cmd/ris/api" + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" + "github.com/urfave/cli" + "google.golang.org/grpc" +) + +// NewDumpLocRIBCommand creates a new dump local rib command +func NewDumpLocRIBCommand() cli.Command { + cmd := cli.Command{ + Name: "dump-loc-rib", + Usage: "dump loc RIB", + } + + cmd.Action = func(c *cli.Context) error { + conn, err := grpc.Dial(c.GlobalString("ris"), grpc.WithInsecure()) + if err != nil { + log.Errorf("GRPC dial failed: %v", err) + os.Exit(1) + } + defer conn.Close() + + client := pb.NewRoutingInformationServiceClient(conn) + err = dumpRIB(client, c.GlobalString("router"), c.GlobalUint64("vrf_id")) + if err != nil { + log.Errorf("DumpRIB failed: %v", err) + os.Exit(1) + } + + return nil + } + + return cmd +} + +func dumpRIB(c pb.RoutingInformationServiceClient, routerName string, vrfID uint64) error { + client, err := c.DumpRIB(context.Background(), &pb.DumpRIBRequest{ + Router: routerName, + VrfId: vrfID, + Afisafi: pb.DumpRIBRequest_IPv4Unicast, + }) + if err != nil { + return errors.Wrap(err, "Unable to get client") + } + + for { + r, err := client.Recv() + if err != nil { + return errors.Wrap(err, "Received failed") + } + + printRoute(r.Route) + } +} diff --git a/cmd/riscli/main.go b/cmd/riscli/main.go new file mode 100644 index 0000000000000000000000000000000000000000..a57f3a73f27e1f3623d017a381725084a1956117 --- /dev/null +++ b/cmd/riscli/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "os" + + log "github.com/sirupsen/logrus" + "github.com/urfave/cli" +) + +func main() { + app := cli.NewApp() + app.Name = "riscli" + app.Usage = "RIS CLI" + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "ris", + Usage: "RIS GRPC address", + Value: "", + }, + cli.StringFlag{ + Name: "router", + Usage: "Router Name", + Value: "", + }, + cli.Uint64Flag{ + Name: "vrf_id", + Usage: "VRF ID", + Value: 0, + }, + } + + app.Commands = []cli.Command{ + NewDumpLocRIBCommand(), + } + + err := app.Run(os.Args) + if err != nil { + log.Error(err) + os.Exit(1) + } +} diff --git a/cmd/riscli/route.go b/cmd/riscli/route.go new file mode 100644 index 0000000000000000000000000000000000000000..c255feab0c2ecbac7812440029cd9f5d5c39bac8 --- /dev/null +++ b/cmd/riscli/route.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" + + "github.com/bio-routing/bio-rd/route" + "github.com/bio-routing/bio-rd/route/api" +) + +func printRoute(ar *api.Route) { + r := route.RouteFromProtoRoute(ar) + fmt.Println(r.Print()) +} diff --git a/go.mod b/go.mod index b6a552d8ecd9d7cb1c83bfdfa9f529fc1ac0cf70..5ee91324265d45a96038715c2d7331f57fb581cc 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/prometheus/common v0.6.0 github.com/sirupsen/logrus v1.3.0 github.com/stretchr/testify v1.3.0 + github.com/urfave/cli v1.21.0 github.com/vishvananda/netlink v1.0.0 github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 diff --git a/go.sum b/go.sum index de6b9ab0e577d5c2aad7c5c17663bdf2b1fb6f25..d989d8a514db4ca73c4d023cfd83819d6cd23523 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -70,6 +71,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCOJgSM= github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc h1:R83G5ikgLMxrBvLh22JhdfI8K6YXEPHx5P03Uu3DRs4=