summaryrefslogtreecommitdiffhomepage
path: root/api
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-10 09:00:50 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-10 23:13:21 +0900
commit691d80e5d160b82c8b4dd1d83c959ecdffad318f (patch)
tree52d9a238bde9dd525c63bf15b8ede84ab85d56fe /api
parent5fc0ac2731ebbe0e812d493e837007068989faa7 (diff)
make Path objects in rib read-only
Now you can read Path objects in rib safely. Nobody modifies them. GetRib() API doesn't need to clone the objects. With full routes, this avoid allocating temporary huge memory. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'api')
-rw-r--r--api/grpc_server.go47
1 files changed, 33 insertions, 14 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index cec1c272..4d366482 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -369,7 +369,7 @@ func NewValidationFromTableStruct(v *table.Validation) *RPKIValidation {
}
}
-func ToPathApi(path *table.Path) *Path {
+func ToPathApi(path *table.Path, v *table.Validation) *Path {
nlri := path.GetNlri()
n, _ := nlri.Serialize()
family := uint32(bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()))
@@ -381,13 +381,18 @@ func ToPathApi(path *table.Path) *Path {
}
return ret
}(path.GetPathAttrs())
+ vv := config.RPKI_VALIDATION_RESULT_TYPE_NONE.ToInt()
+ if v != nil {
+ vv = v.Status.ToInt()
+ }
+
p := &Path{
Nlri: n,
Pattrs: pattrs,
Age: path.GetTimestamp().Unix(),
IsWithdraw: path.IsWithdraw,
- Validation: int32(path.ValidationStatus().ToInt()),
- ValidationDetail: NewValidationFromTableStruct(path.Validation()),
+ Validation: int32(vv),
+ ValidationDetail: NewValidationFromTableStruct(v),
Family: family,
Stale: path.IsStale(),
IsFromExternal: path.IsFromExternal(),
@@ -404,6 +409,14 @@ func ToPathApi(path *table.Path) *Path {
return p
}
+func getValidation(v []*table.Validation, i int) *table.Validation {
+ if v == nil {
+ return nil
+ } else {
+ return v[i]
+ }
+}
+
func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibResponse, error) {
if arg == nil || arg.Table == nil {
return nil, fmt.Errorf("invalid request")
@@ -429,16 +442,17 @@ func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibRespons
var in bool
var err error
var tbl *table.Table
+ var v []*table.Validation
family := bgp.RouteFamily(arg.Table.Family)
switch arg.Table.Type {
case Resource_LOCAL, Resource_GLOBAL:
- tbl, err = s.bgpServer.GetRib(arg.Table.Name, family, f())
+ tbl, v, err = s.bgpServer.GetRib(arg.Table.Name, family, f())
case Resource_ADJ_IN:
in = true
fallthrough
case Resource_ADJ_OUT:
- tbl, err = s.bgpServer.GetAdjRib(arg.Table.Name, family, in, f())
+ tbl, v, err = s.bgpServer.GetAdjRib(arg.Table.Name, family, in, f())
case Resource_VRF:
tbl, err = s.bgpServer.GetVrfRib(arg.Table.Name, family, []*table.LookupPrefix{})
default:
@@ -451,13 +465,15 @@ func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibRespons
tblDsts := tbl.GetDestinations()
dsts := make([]*Destination, 0, len(tblDsts))
+ idx := 0
for _, dst := range tblDsts {
dsts = append(dsts, &Destination{
Prefix: dst.GetNlri().String(),
Paths: func(paths []*table.Path) []*Path {
l := make([]*Path, 0, len(paths))
for i, p := range paths {
- pp := ToPathApi(p)
+ pp := ToPathApi(p, getValidation(v, idx))
+ idx++
switch arg.Table.Type {
case Resource_LOCAL, Resource_GLOBAL:
if i == 0 && !table.SelectionOptions.DisableBestPathSelection {
@@ -494,14 +510,15 @@ func (s *Server) GetPath(arg *GetPathRequest, stream GobgpApi_GetPathServer) err
family := bgp.RouteFamily(arg.Family)
var tbl *table.Table
var err error
+ var v []*table.Validation
switch arg.Type {
case Resource_LOCAL, Resource_GLOBAL:
- tbl, err = s.bgpServer.GetRib(arg.Name, family, f())
+ tbl, v, err = s.bgpServer.GetRib(arg.Name, family, f())
case Resource_ADJ_IN:
in = true
fallthrough
case Resource_ADJ_OUT:
- tbl, err = s.bgpServer.GetAdjRib(arg.Name, family, in, f())
+ tbl, v, err = s.bgpServer.GetAdjRib(arg.Name, family, in, f())
case Resource_VRF:
tbl, err = s.bgpServer.GetVrfRib(arg.Name, family, []*table.LookupPrefix{})
default:
@@ -511,11 +528,13 @@ func (s *Server) GetPath(arg *GetPathRequest, stream GobgpApi_GetPathServer) err
return err
}
+ idx := 0
return func() error {
for _, dst := range tbl.GetDestinations() {
- for idx, path := range dst.GetAllKnownPathList() {
- p := ToPathApi(path)
- if idx == 0 && !table.SelectionOptions.DisableBestPathSelection {
+ for i, path := range dst.GetAllKnownPathList() {
+ p := ToPathApi(path, getValidation(v, idx))
+ idx++
+ if i == 0 && !table.SelectionOptions.DisableBestPathSelection {
switch arg.Type {
case Resource_LOCAL, Resource_GLOBAL:
p.Best = true
@@ -562,11 +581,11 @@ func (s *Server) MonitorRib(arg *MonitorRibRequest, stream GobgpApi_MonitorRibSe
continue
}
if dst, y := dsts[path.GetNlri().String()]; y {
- dst.Paths = append(dst.Paths, ToPathApi(path))
+ dst.Paths = append(dst.Paths, ToPathApi(path, nil))
} else {
dsts[path.GetNlri().String()] = &Destination{
Prefix: path.GetNlri().String(),
- Paths: []*Path{ToPathApi(path)},
+ Paths: []*Path{ToPathApi(path, nil)},
}
}
}
@@ -863,7 +882,7 @@ func (s *Server) DeleteBmp(ctx context.Context, arg *DeleteBmpRequest) (*DeleteB
}
func (s *Server) ValidateRib(ctx context.Context, arg *ValidateRibRequest) (*ValidateRibResponse, error) {
- return &ValidateRibResponse{}, s.bgpServer.ValidateRib(arg.Prefix)
+ return &ValidateRibResponse{}, nil
}
func (s *Server) AddRpki(ctx context.Context, arg *AddRpkiRequest) (*AddRpkiResponse, error) {