Skip to content

Commit bfba92f

Browse files
committed
munet: add loopbacks-autonumber config remove by default
- The previous release included a NBC change that was auton-umbering loopback interfaces if the user configured `networks-autonumber: true`. Change this using a new `loopbacks-autonumber` config instead. Signed-off-by: Christian Hopps <chopps@labn.net>
1 parent 8bbbd4f commit bfba92f

File tree

8 files changed

+45
-16
lines changed

8 files changed

+45
-16
lines changed

README.org

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module: labn-munet-config
126126
| +--rw dns-network? -> ../networks/name
127127
| +--rw ipv6-enable? boolean
128128
| +--rw networks-autonumber? boolean
129+
| +--rw loopbacks-autonumber? boolean
129130
| +--rw initial-setup-cmd? string
130131
| +--rw initial-setup-host-cmd? string
131132
| +--rw networks* [name]
@@ -1084,11 +1085,20 @@ munet>
10841085

10851086
leaf networks-autonumber {
10861087
type boolean;
1088+
default false;
10871089
description
10881090
"Controls if networks and node connections are given IP addresses if
10891091
not explicitly configured.";
10901092
}
10911093

1094+
leaf loopbacks-autonumber {
1095+
type boolean;
1096+
default false;
1097+
description
1098+
"Controls if loopbacks are given IP addresses if not explicitly
1099+
configured.";
1100+
}
1101+
10921102
leaf initial-setup-cmd {
10931103
type string;
10941104
description

doc/source/config.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ along with a few global topology options.
8484
Tree diagram for topology config::
8585

8686
+--rw topology
87-
| +--rw dns-network? -> ../networks/name
88-
| +--rw ipv6-enable? boolean
89-
| +--rw networks-autonumber? boolean
87+
| +--rw dns-network? -> ../networks/name
88+
| +--rw ipv6-enable? boolean
89+
| +--rw networks-autonumber? boolean
90+
| +--rw loopbacks-autonumber? boolean
91+
| +--rw initial-setup-cmd? string
92+
| +--rw initial-setup-host-cmd? string
9093
| +--rw networks* [name]
9194
| ... described in subsection
9295
| +--rw nodes* [name]

munet/munet-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@
400400
"networks-autonumber": {
401401
"type": "boolean"
402402
},
403+
"loopbacks-autonumber": {
404+
"type": "boolean"
405+
},
403406
"initial-setup-cmd": {
404407
"type": "string"
405408
},

munet/native.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
from .watchlog import WatchLog
5656

5757

58+
AUTO_LOOPBACK_IPV4_BASE = ipaddress.ip_interface("10.255.0.0/32")
59+
AUTO_LOOPBACK_IPV6_BASE = ipaddress.ip_interface("fcfe::0/128")
60+
61+
5862
class L3ContainerNotRunningError(MunetError):
5963
"""Exception if no running container exists."""
6064

@@ -63,16 +67,14 @@ def get_loopback_ips(c, nid):
6367
ips = []
6468
if ip := c.get("ip"):
6569
if ip == "auto":
66-
assert nid < 0xFFFF # Limited to 10.255.0.0/16 block
67-
ips.append(ipaddress.ip_interface("10.255.0.0/32") + nid)
70+
ips.append(AUTO_LOOPBACK_IPV4_BASE + nid)
6871
elif isinstance(ip, str):
6972
ips.append(ipaddress.ip_interface(ip))
7073
else:
7174
ips.extend([ipaddress.ip_interface(x) for x in ip])
7275
if ipv6 := c.get("ipv6"):
7376
if ipv6 == "auto":
74-
assert nid < 0xFFFF # Same limit as ipv4 for simplicity
75-
ips.append(ipaddress.ip_interface(f"fcfe:ffff:{nid:02x}::1/128"))
77+
ips.append(AUTO_LOOPBACK_IPV6_BASE + nid)
7678
elif isinstance(ip, str):
7779
ips.append(ipaddress.ip_interface(ipv6))
7880
else:
@@ -797,9 +799,13 @@ def __init__(self, *args, unet=None, **kwargs):
797799
)
798800
self.next_p2p_network6 = ipaddress.ip_network(f"fcff:ffff:{self.id:02x}::/127")
799801

800-
if "ip" not in self.config and self.unet.autonumber:
802+
if "ip" not in self.config and self.unet.autonumber_loopbacks:
801803
self.config["ip"] = "auto"
802-
if "ipv6" not in self.config and self.unet.autonumber and self.unet.ipv6_enable:
804+
if (
805+
"ipv6" not in self.config
806+
and self.unet.autonumber_loopbacks
807+
and self.unet.ipv6_enable
808+
):
803809
self.config["ipv6"] = "auto"
804810
self.loopback_ip = None
805811
self.loopback_ips = get_loopback_ips(self.config, self.id)
@@ -3304,6 +3310,14 @@ def autonumber(self):
33043310
def autonumber(self, value):
33053311
self.topoconf["networks-autonumber"] = bool(value)
33063312

3313+
@property
3314+
def autonumber_loopbacks(self):
3315+
return self.topoconf.get("loopbacks-autonumber", False)
3316+
3317+
@autonumber_loopbacks.setter
3318+
def autonumber_loopbacks(self, value):
3319+
self.topoconf["loopbacks-autonumber"] = bool(value)
3320+
33073321
async def add_dummy_link(self, node1, c1=None):
33083322
c1 = {} if c1 is None else c1
33093323

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "munet"
3-
version = "0.17.0"
3+
version = "0.17.1"
44
description = "A package to facilitate network simulations"
55
readme = {file = "README.org", content-type = "text/plain"}
66
requires-python = ">=3.9"

tests/basic/munet.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: 1
22
topology:
33
networks-autonumber: true
4+
loopbacks-autonumber: true
45
ipv6-enable: true
56
networks:
67
- name: net0

tests/basic/test_basic_topology.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,14 @@ async def test_autonumber_ping(unet_perfunc):
7777
o = await r2.async_cmd_raises("ping -w1 -c1 fcff:ffff:2::1")
7878
logging.debug("r2 ping r3 p2p (fcff:ffff:2::1) output: %s", o)
7979

80-
o = await r2.async_cmd_raises("ping -w1 -c1 fcfe:ffff:2::1")
81-
logging.debug("r2 ping lo (fcfe:ffff:2::1) output: %s", o)
80+
o = await r2.async_cmd_raises("ping -w1 -c1 fcfe::2")
81+
logging.debug("r2 ping lo (fcfe::2) output: %s", o)
8282

8383
o = await r1.async_cmd_nostatus("ip -6 neigh show")
8484
logging.info("ip -6 neigh show: %s", o)
8585

8686

87-
@pytest.mark.parametrize(
88-
"unet_perfunc", ["munet"], indirect=["unet_perfunc"]
89-
)
87+
@pytest.mark.parametrize("unet_perfunc", ["munet"], indirect=["unet_perfunc"])
9088
async def test_basic_config(unet_perfunc):
9189
unet = unet_perfunc
9290
r3 = unet.hosts["r3"]

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)