summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-16 16:33:53 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-16 18:25:18 +0900
commit0cf8045e994b653030b721c574614d46c1870cf1 (patch)
treee409864aafea90c4aa4b990fb88a4917afd2596f /table
parent40ce51137a1bc3733d36ea045daae067eef735f0 (diff)
policy: introduce policy option infra
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/policy.go37
-rw-r--r--table/policy_test.go210
2 files changed, 125 insertions, 122 deletions
diff --git a/table/policy.go b/table/policy.go
index 4484e7e6..a8192a58 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -31,6 +31,9 @@ import (
"github.com/osrg/gobgp/packet"
)
+type PolicyOptions struct {
+}
+
type DefinedType int
const (
@@ -1027,7 +1030,7 @@ func NewDefinedSetFromApiStruct(a *api.DefinedSet) (DefinedSet, error) {
type Condition interface {
Type() ConditionType
- Evaluate(*Path) bool
+ Evaluate(*Path, *PolicyOptions) bool
Set() DefinedSet
}
@@ -1051,7 +1054,7 @@ func (c *PrefixCondition) Option() MatchOption {
// compare prefixes in this condition and nlri of path and
// subsequent comparison is skipped if that matches the conditions.
// If PrefixList's length is zero, return true.
-func (c *PrefixCondition) Evaluate(path *Path) bool {
+func (c *PrefixCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
var key string
var masklen uint8
keyf := func(ip net.IP, ones int) string {
@@ -1149,7 +1152,7 @@ func (c *NeighborCondition) Option() MatchOption {
// compare neighbor ipaddress of this condition and source address of path
// and, subsequent comparisons are skipped if that matches the conditions.
// If NeighborList's length is zero, return true.
-func (c *NeighborCondition) Evaluate(path *Path) bool {
+func (c *NeighborCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
if len(c.set.list) == 0 {
log.Debug("NeighborList doesn't have elements")
@@ -1242,7 +1245,7 @@ func (c *AsPathCondition) ToApiStruct() *api.MatchSet {
}
}
-func (c *AsPathCondition) Evaluate(path *Path) bool {
+func (c *AsPathCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
result := false
aspath := path.GetAsSeqList()
for _, m := range c.set.singleList {
@@ -1333,7 +1336,7 @@ func (c *CommunityCondition) ToApiStruct() *api.MatchSet {
}
}
-func (c *CommunityCondition) Evaluate(path *Path) bool {
+func (c *CommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
cs := path.GetCommunities()
result := false
for _, x := range cs {
@@ -1418,7 +1421,7 @@ func (c *ExtCommunityCondition) ToApiStruct() *api.MatchSet {
}
}
-func (c *ExtCommunityCondition) Evaluate(path *Path) bool {
+func (c *ExtCommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
es := path.GetExtCommunities()
result := false
for _, x := range es {
@@ -1495,7 +1498,7 @@ func (c *AsPathLengthCondition) Type() ConditionType {
// compare AS_PATH length in the message's AS_PATH attribute with
// the one in condition.
-func (c *AsPathLengthCondition) Evaluate(path *Path) bool {
+func (c *AsPathLengthCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
length := uint32(path.GetAsPathLen())
result := false
@@ -1561,7 +1564,7 @@ func (c *RpkiValidationCondition) Type() ConditionType {
return CONDITION_RPKI
}
-func (c *RpkiValidationCondition) Evaluate(path *Path) bool {
+func (c *RpkiValidationCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
return c.result == path.Validation()
}
@@ -2077,17 +2080,17 @@ type Statement struct {
}
// evaluate each condition in the statement according to MatchSetOptions
-func (s *Statement) Evaluate(p *Path) bool {
+func (s *Statement) Evaluate(p *Path, options *PolicyOptions) bool {
for _, c := range s.Conditions {
- if !c.Evaluate(p) {
+ if !c.Evaluate(p, options) {
return false
}
}
return true
}
-func (s *Statement) Apply(path *Path) (RouteType, *Path) {
- result := s.Evaluate(path)
+func (s *Statement) Apply(path *Path, options *PolicyOptions) (RouteType, *Path) {
+ result := s.Evaluate(path, options)
if result {
if len(s.ModActions) != 0 {
// apply all modification actions
@@ -2446,10 +2449,10 @@ func (p *Policy) Name() string {
// Compare path with a policy's condition in stored order in the policy.
// If a condition match, then this function stops evaluation and
// subsequent conditions are skipped.
-func (p *Policy) Apply(path *Path) (RouteType, *Path) {
+func (p *Policy) Apply(path *Path, options *PolicyOptions) (RouteType, *Path) {
for _, stmt := range p.Statements {
var result RouteType
- result, path = stmt.Apply(path)
+ result, path = stmt.Apply(path, options)
if result != ROUTE_TYPE_NONE {
return result, path
}
@@ -2571,7 +2574,7 @@ type RoutingPolicy struct {
AssignmentMap map[string]*Assignment
}
-func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path) *Path {
+func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path, options *PolicyOptions) *Path {
if before == nil {
return nil
}
@@ -2581,7 +2584,7 @@ func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path
result := ROUTE_TYPE_NONE
after := before
for _, p := range r.GetPolicy(id, dir) {
- result, after = p.Apply(before)
+ result, after = p.Apply(before, options)
if result != ROUTE_TYPE_NONE {
break
}
@@ -2839,7 +2842,7 @@ func CanImportToVrf(v *Vrf, path *Path) bool {
MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
}
c, _ := NewExtCommunityCondition(matchSet, map[string]DefinedSet{v.Name: set})
- return c.Evaluate(path)
+ return c.Evaluate(path, nil)
}
func PoliciesToString(ps []*api.Policy) []string {
diff --git a/table/policy_test.go b/table/policy_test.go
index d7cc0254..38b55794 100644
--- a/table/policy_test.go
+++ b/table/policy_test.go
@@ -241,7 +241,7 @@ func TestPolicyNotMatch(t *testing.T) {
r := NewRoutingPolicy()
err := r.Reload(pl)
assert.Nil(t, err)
- pType, newPath := r.PolicyMap["pd1"].Apply(path)
+ pType, newPath := r.PolicyMap["pd1"].Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, newPath, path)
}
@@ -272,7 +272,7 @@ func TestPolicyMatchAndReject(t *testing.T) {
r := NewRoutingPolicy()
err := r.Reload(pl)
assert.Nil(t, err)
- pType, newPath := r.PolicyMap["pd1"].Apply(path)
+ pType, newPath := r.PolicyMap["pd1"].Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
}
@@ -304,7 +304,7 @@ func TestPolicyMatchAndAccept(t *testing.T) {
r := NewRoutingPolicy()
err := r.Reload(pl)
assert.Nil(t, err)
- pType, newPath := r.PolicyMap["pd1"].Apply(path)
+ pType, newPath := r.PolicyMap["pd1"].Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, path, newPath)
}
@@ -347,11 +347,11 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path1)
+ pType, newPath := p.Apply(path1, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path1)
- pType2, newPath2 := p.Apply(path2)
+ pType2, newPath2 := p.Apply(path2, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType2)
assert.Equal(t, newPath2, path2)
}
@@ -393,11 +393,11 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
r := NewRoutingPolicy()
err := r.Reload(pl)
assert.Nil(t, err)
- pType, newPath := r.PolicyMap["pd1"].Apply(path1)
+ pType, newPath := r.PolicyMap["pd1"].Apply(path1, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path1)
- pType2, newPath2 := r.PolicyMap["pd1"].Apply(path2)
+ pType2, newPath2 := r.PolicyMap["pd1"].Apply(path2, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType2)
assert.Equal(t, newPath2, path2)
}
@@ -447,11 +447,11 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType1, newPath1 := p.Apply(pathIPv4)
+ pType1, newPath1 := p.Apply(pathIPv4, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType1)
assert.Equal(t, newPath1, pathIPv4)
- pType2, newPath2 := p.Apply(pathIPv6)
+ pType2, newPath2 := p.Apply(pathIPv6, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType2)
assert.Equal(t, newPath2, pathIPv6)
}
@@ -482,7 +482,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) {
c, _ := NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, true, c.Evaluate(path))
+ assert.Equal(t, true, c.Evaluate(path, nil))
// create match condition
asPathLength = config.AsPathLength{
@@ -492,7 +492,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) {
c, _ = NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, true, c.Evaluate(path))
+ assert.Equal(t, true, c.Evaluate(path, nil))
// create match condition
asPathLength = config.AsPathLength{
@@ -502,7 +502,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) {
c, _ = NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, false, c.Evaluate(path))
+ assert.Equal(t, false, c.Evaluate(path, nil))
}
func TestAsPathLengthConditionWithOtherCondition(t *testing.T) {
@@ -547,7 +547,7 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
@@ -589,7 +589,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) {
c, _ := NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, true, c.Evaluate(path))
+ assert.Equal(t, true, c.Evaluate(path, nil))
// create match condition
asPathLength = config.AsPathLength{
@@ -599,7 +599,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) {
c, _ = NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, true, c.Evaluate(path))
+ assert.Equal(t, true, c.Evaluate(path, nil))
// create match condition
asPathLength = config.AsPathLength{
@@ -609,7 +609,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) {
c, _ = NewAsPathLengthCondition(asPathLength)
// test
- assert.Equal(t, false, c.Evaluate(path))
+ assert.Equal(t, false, c.Evaluate(path, nil))
}
func TestAs4PathLengthConditionWithOtherCondition(t *testing.T) {
@@ -664,7 +664,7 @@ func TestAs4PathLengthConditionWithOtherCondition(t *testing.T) {
r := NewRoutingPolicy()
r.Reload(pl)
p, _ := NewPolicy(pl.PolicyDefinitions[0], r.DefinedSetMap)
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
@@ -753,15 +753,15 @@ func TestAsPathConditionEvaluate(t *testing.T) {
p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, false, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, false, p6.Evaluate(path1))
- assert.Equal(t, true, p6.Evaluate(path2))
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path2))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, false, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, false, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p6.Evaluate(path2, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path2, nil))
}
func TestMultipleAsPathConditionEvaluate(t *testing.T) {
@@ -854,15 +854,15 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) {
p9 := createAspathC("asset9", config.MATCH_SET_OPTIONS_TYPE_ANY)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, true, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, true, p6.Evaluate(path1))
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path1))
- assert.Equal(t, false, p9.Evaluate(path1))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, true, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, true, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path1, nil))
+ assert.Equal(t, false, p9.Evaluate(path1, nil))
}
func TestAsPathCondition(t *testing.T) {
@@ -921,7 +921,7 @@ func TestAsPathCondition(t *testing.T) {
MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
}, map[string]DefinedSet{k: s})
for _, a := range v {
- result := c.Evaluate(a.path)
+ result := c.Evaluate(a.path, nil)
if a.result != result {
log.WithFields(log.Fields{
"EXP": k,
@@ -978,7 +978,7 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
@@ -1085,16 +1085,16 @@ func TestAs4PathConditionEvaluate(t *testing.T) {
p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, false, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, false, p6.Evaluate(path1))
- assert.Equal(t, true, p6.Evaluate(path2))
-
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path2))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, false, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, false, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p6.Evaluate(path2, nil))
+
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path2, nil))
}
func TestMultipleAs4PathConditionEvaluate(t *testing.T) {
@@ -1206,15 +1206,15 @@ func TestMultipleAs4PathConditionEvaluate(t *testing.T) {
p9 := createAspathC("asset9", config.MATCH_SET_OPTIONS_TYPE_ANY)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, true, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, true, p6.Evaluate(path1))
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path1))
- assert.Equal(t, false, p9.Evaluate(path1))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, true, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, true, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path1, nil))
+ assert.Equal(t, false, p9.Evaluate(path1, nil))
}
func TestAs4PathConditionWithOtherCondition(t *testing.T) {
@@ -1271,7 +1271,7 @@ func TestAs4PathConditionWithOtherCondition(t *testing.T) {
r := NewRoutingPolicy()
r.Reload(pl)
p, _ := NewPolicy(pl.PolicyDefinitions[0], r.DefinedSetMap)
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
@@ -1365,13 +1365,13 @@ func TestAs4PathConditionEvaluateMixedWith2byteAS(t *testing.T) {
p7 := createAspathC("asset7", config.MATCH_SET_OPTIONS_TYPE_ANY)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, true, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, false, p6.Evaluate(path1))
- assert.Equal(t, true, p7.Evaluate(path1))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, true, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, false, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
}
@@ -1508,16 +1508,16 @@ func TestCommunityConditionEvaluate(t *testing.T) {
p10 := createCommunityC("comset10", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, true, p4.Evaluate(path1))
- assert.Equal(t, true, p5.Evaluate(path1))
- assert.Equal(t, true, p6.Evaluate(path1))
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path1))
- assert.Equal(t, true, p9.Evaluate(path2))
- assert.Equal(t, true, p10.Evaluate(path1))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, true, p4.Evaluate(path1, nil))
+ assert.Equal(t, true, p5.Evaluate(path1, nil))
+ assert.Equal(t, true, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path1, nil))
+ assert.Equal(t, true, p9.Evaluate(path2, nil))
+ assert.Equal(t, true, p10.Evaluate(path1, nil))
}
@@ -1591,12 +1591,12 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
p = r.PolicyMap["pd2"]
- pType, newPath = p.Apply(path)
+ pType, newPath = p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, newPath, path)
@@ -1637,7 +1637,7 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
log.Debug(newPath)
@@ -1682,7 +1682,7 @@ func TestPolicyMatchAndReplaceCommunities(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunities())
@@ -1726,7 +1726,7 @@ func TestPolicyMatchAndRemoveCommunities(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommunities())
@@ -1772,7 +1772,7 @@ func TestPolicyMatchAndRemoveCommunitiesRegexp(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommunities())
@@ -1818,7 +1818,7 @@ func TestPolicyMatchAndRemoveCommunitiesRegexp2(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommunities())
@@ -1865,7 +1865,7 @@ func TestPolicyMatchAndClearCommunities(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
//assert.Equal(t, []uint32{}, newPath.GetCommunities())
@@ -2036,17 +2036,17 @@ func TestExtCommunityConditionEvaluate(t *testing.T) {
p11 := createExtCommunityC("ecomSet11", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
- assert.Equal(t, true, p1.Evaluate(path1))
- assert.Equal(t, true, p2.Evaluate(path1))
- assert.Equal(t, true, p3.Evaluate(path1))
- assert.Equal(t, false, p4.Evaluate(path1))
- assert.Equal(t, false, p5.Evaluate(path1))
- assert.Equal(t, false, p6.Evaluate(path1))
- assert.Equal(t, true, p7.Evaluate(path1))
- assert.Equal(t, true, p8.Evaluate(path1))
- assert.Equal(t, true, p9.Evaluate(path1))
- assert.Equal(t, true, p10.Evaluate(path1))
- assert.Equal(t, true, p11.Evaluate(path1))
+ assert.Equal(t, true, p1.Evaluate(path1, nil))
+ assert.Equal(t, true, p2.Evaluate(path1, nil))
+ assert.Equal(t, true, p3.Evaluate(path1, nil))
+ assert.Equal(t, false, p4.Evaluate(path1, nil))
+ assert.Equal(t, false, p5.Evaluate(path1, nil))
+ assert.Equal(t, false, p6.Evaluate(path1, nil))
+ assert.Equal(t, true, p7.Evaluate(path1, nil))
+ assert.Equal(t, true, p8.Evaluate(path1, nil))
+ assert.Equal(t, true, p9.Evaluate(path1, nil))
+ assert.Equal(t, true, p10.Evaluate(path1, nil))
+ assert.Equal(t, true, p11.Evaluate(path1, nil))
}
@@ -2169,12 +2169,12 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, newPath, path)
p = r.PolicyMap["pd2"]
- pType, newPath = p.Apply(path)
+ pType, newPath = p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path)
@@ -2215,7 +2215,7 @@ func TestPolicyMatchAndReplaceMed(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
v, err := newPath.GetMed()
@@ -2258,7 +2258,7 @@ func TestPolicyMatchAndAddingMed(t *testing.T) {
err := r.Reload(pl)
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
@@ -2304,7 +2304,7 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
@@ -2350,7 +2350,7 @@ func TestPolicyMatchAndSubtractMed(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
@@ -2396,7 +2396,7 @@ func TestPolicyMatchAndSubtractMedUnderFlow(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
@@ -2439,7 +2439,7 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) {
assert.Nil(t, err)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
@@ -2486,7 +2486,7 @@ func TestPolicyAsPathPrepend(t *testing.T) {
r.Reload(pl)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, newPath.GetAsSeqList())
@@ -2530,7 +2530,7 @@ func TestPolicyAsPathPrependLastAs(t *testing.T) {
r.Reload(pl)
p := r.PolicyMap["pd1"]
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, newPath.GetAsSeqList())
@@ -2580,7 +2580,7 @@ func TestPolicyAs4PathPrepend(t *testing.T) {
r.Reload(pl)
p, _ := NewPolicy(pl.PolicyDefinitions[0], r.DefinedSetMap)
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath)
asn := createAs4Value("65002.1")
@@ -2635,7 +2635,7 @@ func TestPolicyAs4PathPrependLastAs(t *testing.T) {
r.Reload(pl)
p, _ := NewPolicy(pl.PolicyDefinitions[0], r.DefinedSetMap)
- pType, newPath := p.Apply(path)
+ pType, newPath := p.Apply(path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath)
asn := createAs4Value("65002.1")