From a9f2a78753c0f9f76aa594b3770b2635e8a863dd Mon Sep 17 00:00:00 2001 From: Giovanni Barbiero <38290406+GioBar00@users.noreply.github.com> Date: Wed, 29 May 2024 18:06:50 +0000 Subject: [PATCH] tools: Fix topogen network argument, added network-v6 argument, moved default network defines from net.py to defines.py for consistency --- tools/topogen.py | 4 +++- tools/topology/config.py | 10 ++++++---- tools/topology/defines.py | 5 +++++ tools/topology/net.py | 6 +----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/topogen.py b/tools/topogen.py index 33bbb68c03..8bd1a349b2 100755 --- a/tools/topogen.py +++ b/tools/topogen.py @@ -37,7 +37,9 @@ def add_arguments(parser): parser.add_argument('-d', '--docker', action='store_true', help='Create a docker compose configuration') parser.add_argument('-n', '--network', - help='Network to create subnets in (E.g. "127.0.0.0/8"') + help='IPv4 network to create subnets in (E.g. "127.0.0.0/8"') + parser.add_argument('-n6', '--network-v6', + help='IPv6 network to create subnets in (E.g. "fd00:f00d:cafe::7f00:0000/104"') parser.add_argument('-o', '--output-dir', default=GEN_PATH, help='Output directory') parser.add_argument('--random-ifids', action='store_true', diff --git a/tools/topology/config.py b/tools/topology/config.py index fffff91be5..b5af6a6960 100644 --- a/tools/topology/config.py +++ b/tools/topology/config.py @@ -76,15 +76,17 @@ def __init__(self, args): logging.critical("Cannot use sig without docker!") sys.exit(1) self.default_mtu = None - self._read_defaults(self.args.network) + self._read_defaults() - def _read_defaults(self, network): + def _read_defaults(self): """ Configure default network. """ defaults = self.topo_config.get("defaults", {}) - self.subnet_gen4 = SubnetGenerator(DEFAULT_NETWORK, self.args.docker) - self.subnet_gen6 = SubnetGenerator(DEFAULT6_NETWORK, self.args.docker) + self.subnet_gen4 = SubnetGenerator(self.args.network, self.args.docker) \ + if self.args.network else SubnetGenerator(DEFAULT_NETWORK, self.args.docker) + self.subnet_gen6 = SubnetGenerator(self.args.network_v6, self.args.docker) \ + if self.args.network_v6 else SubnetGenerator(DEFAULT6_NETWORK, self.args.docker) self.default_mtu = defaults.get("mtu", DEFAULT_MTU) self.dispatched_ports = defaults.get("dispatched_ports", DEFAULT_DISPATCHED_PORTS) diff --git a/tools/topology/defines.py b/tools/topology/defines.py index f5c9b3bdf2..7f4f28da70 100644 --- a/tools/topology/defines.py +++ b/tools/topology/defines.py @@ -40,6 +40,11 @@ #: IPv6 min value SCION_MIN_MTU = 1280 +# Default IPv4 network +DEFAULT_NETWORK = "127.0.0.0/8" +DEFAULT_PRIV_NETWORK = "192.168.0.0/16" +DEFAULT_SCN_DC_NETWORK = "172.20.0.0/20" + # Default IPv6 network, our equivalent to 127.0.0.0/8 # https://en.wikipedia.org/wiki/Unique_local_address#Definition DEFAULT6_MASK = "/104" diff --git a/tools/topology/net.py b/tools/topology/net.py index 7ac4aa4135..139d1b27e6 100644 --- a/tools/topology/net.py +++ b/tools/topology/net.py @@ -37,11 +37,7 @@ import yaml # SCION -from topology.defines import DEFAULT6_NETWORK_ADDR - -DEFAULT_NETWORK = "127.0.0.0/8" -DEFAULT_PRIV_NETWORK = "192.168.0.0/16" -DEFAULT_SCN_DC_NETWORK = "172.20.0.0/20" +from topology.defines import DEFAULT_NETWORK, DEFAULT_SCN_DC_NETWORK, DEFAULT6_NETWORK_ADDR IPAddress = Union[IPv4Address, IPv6Address] IPNetwork = Union[IPv4Network, IPv6Network]