added default pools for routes
This commit is contained in:
parent
9da371065d
commit
0648f8e095
@ -62,7 +62,7 @@ func (routes Routes) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (routes Routes) Less(i, j int) bool {
|
func (routes Routes) Less(i, j int) bool {
|
||||||
return routes[i].Network < routes[j].Network
|
return *(routes[i].Network) < *(routes[j].Network)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (routes Routes) Swap(i, j int) {
|
func (routes Routes) Swap(i, j int) {
|
||||||
@ -77,7 +77,7 @@ func (routes Routes) ToLookupRoutes(
|
|||||||
) LookupRoutes {
|
) LookupRoutes {
|
||||||
lookupRoutes := make(LookupRoutes, 0, len(routes))
|
lookupRoutes := make(LookupRoutes, 0, len(routes))
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
neighbor, ok := neighbors[route.NeighborID]
|
neighbor, ok := neighbors[*route.NeighborID]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("prepare route, neighbor not found:", route.NeighborID)
|
log.Println("prepare route, neighbor not found:", route.NeighborID)
|
||||||
continue
|
continue
|
||||||
@ -186,7 +186,7 @@ func (r LookupRoutes) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r LookupRoutes) Less(i, j int) bool {
|
func (r LookupRoutes) Less(i, j int) bool {
|
||||||
return r[i].Route.Network < r[j].Route.Network
|
return (*r[i].Route.Network) < (*r[j].Route.Network)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r LookupRoutes) Swap(i, j int) {
|
func (r LookupRoutes) Swap(i, j int) {
|
||||||
|
42
pkg/pools/pools.go
Normal file
42
pkg/pools/pools.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Package pools provides deduplication pools for strings
|
||||||
|
// and lists of ints and strings.
|
||||||
|
package pools
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
// Default pools: These pools are defined globally
|
||||||
|
// and are defined per intended usage
|
||||||
|
|
||||||
|
// Networks stores network ip addresses
|
||||||
|
var Networks *String
|
||||||
|
|
||||||
|
// Interfaces stores interfaces like: eth0, bond0 etc...
|
||||||
|
var Interfaces *String
|
||||||
|
|
||||||
|
// Gateways4 store ip v4 gateway addresses
|
||||||
|
var Gateways4 *String
|
||||||
|
|
||||||
|
// Gateways6 store ip v6 gateway addresses
|
||||||
|
var Gateways6 *String
|
||||||
|
|
||||||
|
// Origins is a store for 'IGP'
|
||||||
|
var Origins *String
|
||||||
|
|
||||||
|
// ASPaths stores lists of ASNs
|
||||||
|
var ASPaths *IntList
|
||||||
|
|
||||||
|
// Types stores a list of types (['BGP', 'univ'])
|
||||||
|
var Types *StringList
|
||||||
|
|
||||||
|
// Initialize global pools
|
||||||
|
func init() {
|
||||||
|
log.Println("initializing memory pools")
|
||||||
|
|
||||||
|
Networks = NewString()
|
||||||
|
Interfaces = NewString()
|
||||||
|
Gateways4 = NewString()
|
||||||
|
Gateways6 = NewString()
|
||||||
|
Origins = NewString()
|
||||||
|
ASPaths = NewIntList()
|
||||||
|
Types = NewStringList()
|
||||||
|
}
|
@ -322,7 +322,12 @@ func parseRouteData(
|
|||||||
details = json.RawMessage(detailsJSON)
|
details = json.RawMessage(detailsJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pool: Gateways
|
||||||
gateway := decoders.String(rdata["gateway"], "unknown gateway")
|
gateway := decoders.String(rdata["gateway"], "unknown gateway")
|
||||||
|
learntFrom := decoders.String(rdata["learnt_from"], "")
|
||||||
|
if learntFrom == "" {
|
||||||
|
learntFrom = gateway
|
||||||
|
}
|
||||||
|
|
||||||
route := &api.Route{
|
route := &api.Route{
|
||||||
ID: decoders.String(rdata["network"], "unknown"),
|
ID: decoders.String(rdata["network"], "unknown"),
|
||||||
@ -332,7 +337,7 @@ func parseRouteData(
|
|||||||
Interface: decoders.String(rdata["interface"], "unknown interface"),
|
Interface: decoders.String(rdata["interface"], "unknown interface"),
|
||||||
Metric: decoders.Int(rdata["metric"], -1),
|
Metric: decoders.Int(rdata["metric"], -1),
|
||||||
Primary: decoders.Bool(rdata["primary"], false),
|
Primary: decoders.Bool(rdata["primary"], false),
|
||||||
LearntFrom: decoders.String(rdata["learnt_from"], gateway),
|
LearntFrom: learntFrom,
|
||||||
Gateway: gateway,
|
Gateway: gateway,
|
||||||
Age: age,
|
Age: age,
|
||||||
Type: rtype,
|
Type: rtype,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user