summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/peer.go23
-rw-r--r--server/server.go1
2 files changed, 19 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()
diff --git a/server/server.go b/server/server.go
index a1c0ccad..54644560 100644
--- a/server/server.go
+++ b/server/server.go
@@ -28,6 +28,7 @@ const (
_ = iota
PEER_MSG_NEW
PEER_MSG_PATH
+ PEER_MSG_DOWN
)
type message struct {