diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-05 17:16:31 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-08 20:56:46 +0900 |
commit | a01b549fffd428f075b8732fde244c47baf28ecd (patch) | |
tree | 9f4d6a8c56d9ab068fd1bb5b85ca9fa59e0ba1e2 /server | |
parent | bd912231e5509829bdb6b892344d4b14ca0b3b29 (diff) |
*: kill protobuf path structure
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/grpc_server.go | 66 | ||||
-rw-r--r-- | server/server.go | 38 |
2 files changed, 34 insertions, 70 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 041f0659..d767c1ee 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -160,38 +160,6 @@ func (s *Server) GetNeighbors(_ *api.Arguments, stream api.Grpc_GetNeighborsServ return nil } -func (s *Server) GetAdjRib(arg *api.Arguments, stream api.Grpc_GetAdjRibServer) error { - var reqType int - switch arg.Resource { - case api.Resource_ADJ_IN: - reqType = REQ_ADJ_RIB_IN - case api.Resource_ADJ_OUT: - reqType = REQ_ADJ_RIB_OUT - default: - return fmt.Errorf("unsupported resource type: %v", arg.Resource) - } - - rf, err := convertAf2Rf(arg.Af) - if err != nil { - return err - } - - req := NewGrpcRequest(reqType, arg.Name, rf, nil) - s.bgpServerCh <- req - - for res := range req.ResponseCh { - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - if err := stream.Send(res.Data.(*api.Path)); err != nil { - return err - } - } - - return nil -} - func (s *Server) GetRib(arg *api.Arguments, stream api.Grpc_GetRibServer) error { var reqType int switch arg.Resource { @@ -199,6 +167,12 @@ func (s *Server) GetRib(arg *api.Arguments, stream api.Grpc_GetRibServer) error reqType = REQ_LOCAL_RIB case api.Resource_GLOBAL: reqType = REQ_GLOBAL_RIB + case api.Resource_ADJ_IN: + reqType = REQ_ADJ_RIB_IN + case api.Resource_ADJ_OUT: + reqType = REQ_ADJ_RIB_OUT + case api.Resource_VRF: + reqType = REQ_VRF default: return fmt.Errorf("unsupported resource type: %v", arg.Resource) } @@ -245,7 +219,7 @@ func (s *Server) MonitorBestChanged(arg *api.Arguments, stream api.Grpc_MonitorB log.Debug(err.Error()) goto END } - if err = stream.Send(res.Data.(*api.Path)); err != nil { + if err = stream.Send(res.Data.(*api.Destination)); err != nil { goto END } } @@ -638,26 +612,6 @@ func (s *Server) GetRPKI(arg *api.Arguments, stream api.Grpc_GetRPKIServer) erro return nil } -func (s *Server) GetVrf(arg *api.Arguments, stream api.Grpc_GetVrfServer) error { - rf, err := convertAf2Rf(arg.Af) - if err != nil { - return err - } - req := NewGrpcRequest(REQ_VRF, "", rf, arg) - s.bgpServerCh <- req - - for res := range req.ResponseCh { - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return err - } - if err := stream.Send(res.Data.(*api.Path)); err != nil { - return err - } - } - return nil -} - func (s *Server) GetVrfs(arg *api.Arguments, stream api.Grpc_GetVrfsServer) error { req := NewGrpcRequest(REQ_VRFS, "", bgp.RouteFamily(0), nil) s.bgpServerCh <- req @@ -688,7 +642,7 @@ func (s *Server) ModVrf(ctx context.Context, arg *api.ModVrfArguments) (*api.Err type GrpcRequest struct { RequestType int - RemoteAddr string + Name string RouteFamily bgp.RouteFamily ResponseCh chan *GrpcResponse EndCh chan struct{} @@ -696,11 +650,11 @@ type GrpcRequest struct { Data interface{} } -func NewGrpcRequest(reqType int, remoteAddr string, rf bgp.RouteFamily, d interface{}) *GrpcRequest { +func NewGrpcRequest(reqType int, name string, rf bgp.RouteFamily, d interface{}) *GrpcRequest { r := &GrpcRequest{ RequestType: reqType, RouteFamily: rf, - RemoteAddr: remoteAddr, + Name: name, ResponseCh: make(chan *GrpcResponse, 8), EndCh: make(chan struct{}, 1), Data: d, diff --git a/server/server.go b/server/server.go index 56ef8c68..cb301fef 100644 --- a/server/server.go +++ b/server/server.go @@ -507,7 +507,10 @@ func (server *BgpServer) broadcastBests(bests []*table.Path) { } result := &GrpcResponse{ - Data: path.ToApiStruct(), + Data: &api.Destination{ + Prefix: path.GetNlri().String(), + Paths: []*api.Path{path.ToApiStruct()}, + }, } remainReqs := make([]*GrpcRequest, 0, len(server.broadcastReqs)) for _, req := range server.broadcastReqs { @@ -543,7 +546,7 @@ func (server *BgpServer) broadcastPeerState(peer *Peer) { default: } ignore := req.RequestType != REQ_MONITOR_NEIGHBOR_PEER_STATE - ignore = ignore || (req.RemoteAddr != "" && req.RemoteAddr != peer.conf.NeighborConfig.NeighborAddress.String()) + ignore = ignore || (req.Name != "" && req.Name != peer.conf.NeighborConfig.NeighborAddress.String()) if ignore { remainReqs = append(remainReqs, req) continue @@ -748,7 +751,7 @@ func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) { } func (server *BgpServer) checkNeighborRequest(grpcReq *GrpcRequest) (*Peer, error) { - remoteAddr := grpcReq.RemoteAddr + remoteAddr := grpcReq.Name peer, found := server.neighborMap[remoteAddr] if !found { result := &GrpcResponse{} @@ -1022,11 +1025,11 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path { switch req.RequestType { case REQ_VRF: - arg := req.Data.(*api.Arguments) + name := req.Name rib := server.localRibMap[GLOBAL_RIB_NAME].rib vrfs := rib.Vrfs - if _, ok := vrfs[arg.Name]; !ok { - result.ResponseErr = fmt.Errorf("vrf %s not found", arg.Name) + if _, ok := vrfs[name]; !ok { + result.ResponseErr = fmt.Errorf("vrf %s not found", name) break } var rf bgp.RouteFamily @@ -1042,12 +1045,15 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path { break } for _, path := range rib.GetPathList(rf) { - ok := policy.CanImportToVrf(vrfs[arg.Name], path) + ok := policy.CanImportToVrf(vrfs[name], path) if !ok { continue } req.ResponseCh <- &GrpcResponse{ - Data: path.ToApiStruct(), + Data: &api.Destination{ + Prefix: path.GetNlri().String(), + Paths: []*api.Path{path.ToApiStruct()}, + }, } } goto END @@ -1124,7 +1130,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { break } if peer.fsm.adminState != ADMIN_STATE_DOWN { - remoteAddr := grpcReq.RemoteAddr + remoteAddr := grpcReq.Name if t, ok := server.localRibMap[remoteAddr].rib.Tables[grpcReq.RouteFamily]; ok { for _, dst := range t.GetDestinations() { result := &GrpcResponse{} @@ -1152,8 +1158,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } for _, p := range paths { - result := &GrpcResponse{} - result.Data = p.ToApiStruct() + result := &GrpcResponse{ + Data: &api.Destination{ + Prefix: p.GetNlri().String(), + Paths: []*api.Path{p.ToApiStruct()}, + }, + } grpcReq.ResponseCh <- result } close(grpcReq.ResponseCh) @@ -2028,15 +2038,15 @@ func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { if err != nil { return } - loc, ok := server.localRibMap[grpcReq.RemoteAddr] + loc, ok := server.localRibMap[grpcReq.Name] if !ok { - result.ResponseErr = fmt.Errorf("no local rib for %s", grpcReq.RemoteAddr) + result.ResponseErr = fmt.Errorf("no local rib for %s", grpcReq.Name) grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) return } manager = loc.rib - view = grpcReq.RemoteAddr + view = grpcReq.Name } msg, err := server.mkMrtPeerIndexTableMsg(now, view) |