summaryrefslogtreecommitdiffhomepage
path: root/server/grpc_server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/grpc_server.go')
-rw-r--r--server/grpc_server.go113
1 files changed, 111 insertions, 2 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
}