From 0ca10d22a069f5160637cc11b043ce2b83877363 Mon Sep 17 00:00:00 2001 From: Yureka Date: Mon, 30 Sep 2024 22:35:07 +0200 Subject: [PATCH] use new juniper as-list syntax --- wanda/as_filter/as_filter.py | 16 ++++++++++++---- wanda/irrd_client.py | 9 +++++---- wanda/tests/test_irrd_client.py | 14 +++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/wanda/as_filter/as_filter.py b/wanda/as_filter/as_filter.py index 62d052f..716fb50 100644 --- a/wanda/as_filter/as_filter.py +++ b/wanda/as_filter/as_filter.py @@ -62,7 +62,8 @@ def get_filter_lists(self, enable_extended_filters=False): policy-statement POLICY_AS{self.autos.asn}_V4 {{ term FILTER_LISTS {{ from {{ - as-path-group AS{self.autos.asn}; + as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR; + as-path-origins as-list-group AS{self.autos.asn}_ORIGINS; prefix-list-filter AS{self.autos.asn}_V4 orlonger; }} then next policy; @@ -73,7 +74,8 @@ def get_filter_lists(self, enable_extended_filters=False): policy-statement POLICY_AS{self.autos.asn}_V6 {{ term FILTER_LISTS {{ from {{ - as-path-group AS{self.autos.asn}; + as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR; + as-path-origins as-list-group AS{self.autos.asn}_ORIGINS; prefix-list-filter AS{self.autos.asn}_V6 orlonger; }} then next policy; @@ -85,7 +87,10 @@ def get_filter_lists(self, enable_extended_filters=False): file_content += f""" policy-statement POLICY_AS{self.autos.asn}_V4 {{ term IMPORT_AS_PATHS {{ - from as-path-group AS{self.autos.asn}; + from {{ + as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR; + as-path-origins as-list-group AS{self.autos.asn}_ORIGINS; + }} then next policy; }} then reject; @@ -93,7 +98,10 @@ def get_filter_lists(self, enable_extended_filters=False): policy-statement POLICY_AS{self.autos.asn}_V6 {{ term IMPORT_AS_PATHS {{ - from as-path-group AS{self.autos.asn}; + from {{ + as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR; + as-path-origins as-list-group AS{self.autos.asn}_ORIGINS; + }} then next policy; }} then reject; diff --git a/wanda/irrd_client.py b/wanda/irrd_client.py index 35c034a..74663c4 100644 --- a/wanda/irrd_client.py +++ b/wanda/irrd_client.py @@ -31,19 +31,20 @@ def call_subprocess(self, command_array): raise Exception("bgpq4 could not be called successfully, this may be an programming error or a bad internet connection.") def call_bgpq4_aspath_access_list(self, asn, irr_name): - command_array = ["bgpq4", *self.host_params, "-f", str(asn), "-W 100", "-J", "-l", f"AS{asn}", irr_name] + command_array = ["bgpq4", *self.host_params, "-H", str(asn), "-W 100", "-J", "-l", f"AS{asn}_ORIGINS", irr_name] return self.call_subprocess(command_array) def generate_input_aspath_access_list(self, asn, irr_name): - # bgpq4 AS-TELIANET-V6 -f 1299 -W 100 -J -l AS1299 + # bgpq4 AS-TELIANET-V6 -H 1299 -W 100 -J -l AS1299_ORIGINS result_str = self.call_bgpq4_aspath_access_list(asn, irr_name) - m = re.search(r'.*as-path-group.*{(.|\n)*?}', result_str) + m = re.search(r'.*as-list-group.*{(.|\n)*?}', result_str) if m: - # Technically, returning m[0] would work, but we do some cleaning for better quality of the generated configuration + # Technically, only adding the AS..._NEIGHBOR list would work, but we do some cleaning for better quality of the generated configuration lines = m[0].split("\n") new_lines = list() + new_lines.append(f"as-list AS{asn}_NEIGHBOR members {asn};") indent_count = 0 for line in lines: diff --git a/wanda/tests/test_irrd_client.py b/wanda/tests/test_irrd_client.py index 0196a04..7790de8 100644 --- a/wanda/tests/test_irrd_client.py +++ b/wanda/tests/test_irrd_client.py @@ -29,9 +29,9 @@ AS_PATH_WOBCOM = """ policy-options { replace: - as-path-group AS9136 { - as-path a0 "^9136(9136)*$"; - as-path a1 "^9136(.)*(112|248|250)$"; + as-list-group AS9136_ORIGINS { + as-list a0 members 9136; + as-list a1 members [ 112 248 250 3573 3624 6766 12654 12748 13020 13130 20488 21158 24679 24956 29670 31451 33940 34219 39788 41955 44194 44780 48387 48777 49009 49225 49745 49933 50017 50472 59568 59645 60729 60802 62028 64404 64475 197532 198824 200490 201173 201567 201701 202329 204867 204911 205597 206236 206313 206356 206506 206554 206618 206740 206813 206946 207180 207592 207871 207921 208135 208183 208230 208395 208633 208727 208772 208893 208942 209347 209530 209894 210909 210916 211286 211479 212488 212520 212989 213027 213097 213106 213341 215236 215250 216188 216355 216441 396507 ]; } } """ @@ -39,8 +39,8 @@ AS_PATH_WDZ = """ policy-options { replace: - as-path-group AS208395 { - as-path a0 "^208395(208395)*$"; + as-list-group AS208395_ORIGINS { + as-list a0 members 208395; } } """ @@ -101,10 +101,10 @@ def test_input_as_path_access_list(self, mocker, irrd_instance, irr_name, asn, a assert "policy-options" not in access_list assert "replace:" not in access_list - assert access_list.startswith(f"as-path-group AS{asn} {{\n") + assert access_list.startswith(f"as-list AS{asn}_NEIGHBOR members {asn};\nas-list-group AS{asn}_ORIGINS {{\n") assert access_list.endswith(f"\n}}") - assert f"as-path a0 \"^{asn}({asn})*$\";" in access_list + assert f"as-list a0 members {asn};" in access_list def test_invalid_bgpq4_prefix_lists(self, irrd_instance): with pytest.raises(Exception):