Skip to content

Commit

Permalink
Merge pull request #254 from bio-routing/fix/dedup_mem
Browse files Browse the repository at this point in the history
Make BGP path dedup optional. Set init cache size = 0.
  • Loading branch information
hikhvar authored Apr 15, 2020
2 parents 3538060 + 64cc1c4 commit 27fb65a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/bio-rdc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func showRouteReceiveBGP(parts []string) {
return
}

rr := route.RouteFromProtoRoute(r)
rr := route.RouteFromProtoRoute(r, false)
fmt.Println(rr.Print())
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/riscli/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
)

func printRoute(ar *api.Route) {
r := route.RouteFromProtoRoute(ar)
r := route.RouteFromProtoRoute(ar, false)
fmt.Println(r.Print())
}
2 changes: 1 addition & 1 deletion net/ip_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
ipCachePreAlloc = 1500000
ipCachePreAlloc = 0
)

var (
Expand Down
2 changes: 1 addition & 1 deletion net/prefix_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
prefixCachePreAlloc = 1500000
prefixCachePreAlloc = 0
)

var (
Expand Down
6 changes: 4 additions & 2 deletions route/bgp_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (b *BGPPath) ToProto() *api.BGPPath {
}

// BGPPathFromProtoBGPPath converts a proto BGPPath to BGPPath
func BGPPathFromProtoBGPPath(pb *api.BGPPath) *BGPPath {
func BGPPathFromProtoBGPPath(pb *api.BGPPath, dedup bool) *BGPPath {
p := &BGPPath{
BGPPathA: &BGPPathA{
NextHop: bnet.IPFromProtoIP(*pb.NextHop),
Expand All @@ -124,7 +124,9 @@ func BGPPathFromProtoBGPPath(pb *api.BGPPath) *BGPPath {
ASPath: types.ASPathFromProtoASPath(pb.AsPath),
}

p = p.Dedup()
if dedup {
p = p.Dedup()
}

communities := make(types.Communities, len(pb.Communities))
p.Communities = &communities
Expand Down
2 changes: 1 addition & 1 deletion route/bgp_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestBGPPathFromProtoBGPPath(t *testing.T) {
ClusterList: &types.ClusterList{999, 199},
}

result := BGPPathFromProtoBGPPath(input)
result := BGPPathFromProtoBGPPath(input, false)
assert.Equal(t, expected, result)
}

Expand Down
4 changes: 2 additions & 2 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (r *Route) ToProto() *api.Route {
}

// RouteFromProtoRoute converts a proto Route to a Route
func RouteFromProtoRoute(ar *api.Route) *Route {
func RouteFromProtoRoute(ar *api.Route, dedup bool) *Route {
r := &Route{
pfx: net.NewPrefixFromProtoPrefix(*ar.Pfx),
paths: make([]*Path, 0, len(ar.Paths)),
Expand All @@ -278,7 +278,7 @@ func RouteFromProtoRoute(ar *api.Route) *Route {
switch ar.Paths[i].Type {
case api.Path_BGP:
p.Type = BGPPathType
p.BGPPath = BGPPathFromProtoBGPPath(ar.Paths[i].BgpPath)
p.BGPPath = BGPPathFromProtoBGPPath(ar.Paths[i].BgpPath, dedup)
}

r.paths = append(r.paths, p)
Expand Down

0 comments on commit 27fb65a

Please sign in to comment.