mirror of
https://github.com/quantum5/bird-filter.git
synced 2025-04-24 00:51:57 -04:00
Add script to generate is_aspa_invalid_pair for bird
This commit is contained in:
parent
a1dd233e78
commit
8395181020
30
aspa/generate.py
Normal file
30
aspa/generate.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
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)
|
21
make-bird-aspa
Executable file
21
make-bird-aspa
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
|
||||
from aspa.data import parse_json
|
||||
from aspa.generate import generate_bird
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Generates is_aspa_invalid_pair function for bird')
|
||||
parser.add_argument('aspa_json', type=str, help='the JSON file with ASPA data')
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.aspa_json) as f:
|
||||
aspas = parse_json(f.read())
|
||||
|
||||
print(generate_bird(aspas))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue