Skip to content
Snippets Groups Projects
Unverified Commit 3b0e52fd authored by Sebastian Lohff's avatar Sebastian Lohff Committed by GitHub
Browse files

riscli dump-loc-rip: dump v4 and v6 + additional error handling (#259)

* riscli dump-loc-rip: Dump IPv4/IPv6 routes

By default riscli dump-loc-rib will now dump IPv4 and IPv6 routes. The
flags -4 and -6 have been added to restrict dumping to a single address
family.

* riscli dump-loc-rip: Handle EOF from API
parent 8f752579
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ package main ...@@ -2,6 +2,8 @@ package main
import ( import (
"context" "context"
"fmt"
"io"
"os" "os"
pb "github.com/bio-routing/bio-rd/cmd/ris/api" pb "github.com/bio-routing/bio-rd/cmd/ris/api"
...@@ -16,6 +18,10 @@ func NewDumpLocRIBCommand() cli.Command { ...@@ -16,6 +18,10 @@ func NewDumpLocRIBCommand() cli.Command {
cmd := cli.Command{ cmd := cli.Command{
Name: "dump-loc-rib", Name: "dump-loc-rib",
Usage: "dump loc RIB", Usage: "dump loc RIB",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "4", Usage: "print IPv4 routes"},
&cli.BoolFlag{Name: "6", Usage: "print IPv6 routes"},
},
} }
cmd.Action = func(c *cli.Context) error { cmd.Action = func(c *cli.Context) error {
...@@ -26,11 +32,26 @@ func NewDumpLocRIBCommand() cli.Command { ...@@ -26,11 +32,26 @@ func NewDumpLocRIBCommand() cli.Command {
} }
defer conn.Close() defer conn.Close()
afisafis := make([]pb.DumpRIBRequest_AFISAFI, 0)
req_ipv4, req_ipv6 := c.Bool("4"), c.Bool("6")
if !req_ipv4 && !req_ipv6 {
req_ipv4, req_ipv6 = true, true
}
if req_ipv4 {
afisafis = append(afisafis, pb.DumpRIBRequest_IPv4Unicast)
}
if req_ipv6 {
afisafis = append(afisafis, pb.DumpRIBRequest_IPv6Unicast)
}
client := pb.NewRoutingInformationServiceClient(conn) client := pb.NewRoutingInformationServiceClient(conn)
err = dumpRIB(client, c.GlobalString("router"), c.GlobalUint64("vrf_id")) for _, afisafi := range afisafis {
if err != nil { fmt.Printf(" --- Dump %s ---\n", pb.DumpRIBRequest_AFISAFI_name[int32(afisafi)])
log.Errorf("DumpRIB failed: %v", err) err = dumpRIB(client, c.GlobalString("router"), c.GlobalUint64("vrf_id"), afisafi)
os.Exit(1) if err != nil {
log.Errorf("DumpRIB failed: %v", err)
os.Exit(1)
}
} }
return nil return nil
...@@ -39,11 +60,11 @@ func NewDumpLocRIBCommand() cli.Command { ...@@ -39,11 +60,11 @@ func NewDumpLocRIBCommand() cli.Command {
return cmd return cmd
} }
func dumpRIB(c pb.RoutingInformationServiceClient, routerName string, vrfID uint64) error { func dumpRIB(c pb.RoutingInformationServiceClient, routerName string, vrfID uint64, afisafi pb.DumpRIBRequest_AFISAFI) error {
client, err := c.DumpRIB(context.Background(), &pb.DumpRIBRequest{ client, err := c.DumpRIB(context.Background(), &pb.DumpRIBRequest{
Router: routerName, Router: routerName,
VrfId: vrfID, VrfId: vrfID,
Afisafi: pb.DumpRIBRequest_IPv4Unicast, Afisafi: afisafi,
}) })
if err != nil { if err != nil {
return errors.Wrap(err, "Unable to get client") return errors.Wrap(err, "Unable to get client")
...@@ -52,6 +73,9 @@ func dumpRIB(c pb.RoutingInformationServiceClient, routerName string, vrfID uint ...@@ -52,6 +73,9 @@ func dumpRIB(c pb.RoutingInformationServiceClient, routerName string, vrfID uint
for { for {
r, err := client.Recv() r, err := client.Recv()
if err != nil { if err != nil {
if err == io.EOF {
return nil
}
return errors.Wrap(err, "Received failed") return errors.Wrap(err, "Received failed")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment