diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-20 04:24:47 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-20 04:24:47 +0900 |
commit | d59f1b147eba8199458df22bba1d2462b65a2308 (patch) | |
tree | 59f5beae035f3424dddf1e993a0458cdcdf47b5f /server | |
parent | 1f9a5cb7e5e8aa90b94847cf787433053ba8324c (diff) |
remove REQ_GRPC_ADD_NEIGHBOR
replace REQ_GRPC_ADD_NEIGHBOR with REQ_ADD_NEIGHBOR
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/grpc_server.go | 113 | ||||
-rw-r--r-- | server/server.go | 135 |
2 files changed, 116 insertions, 132 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 17605f82..04b74858 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -48,7 +48,6 @@ const ( REQ_ADD_NEIGHBOR REQ_DEL_NEIGHBOR // FIXME: we should merge - REQ_GRPC_ADD_NEIGHBOR REQ_GRPC_DELETE_NEIGHBOR REQ_UPDATE_NEIGHBOR REQ_GLOBAL_RIB @@ -538,7 +537,117 @@ func (s *Server) DeleteVrf(ctx context.Context, arg *api.DeleteVrfRequest) (*api } func (s *Server) AddNeighbor(ctx context.Context, arg *api.AddNeighborRequest) (*api.AddNeighborResponse, error) { - d, err := s.get(REQ_GRPC_ADD_NEIGHBOR, arg) + c, err := func(a *api.Peer) (*config.Neighbor, error) { + pconf := &config.Neighbor{} + if a.Conf != nil { + pconf.Config.NeighborAddress = a.Conf.NeighborAddress + pconf.Config.PeerAs = a.Conf.PeerAs + pconf.Config.LocalAs = a.Conf.LocalAs + + if pconf.Config.PeerAs != pconf.Config.LocalAs { + pconf.Config.PeerType = config.PEER_TYPE_EXTERNAL + } else { + pconf.Config.PeerType = config.PEER_TYPE_INTERNAL + } + pconf.Config.AuthPassword = a.Conf.AuthPassword + pconf.Config.RemovePrivateAs = config.RemovePrivateAsOption(a.Conf.RemovePrivateAs) + pconf.Config.RouteFlapDamping = a.Conf.RouteFlapDamping + pconf.Config.SendCommunity = config.CommunityType(a.Conf.SendCommunity) + pconf.Config.Description = a.Conf.Description + pconf.Config.PeerGroup = a.Conf.PeerGroup + pconf.Config.NeighborAddress = a.Conf.NeighborAddress + } + if a.Timers != nil { + if a.Timers.Config != nil { + pconf.Timers.Config.ConnectRetry = float64(a.Timers.Config.ConnectRetry) + pconf.Timers.Config.HoldTime = float64(a.Timers.Config.HoldTime) + pconf.Timers.Config.KeepaliveInterval = float64(a.Timers.Config.KeepaliveInterval) + pconf.Timers.Config.MinimumAdvertisementInterval = float64(a.Timers.Config.MinimumAdvertisementInterval) + } + } else { + pconf.Timers.Config.ConnectRetry = float64(config.DEFAULT_CONNECT_RETRY) + pconf.Timers.Config.HoldTime = float64(config.DEFAULT_HOLDTIME) + pconf.Timers.Config.KeepaliveInterval = float64(config.DEFAULT_HOLDTIME / 3) + } + if a.RouteReflector != nil { + pconf.RouteReflector.Config.RouteReflectorClusterId = config.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) + pconf.RouteReflector.Config.RouteReflectorClient = a.RouteReflector.RouteReflectorClient + } + if a.RouteServer != nil { + pconf.RouteServer.Config.RouteServerClient = a.RouteServer.RouteServerClient + } + if a.ApplyPolicy != nil { + if a.ApplyPolicy.ImportPolicy != nil { + pconf.ApplyPolicy.Config.DefaultImportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ImportPolicy.Default) + for _, p := range a.ApplyPolicy.ImportPolicy.Policies { + pconf.ApplyPolicy.Config.ImportPolicyList = append(pconf.ApplyPolicy.Config.ImportPolicyList, p.Name) + } + } + if a.ApplyPolicy.ExportPolicy != nil { + pconf.ApplyPolicy.Config.DefaultExportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ExportPolicy.Default) + for _, p := range a.ApplyPolicy.ExportPolicy.Policies { + pconf.ApplyPolicy.Config.ExportPolicyList = append(pconf.ApplyPolicy.Config.ExportPolicyList, p.Name) + } + } + if a.ApplyPolicy.InPolicy != nil { + pconf.ApplyPolicy.Config.DefaultInPolicy = config.DefaultPolicyType(a.ApplyPolicy.InPolicy.Default) + for _, p := range a.ApplyPolicy.InPolicy.Policies { + pconf.ApplyPolicy.Config.InPolicyList = append(pconf.ApplyPolicy.Config.InPolicyList, p.Name) + } + } + } + if a.Families != nil { + for _, family := range a.Families { + name, ok := bgp.AddressFamilyNameMap[bgp.RouteFamily(family)] + if !ok { + return pconf, fmt.Errorf("invalid address family: %d", family) + } + cAfiSafi := config.AfiSafi{ + Config: config.AfiSafiConfig{ + AfiSafiName: config.AfiSafiType(name), + }, + } + pconf.AfiSafis = append(pconf.AfiSafis, cAfiSafi) + } + } else { + if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { + pconf.AfiSafis = []config.AfiSafi{ + config.AfiSafi{ + Config: config.AfiSafiConfig{ + AfiSafiName: "ipv4-unicast", + }, + }, + } + } else { + pconf.AfiSafis = []config.AfiSafi{ + config.AfiSafi{ + Config: config.AfiSafiConfig{ + AfiSafiName: "ipv6-unicast", + }, + }, + } + } + } + if a.Transport != nil { + pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress + pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode + } else { + if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { + pconf.Transport.Config.LocalAddress = "0.0.0.0" + } else { + pconf.Transport.Config.LocalAddress = "::" + } + } + if a.EbgpMultihop != nil { + pconf.EbgpMultihop.Config.Enabled = a.EbgpMultihop.Enabled + pconf.EbgpMultihop.Config.MultihopTtl = uint8(a.EbgpMultihop.MultihopTtl) + } + return pconf, nil + }(arg.Peer) + if err != nil { + return nil, err + } + d, err := s.get(REQ_ADD_NEIGHBOR, c) if err != nil { return nil, err } diff --git a/server/server.go b/server/server.go index d5a51c44..602867fb 100644 --- a/server/server.go +++ b/server/server.go @@ -1937,13 +1937,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { } grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) - case REQ_GRPC_ADD_NEIGHBOR: - err := server.handleAddNeighborRequest(grpcReq) - grpcReq.ResponseCh <- &GrpcResponse{ - Data: &api.AddNeighborResponse{}, - ResponseErr: err, - } - close(grpcReq.ResponseCh) case REQ_GRPC_DELETE_NEIGHBOR: err := server.handleDeleteNeighborRequest(grpcReq) grpcReq.ResponseCh <- &GrpcResponse{ @@ -1954,6 +1947,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { case REQ_ADD_NEIGHBOR: err := server.handleAddNeighbor(grpcReq.Data.(*config.Neighbor)) grpcReq.ResponseCh <- &GrpcResponse{ + Data: &api.AddNeighborResponse{}, ResponseErr: err, } close(grpcReq.ResponseCh) @@ -2202,6 +2196,10 @@ func (server *BgpServer) handleAddNeighbor(c *config.Neighbor) error { } log.Info("Add a peer configuration for ", addr) + if c.Config.LocalAs == 0 { + c.Config.LocalAs = server.bgpConfig.Global.Config.As + } + peer := NewPeer(&server.bgpConfig.Global, c, server.globalRib, server.policy) policyMutex.Lock() server.setPolicyByConfig(peer.ID(), c.ApplyPolicy) @@ -2325,129 +2323,6 @@ func (server *BgpServer) handleUpdateNeighbor(c *config.Neighbor) (bool, error) return policyUpdated, err } -func (server *BgpServer) handleAddNeighborRequest(grpcReq *GrpcRequest) error { - arg, ok := grpcReq.Data.(*api.AddNeighborRequest) - if !ok { - return fmt.Errorf("AddNeighborRequest type assertion failed") - } else { - apitoConfig := func(a *api.Peer) (*config.Neighbor, error) { - pconf := &config.Neighbor{} - if a.Conf != nil { - pconf.Config.NeighborAddress = a.Conf.NeighborAddress - pconf.Config.PeerAs = a.Conf.PeerAs - if a.Conf.LocalAs == 0 { - pconf.Config.LocalAs = server.bgpConfig.Global.Config.As - } else { - pconf.Config.LocalAs = a.Conf.LocalAs - } - if pconf.Config.PeerAs != pconf.Config.LocalAs { - pconf.Config.PeerType = config.PEER_TYPE_EXTERNAL - } else { - pconf.Config.PeerType = config.PEER_TYPE_INTERNAL - } - pconf.Config.AuthPassword = a.Conf.AuthPassword - pconf.Config.RemovePrivateAs = config.RemovePrivateAsOption(a.Conf.RemovePrivateAs) - pconf.Config.RouteFlapDamping = a.Conf.RouteFlapDamping - pconf.Config.SendCommunity = config.CommunityType(a.Conf.SendCommunity) - pconf.Config.Description = a.Conf.Description - pconf.Config.PeerGroup = a.Conf.PeerGroup - pconf.Config.NeighborAddress = a.Conf.NeighborAddress - } - if a.Timers != nil { - if a.Timers.Config != nil { - pconf.Timers.Config.ConnectRetry = float64(a.Timers.Config.ConnectRetry) - pconf.Timers.Config.HoldTime = float64(a.Timers.Config.HoldTime) - pconf.Timers.Config.KeepaliveInterval = float64(a.Timers.Config.KeepaliveInterval) - pconf.Timers.Config.MinimumAdvertisementInterval = float64(a.Timers.Config.MinimumAdvertisementInterval) - } - } else { - pconf.Timers.Config.ConnectRetry = float64(config.DEFAULT_CONNECT_RETRY) - pconf.Timers.Config.HoldTime = float64(config.DEFAULT_HOLDTIME) - pconf.Timers.Config.KeepaliveInterval = float64(config.DEFAULT_HOLDTIME / 3) - } - if a.RouteReflector != nil { - pconf.RouteReflector.Config.RouteReflectorClusterId = config.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) - pconf.RouteReflector.Config.RouteReflectorClient = a.RouteReflector.RouteReflectorClient - } - if a.RouteServer != nil { - pconf.RouteServer.Config.RouteServerClient = a.RouteServer.RouteServerClient - } - if a.ApplyPolicy != nil { - if a.ApplyPolicy.ImportPolicy != nil { - pconf.ApplyPolicy.Config.DefaultImportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ImportPolicy.Default) - for _, p := range a.ApplyPolicy.ImportPolicy.Policies { - pconf.ApplyPolicy.Config.ImportPolicyList = append(pconf.ApplyPolicy.Config.ImportPolicyList, p.Name) - } - } - if a.ApplyPolicy.ExportPolicy != nil { - pconf.ApplyPolicy.Config.DefaultExportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ExportPolicy.Default) - for _, p := range a.ApplyPolicy.ExportPolicy.Policies { - pconf.ApplyPolicy.Config.ExportPolicyList = append(pconf.ApplyPolicy.Config.ExportPolicyList, p.Name) - } - } - if a.ApplyPolicy.InPolicy != nil { - pconf.ApplyPolicy.Config.DefaultInPolicy = config.DefaultPolicyType(a.ApplyPolicy.InPolicy.Default) - for _, p := range a.ApplyPolicy.InPolicy.Policies { - pconf.ApplyPolicy.Config.InPolicyList = append(pconf.ApplyPolicy.Config.InPolicyList, p.Name) - } - } - } - if a.Families != nil { - for _, family := range a.Families { - name, ok := bgp.AddressFamilyNameMap[bgp.RouteFamily(family)] - if !ok { - return pconf, fmt.Errorf("invalid address family: %d", family) - } - cAfiSafi := config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: config.AfiSafiType(name), - }, - } - pconf.AfiSafis = append(pconf.AfiSafis, cAfiSafi) - } - } else { - if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { - pconf.AfiSafis = []config.AfiSafi{ - config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: "ipv4-unicast", - }, - }, - } - } else { - pconf.AfiSafis = []config.AfiSafi{ - config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: "ipv6-unicast", - }, - }, - } - } - } - if a.Transport != nil { - pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress - pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode - } else { - if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { - pconf.Transport.Config.LocalAddress = "0.0.0.0" - } else { - pconf.Transport.Config.LocalAddress = "::" - } - } - if a.EbgpMultihop != nil { - pconf.EbgpMultihop.Config.Enabled = a.EbgpMultihop.Enabled - pconf.EbgpMultihop.Config.MultihopTtl = uint8(a.EbgpMultihop.MultihopTtl) - } - return pconf, nil - } - c, err := apitoConfig(arg.Peer) - if err != nil { - return err - } - return server.handleAddNeighbor(c) - } -} - func (server *BgpServer) handleDeleteNeighborRequest(grpcReq *GrpcRequest) error { arg := grpcReq.Data.(*api.DeleteNeighborRequest) return server.handleDelNeighbor(&config.Neighbor{ |