do not deduplicate networks
This commit is contained in:
parent
50f155917a
commit
6e3a433c82
@ -11,7 +11,7 @@ type Route struct {
|
||||
ID string `json:"id"`
|
||||
NeighborID *string `json:"neighbor_id"`
|
||||
|
||||
Network *string `json:"network"`
|
||||
Network string `json:"network"`
|
||||
Interface *string `json:"interface"`
|
||||
Gateway *string `json:"gateway"`
|
||||
Metric int `json:"metric"`
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
|
@ -49,7 +49,7 @@ func apiQueryFilterNextHopGateway(
|
||||
|
||||
results := make(api.Routes, 0, len(routes))
|
||||
for _, r := range routes {
|
||||
if strings.HasPrefix(strings.ToLower(*r.Network), queryString) ||
|
||||
if strings.HasPrefix(strings.ToLower(r.Network), queryString) ||
|
||||
strings.HasPrefix(strings.ToLower(*r.Gateway), queryString) {
|
||||
results = append(results, r)
|
||||
}
|
||||
|
@ -22,19 +22,19 @@ func makeQueryRoutes() api.Routes {
|
||||
&api.Route{
|
||||
ID: "route_01",
|
||||
NeighborID: pools.Neighbors.Acquire("n01"),
|
||||
Network: pools.Networks4.Acquire("123.42.43.0/24"),
|
||||
Network: "123.42.43.0/24",
|
||||
Gateway: pools.Gateways4.Acquire("23.42.42.1"),
|
||||
},
|
||||
&api.Route{
|
||||
ID: "route_02",
|
||||
NeighborID: pools.Neighbors.Acquire("n01"),
|
||||
Network: pools.Networks4.Acquire("142.23.0.0/16"),
|
||||
Network: "142.23.0.0/16",
|
||||
Gateway: pools.Gateways4.Acquire("42.42.42.1"),
|
||||
},
|
||||
&api.Route{
|
||||
ID: "route_03",
|
||||
NeighborID: pools.Neighbors.Acquire("n01"),
|
||||
Network: pools.Networks4.Acquire("123.43.0.0/16"),
|
||||
Network: "123.43.0.0/16",
|
||||
Gateway: pools.Gateways4.Acquire("23.42.43.1"),
|
||||
},
|
||||
}
|
||||
|
@ -319,7 +319,6 @@ func parseRouteData(
|
||||
keepDetails bool,
|
||||
) *api.Route {
|
||||
gwpool := pools.Gateways4 // Let's see
|
||||
netpool := pools.Networks4 // same...
|
||||
|
||||
age := parseRelativeServerTime(rdata["age"], config)
|
||||
rtype := decoders.StringList(rdata["type"])
|
||||
@ -346,8 +345,7 @@ func parseRouteData(
|
||||
|
||||
NeighborID: pools.Neighbors.Acquire(
|
||||
decoders.String(rdata["from_protocol"], "unknown neighbor")),
|
||||
Network: netpool.Acquire(
|
||||
decoders.String(rdata["network"], "unknown net")),
|
||||
Network: decoders.String(rdata["network"], "unknown net"),
|
||||
Interface: pools.Interfaces.Acquire(
|
||||
decoders.String(rdata["interface"], "unknown interface")),
|
||||
Metric: decoders.Int(rdata["metric"], -1),
|
||||
|
@ -88,7 +88,7 @@ func (gobgp *GoBGP) parsePathIntoRoute(
|
||||
route.ID = fmt.Sprintf("%s_%s", path.SourceId, prefix)
|
||||
route.NeighborID = pools.Neighbors.Acquire(
|
||||
PeerHashWithASAndAddress(path.SourceAsn, path.NeighborIp))
|
||||
route.Network = pools.Networks4.Acquire(prefix)
|
||||
route.Network = prefix
|
||||
route.Interface = pools.Interfaces.Acquire("unknown")
|
||||
route.Age = time.Since(time.Unix(path.Age.GetSeconds(), int64(path.Age.GetNanos())))
|
||||
route.Primary = path.Best
|
||||
|
@ -43,7 +43,7 @@ func decodeNeighbor(n interface{}) (*api.Neighbor, error) {
|
||||
prefixes := decoders.MapGet(stats, "prefixes", map[string]interface{}{})
|
||||
|
||||
neighbor := &api.Neighbor{
|
||||
ID: decoders.MapGetString(nb, "remote_addr", "invalid_id"),
|
||||
// ID: decoders.MapGetString(nb, "remote_addr", "invalid_id"),
|
||||
Address: decoders.MapGetString(nb, "remote_addr", "invalid_address"),
|
||||
ASN: decoders.IntFromString(decoders.MapGetString(nb, "remote_as", ""), -1),
|
||||
State: decodeState(decoders.MapGetString(nb, "state", "unknown")),
|
||||
@ -198,7 +198,7 @@ func decodeRoute(details map[string]interface{}) (*api.Route, error) {
|
||||
r := &api.Route{
|
||||
ID: prefix,
|
||||
NeighborID: pools.Neighbors.Acquire(neighborID),
|
||||
Network: pools.Networks4.Acquire(prefix),
|
||||
Network: prefix,
|
||||
Gateway: pools.Gateways4.Acquire(trueNextHop),
|
||||
BGP: bgpInfo,
|
||||
Age: lastUpdate,
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/alice-lg/alice-lg/pkg/pools"
|
||||
)
|
||||
|
||||
func readTestData(filename string) map[string]interface{} {
|
||||
@ -56,8 +54,8 @@ func TestDecodeRoutes(t *testing.T) {
|
||||
|
||||
// Check first route
|
||||
r := routes[0]
|
||||
ipPtr := pools.Networks4.Acquire("23.42.1.0/24")
|
||||
if r.Network != ipPtr {
|
||||
ip := "23.42.1.0/24"
|
||||
if r.Network != ip {
|
||||
t.Error("unexpected network:", r.Network)
|
||||
}
|
||||
// Community decoding
|
||||
|
Loading…
x
Reference in New Issue
Block a user