diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-22 02:52:33 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-22 02:52:33 -0800 |
commit | 275f20e96e674e3a0b654292f81240744c61665a (patch) | |
tree | 8f4a4e6b7b0d6d31cd9e4bea00b2435f67eb8e46 /server/peer.go | |
parent | c90dc7bcf1caadb23119e638ef7ed576e1c97187 (diff) |
table: send withdraw when peer is down
When a peer becomes down, send withdraw for the best pathes of it.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/server/peer.go b/server/peer.go index faea1a02..3c852ccf 100644 --- a/server/peer.go +++ b/server/peer.go @@ -29,6 +29,7 @@ type Peer struct { t tomb.Tomb globalConfig config.GlobalType peerConfig config.NeighborType + state int acceptedConnCh chan *net.TCPConn incoming chan *bgp.BGPMessage outgoing chan *bgp.BGPMessage @@ -45,6 +46,7 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *mes p := &Peer{ globalConfig: g, peerConfig: peer, + state: bgp.BGP_FSM_IDLE, acceptedConnCh: make(chan *net.TCPConn), incoming: make(chan *bgp.BGPMessage, 4096), outgoing: make(chan *bgp.BGPMessage, 4096), @@ -102,20 +104,26 @@ func (peer *Peer) path2update(pathList []table.Path) []*bgp.BGPMessage { } func (peer *Peer) handlePeermessage(m *message) { - switch m.event { - case PEER_MSG_PATH: - pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path)) + + sendpath := func(pList []table.Path, wList []table.Destination) { pathList := append([]table.Path(nil), pList...) for _, dest := range wList { p := dest.GetOldBestPath() pathList = append(pathList, p.Clone(true)) } - peer.adjRib.UpdateOut(pathList) - peer.sendMessages(peer.path2update(pathList)) } + + switch m.event { + case PEER_MSG_PATH: + pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path)) + sendpath(pList, wList) + case PEER_MSG_DOWN: + pList, wList, _ := peer.rib.DeletePathsforPeer(m.data.(*table.PeerInfo)) + sendpath(pList, wList) + } } // this goroutine handles routing table operations @@ -128,6 +136,8 @@ func (peer *Peer) loop() error { case nextState := <-peer.fsm.StateChanged(): // waits for all goroutines created for the current state h.Wait() + oldState := peer.fsm.state + peer.fsm.state = nextState peer.fsm.StateChange(nextState) sameState = false // TODO: check peer's rf @@ -135,6 +145,9 @@ func (peer *Peer) loop() error { pathList := peer.adjRib.GetOutPathList(table.RF_IPv4_UC) peer.sendMessages(peer.path2update(pathList)) } + if oldState == bgp.BGP_FSM_ESTABLISHED { + peer.sendToHub("", PEER_MSG_DOWN, peer.fsm.peerInfo) + } case <-peer.t.Dying(): close(peer.acceptedConnCh) h.Stop() |