diff options
Diffstat (limited to 'internal/pkg/table')
-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) |