summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-18 23:28:46 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-18 23:28:46 -0800
commita6bb09a8478be3914f58d7b5a78daa9128cc64b2 (patch)
treea31f75f4785b9431da335aff2b8c87fa22402a0a
parent4863a27c7ec43f4d85bd0adc85943ad998f4eced (diff)
peer: support peer state
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/fsm.go44
-rw-r--r--table/table_manager.go23
2 files changed, 44 insertions, 23 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 8bf5ca54..9b81d1f4 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -41,6 +41,43 @@ type FSM struct {
routerId net.IP
}
+func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) {
+ state := fsm.peerConfig.BgpNeighborCommonState
+ switch MessageType {
+ case bgp.BGP_MSG_OPEN:
+ if isIn {
+ state.OpenIn++
+ } else {
+ state.OpenOut++
+ }
+ case bgp.BGP_MSG_UPDATE:
+ if isIn {
+ state.UpdateIn++
+ state.UpdateRecvTime = time.Now()
+ } else {
+ state.UpdateOut++
+ }
+ case bgp.BGP_MSG_NOTIFICATION:
+ if isIn {
+ state.NotifyIn++
+ } else {
+ state.NotifyOut++
+ }
+ case bgp.BGP_MSG_KEEPALIVE:
+ if isIn {
+ state.KeepaliveIn++
+ } else {
+ state.KeepaliveOut++
+ }
+ case bgp.BGP_MSG_ROUTE_REFRESH:
+ if isIn {
+ state.RefreshIn++
+ } else {
+ state.RefreshOut++
+ }
+ }
+}
+
func NewFSM(gConfig *config.GlobalType, pConfig *config.NeighborType, connCh chan *net.TCPConn, incoming chan *bgp.BGPMessage, outgoing chan *bgp.BGPMessage) *FSM {
return &FSM{
globalConfig: gConfig,
@@ -192,6 +229,7 @@ func (h *FSMHandler) opensent() int {
m := buildopen(fsm.globalConfig, fsm.peerConfig)
b, _ := m.Serialize()
fsm.passiveConn.Write(b)
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
h.ch = make(chan *bgp.BGPMessage)
h.conn = fsm.passiveConn
@@ -205,11 +243,13 @@ func (h *FSMHandler) opensent() int {
return 0
case m, ok := <-h.ch:
if ok {
+ fsm.bgpMessageStateUpdate(m.Header.Type, true)
if m.Header.Type == bgp.BGP_MSG_OPEN {
fsm.routerId = m.Body.(*bgp.BGPOpen).ID
msg := bgp.NewBGPKeepAliveMessage()
b, _ := msg.Serialize()
fsm.passiveConn.Write(b)
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
nextState = bgp.BGP_FSM_OPENCONFIRM
} else {
// send error
@@ -244,6 +284,7 @@ func (h *FSMHandler) openconfirm() int {
case m, ok := <-h.ch:
nextState := bgp.BGP_FSM_IDLE
if ok {
+ fsm.bgpMessageStateUpdate(m.Header.Type, true)
if m.Header.Type == bgp.BGP_MSG_KEEPALIVE {
nextState = bgp.BGP_FSM_ESTABLISHED
} else {
@@ -272,6 +313,7 @@ func (h *FSMHandler) sendMessageloop() error {
if err != nil {
return nil
}
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
case <-fsm.keepaliveTicker.C:
m := bgp.NewBGPKeepAliveMessage()
b, _ := m.Serialize()
@@ -279,6 +321,7 @@ func (h *FSMHandler) sendMessageloop() error {
if err != nil {
return nil
}
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
}
}
}
@@ -304,6 +347,7 @@ func (h *FSMHandler) established() int {
select {
case m, ok := <-h.ch:
if ok {
+ fsm.bgpMessageStateUpdate(m.Header.Type, true)
fsm.incoming <- m
} else {
h.conn.Close()
diff --git a/table/table_manager.go b/table/table_manager.go
index 72fa5f0b..7a913b6d 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -29,19 +29,6 @@ var logger *log.Logger = &log.Logger{
Level: log.InfoLevel,
}
-type PeerCounterName string
-
-const (
- RECV_PREFIXES PeerCounterName = "recv_prefixes"
- RECV_UPDATES PeerCounterName = "recv_updates"
- SENT_UPDATES PeerCounterName = "sent_updates"
- RECV_NOTIFICATION PeerCounterName = "recv_notification"
- SENT_NOTIFICATION PeerCounterName = "sent_notification"
- SENT_REFRESH PeerCounterName = "sent_refresh"
- RECV_REFRESH PeerCounterName = "recv_refresh"
- FSM_ESTB_TRANSITIONS PeerCounterName = "fms_established_transitions"
-)
-
type RouteFamily int
const (
@@ -232,7 +219,6 @@ func (p *ProcessMessage) ToPathList() []Path {
type TableManager struct {
Tables map[RouteFamily]Table
- Counter map[PeerCounterName]int
localAsn uint32
}
@@ -241,9 +227,6 @@ func NewTableManager() *TableManager {
t.Tables = make(map[RouteFamily]Table)
t.Tables[RF_IPv4_UC] = NewIPv4Table(0)
t.Tables[RF_IPv6_UC] = NewIPv6Table(0)
- // initialize prefix counter
- t.Counter = make(map[PeerCounterName]int)
- t.Counter[RECV_PREFIXES] = 0
return t
}
@@ -251,12 +234,6 @@ func setLogger(loggerInstance *log.Logger) {
logger = loggerInstance
}
-func (manager *TableManager) incrCounter(name PeerCounterName, step int) {
- val := manager.Counter[name]
- val += step
- manager.Counter[name] = val
-}
-
func (manager *TableManager) ProcessPaths(pathList []Path) ([]Path, []Destination, error) {
bestPaths := make([]Path, 0)
lostDest := make([]Destination, 0)