summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go24
-rw-r--r--server/peer.go7
-rw-r--r--server/server.go3
3 files changed, 17 insertions, 17 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 62c2495b..7cdd866b 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -29,12 +29,12 @@ type FSM struct {
globalConfig *config.GlobalType
peerConfig *config.NeighborType
keepaliveTicker *time.Ticker
- state int
+ state bgp.FSMState
incoming chan *bgp.BGPMessage
outgoing chan *bgp.BGPMessage
passiveConn *net.TCPConn
passiveConnCh chan *net.TCPConn
- stateCh chan int
+ stateCh chan bgp.FSMState
peerInfo *table.PeerInfo
sourceVerNum int
@@ -86,16 +86,16 @@ func NewFSM(gConfig *config.GlobalType, pConfig *config.NeighborType, connCh cha
outgoing: outgoing,
state: bgp.BGP_FSM_IDLE,
passiveConnCh: connCh,
- stateCh: make(chan int),
+ stateCh: make(chan bgp.FSMState),
sourceVerNum: 1,
}
}
-func (fsm *FSM) StateChanged() chan int {
+func (fsm *FSM) StateChanged() chan bgp.FSMState {
return fsm.stateCh
}
-func (fsm *FSM) StateChange(nextState int) {
+func (fsm *FSM) StateChange(nextState bgp.FSMState) {
log.Debugf("Peer (%v) state changed from %v to %v", fsm.peerConfig.NeighborAddress, fsm.state, nextState)
fsm.state = nextState
}
@@ -139,7 +139,7 @@ func (h *FSMHandler) Stop() error {
return h.t.Wait()
}
-func (h *FSMHandler) idle() int {
+func (h *FSMHandler) idle() bgp.FSMState {
fsm := h.fsm
// TODO: support idle hold timer
@@ -150,7 +150,7 @@ func (h *FSMHandler) idle() int {
return bgp.BGP_FSM_ACTIVE
}
-func (h *FSMHandler) active() int {
+func (h *FSMHandler) active() bgp.FSMState {
fsm := h.fsm
select {
case <-h.t.Dying():
@@ -224,7 +224,7 @@ func (h *FSMHandler) recvMessage() error {
return nil
}
-func (h *FSMHandler) opensent() int {
+func (h *FSMHandler) opensent() bgp.FSMState {
fsm := h.fsm
m := buildopen(fsm.globalConfig, fsm.peerConfig)
b, _ := m.Serialize()
@@ -261,7 +261,7 @@ func (h *FSMHandler) opensent() int {
return nextState
}
-func (h *FSMHandler) openconfirm() int {
+func (h *FSMHandler) openconfirm() bgp.FSMState {
fsm := h.fsm
sec := time.Second * time.Duration(fsm.peerConfig.Timers.KeepaliveInterval)
fsm.keepaliveTicker = time.NewTicker(sec)
@@ -308,7 +308,7 @@ func (h *FSMHandler) sendMessageloop() error {
case <-h.t.Dying():
return nil
case m := <-fsm.outgoing:
- isSend := func(state int, Type uint8) bool {
+ isSend := func(state bgp.FSMState, Type uint8) bool {
switch Type {
case bgp.BGP_MSG_UPDATE:
if state == bgp.BGP_FSM_ESTABLISHED {
@@ -347,7 +347,7 @@ func (h *FSMHandler) recvMessageloop() error {
}
}
-func (h *FSMHandler) established() int {
+func (h *FSMHandler) established() bgp.FSMState {
fsm := h.fsm
h.conn = fsm.passiveConn
h.t.Go(h.sendMessageloop)
@@ -376,7 +376,7 @@ func (h *FSMHandler) established() int {
func (h *FSMHandler) loop() error {
fsm := h.fsm
- nextState := 0
+ nextState := bgp.FSMState(0)
switch fsm.state {
case bgp.BGP_FSM_IDLE:
nextState = h.idle()
diff --git a/server/peer.go b/server/peer.go
index a28e94b6..45fc1cf5 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -29,7 +29,6 @@ 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
@@ -46,7 +45,6 @@ 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),
@@ -54,6 +52,7 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *mes
outEventCh: outEventCh,
}
p.fsm = NewFSM(&g, &peer, p.acceptedConnCh, p.incoming, p.outgoing)
+ peer.BgpNeighborCommonState.State = uint32(bgp.BGP_FSM_IDLE)
p.adjRib = table.NewAdjRib()
p.rib = table.NewTableManager()
p.t.Go(p.loop)
@@ -136,8 +135,8 @@ func (peer *Peer) loop() error {
case nextState := <-peer.fsm.StateChanged():
// waits for all goroutines created for the current state
h.Wait()
- oldState := peer.state
- peer.state = nextState
+ oldState := bgp.FSMState(peer.peerConfig.BgpNeighborCommonState.State)
+ peer.peerConfig.BgpNeighborCommonState.State = uint32(nextState)
peer.fsm.StateChange(nextState)
sameState = false
// TODO: check peer's rf
diff --git a/server/server.go b/server/server.go
index f3ed0092..126bd6a9 100644
--- a/server/server.go
+++ b/server/server.go
@@ -20,6 +20,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
+ "github.com/osrg/gobgp/packet"
"net"
"os"
"strconv"
@@ -158,7 +159,7 @@ func (server *BgpServer) handleRest(restReq *api.RestRequest) {
peer, found := server.peerMap[remoteAddr]
if found {
c := peer.peerConfig
- result.NeighborState = c.BgpNeighborCommonState.State
+ result.NeighborState = bgp.FSMState(c.BgpNeighborCommonState.State).String()
result.RemoteAddr = c.NeighborAddress.String()
result.RemoteAs = c.PeerAs
} else {