diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-10 09:00:50 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-10 23:13:21 +0900 |
commit | 691d80e5d160b82c8b4dd1d83c959ecdffad318f (patch) | |
tree | 52d9a238bde9dd525c63bf15b8ede84ab85d56fe /table | |
parent | 5fc0ac2731ebbe0e812d493e837007068989faa7 (diff) |
make Path objects in rib read-only
Now you can read Path objects in rib safely. Nobody modifies
them. GetRib() API doesn't need to clone the objects. With full
routes, this avoid allocating temporary huge memory.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 14 | ||||
-rw-r--r-- | table/policy.go | 10 |
2 files changed, 12 insertions, 12 deletions
diff --git a/table/destination.go b/table/destination.go index 84183002..e063d89d 100644 --- a/table/destination.go +++ b/table/destination.go @@ -968,7 +968,7 @@ func (d *Destination) MarshalJSON() ([]byte, error) { return json.Marshal(d.GetAllKnownPathList()) } -func (old *Destination) Select(option ...DestinationSelectOption) *Destination { +func (d *Destination) Select(option ...DestinationSelectOption) *Destination { id := GLOBAL_RIB_NAME var vrf *Vrf adj := false @@ -989,9 +989,10 @@ func (old *Destination) Select(option ...DestinationSelectOption) *Destination { } var paths []*Path if adj { - paths = old.knownPathList + paths = make([]*Path, len(d.knownPathList)) + copy(paths, d.knownPathList) } else { - paths = old.GetKnownPathList(id, as) + paths = d.GetKnownPathList(id, as) if vrf != nil { ps := make([]*Path, 0, len(paths)) for _, p := range paths { @@ -1022,12 +1023,7 @@ func (old *Destination) Select(option ...DestinationSelectOption) *Destination { } } } - new := NewDestination(old.nlri, 0) - for _, path := range paths { - p := path.Clone(path.IsWithdraw) - new.knownPathList = append(new.knownPathList, p) - } - return new + return NewDestination(d.nlri, 0, paths...) } type destinations []*Destination diff --git a/table/policy.go b/table/policy.go index 299a976b..e42c3462 100644 --- a/table/policy.go +++ b/table/policy.go @@ -35,7 +35,8 @@ import ( ) type PolicyOptions struct { - Info *PeerInfo + Info *PeerInfo + ValidationResult *Validation } type DefinedType int @@ -1712,8 +1713,11 @@ func (c *RpkiValidationCondition) Type() ConditionType { return CONDITION_RPKI } -func (c *RpkiValidationCondition) Evaluate(path *Path, _ *PolicyOptions) bool { - return c.result == path.ValidationStatus() +func (c *RpkiValidationCondition) Evaluate(path *Path, options *PolicyOptions) bool { + if options != nil && options.ValidationResult != nil { + return c.result == options.ValidationResult.Status + } + return false } func (c *RpkiValidationCondition) Set() DefinedSet { |