diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 4 | ||||
-rw-r--r-- | server/peer.go | 16 | ||||
-rw-r--r-- | server/server.go | 24 |
3 files changed, 18 insertions, 26 deletions
diff --git a/server/fsm.go b/server/fsm.go index d20de598..2de4787e 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -20,6 +20,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet" + "github.com/osrg/gobgp/table" "gopkg.in/tomb.v2" "io" "net" @@ -80,6 +81,7 @@ type FSM struct { h *FSMHandler rfMap map[bgp.RouteFamily]bool confedCheck bool + peerInfo *table.PeerInfo } func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) { @@ -147,6 +149,7 @@ func NewFSM(gConf *config.Global, pConf *config.Neighbor) *FSM { getActiveCh: make(chan struct{}), rfMap: make(map[bgp.RouteFamily]bool), confedCheck: !config.IsConfederationMember(gConf, pConf) && config.IsEBGPPeer(gConf, pConf), + peerInfo: table.NewPeerInfo(gConf, pConf), } fsm.t.Go(fsm.connectLoop) return fsm @@ -567,6 +570,7 @@ func (h *FSMHandler) opensent() bgp.FSMState { fsm.sendNotificatonFromErrorMsg(h.conn, err.(*bgp.MessageError)) return bgp.BGP_FSM_IDLE } + fsm.peerInfo.ID = body.ID _, fsm.rfMap = open2Cap(body, fsm.pConf) e := &fsmMsg{ diff --git a/server/peer.go b/server/peer.go index 6f9627a7..82c61ae9 100644 --- a/server/peer.go +++ b/server/peer.go @@ -38,7 +38,6 @@ type Peer struct { rfMap map[bgp.RouteFamily]bool capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface adjRib *table.AdjRib - peerInfo *table.PeerInfo outgoing chan *bgp.BGPMessage inPolicies []*table.Policy defaultInPolicy table.RouteType @@ -57,18 +56,8 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager) *Pe outgoing: make(chan *bgp.BGPMessage, 128), localRib: loc, } - conf.NeighborState.SessionState = uint32(bgp.BGP_FSM_IDLE) conf.Timers.TimersState.Downtime = time.Now().Unix() - id := net.ParseIP(string(conf.RouteReflector.RouteReflectorConfig.RouteReflectorClusterId)).To4() - peer.peerInfo = &table.PeerInfo{ - AS: conf.NeighborConfig.PeerAs, - LocalAS: g.GlobalConfig.As, - LocalID: g.GlobalConfig.RouterId, - Address: conf.NeighborConfig.NeighborAddress, - RouteReflectorClient: peer.isRouteReflectorClient(), - RouteReflectorClusterID: id, - } peer.adjRib = table.NewAdjRib(peer.configuredRFlist()) peer.fsm = NewFSM(&g, &conf) return peer @@ -158,7 +147,6 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b case bgp.BGP_MSG_OPEN: peer.recvOpen = m body := m.Body.(*bgp.BGPOpen) - peer.peerInfo.ID = m.Body.(*bgp.BGPOpen).ID peer.capMap, peer.rfMap = open2Cap(body, &peer.conf) // calculate HoldTime @@ -207,7 +195,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b peer.conf.Timers.TimersState.UpdateRecvTime = time.Now().Unix() body := m.Body.(*bgp.BGPUpdate) table.UpdatePathAttrs4ByteAs(body) - pathList = table.ProcessMessage(m, peer.peerInfo) + pathList = table.ProcessMessage(m, peer.fsm.peerInfo) if len(pathList) > 0 { peer.staleAccepted = true peer.ApplyPolicy(table.POLICY_DIRECTION_IN, pathList) @@ -268,7 +256,7 @@ func (peer *Peer) ToApiStruct() *api.Peer { conf := &api.PeerConf{ NeighborAddress: c.NeighborConfig.NeighborAddress.String(), - Id: peer.peerInfo.ID.To4().String(), + Id: peer.fsm.peerInfo.ID.To4().String(), PeerAs: c.NeighborConfig.PeerAs, LocalAs: c.NeighborConfig.LocalAs, PeerType: uint32(c.NeighborConfig.PeerType), diff --git a/server/server.go b/server/server.go index 386e82f3..80c6059a 100644 --- a/server/server.go +++ b/server/server.go @@ -329,7 +329,7 @@ func (server *BgpServer) Serve() { for _, p := range targetPeer.adjRib.GetInPathList(targetPeer.configuredRFlist()) { // avoid to merge for timestamp u := table.CreateUpdateMsgFromPaths([]*table.Path{p}) - bmpMsgList = append(bmpMsgList, bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, false, 0, targetPeer.peerInfo, p.GetTimestamp().Unix(), u[0])) + bmpMsgList = append(bmpMsgList, bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, false, 0, targetPeer.fsm.peerInfo, p.GetTimestamp().Unix(), u[0])) } } @@ -487,7 +487,7 @@ func filterpath(peer *Peer, pathList []*table.Path) []*table.Path { // If the local CLUSTER_ID is found in the CLUSTER_LIST, // the advertisement received SHOULD be ignored. for _, clusterId := range path.GetClusterList() { - if clusterId.Equal(peer.peerInfo.RouteReflectorClusterID) { + if clusterId.Equal(peer.fsm.peerInfo.RouteReflectorClusterID) { log.WithFields(log.Fields{ "Topic": "Peer", "Key": remoteAddr, @@ -550,7 +550,7 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { if !targetPeer.isRouteServerClient() || rib.OwnerName() == peer.conf.NeighborConfig.NeighborAddress.String() { continue } - pathList, _ := rib.DeletePathsforPeer(peer.peerInfo, rf) + pathList, _ := rib.DeletePathsforPeer(peer.fsm.peerInfo, rf) if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(pathList) == 0 { continue } @@ -560,7 +560,7 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { } } else { rib := server.globalRib - pathList, _ := rib.DeletePathsforPeer(peer.peerInfo, rf) + pathList, _ := rib.DeletePathsforPeer(peer.fsm.peerInfo, rf) if len(pathList) == 0 { continue } @@ -718,7 +718,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * if ch := server.bmpClient.send(); ch != nil { m := &broadcastBMPMsg{ ch: ch, - msgList: []*bgp.BMPMessage{bmpPeerDown(bgp.BMP_PEER_DOWN_REASON_UNKNOWN, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.peerInfo, peer.conf.Timers.TimersState.Downtime)}, + msgList: []*bgp.BMPMessage{bmpPeerDown(bgp.BMP_PEER_DOWN_REASON_UNKNOWN, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.fsm.peerInfo, peer.conf.Timers.TimersState.Downtime)}, } server.broadcastMsgs = append(server.broadcastMsgs, m) } @@ -742,7 +742,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * _, rport := peer.fsm.RemoteHostPort() m := &broadcastBMPMsg{ ch: ch, - msgList: []*bgp.BMPMessage{bmpPeerUp(laddr, lport, rport, buildopen(peer.fsm.gConf, peer.fsm.pConf), peer.recvOpen, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.peerInfo, peer.conf.Timers.TimersState.Uptime)}, + msgList: []*bgp.BMPMessage{bmpPeerUp(laddr, lport, rport, buildopen(peer.fsm.gConf, peer.fsm.pConf), peer.recvOpen, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.fsm.peerInfo, peer.conf.Timers.TimersState.Uptime)}, } server.broadcastMsgs = append(server.broadcastMsgs, m) } @@ -801,9 +801,9 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * l, _ := peer.fsm.LocalHostPort() bm := &broadcastBGPMsg{ message: m, - peerAS: peer.peerInfo.AS, - localAS: peer.peerInfo.LocalAS, - peerAddress: peer.peerInfo.Address, + peerAS: peer.fsm.peerInfo.AS, + localAS: peer.fsm.peerInfo.LocalAS, + peerAddress: peer.fsm.peerInfo.Address, localAddress: net.ParseIP(l), fourBytesAs: y, ch: server.dumper.sendCh(), @@ -813,7 +813,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * if ch := server.bmpClient.send(); ch != nil { bm := &broadcastBMPMsg{ ch: ch, - msgList: []*bgp.BMPMessage{bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.peerInfo, time.Now().Unix(), m)}, + msgList: []*bgp.BMPMessage{bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.fsm.peerInfo, time.Now().Unix(), m)}, } server.broadcastMsgs = append(server.broadcastMsgs, bm) } @@ -2275,7 +2275,7 @@ func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32, view string) (*bgp.MRTMessage, error) { peers := make([]*bgp.Peer, 0, len(server.neighborMap)) for _, peer := range server.neighborMap { - id := peer.peerInfo.ID.To4().String() + id := peer.fsm.peerInfo.ID.To4().String() ipaddr := peer.conf.NeighborConfig.NeighborAddress.String() asn := peer.conf.NeighborConfig.PeerAs peers = append(peers, bgp.NewPeer(id, ipaddr, asn, true)) @@ -2289,7 +2289,7 @@ func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*bgp.MRTMes getPeerIndex := func(info *table.PeerInfo) uint16 { var idx uint16 for _, peer := range server.neighborMap { - if peer.peerInfo.Equal(info) { + if peer.fsm.peerInfo.Equal(info) { return idx } idx++ |