Skip to content
Snippets Groups Projects

Support ASN dot notation.

Merged Neda Moeini requested to merge feature/DBOARD3-719-support-extended-asn-notation into develop
All threads resolved!
2 files
+ 26
9
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -252,12 +252,25 @@ def asn_to_int(asn_string: str) -> int:
Returns:
int: ASN in integer format.
Raises:
ValueError: If the ASN string is not in the expected format or exceeds valid range.
"""
if '.' in asn_string:
high_order, low_order = map(int, asn_string.split('.'))
dotted_asn_pattern = re.compile(r'^(\d+)\.(\d+)$')
match = dotted_asn_pattern.match(asn_string)
if match:
high_order, low_order = map(int, match.groups())
if high_order > 0xffff or low_order > 0xffff:
raise ValueError(f'Invalid ASN format: {asn_string}. Both components must be <= 0xffff.')
return (high_order << 16) | low_order
else:
elif asn_string.isdigit():
return int(asn_string)
else:
raise ValueError(f'Unable to parse ASN string: {asn_string}. Expected either a pure integer or a dot notation.')
def _system_bgp_peers(system_node):
Loading