diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-02-07 07:04:18 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-02-07 07:19:17 +0900 |
commit | fba7e1a349222ff433061e9535481ed5a2a6ce73 (patch) | |
tree | 96806cc27c8dd80c8d5ea027973573650051c509 | |
parent | 64fdc90646db6824e37625d373c7468b8f74a3af (diff) |
cli: add monitor adj-in command
// monitor all incoming updates
$ gobgp monitor adj-in
// filter by neighbor
$ gobgp monitor adj-in 192.168.10.1
// filter by address family
$ gobgp monitor adj-in -a ipv4
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/common.go | 2 | ||||
-rw-r--r-- | gobgp/cmd/monitor.go | 55 |
2 files changed, 57 insertions, 0 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index 84925d0b..44de301e 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -163,6 +163,7 @@ type Path struct { IsWithdraw bool `json:"isWithdraw"` Validation int32 `json:"validation"` Filtered bool `json:"filtered"` + SourceId string `json:"source-id"` } func ApiStruct2Path(p *gobgpapi.Path) ([]*Path, error) { @@ -208,6 +209,7 @@ func ApiStruct2Path(p *gobgpapi.Path) ([]*Path, error) { Best: p.Best, IsWithdraw: p.IsWithdraw, Validation: p.Validation, + SourceId: p.SourceId, Filtered: p.Filtered, }) } diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go index 95f5af2a..88142866 100644 --- a/gobgp/cmd/monitor.go +++ b/gobgp/cmd/monitor.go @@ -164,12 +164,67 @@ func NewMonitorCmd() *cobra.Command { }, } + adjInCmd := &cobra.Command{ + Use: CMD_ADJ_IN, + Run: func(cmd *cobra.Command, args []string) { + name := "" + if len(args) > 0 { + remoteIP := net.ParseIP(args[0]) + if remoteIP == nil { + fmt.Println("invalid ip address: %s", args[0]) + os.Exit(1) + } + name = args[0] + } + family, err := checkAddressFamily(bgp.RouteFamily(0)) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + arg := &gobgpapi.Table{ + Type: gobgpapi.Resource_ADJ_IN, + Family: uint32(family), + Name: name, + } + + stream, err := client.MonitorRib(context.Background(), arg) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + for { + d, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + fmt.Println(err) + os.Exit(1) + } + p, err := ApiStruct2Path(d.Paths[0]) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + if globalOpts.Json { + j, _ := json.Marshal(p) + fmt.Println(string(j)) + } else { + ShowRoute(p, false, false, false, true, false) + } + } + + }, + } + adjInCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family") + monitorCmd := &cobra.Command{ Use: CMD_MONITOR, } monitorCmd.AddCommand(globalCmd) monitorCmd.AddCommand(neighborCmd) monitorCmd.AddCommand(rpkiCmd) + monitorCmd.AddCommand(adjInCmd) return monitorCmd } |