Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support BGP ASNs in local topologies #4665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tools/topology/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def generate_all(self):
Generate all needed files.
"""
self._ensure_uniq_ases()
self._canonicalize_isd_asns()
topo_dicts, self.all_networks = self._generate_topology()
self.networks = remove_v4_nets(self.all_networks)
self._generate_with_topo(topo_dicts)
Expand All @@ -110,6 +111,12 @@ def _ensure_uniq_ases(self):
sys.exit(1)
seen.add(ia.as_str())

def _canonicalize_isd_asns(self):
canonicalized = {}
for asStr, value in self.topo_config["ASes"].items():
canonicalized[str(ISD_AS(asStr))] = value
self.topo_config["ASes"] = canonicalized

def _generate_with_topo(self, topo_dicts):
self._generate_go(topo_dicts)
if self.args.docker:
Expand Down
27 changes: 18 additions & 9 deletions tools/topology/scion_addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ def __hash__(self):
return hash(str(self))


# Regex matching ISD-AS (hex form), with either : or _ as hex-part separator
# Regex matching ISD-AS (hex or decimal form), with either : or _ as hex-part separator
_RE_ISD_AS = re.compile(
r"^([1-9][0-9]{0,4})-([0-9a-fA-F]{1,4})[:_]([0-9a-fA-F]{1,4})[:_]([0-9a-fA-F]{1,4})$"
r"^([1-9][0-9]{0,4})-([0-9a-fA-F]{1,4})[:_]([0-9a-fA-F]{1,4})[:_]([0-9a-fA-F]{1,4})" +
r"|([1-9][0-9]{0,4})-([1-9][0-9]{1,9})$"
)


def _clean_isd_as(isd_as_str):
"""
Parse an ISD-AS-identifier and return the "canonical" string representation.

Note that the short form for decimal BGP AS numbers is not supported here.

:param str as_id_str: AS-identifier to parse
:returns: AS-identifier as integer
:raises:
Expand All @@ -75,10 +74,20 @@ def _clean_isd_as(isd_as_str):
m = _RE_ISD_AS.match(isd_as_str)
if not m:
raise ValueError('Invalid ISD-AS', isd_as_str)
isd = int(m.group(1), 10)
if m.group(1) is not None:
isd = int(m.group(1), 10)
hig = int(m.group(2), 16)
mid = int(m.group(3), 16)
low = int(m.group(4), 16)
asn = (hig << 32) | (mid << 16) | low
else:
isd = int(m.group(5), 10)
asn = int(m.group(6), 10)
if asn >= 2**32:
ValueError('Invalid ISD-AS, ASN out of range', isd_as_str)
if isd >= 2**16:
raise ValueError('Invalid ISD-AS, ISD out of range', isd_as_str)
hig = int(m.group(2), 16)
mid = int(m.group(3), 16)
low = int(m.group(4), 16)
return "%i-%x:%x:%x" % (isd, hig, mid, low)
if asn < 2**32:
return "%i-%d" % (isd, asn)
else:
return "%i-%x:%x:%x" % (isd, hig, mid, low)