diff options
-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 } |