diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-10-29 18:27:37 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-10-29 18:27:37 +0900 |
commit | c8694bc8a7dccd663689f8d134b89fe3a1f37d70 (patch) | |
tree | 2539bed4de902626cdacad748caddbd4294d5919 /pkg/server/peer.go | |
parent | 0b4d946298c6aca479dc79b578adb9ae0da1a850 (diff) |
server: unexport Peer adn PeerGroup
No need to export them. Also fixed golint errors.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/server/peer.go')
-rw-r--r-- | pkg/server/peer.go | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/pkg/server/peer.go b/pkg/server/peer.go index 632e14a4..28bf0fee 100644 --- a/pkg/server/peer.go +++ b/pkg/server/peer.go @@ -29,37 +29,37 @@ import ( ) const ( - FLOP_THRESHOLD = time.Second * 30 - MIN_CONNECT_RETRY = 10 + flopThreshold = time.Second * 30 + minConnectRetry = 10 ) -type PeerGroup struct { +type peerGroup struct { Conf *config.PeerGroup members map[string]config.Neighbor dynamicNeighbors map[string]*config.DynamicNeighbor } -func NewPeerGroup(c *config.PeerGroup) *PeerGroup { - return &PeerGroup{ +func newPeerGroup(c *config.PeerGroup) *peerGroup { + return &peerGroup{ Conf: c, members: make(map[string]config.Neighbor), dynamicNeighbors: make(map[string]*config.DynamicNeighbor), } } -func (pg *PeerGroup) AddMember(c config.Neighbor) { +func (pg *peerGroup) AddMember(c config.Neighbor) { pg.members[c.State.NeighborAddress] = c } -func (pg *PeerGroup) DeleteMember(c config.Neighbor) { +func (pg *peerGroup) DeleteMember(c config.Neighbor) { delete(pg.members, c.State.NeighborAddress) } -func (pg *PeerGroup) AddDynamicNeighbor(c *config.DynamicNeighbor) { +func (pg *peerGroup) AddDynamicNeighbor(c *config.DynamicNeighbor) { pg.dynamicNeighbors[c.Config.Prefix] = c } -func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGroup, loc *table.TableManager, policy *table.RoutingPolicy) *Peer { +func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGroup, loc *table.TableManager, policy *table.RoutingPolicy) *peer { conf := config.Neighbor{ Config: config.NeighborConfig{ PeerGroup: pg.Config.PeerGroupName, @@ -87,14 +87,14 @@ func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGro }).Debugf("Can't set default config: %s", err) return nil } - peer := NewPeer(g, &conf, loc, policy) + peer := newPeer(g, &conf, loc, policy) peer.fsm.lock.Lock() peer.fsm.state = bgp.BGP_FSM_ACTIVE peer.fsm.lock.Unlock() return peer } -type Peer struct { +type peer struct { tableId string fsm *FSM adjRibIn *table.AdjRib @@ -105,8 +105,8 @@ type Peer struct { llgrEndChs []chan struct{} } -func NewPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy) *Peer { - peer := &Peer{ +func newPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy) *peer { + peer := &peer{ outgoing: channels.NewInfiniteChannel(), localRib: loc, policy: policy, @@ -123,45 +123,45 @@ func NewPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, p return peer } -func (peer *Peer) AS() uint32 { +func (peer *peer) AS() uint32 { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.State.PeerAs } -func (peer *Peer) ID() string { +func (peer *peer) ID() string { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.State.NeighborAddress } -func (peer *Peer) TableID() string { +func (peer *peer) TableID() string { return peer.tableId } -func (peer *Peer) isIBGPPeer() bool { +func (peer *peer) isIBGPPeer() bool { return peer.fsm.pConf.State.PeerAs == peer.fsm.gConf.Config.As } -func (peer *Peer) isRouteServerClient() bool { +func (peer *peer) isRouteServerClient() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.RouteServer.Config.RouteServerClient } -func (peer *Peer) isRouteReflectorClient() bool { +func (peer *peer) isRouteReflectorClient() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.RouteReflector.Config.RouteReflectorClient } -func (peer *Peer) isGracefulRestartEnabled() bool { +func (peer *peer) isGracefulRestartEnabled() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.GracefulRestart.State.Enabled } -func (peer *Peer) getAddPathMode(family bgp.RouteFamily) bgp.BGPAddPathMode { +func (peer *peer) getAddPathMode(family bgp.RouteFamily) bgp.BGPAddPathMode { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() if mode, y := peer.fsm.rfMap[family]; y { @@ -170,21 +170,21 @@ func (peer *Peer) getAddPathMode(family bgp.RouteFamily) bgp.BGPAddPathMode { return bgp.BGP_ADD_PATH_NONE } -func (peer *Peer) isAddPathReceiveEnabled(family bgp.RouteFamily) bool { +func (peer *peer) isAddPathReceiveEnabled(family bgp.RouteFamily) bool { return (peer.getAddPathMode(family) & bgp.BGP_ADD_PATH_RECEIVE) > 0 } -func (peer *Peer) isAddPathSendEnabled(family bgp.RouteFamily) bool { +func (peer *peer) isAddPathSendEnabled(family bgp.RouteFamily) bool { return (peer.getAddPathMode(family) & bgp.BGP_ADD_PATH_SEND) > 0 } -func (peer *Peer) isDynamicNeighbor() bool { +func (peer *peer) isDynamicNeighbor() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() return peer.fsm.pConf.Config.NeighborAddress == "" && peer.fsm.pConf.Config.NeighborInterface == "" } -func (peer *Peer) recvedAllEOR() bool { +func (peer *peer) recvedAllEOR() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() for _, a := range peer.fsm.pConf.AfiSafis { @@ -195,14 +195,14 @@ func (peer *Peer) recvedAllEOR() bool { return true } -func (peer *Peer) configuredRFlist() []bgp.RouteFamily { +func (peer *peer) configuredRFlist() []bgp.RouteFamily { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() rfs, _ := config.AfiSafis(peer.fsm.pConf.AfiSafis).ToRfList() return rfs } -func (peer *Peer) negotiatedRFList() []bgp.RouteFamily { +func (peer *peer) negotiatedRFList() []bgp.RouteFamily { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() l := make([]bgp.RouteFamily, 0, len(peer.fsm.rfMap)) @@ -212,7 +212,7 @@ func (peer *Peer) negotiatedRFList() []bgp.RouteFamily { return l } -func (peer *Peer) toGlobalFamilies(families []bgp.RouteFamily) []bgp.RouteFamily { +func (peer *peer) toGlobalFamilies(families []bgp.RouteFamily) []bgp.RouteFamily { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() if peer.fsm.pConf.Config.Vrf != "" { @@ -256,7 +256,7 @@ func classifyFamilies(all, part []bgp.RouteFamily) ([]bgp.RouteFamily, []bgp.Rou return a, b } -func (peer *Peer) forwardingPreservedFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { +func (peer *peer) forwardingPreservedFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { peer.fsm.lock.RLock() list := []bgp.RouteFamily{} for _, a := range peer.fsm.pConf.AfiSafis { @@ -268,7 +268,7 @@ func (peer *Peer) forwardingPreservedFamilies() ([]bgp.RouteFamily, []bgp.RouteF return classifyFamilies(peer.configuredRFlist(), list) } -func (peer *Peer) llgrFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { +func (peer *peer) llgrFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { peer.fsm.lock.RLock() list := []bgp.RouteFamily{} for _, a := range peer.fsm.pConf.AfiSafis { @@ -280,7 +280,7 @@ func (peer *Peer) llgrFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { return classifyFamilies(peer.configuredRFlist(), list) } -func (peer *Peer) isLLGREnabledFamily(family bgp.RouteFamily) bool { +func (peer *peer) isLLGREnabledFamily(family bgp.RouteFamily) bool { peer.fsm.lock.RLock() llgrEnabled := peer.fsm.pConf.GracefulRestart.Config.LongLivedEnabled peer.fsm.lock.RUnlock() @@ -296,7 +296,7 @@ func (peer *Peer) isLLGREnabledFamily(family bgp.RouteFamily) bool { return false } -func (peer *Peer) llgrRestartTime(family bgp.RouteFamily) uint32 { +func (peer *peer) llgrRestartTime(family bgp.RouteFamily) uint32 { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() for _, a := range peer.fsm.pConf.AfiSafis { @@ -307,7 +307,7 @@ func (peer *Peer) llgrRestartTime(family bgp.RouteFamily) uint32 { return 0 } -func (peer *Peer) llgrRestartTimerExpired(family bgp.RouteFamily) bool { +func (peer *peer) llgrRestartTimerExpired(family bgp.RouteFamily) bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() all := true @@ -323,7 +323,7 @@ func (peer *Peer) llgrRestartTimerExpired(family bgp.RouteFamily) bool { return all } -func (peer *Peer) markLLGRStale(fs []bgp.RouteFamily) []*table.Path { +func (peer *peer) markLLGRStale(fs []bgp.RouteFamily) []*table.Path { paths := peer.adjRibIn.PathList(fs, true) for i, p := range paths { doStale := true @@ -343,7 +343,7 @@ func (peer *Peer) markLLGRStale(fs []bgp.RouteFamily) []*table.Path { return paths } -func (peer *Peer) stopPeerRestarting() { +func (peer *peer) stopPeerRestarting() { peer.fsm.lock.Lock() defer peer.fsm.lock.Unlock() peer.fsm.pConf.GracefulRestart.State.PeerRestarting = false @@ -354,7 +354,7 @@ func (peer *Peer) stopPeerRestarting() { } -func (peer *Peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path { +func (peer *peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path { if peer.ID() != path.GetSource().Address.String() { return path } @@ -389,7 +389,7 @@ func (peer *Peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path { return nil } -func (peer *Peer) doPrefixLimit(k bgp.RouteFamily, c *config.PrefixLimitConfig) *bgp.BGPMessage { +func (peer *peer) doPrefixLimit(k bgp.RouteFamily, c *config.PrefixLimitConfig) *bgp.BGPMessage { if maxPrefixes := int(c.MaxPrefixes); maxPrefixes > 0 { count := peer.adjRibIn.Count([]bgp.RouteFamily{k}) pct := int(c.ShutdownThresholdPct) @@ -414,7 +414,7 @@ func (peer *Peer) doPrefixLimit(k bgp.RouteFamily, c *config.PrefixLimitConfig) } -func (peer *Peer) updatePrefixLimitConfig(c []config.AfiSafi) error { +func (peer *peer) updatePrefixLimitConfig(c []config.AfiSafi) error { peer.fsm.lock.RLock() x := peer.fsm.pConf.AfiSafis peer.fsm.lock.RUnlock() @@ -451,7 +451,7 @@ func (peer *Peer) updatePrefixLimitConfig(c []config.AfiSafi) error { return nil } -func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bgp.BGPMessage) { +func (peer *peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bgp.BGPMessage) { m := e.MsgData.(*bgp.BGPMessage) update := m.Body.(*bgp.BGPUpdate) log.WithFields(log.Fields{ @@ -526,18 +526,18 @@ func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bg return nil, nil, nil } -func (peer *Peer) startFSMHandler(incoming *channels.InfiniteChannel, stateCh chan *FsmMsg) { +func (peer *peer) startFSMHandler(incoming *channels.InfiniteChannel, stateCh chan *FsmMsg) { handler := NewFSMHandler(peer.fsm, incoming, stateCh, peer.outgoing) peer.fsm.lock.Lock() peer.fsm.h = handler peer.fsm.lock.Unlock() } -func (peer *Peer) StaleAll(rfList []bgp.RouteFamily) []*table.Path { +func (peer *peer) StaleAll(rfList []bgp.RouteFamily) []*table.Path { return peer.adjRibIn.StaleAll(rfList) } -func (peer *Peer) PassConn(conn *net.TCPConn) { +func (peer *peer) PassConn(conn *net.TCPConn) { select { case peer.fsm.connCh <- conn: default: @@ -549,11 +549,11 @@ func (peer *Peer) PassConn(conn *net.TCPConn) { } } -func (peer *Peer) DropAll(rfList []bgp.RouteFamily) { +func (peer *peer) DropAll(rfList []bgp.RouteFamily) { peer.adjRibIn.Drop(rfList) } -func (peer *Peer) stopFSM() error { +func (peer *peer) stopFSM() error { failed := false peer.fsm.lock.RLock() addr := peer.fsm.pConf.State.NeighborAddress |