Skip to content
Merged
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
10 changes: 10 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module: labn-munet-config
| +--rw dns-network? -> ../networks/name
| +--rw ipv6-enable? boolean
| +--rw networks-autonumber? boolean
| +--rw loopbacks-autonumber? boolean
| +--rw initial-setup-cmd? string
| +--rw initial-setup-host-cmd? string
| +--rw networks* [name]
Expand Down Expand Up @@ -1084,11 +1085,20 @@ munet>

leaf networks-autonumber {
type boolean;
default false;
description
"Controls if networks and node connections are given IP addresses if
not explicitly configured.";
}

leaf loopbacks-autonumber {
type boolean;
default false;
description
"Controls if loopbacks are given IP addresses if not explicitly
configured.";
}

leaf initial-setup-cmd {
type string;
description
Expand Down
9 changes: 6 additions & 3 deletions doc/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ along with a few global topology options.
Tree diagram for topology config::

+--rw topology
| +--rw dns-network? -> ../networks/name
| +--rw ipv6-enable? boolean
| +--rw networks-autonumber? boolean
| +--rw dns-network? -> ../networks/name
| +--rw ipv6-enable? boolean
| +--rw networks-autonumber? boolean
| +--rw loopbacks-autonumber? boolean
| +--rw initial-setup-cmd? string
| +--rw initial-setup-host-cmd? string
| +--rw networks* [name]
| ... described in subsection
| +--rw nodes* [name]
Expand Down
3 changes: 3 additions & 0 deletions munet/munet-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@
"networks-autonumber": {
"type": "boolean"
},
"loopbacks-autonumber": {
"type": "boolean"
},
"initial-setup-cmd": {
"type": "string"
},
Expand Down
26 changes: 20 additions & 6 deletions munet/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
from .watchlog import WatchLog


AUTO_LOOPBACK_IPV4_BASE = ipaddress.ip_interface("10.255.0.0/32")
AUTO_LOOPBACK_IPV6_BASE = ipaddress.ip_interface("fcfe::0/128")


class L3ContainerNotRunningError(MunetError):
"""Exception if no running container exists."""

Expand All @@ -63,16 +67,14 @@ def get_loopback_ips(c, nid):
ips = []
if ip := c.get("ip"):
if ip == "auto":
assert nid < 0xFFFF # Limited to 10.255.0.0/16 block
ips.append(ipaddress.ip_interface("10.255.0.0/32") + nid)
ips.append(AUTO_LOOPBACK_IPV4_BASE + nid)
elif isinstance(ip, str):
ips.append(ipaddress.ip_interface(ip))
else:
ips.extend([ipaddress.ip_interface(x) for x in ip])
if ipv6 := c.get("ipv6"):
if ipv6 == "auto":
assert nid < 0xFFFF # Same limit as ipv4 for simplicity
ips.append(ipaddress.ip_interface(f"fcfe:ffff:{nid:02x}::1/128"))
ips.append(AUTO_LOOPBACK_IPV6_BASE + nid)
elif isinstance(ip, str):
ips.append(ipaddress.ip_interface(ipv6))
else:
Expand Down Expand Up @@ -797,9 +799,13 @@ def __init__(self, *args, unet=None, **kwargs):
)
self.next_p2p_network6 = ipaddress.ip_network(f"fcff:ffff:{self.id:02x}::/127")

if "ip" not in self.config and self.unet.autonumber:
if "ip" not in self.config and self.unet.autonumber_loopbacks:
self.config["ip"] = "auto"
if "ipv6" not in self.config and self.unet.autonumber and self.unet.ipv6_enable:
if (
"ipv6" not in self.config
and self.unet.autonumber_loopbacks
and self.unet.ipv6_enable
):
self.config["ipv6"] = "auto"
self.loopback_ip = None
self.loopback_ips = get_loopback_ips(self.config, self.id)
Expand Down Expand Up @@ -3304,6 +3310,14 @@ def autonumber(self):
def autonumber(self, value):
self.topoconf["networks-autonumber"] = bool(value)

@property
def autonumber_loopbacks(self):
return self.topoconf.get("loopbacks-autonumber", False)

@autonumber_loopbacks.setter
def autonumber_loopbacks(self, value):
self.topoconf["loopbacks-autonumber"] = bool(value)

async def add_dummy_link(self, node1, c1=None):
c1 = {} if c1 is None else c1

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "munet"
version = "0.17.0"
version = "0.17.1"
description = "A package to facilitate network simulations"
readme = {file = "README.org", content-type = "text/plain"}
requires-python = ">=3.9"
Expand Down
1 change: 1 addition & 0 deletions tests/basic/munet.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 1
topology:
networks-autonumber: true
loopbacks-autonumber: true
ipv6-enable: true
networks:
- name: net0
Expand Down
8 changes: 3 additions & 5 deletions tests/basic/test_basic_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ async def test_autonumber_ping(unet_perfunc):
o = await r2.async_cmd_raises("ping -w1 -c1 fcff:ffff:2::1")
logging.debug("r2 ping r3 p2p (fcff:ffff:2::1) output: %s", o)

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

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


@pytest.mark.parametrize(
"unet_perfunc", ["munet"], indirect=["unet_perfunc"]
)
@pytest.mark.parametrize("unet_perfunc", ["munet"], indirect=["unet_perfunc"])
async def test_basic_config(unet_perfunc):
unet = unet_perfunc
r3 = unet.hosts["r3"]
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading