summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/sources/lib.md2
-rw-r--r--gobgpd/main.go2
-rw-r--r--openswitch/openswitch.go9
-rw-r--r--server/grpc_server.go113
-rw-r--r--server/server.go135
5 files changed, 124 insertions, 137 deletions
diff --git a/docs/sources/lib.md b/docs/sources/lib.md
index a8c14d65..4fac54de 100644
--- a/docs/sources/lib.md
+++ b/docs/sources/lib.md
@@ -43,7 +43,7 @@ func main() {
}
// neighbor configuration
- req = gobgp.NewGrpcRequest(gobgp.REQ_GRPC_ADD_NEIGHBOR, "", bgp.RouteFamily(0), &api.AddNeighborRequest{
+ req = gobgp.NewGrpcRequest(gobgp.REQ_ADD_NEIGHBOR, "", bgp.RouteFamily(0), &api.AddNeighborRequest{
Peer: &api.Peer{
Conf: &api.PeerConf{
NeighborAddress: "192.168.0.3",
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 32c63bcc..7ad48f83 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -186,7 +186,7 @@ func main() {
}()
if opts.Ops {
- m, err := ops.NewOpsManager(bgpServer.GrpcReqCh)
+ m, err := ops.NewOpsManager(grpcServer, bgpServer.GrpcReqCh)
if err != nil {
log.Errorf("Failed to start ops config manager: %s", err)
os.Exit(1)
diff --git a/openswitch/openswitch.go b/openswitch/openswitch.go
index c6ff5e55..f1339123 100644
--- a/openswitch/openswitch.go
+++ b/openswitch/openswitch.go
@@ -24,6 +24,7 @@ import (
"github.com/osrg/gobgp/server"
"github.com/satori/go.uuid"
ovsdb "github.com/socketplane/libovsdb"
+ "golang.org/x/net/context"
"net"
"reflect"
"strconv"
@@ -351,14 +352,14 @@ func (m *OpsManager) handleNeighborUpdate(update ovsdb.TableUpdate) []*server.Gr
}).Debug("remote-as is not configured yet")
continue
}
- reqs = append(reqs, server.NewGrpcRequest(server.REQ_GRPC_ADD_NEIGHBOR, "", bgp.RouteFamily(0), &api.AddNeighborRequest{
+ m.grpcServer.AddNeighbor(context.Background(), &api.AddNeighborRequest{
Peer: &api.Peer{
Conf: &api.PeerConf{
NeighborAddress: addrs[idx].String(),
PeerAs: uint32(asn),
},
},
- }))
+ })
}
}
}
@@ -717,6 +718,7 @@ type OpsChs struct {
}
type OpsManager struct {
+ grpcServer *server.Server
ops *ovsdb.OvsdbClient
grpcCh chan *server.GrpcRequest
opsCh chan *OpsOperation
@@ -726,7 +728,7 @@ type OpsManager struct {
cache map[string]map[string]ovsdb.Row
}
-func NewOpsManager(grpcCh chan *server.GrpcRequest) (*OpsManager, error) {
+func NewOpsManager(grpcServer *server.Server, grpcCh chan *server.GrpcRequest) (*OpsManager, error) {
ops, err := ovsdb.Connect("", 0)
if err != nil {
return nil, err
@@ -737,6 +739,7 @@ func NewOpsManager(grpcCh chan *server.GrpcRequest) (*OpsManager, error) {
ops.Register(n)
return &OpsManager{
+ grpcServer: grpcServer,
ops: ops,
grpcCh: grpcCh,
opsCh: make(chan *OpsOperation, 1024),
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{