summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 17:01:26 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 17:01:26 +0900
commit474f7c3a4d992b4597536e36a2f1597db418580f (patch)
treee9313f03b97e8a07b2b837085f63b058009fc501
parent5966466632bd73676ec80ca71c5082f88cb65bd6 (diff)
move gRPC-related code for REQ_ADD_VRF and REQ_DELETE_VRF to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/grpc_server.go30
-rw-r--r--server/server.go79
2 files changed, 57 insertions, 52 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index ca852f83..e69b2b0d 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -804,20 +804,32 @@ func (s *Server) get(typ int, d interface{}) (interface{}, error) {
return res.Data, res.Err()
}
-func (s *Server) AddVrf(ctx context.Context, arg *api.AddVrfRequest) (*api.AddVrfResponse, error) {
- d, err := s.get(REQ_ADD_VRF, arg)
+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) {
+ ret := make([]bgp.ExtendedCommunityInterface, 0, len(bufs))
+ for _, rt := range bufs {
+ r, err := bgp.ParseExtended(rt)
+ if err != nil {
+ return nil, err
+ }
+ ret = append(ret, r)
+ }
+ return ret, nil
+ }
+ im, err := f(arg.Vrf.ImportRt)
if err != nil {
- return nil, err
+ return &api.AddVrfResponse{}, err
}
- return d.(*api.AddVrfResponse), err
+ ex, err := f(arg.Vrf.ExportRt)
+ if err != nil {
+ return &api.AddVrfResponse{}, err
+ }
+ return &api.AddVrfResponse{}, s.bgpServer.AddVrf(arg.Vrf.Name, rd, im, ex)
}
func (s *Server) DeleteVrf(ctx context.Context, arg *api.DeleteVrfRequest) (*api.DeleteVrfResponse, error) {
- d, err := s.get(REQ_DELETE_VRF, arg)
- if err != nil {
- return nil, err
- }
- return d.(*api.DeleteVrfResponse), err
+ return &api.DeleteVrfResponse{}, s.bgpServer.DeleteVrf(arg.Vrf.Name)
}
func (s *Server) AddNeighbor(ctx context.Context, arg *api.AddNeighborRequest) (*api.AddNeighborResponse, error) {
diff --git a/server/server.go b/server/server.go
index 82195a93..bddde1e2 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1172,42 +1172,6 @@ func (s *BgpServer) DeletePath(uuid []byte, f bgp.RouteFamily, vrfId string, pat
return err
}
-func (server *BgpServer) handleAddVrfRequest(grpcReq *GrpcRequest) ([]*table.Path, error) {
- arg, _ := grpcReq.Data.(*api.AddVrfRequest)
- rib := server.globalRib
- rd := bgp.GetRouteDistinguisher(arg.Vrf.Rd)
- f := func(bufs [][]byte) ([]bgp.ExtendedCommunityInterface, error) {
- ret := make([]bgp.ExtendedCommunityInterface, 0, len(bufs))
- for _, rt := range bufs {
- r, err := bgp.ParseExtended(rt)
- if err != nil {
- return nil, err
- }
- ret = append(ret, r)
- }
- return ret, nil
- }
- importRt, err := f(arg.Vrf.ImportRt)
- if err != nil {
- return nil, err
- }
- exportRt, err := f(arg.Vrf.ExportRt)
- if err != nil {
- return nil, err
- }
- pi := &table.PeerInfo{
- AS: server.bgpConfig.Global.Config.As,
- LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(),
- }
- return rib.AddVrf(arg.Vrf.Name, rd, importRt, exportRt, pi)
-}
-
-func (server *BgpServer) handleDeleteVrfRequest(grpcReq *GrpcRequest) ([]*table.Path, error) {
- arg, _ := grpcReq.Data.(*api.DeleteVrfRequest)
- rib := server.globalRib
- return rib.DeleteVrf(arg.Vrf.Name)
-}
-
func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path {
var msgs []*table.Path
result := &GrpcResponse{}
@@ -1247,12 +1211,6 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path {
Data: paths,
}
goto END
- case REQ_ADD_VRF:
- msgs, result.ResponseErr = server.handleAddVrfRequest(req)
- result.Data = &api.AddVrfResponse{}
- case REQ_DELETE_VRF:
- msgs, result.ResponseErr = server.handleDeleteVrfRequest(req)
- result.Data = &api.DeleteVrfResponse{}
default:
result.ResponseErr = fmt.Errorf("unknown request type: %d", req.RequestType)
}
@@ -1318,6 +1276,41 @@ func (s *BgpServer) GetVrf() (l []*table.Vrf) {
return l
}
+func (s *BgpServer) AddVrf(name string, rd bgp.RouteDistinguisherInterface, im, ex []bgp.ExtendedCommunityInterface) (err error) {
+ ch := make(chan struct{})
+ defer func() { <-ch }()
+
+ s.mgmtCh <- func() {
+ defer close(ch)
+
+ pi := &table.PeerInfo{
+ AS: s.bgpConfig.Global.Config.As,
+ LocalID: net.ParseIP(s.bgpConfig.Global.Config.RouterId).To4(),
+ }
+ if pathList, e := s.globalRib.AddVrf(name, rd, im, ex, pi); e != nil {
+ err = e
+ } else if len(pathList) > 0 {
+ s.propagateUpdate(nil, pathList)
+ }
+ }
+ return err
+}
+
+func (s *BgpServer) DeleteVrf(name string) (err error) {
+ ch := make(chan struct{})
+ defer func() { <-ch }()
+
+ s.mgmtCh <- func() {
+ defer close(ch)
+
+ pathList, err := s.globalRib.DeleteVrf(name)
+ if err == nil && len(pathList) > 0 {
+ s.propagateUpdate(nil, pathList)
+ }
+ }
+ return err
+}
+
func (s *BgpServer) Stop() (err error) {
ch := make(chan struct{})
defer func() { <-ch }()
@@ -1702,7 +1695,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
rsp := server.roaManager.handleGRPC(grpcReq)
grpcReq.ResponseCh <- rsp
close(grpcReq.ResponseCh)
- case REQ_VRF, REQ_ADD_VRF, REQ_DELETE_VRF:
+ case REQ_VRF:
pathList := server.handleVrfRequest(grpcReq)
if len(pathList) > 0 {
server.propagateUpdate(nil, pathList)