summaryrefslogtreecommitdiffhomepage
path: root/api
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-08-20 12:02:36 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-08-25 15:53:14 +0900
commitb3c874da2581eb71d8c137d956e792565193ec0e (patch)
tree563169c8233d48a10fd5d45ac805e1320a89c532 /api
parenta17ee18e5b1fe90a7c80d6cb1f0778b97f00235a (diff)
server/api: fix GetRib API to return sorted destination
the feature has been broken. Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'api')
-rw-r--r--api/grpc_server.go72
1 files changed, 37 insertions, 35 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index b4bfd1e3..225c3971 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -180,7 +180,7 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *GetNeighborRequest) (*Get
return &GetNeighborResponse{Peers: p}, nil
}
-func toPathApi(id string, path *table.Path) *Path {
+func toPathApi(path *table.Path) *Path {
nlri := path.GetNlri()
n, _ := nlri.Serialize()
family := uint32(bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()))
@@ -198,7 +198,7 @@ func toPathApi(id string, path *table.Path) *Path {
Age: path.GetTimestamp().Unix(),
IsWithdraw: path.IsWithdraw,
Validation: int32(path.Validation().ToInt()),
- Filtered: path.Filtered(id) == table.POLICY_DIRECTION_IN,
+ Filtered: path.Filtered("") == table.POLICY_DIRECTION_IN,
Family: family,
SourceAsn: path.GetSource().AS,
SourceId: path.GetSource().ID.String(),
@@ -209,18 +209,18 @@ func toPathApi(id string, path *table.Path) *Path {
}
func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibResponse, error) {
- f := func() []*server.LookupPrefix {
- l := make([]*server.LookupPrefix, 0, len(arg.Table.Destinations))
+ f := func() []*table.LookupPrefix {
+ l := make([]*table.LookupPrefix, 0, len(arg.Table.Destinations))
for _, p := range arg.Table.Destinations {
- l = append(l, &server.LookupPrefix{
+ l = append(l, &table.LookupPrefix{
Prefix: p.Prefix,
- LookupOption: func() server.LookupOption {
+ LookupOption: func() table.LookupOption {
if p.LongerPrefixes {
- return server.LOOKUP_LONGER
+ return table.LOOKUP_LONGER
} else if p.ShorterPrefixes {
- return server.LOOKUP_SHORTER
+ return table.LOOKUP_SHORTER
}
- return server.LOOKUP_EXACT
+ return table.LOOKUP_EXACT
}(),
})
}
@@ -229,46 +229,48 @@ func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibRespons
var in bool
var err error
- var id string
- var r map[string][]*table.Path
+ var tbl *table.Table
family := bgp.RouteFamily(arg.Table.Family)
switch arg.Table.Type {
case Resource_LOCAL, Resource_GLOBAL:
- id, r, err = s.bgpServer.GetRib(arg.Table.Name, family, f())
+ tbl, err = s.bgpServer.GetRib(arg.Table.Name, family, f())
case Resource_ADJ_IN:
in = true
fallthrough
case Resource_ADJ_OUT:
- id, r, err = s.bgpServer.GetAdjRib(arg.Table.Name, family, in, f())
+ tbl, err = s.bgpServer.GetAdjRib(arg.Table.Name, family, in, f())
case Resource_VRF:
- id, r, err = s.bgpServer.GetVrfRib(arg.Table.Name, family, []*server.LookupPrefix{})
+ tbl, err = s.bgpServer.GetVrfRib(arg.Table.Name, family, []*table.LookupPrefix{})
default:
return nil, fmt.Errorf("unsupported resource type: %v", arg.Table.Type)
}
- dsts := make([]*Destination, 0, len(r))
- if err == nil {
- for k, v := range r {
- dsts = append(dsts, &Destination{
- Prefix: k,
- Paths: func(paths []*table.Path) []*Path {
- l := make([]*Path, 0, len(v))
- for i, p := range paths {
- pp := toPathApi(id, p)
- switch arg.Table.Type {
- case Resource_LOCAL, Resource_GLOBAL:
- if i == 0 {
- pp.Best = true
- }
+ if err != nil {
+ return nil, err
+ }
+
+ dsts := []*Destination{}
+ for _, dst := range tbl.GetSortedDestinations() {
+ 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)
+ switch arg.Table.Type {
+ case Resource_LOCAL, Resource_GLOBAL:
+ if i == 0 {
+ pp.Best = true
}
- l = append(l, pp)
}
- return l
- }(v),
- })
- }
+ l = append(l, pp)
+ }
+ return l
+ }(dst.GetAllKnownPathList()),
+ })
}
+
return &GetRibResponse{Table: &Table{
Type: arg.Table.Type,
Family: arg.Table.Family,
@@ -304,11 +306,11 @@ func (s *Server) MonitorRib(arg *Table, stream GobgpApi_MonitorRibServer) error
continue
}
if dst, y := dsts[path.GetNlri().String()]; y {
- dst.Paths = append(dst.Paths, toPathApi(table.GLOBAL_RIB_NAME, path))
+ dst.Paths = append(dst.Paths, toPathApi(path))
} else {
dsts[path.GetNlri().String()] = &Destination{
Prefix: path.GetNlri().String(),
- Paths: []*Path{toPathApi(table.GLOBAL_RIB_NAME, path)},
+ Paths: []*Path{toPathApi(path)},
}
}
}