diff options
author | Nasato Goto <7310510@gmail.com> | 2019-03-24 14:12:04 +0900 |
---|---|---|
committer | Nasato Goto <7310510@gmail.com> | 2019-03-24 14:16:26 +0900 |
commit | ddf9e5572f144ebac031e4128c8e3432470c6ef7 (patch) | |
tree | 092d79d127840620a0e54aac6e70b7af943f035f /internal/pkg | |
parent | 15f0c50a61711c46357d369bbef60016ced7bbb2 (diff) |
table: fix Path.SetLargeCommunities not to set vacant communities value
Diffstat (limited to 'internal/pkg')
-rw-r--r-- | internal/pkg/table/path.go | 6 | ||||
-rw-r--r-- | internal/pkg/table/policy_test.go | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/internal/pkg/table/path.go b/internal/pkg/table/path.go index b6080ffa..92aec66f 100644 --- a/internal/pkg/table/path.go +++ b/internal/pkg/table/path.go @@ -900,6 +900,12 @@ func (path *Path) GetLargeCommunities() []*bgp.LargeCommunity { } func (path *Path) SetLargeCommunities(cs []*bgp.LargeCommunity, doReplace bool) { + if len(cs) == 0 && doReplace { + // clear large communities + path.delPathAttr(bgp.BGP_ATTR_TYPE_LARGE_COMMUNITY) + return + } + a := path.getPathAttr(bgp.BGP_ATTR_TYPE_LARGE_COMMUNITY) if a == nil || doReplace { path.setPathAttr(bgp.NewPathAttributeLargeCommunities(cs)) diff --git a/internal/pkg/table/policy_test.go b/internal/pkg/table/policy_test.go index 31889980..c67470ef 100644 --- a/internal/pkg/table/policy_test.go +++ b/internal/pkg/table/policy_test.go @@ -3076,6 +3076,30 @@ func TestLargeCommunityMatchAction(t *testing.T) { assert.Equal(t, m.Evaluate(p, nil), true) } +func TestLargeCommunitiesMatchClearAction(t *testing.T) { + coms := []*bgp.LargeCommunity{ + &bgp.LargeCommunity{ASN: 100, LocalData1: 100, LocalData2: 100}, + &bgp.LargeCommunity{ASN: 100, LocalData1: 200, LocalData2: 200}, + } + p := NewPath(nil, nil, false, []bgp.PathAttributeInterface{bgp.NewPathAttributeLargeCommunities(coms)}, time.Time{}, false) + + a, err := NewLargeCommunityAction(config.SetLargeCommunity{ + SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + CommunitiesList: []string{ + "100:100:100", + "100:200:200", + }, + }, + Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + }) + + assert.Equal(t, err, nil) + p = a.Apply(p, nil) + + var lc []*bgp.LargeCommunity + assert.Equal(t, lc, p.GetLargeCommunities()) +} + func TestAfiSafiInMatchPath(t *testing.T) { condition, err := NewAfiSafiInCondition([]config.AfiSafiType{config.AFI_SAFI_TYPE_L3VPN_IPV4_UNICAST, config.AFI_SAFI_TYPE_L3VPN_IPV6_UNICAST}) require.NoError(t, err) |