added prefix lookup on single node
This commit is contained in:
parent
b7e0792976
commit
03140a1187
@ -143,6 +143,26 @@ type Route struct {
|
|||||||
Details Details `json:"details"`
|
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
|
type Routes []Route
|
||||||
|
|
||||||
// Implement sorting interface for routes
|
// Implement sorting interface for routes
|
||||||
@ -167,5 +187,5 @@ type RoutesResponse struct {
|
|||||||
|
|
||||||
type LookupResponse struct {
|
type LookupResponse struct {
|
||||||
Api ApiStatus `json:"api"`
|
Api ApiStatus `json:"api"`
|
||||||
Routes []Route `json:"routes"`
|
Routes []LookupRoute `json:"routes"`
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ type UiConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SourceConfig struct {
|
type SourceConfig struct {
|
||||||
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Type int
|
Type int
|
||||||
|
|
||||||
@ -181,7 +182,7 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
|
|||||||
sources := []SourceConfig{}
|
sources := []SourceConfig{}
|
||||||
|
|
||||||
sourceSections := config.ChildSections("source")
|
sourceSections := config.ChildSections("source")
|
||||||
for _, section := range sourceSections {
|
for id, section := range sourceSections {
|
||||||
if !isSourceBase(section) {
|
if !isSourceBase(section) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -209,6 +210,7 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
|
|||||||
|
|
||||||
// Make config
|
// Make config
|
||||||
config := SourceConfig{
|
config := SourceConfig{
|
||||||
|
Id: id,
|
||||||
Name: section.Key("name").MustString("Unknown Source"),
|
Name: section.Key("name").MustString("Unknown Source"),
|
||||||
Type: backendType,
|
Type: backendType,
|
||||||
}
|
}
|
||||||
@ -217,6 +219,8 @@ func getSources(config *ini.File) ([]SourceConfig, error) {
|
|||||||
switch backendType {
|
switch backendType {
|
||||||
case SOURCE_BIRDWATCHER:
|
case SOURCE_BIRDWATCHER:
|
||||||
backendConfig.MapTo(&config.Birdwatcher)
|
backendConfig.MapTo(&config.Birdwatcher)
|
||||||
|
config.Birdwatcher.Id = config.Id
|
||||||
|
config.Birdwatcher.Name = config.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to list of sources
|
// Add to list of sources
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package birdwatcher
|
package birdwatcher
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Id int
|
||||||
|
Name string
|
||||||
|
|
||||||
Api string `ini:"api"`
|
Api string `ini:"api"`
|
||||||
Timezone string `ini:"timezone"`
|
Timezone string `ini:"timezone"`
|
||||||
ShowLastReboot bool `ini:"show_last_reboot"`
|
ShowLastReboot bool `ini:"show_last_reboot"`
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package birdwatcher
|
package birdwatcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/ecix/alice-lg/backend/api"
|
"github.com/ecix/alice-lg/backend/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,5 +110,67 @@ func (self *Birdwatcher) Routes(neighbourId string) (api.RoutesResponse, error)
|
|||||||
|
|
||||||
// Make routes lookup
|
// Make routes lookup
|
||||||
func (self *Birdwatcher) LookupPrefix(prefix string) (api.LookupResponse, error) {
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user