Skip to content

Commit

Permalink
riscli: Add "get routers" feature (#431)
Browse files Browse the repository at this point in the history
Co-authored-by: Marvin Gaube <marvin.gaube@exaring.de>
  • Loading branch information
margau and Marvin Gaube authored Feb 15, 2023
1 parent 299db46 commit ee76fb0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/riscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func main() {

logger := logrus.New()
logger.SetLevel(logrus.InfoLevel)
log.SetLogger(log.NewLogrusWrapper(logger))
Expand Down Expand Up @@ -49,6 +48,7 @@ func main() {
NewObserveRIBCommand(),
NewDumpLocRIBCommand(),
NewLPMCommand(),
NewGetRoutersCommand(),
}

err := app.Run(os.Args)
Expand Down
53 changes: 53 additions & 0 deletions cmd/riscli/routers.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ee76fb0

Please sign in to comment.