cli: support monitoring specific route family

// monitor only ipv6 best path changes
$ gobgp monitor global rib -a ipv6

Signed-off-by: ISHIDA Wataru <[email protected]>
This commit is contained in:
ISHIDA Wataru
2015-10-07 22:58:50 +09:00
parent 8669c4ecea
commit 28ecbd5b2e
3 changed files with 13 additions and 7 deletions
+3 -1
View File
@@ -465,7 +465,9 @@ func checkAddressFamily(ip net.IP) (bgp.RouteFamily, error) {
case "ipv6-flowspec", "ipv6-flow", "flow6":
rf = bgp.RF_FS_IPv6_UC
case "":
if len(ip) == 0 || ip.To4() != nil {
if ip == nil {
return rf, nil
} else if len(ip) == 0 || ip.To4() != nil {
rf = bgp.RF_IPv4_UC
} else {
rf = bgp.RF_IPv6_UC
+2 -2
View File
@@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/context"
"io"
"net"
"os"
)
@@ -30,7 +29,7 @@ func NewMonitorCmd() *cobra.Command {
ribCmd := &cobra.Command{
Use: CMD_RIB,
Run: func(cmd *cobra.Command, args []string) {
rf, err := checkAddressFamily(net.IP{})
rf, err := checkAddressFamily(nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
@@ -69,6 +68,7 @@ func NewMonitorCmd() *cobra.Command {
},
}
ribCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")
globalCmd := &cobra.Command{
Use: CMD_GLOBAL,
+8 -4
View File
@@ -608,6 +608,8 @@ func (server *BgpServer) broadcastBests(bests []*table.Path) {
}
}
rf := path.GetRouteFamily()
result := &GrpcResponse{
Data: &api.Destination{
Prefix: path.GetNlri().String(),
@@ -625,11 +627,13 @@ func (server *BgpServer) broadcastBests(bests []*table.Path) {
remainReqs = append(remainReqs, req)
continue
}
m := &broadcastGrpcMsg{
req: req,
result: result,
if req.RouteFamily == bgp.RouteFamily(0) || req.RouteFamily == rf {
m := &broadcastGrpcMsg{
req: req,
result: result,
}
server.broadcastMsgs = append(server.broadcastMsgs, m)
}
server.broadcastMsgs = append(server.broadcastMsgs, m)
remainReqs = append(remainReqs, req)
}
server.broadcastReqs = remainReqs