infamy: Add new class to test multicast

Depends on having mtools v3+ on test PC, so add it to the docker.
This commit is contained in:
Mattias Walström
2024-03-07 12:45:55 +01:00
parent 12eae1ec2b
commit 68af24adcf
3 changed files with 64 additions and 2 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
# shellcheck disable=SC2034,SC2154
# Current container image
INFIX_TEST=ghcr.io/kernelkit/infix-test:1.2
INFIX_TEST=ghcr.io/kernelkit/infix-test:1.3
ixdir=$(readlink -f "$testdir/..")
logdir=$(readlink -f "$testdir/.log")
+7 -1
View File
@@ -19,7 +19,13 @@ RUN apk add --no-cache \
socat \
squashfs-tools \
tcpdump \
tshark
tshark \
make
ARG MTOOL_VERSION="3.0"
RUN wget https://github.com/troglobit/mtools/releases/download/v3.0/mtools-$MTOOL_VERSION.tar.gz -O /tmp/mtools-$MTOOL_VERSION.tar.gz
RUN cd /tmp/ && tar zxvf mtools-$MTOOL_VERSION.tar.gz
RUN cd /tmp/mtools-$MTOOL_VERSION && make && make install
# Alpine's QEMU package does not bundle this for some reason, copied
# from Ubuntu
+56
View File
@@ -0,0 +1,56 @@
import time
import subprocess
import signal
import sys
class MCastSender:
def __init__(self, netns,group):
self.group = group
self.netns = netns
def __enter__(self):
cmd = f"msend -I iface -g {self.group}"
arg = cmd.split(" ")
self.proc = self.netns.popen(arg, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def __exit__(self, _, __, ___):
if not self.proc:
return False
sys.stdout.flush()
self.proc.send_signal(signal.SIGINT)
time.sleep(1)
if not self.proc.poll():
try:
self.proc.kill()
except OSError:
pass
self.proc.wait()
class MCastReceiver:
def __init__(self, netns, group):
self.group = group
self.netns = netns
def __enter__(self):
cmd = f"mreceive -I iface -g {self.group}"
arg = cmd.split(" ")
self.proc = self.netns.popen(arg, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def __exit__(self, _, __, ___):
if not self.proc:
return False
sys.stdout.flush()
self.proc.send_signal(signal.SIGINT)
time.sleep(3)
if not self.proc.poll():
print("PROC")
try:
self.proc.kill()
except OSError:
print("ERR")
pass
self.proc.wait()