mirror of
https://github.com/quantum5/bird-filter.git
synced 2025-04-24 09:01:57 -04:00
31 lines
733 B
Python
31 lines
733 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 not aspa.providers:
|
||
|
lines.append(f' {aspa.customer}: return true;')
|
||
|
continue
|
||
|
|
||
|
lines.append(f' {aspa.customer}: case upstream_asn {{')
|
||
|
for provider in aspa.providers:
|
||
|
lines.append(f' {provider}: {{}}')
|
||
|
|
||
|
lines += [
|
||
|
' else: return true;',
|
||
|
' }'
|
||
|
]
|
||
|
|
||
|
lines += [
|
||
|
' }',
|
||
|
' return false;',
|
||
|
'}'
|
||
|
]
|
||
|
|
||
|
return '\n'.join(lines)
|