diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-18 13:01:43 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-19 00:44:47 +0000 |
commit | b281f7f4ffc965b8a88b0a85b5315b97ca512f68 (patch) | |
tree | b3a7a793de7532a860d3718174725300cf378681 /table/table.go | |
parent | c2bb04d5efa1c7586500832e16524e13596dbe29 (diff) |
server: return flowspec routes in rfc compliant manner
The order of the flowspec routes matters because they will be used
as ACL rules and what rule will be applied depends on the order.
RFC5575 specifies how flowspec routes should be sorted.
This commit implements what it says.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table.go')
-rw-r--r-- | table/table.go | 27 |
1 files changed, 27 insertions, 0 deletions
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 } |