mirror of
https://github.com/quantum5/bird-filter.git
synced 2025-04-24 00:51:57 -04:00
Add version of ASPA validation restricted to bird DSL powers
This commit is contained in:
parent
bb1e610025
commit
1de62619c6
14
aspa/test.py
14
aspa/test.py
|
@ -2,7 +2,7 @@ import unittest
|
|||
from pathlib import Path
|
||||
|
||||
from aspa.data import ASPA, parse_json
|
||||
from aspa.validate import Validator
|
||||
from aspa.validate import BirdValidator, Validator
|
||||
|
||||
|
||||
class ParserTest(unittest.TestCase):
|
||||
|
@ -158,5 +158,17 @@ class UpstreamTest(unittest.TestCase):
|
|||
self.assertTrue(self.validator.is_aspa_invalid_upstream(64531, [64521, 64521, 64514, 64520, 64530]))
|
||||
|
||||
|
||||
class BirdCustomerTest(CustomerTest):
|
||||
validator_class = BirdValidator
|
||||
|
||||
|
||||
class BirdPeerTest(PeerTest):
|
||||
validator_class = BirdValidator
|
||||
|
||||
|
||||
class BirdUpstreamTest(UpstreamTest):
|
||||
validator_class = BirdValidator
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -51,3 +51,46 @@ class Validator:
|
|||
min_down_ramp = max(min_down_ramp, i)
|
||||
|
||||
return min_down_ramp > max_up_ramp
|
||||
|
||||
|
||||
class BirdValidator(Validator):
|
||||
"""Validator coded with only language features available in bird DSL."""
|
||||
|
||||
def is_aspa_invalid_customer(self, my_asn: int, bgp_path: list[int]) -> bool:
|
||||
prev_asn = my_asn
|
||||
|
||||
for asn in bgp_path:
|
||||
if prev_asn != asn and self.is_invalid_pair(prev_asn, asn):
|
||||
return True
|
||||
prev_asn = asn
|
||||
|
||||
return False
|
||||
|
||||
def is_aspa_invalid_peer(self, peer_asn: int, bgp_path: list[int]) -> bool:
|
||||
prev_asn = peer_asn
|
||||
|
||||
for asn in bgp_path:
|
||||
if asn != peer_asn and prev_asn != asn and self.is_invalid_pair(prev_asn, asn):
|
||||
return True
|
||||
prev_asn = asn
|
||||
|
||||
return False
|
||||
|
||||
def is_aspa_invalid_upstream(self, my_asn: int, bgp_path: list[int]) -> bool:
|
||||
prev_asn = my_asn
|
||||
max_up_ramp = len(bgp_path)
|
||||
min_down_ramp = 0
|
||||
i = 0
|
||||
|
||||
for asn in bgp_path:
|
||||
if prev_asn != asn:
|
||||
if self.is_invalid_pair(asn, prev_asn) and max_up_ramp > i:
|
||||
max_up_ramp = i
|
||||
|
||||
if self.is_invalid_pair(prev_asn, asn) and min_down_ramp < i:
|
||||
min_down_ramp = i
|
||||
|
||||
prev_asn = asn
|
||||
i += 1
|
||||
|
||||
return min_down_ramp > max_up_ramp
|
||||
|
|
Loading…
Reference in a new issue