diff --git a/cmd/riscli/main.go b/cmd/riscli/main.go index abe8ba4a..a6145348 100644 --- a/cmd/riscli/main.go +++ b/cmd/riscli/main.go @@ -10,7 +10,6 @@ import ( ) func main() { - logger := logrus.New() logger.SetLevel(logrus.InfoLevel) log.SetLogger(log.NewLogrusWrapper(logger)) @@ -49,6 +48,7 @@ func main() { NewObserveRIBCommand(), NewDumpLocRIBCommand(), NewLPMCommand(), + NewGetRoutersCommand(), } err := app.Run(os.Args) diff --git a/cmd/riscli/routers.go b/cmd/riscli/routers.go new file mode 100644 index 00000000..66b3c210 --- /dev/null +++ b/cmd/riscli/routers.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "fmt" + "os" + + pb "github.com/bio-routing/bio-rd/cmd/ris/api" + "github.com/bio-routing/bio-rd/routingtable/vrf" + "github.com/bio-routing/bio-rd/util/log" + "github.com/urfave/cli" +) + +// NewLPMCommand creates a new LPM command +func NewGetRoutersCommand() cli.Command { + cmd := cli.Command{ + Name: "routers", + Usage: "get all routers and vrfs available", + Flags: []cli.Flag{}, + } + + cmd.Action = func(c *cli.Context) error { + conn := SetupGRPCClient(c) + defer conn.Close() + + client := pb.NewRoutingInformationServiceClient(conn) + err := getRouters(client) + if err != nil { + log.Errorf("Get Routers failed: %v", err) + os.Exit(1) + } + + return nil + } + + return cmd +} + +func getRouters(c pb.RoutingInformationServiceClient) error { + resp, err := c.GetRouters(context.Background(), &pb.GetRoutersRequest{}) + if err != nil { + return fmt.Errorf("unable to get client: %w", err) + } + for _, r := range resp.GetRouters() { + fmt.Printf("Router %s at %s\n", r.SysName, r.Address) + fmt.Println("VRFs:") + for _, v := range r.VrfIds { + fmt.Printf("%s (Numeric: %v)\n", vrf.RouteDistinguisherHumanReadable(v), v) + } + fmt.Println("---") + } + return nil +}