Skip to content

Commit

Permalink
Implement MTU command
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Aug 10, 2024
1 parent f7e2857 commit b81ae86
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
=====================================
generator=datazen
version=3.1.4
hash=75472a985efe131b3312ecf46e006599
hash=3b287fdc5e1b1691d94597b8f170f111
=====================================
-->

Expand Down Expand Up @@ -102,10 +102,19 @@ options:
```
$ ./venv3.12/bin/runtimepy mtu -h
usage: runtimepy mtu [-h]
usage: runtimepy mtu [-h] [--probe-size PROBE_SIZE] [--fallback FALLBACK] [-t]
destination [destination ...]
positional arguments:
destination endpoint parameters (host, port[, flowinfo, scope_id])
options:
-h, --help show this help message and exit
-h, --help show this help message and exit
--probe-size PROBE_SIZE
data payload size to use for probe (default: 1432)
--fallback FALLBACK fallback MTU value if probing doesn't succeed (i.e.
not on Linux, default: 1432)
-t, --tcp use TCP instead of UDP
```

Expand Down
32 changes: 16 additions & 16 deletions runtimepy/commands/mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# built-in
import argparse
import socket

# third-party
from vcorelib.args import CommandFunction
Expand All @@ -15,18 +16,13 @@
def mtu_cmd(args: argparse.Namespace) -> int:
"""Execute the mtu command."""

print(args.probe_size)
print(args.fallback)

print(discover_mtu)

# def discover_mtu(
# *destination: IpHostlike,
# local: IpHost = None,
# probe_size=args.probe_size,
# fallback=args.fallback,
# kind: int = socket.SOCK_DGRAM,
# ) -> int:
discover_mtu(
args.destination[0],
*(int(x) for x in args.destination[1:]),
probe_size=args.probe_size,
fallback=args.fallback,
kind=socket.SOCK_STREAM if args.tcp else socket.SOCK_DGRAM,
)

return 0

Expand All @@ -48,10 +44,14 @@ def add_mtu_cmd(parser: argparse.ArgumentParser) -> CommandFunction:
"(i.e. not on Linux, default: %(default)d)",
)

# udp vs tcp
# ip6 flag?
parser.add_argument(
"-t", "--tcp", action="store_true", help="use TCP instead of UDP"
)

# dest
# local params?
parser.add_argument(
"destination",
nargs="+",
help="endpoint parameters (host, port[, flowinfo, scope_id])",
)

return mtu_cmd
2 changes: 1 addition & 1 deletion runtimepy/net/mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def discover_mtu(
host.
"""

local = normalize_host(local)
dest = normalize_host(*destination)
local = normalize_host(local, default=type(dest))
result = host_discover_mtu(local, dest, probe_size, fallback, kind=kind)

LOG.info(
Expand Down
3 changes: 2 additions & 1 deletion tests/commands/test_mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def test_mtu_command_basic():
"""Test basic usages of the 'mtu' command."""

base = base_args("mtu")
assert runtimepy_main(base) == 0
assert runtimepy_main(base + ["localhost", "8000"]) == 0
assert runtimepy_main(base + ["::1", "8000", "0", "0"]) == 0
8 changes: 3 additions & 5 deletions tests/net/test_mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

# module under test
from runtimepy.net.mtu import discover_mtu
from runtimepy.net.util import IPv6Host, normalize_host

# from runtimepy.net.util import IPv6Host, normalize_host


def test_ipv4_mtu_discovery() -> None:
"""Test that we can discover maximum transmission units."""

assert discover_mtu("localhost", 80) > 0
assert (
discover_mtu("::1", 80, 0, 0, local=normalize_host(default=IPv6Host))
> 0
)
assert discover_mtu("::1", 80, 0, 0) > 0
assert discover_mtu("localhost", 80, probe_size=2**16) > 0

0 comments on commit b81ae86

Please sign in to comment.