diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-03-11 21:15:00 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-04-19 11:12:44 +0000 |
commit | 56b69b76797fc7dbd1ff036a20dde5246fb97ed2 (patch) | |
tree | eb689c6baa0582e7c2672ec69c9df8ffc9ee910e /server/peer.go | |
parent | 8a71ae649e79b5ca62c1684a81e7c15d9a7b3c16 (diff) |
peer: remove redundant config structs
preparation for #597
stop messing up where neighbor configuration is stored
just keep it in each peers' fsm struct
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/server/peer.go b/server/peer.go index dfdfdc37..2b878b6f 100644 --- a/server/peer.go +++ b/server/peer.go @@ -34,8 +34,6 @@ const ( type Peer struct { tableId string - gConf config.Global - conf config.Neighbor fsm *FSM adjRibIn *table.AdjRib adjRibOut *table.AdjRib @@ -45,31 +43,27 @@ type Peer struct { prefixLimitWarned map[bgp.RouteFamily]bool } -func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy) *Peer { +func NewPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy) *Peer { peer := &Peer{ - gConf: g, - conf: conf, outgoing: make(chan *FsmOutgoingMsg, 128), localRib: loc, policy: policy, + fsm: NewFSM(g, conf, policy), prefixLimitWarned: make(map[bgp.RouteFamily]bool), } - tableId := table.GLOBAL_RIB_NAME if peer.isRouteServerClient() { - tableId = conf.Config.NeighborAddress + peer.tableId = conf.Config.NeighborAddress + } else { + peer.tableId = table.GLOBAL_RIB_NAME } - peer.tableId = tableId - conf.State.SessionState = config.IntToSessionStateMap[int(bgp.BGP_FSM_IDLE)] - conf.Timers.State.Downtime = time.Now().Unix() rfs, _ := config.AfiSafis(conf.AfiSafis).ToRfList() peer.adjRibIn = table.NewAdjRib(peer.ID(), rfs, g.Collector.Enabled) peer.adjRibOut = table.NewAdjRib(peer.ID(), rfs, g.Collector.Enabled) - peer.fsm = NewFSM(&g, &conf, policy) return peer } func (peer *Peer) ID() string { - return peer.conf.Config.NeighborAddress + return peer.fsm.pConf.Config.NeighborAddress } func (peer *Peer) TableID() string { @@ -77,15 +71,15 @@ func (peer *Peer) TableID() string { } func (peer *Peer) isIBGPPeer() bool { - return peer.conf.Config.PeerAs == peer.gConf.Config.As + return peer.fsm.pConf.Config.PeerAs == peer.fsm.gConf.Config.As } func (peer *Peer) isRouteServerClient() bool { - return peer.conf.RouteServer.Config.RouteServerClient + return peer.fsm.pConf.RouteServer.Config.RouteServerClient } func (peer *Peer) isRouteReflectorClient() bool { - return peer.conf.RouteReflector.Config.RouteReflectorClient + return peer.fsm.pConf.RouteReflector.Config.RouteReflectorClient } func (peer *Peer) isGracefulRestartEnabled() bool { @@ -102,7 +96,7 @@ func (peer *Peer) recvedAllEOR() bool { } func (peer *Peer) configuredRFlist() []bgp.RouteFamily { - rfs, _ := config.AfiSafis(peer.conf.AfiSafis).ToRfList() + rfs, _ := config.AfiSafis(peer.fsm.pConf.AfiSafis).ToRfList() return rfs } @@ -142,7 +136,7 @@ func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []* Neighbor: peer.fsm.peerInfo.Address, } var source []*table.Path - if peer.gConf.Collector.Enabled { + if peer.fsm.gConf.Collector.Enabled { source = peer.localRib.GetPathList(peer.TableID(), rfList) } else { source = peer.localRib.GetBestPathList(peer.TableID(), rfList) @@ -153,9 +147,9 @@ func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []* filtered = append(filtered, path) continue } - if !peer.gConf.Collector.Enabled && !peer.isRouteServerClient() { + if !peer.fsm.gConf.Collector.Enabled && !peer.isRouteServerClient() { p = p.Clone(p.IsWithdraw) - p.UpdatePathAttrs(&peer.gConf, &peer.conf) + p.UpdatePathAttrs(peer.fsm.gConf, peer.fsm.pConf) } pathList = append(pathList, p) } @@ -174,7 +168,7 @@ func (peer *Peer) processOutgoingPaths(paths, withdrawals []*table.Path) []*tabl if peer.fsm.pConf.GracefulRestart.State.LocalRestarting { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.fsm.pConf.Config.NeighborAddress, }).Debug("now syncing, suppress sending updates") return nil } @@ -194,9 +188,9 @@ func (peer *Peer) processOutgoingPaths(paths, withdrawals []*table.Path) []*tabl if path == nil { continue } - if !peer.isRouteServerClient() && !peer.gConf.Collector.Enabled { + if !peer.isRouteServerClient() && !peer.fsm.gConf.Collector.Enabled { path = path.Clone(path.IsWithdraw) - path.UpdatePathAttrs(&peer.gConf, &peer.conf) + path.UpdatePathAttrs(peer.fsm.gConf, peer.fsm.pConf) } outgoing = append(outgoing, path) } @@ -212,7 +206,7 @@ func (peer *Peer) handleRouteRefresh(e *FsmMsg) []*table.Path { if _, ok := peer.fsm.rfMap[rf]; !ok { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), "Data": rf, }).Warn("Route family isn't supported") return nil @@ -220,7 +214,7 @@ func (peer *Peer) handleRouteRefresh(e *FsmMsg) []*table.Path { if _, ok := peer.fsm.capMap[bgp.BGP_CAP_ROUTE_REFRESH]; !ok { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), }).Warn("ROUTE_REFRESH received but the capability wasn't advertised") return nil } @@ -239,10 +233,10 @@ func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bg m := e.MsgData.(*bgp.BGPMessage) log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.fsm.pConf.Config.NeighborAddress, "data": m, }).Debug("received") - peer.conf.Timers.State.UpdateRecvTime = time.Now().Unix() + peer.fsm.pConf.Timers.State.UpdateRecvTime = time.Now().Unix() if len(e.PathList) > 0 { peer.adjRibIn.Update(e.PathList) for _, family := range peer.fsm.pConf.AfiSafis { @@ -254,14 +248,14 @@ func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bg peer.prefixLimitWarned[k] = true log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), "AddressFamily": family.AfiSafiName, }).Warnf("prefix limit %d%% reached", pct) } if count > maxPrefixes { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), "AddressFamily": family.AfiSafiName, }).Warnf("prefix limit reached") return nil, nil, bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED, nil) @@ -275,7 +269,7 @@ func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bg family := path.GetRouteFamily() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), "AddressFamily": family, }).Debug("EOR received") eor = append(eor, family) @@ -305,7 +299,7 @@ func (peer *Peer) PassConn(conn *net.TCPConn) { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": peer.conf.Config.NeighborAddress, + "Key": peer.ID(), }).Warn("accepted conn is closed to avoid be blocked") } } @@ -327,7 +321,7 @@ func (peer *Peer) ToApiStruct() *api.Peer { } } - caps := capabilitiesFromConfig(&peer.conf) + caps := capabilitiesFromConfig(peer.fsm.pConf) localCap := make([][]byte, 0, len(caps)) for _, c := range caps { buf, _ := c.Serialize() |