From 2a552a49b4991fcf765dbbbbd56619256dab96ac Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Fri, 29 Jul 2016 00:32:06 +0900 Subject: remove unused GrpcRequest and GrpcResponse Signed-off-by: FUJITA Tomonori --- server/grpc_server.go | 141 ++++++-------------------------------------------- server/server.go | 54 +++++++------------ 2 files changed, 35 insertions(+), 160 deletions(-) (limited to 'server') diff --git a/server/grpc_server.go b/server/grpc_server.go index c9ca9a24..03dc9c7b 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -34,75 +34,22 @@ import ( "time" ) -const ( - _ = iota - REQ_GET_SERVER - REQ_START_SERVER - REQ_STOP_SERVER - REQ_NEIGHBOR - REQ_ADJ_RIB_IN - REQ_ADJ_RIB_OUT - REQ_LOCAL_RIB - REQ_NEIGHBOR_RESET - REQ_NEIGHBOR_SOFT_RESET - REQ_NEIGHBOR_SOFT_RESET_IN - REQ_NEIGHBOR_SOFT_RESET_OUT - REQ_NEIGHBOR_SHUTDOWN - REQ_NEIGHBOR_ENABLE - REQ_NEIGHBOR_DISABLE - REQ_ADD_NEIGHBOR - REQ_DELETE_NEIGHBOR - REQ_UPDATE_NEIGHBOR - REQ_GLOBAL_RIB - REQ_MONITOR_RIB - REQ_MONITOR_NEIGHBOR_PEER_STATE - REQ_ENABLE_MRT - REQ_DISABLE_MRT - REQ_ADD_BMP - REQ_DELETE_BMP - REQ_VALIDATE_RIB - // TODO: delete - REQ_INITIALIZE_RPKI - REQ_GET_RPKI - REQ_ADD_RPKI - REQ_DELETE_RPKI - REQ_ENABLE_RPKI - REQ_DISABLE_RPKI - REQ_RESET_RPKI - REQ_SOFT_RESET_RPKI - REQ_ROA - REQ_ADD_VRF - REQ_DELETE_VRF - REQ_VRF - REQ_GET_VRF - REQ_ADD_PATH - REQ_DELETE_PATH - REQ_GET_DEFINED_SET - REQ_ADD_DEFINED_SET - REQ_DELETE_DEFINED_SET - REQ_REPLACE_DEFINED_SET - REQ_GET_STATEMENT - REQ_ADD_STATEMENT - REQ_DELETE_STATEMENT - REQ_REPLACE_STATEMENT - REQ_GET_POLICY - REQ_ADD_POLICY - REQ_DELETE_POLICY - REQ_REPLACE_POLICY - REQ_GET_POLICY_ASSIGNMENT - REQ_ADD_POLICY_ASSIGNMENT - REQ_DELETE_POLICY_ASSIGNMENT - REQ_REPLACE_POLICY_ASSIGNMENT - REQ_DEFERRAL_TIMER_EXPIRED - REQ_RELOAD_POLICY - REQ_INITIALIZE_ZEBRA -) - type Server struct { - bgpServer *BgpServer - grpcServer *grpc.Server - bgpServerCh chan *GrpcRequest - hosts string + bgpServer *BgpServer + grpcServer *grpc.Server + hosts string +} + +func NewGrpcServer(b *BgpServer, hosts string) *Server { + grpc.EnableTracing = false + grpcServer := grpc.NewServer() + server := &Server{ + bgpServer: b, + grpcServer: grpcServer, + hosts: hosts, + } + api.RegisterGobgpApiServer(grpcServer, server) + return server } func (s *Server) Serve() error { @@ -435,13 +382,6 @@ func (s *Server) MonitorPeerState(arg *api.Arguments, stream api.GobgpApi_Monito }() } -func (s *Server) neighbor(reqType int, address string, d interface{}) (interface{}, error) { - req := NewGrpcRequest(reqType, address, bgp.RouteFamily(0), d) - s.bgpServerCh <- req - res := <-req.ResponseCh - return res.Data, res.Err() -} - func (s *Server) ResetNeighbor(ctx context.Context, arg *api.ResetNeighborRequest) (*api.ResetNeighborResponse, error) { return &api.ResetNeighborResponse{}, s.bgpServer.ResetNeighbor(arg.Address) } @@ -766,13 +706,6 @@ func (s *Server) GetVrf(ctx context.Context, arg *api.GetVrfRequest) (*api.GetVr return &api.GetVrfResponse{Vrfs: l}, nil } -func (s *Server) get(typ int, d interface{}) (interface{}, error) { - req := NewGrpcRequest(typ, "", bgp.RouteFamily(0), d) - s.bgpServerCh <- req - res := <-req.ResponseCh - return res.Data, res.Err() -} - func (s *Server) AddVrf(ctx context.Context, arg *api.AddVrfRequest) (r *api.AddVrfResponse, err error) { rd := bgp.GetRouteDistinguisher(arg.Vrf.Rd) f := func(bufs [][]byte) ([]bgp.ExtendedCommunityInterface, error) { @@ -1738,47 +1671,3 @@ func (s *Server) StartServer(ctx context.Context, arg *api.StartServerRequest) ( func (s *Server) StopServer(ctx context.Context, arg *api.StopServerRequest) (*api.StopServerResponse, error) { return &api.StopServerResponse{}, s.bgpServer.Stop() } - -type GrpcRequest struct { - RequestType int - Name string - RouteFamily bgp.RouteFamily - ResponseCh chan *GrpcResponse - EndCh chan struct{} - Err error - Data interface{} -} - -func NewGrpcRequest(reqType int, name string, rf bgp.RouteFamily, d interface{}) *GrpcRequest { - r := &GrpcRequest{ - RequestType: reqType, - RouteFamily: rf, - Name: name, - ResponseCh: make(chan *GrpcResponse, 8), - EndCh: make(chan struct{}, 1), - Data: d, - } - return r -} - -type GrpcResponse struct { - ResponseErr error - Data interface{} -} - -func (r *GrpcResponse) Err() error { - return r.ResponseErr -} - -func NewGrpcServer(b *BgpServer, hosts string, bgpServerCh chan *GrpcRequest) *Server { - grpc.EnableTracing = false - grpcServer := grpc.NewServer() - server := &Server{ - bgpServer: b, - grpcServer: grpcServer, - bgpServerCh: bgpServerCh, - hosts: hosts, - } - api.RegisterGobgpApiServer(grpcServer, server) - return server -} diff --git a/server/server.go b/server/server.go index 47f9e3da..f6b08246 100644 --- a/server/server.go +++ b/server/server.go @@ -95,7 +95,6 @@ type BgpServer struct { acceptCh chan *net.TCPConn mgmtCh chan func() - GrpcReqCh chan *GrpcRequest policy *table.RoutingPolicy listeners []*TCPListener neighborMap map[string]*Peer @@ -111,7 +110,6 @@ type BgpServer struct { func NewBgpServer() *BgpServer { roaManager, _ := NewROAManager(0) s := &BgpServer{ - GrpcReqCh: make(chan *GrpcRequest, 1), neighborMap: make(map[string]*Peer), policy: table.NewRoutingPolicy(), roaManager: roaManager, @@ -135,6 +133,13 @@ func (server *BgpServer) Listeners(addr string) []*net.TCPListener { return list } +func (s *BgpServer) active() error { + if s.bgpConfig.Global.Config.As == 0 { + return fmt.Errorf("bgp server hasn't started yet") + } + return nil +} + func (server *BgpServer) Serve() { server.listeners = make([]*TCPListener, 0, 2) server.fsmincomingCh = channels.NewInfiniteChannel() @@ -200,8 +205,6 @@ func (server *BgpServer) Serve() { } select { - case grpcReq := <-server.GrpcReqCh: - server.handleGrpc(grpcReq) case conn := <-server.acceptCh: passConn(conn) default: @@ -231,8 +234,6 @@ func (server *BgpServer) Serve() { handleFsmMsg(e.(*FsmMsg)) case e := <-server.fsmStateCh: handleFsmMsg(e) - case grpcReq := <-server.GrpcReqCh: - server.handleGrpc(grpcReq) } } } @@ -942,19 +943,6 @@ func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) error { return nil } -func (server *BgpServer) checkNeighborRequest(grpcReq *GrpcRequest) (*Peer, error) { - remoteAddr := grpcReq.Name - peer, found := server.neighborMap[remoteAddr] - if !found { - result := &GrpcResponse{} - result.ResponseErr = fmt.Errorf("Neighbor that has %v doesn't exist.", remoteAddr) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - return nil, result.ResponseErr - } - return peer, nil -} - // EVPN MAC MOBILITY HANDLING // // We don't have multihoming function now, so ignore @@ -1094,6 +1082,10 @@ func (s *BgpServer) AddPath(vrfId string, pathList []*table.Path) (uuidBytes []b s.mgmtCh <- func() { defer close(ch) + if err = s.active(); err != nil { + return + } + if err = s.fixupApiPath(vrfId, pathList); err == nil { if len(pathList) == 1 { uuidBytes = uuid.NewV4().Bytes() @@ -1102,7 +1094,7 @@ func (s *BgpServer) AddPath(vrfId string, pathList []*table.Path) (uuidBytes []b s.propagateUpdate(nil, pathList) } } - return uuidBytes, nil + return uuidBytes, err } func (s *BgpServer) DeletePath(uuid []byte, f bgp.RouteFamily, vrfId string, pathList []*table.Path) (err error) { @@ -1211,6 +1203,10 @@ func (s *BgpServer) AddVrf(name string, rd bgp.RouteDistinguisherInterface, im, s.mgmtCh <- func() { defer close(ch) + if err = s.active(); err != nil { + return + } + pi := &table.PeerInfo{ AS: s.bgpConfig.Global.Config.As, LocalID: net.ParseIP(s.bgpConfig.Global.Config.RouterId).To4(), @@ -1409,20 +1405,6 @@ func (s *BgpServer) SoftReset(addr string, family bgp.RouteFamily) (err error) { return err } -func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { - if server.bgpConfig.Global.Config.As == 0 && grpcReq.RequestType != REQ_START_SERVER { - grpcReq.ResponseCh <- &GrpcResponse{ - ResponseErr: fmt.Errorf("bgpd main loop is not started yet"), - } - close(grpcReq.ResponseCh) - return - } - - switch grpcReq.RequestType { - } - return -} - type LookupOption uint8 const ( @@ -1711,6 +1693,10 @@ func (s *BgpServer) AddNeighbor(c *config.Neighbor) (err error) { policyMutex.Unlock() close(ch) }() + + if err = s.active(); err != nil { + return + } err = s.addNeighbor(c) } return err -- cgit v1.2.3