summaryrefslogtreecommitdiffhomepage
path: root/server/peer.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-10-09 17:28:58 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-10-09 17:28:58 +0900
commitca6eab76c486a038d654b2b33ec2489e727543e3 (patch)
tree62274058f8030ff8b7aea3eb58db3636bc4dfeac /server/peer.go
parentc1ca1ea7dbfb3d27bd5850297de070389f77ed63 (diff)
server: fix the number of accepted routes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r--server/peer.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/server/peer.go b/server/peer.go
index a370b1af..5f92d690 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -44,6 +44,7 @@ type Peer struct {
inPolicies []*policy.Policy
defaultInPolicy config.DefaultPolicyType
accepted uint32
+ staleAccepted bool
importPolicies []*policy.Policy
defaultImportPolicy config.DefaultPolicyType
exportPolicies []*policy.Policy
@@ -292,11 +293,24 @@ func (peer *Peer) ToApiStruct() *api.Peer {
advertized := uint32(0)
received := uint32(0)
+ accepted := uint32(0)
if f.state == bgp.BGP_FSM_ESTABLISHED {
for _, rf := range peer.configuredRFlist() {
advertized += uint32(peer.adjRib.GetOutCount(rf))
received += uint32(peer.adjRib.GetInCount(rf))
- // FIXME: we should store 'accepted' in memory
+ if peer.staleAccepted {
+ for _, path := range peer.adjRib.GetInPathList(rf) {
+ if path.Filtered == false {
+ accepted++
+ }
+ }
+ }
+ }
+ if peer.staleAccepted {
+ peer.staleAccepted = false
+ peer.accepted = accepted
+ } else {
+ accepted = peer.accepted
}
}
@@ -330,7 +344,7 @@ func (peer *Peer) ToApiStruct() *api.Peer {
Uptime: uptime,
Downtime: downtime,
Received: received,
- Accepted: peer.accepted,
+ Accepted: accepted,
Advertized: advertized,
OutQ: uint32(len(peer.outgoing)),
Flops: s.Flops,
@@ -424,6 +438,9 @@ func (peer *Peer) GetDefaultPolicy(d PolicyDirection) policy.RouteType {
}
func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) ([]*table.Path, []*table.Path) {
+ if d == POLICY_DIRECTION_IN {
+ peer.staleAccepted = true
+ }
newpaths := make([]*table.Path, 0, len(paths))
filteredPaths := make([]*table.Path, 0)
for _, path := range paths {
@@ -443,9 +460,6 @@ func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) ([]*table.
switch result {
case policy.ROUTE_TYPE_ACCEPT:
newpaths = append(newpaths, newpath)
- if d == POLICY_DIRECTION_IN {
- peer.accepted += 1
- }
case policy.ROUTE_TYPE_REJECT:
path.Filtered = true
filteredPaths = append(filteredPaths, path)
@@ -462,5 +476,6 @@ func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) ([]*table.
func (peer *Peer) DropAll(rf bgp.RouteFamily) {
peer.adjRib.DropAll(rf)
+ peer.staleAccepted = false
peer.accepted = 0
}