fix: Correct SCION AS to decimal conversion logic

- Remove incorrect ISD:AS:Instance interpretation
- SCION AS format is three 16-bit hex values (48-bit total)
- Only convert to decimal if result is within BGP range (0 to 2^32-1)
- Example: 0:1:f = (0<<32) + (1<<16) + 15 = 65551
- AS numbers like 2:0:17 exceed BGP range and remain in hex format
This commit is contained in:
Olaf Baumert
2025-06-03 11:08:16 +00:00
parent 7f548110ff
commit eeb538bcde
2 changed files with 26 additions and 44 deletions

35
add-as
View File

@@ -7,39 +7,30 @@ import json
# Function to convert SCION AS to decimal if in BGP range
def scion_as_to_decimal(as_id):
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)"""
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)
SCION AS format uses 16-bit : separated lowercase hex encoding.
Examples:
- 0:0:0 -> 0
- 0:1:f -> 65551
- 2:2:0 -> 131584
"""
# Handle plain decimal AS numbers
if ':' not in as_id:
return as_id
# Parse SCION format
# Parse SCION AS format (colon-separated hex values)
parts = as_id.split(':')
# Check if this looks like ISD:AS:Instance format (first part is single digit ISD)
if len(parts) == 3 and len(parts[0]) == 1 and parts[0].isdigit():
# ISD:AS:Instance format - convert the AS part (middle) and instance (last)
try:
# AS is 16-bit hex, instance is 16-bit hex
# Combine them as 32-bit number: AS << 16 | Instance
as_num = int(parts[1], 16)
instance = int(parts[2], 16)
total = (as_num << 16) | instance
if 0 <= total <= 0xFFFFFFFF: # BGP AS range
return str(total)
except ValueError:
pass
return ""
# For standard colon-separated hex format (e.g., 0:1:f)
# Each part is up to 16 bits
# Convert hex parts to decimal
# Each part represents 16 bits, combine them into a single number
try:
total = 0
for part in parts:
total = (total << 16) + int(part, 16)
# Check if in BGP AS range
if 0 <= total <= 0xFFFFFFFF: # 2^32 - 1
# Check if in BGP AS range (0 to 2^32-1)
if 0 <= total <= 0xFFFFFFFF:
return str(total)
except ValueError:
pass

View File

@@ -12,39 +12,30 @@ os.system("mkdir -p db/as")
# Function to convert SCION AS to decimal if in BGP range
def scion_as_to_decimal(as_id):
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)"""
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)
SCION AS format uses 16-bit : separated lowercase hex encoding.
Examples:
- 0:0:0 -> 0
- 0:1:f -> 65551
- 2:2:0 -> 131584
"""
# Handle plain decimal AS numbers
if ':' not in as_id:
return as_id
# Parse SCION format
# Parse SCION AS format (colon-separated hex values)
parts = as_id.split(':')
# Check if this looks like ISD:AS:Instance format (first part is single digit ISD)
if len(parts) == 3 and len(parts[0]) == 1 and parts[0].isdigit():
# ISD:AS:Instance format - convert the AS part (middle) and instance (last)
try:
# AS is 16-bit hex, instance is 16-bit hex
# Combine them as 32-bit number: AS << 16 | Instance
as_num = int(parts[1], 16)
instance = int(parts[2], 16)
total = (as_num << 16) | instance
if 0 <= total <= 0xFFFFFFFF: # BGP AS range
return str(total)
except ValueError:
pass
return ""
# For standard colon-separated hex format (e.g., 0:1:f)
# Each part is up to 16 bits
# Convert hex parts to decimal
# Each part represents 16 bits, combine them into a single number
try:
total = 0
for part in parts:
total = (total << 16) + int(part, 16)
# Check if in BGP AS range
if 0 <= total <= 0xFFFFFFFF: # 2^32 - 1
# Check if in BGP AS range (0 to 2^32-1)
if 0 <= total <= 0xFFFFFFFF:
return str(total)
except ValueError:
pass