Skip to content

Commit dac9dc2

Browse files
authored
Replace routing policy 'set.community.delete' with 'delete.community' (#2842)
The 'set.community.delete: True' is a ridiculous way to say 'delete the community'. This commit resolves #2244 and implement the more logical way of deleting communities in routing policies: * It defines the new 'delete.community' dictionary that can contain lists of community or community list name * It automatically converts old-style routing policies into the new format (while generating a warning) * All device definitions and configuration templates have been updated to use the new attributes * Add missing features for the "netlab show module" printout Bonus: * 'delete.community.list' is now implemented for Junos
1 parent bc2b21d commit dac9dc2

File tree

20 files changed

+137
-66
lines changed

20 files changed

+137
-66
lines changed

docs/module/routing.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Routing policies are lists of instructions that can **match** route parameters a
5757
* **sequence**: Statement sequence number. When not specified, *netlab* sets a routing policy entry's **sequence** number to ten times its list position.
5858
* **match**: Conditions that must match for the routing policy entry to take effect. Entries without a **match** parameter match all routes
5959
* **set**: Parameters that are set on matched routes.
60+
* **delete**: Parameters that are deleted on matched routes.
6061

6162
You can match these route parameters in a _netlab_ routing policy:
6263

@@ -70,16 +71,18 @@ You can set these route parameters in a _netlab_ routing policy:
7071
* **med**: Route metric (for example, BGP MED)
7172
* **prepend**: BGP AS-path prepending ([more details](plugin-bgp-policy-attributes))
7273
* **weight**: BGP weight
73-
* **community**: A dictionary that can be used to set, add, or remove standard, large, or extended communities.
74+
* **community**: A dictionary that can be used to set or add standard, large, or extended communities.
7475

7576
The **set.community** dictionary has these parameters:
7677

7778
* **standard**: Standard BGP communities to set
7879
* **large**: Large BGP communities to set
7980
* **extended**: Extended BGP communities to set. The value is passed to the network device as-is (the same value might not work on all devices).
8081
* **append**: Add communities to existing BGP communities
81-
* **delete**: Remove specified communities from the BGP route
82-
* **delete_list**: Remove communities matching the specified community list from the BGP route. Cannot be used with any other **set.community** parameters.
82+
83+
You can delete these route parameters:
84+
85+
* **community**: A dictionary that can be used to delete standard, large, or extended communities. The dictionary can also contain **list** element to delete all communities matching a BGP [community filter](generic-routing-community).
8386

8487
Routing policies are specified in the global- or node-level **routing.policy** dictionary (see [](routing-object-import) and [](routing-object-merge) for more details).
8588

@@ -156,12 +159,12 @@ Apart from setting BGP communities on BGP routes, these devices can execute addi
156159
| Cisco IOS/XE[^18v] || ✅❗️||
157160
| Cumulus Linux ||||
158161
| Dell OS10 ||||
159-
| Junos ||| |
162+
| Junos ||| |
160163
| FRR || ✅❗️ ||
161164
| VyOS ||||
162165

163166
**Notes:**
164-
* _netlab_ is creating an internal BGP community list on FRR and Cisco IOS/XE to delete BGP communities specified with the **set.community.delete** routing policy parameter. This approach is currently limited to standard BGP communities.
167+
* _netlab_ is creating an internal BGP community list on FRR and Cisco IOS/XE to delete BGP communities specified with the **delete.community** routing policy parameter. This approach is currently limited to standard BGP communities.
165168

166169
### Shortcut Routing Policy Definitions
167170

netsim/ansible/templates/routing/_route_map_ios.j2

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ that use "industry standard" CLI (IOS, IOS-XE, FRR, Cumulus, Arista)
1515
Include OS-specific route map macros
1616
#}
1717
!
18+
{#
19+
This macro generates community set command across "industry standard CLI" devices
20+
#}
21+
{% macro common_community_element(community,action) %}
22+
{% set ckw = { 'standard': 'community', 'extended': 'extcommunity', 'large': 'large-community' } %}
23+
{% for kw in ('standard','extended','large') if kw in community %}
24+
set {{ ckw[kw] }} {{ community[kw]|join(' ') }}{{ action }}
25+
{% endfor %}
26+
{% endmacro %}
1827
{#
1928
This macro generates the elements of route-map entries common across all "industry standard CLI" devices
2029
#}
@@ -34,14 +43,13 @@ that use "industry standard" CLI (IOS, IOS-XE, FRR, Cumulus, Arista)
3443
{% endif %}
3544
{% if 'community' in p_entry.set %}
3645
{% set cset = p_entry.set.community %}
37-
{% set ckw = { 'standard': 'community', 'extended': 'extcommunity', 'large': 'large-community' } %}
38-
{% for kw in ('standard','extended','large') if kw in cset %}
39-
set {{ ckw[kw] }} {{ cset[kw]|join(' ') if cset[kw] is not string else cset[kw] }}{{
40-
' additive' if cset.append|default(False) }}{{
41-
' delete' if cset.delete|default(False) }}
42-
{% endfor %}
46+
{% set action = ' additive' if cset.append|default(False) else '' %}
47+
{{ common_community_element(cset,action) }}
4348
{% endif %}
4449
{% endif %}
50+
{% if p_entry.delete.community is defined %}
51+
{{ common_community_element(p_entry.delete.community,' delete') }}
52+
{% endif %}
4553
{% if 'match' in p_entry %}
4654
{% set ipkwd = 'ip' if match_af == 'ipv4' else 'ipv6' %}
4755
{% if 'prefix' in p_entry.match %}

netsim/ansible/templates/routing/_route_policy_junos.j2

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% endif %}
77
{%- endmacro %}
88

9-
{% macro community_set(comm,c_append,c_delete) -%}
9+
{% macro community_set(comm,c_append=False,c_delete=False) -%}
1010
{% if c_delete %}
1111
then community delete x_comm_del_{{ comm|replace(':', '_')|replace('.', '_') }};
1212
{% elif c_append %}
@@ -28,23 +28,30 @@
2828
{% if 'med' in p_entry.set %}
2929
then metric {{ p_entry.set.med }};
3030
{% endif %}
31-
{% if 'community' in p_entry.set %}
31+
{% if p_entry.set.community is defined %}
3232
{% set cset = p_entry.set.community %}
33-
{% for kw in ('standard','extended','large') if kw in cset %}
34-
{% if cset[kw] is not string %}
35-
{% for cur_com in cset[kw] %}
36-
{{ community_set(cur_com, cset.append|default(False), cset.delete|default(False)) }}
37-
{% endfor %}
38-
{% else %}
39-
{{ community_set(cset[kw], cset.append|default(False), cset.delete|default(False)) }}
40-
{% endif %}
33+
{% for kw in ('standard','extended','large') if kw in cset %}
34+
{% for cur_com in cset[kw] %}
35+
{{ community_set(cur_com,c_append=cset.append|default(False)) }}
4136
{% endfor %}
37+
{% endfor %}
4238
{% endif %}
43-
4439
{% if 'prepend' in p_entry.set %}
4540
{{ prepend_set(p_entry.set.prepend,bgp.as|string) }}
4641
{% endif %}
4742
{% endif %}
43+
{# - DELETE entries #}
44+
{% if p_entry.delete.community is defined %}
45+
{% set dset = p_entry.delete.community %}
46+
{% for kw in ('standard','extended','large') if kw in dset %}
47+
{% for cur_com in dset[kw] %}
48+
{{ community_set(cur_com,c_delete=True) }}
49+
{% endfor %}
50+
{% endfor %}
51+
{% if dset.list is defined %}
52+
then community delete {{ dset.list }};
53+
{% endif %}
54+
{% endif %}
4855
{# - MATCH entries #}
4956
{% if 'match' in p_entry %}
5057
{% if 'prefix' in p_entry.match %}

netsim/ansible/templates/routing/dellos10.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
{% if routing.prefix|default({}) %}
99
{% include '_prefix_list_ios.j2' %}
1010
{% endif %}
11+
{% if routing.aspath|default({}) %}
1112
!
1213
! AS-path access lists
1314
!
14-
{% if routing.aspath|default({}) %}
1515
{% for asp_name,asp_list in routing.aspath.items() %}
1616
!
1717
{% for asp_line in asp_list %}
@@ -28,10 +28,12 @@ ip community-list standard {{ c_name }} {{ c_line.action }} {{ c_line._value }}
2828
{% endfor %}
2929
{% endfor %}
3030
{% endif %}
31+
{% for sr_data in routing.static|default([]) %}
32+
{% if loop.first %}
3133
!
3234
! Static routes (dual routes for each entry, in entry VRF and next hop VRF)
3335
!
34-
{% for sr_data in routing.static|default([]) %}
36+
{% endif %}
3537
{% set _vrf = sr_data.vrf|default(None) %}
3638
{% set _vrf_str = 'vrf ' + _vrf + ' ' if _vrf else '' %}
3739
{% set _nh_vrf = sr_data.nexthop.vrf|default(None) %}

netsim/ansible/templates/routing/eos.j2

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
!
44
{% if routing.policy|default({}) %}
55
{% call(p_entry,af_list) routemap.create_route_maps(routing.policy) -%}
6-
{% if 'bandwidth' in p_entry.set|default({}) %}
6+
{% if p_entry.set.bandwidth is defined %}
77
set extcommunity lbw {{ p_entry.set.bandwidth }}M
88
{% endif %}
9-
{% if p_entry.set.community.delete_list|default(False) %}
10-
set community community-list {{ p_entry.set.community.delete_list }} delete
9+
{% if p_entry.delete.community.list is defined %}
10+
set community community-list {{ p_entry.delete.community.list }} delete
1111
{% endif %}
1212
{{ routemap.common_route_map_entry(p_entry,af_list) }}
1313
{%- endcall %}
@@ -36,10 +36,10 @@ ipv6 prefix-list {{ p_name }}-ipv6
3636
{% endfor %}
3737
{% endfor %}
3838
{% endif %}
39+
{% if routing.aspath|default({}) %}
3940
!
4041
! AS-path access lists
4142
!
42-
{% if routing.aspath|default({}) %}
4343
ip as-path regex-mode string
4444
{% for asp_name,asp_list in routing.aspath.items() %}
4545
!
@@ -56,10 +56,12 @@ ip community-list {{ c_value.regexp }} {{ c_name }} {{ c_line.action }} {{ c_lin
5656
{% endfor %}
5757
{% endfor %}
5858
{% endif %}
59+
{% for sr_data in routing.static|default([]) %}
60+
{% if loop.first %}
5961
!
6062
! Static routes
6163
!
62-
{% for sr_data in routing.static|default([]) %}
64+
{% endif %}
6365
{% for sr_af in ['ipv4','ipv6'] if sr_af in sr_data %}
6466
{% set cmd_af = 'ip' if sr_af == 'ipv4' else sr_af %}
6567
{% set cmd_vrf = 'vrf ' + sr_data.vrf + ' ' if 'vrf' in sr_data else '' %}

netsim/ansible/templates/routing/frr.j2

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
!
33
{% if routing.policy|default({}) %}
44
{% call(p_entry,af_list) routemap.create_route_maps(routing.policy) -%}
5-
{% if 'set' in p_entry %}
6-
{% if 'bandwidth' in p_entry.set %}
5+
{% if p_entry.set.bandwidth is defined %}
76
set extcommunity bandwidth {{ p_entry.set.bandwidth }}
8-
{% endif %}
9-
{% if p_entry.set.community.delete_list|default(False) %}
10-
set comm-list {{ p_entry.set.community.delete_list }} delete
11-
{% endif %}
7+
{% endif %}
8+
{% if p_entry.delete.community.list is defined %}
9+
set comm-list {{ p_entry.delete.community.list }} delete
1210
{% endif %}
1311
{{ routemap.common_route_map_entry(p_entry,af_list) }}
1412
{%- endcall %}

netsim/ansible/templates/routing/ios.j2

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
!
33
{% if routing.policy|default({}) %}
44
{% call(p_entry,af_list) routemap.create_route_maps(routing.policy) -%}
5-
{% if p_entry.set.community.delete_list|default(False) %}
6-
set comm-list {{ p_entry.set.community.delete_list }} delete
5+
{% if p_entry.delete.community.list is defined %}
6+
set comm-list {{ p_entry.delete.community.list }} delete
77
{% endif %}
88
{{ routemap.common_route_map_entry(p_entry,af_list) }}
99
{%- endcall %}
1010
{% endif %}
1111
{% if routing.prefix|default({}) %}
1212
{% include '_prefix_list_ios.j2' %}
1313
{% endif %}
14+
{% if routing.aspath|default({}) %}
1415
!
1516
! AS-path access lists
1617
!
17-
{% if routing.aspath|default({}) %}
1818
{% for asp_name,asp_list in routing.aspath.items() %}
1919
!
2020
{% for asp_line in asp_list %}
@@ -30,10 +30,12 @@ ip community-list {{ c_value.type }} {{ c_name }} {{ c_line.action }} {{ c_line.
3030
{% endfor %}
3131
{% endfor %}
3232
{% endif %}
33+
{% for sr_data in routing.static|default([]) %}
34+
{% if loop.first %}
3335
!
3436
! Static routes
3537
!
36-
{% for sr_data in routing.static|default([]) %}
38+
{% endif %}
3739
{% set cmd_vrf = 'vrf ' + sr_data.vrf + ' ' if 'vrf' in sr_data else '' %}
3840
{% set cmd_intf = sr_data.nexthop.intf + ' ' if 'intf' in sr_data.nexthop else '' %}
3941
{% set leak_global = ' global' if sr_data.nexthop.vrf is defined and sr_data.nexthop.vrf is none else '' %}

netsim/devices/arubacx.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ features:
7676
prepend: True
7777
community:
7878
standard: True
79-
delete: True
8079
append: True
80+
delete:
81+
community:
82+
standard: True
8183
match: [ prefix, nexthop, aspath, community ]
8284
prefix: True
8385
aspath: True

netsim/devices/dellos10.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ features:
5555
large: False
5656
extended: True
5757
append: True
58-
delete: False
58+
delete.community: False
5959
prefix: True
6060
static:
6161
vrf: True

netsim/devices/eos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ features:
9090
policy:
9191
set: [ locpref, med, weight, prepend, community ]
9292
match: [ prefix, nexthop, aspath, community ]
93+
delete:
94+
community: True
9395
prefix: True
9496
aspath: True
9597
community:

0 commit comments

Comments
 (0)