summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2020-10-20 21:09:34 +0900
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2020-10-21 21:09:12 +0900
commit3d3d6f34381f811c4e42c148c7666b47f45a7654 (patch)
tree6ac6cd1a32b0af142bb39ba8f83b45e5ccf9be6b /pkg
parente6eb1da279769bd3d56364ab685b4fb2e0b029a7 (diff)
api: add ListPathRequest's option to get binary of nlri and attributes
put the binary of nlri and path attribute to the response. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/server/grpc_server.go19
-rw-r--r--pkg/server/server.go4
2 files changed, 19 insertions, 4 deletions
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go
index 69af445c..a9f621fb 100644
--- a/pkg/server/grpc_server.go
+++ b/pkg/server/grpc_server.go
@@ -153,11 +153,26 @@ func toPathAPI(binNlri []byte, binPattrs [][]byte, anyNlri *any.Any, anyPattrs [
return p
}
-func toPathApi(path *table.Path, v *table.Validation) *api.Path {
+func toPathApi(path *table.Path, v *table.Validation, nlri_binary, attribute_binary bool) *api.Path {
nlri := path.GetNlri()
anyNlri := apiutil.MarshalNLRI(nlri)
anyPattrs := apiutil.MarshalPathAttributes(path.GetPathAttrs())
- return toPathAPI(nil, nil, anyNlri, anyPattrs, path, v)
+ var binNlri []byte
+ if nlri_binary {
+ binNlri, _ = nlri.Serialize()
+ }
+ var binPattrs [][]byte
+ if attribute_binary {
+ pa := path.GetPathAttrs()
+ binPattrs = make([][]byte, 0, len(pa))
+ for _, a := range pa {
+ b, e := a.Serialize()
+ if e == nil {
+ binPattrs = append(binPattrs, b)
+ }
+ }
+ }
+ return toPathAPI(binNlri, binPattrs, anyNlri, anyPattrs, path, v)
}
func getValidation(v map[*table.Path]*table.Validation, p *table.Path) *table.Validation {
diff --git a/pkg/server/server.go b/pkg/server/server.go
index ef8bd3c8..274f7177 100644
--- a/pkg/server/server.go
+++ b/pkg/server/server.go
@@ -2521,7 +2521,7 @@ func (s *BgpServer) ListPath(ctx context.Context, r *api.ListPathRequest, fn fun
}
knownPathList := dst.GetAllKnownPathList()
for i, path := range knownPathList {
- p := toPathApi(path, getValidation(v, path))
+ p := toPathApi(path, getValidation(v, path), r.EnableNlriBinary, r.EnableAttributeBinary)
if !table.SelectionOptions.DisableBestPathSelection {
if i == 0 {
switch r.TableType {
@@ -3735,7 +3735,7 @@ func (s *BgpServer) MonitorTable(ctx context.Context, r *api.MonitorTableRequest
case <-ctx.Done():
return
default:
- fn(toPathApi(path, nil))
+ fn(toPathApi(path, nil, false, false))
}
}
case <-ctx.Done():