|
| 1 | +import subprocess |
| 2 | +from typing import List, Optional |
| 3 | + |
| 4 | +from netunicorn.base import Task |
| 5 | + |
| 6 | + |
| 7 | +class StartServer(Task): |
| 8 | + """ |
| 9 | + Starts netserver on the node. |
| 10 | + """ |
| 11 | + |
| 12 | + requirements = ["sudo apt install netperf"] |
| 13 | + |
| 14 | + def run(self) -> str: |
| 15 | + return subprocess.check_output(["netserver"]).decode("utf-8") |
| 16 | + |
| 17 | + |
| 18 | +class StopServer(Task): |
| 19 | + """ |
| 20 | + Stops all netservers on the node. |
| 21 | + """ |
| 22 | + |
| 23 | + def run(self) -> str: |
| 24 | + return subprocess.check_output(["killall", "netserver"]).decode("utf-8") |
| 25 | + |
| 26 | + |
| 27 | +class FlentCommand(Task): |
| 28 | + requirements = [ |
| 29 | + "sudo apt install -y netperf iputils-ping irtt python3-pip", |
| 30 | + "pip install matplotlib flent", |
| 31 | + ] |
| 32 | + |
| 33 | + def __init__( |
| 34 | + self, |
| 35 | + test_name: str = "rrul", |
| 36 | + host: str = "netperf-west.bufferbloat.net", |
| 37 | + duration: int = 60, |
| 38 | + additional_arguments: Optional[List[str]] = None, |
| 39 | + *args, |
| 40 | + **kwargs, |
| 41 | + ): |
| 42 | + self.test_name = test_name |
| 43 | + self.host = host |
| 44 | + self.duration = duration |
| 45 | + self.additional_arguments = additional_arguments or [] |
| 46 | + super().__init__(*args, **kwargs) |
| 47 | + |
| 48 | + def run(self) -> str: |
| 49 | + command = ["flent", self.test_name, "-H", self.host, "-l", str(self.duration)] |
| 50 | + command.extend(self.additional_arguments) |
| 51 | + return subprocess.check_output(command).decode("utf-8") |
| 52 | + |
| 53 | + |
| 54 | +class PingTest(FlentCommand): |
| 55 | + def __init__(self, *args, **kwargs): |
| 56 | + super().__init__(test_name="ping", *args, **kwargs) |
| 57 | + |
| 58 | + |
| 59 | +class CubicBBRTest(FlentCommand): |
| 60 | + def __init__(self, *args, **kwargs): |
| 61 | + super().__init__(test_name="cubic_bbr", *args, **kwargs) |
| 62 | + |
| 63 | + |
| 64 | +class RRULTest(FlentCommand): |
| 65 | + def __init__(self, *args, **kwargs): |
| 66 | + super().__init__(test_name="rrul", *args, **kwargs) |
| 67 | + |
| 68 | + |
| 69 | +class TCPDownloadTest(FlentCommand): |
| 70 | + def __init__(self, *args, **kwargs): |
| 71 | + super().__init__(test_name="tcp_download", *args, **kwargs) |
| 72 | + |
| 73 | + |
| 74 | +class TCPUploadTest(FlentCommand): |
| 75 | + def __init__(self, *args, **kwargs): |
| 76 | + super().__init__(test_name="tcp_upload", *args, **kwargs) |
| 77 | + |
| 78 | + |
| 79 | +class VOIPTest(FlentCommand): |
| 80 | + def __init__(self, *args, **kwargs): |
| 81 | + super().__init__(test_name="voip", *args, **kwargs) |
0 commit comments