mirror of
https://github.com/quantum5/bird-filter.git
synced 2025-04-24 09:01:57 -04:00
24 lines
607 B
Python
24 lines
607 B
Python
from aspa.data import ASPA
|
|
|
|
|
|
def generate_bird(aspas: list[ASPA]) -> str:
|
|
lines = [
|
|
'function is_aspa_invalid_pair(int upstream_asn; int downstream_asn) {',
|
|
' case downstream_asn {'
|
|
]
|
|
|
|
for aspa in aspas:
|
|
if aspa.providers:
|
|
asns = ', '.join(map(str, aspa.providers))
|
|
lines.append(f' {aspa.customer}: if upstream_asn !~ [{asns}] then return true;')
|
|
else:
|
|
lines.append(f' {aspa.customer}: return true;')
|
|
|
|
lines += [
|
|
' }',
|
|
' return false;',
|
|
'}'
|
|
]
|
|
|
|
return '\n'.join(lines)
|