added default pools for routes

This commit is contained in:
Annika Hannig 2022-11-16 10:03:33 +01:00
parent 9da371065d
commit 0648f8e095
7 changed files with 51 additions and 4 deletions

View File

@ -62,7 +62,7 @@ func (routes Routes) Len() int {
}
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) {
@ -77,7 +77,7 @@ func (routes Routes) ToLookupRoutes(
) LookupRoutes {
lookupRoutes := make(LookupRoutes, 0, len(routes))
for _, route := range routes {
neighbor, ok := neighbors[route.NeighborID]
neighbor, ok := neighbors[*route.NeighborID]
if !ok {
log.Println("prepare route, neighbor not found:", route.NeighborID)
continue
@ -186,7 +186,7 @@ func (r LookupRoutes) Len() int {
}
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) {

42
pkg/pools/pools.go Normal file
View 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()
}

View File

@ -322,7 +322,12 @@ func parseRouteData(
details = json.RawMessage(detailsJSON)
}
// Pool: Gateways
gateway := decoders.String(rdata["gateway"], "unknown gateway")
learntFrom := decoders.String(rdata["learnt_from"], "")
if learntFrom == "" {
learntFrom = gateway
}
route := &api.Route{
ID: decoders.String(rdata["network"], "unknown"),
@ -332,7 +337,7 @@ func parseRouteData(
Interface: decoders.String(rdata["interface"], "unknown interface"),
Metric: decoders.Int(rdata["metric"], -1),
Primary: decoders.Bool(rdata["primary"], false),
LearntFrom: decoders.String(rdata["learnt_from"], gateway),
LearntFrom: learntFrom,
Gateway: gateway,
Age: age,
Type: rtype,