summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/destination.go9
-rw-r--r--table/path.go25
-rw-r--r--table/table.go14
3 files changed, 39 insertions, 9 deletions
diff --git a/table/destination.go b/table/destination.go
index 7e0deb2b..3a1c1c45 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -18,6 +18,7 @@ package table
import (
"bytes"
"encoding/binary"
+ "encoding/json"
"fmt"
"net"
"sort"
@@ -124,11 +125,11 @@ type Destination struct {
RadixKey string
}
-func NewDestination(nlri bgp.AddrPrefixInterface) *Destination {
+func NewDestination(nlri bgp.AddrPrefixInterface, known ...*Path) *Destination {
d := &Destination{
routeFamily: bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()),
nlri: nlri,
- knownPathList: make([]*Path, 0),
+ knownPathList: known,
withdrawList: make([]*Path, 0),
newPathList: make([]*Path, 0),
}
@@ -856,6 +857,10 @@ type DestinationSelectOption struct {
adj bool
}
+func (d *Destination) MarshalJSON() ([]byte, error) {
+ return json.Marshal(d.GetAllKnownPathList())
+}
+
func (old *Destination) Select(option ...DestinationSelectOption) *Destination {
id := GLOBAL_RIB_NAME
var vrf *Vrf
diff --git a/table/path.go b/table/path.go
index c75ca579..0aab6004 100644
--- a/table/path.go
+++ b/table/path.go
@@ -17,6 +17,7 @@ package table
import (
"bytes"
+ "encoding/json"
"fmt"
"math"
"net"
@@ -845,6 +846,30 @@ func (lhs *Path) Equal(rhs *Path) bool {
return bytes.Equal(pattrs(lhs.GetPathAttrs()), pattrs(rhs.GetPathAttrs()))
}
+func (path *Path) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Nlri bgp.AddrPrefixInterface `json:"nlri"`
+ PathAttrs []bgp.PathAttributeInterface `json:"attrs"`
+ Age int64 `json:"age"`
+ Withdrawal bool `json:"withdrawal,omitempty"`
+ Validation string `json:"validation,omitempty"`
+ SourceID net.IP `json:"source-id,omitempty"`
+ NeighborIP net.IP `json:"neighbor-ip,omitempty"`
+ Stale bool `json:"stale,omitempty"`
+ Filtered bool `json:"filtered,omitempty"`
+ }{
+ Nlri: path.GetNlri(),
+ PathAttrs: path.GetPathAttrs(),
+ Age: path.GetTimestamp().Unix(),
+ Withdrawal: path.IsWithdraw,
+ Validation: string(path.Validation()),
+ SourceID: path.GetSource().ID,
+ NeighborIP: path.GetSource().Address,
+ Stale: path.IsStale(),
+ Filtered: path.Filtered("") > POLICY_DIRECTION_NONE,
+ })
+}
+
func (lhs *Path) Compare(rhs *Path) int {
if lhs.IsLocal() && !rhs.IsLocal() {
return 1
diff --git a/table/table.go b/table/table.go
index bad0e824..f89e8dff 100644
--- a/table/table.go
+++ b/table/table.go
@@ -50,10 +50,14 @@ type Table struct {
destinations map[string]*Destination
}
-func NewTable(rf bgp.RouteFamily) *Table {
+func NewTable(rf bgp.RouteFamily, dsts ...*Destination) *Table {
+ destinations := make(map[string]*Destination)
+ for _, dst := range dsts {
+ destinations[dst.GetNlri().String()] = dst
+ }
return &Table{
routeFamily: rf,
- destinations: make(map[string]*Destination),
+ destinations: destinations,
}
}
@@ -229,15 +233,11 @@ func (t *Table) GetSortedDestinations() []*Destination {
results = append(results, v.(*Destination))
return false
})
- case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
- for _, dst := range t.GetDestinations() {
- results = append(results, dst)
- }
- sort.Sort(destinations(results))
default:
for _, dst := range t.GetDestinations() {
results = append(results, dst)
}
+ sort.Sort(destinations(results))
}
return results
}