From 4b5e4e719234457ca5e425fe3163ed0ae1e5df6a Mon Sep 17 00:00:00 2001 From: Oliver Herms Date: Fri, 15 Jan 2021 19:41:27 +0100 Subject: [PATCH] Implement next AS resolution --- go.mod | 2 +- go.sum | 2 ++ pkg/clickhousegw/clickhousegw.go | 23 ++++++++++++++++++++++- pkg/ipannotator/ipannotator.go | 15 ++++++++++++--- pkg/routemirror/route_mirror.go | 1 - 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 4afb68c..ab6d5ce 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( github.com/ClickHouse/clickhouse-go v1.4.1 - github.com/bio-routing/bio-rd v0.0.3-pre4 + github.com/bio-routing/bio-rd v0.0.3-pre5 github.com/bio-routing/tflow2 v0.0.0-20200122091514-89924193643e github.com/gogo/protobuf v1.3.1 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index e3f0063..253fa00 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ github.com/bio-routing/bio-rd v0.0.3-pre2 h1:Ho7ytp/sVp3Bh9SsFd1wn/IMwygwAkTRNkO github.com/bio-routing/bio-rd v0.0.3-pre2/go.mod h1:Dm2pV+USySIWrQ13pjU0+KxXwiKPGdiigDv2fM+RcDs= github.com/bio-routing/bio-rd v0.0.3-pre4 h1:Q3zvIBhT2V63p3/KTFpB1hShDD/9Ej0iWSC6xY9+6ks= github.com/bio-routing/bio-rd v0.0.3-pre4/go.mod h1:Dm2pV+USySIWrQ13pjU0+KxXwiKPGdiigDv2fM+RcDs= +github.com/bio-routing/bio-rd v0.0.3-pre5 h1:DT9DmIf+tpU0++Y5/hz8Nx9Ly0X2NdaMlpjpLek/cDI= +github.com/bio-routing/bio-rd v0.0.3-pre5/go.mod h1:Dm2pV+USySIWrQ13pjU0+KxXwiKPGdiigDv2fM+RcDs= github.com/bio-routing/tflow2 v0.0.0-20181230153523-2e308a4a3c3a/go.mod h1:tjzJ5IykdbWNs1FjmiJWsH6SRBl+aWgxO5I44DAegIw= github.com/bio-routing/tflow2 v0.0.0-20200122091514-89924193643e h1:Zh5s5mFKBG1dwDLJU1fsPoFxTmixabOhqEuKrOkrKLM= github.com/bio-routing/tflow2 v0.0.0-20200122091514-89924193643e/go.mod h1:4E2F/ExVEOHe9VF0fqQP60HTCWCMOWV4PyB8R/HndPU= diff --git a/pkg/clickhousegw/clickhousegw.go b/pkg/clickhousegw/clickhousegw.go index db008d7..ca63501 100644 --- a/pkg/clickhousegw/clickhousegw.go +++ b/pkg/clickhousegw/clickhousegw.go @@ -103,7 +103,28 @@ func (c *ClickHouseGateway) InsertFlows(flows []*flow.Flow) error { return errors.Wrap(err, "Begin failed") } - stmt, err := tx.Prepare("INSERT INTO flows (agent, int_in, int_out, src_ip_addr, dst_ip_addr, src_ip_pfx_addr, src_ip_pfx_len, dst_ip_pfx_addr, dst_ip_pfx_len, nexthop, next_asn, src_asn, dst_asn, ip_protocol, src_port, dst_port, timestamp, size, packets, samplerate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + stmt, err := tx.Prepare(`INSERT INTO flows ( + agent, + int_in, + int_out, + src_ip_addr, + dst_ip_addr, + src_ip_pfx_addr, + src_ip_pfx_len, + dst_ip_pfx_addr, + dst_ip_pfx_len, + nexthop, + next_asn, + src_asn, + dst_asn, + ip_protocol, + src_port, + dst_port, + timestamp, + size, + packets, + samplerate + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ?, ?, ?)`) if err != nil { return errors.Wrap(err, "Prepare failed") } diff --git a/pkg/ipannotator/ipannotator.go b/pkg/ipannotator/ipannotator.go index 64b2776..ad08edb 100644 --- a/pkg/ipannotator/ipannotator.go +++ b/pkg/ipannotator/ipannotator.go @@ -47,12 +47,21 @@ func (ipa *IPAnnotator) Annotate(fl *flow.Flow) error { } fl.DstPfx = *drt.Prefix() - dstFirstASPathSeg := drt.BestPath().BGPPath.ASPath.GetLastSequenceSegment() - if dstFirstASPathSeg != nil { - dstASN := dstFirstASPathSeg.GetLastASN() + dstLastASPathSeg := drt.BestPath().BGPPath.ASPath.GetLastSequenceSegment() + if dstLastASPathSeg != nil { + dstASN := dstLastASPathSeg.GetLastASN() if dstASN != nil { fl.DstAs = *dstASN } } + + dstFirstASPathSeg := drt.BestPath().BGPPath.ASPath.GetFirstSequenceSegment() + if dstFirstASPathSeg != nil { + nextASN := dstFirstASPathSeg.GetFirstASN() + if nextASN != nil { + fl.NextAs = *nextASN + } + } + return nil } diff --git a/pkg/routemirror/route_mirror.go b/pkg/routemirror/route_mirror.go index 206d415..953835a 100644 --- a/pkg/routemirror/route_mirror.go +++ b/pkg/routemirror/route_mirror.go @@ -92,6 +92,5 @@ func (r *RouteMirror) LPM(rtrAddr string, vrfRD uint64, addr bnet.IP) (*route.Ro return nil, nil } - // TODO: Check if PathSelection() in bio is wrong. Best route is apparently last element. Should be first... return routes[len(routes)-1], nil }