Skip to content

Commit 5273237

Browse files
committed
use new juniper as-list syntax
1 parent bdbbe24 commit 5273237

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

wanda/as_filter/as_filter.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def get_filter_lists(self, enable_extended_filters=False):
6262
policy-statement POLICY_AS{self.autos.asn}_V4 {{
6363
term FILTER_LISTS {{
6464
from {{
65-
as-path-group AS{self.autos.asn};
65+
as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR;
66+
as-path-origins as-list-group AS{self.autos.asn}_ORIGINS;
6667
prefix-list-filter AS{self.autos.asn}_V4 orlonger;
6768
}}
6869
then next policy;
@@ -73,7 +74,8 @@ def get_filter_lists(self, enable_extended_filters=False):
7374
policy-statement POLICY_AS{self.autos.asn}_V6 {{
7475
term FILTER_LISTS {{
7576
from {{
76-
as-path-group AS{self.autos.asn};
77+
as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR;
78+
as-path-origins as-list-group AS{self.autos.asn}_ORIGINS;
7779
prefix-list-filter AS{self.autos.asn}_V6 orlonger;
7880
}}
7981
then next policy;
@@ -85,15 +87,21 @@ def get_filter_lists(self, enable_extended_filters=False):
8587
file_content += f"""
8688
policy-statement POLICY_AS{self.autos.asn}_V4 {{
8789
term IMPORT_AS_PATHS {{
88-
from as-path-group AS{self.autos.asn};
90+
from {{
91+
as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR;
92+
as-path-origins as-list-group AS{self.autos.asn}_ORIGINS;
93+
}}
8994
then next policy;
9095
}}
9196
then reject;
9297
}}
9398
9499
policy-statement POLICY_AS{self.autos.asn}_V6 {{
95100
term IMPORT_AS_PATHS {{
96-
from as-path-group AS{self.autos.asn};
101+
from {{
102+
as-path-neighbors as-list AS{self.autos.asn}_NEIGHBOR;
103+
as-path-origins as-list-group AS{self.autos.asn}_ORIGINS;
104+
}}
97105
then next policy;
98106
}}
99107
then reject;

wanda/irrd_client.py

+3-25
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,14 @@ def call_subprocess(self, command_array):
3131
raise Exception("bgpq4 could not be called successfully, this may be an programming error or a bad internet connection.")
3232

3333
def call_bgpq4_aspath_access_list(self, asn, irr_name):
34-
command_array = ["bgpq4", *self.host_params, "-f", str(asn), "-W 100", "-J", "-l", f"AS{asn}", irr_name]
34+
command_array = ["bgpq4", *self.host_params, "-H", str(asn), "-W 100", "-J", "-l", f"AS{asn}_ORIGINS", irr_name]
3535
return self.call_subprocess(command_array)
3636

3737
def generate_input_aspath_access_list(self, asn, irr_name):
3838
# bgpq4 AS-TELIANET-V6 -f 1299 -W 100 -J -l AS1299
3939
result_str = self.call_bgpq4_aspath_access_list(asn, irr_name)
40-
m = re.search(r'.*as-path-group.*{(.|\n)*?}', result_str)
41-
42-
if m:
43-
# Technically, returning m[0] would work, but we do some cleaning for better quality of the generated configuration
44-
45-
lines = m[0].split("\n")
46-
new_lines = list()
47-
indent_count = 0
48-
49-
for line in lines:
50-
line_without_prefixed_spaces = line.lstrip()
51-
52-
if '}' in line_without_prefixed_spaces:
53-
indent_count -= 1
54-
55-
spaces = [" " for _ in range(indent_count * 4)]
56-
new_lines.append("".join(spaces) + line_without_prefixed_spaces)
57-
58-
if '{' in line_without_prefixed_spaces:
59-
indent_count += 1
60-
61-
return "\n".join(new_lines)
62-
63-
return None
40+
m = re.search(r'.*as-list-group.*{(.|\n)*?}', result_str)
41+
return f"as-list AS{asn}_NEIGHBOR members {asn};\n" + m[0]
6442

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

0 commit comments

Comments
 (0)