Skip to content

Commit

Permalink
use new juniper as-list syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuyureka committed Sep 30, 2024
1 parent bdbbe24 commit 0ca10d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
16 changes: 12 additions & 4 deletions wanda/as_filter/as_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -85,15 +87,21 @@ 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;
}}
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;
Expand Down
9 changes: 5 additions & 4 deletions wanda/irrd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions wanda/tests/test_irrd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
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 ];
}
}
"""

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;
}
}
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0ca10d2

Please sign in to comment.