diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-17 09:25:34 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-17 09:25:34 +0900 |
commit | 5305b68266b5fe81fdd390448e775936c57d93ef (patch) | |
tree | 731083991e7bd6c62d522e02b960497ae19ff66b | |
parent | 5dddfe65e94deb55c1dcb4dfab1ea48390771168 (diff) |
server: keep source version number
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/fsm.go | 7 | ||||
-rw-r--r-- | server/peer.go | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/server/fsm.go b/server/fsm.go index 2de18cd9..7469f47e 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -53,9 +53,14 @@ func (fsm *FSM) StateChanged() chan int { return fsm.stateCh } -func (fsm *FSM) StateSet(nextState int) { +func (fsm *FSM) StateChange(nextState int) bool { fmt.Println("state changed", nextState, fsm.state) + oldState := fsm.state fsm.state = nextState + if oldState >= bgp.BGP_FSM_OPENSENT && fsm.state == bgp.BGP_FSM_IDLE { + return true + } + return false } type FSMHandler struct { diff --git a/server/peer.go b/server/peer.go index 750d2230..086c0250 100644 --- a/server/peer.go +++ b/server/peer.go @@ -32,6 +32,7 @@ type Peer struct { incoming chan *bgp.BGPMessage outgoing chan *bgp.BGPMessage fsm *FSM + sourceVerNum int } func NewPeer(g config.GlobalType, peer config.NeighborType) *Peer { @@ -41,6 +42,7 @@ func NewPeer(g config.GlobalType, peer config.NeighborType) *Peer { acceptedConnCh: make(chan *net.TCPConn), incoming: make(chan *bgp.BGPMessage, 4096), outgoing: make(chan *bgp.BGPMessage, 4096), + sourceVerNum: 1, } p.fsm = NewFSM(&g, &peer, p.acceptedConnCh, p.incoming, p.outgoing) p.t.Go(p.loop) @@ -57,7 +59,9 @@ func (peer *Peer) loop() error { case nextState := <-peer.fsm.StateChanged(): // waits for all goroutines created for the current state h.Wait() - peer.fsm.StateSet(nextState) + if peer.fsm.StateChange(nextState) { + peer.sourceVerNum++ + } sameState = false case <-peer.t.Dying(): close(peer.acceptedConnCh) |