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
yu-re-ka committed Sep 30, 2024
1 parent bdbbe24 commit 5273237
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 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
28 changes: 3 additions & 25 deletions wanda/irrd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,14 @@ 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
result_str = self.call_bgpq4_aspath_access_list(asn, irr_name)
m = re.search(r'.*as-path-group.*{(.|\n)*?}', result_str)

if m:
# Technically, returning m[0] would work, but we do some cleaning for better quality of the generated configuration

lines = m[0].split("\n")
new_lines = list()
indent_count = 0

for line in lines:
line_without_prefixed_spaces = line.lstrip()

if '}' in line_without_prefixed_spaces:
indent_count -= 1

spaces = [" " for _ in range(indent_count * 4)]
new_lines.append("".join(spaces) + line_without_prefixed_spaces)

if '{' in line_without_prefixed_spaces:
indent_count += 1

return "\n".join(new_lines)

return None
m = re.search(r'.*as-list-group.*{(.|\n)*?}', result_str)
return f"as-list AS{asn}_NEIGHBOR members {asn};\n" + m[0]

def call_bgpq4_prefix_lists(self, irr_name, ip_version):
command_array = ["bgpq4", *self.host_params, f"-{ip_version}", "-F", "%n/%l\n", irr_name]
Expand Down

0 comments on commit 5273237

Please sign in to comment.