diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-24 21:39:27 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-24 21:51:54 +0900 |
commit | bb881467bcbff28a56ff0f3eb6e16d261b31d4c3 (patch) | |
tree | b4ae401e0ad295a814c16bdc832bbc2f3c463779 | |
parent | 1aa345882e9feb46c0b7c2fa8c658794242e7418 (diff) |
policy: modify path.GetAsSeqList() to insert 0 for non-seq-as-elems
GetAsSeqList() is used for AsPathSet matching and AsPathPrepend action.
Just eliminating non-seq-as-elems from what GetAsSeqList() returns cause
wrong results for these two match/action.
e.g path A's as-path: {100, 200} 300
currently, action 'as-path-prepend left-most repeat 2' will alter
as-path to 300 300 {100, 200} 300, which is not expected behavior.
To fix this, insert 0 for non-seq-as-elems.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | table/path.go | 2 | ||||
-rw-r--r-- | table/path_test.go | 8 | ||||
-rw-r--r-- | table/policy.go | 11 |
3 files changed, 15 insertions, 6 deletions
diff --git a/table/path.go b/table/path.go index bcf5b4ce..3cebdb96 100644 --- a/table/path.go +++ b/table/path.go @@ -393,6 +393,8 @@ func (path *Path) getAsListofSpecificType(getAsSeq, getAsSet bool) []uint32 { } if getAsSet && segment.Type == bgp.BGP_ASPATH_ATTR_TYPE_SET { asList = append(asList, segment.AS...) + } else { + asList = append(asList, 0) } } } diff --git a/table/path_test.go b/table/path_test.go index 1f2311f5..98e59092 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -146,7 +146,7 @@ func TestPathPrependAsnToExistingSeqAttr(t *testing.T) { p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) p.PrependAsn(65000, 1) - assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005}, p.GetAsSeqList()) + assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetAsSeqList()) fmt.Printf("asns: %v", p.GetAsSeqList()) } @@ -197,7 +197,7 @@ func TestPathPrependAsnToNewAsPathSeq(t *testing.T) { asn := uint32(65000) p.PrependAsn(asn, 1) - assert.Equal([]uint32{asn}, p.GetAsSeqList()) + assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) fmt.Printf("asns: %v", p.GetAsSeqList()) } @@ -227,7 +227,7 @@ func TestPathPrependAsnToEmptyAsPathAttr(t *testing.T) { asn := uint32(65000) p.PrependAsn(asn, 1) - assert.Equal([]uint32{asn}, p.GetAsSeqList()) + assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) fmt.Printf("asns: %v", p.GetAsSeqList()) } @@ -266,7 +266,7 @@ func TestPathPrependAsnToFullPathAttr(t *testing.T) { expected = append(expected, uint32(v)) } p.PrependAsn(65000, 2) - assert.Equal(expected, p.GetAsSeqList()) + assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList()) fmt.Printf("asns: %v", p.GetAsSeqList()) } diff --git a/table/policy.go b/table/policy.go index 71793485..bc59799e 100644 --- a/table/policy.go +++ b/table/policy.go @@ -2021,16 +2021,23 @@ func (a *AsPathPrependAction) Apply(path *Path) *Path { log.WithFields(log.Fields{ "Topic": "Policy", "Type": "AsPathPrepend Action", - }).Errorf("aspath length is zero.") + }).Warnf("aspath length is zero.") return path } asn = aspath[0] + if asn == 0 { + log.WithFields(log.Fields{ + "Topic": "Policy", + "Type": "AsPathPrepend Action", + }).Warnf("left-most ASN is not seq") + return path + } log.WithFields(log.Fields{ "Topic": "Policy", "Type": "AsPathPrepend Action", "LastAs": asn, "Repeat": a.repeat, - }).Debug("use last AS.") + }).Debug("use left-most ASN") } else { asn = a.asn } |