summaryrefslogtreecommitdiffhomepage
path: root/table/destination.go
diff options
context:
space:
mode:
Diffstat (limited to 'table/destination.go')
-rw-r--r--table/destination.go51
1 files changed, 39 insertions, 12 deletions
diff --git a/table/destination.go b/table/destination.go
index 3a1c1c45..845c2ab2 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -852,9 +852,11 @@ func (dest *Destination) String() string {
}
type DestinationSelectOption struct {
- ID string
- VRF *Vrf
- adj bool
+ ID string
+ VRF *Vrf
+ adj bool
+ Best bool
+ MultiPath bool
}
func (d *Destination) MarshalJSON() ([]byte, error) {
@@ -865,6 +867,8 @@ func (old *Destination) Select(option ...DestinationSelectOption) *Destination {
id := GLOBAL_RIB_NAME
var vrf *Vrf
adj := false
+ best := false
+ mp := false
for _, o := range option {
if o.ID != "" {
id = o.ID
@@ -873,27 +877,50 @@ func (old *Destination) Select(option ...DestinationSelectOption) *Destination {
vrf = o.VRF
}
adj = o.adj
+ best = o.Best
+ mp = o.MultiPath
}
var paths []*Path
if adj {
paths = old.knownPathList
} else {
paths = old.GetKnownPathList(id)
+ if vrf != nil {
+ ps := make([]*Path, 0, len(paths))
+ for _, p := range paths {
+ if CanImportToVrf(vrf, p) {
+ ps = append(ps, p)
+ }
+ }
+ paths = ps
+ }
+ if len(paths) == 0 {
+ return nil
+ }
+ if best {
+ if !mp {
+ paths = []*Path{paths[0]}
+ } else {
+ ps := make([]*Path, 0, len(paths))
+ var best *Path
+ for _, p := range paths {
+ if best == nil {
+ best = p
+ ps = append(ps, p)
+ } else if best.Compare(p) == 0 {
+ ps = append(ps, p)
+ }
+ }
+ paths = ps
+ }
+ }
}
new := NewDestination(old.nlri)
- list := make([]*Path, 0, len(old.knownPathList))
for _, path := range paths {
- if vrf != nil && !CanImportToVrf(vrf, path) {
- continue
- }
p := path.Clone(path.IsWithdraw)
p.Filter("", path.Filtered(id))
- list = append(list, p)
- }
- if len(list) == 0 {
- return nil
+ new.knownPathList = append(new.knownPathList, p)
}
- new.knownPathList = list
return new
}