summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/destination.go42
-rw-r--r--table/table.go27
2 files changed, 69 insertions, 0 deletions
diff --git a/table/destination.go b/table/destination.go
index 3642cf7e..91d2d89b 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -801,3 +801,45 @@ func compareByAge(path1, path2 *Path) *Path {
func (dest *Destination) String() string {
return fmt.Sprintf("Destination NLRI: %s", dest.nlri.String())
}
+
+type destinations []*Destination
+
+func (d destinations) Len() int {
+ return len(d)
+}
+
+func (d destinations) Swap(i, j int) {
+ d[i], d[j] = d[j], d[i]
+}
+
+func (d destinations) Less(i, j int) bool {
+ switch d[i].routeFamily {
+ 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:
+ var s, t *bgp.FlowSpecNLRI
+ switch d[i].routeFamily {
+ case bgp.RF_FS_IPv4_UC:
+ s = &d[i].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
+ t = &d[j].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
+ case bgp.RF_FS_IPv6_UC:
+ s = &d[i].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
+ t = &d[j].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
+ case bgp.RF_FS_IPv4_VPN:
+ s = &d[i].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
+ t = &d[j].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
+ case bgp.RF_FS_IPv6_VPN:
+ s = &d[i].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
+ t = &d[j].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
+ case bgp.RF_FS_L2_VPN:
+ s = &d[i].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
+ t = &d[j].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
+ }
+ if r, _ := bgp.CompareFlowSpecNLRI(s, t); r >= 0 {
+ return true
+ } else {
+ return false
+ }
+ default:
+ strings := sort.StringSlice{d[i].nlri.String(), d[j].nlri.String()}
+ return strings.Less(0, 1)
+ }
+}
diff --git a/table/table.go b/table/table.go
index 9246c6ff..50cecc58 100644
--- a/table/table.go
+++ b/table/table.go
@@ -17,7 +17,9 @@ package table
import (
log "github.com/Sirupsen/logrus"
+ "github.com/armon/go-radix"
"github.com/osrg/gobgp/packet/bgp"
+ "sort"
)
type Table struct {
@@ -194,6 +196,31 @@ func (t *Table) getOrCreateDest(nlri bgp.AddrPrefixInterface) *Destination {
return dest
}
+func (t *Table) GetSortedDestinations() []*Destination {
+ results := make([]*Destination, 0, len(t.GetDestinations()))
+ switch t.routeFamily {
+ case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
+ r := radix.New()
+ for _, dst := range t.GetDestinations() {
+ r.Insert(dst.RadixKey, dst)
+ }
+ r.Walk(func(s string, v interface{}) bool {
+ 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)
+ }
+ }
+ return results
+}
+
func (t *Table) GetDestinations() map[string]*Destination {
return t.destinations
}