1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

172 lines
4.2 KiB
Go
Raw Normal View History

2017-05-18 12:52:10 +02:00
package api
import (
"time"
)
2017-05-18 15:26:22 +02:00
// General api response
type Response interface{}
2017-05-18 12:52:10 +02:00
// Details, usually the original backend response
type Details map[string]interface{}
2017-05-18 14:44:38 +02:00
// Error Handling
type ErrorResponse struct {
Error string `json:"error"`
}
// Config
2017-05-18 15:23:36 +02:00
type ConfigResponse struct {
Rejection Rejection `json:"rejection"`
RejectReasons map[int]string `json:"reject_reasons"`
2017-05-18 14:44:38 +02:00
2017-05-18 15:23:36 +02:00
Noexport Noexport `json:"noexport"`
NoexportReasons map[int]string `json:"noexport_reasons"`
2017-05-18 14:44:38 +02:00
RoutesColumns map[string]string `json:"routes_columns"`
}
type Rejection struct {
Asn int `json:"asn"`
RejectId int `json:"reject_id"`
}
type Noexport struct {
Asn int `json:"asn"`
NoexportId int `json:"noexport_id"`
}
2017-05-18 12:52:10 +02:00
// Status
type ApiStatus struct {
Version string `json:"version"`
CacheStatus CacheStatus `json:"cache_status"`
ResultFromCache bool `json:"result_from_cache"`
2017-05-19 17:56:24 +02:00
Ttl time.Time `json:"ttl"`
2017-05-18 12:52:10 +02:00
}
type CacheStatus struct {
CachedAt time.Time `json:"cached_at"`
OrigTtl int `json:"orig_ttl"`
}
type Status struct {
ServerTime time.Time `json:"server_time"`
LastReboot time.Time `json:"last_reboot"`
LastReconfig time.Time `json:"last_reconfig"`
Message string `json:"message"`
RouterId string `json:"router_id"`
Version string `json:"version"`
Backend string `json:"backend"`
}
type StatusResponse struct {
Api ApiStatus `json:"api"`
Status Status `json:"status"`
}
// Routeservers
type Routeserver struct {
Id int `json:"id"`
Name string `json:"name"`
}
type RouteserversResponse struct {
Routeservers []Routeserver `json:"routeservers"`
}
// Neighbours
2017-05-22 16:21:48 +02:00
type Neighbours []Neighbour
2017-05-18 12:52:10 +02:00
type Neighbour struct {
Id string `json:"id"`
// Mandatory fields
2017-05-22 11:46:27 +02:00
Address string `json:"address"`
Asn int `json:"asn"`
State string `json:"state"`
Description string `json:"description"`
RoutesReceived int `json:"routes_received"`
RoutesFiltered int `json:"routes_filtered"`
RoutesExported int `json:"routes_exported"`
RoutesPreferred int `json:"routes_preferred"`
Uptime time.Duration `json:"uptime"`
2017-05-22 16:21:48 +02:00
LastError string `json:"last_error"`
2017-05-18 12:52:10 +02:00
// Original response
Details map[string]interface{} `json:"details"`
}
2017-05-22 16:21:48 +02:00
// Implement sorting interface for routes
func (neighbours Neighbours) Len() int {
return len(neighbours)
}
func (neighbours Neighbours) Less(i, j int) bool {
return neighbours[i].Asn < neighbours[j].Asn
}
func (neighbours Neighbours) Swap(i, j int) {
neighbours[i], neighbours[j] = neighbours[j], neighbours[i]
}
2017-05-18 12:52:10 +02:00
type NeighboursResponse struct {
2017-05-22 16:21:48 +02:00
Api ApiStatus `json:"api"`
Neighbours Neighbours `json:"neighbours"`
2017-05-18 12:52:10 +02:00
}
// BGP
type Community []int
type BgpInfo struct {
2017-05-22 16:52:09 +02:00
Origin string `json:"origin"`
2017-05-22 13:26:37 +02:00
AsPath []int `json:"as_path"`
NextHop string `json:"next_hop"`
Communities []Community `json:"communities"`
LargeCommunities []Community `json:"large_communities"`
LocalPref int `json:"local_pref"`
Med int `json:"med"`
2017-05-18 12:52:10 +02:00
}
// Prefixes
2017-05-18 18:10:06 +02:00
type Route struct {
Id string `json:"id"`
NeighbourId string `json:"neighbour_id"`
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]
2017-05-18 12:52:10 +02:00
Details Details `json:"details"`
}
2017-05-18 18:10:06 +02:00
2017-05-22 16:21:48 +02:00
type Routes []Route
// Implement sorting interface for routes
func (routes Routes) Len() int {
return len(routes)
}
func (routes Routes) Less(i, j int) bool {
return routes[i].Network < routes[j].Network
}
func (routes Routes) Swap(i, j int) {
routes[i], routes[j] = routes[j], routes[i]
}
2017-05-18 18:10:06 +02:00
type RoutesResponse struct {
2017-05-23 15:25:15 +02:00
Api ApiStatus `json:"api"`
Imported []Route `json:"imported"`
Filtered []Route `json:"filtered"`
NotExported []Route `json:"not_exported"`
2017-05-18 18:10:06 +02:00
}
2017-05-23 13:58:58 +02:00
type LookupResponse struct {
Api ApiStatus `json:"api"`
Routes []Route `json:"routes"`
}