added prefix lookup on single node

This commit is contained in:
Matthias Hannig 2017-06-19 15:27:11 +02:00
parent b7e0792976
commit 03140a1187
4 changed files with 93 additions and 5 deletions

View File

@ -143,6 +143,26 @@ type Route struct {
Details Details `json:"details"`
}
// Lookup Prefixes
type LookupRoute struct {
Id string `json:"id"`
Routeserver Routeserver `json:"routeserver"`
NeighbourId string `json:"neighbour_id"`
Neighbour Neighbour `json:"neighbour"`
Network string `json:"network"`
Interface string `json:"interface"`
Gateway string `json:"gateway"`
Metric int `json:"metric"`
Bgp BgpInfo `json:"bgp"`
Age time.Duration `json:"age"`
Type []string `json:"type"` // [BGP, unicast, univ]
Details Details `json:"details"`
}
type Routes []Route
// Implement sorting interface for routes
@ -167,5 +187,5 @@ type RoutesResponse struct {
type LookupResponse struct {
Api ApiStatus `json:"api"`
Routes []Route `json:"routes"`
Routes []LookupRoute `json:"routes"`
}

View File

@ -42,6 +42,7 @@ type UiConfig struct {
}
type SourceConfig struct {
Id int
Name string
Type int
@ -181,7 +182,7 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
sources := []SourceConfig{}
sourceSections := config.ChildSections("source")
for _, section := range sourceSections {
for id, section := range sourceSections {
if !isSourceBase(section) {
continue
}
@ -209,6 +210,7 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
// Make config
config := SourceConfig{
Id: id,
Name: section.Key("name").MustString("Unknown Source"),
Type: backendType,
}
@ -217,6 +219,8 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
switch backendType {
case SOURCE_BIRDWATCHER:
backendConfig.MapTo(&config.Birdwatcher)
config.Birdwatcher.Id = config.Id
config.Birdwatcher.Name = config.Name
}
// Add to list of sources

View File

@ -1,6 +1,9 @@
package birdwatcher
type Config struct {
Id int
Name string
Api string `ini:"api"`
Timezone string `ini:"timezone"`
ShowLastReboot bool `ini:"show_last_reboot"`

View File

@ -1,7 +1,6 @@
package birdwatcher
import (
"fmt"
"github.com/ecix/alice-lg/backend/api"
)
@ -111,5 +110,67 @@ func (self *Birdwatcher) Routes(neighbourId string) (api.RoutesResponse, error)
// Make routes lookup
func (self *Birdwatcher) LookupPrefix(prefix string) (api.LookupResponse, error) {
return api.LookupResponse{}, fmt.Errorf("not implemented")
// Get RS info
rs := api.Routeserver{
Id: self.config.Id,
Name: self.config.Name,
}
// Get neighbours list from RS
neighboursRes, err := self.Neighbours()
if err != nil {
return api.LookupResponse{}, err
}
neighbours := neighboursRes.Neighbours
// Query prefix on RS
bird, err := self.client.GetJson("/routes/prefix?prefix=" + prefix)
if err != nil {
return api.LookupResponse{}, err
}
// Parse API status
apiStatus, err := parseApiStatus(bird, self.config)
if err != nil {
return api.LookupResponse{}, err
}
// Parse routes
routes, err := parseRoutes(bird, self.config)
// Add corresponding neighbour and source rs to result
results := []api.LookupRoute{}
for _, src := range routes {
// Get corresponding neighbour
neighbour, _ := getNeighbourById(neighbours, src.NeighbourId)
// Okay. This is actually really hacky.
// A less bruteforce approach would be highly appreciated
route := api.LookupRoute{
Id: src.Id,
Routeserver: rs,
NeighbourId: src.NeighbourId,
Neighbour: neighbour,
Network: src.Network,
Interface: src.Interface,
Gateway: src.Gateway,
Metric: src.Metric,
Bgp: src.Bgp,
Age: src.Age,
Type: src.Type,
Details: src.Details,
}
results = append(results, route)
}
// Make result
response := api.LookupResponse{
Api: apiStatus,
Routes: results,
}
return response, nil
}