1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

added routes dumping

This commit is contained in:
Matthias Hannig 2017-06-22 15:06:54 +02:00
parent 5a63f96ea5
commit 56141bb10f
3 changed files with 65 additions and 0 deletions

View file

@ -242,3 +242,61 @@ func RoutesLookupProtocol(net string, protocol string) (Parsed, bool) {
func RoutesPeer(peer string) (Parsed, bool) {
return RunAndParse("route export '"+peer+"'", parseRoutes)
}
func RoutesDump() (Parsed, bool) {
if ParserConf.PerPeerTables {
return RoutesDumpPerPeerTable()
}
return RoutesDumpSingleTable()
}
func RoutesDumpSingleTable() (Parsed, bool) {
exportedRes, cached := RunAndParse("route all", parseRoutes)
filteredRes, _ := RunAndParse("route filtered all", parseRoutes)
exported := exportedRes["routes"]
filtered := filteredRes["routes"]
result := Parsed{
"exported": exported,
"filtered": filtered,
}
return result, cached
}
func RoutesDumpPerPeerTable() (Parsed, bool) {
exportedRes, cached := RunAndParse("route all", parseRoutes)
exported := exportedRes["routes"]
filtered := []Parsed{}
// Get protocols with filtered routes
protocols, _ := ProtocolsBgp()
for protocol, details := range protocols {
details, ok := details.(Parsed)
counters, ok := details["routes"].(map[string]int)
if !ok {
continue
}
filterCount := counters["filtered"]
if filterCount == 0 {
continue // nothing to do here.
}
// Lookup filtered routes
pfilteredRes, _ := RunAndParse(
"route filtered protocol '"+protocol+"' all",
parseRoutes)
pfiltered, ok := pfilteredRes["routes"].([]Parsed)
if !ok {
continue // something went wrong...
}
filtered = append(filtered, pfiltered...)
}
result := Parsed{
"exported": exported,
"filtered": filtered,
}
return result, cached
}

View file

@ -75,6 +75,9 @@ func makeRouter(config endpoints.ServerConfig) *httprouter.Router {
if isModuleEnabled("routes_peer", whitelist) {
r.GET("/routes/peer", endpoints.Endpoint(endpoints.RoutesPeer))
}
if isModuleEnabled("routes_dump", whitelist) {
r.GET("/routes/dump", endpoints.Endpoint(endpoints.RoutesDump))
}
return r
}

View file

@ -83,3 +83,7 @@ func RoutesPeer(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
}
return bird.RoutesPeer(peer)
}
func RoutesDump(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
return bird.RoutesDump()
}