diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/adj.go | 14 | ||||
-rw-r--r-- | table/table.go | 21 | ||||
-rw-r--r-- | table/table_manager.go | 8 |
3 files changed, 43 insertions, 0 deletions
diff --git a/table/adj.go b/table/adj.go index b38e02b8..ea7b4151 100644 --- a/table/adj.go +++ b/table/adj.go @@ -16,6 +16,7 @@ package table import ( + "fmt" "github.com/osrg/gobgp/packet/bgp" ) @@ -188,3 +189,16 @@ func (adj *AdjRib) Select(family bgp.RouteFamily, accepted bool, option ...Table option = append(option, TableSelectOption{adj: true}) return tbl.Select(option...) } + +func (adj *AdjRib) TableInfo(family bgp.RouteFamily) (*TableInfo, error) { + if _, ok := adj.table[family]; !ok { + return nil, fmt.Errorf("%s unsupported") + } + c := adj.Count([]bgp.RouteFamily{family}) + a := adj.Accepted([]bgp.RouteFamily{family}) + return &TableInfo{ + NumDestination: c, + NumPath: c, + NumAccepted: a, + }, nil +} diff --git a/table/table.go b/table/table.go index f54766c8..08637522 100644 --- a/table/table.go +++ b/table/table.go @@ -400,3 +400,24 @@ func (t *Table) Select(option ...TableSelectOption) (*Table, error) { destinations: dsts, }, nil } + +type TableInfo struct { + NumDestination int + NumPath int + NumAccepted int +} + +func (t *Table) Info(id string) *TableInfo { + var numD, numP int + for _, d := range t.destinations { + ps := d.GetKnownPathList(id) + if len(ps) > 0 { + numD += 1 + numP += len(ps) + } + } + return &TableInfo{ + NumDestination: numD, + NumPath: numP, + } +} diff --git a/table/table_manager.go b/table/table_manager.go index f93c3a54..083889c7 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -378,3 +378,11 @@ func (manager *TableManager) GetDestination(path *Path) *Destination { } return t.GetDestination(path.getPrefix()) } + +func (manager *TableManager) TableInfo(id string, family bgp.RouteFamily) (*TableInfo, error) { + t, ok := manager.Tables[family] + if !ok { + return nil, fmt.Errorf("address family %s is not configured", family) + } + return t.Info(id), nil +} |