forked from named-data/ndnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_scenario.py
More file actions
72 lines (58 loc) · 2.13 KB
/
run_scenario.py
File metadata and controls
72 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
import importlib
import inspect
import os
import random
import subprocess
import sys
import time
from pathlib import Path
from mininet.log import info, setLogLevel
from minindn.minindn import Minindn
def ensure_local_ndnd(repo_root: Path) -> None:
local_bin = repo_root / ".bin"
local_ndnd = local_bin / "ndnd"
local_bin.mkdir(parents=True, exist_ok=True)
if not local_ndnd.exists():
info("Building local ndnd binary for E2E scenario\n")
subprocess.check_call(
["go", "build", "-o", str(local_ndnd), "./cmd/ndnd"],
cwd=repo_root,
)
os.environ["PATH"] = f"{local_bin}:{os.environ.get('PATH', '')}"
def main():
parser = argparse.ArgumentParser(description="Run one Mini-NDN E2E scenario headlessly")
parser.add_argument("--scenario", required=True, help="Python module name under e2e/, e.g. test_003")
parser.add_argument("--network", default="/minindn", help="NDN network prefix passed to scenario")
parser.add_argument("--topo", default="e2e/topo.sprint.conf", help="Topology config file")
args = parser.parse_args()
sys.argv = [sys.argv[0]]
# Prefer workspace binary and build it if missing.
repo_root = Path(__file__).resolve().parent.parent
ensure_local_ndnd(repo_root)
setLogLevel("info")
Minindn.cleanUp()
Minindn.verifyDependencies()
ndn = Minindn(topoFile=args.topo)
ndn.start()
try:
mod = importlib.import_module(args.scenario)
scenario = getattr(mod, "scenario")
sig = inspect.signature(scenario)
random.seed(0)
info("===================================================\n")
start = time.time()
if "network" in sig.parameters:
scenario(ndn, network=args.network)
else:
scenario(ndn)
info(f"Scenario completed in: {time.time()-start:.2f}s\n")
info("===================================================\n")
for cleanup in reversed(ndn.cleanups):
cleanup()
finally:
ndn.stop()
os.system("pkill -9 ndnd")
os.system("pkill -9 nfd")
if __name__ == "__main__":
main()