diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 07:16:13 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 07:16:13 -0800 |
commit | 4ff5a68f964a2f85956374b5b95e03f5a19af4da (patch) | |
tree | 33e1d0f810cae15735b24ece5686dad24460b9ec /server/peer.go | |
parent | 02f33490e74f7aa9c0680067934da3088cacf754 (diff) |
server: update state and counter properly
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/server/peer.go b/server/peer.go index 71144067..1d7ec4a8 100644 --- a/server/peer.go +++ b/server/peer.go @@ -154,10 +154,11 @@ func (peer *Peer) loop() error { if nextState == bgp.BGP_FSM_ESTABLISHED { pathList := peer.adjRib.GetOutPathList(table.RF_IPv4_UC) peer.sendMessages(peer.path2update(pathList)) - peer.peerConfig.BgpNeighborCommonState.Uptime = time.Now() - peer.peerConfig.BgpNeighborCommonState.EstablishedCount++ + peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Now() + peer.fsm.peerConfig.BgpNeighborCommonState.EstablishedCount++ } if oldState == bgp.BGP_FSM_ESTABLISHED { + peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Time{} peer.sendToHub("", PEER_MSG_DOWN, peer.fsm.peerInfo) } case <-peer.t.Dying(): @@ -202,32 +203,37 @@ func (peer *Peer) sendToHub(destination string, event int, data interface{}) { func (peer *Peer) MarshalJSON() ([]byte, error) { - c := peer.peerConfig f := peer.fsm + c := f.peerConfig p := make(map[string]interface{}) p["conf"] = struct { - RemoteIP string `json:"remote_ip"` - Id string `json:"id"` - Description string `json:"description"` - RemoteAS uint32 `json:"remote_as"` - LocalAddress string `json:"local_address"` - LocalPort int `json:"local_port"` - CapRefresh bool `json:"cap_refresh"` - CapEnhancedRefresh bool `json:"cap_enhanced_refresh"` + RemoteIP string `json:"remote_ip"` + Id string `json:"id"` + //Description string `json:"description"` + RemoteAS uint32 `json:"remote_as"` + //LocalAddress string `json:"local_address"` + //LocalPort int `json:"local_port"` + CapRefresh bool `json:"cap_refresh"` + CapEnhancedRefresh bool `json:"cap_enhanced_refresh"` }{ - RemoteIP: c.NeighborAddress.String(), - Id: f.routerId.To4().String(), - Description: "", - RemoteAS: c.PeerAs, + RemoteIP: c.NeighborAddress.String(), + Id: f.routerId.To4().String(), + //Description: "", + RemoteAS: c.PeerAs, //LocalAddress: f.passiveConn.LocalAddr().String(), //LocalPort: f.passiveConn.LocalAddr().(*net.TCPAddr).Port, CapRefresh: false, CapEnhancedRefresh: false, } - s := peer.peerConfig.BgpNeighborCommonState + s := c.BgpNeighborCommonState + + uptime := float64(0) + if !s.Uptime.IsZero() { + uptime = time.Now().Sub(s.Uptime).Seconds() + } p["info"] = struct { BgpState string `json:"bgp_state"` FsmEstablishedTransitions uint32 `json:"fsm_established_transitions"` @@ -249,8 +255,8 @@ func (peer *Peer) MarshalJSON() ([]byte, error) { BgpState: f.state.String(), FsmEstablishedTransitions: s.EstablishedCount, - TotalMessageOut: 0, - TotalMessageIn: 0, + TotalMessageOut: s.TotalOut, + TotalMessageIn: s.TotalIn, UpdateMessageOut: s.UpdateOut, UpdateMessageIn: s.UpdateIn, KeepAliveMessageOut: s.KeepaliveOut, @@ -261,7 +267,7 @@ func (peer *Peer) MarshalJSON() ([]byte, error) { NotificationIn: s.NotifyIn, RefreshMessageOut: s.RefreshOut, RefreshMessageIn: s.RefreshIn, - Uptime: time.Now().Sub(s.Uptime).Seconds(), + Uptime: uptime, } return json.Marshal(p) |