Skip to content

Commit d9aac23

Browse files
committed
Moved radian route-maps to msft general, Added config gen tests
Signed-off-by: Mukul Chodhary <70460358+Muckthebuck@users.noreply.github.com>
1 parent 7257a12 commit d9aac23

File tree

10 files changed

+128
-4
lines changed

10 files changed

+128
-4
lines changed

dockers/docker-fpm-frr/frr/bgpd/templates/voq_chassis/policies.conf.j2

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!
22
! template: bgpd/templates/voq_chassis/policies.conf.j2
33
!
4+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.local_anchor_route_community }}
45
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit {{ constants.bgp.internal_community }}
56
bgp community-list standard DEVICE_INTERNAL_FALLBACK_COMMUNITY permit {{ constants.bgp.internal_fallback_community }}
67
bgp community-list standard NO_EXPORT permit no-export
@@ -31,6 +32,9 @@ route-map TO_VOQ_CHASSIS_V4_PEER permit 1
3132
match ip address prefix-list PL_LoopbackV4
3233
set community {{ constants.bgp.internal_community }}
3334
!
35+
route-map TO_VOQ_CHASSIS_V4_PEER deny 15
36+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
37+
!
3438
route-map TO_VOQ_CHASSIS_V4_PEER permit 100
3539
!
3640
route-map FROM_VOQ_CHASSIS_V6_PEER permit 1
@@ -63,6 +67,9 @@ route-map TO_VOQ_CHASSIS_V6_PEER permit 1
6367
match ipv6 address prefix-list PL_LoopbackV6
6468
set community {{ constants.bgp.internal_community }}
6569
!
70+
route-map TO_VOQ_CHASSIS_V6_PEER deny 15
71+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
72+
!
6673
route-map TO_VOQ_CHASSIS_V6_PEER permit 100
6774
!
6875
! end of template: bgpd/templates/voq_chassis/policies.conf.j2

files/image_config/constants/constants.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ constants:
88
internal_fallback_community: 22222:22222
99
sentinel_community: 12345:12346
1010
internal_community_match_tag: 201
11+
local_anchor_route_community: 12345:555
1112
route_do_not_send_appdb_tag: 202
1213
route_eligible_for_fallback_to_default_tag: 203
1314
families:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 48
2+
router bgp 1234
3+
address-family ipv6 unicast
4+
aggregate-address ffff::/64 route-map TAG_ANCHOR_COMMUNITY
5+
exit
6+
exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"ipv": "ipv6",
4+
"prefix": "ffff::/64",
5+
"bgp_asn": 1234
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
no ipv6 prefix-list ANCHOR_CONTRIBUTING_ROUTES permit ffff::/64 ge 48
2+
router bgp 1234
3+
address-family ipv6 unicast
4+
no aggregate-address ffff::/64 route-map TAG_ANCHOR_COMMUNITY
5+
exit
6+
exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"ipv": "ipv6",
4+
"prefix": "ffff::/64",
5+
"bgp_asn": 1234
6+
}
7+
}

src/sonic-bgpcfgd/tests/data/voq_chassis/policies.conf/param_base.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"localhost": {
44
"type": "SpineRouter",
55
"subtype": "DownstreamLC"
6-
}
6+
}
77
},
88
"constants": {
99
"bgp": {
1010
"internal_community": "12345:556",
11-
"internal_community_match_tag": "101",
11+
"internal_community_match_tag": "101",
1212
"route_eligible_for_fallback_to_default_tag": "203",
13-
"internal_fallback_community": "1111:2222"
13+
"internal_fallback_community": "1111:2222",
14+
"local_anchor_route_community": "12345:555"
1415
}
1516
}
1617
}

src/sonic-bgpcfgd/tests/data/voq_chassis/policies.conf/result_base.conf

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!
22
! template: bgpd/templates/voq_chassis/policies.conf.j2
33
!
4+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit 12345:555
45
bgp community-list standard DEVICE_INTERNAL_COMMUNITY permit 12345:556
56
bgp community-list standard DEVICE_INTERNAL_FALLBACK_COMMUNITY permit 1111:2222
67
bgp community-list standard NO_EXPORT permit no-export
@@ -26,6 +27,9 @@ route-map TO_VOQ_CHASSIS_V4_PEER permit 1
2627
match ip address prefix-list PL_LoopbackV4
2728
set community 12345:556
2829
!
30+
route-map TO_VOQ_CHASSIS_V4_PEER deny 15
31+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
32+
!
2933
route-map TO_VOQ_CHASSIS_V4_PEER permit 100
3034
!
3135
route-map FROM_VOQ_CHASSIS_V6_PEER permit 1
@@ -53,7 +57,10 @@ route-map TO_VOQ_CHASSIS_V6_PEER permit 1
5357
match ipv6 address prefix-list PL_LoopbackV6
5458
set community 12345:556
5559
!
60+
route-map TO_VOQ_CHASSIS_V6_PEER deny 15
61+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
62+
!
5663
route-map TO_VOQ_CHASSIS_V6_PEER permit 100
5764
!
5865
! end of template: bgpd/templates/voq_chassis/policies.conf.j2
59-
!
66+
!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
import os
4+
from bgpcfgd.directory import Directory
5+
from bgpcfgd.template import TemplateFabric
6+
from . import swsscommon_test
7+
from swsscommon import swsscommon
8+
9+
from bgpcfgd.managers_prefix_list import PrefixListMgr
10+
11+
TEMPLATE_PATH = os.path.abspath('../../dockers/docker-fpm-frr/frr')
12+
13+
def constructor():
14+
cfg_mgr = MagicMock()
15+
common_objs = {
16+
'directory': Directory(),
17+
'cfg_mgr': cfg_mgr,
18+
'tf': TemplateFabric(TEMPLATE_PATH),
19+
'constants': {},
20+
}
21+
22+
m = PrefixListMgr(common_objs, "CONFIG_DB", "PREFIX_LIST")
23+
m.directory.put("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost", {"bgp_asn": "65100", "type": "SpineRouter"})
24+
25+
return m
26+
27+
def set_handler_test(manager, key, value):
28+
res = manager.set_handler(key, value)
29+
assert res, "Returns always True"
30+
31+
def del_handler_test(manager, key):
32+
res = manager.del_handler(key)
33+
assert res, "Returns always True"
34+
35+
# test if the ipv4 radian configs are set correctly
36+
@patch('bgpcfgd.managers_prefix_list.log_debug')
37+
def test_generate_prefix_list_config_ipv4(mocked_log_debug):
38+
m = constructor()
39+
set_handler_test(m, "ANCHOR_PREFIX|192.168.0.0/24", {})
40+
mocked_log_debug.assert_called_with("PrefixListMgr:: Anchor prefix 192.168.0.0/24 added to radian configuration")
41+
42+
# test if the ipv6 radian configs are set correctly
43+
@patch('bgpcfgd.managers_prefix_list.log_debug')
44+
def test_generate_prefix_list_config_ipv6(mocked_log_debug):
45+
m = constructor()
46+
set_handler_test(m, "ANCHOR_PREFIX|fc02:100::/64", {})
47+
mocked_log_debug.assert_called_with("PrefixListMgr:: Anchor prefix fc02:100::/64 added to radian configuration")
48+
49+
# test if invalid prefix is handled correctly
50+
@patch('bgpcfgd.managers_prefix_list.log_warn')
51+
def test_generate_prefix_list_config_invalid_prefix(mocked_log_warn):
52+
m = constructor()
53+
set_handler_test(m, "ANCHOR_PREFIX|invalid_prefix", {})
54+
mocked_log_warn.assert_called_with("PrefixListMgr:: Prefix 'invalid_prefix' format is wrong for prefix list 'ANCHOR_PREFIX'")
55+
56+
# test if the ipv4 radian configs are deleted correctly
57+
@patch('bgpcfgd.managers_prefix_list.log_debug')
58+
def test_del_handler_ipv4(mocked_log_debug):
59+
m = constructor()
60+
set_handler_test(m, "ANCHOR_PREFIX|192.168.0.0/24", {})
61+
del_handler_test(m, "ANCHOR_PREFIX|192.168.0.0/24")
62+
mocked_log_debug.assert_called_with("PrefixListMgr:: Anchor prefix 192.168.0.0/24 removed from radian configuration")
63+
64+
# test if the ipv6 radian configs are deleted correctly
65+
@patch('bgpcfgd.managers_prefix_list.log_debug')
66+
def test_del_handler_ipv6(mocked_log_debug):
67+
m = constructor()
68+
set_handler_test(m, "ANCHOR_PREFIX|fc02:100::/64", {})
69+
del_handler_test(m, "ANCHOR_PREFIX|fc02:100::/64")
70+
mocked_log_debug.assert_called_with("PrefixListMgr:: Anchor prefix fc02:100::/64 removed from radian configuration")

src/sonic-bgpcfgd/tests/test_sonic-cfggen.py

+12
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,15 @@ def test_bgpd_main_conf_defaults_router_id():
206206
"bgpd/bgpd.main.conf.j2",
207207
"bgpd.main.conf.j2/defaults_router_id.json",
208208
"bgpd.main.conf.j2/defaults_router_id.conf")
209+
210+
def test_prefix_list_add_radian():
211+
run_test("Add radian configuration",
212+
"bgpd/radian/add_radian.conf.j2",
213+
"radian/add_radian.json",
214+
"radian/add_radian.conf")
215+
216+
def test_prefix_list_del_radian():
217+
run_test("Del radian configuration",
218+
"bgpd/radian/del_radian.conf.j2",
219+
"radian/del_radian.json",
220+
"radian/del_radian.conf")

0 commit comments

Comments
 (0)