spongebob-cli 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spongebob/__init__.py +1 -0
- spongebob/__main__.py +375 -0
- spongebob/analyzer/__init__.py +9 -0
- spongebob/analyzer/__main__.py +39 -0
- spongebob/analyzer/analyzer.py +234 -0
- spongebob/bus/__init__.py +6 -0
- spongebob/bus/bus.py +38 -0
- spongebob/diagnose/__init__.py +29 -0
- spongebob/diagnose/__main__.py +111 -0
- spongebob/diagnose/adapter.py +82 -0
- spongebob/diagnose/models.py +79 -0
- spongebob/diagnose/probes.py +129 -0
- spongebob/engine/__init__.py +26 -0
- spongebob/engine/__main__.py +25 -0
- spongebob/engine/models.py +161 -0
- spongebob/engine/simulator.py +196 -0
- spongebob/export/__init__.py +25 -0
- spongebob/export/exporter.py +354 -0
- spongebob/meter/__init__.py +7 -0
- spongebob/meter/__main__.py +50 -0
- spongebob/meter/meter.py +140 -0
- spongebob/narrator/__init__.py +25 -0
- spongebob/narrator/narrator.py +352 -0
- spongebob/plugins/__init__.py +28 -0
- spongebob/plugins/loader.py +308 -0
- spongebob/plugins/models.py +47 -0
- spongebob/scenarios/__init__.py +25 -0
- spongebob/scenarios/builtin/__init__.py +1 -0
- spongebob/scenarios/builtin/control-line.toml +33 -0
- spongebob/scenarios/builtin/crowded-wifi.toml +33 -0
- spongebob/scenarios/builtin/flaky-last-mile.toml +33 -0
- spongebob/scenarios/builtin/long-haul-orbit.toml +33 -0
- spongebob/scenarios/builtin/overloaded-uplink.toml +35 -0
- spongebob/scenarios/builtin/tunnel-burst.toml +38 -0
- spongebob/scenarios/loader.py +205 -0
- spongebob/scenarios/models.py +55 -0
- spongebob/scenarios/runner.py +24 -0
- spongebob/ui/__init__.py +23 -0
- spongebob/ui/__main__.py +11 -0
- spongebob/ui/app.py +88 -0
- spongebob/ui/canvas.py +147 -0
- spongebob/ui/diagnose_screen.py +525 -0
- spongebob/ui/export_modal.py +158 -0
- spongebob/ui/menu_screen.py +159 -0
- spongebob/ui/replay.py +209 -0
- spongebob/ui/settings_screen.py +101 -0
- spongebob/ui/simulate_screen.py +566 -0
- spongebob/ui/theme.py +364 -0
- spongebob/ui/visualize_screen.py +411 -0
- spongebob_cli-0.3.2.dist-info/METADATA +78 -0
- spongebob_cli-0.3.2.dist-info/RECORD +54 -0
- spongebob_cli-0.3.2.dist-info/WHEEL +5 -0
- spongebob_cli-0.3.2.dist-info/entry_points.txt +2 -0
- spongebob_cli-0.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import string
|
|
5
|
+
import tomllib
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from spongebob.narrator.narrator import BANNED_NAMES, DROP_REASON_POOLS, FINDING_POOLS
|
|
10
|
+
from spongebob.scenarios import list_builtin_scenarios, load_scenario
|
|
11
|
+
from spongebob.scenarios.models import Scenario
|
|
12
|
+
|
|
13
|
+
from .models import (
|
|
14
|
+
MAX_JOKE_LEN,
|
|
15
|
+
MAX_PLUGIN_FILE_BYTES,
|
|
16
|
+
MAX_PLUGIN_FILES,
|
|
17
|
+
MAX_PLUGIN_TOTAL_BYTES,
|
|
18
|
+
MIN_CONTRAST_RATIO,
|
|
19
|
+
LoadedPlugin,
|
|
20
|
+
PluginManifest,
|
|
21
|
+
PluginRegistry,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
_PLUGIN_NAME_RE = re.compile(r"^[a-z0-9-]{3,32}$")
|
|
25
|
+
_HEX_COLOR_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
|
|
26
|
+
_MANIFEST_KEYS = frozenset({"name", "version", "kind", "description"})
|
|
27
|
+
_VALID_KINDS = frozenset({"scenarios", "jokes", "theme"})
|
|
28
|
+
_ALLOWED_JOKE_FIELDS = frozenset({"hop", "value"})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _read_toml_file(path: Path) -> dict[str, Any]:
|
|
32
|
+
raw = path.read_bytes()
|
|
33
|
+
if len(raw) > MAX_PLUGIN_FILE_BYTES:
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f"File {path.name} ({len(raw)} bytes) exceeds limit of {MAX_PLUGIN_FILE_BYTES} bytes"
|
|
36
|
+
)
|
|
37
|
+
try:
|
|
38
|
+
data = tomllib.loads(raw.decode("utf-8"))
|
|
39
|
+
except (UnicodeDecodeError, tomllib.TOMLDecodeError) as exc:
|
|
40
|
+
raise ValueError(f"Invalid TOML in {path.name}: {exc}") from exc
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _validate_folder_limits(folder: Path) -> list[Path]:
|
|
45
|
+
if not folder.is_dir():
|
|
46
|
+
raise FileNotFoundError(f"Plugin folder not found: {folder}")
|
|
47
|
+
files = sorted(p for p in folder.rglob("*") if p.is_file())
|
|
48
|
+
if len(files) > MAX_PLUGIN_FILES:
|
|
49
|
+
raise ValueError(
|
|
50
|
+
f"Plugin {folder.name} has {len(files)} files (max {MAX_PLUGIN_FILES})"
|
|
51
|
+
)
|
|
52
|
+
total_bytes = 0
|
|
53
|
+
for f in files:
|
|
54
|
+
sz = f.stat().st_size
|
|
55
|
+
if sz > MAX_PLUGIN_FILE_BYTES:
|
|
56
|
+
raise ValueError(
|
|
57
|
+
f"File {f.name} ({sz} bytes) exceeds limit of {MAX_PLUGIN_FILE_BYTES} bytes"
|
|
58
|
+
)
|
|
59
|
+
total_bytes += sz
|
|
60
|
+
if total_bytes > MAX_PLUGIN_TOTAL_BYTES:
|
|
61
|
+
raise ValueError(
|
|
62
|
+
f"Plugin {folder.name} total size {total_bytes} bytes exceeds {MAX_PLUGIN_TOTAL_BYTES} bytes"
|
|
63
|
+
)
|
|
64
|
+
return files
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _parse_manifest(folder: Path) -> PluginManifest:
|
|
68
|
+
manifest_path = folder / "plugin.toml"
|
|
69
|
+
if not manifest_path.is_file():
|
|
70
|
+
raise ValueError(f"Missing plugin.toml in {folder}")
|
|
71
|
+
data = _read_toml_file(manifest_path)
|
|
72
|
+
|
|
73
|
+
for key in data:
|
|
74
|
+
if key not in _MANIFEST_KEYS:
|
|
75
|
+
raise ValueError(f"Unknown key {key!r} in plugin.toml")
|
|
76
|
+
for req in sorted(_MANIFEST_KEYS):
|
|
77
|
+
if req not in data:
|
|
78
|
+
raise ValueError(f"Missing required key {req!r} in plugin.toml")
|
|
79
|
+
|
|
80
|
+
name = data["name"]
|
|
81
|
+
version = data["version"]
|
|
82
|
+
kind = data["kind"]
|
|
83
|
+
description = data["description"]
|
|
84
|
+
|
|
85
|
+
if not isinstance(name, str) or not _PLUGIN_NAME_RE.match(name):
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Invalid plugin name {name!r}: must be 3-32 lowercase letters, digits, or hyphens"
|
|
88
|
+
)
|
|
89
|
+
if not isinstance(version, str) or not version.strip():
|
|
90
|
+
raise ValueError("Plugin version must be a non-empty string")
|
|
91
|
+
if not isinstance(kind, str) or kind not in _VALID_KINDS:
|
|
92
|
+
raise ValueError(f"Invalid plugin kind {kind!r}: must be scenarios, jokes, or theme")
|
|
93
|
+
if not isinstance(description, str) or not description.strip():
|
|
94
|
+
raise ValueError("Plugin description must be a non-empty string")
|
|
95
|
+
|
|
96
|
+
return PluginManifest(name=name, version=version, kind=kind, description=description) # type: ignore[arg-type]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _validate_joke_line(line: Any) -> str:
|
|
100
|
+
if not isinstance(line, str) or not line.strip():
|
|
101
|
+
raise ValueError("Joke line must be a non-empty string")
|
|
102
|
+
if len(line) > MAX_JOKE_LEN:
|
|
103
|
+
raise ValueError(f"Joke line exceeds {MAX_JOKE_LEN} chars")
|
|
104
|
+
for ch in line:
|
|
105
|
+
code = ord(ch)
|
|
106
|
+
if code < 32 or code == 127:
|
|
107
|
+
raise ValueError("Joke line contains disallowed control or escape characters")
|
|
108
|
+
lowered = line.lower()
|
|
109
|
+
for banned in BANNED_NAMES:
|
|
110
|
+
if banned in lowered:
|
|
111
|
+
raise ValueError(f"Joke line contains banned name {banned!r}")
|
|
112
|
+
|
|
113
|
+
formatter = string.Formatter()
|
|
114
|
+
try:
|
|
115
|
+
for _literal, field_name, format_spec, conversion in formatter.parse(line):
|
|
116
|
+
if field_name is not None:
|
|
117
|
+
if field_name not in _ALLOWED_JOKE_FIELDS:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
f"Disallowed placeholder {{{field_name}}} in joke line; only {{hop}} and {{value}} allowed"
|
|
120
|
+
)
|
|
121
|
+
if format_spec or conversion:
|
|
122
|
+
raise ValueError("Format specs/conversions are not allowed in joke placeholders")
|
|
123
|
+
line.format(hop="router", value="42.0")
|
|
124
|
+
except ValueError:
|
|
125
|
+
raise
|
|
126
|
+
except Exception as exc:
|
|
127
|
+
raise ValueError(f"Invalid joke template: {exc}") from exc
|
|
128
|
+
return line
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _load_scenarios_plugin(manifest: PluginManifest, files: list[Path]) -> dict[str, Scenario]:
|
|
132
|
+
builtins = set(list_builtin_scenarios())
|
|
133
|
+
scenarios: dict[str, Scenario] = {}
|
|
134
|
+
toml_files = [f for f in files if f.suffix == ".toml" and f.name != "plugin.toml"]
|
|
135
|
+
if not toml_files:
|
|
136
|
+
raise ValueError(f"Scenarios plugin {manifest.name!r} contains no scenario .toml files")
|
|
137
|
+
for f in toml_files:
|
|
138
|
+
stem = f.stem
|
|
139
|
+
if stem in builtins:
|
|
140
|
+
raise ValueError(f"Plugin scenario {stem!r} cannot override built-in scenario")
|
|
141
|
+
reg_key = f"{manifest.name}/{stem}"
|
|
142
|
+
if reg_key in builtins:
|
|
143
|
+
raise ValueError(f"Plugin scenario {reg_key!r} cannot override built-in scenario")
|
|
144
|
+
scenarios[reg_key] = load_scenario(f)
|
|
145
|
+
return scenarios
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _load_jokes_plugin(
|
|
149
|
+
manifest: PluginManifest, files: list[Path]
|
|
150
|
+
) -> tuple[dict[tuple[str, str], tuple[str, ...]], dict[str, tuple[str, ...]]]:
|
|
151
|
+
toml_files = [f for f in files if f.suffix == ".toml" and f.name != "plugin.toml"]
|
|
152
|
+
if not toml_files:
|
|
153
|
+
raise ValueError(f"Jokes plugin {manifest.name!r} contains no .toml files")
|
|
154
|
+
|
|
155
|
+
finding_jokes: dict[tuple[str, str], list[str]] = {}
|
|
156
|
+
drop_jokes: dict[str, list[str]] = {}
|
|
157
|
+
|
|
158
|
+
for f in toml_files:
|
|
159
|
+
data = _read_toml_file(f)
|
|
160
|
+
for top_key in data:
|
|
161
|
+
if top_key not in ("findings", "drop_reasons"):
|
|
162
|
+
raise ValueError(f"Unknown key {top_key!r} in {f.name}")
|
|
163
|
+
|
|
164
|
+
findings_tbl = data.get("findings", {})
|
|
165
|
+
if not isinstance(findings_tbl, dict):
|
|
166
|
+
raise ValueError(f"[findings] in {f.name} must be a table")
|
|
167
|
+
for key, lines in findings_tbl.items():
|
|
168
|
+
if "." not in key:
|
|
169
|
+
raise ValueError(f"Invalid finding key {key!r}; expected 'CODE.severity'")
|
|
170
|
+
code, sev = key.split(".", 1)
|
|
171
|
+
if (code, sev) not in FINDING_POOLS:
|
|
172
|
+
raise ValueError(f"Unknown finding/severity key {key!r}")
|
|
173
|
+
if not isinstance(lines, list):
|
|
174
|
+
raise ValueError(f"Finding pool {key!r} must be a list of strings")
|
|
175
|
+
validated = [_validate_joke_line(ln) for ln in lines]
|
|
176
|
+
finding_jokes.setdefault((code, sev), []).extend(validated)
|
|
177
|
+
|
|
178
|
+
drops_tbl = data.get("drop_reasons", {})
|
|
179
|
+
if not isinstance(drops_tbl, dict):
|
|
180
|
+
raise ValueError(f"[drop_reasons] in {f.name} must be a table")
|
|
181
|
+
for reason, lines in drops_tbl.items():
|
|
182
|
+
if reason not in DROP_REASON_POOLS:
|
|
183
|
+
raise ValueError(f"Unknown drop reason {reason!r}")
|
|
184
|
+
if not isinstance(lines, list):
|
|
185
|
+
raise ValueError(f"Drop reason pool {reason!r} must be a list of strings")
|
|
186
|
+
validated = [_validate_joke_line(ln) for ln in lines]
|
|
187
|
+
drop_jokes.setdefault(reason, []).extend(validated)
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
{k: tuple(v) for k, v in finding_jokes.items()},
|
|
191
|
+
{k: tuple(v) for k, v in drop_jokes.items()},
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _relative_luminance(hex_color: str) -> float:
|
|
196
|
+
r = int(hex_color[1:3], 16) / 255.0
|
|
197
|
+
g = int(hex_color[3:5], 16) / 255.0
|
|
198
|
+
b = int(hex_color[5:7], 16) / 255.0
|
|
199
|
+
|
|
200
|
+
def _lin(c: float) -> float:
|
|
201
|
+
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
|
|
202
|
+
|
|
203
|
+
return 0.2126 * _lin(r) + 0.7152 * _lin(g) + 0.0722 * _lin(b)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _contrast_ratio(c1: str, c2: str) -> float:
|
|
207
|
+
l1 = _relative_luminance(c1)
|
|
208
|
+
l2 = _relative_luminance(c2)
|
|
209
|
+
lighter, darker = max(l1, l2), min(l1, l2)
|
|
210
|
+
return (lighter + 0.05) / (darker + 0.05)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _load_theme_plugin(manifest: PluginManifest, files: list[Path]) -> dict[str, str]:
|
|
214
|
+
from spongebob.ui.theme import DEFAULT_PALETTE, THEME_ROLES
|
|
215
|
+
|
|
216
|
+
toml_files = [f for f in files if f.suffix == ".toml" and f.name != "plugin.toml"]
|
|
217
|
+
if not toml_files:
|
|
218
|
+
raise ValueError(f"Theme plugin {manifest.name!r} contains no .toml files")
|
|
219
|
+
|
|
220
|
+
colors: dict[str, str] = {}
|
|
221
|
+
for f in toml_files:
|
|
222
|
+
data = _read_toml_file(f)
|
|
223
|
+
for top_key in data:
|
|
224
|
+
if top_key != "colors":
|
|
225
|
+
raise ValueError(f"Unknown key {top_key!r} in {f.name}; expected [colors]")
|
|
226
|
+
colors_tbl = data.get("colors", {})
|
|
227
|
+
if not isinstance(colors_tbl, dict):
|
|
228
|
+
raise ValueError(f"[colors] in {f.name} must be a table")
|
|
229
|
+
for role, val in colors_tbl.items():
|
|
230
|
+
if role not in THEME_ROLES:
|
|
231
|
+
raise ValueError(f"Unknown theme role {role!r}")
|
|
232
|
+
if not isinstance(val, str) or not _HEX_COLOR_RE.match(val):
|
|
233
|
+
raise ValueError(f"Invalid hex color {val!r} for role {role!r}; expected #RRGGBB")
|
|
234
|
+
colors[role] = val.lower()
|
|
235
|
+
|
|
236
|
+
merged = {**DEFAULT_PALETTE, **colors}
|
|
237
|
+
for fg_role, bg_role in (("cream", "bg"), ("signal_green", "bg"), ("cream", "banner_blue")):
|
|
238
|
+
ratio = _contrast_ratio(merged[fg_role], merged[bg_role])
|
|
239
|
+
if ratio < MIN_CONTRAST_RATIO:
|
|
240
|
+
raise ValueError(
|
|
241
|
+
f"Low contrast ratio ({ratio:.2f} < {MIN_CONTRAST_RATIO}) between {fg_role} and {bg_role}"
|
|
242
|
+
)
|
|
243
|
+
return colors
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def load_plugin(folder: str | Path) -> LoadedPlugin:
|
|
247
|
+
"""Load and validate a single data-only plugin folder."""
|
|
248
|
+
plugin_dir = Path(folder)
|
|
249
|
+
files = _validate_folder_limits(plugin_dir)
|
|
250
|
+
manifest = _parse_manifest(plugin_dir)
|
|
251
|
+
|
|
252
|
+
if manifest.kind == "scenarios":
|
|
253
|
+
return LoadedPlugin(
|
|
254
|
+
manifest=manifest,
|
|
255
|
+
scenarios=_load_scenarios_plugin(manifest, files),
|
|
256
|
+
)
|
|
257
|
+
if manifest.kind == "jokes":
|
|
258
|
+
f_jokes, d_jokes = _load_jokes_plugin(manifest, files)
|
|
259
|
+
return LoadedPlugin(
|
|
260
|
+
manifest=manifest,
|
|
261
|
+
finding_jokes=f_jokes,
|
|
262
|
+
drop_jokes=d_jokes,
|
|
263
|
+
)
|
|
264
|
+
return LoadedPlugin(
|
|
265
|
+
manifest=manifest,
|
|
266
|
+
theme_colors=_load_theme_plugin(manifest, files),
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def load_plugins_from_dir(plugins_dir: str | Path) -> PluginRegistry:
|
|
271
|
+
"""Explicitly load all valid plugins from a user-provided folder, skipping failures."""
|
|
272
|
+
root = Path(plugins_dir)
|
|
273
|
+
if not root.is_dir():
|
|
274
|
+
return PluginRegistry(errors=((str(root), f"Plugin directory not found: {root}"),))
|
|
275
|
+
|
|
276
|
+
candidates = [root] if (root / "plugin.toml").is_file() else sorted(
|
|
277
|
+
p for p in root.iterdir() if p.is_dir()
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
loaded: list[LoadedPlugin] = []
|
|
281
|
+
scenarios: dict[str, Scenario] = {}
|
|
282
|
+
finding_jokes: dict[tuple[str, str], list[str]] = {}
|
|
283
|
+
drop_jokes: dict[str, list[str]] = {}
|
|
284
|
+
theme_colors: dict[str, str] = {}
|
|
285
|
+
errors: list[tuple[str, str]] = []
|
|
286
|
+
|
|
287
|
+
for candidate in candidates:
|
|
288
|
+
try:
|
|
289
|
+
plugin = load_plugin(candidate)
|
|
290
|
+
except Exception as exc:
|
|
291
|
+
errors.append((candidate.name, str(exc)))
|
|
292
|
+
continue
|
|
293
|
+
loaded.append(plugin)
|
|
294
|
+
scenarios.update(plugin.scenarios)
|
|
295
|
+
for k, lines in plugin.finding_jokes.items():
|
|
296
|
+
finding_jokes.setdefault(k, []).extend(lines)
|
|
297
|
+
for k, lines in plugin.drop_jokes.items():
|
|
298
|
+
drop_jokes.setdefault(k, []).extend(lines)
|
|
299
|
+
theme_colors.update(plugin.theme_colors)
|
|
300
|
+
|
|
301
|
+
return PluginRegistry(
|
|
302
|
+
plugins=tuple(loaded),
|
|
303
|
+
scenarios=scenarios,
|
|
304
|
+
finding_jokes={k: tuple(v) for k, v in finding_jokes.items()},
|
|
305
|
+
drop_jokes={k: tuple(v) for k, v in drop_jokes.items()},
|
|
306
|
+
theme_colors=theme_colors,
|
|
307
|
+
errors=tuple(errors),
|
|
308
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from spongebob.scenarios.models import Scenario
|
|
7
|
+
|
|
8
|
+
PluginKind = Literal["scenarios", "jokes", "theme"]
|
|
9
|
+
|
|
10
|
+
MAX_PLUGIN_FILES = 20
|
|
11
|
+
MAX_PLUGIN_FILE_BYTES = 65_536
|
|
12
|
+
MAX_PLUGIN_TOTAL_BYTES = 524_288
|
|
13
|
+
MAX_JOKE_LEN = 200
|
|
14
|
+
MIN_CONTRAST_RATIO = 4.5
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class PluginManifest:
|
|
19
|
+
"""Validated plugin.toml metadata."""
|
|
20
|
+
|
|
21
|
+
name: str
|
|
22
|
+
version: str
|
|
23
|
+
kind: PluginKind
|
|
24
|
+
description: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class LoadedPlugin:
|
|
29
|
+
"""Validated data-only plugin payload."""
|
|
30
|
+
|
|
31
|
+
manifest: PluginManifest
|
|
32
|
+
scenarios: dict[str, Scenario] = field(default_factory=dict)
|
|
33
|
+
finding_jokes: dict[tuple[str, str], tuple[str, ...]] = field(default_factory=dict)
|
|
34
|
+
drop_jokes: dict[str, tuple[str, ...]] = field(default_factory=dict)
|
|
35
|
+
theme_colors: dict[str, str] = field(default_factory=dict)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class PluginRegistry:
|
|
40
|
+
"""Aggregated data from explicitly loaded plugins."""
|
|
41
|
+
|
|
42
|
+
plugins: tuple[LoadedPlugin, ...] = ()
|
|
43
|
+
scenarios: dict[str, Scenario] = field(default_factory=dict)
|
|
44
|
+
finding_jokes: dict[tuple[str, str], tuple[str, ...]] = field(default_factory=dict)
|
|
45
|
+
drop_jokes: dict[str, tuple[str, ...]] = field(default_factory=dict)
|
|
46
|
+
theme_colors: dict[str, str] = field(default_factory=dict)
|
|
47
|
+
errors: tuple[tuple[str, str], ...] = ()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .loader import (
|
|
4
|
+
dump_scenario,
|
|
5
|
+
list_builtin_scenarios,
|
|
6
|
+
load_builtin_scenario,
|
|
7
|
+
load_scenario,
|
|
8
|
+
loads_scenario,
|
|
9
|
+
)
|
|
10
|
+
from .models import MAX_HOPS, MAX_PACKETS, MAX_SCENARIO_BYTES, Scenario, ScenarioRunResult
|
|
11
|
+
from .runner import run_scenario
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"MAX_HOPS",
|
|
15
|
+
"MAX_PACKETS",
|
|
16
|
+
"MAX_SCENARIO_BYTES",
|
|
17
|
+
"Scenario",
|
|
18
|
+
"ScenarioRunResult",
|
|
19
|
+
"dump_scenario",
|
|
20
|
+
"list_builtin_scenarios",
|
|
21
|
+
"load_builtin_scenario",
|
|
22
|
+
"load_scenario",
|
|
23
|
+
"loads_scenario",
|
|
24
|
+
"run_scenario",
|
|
25
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Clean Control Line"
|
|
3
|
+
description = "Baseline wired path with low delay, minimal jitter, and zero packet loss."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 100
|
|
7
|
+
interval_ms = 10.0
|
|
8
|
+
size_bytes = 64
|
|
9
|
+
seed = 42
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 5.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 0.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 10.0
|
|
20
|
+
jitter_ms = 1.0
|
|
21
|
+
loss_pct = 0.0
|
|
22
|
+
|
|
23
|
+
[[hop]]
|
|
24
|
+
name = "isp"
|
|
25
|
+
delay_ms = 15.0
|
|
26
|
+
jitter_ms = 2.0
|
|
27
|
+
loss_pct = 0.0
|
|
28
|
+
|
|
29
|
+
[[hop]]
|
|
30
|
+
name = "server"
|
|
31
|
+
delay_ms = 5.0
|
|
32
|
+
jitter_ms = 1.0
|
|
33
|
+
loss_pct = 0.0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Crowded Wi-Fi Evening"
|
|
3
|
+
description = "Shared wireless router during peak evening hours with heavy jitter and mild loss."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 120
|
|
7
|
+
interval_ms = 10.0
|
|
8
|
+
size_bytes = 64
|
|
9
|
+
seed = 19
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 4.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 0.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 80.0
|
|
20
|
+
jitter_ms = 70.0
|
|
21
|
+
loss_pct = 2.0
|
|
22
|
+
|
|
23
|
+
[[hop]]
|
|
24
|
+
name = "isp"
|
|
25
|
+
delay_ms = 15.0
|
|
26
|
+
jitter_ms = 3.0
|
|
27
|
+
loss_pct = 0.0
|
|
28
|
+
|
|
29
|
+
[[hop]]
|
|
30
|
+
name = "server"
|
|
31
|
+
delay_ms = 5.0
|
|
32
|
+
jitter_ms = 1.0
|
|
33
|
+
loss_pct = 0.0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Flaky Last Mile"
|
|
3
|
+
description = "Degraded access drop between subscriber and gateway causing steady random packet loss."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 120
|
|
7
|
+
interval_ms = 10.0
|
|
8
|
+
size_bytes = 64
|
|
9
|
+
seed = 11
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 5.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 8.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 10.0
|
|
20
|
+
jitter_ms = 1.0
|
|
21
|
+
loss_pct = 0.0
|
|
22
|
+
|
|
23
|
+
[[hop]]
|
|
24
|
+
name = "isp"
|
|
25
|
+
delay_ms = 15.0
|
|
26
|
+
jitter_ms = 2.0
|
|
27
|
+
loss_pct = 0.0
|
|
28
|
+
|
|
29
|
+
[[hop]]
|
|
30
|
+
name = "server"
|
|
31
|
+
delay_ms = 5.0
|
|
32
|
+
jitter_ms = 1.0
|
|
33
|
+
loss_pct = 0.0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Long-Haul Orbit"
|
|
3
|
+
description = "High-altitude orbital relay path with high propagation delay and steady timing."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 100
|
|
7
|
+
interval_ms = 10.0
|
|
8
|
+
size_bytes = 64
|
|
9
|
+
seed = 42
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 5.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 0.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 15.0
|
|
20
|
+
jitter_ms = 2.0
|
|
21
|
+
loss_pct = 0.0
|
|
22
|
+
|
|
23
|
+
[[hop]]
|
|
24
|
+
name = "isp"
|
|
25
|
+
delay_ms = 280.0
|
|
26
|
+
jitter_ms = 3.0
|
|
27
|
+
loss_pct = 0.0
|
|
28
|
+
|
|
29
|
+
[[hop]]
|
|
30
|
+
name = "server"
|
|
31
|
+
delay_ms = 5.0
|
|
32
|
+
jitter_ms = 1.0
|
|
33
|
+
loss_pct = 0.0
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Overloaded Uplink"
|
|
3
|
+
description = "Narrow residential uplink with tight bandwidth cap and shallow queue tail-drops."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 80
|
|
7
|
+
interval_ms = 5.0
|
|
8
|
+
size_bytes = 256
|
|
9
|
+
seed = 42
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 4.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 0.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 10.0
|
|
20
|
+
jitter_ms = 1.0
|
|
21
|
+
loss_pct = 0.0
|
|
22
|
+
bandwidth_kbps = 64.0
|
|
23
|
+
queue_limit_packets = 3
|
|
24
|
+
|
|
25
|
+
[[hop]]
|
|
26
|
+
name = "isp"
|
|
27
|
+
delay_ms = 15.0
|
|
28
|
+
jitter_ms = 2.0
|
|
29
|
+
loss_pct = 0.0
|
|
30
|
+
|
|
31
|
+
[[hop]]
|
|
32
|
+
name = "server"
|
|
33
|
+
delay_ms = 5.0
|
|
34
|
+
jitter_ms = 1.0
|
|
35
|
+
loss_pct = 0.0
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[scenario]
|
|
2
|
+
name = "Tunnel Burst"
|
|
3
|
+
description = "Intermittent tunnel link with Gilbert-Elliott two-state bursty packet loss."
|
|
4
|
+
|
|
5
|
+
[flow]
|
|
6
|
+
packets = 120
|
|
7
|
+
interval_ms = 10.0
|
|
8
|
+
size_bytes = 64
|
|
9
|
+
seed = 7
|
|
10
|
+
|
|
11
|
+
[[hop]]
|
|
12
|
+
name = "client"
|
|
13
|
+
delay_ms = 5.0
|
|
14
|
+
jitter_ms = 1.0
|
|
15
|
+
loss_pct = 0.0
|
|
16
|
+
|
|
17
|
+
[[hop]]
|
|
18
|
+
name = "router"
|
|
19
|
+
delay_ms = 10.0
|
|
20
|
+
jitter_ms = 2.0
|
|
21
|
+
loss_pct = 0.0
|
|
22
|
+
|
|
23
|
+
[[hop]]
|
|
24
|
+
name = "isp"
|
|
25
|
+
delay_ms = 20.0
|
|
26
|
+
jitter_ms = 3.0
|
|
27
|
+
loss_pct = 0.0
|
|
28
|
+
loss_model = "gilbert"
|
|
29
|
+
p_good_to_bad = 0.25
|
|
30
|
+
p_bad_to_good = 0.2
|
|
31
|
+
loss_good = 0.0
|
|
32
|
+
loss_bad = 100.0
|
|
33
|
+
|
|
34
|
+
[[hop]]
|
|
35
|
+
name = "server"
|
|
36
|
+
delay_ms = 5.0
|
|
37
|
+
jitter_ms = 1.0
|
|
38
|
+
loss_pct = 0.0
|