summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 13:55:24 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 13:55:24 +0900
commitc0e81a21fb4c1c9f2f0c6597f0f8386288ee5b03 (patch)
tree5d66134179f5cd6aa469d9483f7164562096d2a4 /server
parente0e421bbca8f620fc40c98de7d8ae386a8f8a6ad (diff)
move gRPC-related code for REQ_NEIGHBOR to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go10
-rw-r--r--server/server.go24
2 files changed, 16 insertions, 18 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index c6486eac..cd5d6a4e 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -138,14 +138,6 @@ func (s *Server) Serve() error {
}
func (s *Server) GetNeighbor(ctx context.Context, arg *api.GetNeighborRequest) (*api.GetNeighborResponse, error) {
- var rf bgp.RouteFamily
- req := NewGrpcRequest(REQ_NEIGHBOR, "", rf, nil)
- s.bgpServerCh <- req
- res := <-req.ResponseCh
- if res.Err() != nil {
- return nil, res.Err()
- }
-
toApi := func(pconf *config.Neighbor) *api.Peer {
prefixLimits := make([]*api.PrefixLimit, 0, len(pconf.AfiSafis))
for _, family := range pconf.AfiSafis {
@@ -229,7 +221,7 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *api.GetNeighborRequest) (
}
p := []*api.Peer{}
- for _, e := range res.Data.([]*config.Neighbor) {
+ for _, e := range s.bgpServer.GetNeighbor() {
p = append(p, toApi(e))
}
return &api.GetNeighborResponse{Peers: p}, nil
diff --git a/server/server.go b/server/server.go
index 75031f30..35b2388b 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1460,15 +1460,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
Data: dsts,
}
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR:
- l := make([]*config.Neighbor, 0)
- for _, peer := range server.neighborMap {
- l = append(l, peer.ToConfig())
- }
- grpcReq.ResponseCh <- &GrpcResponse{
- Data: l,
- }
- close(grpcReq.ResponseCh)
case REQ_ADJ_RIB_IN, REQ_ADJ_RIB_OUT:
arg := grpcReq.Data.(*api.GetRibRequest)
@@ -1732,6 +1723,21 @@ ERROR:
return
}
+func (s *BgpServer) GetNeighbor() (l []*config.Neighbor) {
+ ch := make(chan struct{})
+ defer func() { <-ch }()
+
+ s.mgmtCh <- func() {
+ defer close(ch)
+
+ l = make([]*config.Neighbor, 0, len(s.neighborMap))
+ for _, peer := range s.neighborMap {
+ l = append(l, peer.ToConfig())
+ }
+ }
+ return l
+}
+
func (server *BgpServer) addNeighbor(c *config.Neighbor) error {
addr := c.Config.NeighborAddress
if _, y := server.neighborMap[addr]; y {