summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2018-06-14 11:40:32 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-06 11:08:15 +0900
commitcd1e60dd83e9138e45eee164c9b2ab1e2994f6fd (patch)
tree00ce976edab070bde95394094e5f9f94050466aa /table
parent1dc0124f3e106619ecb10279d8dfe7aa204aaaa5 (diff)
table: Sort in table package
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'table')
-rw-r--r--table/policy.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/table/policy.go b/table/policy.go
index 325121c0..55d2fc23 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -22,6 +22,7 @@ import (
"net"
"reflect"
"regexp"
+ "sort"
"strconv"
"strings"
"sync"
@@ -3461,12 +3462,20 @@ func (r *RoutingPolicy) reload(c config.RoutingPolicy) error {
func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.DefinedSets, error) {
r.mu.RLock()
- defer r.mu.RUnlock()
set, ok := r.definedSetMap[typ]
if !ok {
return nil, fmt.Errorf("invalid defined-set type: %d", typ)
}
+
+ var dl DefinedSetList
+ for _, s := range set {
+ dl = append(dl, s)
+ }
+ r.mu.RUnlock()
+
+ sort.Sort(dl)
+
sets := &config.DefinedSets{
PrefixSets: make([]config.PrefixSet, 0),
NeighborSets: make([]config.NeighborSet, 0),
@@ -3477,7 +3486,7 @@ func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.Def
AsPathSets: make([]config.AsPathSet, 0),
},
}
- for _, s := range set {
+ for _, s := range dl {
if name != "" && s.Name() != name {
continue
}
@@ -3631,10 +3640,17 @@ func (r *RoutingPolicy) ReplaceStatement(st *Statement) (err error) {
func (r *RoutingPolicy) GetAllPolicy() []*config.PolicyDefinition {
r.mu.RLock()
- defer r.mu.RUnlock()
- l := make([]*config.PolicyDefinition, 0, len(r.policyMap))
+ var ps Policies
for _, p := range r.policyMap {
+ ps = append(ps, p)
+ }
+ r.mu.RUnlock()
+
+ sort.Sort(ps)
+
+ l := make([]*config.PolicyDefinition, 0, len(ps))
+ for _, p := range ps {
l = append(l, p.ToConfig())
}
return l