From 10746e5f4b303aba553c2bb759afe3a8d4ffe3aa Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Tue, 24 May 2016 05:23:49 +0000 Subject: server: refactoring for zebra related code use watcher infra Signed-off-by: ISHIDA Wataru --- server/server.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'server/server.go') diff --git a/server/server.go b/server/server.go index 7efc3686..faf4a06c 100644 --- a/server/server.go +++ b/server/server.go @@ -32,7 +32,6 @@ import ( "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/packet/bmp" "github.com/osrg/gobgp/table" - "github.com/osrg/gobgp/zebra" "github.com/satori/go.uuid" ) @@ -145,7 +144,6 @@ type BgpServer struct { fsmincomingCh *channels.InfiniteChannel fsmStateCh chan *FsmMsg acceptCh chan *net.TCPConn - zapiMsgCh chan *zebra.Message collector *Collector GrpcReqCh chan *GrpcRequest @@ -155,7 +153,6 @@ type BgpServer struct { listeners []*TCPListener neighborMap map[string]*Peer globalRib *table.TableManager - zclient *zebra.Client roaManager *roaManager shutdown bool watchers Watchers @@ -328,11 +325,6 @@ func (server *BgpServer) Serve() { select { case rmsg := <-server.roaManager.ReceiveROA(): server.roaManager.HandleROAEvent(rmsg) - case zmsg := <-server.zapiMsgCh: - m := handleZapiMsg(zmsg, server) - if len(m) > 0 { - senderMsgs = append(senderMsgs, m...) - } case conn := <-server.acceptCh: passConn(conn) case e, ok := <-server.fsmincomingCh.Out(): @@ -502,22 +494,11 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer, families []bgp.RouteFamil } func (server *BgpServer) broadcastBests(bests []*table.Path) { + server.notify2watchers(WATCHER_EVENT_BESTPATH_CHANGE, &watcherEventBestPathMsg{pathList: bests}) for _, path := range bests { if path == nil { continue } - if !path.IsFromExternal() { - z := newBroadcastZapiBestMsg(server.zclient, path) - if z != nil { - server.broadcastMsgs = append(server.broadcastMsgs, z) - log.WithFields(log.Fields{ - "Topic": "Server", - "Client": z.client, - "Message": z.msg, - }).Debug("Default policy applied and rejected.") - } - } - rf := path.GetRouteFamily() result := &GrpcResponse{ @@ -2359,10 +2340,13 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { close(grpcReq.ResponseCh) case REQ_INITIALIZE_ZEBRA: c := grpcReq.Data.(*config.ZebraConfig) - cli, err := NewZclient(c.Url, c.RedistributeRouteTypeList) + protos := make([]string, 0, len(c.RedistributeRouteTypeList)) + for _, p := range c.RedistributeRouteTypeList { + protos = append(protos, string(p)) + } + z, err := newZebraWatcher(server.GrpcReqCh, c.Url, protos) if err == nil { - server.zclient = cli - server.zapiMsgCh = server.zclient.Receive() + server.watchers[WATCHER_ZEBRA] = z } grpcReq.ResponseCh <- &GrpcResponse{ ResponseErr: err, -- cgit v1.2.3