diff options
Diffstat (limited to 'table/policy_test.go')
-rw-r--r-- | table/policy_test.go | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/table/policy_test.go b/table/policy_test.go index 6897a227..a846dabe 100644 --- a/table/policy_test.go +++ b/table/policy_test.go @@ -17,16 +17,17 @@ package table import ( "fmt" - log "github.com/Sirupsen/logrus" - "github.com/osrg/gobgp/config" - "github.com/osrg/gobgp/packet/bgp" - "github.com/stretchr/testify/assert" "math" "net" "strconv" "strings" "testing" "time" + + log "github.com/Sirupsen/logrus" + "github.com/osrg/gobgp/config" + "github.com/osrg/gobgp/packet/bgp" + "github.com/stretchr/testify/assert" ) func TestPrefixCalcurateNoRange(t *testing.T) { @@ -2804,6 +2805,38 @@ func createAs4Value(s string) uint32 { return uint32(upper)<<16 + uint32(lower) } +func TestPrefixSetOperation(t *testing.T) { + // tryp to create prefixset with multiple families + p1 := config.Prefix{ + IpPrefix: "0.0.0.0/0", + MasklengthRange: "0..7", + } + p2 := config.Prefix{ + IpPrefix: "0::/25", + MasklengthRange: "25..128", + } + _, err := NewPrefixSet(config.PrefixSet{ + PrefixSetName: "ps1", + PrefixList: []config.Prefix{p1, p2}, + }) + assert.NotNil(t, err) + m1, _ := NewPrefixSet(config.PrefixSet{ + PrefixSetName: "ps1", + PrefixList: []config.Prefix{p1}, + }) + m2, err := NewPrefixSet(config.PrefixSet{PrefixSetName: "ps2"}) + assert.Nil(t, err) + err = m1.Append(m2) + assert.Nil(t, err) + err = m2.Append(m1) + assert.Nil(t, err) + assert.Equal(t, bgp.RF_IPv4_UC, m2.family) + p3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""}) + p4, _ := NewPrefix(config.Prefix{IpPrefix: "0::/25", MasklengthRange: ""}) + _, err = NewPrefixSetFromApiStruct("ps3", []*Prefix{p3, p4}) + assert.NotNil(t, err) +} + func TestPrefixSetMatch(t *testing.T) { p1 := config.Prefix{ IpPrefix: "0.0.0.0/0", @@ -2861,6 +2894,24 @@ func TestPrefixSetMatch(t *testing.T) { assert.False(t, m.Evaluate(path, nil)) } +func TestPrefixSetMatchV4withV6Prefix(t *testing.T) { + p1 := config.Prefix{ + IpPrefix: "c000::/3", + MasklengthRange: "3..128", + } + ps, err := NewPrefixSet(config.PrefixSet{ + PrefixSetName: "ps1", + PrefixList: []config.Prefix{p1}, + }) + assert.Nil(t, err) + m := &PrefixCondition{ + set: ps, + } + + path := NewPath(nil, bgp.NewIPAddrPrefix(6, "192.0.0.0"), false, []bgp.PathAttributeInterface{}, time.Now(), false) + assert.False(t, m.Evaluate(path, nil)) +} + func TestLargeCommunityMatchAction(t *testing.T) { coms := []*bgp.LargeCommunity{ &bgp.LargeCommunity{ASN: 100, LocalData1: 100, LocalData2: 100}, |