Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f66fb6c122 | ||
|
|
577edbec79 | ||
|
|
f3bed57e4d | ||
|
|
71ca95d7ce | ||
|
|
29cff2321a | ||
|
|
8a804e782a | ||
|
|
f7194ab2e4 | ||
|
|
c015861147 | ||
|
|
4d3f67277f | ||
|
|
f4ea05e5b3 | ||
|
|
f03cb13c87 | ||
|
|
33ed6d2c12 | ||
|
|
7c2b5a95c9 | ||
|
|
3faa1fb570 | ||
|
|
d6ab25c363 |
No files matched your search
@@ -1,367 +0,0 @@
|
||||
# MANET NS-3 容器化仿真系统
|
||||
|
||||
**目标平台:x86_64 Linux**(需 Docker、`tun/tap/bridge` 内核模块)
|
||||
|
||||
每个 MANET 节点是一个独立 Docker 容器,所有节点间流量强制经过 NS-3 的 802.11s Mesh / AdHoc 信道模型(PHY/MAC/传播/路由)。80+ 仿真参数可通过 REST API 或 React Web 面板实时配置。
|
||||
|
||||
---
|
||||
|
||||
## 控制器启动方式
|
||||
|
||||
### Docker — 本地构建
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 构建镜像
|
||||
docker compose --profile build build node-image-builder
|
||||
docker compose build controller
|
||||
|
||||
# 启动控制器(--privileged --network host --pid host)
|
||||
docker compose up -d controller
|
||||
curl -s localhost:8000/api/health # {"ok":true}
|
||||
```
|
||||
|
||||
### Docker — 从 GHCR 拉取(无需源码)
|
||||
|
||||
```bash
|
||||
# 1. 拉取节点镜像
|
||||
docker pull ghcr.io/clawdbuddy/manet-node:latest
|
||||
docker tag ghcr.io/clawdbuddy/manet-node:latest manet-node:latest
|
||||
|
||||
# 2. 启动控制器
|
||||
docker run -d --name controller \
|
||||
--privileged --network host --pid host \
|
||||
--cap-add NET_ADMIN --cap-add NET_RAW --cap-add SYS_ADMIN \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /var/run/netns:/var/run/netns \
|
||||
-v $(pwd)/results:/results \
|
||||
-v $(pwd)/config:/app/config \
|
||||
ghcr.io/clawdbuddy/manet-controller:latest
|
||||
|
||||
# 3. 检查健康
|
||||
curl localhost:8000/api/health
|
||||
|
||||
# 4. 启动仿真
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
```
|
||||
|
||||
> 远端主机使用 `host-manet-node` 时,远端也需提前拉取:
|
||||
> ```bash
|
||||
> ssh user@remote-host
|
||||
> docker pull ghcr.io/clawdbuddy/host-manet-node:main
|
||||
> ```
|
||||
|
||||
> 如需停止并删除控制器容器:
|
||||
> ```bash
|
||||
> docker stop controller && docker rm controller
|
||||
> ```
|
||||
|
||||
### Conda 物理主机
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 首次安装系统依赖 + conda 环境 + systemd 服务
|
||||
sudo bash setup-controller.sh
|
||||
|
||||
# 手动启动
|
||||
conda activate manet-controller
|
||||
PYTHONPATH=./controller MANET_WEB_DIR=./web-manager/dist \
|
||||
python3 -m uvicorn controller.api.main:app --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### 独立可执行程序
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
bash build-controller.sh # 输出 dist/manet-controller/
|
||||
./dist/manet-controller/manet-controller
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 快速启动
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 1. 构建镜像(Docker 方式启动时才需执行)
|
||||
docker compose --profile build build node-image-builder
|
||||
docker compose build controller
|
||||
|
||||
# 2. 启动控制器
|
||||
docker compose up -d controller
|
||||
curl -s localhost:8000/api/health # {"ok":true}
|
||||
|
||||
# 3. 启动仿真(5 节点冒烟测试)
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
|
||||
# 4. 打开 Web 面板
|
||||
# http://localhost:8000/
|
||||
|
||||
# 5. 停止仿真(自动清理容器/网桥/TAP)
|
||||
curl -X POST localhost:8000/api/sim/stop
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
每个节点独占一个 Linux bridge,桥接三个接口:
|
||||
|
||||
mesh-br-{id}
|
||||
├── mesh-veth{id} ← 容器 eth0(本地节点)
|
||||
├── mesh-tap-{id} → ns-3 TapBridge → MeshPointDevice → 802.11s
|
||||
└── vxlan-{id} ← 远端 VXLAN 隧道(仅 remote/host-manet 节点)
|
||||
|
||||
数据流:容器 eth0 → veth → bridge → tap → ns-3 PHY/MAC → tap → bridge → veth → 目标容器 eth0
|
||||
```
|
||||
|
||||
### 节点部署模式
|
||||
|
||||
| 模式 | host 值 | hostType | 说明 |
|
||||
|------|---------|----------|------|
|
||||
| 本地容器 | `"local"` | `"container"` | Docker 容器,eth0 → veth → tap → ns-3 |
|
||||
| 远端主机节点 | `"<IP>"` | `"host-manet"` | SSH 启动容器(`--net=host`),VXLAN 隧道跨主机 |
|
||||
| 远端容器 | `"<IP>"` | `"container"` | SSH 启动容器,VXLAN 隧道跨主机 |
|
||||
|
||||
### VXLAN 隧道(远端节点)
|
||||
|
||||
```
|
||||
远端主机 控制器主机
|
||||
vxlan-{id} ← UDP/4789 → vxlan-{id}
|
||||
VNI=100+id ↓
|
||||
MTU=1400 mesh-br-{id} → mesh-tap-{id} → ns-3
|
||||
IP=MANET_IP/24
|
||||
|
||||
隧道端点自动选取同一 L2 子网 IP(如 192.168.50.x),避免 NAT。
|
||||
静态 ARP 条目在启动时自动注入。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 节点管理
|
||||
|
||||
### 注册远端主机
|
||||
|
||||
```bash
|
||||
curl -X POST localhost:8000/api/hosts/register \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"ip": "100.100.100.9",
|
||||
"sshUser": "binnary",
|
||||
"sshKey": "-----BEGIN OPENSSH PRIVATE KEY-----\n...",
|
||||
"capacity": 1
|
||||
}'
|
||||
```
|
||||
|
||||
### 配置节点规格
|
||||
|
||||
```bash
|
||||
# 查看当前规格
|
||||
curl -s localhost:8000/api/nodes/specs | jq
|
||||
|
||||
# 更新规格
|
||||
curl -X PUT localhost:8000/api/nodes/specs \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"specs": [
|
||||
{"id": 0, "ip": "192.168.100.10", "role": "server", "host": "local"},
|
||||
{"id": 1, "ip": "192.168.100.11", "role": "server",
|
||||
"host": "100.100.100.9", "hostType": "host-manet"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
### 启动含远端节点的仿真
|
||||
|
||||
```bash
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"config": {
|
||||
"nNodes": 5, "simulationTime": 180,
|
||||
"standard": "80211n-2.4GHz",
|
||||
"macMode": "mesh",
|
||||
"mobilityModel": "grid",
|
||||
"gridDeltaX": 50, "gridWidth": 5,
|
||||
"txPowerStart": 20, "pathLossModel": "FreeSpace"
|
||||
},
|
||||
"nodes": [
|
||||
{"id": 0, "ip": "192.168.100.10", "role": "server", "host": "local"},
|
||||
{"id": 1, "ip": "192.168.100.11", "role": "server",
|
||||
"host": "100.100.100.9", "hostType": "host-manet"},
|
||||
{"id": 2, "ip": "192.168.100.12", "role": "client", "host": "local"},
|
||||
{"id": 3, "ip": "192.168.100.13", "role": "client", "host": "local"},
|
||||
{"id": 4, "ip": "192.168.100.14", "role": "client", "host": "local"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
> **注意**:远端节点默认使用 `ghcr.io/clawdbuddy/host-manet-node:main` 镜像。
|
||||
> 控制器需 `--pid host`(docker-compose 已配置 `pid: host`)以访问宿主机 PID 空间。
|
||||
|
||||
---
|
||||
|
||||
## 测试
|
||||
|
||||
### WiFi 自动化测试套件
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 运行全部 8 个测试用例
|
||||
python3 tests/wifi_test_suite.py
|
||||
|
||||
# 运行单个测试
|
||||
python3 tests/wifi_test_suite.py tc_frequency_2_4g
|
||||
|
||||
# 生成测试报告
|
||||
python3 tests/generate_report.py
|
||||
# → test-results/wifi_test_report.md
|
||||
```
|
||||
|
||||
| 用例 | 说明 |
|
||||
|------|------|
|
||||
| `tc_frequency_2_4g` | 2.4GHz 频段连通性 |
|
||||
| `tc_frequency_5g` | 5GHz 频段连通性 |
|
||||
| `tc_bandwidth_20m` | 20MHz 带宽吞吐 |
|
||||
| `tc_bandwidth_40m` | 40MHz 带宽吞吐 |
|
||||
| `tc_distance_attenuation` | 距离衰减(500-2000m) |
|
||||
| `tc_adhoc_multihop` | 10 节点多跳 |
|
||||
| `tc_broadcast` | 广播覆盖 |
|
||||
| `tc_frequency_sweep` | 多信道遍历 |
|
||||
|
||||
### 后端单元测试
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# API 路由测试(Mock 模式,无需 Docker)
|
||||
python3 -m pytest controller/tests/test_api_routes.py -v
|
||||
|
||||
# Docker 管理器测试
|
||||
python3 -m pytest controller/tests/test_docker_mgr.py -v
|
||||
|
||||
# 网络操作测试
|
||||
python3 -m pytest controller/tests/test_netns.py -v
|
||||
```
|
||||
|
||||
### 前端检查
|
||||
|
||||
```bash
|
||||
cd manet-30ns3/web-manager
|
||||
npm run lint
|
||||
npm run build # tsc + vite build
|
||||
```
|
||||
|
||||
### 手动端到端验证
|
||||
|
||||
```bash
|
||||
# 1. 启动 5 节点仿真(4 本地 + 1 远程)
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
|
||||
# 2. 检查节点状态
|
||||
curl -s localhost:8000/api/nodes | jq
|
||||
|
||||
# 3. 连通性测试
|
||||
curl -s -X POST localhost:8000/api/nodes/0/exec \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"cmd":"ping -c 4 192.168.100.11"}'
|
||||
|
||||
# 4. 吞吐测试
|
||||
curl -s -X POST localhost:8000/api/nodes/0/exec \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"cmd":"iperf3 -c 192.168.100.11 -t 5"}'
|
||||
|
||||
# 5. 停止
|
||||
curl -X POST localhost:8000/api/sim/stop
|
||||
|
||||
# 6. 验证清理
|
||||
ip link | grep -E 'mesh-|vxlan-' || echo "clean"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## REST API 速查
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/api/health` | 健康检查 |
|
||||
| POST | `/api/sim/start` | 启动仿真(body: RunRequest) |
|
||||
| POST | `/api/sim/stop` | 停止仿真 |
|
||||
| GET | `/api/sim/status` | 仿真状态 |
|
||||
| GET | `/api/sim/presets` | 预设列表 |
|
||||
| GET | `/api/nodes` | 节点状态列表 |
|
||||
| GET | `/api/flows` | 流量统计 |
|
||||
| POST | `/api/nodes/{id}/exec` | 在节点中执行命令 |
|
||||
| GET | `/api/logs?node={id}` | 查看节点日志 |
|
||||
| GET | `/api/config` | 获取当前配置 |
|
||||
| PUT | `/api/config` | 更新配置 |
|
||||
| POST | `/api/hosts/register` | 注册远端主机 |
|
||||
| GET | `/api/hosts` | 主机列表 |
|
||||
| DELETE | `/api/hosts/{ip}` | 删除主机 |
|
||||
| GET | `/api/nodes/specs` | 节点规格列表 |
|
||||
| PUT | `/api/nodes/specs` | 更新节点规格 |
|
||||
| WS | `/ws/telemetry` | 实时遥测(5Hz) |
|
||||
|
||||
### 预设
|
||||
|
||||
| 预设 | 场景 | 参数 |
|
||||
|------|------|------|
|
||||
| `debug` | 5 节点冒烟 | mesh, grid 50m, FreeSpace, Tx=20dBm |
|
||||
| `default` | 用户目标 | mesh, 5000x5000, FreeSpace, Tx=30dBm |
|
||||
| `urban` | 高密度城市 | mesh, LogDistance n=3.5, Nakagami, 2km |
|
||||
| `rural` | 开阔野外 | mesh, FreeSpace, Grid 8km, 无衰落 |
|
||||
| `tactical` | 战术通信 | mesh, UHF 590MHz, TwoRayGround, Tx=37dBm |
|
||||
|
||||
---
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
manet-30ns3/
|
||||
├── controller/
|
||||
│ ├── api/ # FastAPI 路由(sim/nodes/config/hosts)
|
||||
│ ├── orchestrator/ # 核心:config/netns/docker_mgr/host_node_mgr/sim_runner
|
||||
│ └── tests/ # 后端单元测试
|
||||
├── node/ # 节点 Dockerfile + node-entrypoint.py
|
||||
├── web-manager/ # React 19 + Vite + TypeScript 前端
|
||||
├── tests/ # WiFi 自动化测试套件 + 报告生成器
|
||||
│ ├── wifi_test_suite.py
|
||||
│ ├── generate_report.py
|
||||
│ └── docs/ # 测试用例文档
|
||||
├── config/ # 运行时持久化(host_registry.json, node_specs.json)
|
||||
├── docker-compose.yml
|
||||
└── results/ # PCAP / ASCII trace 输出
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 故障排查
|
||||
|
||||
| 现象 | 排查 |
|
||||
|------|------|
|
||||
| 远端容器未启动 | 检查 `node_specs.json` 中节点 `host` 和 `hostType` 是否正确配置 |
|
||||
| docker pull 403 | daocloud 镜像代理限制 → 使用 GHCR 全路径镜像名 |
|
||||
| VXLAN 不通 | 检查两端 LAN IP 是否在同一子网(`ip route get 8.8.8.8`) |
|
||||
| ping 丢包 | 检查 ARP 表(`arp -n`),静态 ARP 是否注入 |
|
||||
| `--privileged` 缺失 | pyroute2 创建网桥/TAP 时报 `NetlinkError(1, 'Operation not permitted')` |
|
||||
| 容器残留 | `docker rm -f $(docker ps -aq --filter name=manet-node)` |
|
||||
|
||||
---
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Docker ≥ 20.10, Linux x86_64
|
||||
- 内核模块:`tun`, `tap`, `bridge`
|
||||
- CPU ≥ 4 核, 内存 ≥ 4 GB
|
||||
- 控制器需 `--privileged --network host --pid host`
|
||||
BIN
Binary file not shown.
+405
-243
@@ -1,290 +1,452 @@
|
||||
# MANET NS-3 容器化仿真系统
|
||||
# NS-3 802.11s Mesh / AdHoc 容器化 MANET 仿真系统
|
||||
|
||||
**目标平台:x86_64 Linux**(需 Docker、`tun/tap/bridge` 内核模块)
|
||||
**目标平台:x86_64 Ubuntu 22.04**
|
||||
|
||||
每个 MANET 节点是一个独立 Docker 容器,所有节点间流量强制经过 NS-3 的 802.11s Mesh / AdHoc 信道模型(PHY/MAC/传播/路由)。80+ 仿真参数可通过 REST API 或 React Web 面板实时配置。
|
||||
**802.11s Mesh (HWMP) / 802.11 AdHoc (IBSS)** 网络仿真。每个 MANET 节点是一个独立的 Docker 容器,所有节点间流量被强制经过 NS-3 的信道模型。PHY/MAC/路由/移动模型参数均可通过 **REST 接口**或 **React Web 管理面板**自由配置。
|
||||
|
||||
---
|
||||
> ⚠️ **架构升级说明**:本项目已从旧的"C++ scratch + shell 脚本"流水线全面迁移到 **Python 控制器(FastAPI + ns-3 Python 绑定)**。节点容器入口也从 shell 脚本改为 Python(`node-entrypoint.py`)。详情见仓库根目录 `CLAUDE.md`。
|
||||
|
||||
## 快速启动
|
||||
## 核心架构:每节点一个独立容器
|
||||
|
||||
```
|
||||
+====================================================================+
|
||||
| 宿主机 (x86_64 Ubuntu 22.04) |
|
||||
| |
|
||||
| +-------------+ mesh-br-0 +-------------+ |
|
||||
| | Container-0 |<--mesh-veth0--+---+-mesh-tap-0------>| NS-3 |
|
||||
| | [节点 0] | | | 802.11s |
|
||||
| | eth0 | | | Mesh MAC |
|
||||
| +-------------+ | | + PHY |
|
||||
| | | |
|
||||
| +-------------+ mesh-br-1 | | 每帧由 |
|
||||
| | Container-1 |<--mesh-veth1--+---+-mesh-tap-1------>| Mesh / Adhoc |
|
||||
| | [节点 1] | | | MAC 处理, |
|
||||
| | eth0 | | | PHY 决定 |
|
||||
| +-------------+ | | 转发或丢弃 |
|
||||
| | | |
|
||||
| ... (最多 30 个节点) ... | +---------------------+ |
|
||||
| | ^ |
|
||||
| +-------------+ mesh-br-29 | | |
|
||||
| |Container-29 |<--mesh-veth29-+-mesh-tap-29------------------+ |
|
||||
| | [节点 29] | |
|
||||
| | eth0 | |
|
||||
| +-------------+ |
|
||||
| |
|
||||
| 关键点:每个容器独占自己的网络命名空间 + 独占的 Linux 桥。 |
|
||||
| 容器之间无法直接相互通信(无共享 L2 广播域)。 |
|
||||
| 所有跨节点流量必须经过 ns-3 802.11s Mesh / AdHoc 信道模型。 |
|
||||
+====================================================================+
|
||||
```
|
||||
|
||||
### 数据流路径
|
||||
|
||||
**节点 A (Container-0) → 节点 B (Container-1):**
|
||||
|
||||
```
|
||||
Container-0 用户应用
|
||||
→ Container-0 eth0 (192.168.100.10)
|
||||
→ vethns0(容器侧)
|
||||
→ mesh-veth0(宿主侧,挂在 mesh-br 上)
|
||||
→ mesh-br(Linux 桥)
|
||||
→ mesh-tap-0(ns-3 TapBridge 接口)
|
||||
→ [ns-3 802.11s Mesh (HWMP) / AdHocWifiMac 处理帧]
|
||||
→ [路径损耗模型:A 是否在 B 的覆盖范围内?]
|
||||
→ [衰落模型:是否因多径而丢包?]
|
||||
→ [信道模型决定:转发 或 丢弃]
|
||||
→ mesh-tap-1(若帧通过 PHY,单跳直达)
|
||||
→ mesh-tap-中间节点(若超出单跳,HWMP 自动多跳中继)
|
||||
→ mesh-br
|
||||
→ mesh-veth1
|
||||
→ vethns1(位于 Container-1 netns)
|
||||
→ Container-1 eth0
|
||||
→ Container-1 用户应用
|
||||
```
|
||||
|
||||
### 网络隔离保证
|
||||
|
||||
| 特性 | 实现方式 |
|
||||
|------|---------|
|
||||
| 独立网络命名空间 | 每个 Docker 容器 `network_mode="none"` + veth 注入 |
|
||||
| 容器之间无直接互通 | 没有共享网桥;每节点独占 mesh-br-{i} |
|
||||
| 强制经过 ns-3 | veth 与 TAP 隔离在独立桥内,跨节点流量只能由 ns-3 转发 |
|
||||
| 唯一 IP | 每个容器分配 `192.168.100.(10+N)` |
|
||||
| 唯一 MAC | ns-3 为每个节点分配独立的 WiFi MAC |
|
||||
|
||||
> **重要提示**:`TapBridge` 工作在 `UseBridge` 模式(**L2**)。安装在 ns-3 IP 协议栈上的 AODV/OLSR/DSDV/DSR 路由协议**只能看到 ns-3 自己的控制面流量**,看不到用户载荷。多跳转发用户载荷必须由容器内的应用软件实现;ns-3 仅模拟相邻无线电之间的信道。
|
||||
|
||||
### 平台支持
|
||||
|
||||
仅支持 **linux/amd64** —— 部署目标是 x86 Ubuntu 20.04 主机或同等 Linux VM。
|
||||
|
||||
> ⚠️ **运行时仅支持 Linux**。控制器需要在容器中调用 `pyroute2` 直接操作宿主网络(创建桥、veth、TAP,移动 netns),需要 `tun` / `tap` / `bridge` 内核模块。**无法在 macOS 宿主上跑**——请用 x86 Ubuntu 20.04 或等价 Linux 主机/虚机。
|
||||
|
||||
## 快速上手
|
||||
|
||||
### 推荐路径:Docker Compose + Web 管理面板
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 1. 构建镜像
|
||||
# 1. 构建镜像(节点镜像 + 控制器镜像)
|
||||
docker compose --profile build build node-image-builder
|
||||
docker compose build controller
|
||||
|
||||
# 2. 启动控制器
|
||||
# 2. 启动控制器(FastAPI 监听 :8000,特权模式 + host 网络)
|
||||
docker compose up -d controller
|
||||
curl -s localhost:8000/api/health # {"ok":true}
|
||||
curl -s localhost:8000/api/health # → {"ok": true}
|
||||
|
||||
# 3. 启动仿真(5 节点冒烟测试)
|
||||
# 3. 浏览器打开 http://localhost:8000/ 即可使用 React 管理面板
|
||||
```
|
||||
|
||||
### 使用 GitHub 预构建镜像(无需本地编译 NS-3)
|
||||
|
||||
GitHub Actions 已自动构建并推送镜像到 `ghcr.io`:
|
||||
|
||||
```bash
|
||||
# 1. 登录 GitHub Container Registry
|
||||
# 在 https://github.com/settings/tokens 生成具有 read:packages 权限的 Personal Access Token
|
||||
export CR_PAT=<your-token>
|
||||
echo $CR_PAT | docker login ghcr.io -u <your-github-username> --password-stdin
|
||||
|
||||
# 2. 拉取镜像
|
||||
docker pull ghcr.io/clawdbuddy/manet-controller:latest
|
||||
docker pull ghcr.io/clawdbuddy/manet-node:latest
|
||||
|
||||
# 3. 节点镜像必须本地 tag 为 manet-node:latest(控制器硬编码)
|
||||
docker tag ghcr.io/clawdbuddy/manet-node:latest manet-node:latest
|
||||
|
||||
# 4. 启动控制器
|
||||
# ⚠️ --privileged 绝对不能省略,否则 pyroute2 创建网桥/TAP/veth 会报
|
||||
# NetlinkError(1, 'Operation not permitted')
|
||||
docker run -d --name controller \
|
||||
--privileged \
|
||||
--network host \
|
||||
--pid host \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /var/run/netns:/var/run/netns \
|
||||
ghcr.io/clawdbuddy/manet-controller:latest
|
||||
|
||||
# 5. 验证
|
||||
curl -s localhost:8000/api/health
|
||||
```
|
||||
|
||||
关键参数说明:
|
||||
|
||||
| 参数 | 必要性 | 说明 |
|
||||
|------|--------|------|
|
||||
| `--privileged` | **必须** | 创建 Linux bridge / TAP / veth、移动 netns 需要完整特权 |
|
||||
| `--network host` | **必须** | 控制器直接操作宿主机网络栈 |
|
||||
| `--pid host` | 推荐 | 容器内 `ps` 能看到宿主机进程,便于调试 |
|
||||
| `-v /var/run/docker.sock` | **必须** | 控制器通过 Docker API 动态创建节点容器 |
|
||||
| `-v /var/run/netns` | **必须** | `pyroute2` 创建的 netns 符号链接需要持久化到宿主机路径 |
|
||||
|
||||
Web 面板功能:
|
||||
|
||||
- **Dashboard**:仿真概览、关键指标、节点统计
|
||||
- **Configuration**:80+ 参数表单、四种场景预设、导入/导出 `.conf`
|
||||
- **Topology**:实时网络拓扑可视化(Canvas 画布)、节点列表、流统计
|
||||
- **Realtime**:控制面板 + 拓扑联合视图
|
||||
- **Logs**:实时滚动的系统日志
|
||||
|
||||
### 通过 REST 接口直接驱动
|
||||
|
||||
```bash
|
||||
# 用预设启动一次仿真
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}' # 5 节点,60 秒,无衰落
|
||||
|
||||
# 4. 打开 Web 面板
|
||||
# http://localhost:8000/
|
||||
# 查看运行状态
|
||||
curl -s localhost:8000/api/sim/status
|
||||
|
||||
# 5. 停止仿真(自动清理容器/网桥/TAP)
|
||||
# 取节点列表 / 流量统计
|
||||
curl -s localhost:8000/api/nodes
|
||||
curl -s localhost:8000/api/flows
|
||||
|
||||
# 在指定节点容器中执行命令
|
||||
curl -X POST localhost:8000/api/nodes/0/exec \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"cmd":"ip -4 addr show eth0"}'
|
||||
|
||||
# 取节点日志
|
||||
curl 'localhost:8000/api/logs?node=0&tail=50'
|
||||
|
||||
# 停止仿真(自动拆桥/拆 veth/拆 TAP/停容器)
|
||||
curl -X POST localhost:8000/api/sim/stop
|
||||
```
|
||||
|
||||
---
|
||||
### 自定义配置
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
每个节点独占一个 Linux bridge,桥接三个接口:
|
||||
|
||||
mesh-br-{id}
|
||||
├── mesh-veth{id} ← 容器 eth0(本地节点)
|
||||
├── mesh-tap-{id} → ns-3 TapBridge → MeshPointDevice → 802.11s
|
||||
└── vxlan-{id} ← 远端 VXLAN 隧道(仅 remote/host-manet 节点)
|
||||
|
||||
数据流:容器 eth0 → veth → bridge → tap → ns-3 PHY/MAC → tap → bridge → veth → 目标容器 eth0
|
||||
```
|
||||
|
||||
### 节点部署模式
|
||||
|
||||
| 模式 | host 值 | hostType | 说明 |
|
||||
|------|---------|----------|------|
|
||||
| 本地容器 | `"local"` | `"container"` | Docker 容器,eth0 → veth → tap → ns-3 |
|
||||
| 远端主机节点 | `"<IP>"` | `"host-manet"` | SSH 启动容器(`--net=host`),VXLAN 隧道跨主机 |
|
||||
| 远端容器 | `"<IP>"` | `"container"` | SSH 启动容器,VXLAN 隧道跨主机 |
|
||||
|
||||
### VXLAN 隧道(远端节点)
|
||||
|
||||
```
|
||||
远端主机 控制器主机
|
||||
vxlan-{id} ← UDP/4789 → vxlan-{id}
|
||||
VNI=100+id ↓
|
||||
MTU=1400 mesh-br-{id} → mesh-tap-{id} → ns-3
|
||||
IP=MANET_IP/24
|
||||
|
||||
隧道端点自动选取同一 L2 子网 IP(如 192.168.50.x),避免 NAT。
|
||||
静态 ARP 条目在启动时自动注入。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 节点管理
|
||||
|
||||
### 注册远端主机
|
||||
|
||||
```bash
|
||||
curl -X POST localhost:8000/api/hosts/register \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"ip": "100.100.100.9",
|
||||
"sshUser": "binnary",
|
||||
"sshKey": "-----BEGIN OPENSSH PRIVATE KEY-----\n...",
|
||||
"capacity": 1
|
||||
}'
|
||||
```
|
||||
|
||||
### 配置节点规格
|
||||
|
||||
```bash
|
||||
# 查看当前规格
|
||||
curl -s localhost:8000/api/nodes/specs | jq
|
||||
|
||||
# 更新规格
|
||||
curl -X PUT localhost:8000/api/nodes/specs \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"specs": [
|
||||
{"id": 0, "ip": "192.168.100.10", "role": "server", "host": "local"},
|
||||
{"id": 1, "ip": "192.168.100.11", "role": "server",
|
||||
"host": "100.100.100.9", "hostType": "host-manet"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
### 启动含远端节点的仿真
|
||||
通过 REST 传入 `config` 字段即可覆盖任意参数(命名采用 camelCase,与 `manet-30ns3/web-manager/src/types/config.ts` 一致):
|
||||
|
||||
```bash
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"config": {
|
||||
"nNodes": 5, "simulationTime": 180,
|
||||
"standard": "80211n-2.4GHz",
|
||||
"macMode": "mesh",
|
||||
"mobilityModel": "grid",
|
||||
"gridDeltaX": 50, "gridWidth": 5,
|
||||
"txPowerStart": 20, "pathLossModel": "FreeSpace"
|
||||
},
|
||||
"nodes": [
|
||||
{"id": 0, "ip": "192.168.100.10", "role": "server", "host": "local"},
|
||||
{"id": 1, "ip": "192.168.100.11", "role": "server",
|
||||
"host": "100.100.100.9", "hostType": "host-manet"},
|
||||
{"id": 2, "ip": "192.168.100.12", "role": "client", "host": "local"},
|
||||
{"id": 3, "ip": "192.168.100.13", "role": "client", "host": "local"},
|
||||
{"id": 4, "ip": "192.168.100.14", "role": "client", "host": "local"}
|
||||
]
|
||||
}'
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"preset": "default",
|
||||
"config": {
|
||||
"nNodes": 20,
|
||||
"simulationTime": 180,
|
||||
"txPowerStart": 22,
|
||||
"pathLossExponent": 2.5,
|
||||
"routingProtocol": "olsr",
|
||||
"mobilityModel": "gauss-markov"
|
||||
},
|
||||
"nodes": [
|
||||
{"id": 0, "userAppMode": "exec"},
|
||||
{"id": 1, "userAppMode": "bind", "userAppBindPath": "/host/path/to/app"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
> **注意**:远端节点默认使用 `ghcr.io/clawdbuddy/host-manet-node:main` 镜像。
|
||||
> 控制器需 `--pid host`(docker-compose 已配置 `pid: host`)以访问宿主机 PID 空间。
|
||||
|
||||
---
|
||||
|
||||
## 测试
|
||||
|
||||
### WiFi 自动化测试套件
|
||||
也可以通过 `PUT /api/config` 暂存"下一轮"配置:
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 运行全部 8 个测试用例
|
||||
python3 tests/wifi_test_suite.py
|
||||
|
||||
# 运行单个测试
|
||||
python3 tests/wifi_test_suite.py tc_frequency_2_4g
|
||||
|
||||
# 生成测试报告
|
||||
python3 tests/generate_report.py
|
||||
# → test-results/wifi_test_report.md
|
||||
curl -X PUT localhost:8000/api/config \
|
||||
-H 'content-type: application/json' \
|
||||
-d @my-config.json
|
||||
```
|
||||
|
||||
| 用例 | 说明 |
|
||||
|------|------|
|
||||
| `tc_frequency_2_4g` | 2.4GHz 频段连通性 |
|
||||
| `tc_frequency_5g` | 5GHz 频段连通性 |
|
||||
| `tc_bandwidth_20m` | 20MHz 带宽吞吐 |
|
||||
| `tc_bandwidth_40m` | 40MHz 带宽吞吐 |
|
||||
| `tc_distance_attenuation` | 距离衰减(500-2000m) |
|
||||
| `tc_adhoc_multihop` | 10 节点多跳 |
|
||||
| `tc_broadcast` | 广播覆盖 |
|
||||
| `tc_frequency_sweep` | 多信道遍历 |
|
||||
> 仿真运行中 `PUT /api/config` 会被拒绝;先 stop 再下发。
|
||||
|
||||
### 后端单元测试
|
||||
## 配置预设
|
||||
|
||||
预设定义在 `controller/orchestrator/config.py:PRESETS`,并通过 `GET /api/sim/presets` 暴露:
|
||||
|
||||
| Preset | 适用场景 | 关键设置 |
|
||||
|--------|----------|----------|
|
||||
| `default` | 用户目标场景(adhoc) | AdhocWifiMac + SpectrumWifiPhy + Friis @ 2412 MHz WiFi + 6 节点 + 5 km × 5 km + 4 km LOS + AODV |
|
||||
| `urban` | 高密度城市(mesh) | LogDistance n=3.5、Nakagami 强衰落、Aarf、始终 RTS/CTS、2 km × 2 km |
|
||||
| `rural` | 开阔野外(mesh) | FreeSpace、关闭衰落、Grid 8 km × 8 km、关闭 RTS/CTS |
|
||||
| `debug` | 5 节点冒烟测试(adhoc) | adhoc 模式、routing=none、Grid 5×5 / 50 m 间距、200 m 视距、ASCII trace |
|
||||
|
||||
## 完整参数参考
|
||||
|
||||
> 参数权威源在 `controller/orchestrator/config.py:SimConfig`(Pydantic v2 模型,camelCase 别名);`manet-30ns3/web-manager/src/types/config.ts` 与之对齐。
|
||||
|
||||
### 通用参数
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `nNodes` | 6 | AdHoc 节点数(2–16) |
|
||||
| `simulationTime` | 300 | 仿真时长(秒) |
|
||||
| `seed` | 1 | 随机种子 |
|
||||
| `run` | 1 | run 编号 |
|
||||
| `logComponents` | "" | 逗号分隔的 `NS_LOG` 组件 |
|
||||
|
||||
### PHY(物理层)
|
||||
|
||||
| 参数 | 默认值 | 取值 |
|
||||
|------|--------|------|
|
||||
| `standard` | `80211g` | `80211b`、`80211a`、`80211g`、`80211n-2.4GHz`、`80211n-5GHz`、`80211ac`、`80211ax-2.4GHz`、`80211ax-5GHz` |
|
||||
| `phyModel` | `spectrum` | `yans` 或 `spectrum`(默认走 `SpectrumWifiPhy + MultiModelSpectrumChannel`) |
|
||||
| `frequencyMhz` | 2412 | 中心频率(MHz);默认 2.4 GHz WiFi Channel 1 (2412 MHz),路径损耗按此频率算 |
|
||||
| `channelWidthMhz` | 20 | 信道带宽(MHz) |
|
||||
| `rangeTargetM` | 4000 | 期望视距覆盖半径(m),用于显示与冒烟检查 |
|
||||
| `dataRate` | `ErpOfdmRate24Mbps` | 任意 ns-3 wifi mode 字符串 |
|
||||
| `txPowerStart` / `txPowerEnd` | 30.0 | 发射功率(dBm) |
|
||||
| `txPowerLevels` | 1 | 功率级数 |
|
||||
| `rxSensitivity` | -92.0 | 接收灵敏度(dBm) |
|
||||
| `ccaThreshold` | -82.0 | CCA 能量检测门限(dBm) |
|
||||
| `antennaGain` | 3.0 | 天线增益(dBi) |
|
||||
|
||||
### 传播模型
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `propagationDelay` | `ConstantSpeed` | `ConstantSpeed` 或 `Random` |
|
||||
| `pathLossModel` | `FreeSpace` | `LogDistance`、`FreeSpace`、`TwoRayGround`、`ThreeLogDistance`、`Cost231`、`Range`(`spectrum` PHY 默认 Friis @ 2412 MHz) |
|
||||
| `pathLossExponent` | 2.0 | 路径损耗指数 n(2 = 自由空间,3 = 城市,4 = 高密度城市) |
|
||||
| `pathLossRefLoss` | 46.6777 | 1m 处参考损耗(dB) |
|
||||
| `pathLossRefDistance` | 1.0 | 参考距离(m) |
|
||||
| `enableFading` | false | 是否启用衰落(mesh 默认关闭,让 4 km 视距预算稳定) |
|
||||
| `fadingModel` | `Nakagami` | `Nakagami` 或 `Jakes` |
|
||||
| `nakagamiM0` | 1.5 | d < d1 段的 m 因子(m<1 严重,m=1 Rayleigh,m>2 轻) |
|
||||
| `nakagamiM1` | 1.0 | d1 < d < d2 段的 m 因子 |
|
||||
| `nakagamiM2` | 0.75 | d > d2 段的 m 因子 |
|
||||
| `nakagamiD1` | 50.0 | 距离边界 1(m) |
|
||||
| `nakagamiD2` | 100.0 | 距离边界 2(m) |
|
||||
|
||||
### MAC
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `macMode` | `adhoc` | `mesh`(802.11s + HWMP,L2 多跳)或 `adhoc`(IBSS,单跳广播域,多跳由上层路由完成) |
|
||||
| `ssid` | `adhoc-30ns3` | IBSS / mesh 网络名 |
|
||||
| `bssid` | `00:00:00:00:AD:H0` | IBSS BSSID(hex,仅 `adhoc` 模式) |
|
||||
| `rateControl` | `Arf` | `Arf`、`Aarf`、`Onoe`、`Constant`、`Minstrel` |
|
||||
| `rtsCtsThreshold` | 2200 | RTS/CTS 阈值(字节,**65535 = 关闭**) |
|
||||
| `fragmentationThreshold` | 2200 | 最大分片字节 |
|
||||
| `nonUnicastMode` | false | 广播/组播是否走固定速率 |
|
||||
| `beaconInterval` | 100 | Beacon 间隔(TU,1 TU = 1024 µs) |
|
||||
| `cwMin` | 15 | 最小竞争窗口 |
|
||||
| `cwMax` | 1023 | 最大竞争窗口 |
|
||||
|
||||
### 路由协议
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `routingProtocol` | `aodv` | `aodv`、`olsr`、`dsdv`、`dsr`、`none` |
|
||||
| **AODV** | | |
|
||||
| `aodvHelloInterval` | 1.0 | Hello 间隔(秒) |
|
||||
| `aodvRreqRetries` | 2 | RREQ 重试次数 |
|
||||
| `aodvActiveRouteTimeout` | 3.0 | 路由过期时间(秒) |
|
||||
| `aodvDeletePeriod` | 5.0 | 路由删除周期(秒) |
|
||||
| `aodvNetDiameter` | 35 | 期望网络直径(跳数) |
|
||||
| `aodvEnableHello` | true | 是否启用 hello |
|
||||
| **OLSR** | | |
|
||||
| `olsrHelloInterval` | 2.0 | Hello 间隔(秒) |
|
||||
| `olsrTcInterval` | 5.0 | TC 间隔(秒) |
|
||||
| `olsrWillingness` | 7 | MPR willingness(0–7) |
|
||||
| **DSDV** | | |
|
||||
| `dsdvPeriodicUpdateInterval` | 15.0 | 周期更新间隔(秒) |
|
||||
| `dsdvSettlingTime` | 6 | settling 时间倍数 |
|
||||
|
||||
### 移动模型
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `mobilityModel` | `random-walk` | `random-walk`、`gauss-markov`、`grid`、`constant` |
|
||||
| `mobilityMinX/MaxX` | 0.0/5000.0 | X 方向边界(m) |
|
||||
| `mobilityMinY/MaxY` | 0.0/5000.0 | Y 方向边界(m) |
|
||||
| **RandomWalk** | | |
|
||||
| `rwMinSpeed` / `rwMaxSpeed` | 0.5/3.0 | 速度区间(m/s) |
|
||||
| `rwDistance` | 200.0 | 转向前的距离(m) |
|
||||
| `rwMode` | `Time` | `Time` 或 `Distance` |
|
||||
| `rwTime` | 1.0 | 时间步长(s) |
|
||||
| **Grid** | | |
|
||||
| `gridDeltaX/Y` | 800.0/800.0 | 网格间距(m) |
|
||||
| `gridWidth` | 6 | 每行节点数 |
|
||||
| **GaussMarkov** | | |
|
||||
| `gmAlpha` | 0.85 | 记忆因子(0–1,越大相关性越强) |
|
||||
|
||||
### 跟踪 / 输出
|
||||
|
||||
| 参数 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `pcap` | true | 每节点 PCAP 抓包 |
|
||||
| `ascii` | false | ASCII 跟踪 |
|
||||
| `flowMonitor` | true | FlowMonitor 统计 |
|
||||
| `pcapPrefix` | `manet-30nodes-adhoc` | PCAP 文件名前缀 |
|
||||
| `enableMobilityTrace` | false | 移动 ASCII trace |
|
||||
|
||||
> **历史命名注意**:`pcap` / `ascii` 在旧版 `.conf` 中曾叫 `pcapTracing` / `asciiTracing`,旧 C++ 解析器会把它们静默丢弃。现在的 Python 解析器(`parse_conf_file`)显式接受这两个旧别名并自动转换。
|
||||
|
||||
## 用户软件加载模式(R7)
|
||||
|
||||
每个节点容器通过环境变量 `USER_APP_MODE` 选择加载方式(在 `nodes` 数组中按节点指定):
|
||||
|
||||
| 模式 | 机制 | 适用 |
|
||||
|------|------|------|
|
||||
| `bind` | bind 挂载用户目录到 `/opt/userapp`,运行 `${USER_APP_CMD:-/opt/userapp/run.sh}` | 迭代开发,宿主侧改代码即可 |
|
||||
| `image` | 以用户镜像启动;入口脚本检测 `/opt/userapp/run.sh` 已存在 | 可复现的打包软件 |
|
||||
| `exec`/`ssh` | 容器空转(sshd 或 `tail -f`);后端通过 `docker exec` / `ssh` 推送二进制 | 演示 / 运行时下发 |
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# API 路由测试(Mock 模式,无需 Docker)
|
||||
python3 -m pytest controller/tests/test_api_routes.py -v
|
||||
|
||||
# Docker 管理器测试
|
||||
python3 -m pytest controller/tests/test_docker_mgr.py -v
|
||||
|
||||
# 网络操作测试
|
||||
python3 -m pytest controller/tests/test_netns.py -v
|
||||
```
|
||||
|
||||
### 前端检查
|
||||
|
||||
```bash
|
||||
cd manet-30ns3/web-manager
|
||||
npm run lint
|
||||
npm run build # tsc + vite build
|
||||
```
|
||||
|
||||
### 手动端到端验证
|
||||
|
||||
```bash
|
||||
# 1. 启动 5 节点仿真(4 本地 + 1 远程)
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
|
||||
# 2. 检查节点状态
|
||||
curl -s localhost:8000/api/nodes | jq
|
||||
|
||||
# 3. 连通性测试
|
||||
curl -s -X POST localhost:8000/api/nodes/0/exec \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"cmd":"ping -c 4 192.168.100.11"}'
|
||||
|
||||
# 4. 吞吐测试
|
||||
curl -s -X POST localhost:8000/api/nodes/0/exec \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"cmd":"iperf3 -c 192.168.100.11 -t 5"}'
|
||||
|
||||
# 5. 停止
|
||||
curl -X POST localhost:8000/api/sim/stop
|
||||
|
||||
# 6. 验证清理
|
||||
ip link | grep -E 'mesh-|vxlan-' || echo "clean"
|
||||
-H 'content-type: application/json' \
|
||||
-d '{
|
||||
"preset":"debug",
|
||||
"nodes":[
|
||||
{"id":0,"userAppMode":"bind","userAppBindPath":"/opt/myapp"},
|
||||
{"id":1,"userAppMode":"image","image":"my/app:latest"},
|
||||
{"id":2,"userAppMode":"exec","sshEnable":false}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## REST API 速查
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/api/health` | 健康检查 |
|
||||
| POST | `/api/sim/start` | 启动仿真(body: RunRequest) |
|
||||
| POST | `/api/sim/stop` | 停止仿真 |
|
||||
| GET | `/api/sim/status` | 仿真状态 |
|
||||
| GET | `/api/sim/presets` | 预设列表 |
|
||||
| GET | `/api/nodes` | 节点状态列表 |
|
||||
| GET | `/api/flows` | 流量统计 |
|
||||
| POST | `/api/nodes/{id}/exec` | 在节点中执行命令 |
|
||||
| GET | `/api/logs?node={id}` | 查看节点日志 |
|
||||
| GET | `/api/config` | 获取当前配置 |
|
||||
| PUT | `/api/config` | 更新配置 |
|
||||
| POST | `/api/hosts/register` | 注册远端主机 |
|
||||
| GET | `/api/hosts` | 主机列表 |
|
||||
| DELETE | `/api/hosts/{ip}` | 删除主机 |
|
||||
| GET | `/api/nodes/specs` | 节点规格列表 |
|
||||
| PUT | `/api/nodes/specs` | 更新节点规格 |
|
||||
| WS | `/ws/telemetry` | 实时遥测(5Hz) |
|
||||
|
||||
### 预设
|
||||
|
||||
| 预设 | 场景 | 参数 |
|
||||
|------|------|------|
|
||||
| `debug` | 5 节点冒烟 | mesh, grid 50m, FreeSpace, Tx=20dBm |
|
||||
| `default` | 用户目标 | mesh, 5000x5000, FreeSpace, Tx=30dBm |
|
||||
| `urban` | 高密度城市 | mesh, LogDistance n=3.5, Nakagami, 2km |
|
||||
| `rural` | 开阔野外 | mesh, FreeSpace, Grid 8km, 无衰落 |
|
||||
| `tactical` | 战术通信 | mesh, UHF 590MHz, TwoRayGround, Tx=37dBm |
|
||||
|
||||
---
|
||||
|
||||
## 目录结构
|
||||
## 文件结构
|
||||
|
||||
```
|
||||
manet-30ns3/
|
||||
├── controller/
|
||||
│ ├── api/ # FastAPI 路由(sim/nodes/config/hosts)
|
||||
│ ├── orchestrator/ # 核心:config/netns/docker_mgr/host_node_mgr/sim_runner
|
||||
│ └── tests/ # 后端单元测试
|
||||
├── node/ # 节点 Dockerfile + node-entrypoint.py
|
||||
├── web-manager/ # React 19 + Vite + TypeScript 前端
|
||||
├── tests/ # WiFi 自动化测试套件 + 报告生成器
|
||||
│ ├── wifi_test_suite.py
|
||||
│ ├── generate_report.py
|
||||
│ └── docs/ # 测试用例文档
|
||||
├── config/ # 运行时持久化(host_registry.json, node_specs.json)
|
||||
├── docker-compose.yml
|
||||
└── results/ # PCAP / ASCII trace 输出
|
||||
├─ controller/ # Python 控制器(主路径)
|
||||
│ ├─ orchestrator/ # config / netns / docker_mgr / sim_runner / telemetry
|
||||
│ └─ api/ # FastAPI 应用 + REST 路由 + /ws/telemetry
|
||||
├─ controller/ # 控制器 Dockerfile(含 NS-3.45 + Python 绑定)
|
||||
├─ node/ # 节点 Dockerfile + node-entrypoint.py
|
||||
├─ web-manager/ # React 19 + Vite + TS 源码 + 由 `npm run build` 产出的 dist/
|
||||
├─ docker-compose.yml # 控制器 + 节点镜像构建目标
|
||||
│
|
||||
└─ ns3-code/ # ⚠ 旧版 C++ scratch 程序(仅作历史参考)
|
||||
```
|
||||
|
||||
---
|
||||
## 多机部署(Phase 2,已设计未实现)
|
||||
|
||||
单机 MVP 是当前已落地形态。多机方案:
|
||||
|
||||
- 选定一台主机跑 ns-3 控制器,独占 `mesh-br` 与所有 TAP。
|
||||
- 其它主机仅跑节点容器;它们的 `mesh-veth*-h` 不接本地桥,而是接到 VXLAN 网卡,把 L2 平面延伸到控制器主机的 `mesh-br`。
|
||||
- 控制器主机:对每个远端 peer 执行 `bridge fdb append … dst <peer-ip> via vxlan100`;`netns.py` 与 `docker_mgr.py` 增加 `host` 参数,`POST /api/hosts/register` 用于远端注册。
|
||||
- 仍只有一个 ns-3 进程,仿真时间与 PHY 模型一致。
|
||||
|
||||
详见 `/Users/clawdbuddy/.claude/plans/melodic-puzzling-pebble.md` §9。
|
||||
|
||||
## 端到端验证(仅 Linux)
|
||||
|
||||
```bash
|
||||
cd manet-30ns3
|
||||
|
||||
# 1. 构建
|
||||
docker compose --profile build build node-image-builder
|
||||
docker compose build controller
|
||||
# 预期:controller 镜像内 `python3 -c "from ns import ns"` 成功导入
|
||||
|
||||
# 2. 起服
|
||||
docker compose up -d controller
|
||||
curl -s localhost:8000/api/health # {"ok": true}
|
||||
|
||||
# 3. 启动 5 节点冒烟
|
||||
curl -X POST localhost:8000/api/sim/start \
|
||||
-H 'content-type: application/json' \
|
||||
-d '{"preset":"debug"}'
|
||||
ip link | grep -E 'mesh-br|mesh-tap|mesh-veth' # 应能看到 mesh-br、5 个 mesh-tap-{i}、5 个 mesh-veth{i}
|
||||
docker ps | grep manet-node # 5 个节点容器
|
||||
|
||||
# 4. 连通性
|
||||
docker exec manet-node-0 ping -c 3 192.168.100.11
|
||||
docker exec manet-node-0 iperf3 -c 192.168.100.14 -t 5
|
||||
|
||||
# 5. 遥测
|
||||
# 打开 http://localhost:8000/ → React UI 加载
|
||||
# Topology 页显示 5 个节点;iperf3 起来约 10 秒后 FlowStats 更新
|
||||
|
||||
# 6. 拆除
|
||||
curl -X POST localhost:8000/api/sim/stop
|
||||
ip link | grep -E 'mesh-br|mesh-tap|mesh-veth' || echo "clean"
|
||||
```
|
||||
|
||||
## 构建缓存
|
||||
|
||||
两个 Dockerfile(`node/Dockerfile.node`、`controller/Dockerfile.controller`)都使用 `ccache`(挂载到 `/ccache`,10 GB 上限),第二次起的构建会快很多。
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Docker ≥ 20.10
|
||||
- Linux 内核加载 `tun`、`tap`、`bridge`
|
||||
- **x86_64**(linux/amd64)宿主
|
||||
|
||||
| 资源 | 推荐 | 备注 |
|
||||
|------|------|------|
|
||||
| CPU | 4 核+ | `pip install ns3` 期间可能编译少量扩展 |
|
||||
| 内存 | 4 GB+ | 镜像构建峰值会用到 ~3 GB |
|
||||
| 编译耗时 | ~5–10 min | ccache 命中后通常 < 1 min |
|
||||
|
||||
## 故障排查
|
||||
|
||||
| 现象 | 排查 |
|
||||
|------|------|
|
||||
| 远端容器未启动 | 检查 `node_specs.json` 中节点 `host` 和 `hostType` 是否正确配置 |
|
||||
| docker pull 403 | daocloud 镜像代理限制 → 使用 GHCR 全路径镜像名 |
|
||||
| VXLAN 不通 | 检查两端 LAN IP 是否在同一子网(`ip route get 8.8.8.8`) |
|
||||
| ping 丢包 | 检查 ARP 表(`arp -n`),静态 ARP 是否注入 |
|
||||
| `--privileged` 缺失 | pyroute2 创建网桥/TAP 时报 `NetlinkError(1, 'Operation not permitted')` |
|
||||
| 容器残留 | `docker rm -f $(docker ps -aq --filter name=manet-node)` |
|
||||
| `/api/health` 返回错误 | `docker logs controller` 看是否绑定 socket / 启动成功 |
|
||||
| 容器之间不通 | 仿真未启动;ns-3 不跑时桥本身不会转发——属于设计内行为 |
|
||||
| `ip link` 看不到 `mesh-br` | 仿真未启动,或控制器创建桥失败(缺权限/缺内核模块) |
|
||||
| ns-3 build 出错 `unknown module` | 重建控制器镜像:`docker compose build --no-cache controller` |
|
||||
| 吞吐 0 | 试试 `rtsCtsThreshold=65535`、检查 `pathLossExponent` 是否过大 |
|
||||
| 仿真很慢 | 减小 `nNodes`、用 `mobilityModel=grid`、关掉 `ascii` |
|
||||
| `exec format error` | 镜像是为 amd64 构建的;确认主机也是 x86_64 |
|
||||
| `NetlinkError(1, 'Operation not permitted')` | 容器缺少 `--privileged`。删除容器后重新用 `--privileged` 启动 |
|
||||
| ccache 不生效 | 检查 `CCACHE_DIR` 卷挂载(`-v /ccache:/ccache`) |
|
||||
|
||||
---
|
||||
## 许可证
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Docker ≥ 20.10, Linux x86_64
|
||||
- 内核模块:`tun`, `tap`, `bridge`
|
||||
- CPU ≥ 4 核, 内存 ≥ 4 GB
|
||||
- 控制器需 `--privileged --network host --pid host`
|
||||
NS-3 部分代码遵循 GPLv2。本项目作为配置/参考实现提供。
|
||||
@@ -23,6 +23,6 @@
|
||||
"pathLossExponent": 2.0,
|
||||
"frequencyMhz": 2412,
|
||||
"channelWidthMhz": 20,
|
||||
"rangeTargetM": 500.0,
|
||||
"rangeTargetM": 3400.0,
|
||||
"pathLossModel": "FreeSpace"
|
||||
}
|
||||
@@ -217,14 +217,12 @@ class HostNodeMgr:
|
||||
name, self.host_ip, spec.image, spec.ip)
|
||||
|
||||
# 3) docker run (--net=host, --privileged)
|
||||
# Map local image names to GHCR host-manet-node images.
|
||||
# If the caller specifies a custom image (e.g. GHCR path), use it as-is.
|
||||
image = spec.image or "manet-node:latest"
|
||||
if image in ("manet-node:latest", "host-manet-node:latest"):
|
||||
# If spec.image is the default container image, use the host-specific one.
|
||||
# Otherwise trust the caller's image choice (e.g. GHCR path).
|
||||
if spec.image == "manet-node:latest":
|
||||
image = "ghcr.io/clawdbuddy/host-manet-node:main"
|
||||
# v1.1.4+ tagged images
|
||||
if image == "host-manet-node:1.1.4":
|
||||
image = "ghcr.io/clawdbuddy/host-manet-node:1.1.4"
|
||||
else:
|
||||
image = spec.image
|
||||
# Auto-pull if not present
|
||||
self._exec(f"docker images -q {image} 2>/dev/null | grep -q . || docker pull {image}")
|
||||
run_cmd = (
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
"""Integration tests for FastAPI REST routes.
|
||||
|
||||
Uses FastAPI's TestClient — no real network, no real Docker, no real ns-3.
|
||||
Mocks the Session singleton so tests are fully isolated from state.py.
|
||||
|
||||
Covers: TC-API-001 through TC-API-015.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch, AsyncMock
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from controller.orchestrator.config import PRESETS
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Mock helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class MockSim:
|
||||
elapsed = 45.0
|
||||
mac_mode_actual = "mesh"
|
||||
|
||||
def find_path(self, src, dst):
|
||||
if src == 0 and dst == 4:
|
||||
return [0, 2, 4]
|
||||
return None
|
||||
|
||||
|
||||
class MockSpecs:
|
||||
def __init__(self, n=5):
|
||||
self._specs = [
|
||||
MagicMock(id=i, ip=f"192.168.100.{10+i}") for i in range(n)
|
||||
]
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._specs)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._specs)
|
||||
|
||||
|
||||
def make_mock_session(**overrides):
|
||||
sess = MagicMock()
|
||||
sess.running = False
|
||||
sess.config = MagicMock()
|
||||
sess.config.n_nodes = 5
|
||||
sess.config.routing_protocol = "aodv"
|
||||
sess.preset = "debug"
|
||||
sess.sim = None
|
||||
sess.specs = MockSpecs()
|
||||
sess.docker_mgr = None
|
||||
sess.host_mgrs = {}
|
||||
sess.remote_mgrs = {}
|
||||
# Use AsyncMock so the await in routes_sim.py works without hitting real code
|
||||
sess.start = AsyncMock(return_value=None)
|
||||
sess.stop = AsyncMock(return_value=None)
|
||||
for k, v in overrides.items():
|
||||
setattr(sess, k, v)
|
||||
return sess
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# No-op lifespan avoids UDP port binding
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@asynccontextmanager
|
||||
async def _stub_lifespan(app):
|
||||
yield
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Test cases
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestHealth:
|
||||
def test_health_returns_ok(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
with patch("controller.api.state.get_session", return_value=make_mock_session()):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"ok": True}
|
||||
|
||||
|
||||
class TestSimStart:
|
||||
"""Test POST /api/sim/start endpoint.
|
||||
|
||||
Mocks:
|
||||
- sess.start: prevents actual simulation startup
|
||||
- _reap_orphans: prevents netlink calls inside state.py
|
||||
- list_stale_links: prevents netlink calls inside state.py
|
||||
"""
|
||||
|
||||
def _start_sim(self, mock_sess):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
# Patch where the local binding is used (routes_sim.py), not just where
|
||||
# get_session is defined. This is needed because routes_sim does:
|
||||
# "from controller.api.state import get_session"
|
||||
# which creates a local reference that must also be patched.
|
||||
with patch("controller.api.state._reap_orphans"):
|
||||
with patch("controller.api.state.list_stale_links", return_value=[]):
|
||||
with patch("controller.api.routes_sim.get_session", return_value=mock_sess):
|
||||
with patch("controller.api.state.get_session", return_value=mock_sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.post("/api/sim/start", json={})
|
||||
return response, mock_sess
|
||||
|
||||
def test_start_sim_returns_ok(self):
|
||||
response, _ = self._start_sim(make_mock_session(running=False))
|
||||
assert response.status_code == 200
|
||||
assert response.json()["ok"] is True
|
||||
|
||||
def test_start_sim_already_running_returns_409(self):
|
||||
response, _ = self._start_sim(make_mock_session(running=True))
|
||||
assert response.status_code == 409
|
||||
|
||||
def test_start_sim_with_unknown_preset_returns_400(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=False)
|
||||
sess.start.side_effect = KeyError("unknown preset")
|
||||
with patch("controller.api.state._reap_orphans"):
|
||||
with patch("controller.api.state.list_stale_links", return_value=[]):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.post(
|
||||
"/api/sim/start",
|
||||
json={"preset": "nonexistent_preset_xyz"},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_start_sim_with_valid_preset(self):
|
||||
response, _ = self._start_sim(make_mock_session(running=False))
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_start_sim_with_config_override(self):
|
||||
sess = make_mock_session(running=False)
|
||||
response, _ = self._start_sim(sess)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
class TestSimStop:
|
||||
def test_stop_sim_returns_ok(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session()
|
||||
with patch("controller.api.state._reap_orphans"):
|
||||
with patch("controller.api.state.list_stale_links", return_value=[]):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.post("/api/sim/stop")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["ok"] is True
|
||||
|
||||
|
||||
class TestSimStatus:
|
||||
def test_status_returns_running_false(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=False)
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/status")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["running"] is False
|
||||
|
||||
def test_status_returns_running_true(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=True, sim=MockSim())
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/status")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["running"] is True
|
||||
assert response.json()["elapsed"] == 45.0
|
||||
|
||||
|
||||
class TestSimPresets:
|
||||
def test_presets_returns_dict(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session()
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/presets")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "debug" in data
|
||||
assert "default" in data
|
||||
assert "tactical" in data
|
||||
|
||||
def test_all_presets_have_required_keys(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session()
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/presets")
|
||||
required_keys = {"nNodes", "macMode", "routingProtocol", "simulationTime"}
|
||||
for name, preset in response.json().items():
|
||||
missing = required_keys - set(preset.keys())
|
||||
assert not missing, f"preset '{name}' missing keys: {missing}"
|
||||
|
||||
|
||||
class TestSimPath:
|
||||
def test_path_returns_bfs_result(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=True, sim=MockSim())
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/path?src=0&dst=4")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["reachable"] is True
|
||||
assert data["hops"] == 2
|
||||
assert data["path"] == [0, 2, 4]
|
||||
|
||||
def test_path_no_sim_returns_409(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=False, sim=None)
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/path?src=0&dst=1")
|
||||
assert response.status_code == 409
|
||||
|
||||
def test_path_unreachable_returns_reachable_false(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=True, sim=MockSim())
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/path?src=0&dst=99")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["reachable"] is False
|
||||
assert data["hops"] == -1
|
||||
|
||||
def test_path_includes_ips(self):
|
||||
from controller.api.main import app
|
||||
app.router.lifespan_context = _stub_lifespan
|
||||
sess = make_mock_session(running=True, sim=MockSim())
|
||||
with patch("controller.api.routes_sim.get_session", return_value=sess):
|
||||
with patch("controller.api.state.get_session", return_value=sess):
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/api/sim/path?src=0&dst=4")
|
||||
data = response.json()
|
||||
assert "ips" in data
|
||||
assert len(data["ips"]) == len(data["path"])
|
||||
@@ -1,162 +0,0 @@
|
||||
"""Unit tests for controller/orchestrator/docker_mgr.py.
|
||||
|
||||
Docker SDK calls are patched with mocks so these run anywhere.
|
||||
Real Docker/netns operations require a privileged Linux environment
|
||||
and are covered by E2E tests (TC-E2E-*).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from controller.orchestrator.docker_mgr import DockerMgr, RuntimeNode, CONTAINER_PREFIX
|
||||
from controller.orchestrator.config import NodeSpec, SimConfig
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_docker_client():
|
||||
return MagicMock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def docker_mgr(mock_docker_client):
|
||||
return DockerMgr(client=mock_docker_client)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_spec():
|
||||
return NodeSpec(id=0, ip="192.168.100.10", role="client")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_config():
|
||||
return SimConfig(n_nodes=5)
|
||||
|
||||
|
||||
def _make_runtime_node(node_id: int = 0, container_id: str = "c123") -> RuntimeNode:
|
||||
return RuntimeNode(
|
||||
spec=NodeSpec(id=node_id, ip=f"192.168.100.{10+node_id}"),
|
||||
container_id=container_id,
|
||||
pid=12345,
|
||||
name=f"manet-node-{node_id}",
|
||||
)
|
||||
|
||||
|
||||
class TestRuntimeNode:
|
||||
def test_runtime_node_fields(self):
|
||||
rn = RuntimeNode(
|
||||
spec=NodeSpec(id=1, ip="192.168.100.11"),
|
||||
container_id="abc123",
|
||||
pid=12345,
|
||||
name="manet-node-1",
|
||||
)
|
||||
assert rn.spec.id == 1
|
||||
assert rn.container_id == "abc123"
|
||||
assert rn.pid == 12345
|
||||
|
||||
|
||||
class TestDockerMgrInit:
|
||||
def test_uses_provided_client(self, mock_docker_client):
|
||||
mgr = DockerMgr(client=mock_docker_client)
|
||||
assert mgr.client is mock_docker_client
|
||||
|
||||
def test_empty_nodes_on_init(self, docker_mgr):
|
||||
assert docker_mgr._nodes == {}
|
||||
|
||||
def test_status_cache_empty_on_init(self, docker_mgr):
|
||||
assert docker_mgr._status_cache == {}
|
||||
|
||||
|
||||
class TestIsRunning:
|
||||
def test_returns_true_for_running_container(self, docker_mgr, mock_docker_client):
|
||||
docker_mgr._nodes[0] = _make_runtime_node(0, "container-0")
|
||||
mock_container = MagicMock()
|
||||
mock_container.status = "running"
|
||||
mock_docker_client.containers.get.return_value = mock_container
|
||||
|
||||
assert docker_mgr.is_running(0) is True
|
||||
mock_docker_client.containers.get.assert_called_once_with("container-0")
|
||||
|
||||
def test_returns_false_for_missing_container(self, docker_mgr, mock_docker_client):
|
||||
docker_mgr._nodes[99] = _make_runtime_node(99, "container-99")
|
||||
from docker.errors import NotFound
|
||||
mock_docker_client.containers.get.side_effect = NotFound("not found")
|
||||
assert docker_mgr.is_running(99) is False
|
||||
|
||||
def test_returns_false_for_stopped_container(self, docker_mgr, mock_docker_client):
|
||||
docker_mgr._nodes[0] = _make_runtime_node(0, "container-0")
|
||||
mock_container = MagicMock()
|
||||
mock_container.status = "exited"
|
||||
mock_docker_client.containers.get.return_value = mock_container
|
||||
assert docker_mgr.is_running(0) is False
|
||||
|
||||
def test_returns_false_for_unknown_node_id(self, docker_mgr, mock_docker_client):
|
||||
# Never touches Docker API when node not tracked
|
||||
assert docker_mgr.is_running(999) is False
|
||||
mock_docker_client.containers.get.assert_not_called()
|
||||
|
||||
def test_cache_hit_avoids_docker_api(self, docker_mgr, mock_docker_client):
|
||||
docker_mgr._nodes[0] = _make_runtime_node(0, "container-0")
|
||||
# Pre-populate cache to simulate recent status check
|
||||
docker_mgr._status_cache[0] = True
|
||||
|
||||
result = docker_mgr.is_running(0)
|
||||
assert result is True
|
||||
# No Docker API calls when cache is populated
|
||||
mock_docker_client.containers.get.assert_not_called()
|
||||
|
||||
|
||||
class TestStartOneValidation:
|
||||
"""start_one requires privileged netns operations; these are E2E tests.
|
||||
|
||||
The image-pull logic (ImageNotFound → pull) is tested below by patching
|
||||
all netns operations.
|
||||
"""
|
||||
|
||||
@pytest.mark.skip(reason="requires --privileged; covered by TC-E2E-001")
|
||||
def test_raises_when_image_tag_is_host_manet_latest(self):
|
||||
pass
|
||||
|
||||
@pytest.mark.skip(reason="requires --privileged; covered by TC-E2E-001")
|
||||
def test_raises_when_image_tag_is_host_manet_latest_netns_needed(self):
|
||||
pass
|
||||
|
||||
def test_image_pull_on_not_found(self, docker_mgr, mock_docker_client):
|
||||
"""Images not present locally are automatically pulled."""
|
||||
spec = NodeSpec(id=0, ip="192.168.100.10")
|
||||
config = SimConfig()
|
||||
from docker.errors import ImageNotFound
|
||||
mock_docker_client.images.get.side_effect = ImageNotFound("not found")
|
||||
mock_docker_client.images.pull.return_value = MagicMock()
|
||||
|
||||
with patch.object(docker_mgr, "_kill_stale"):
|
||||
with patch("controller.orchestrator.docker_mgr.netns.ensure_node_bridge"):
|
||||
with patch("controller.orchestrator.docker_mgr.netns.move_to_netns"):
|
||||
with patch("controller.orchestrator.docker_mgr.netns.create_veth"):
|
||||
with patch(
|
||||
"controller.orchestrator.docker_mgr.netns.create_tap"
|
||||
):
|
||||
with patch(
|
||||
"controller.orchestrator.docker_mgr.netns.DEFAULT_BRIDGE_IP",
|
||||
"192.168.100.1",
|
||||
):
|
||||
mock_container = MagicMock()
|
||||
mock_container.attrs = {"State": {"Pid": 12345}}
|
||||
mock_docker_client.containers.run.return_value = (
|
||||
mock_container
|
||||
)
|
||||
|
||||
docker_mgr.start_one(spec, config)
|
||||
|
||||
mock_docker_client.images.pull.assert_called_once_with(
|
||||
"manet-node:latest"
|
||||
)
|
||||
|
||||
|
||||
class TestContainerNaming:
|
||||
def test_container_name_prefix(self):
|
||||
assert CONTAINER_PREFIX == "manet-node-"
|
||||
|
||||
def test_node_spec_default_image(self, sample_spec):
|
||||
assert sample_spec.image == "manet-node:latest"
|
||||
@@ -1,63 +0,0 @@
|
||||
"""Unit tests for controller/orchestrator/netns.py (pure-function subset).
|
||||
|
||||
Real netlink/bridge operations require a privileged Linux environment
|
||||
and are covered by E2E tests (TC-E2E-*).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from controller.orchestrator.netns import (
|
||||
node_bridge_name,
|
||||
mesh_mac,
|
||||
DEFAULT_BRIDGE,
|
||||
DEFAULT_BRIDGE_IP,
|
||||
DEFAULT_BRIDGE_PREFIX,
|
||||
)
|
||||
|
||||
|
||||
class TestNodeBridgeName:
|
||||
def test_format(self):
|
||||
assert node_bridge_name(0) == "mesh-br-0"
|
||||
assert node_bridge_name(5) == "mesh-br-5"
|
||||
assert node_bridge_name(15) == "mesh-br-15"
|
||||
|
||||
def test_prefix_uses_default_constant(self):
|
||||
assert DEFAULT_BRIDGE == "mesh-br"
|
||||
|
||||
|
||||
class TestMeshMac:
|
||||
def test_format_valid(self):
|
||||
mac = mesh_mac(0)
|
||||
assert isinstance(mac, str)
|
||||
parts = mac.split(":")
|
||||
assert len(parts) == 6
|
||||
assert all(len(p) == 2 for p in parts)
|
||||
# All hex
|
||||
assert all(int(p, 16) < 256 for p in parts)
|
||||
|
||||
def test_deterministic(self):
|
||||
assert mesh_mac(0) == mesh_mac(0)
|
||||
assert mesh_mac(5) == mesh_mac(5)
|
||||
|
||||
def test_unique_per_node(self):
|
||||
macs = {mesh_mac(i) for i in range(16)}
|
||||
assert len(macs) == 16
|
||||
|
||||
def test_node_15_last_octet_sixteen(self):
|
||||
# node_id=15 → last octet = 0x10 = 16
|
||||
assert mesh_mac(15).endswith(":10")
|
||||
|
||||
def test_first_octet_zero(self):
|
||||
# First octet must be 00 to avoid ns-3 special-address confusion
|
||||
assert mesh_mac(0).startswith("00:")
|
||||
|
||||
|
||||
class TestDefaultConstants:
|
||||
def test_bridge_ip_format(self):
|
||||
parts = DEFAULT_BRIDGE_IP.split(".")
|
||||
assert len(parts) == 4
|
||||
assert all(0 <= int(p) <= 255 for p in parts)
|
||||
|
||||
def test_bridge_prefixlen(self):
|
||||
assert DEFAULT_BRIDGE_PREFIX == 24
|
||||
@@ -1,2 +0,0 @@
|
||||
Bug ID,Severity,Test Case,Summary,Steps to Reproduce,Expected,Actual,Status,Reporter,Date
|
||||
BUG-001,P4,TC-NET-007 (known limitation),mesh_mac node_15 returns ':10' not ':0f',Code review of netns.py:mesh_mac(15) formula,Should end with ':0f' for node 15,Ends with ':10' (16 in hex) — code formula uses node_id+1,Known,Code comment correct; test updated to match,2026-05-17
|
||||
|
@@ -1,7 +0,0 @@
|
||||
Test ID,Category,Priority,Status,Result,P0 Count,P1 Count,P2 Count,P3 Count,P4 Count,Passed,Failed,Skipped,Total,Execution Date,Notes
|
||||
MANET-QA-001,Config,P0,PASS,Pass with fixes,0,0,0,0,1,37,0,0,37,2026-05-17,All config tests passed; mac_mode forced to mesh validated
|
||||
MANET-QA-002,Config,P0,PASS,Pass,0,0,0,0,0,30,0,0,30,2026-05-17,test_config.py: 30 passed
|
||||
MANET-QA-003,Netns,P1,PASS,Pass (pure functions only),0,0,0,0,0,8,0,0,8,2026-05-17,test_netns.py: 8 passed; netns operations need privileged Linux
|
||||
MANET-QA-004,DockerMgr,P1,PASS,Pass with skips,0,0,0,0,2,10,0,2,12,2026-05-17,test_docker_mgr.py: 10 passed, 2 skipped (privileged ops)
|
||||
MANET-QA-005,API Routes,P0,PASS,Pass,0,0,0,0,0,15,0,0,15,2026-05-17,test_api_routes.py: 15 passed; patch both import sites critical
|
||||
MANET-QA-006,Frontend,P0,PASS,Pass,0,0,0,0,0,9,0,0,9,2026-05-17,useSimConfig.test.ts: 9 passed (vitest)
|
||||
|
@@ -1,182 +0,0 @@
|
||||
# Config Layer Test Cases (TC-CFG-001 ~ TC-CFG-010)
|
||||
|
||||
## TC-CFG-001: parse_conf_file parses standard key=value
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Python 3.13+, pytest installed
|
||||
- Working directory: `manet-30ns3/`
|
||||
|
||||
**Test Steps**:
|
||||
1. Create a temporary `.conf` file with: `nNodes = 8\nfrequencyMhz = 5180\n`
|
||||
2. Call `parse_conf_file(path)`
|
||||
3. Assert the result equals `{"nNodes": 8, "frequencyMhz": 5180}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ `nNodes` parsed as int 8, `frequencyMhz` parsed as int 5180
|
||||
|
||||
**Pass/Fail Criteria**:
|
||||
- ✅ PASS: Both keys parsed correctly with correct types
|
||||
- ❌ FAIL: Type coercion wrong or key missing
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-002: parse_conf_file ignores // comments and empty lines
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Python 3.13+, pytest installed
|
||||
|
||||
**Test Steps**:
|
||||
1. Create a `.conf` file with:
|
||||
```
|
||||
// comment
|
||||
nNodes = 3 // inline comment
|
||||
|
||||
// empty line above
|
||||
ssid = "test-net"
|
||||
```
|
||||
2. Call `parse_conf_file(path)`
|
||||
3. Assert result is `{"nNodes": 3, "ssid": "test-net"}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Comments stripped, empty lines ignored, only valid key=value pairs returned
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-003: parse_conf_file converts legacy aliases pcapTracing→pcap, asciiTracing→ascii
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Python 3.13+, pytest installed
|
||||
|
||||
**Test Steps**:
|
||||
1. Create a `.conf` with: `pcapTracing = true\nasciiTracing = false\n`
|
||||
2. Call `parse_conf_file(path)`
|
||||
3. Assert result is `{"pcap": True, "ascii": False}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Legacy aliases correctly mapped to new keys
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-004: load_config priority — overrides > file > preset > defaults
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Python 3.13+, pytest installed
|
||||
|
||||
**Test Steps**:
|
||||
1. Create file with `nNodes = 12`
|
||||
2. Call `load_config(file_path=path, overrides={"nNodes": 3}, preset="debug")`
|
||||
3. Assert `cfg.n_nodes == 3`
|
||||
|
||||
**Expected Result**:
|
||||
✅ overrides (3) wins over file (12) and preset default (5)
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-005: load_config accepts both snake_case and camelCase overrides
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `load_config(overrides={"frequency_mhz": 5900})` — snake_case
|
||||
2. `load_config(overrides={"frequencyMhz": 5180})` — camelCase
|
||||
3. Assert both produce correct values
|
||||
|
||||
**Expected Result**:
|
||||
✅ Both formats accepted, same result
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-006: SimConfig.merged_with merges partial overrides
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Create `SimConfig()` with defaults
|
||||
2. Call `cfg.merged_with({"n_nodes": 10})`
|
||||
3. Assert `merged.n_nodes == 10` and other fields unchanged
|
||||
|
||||
**Expected Result**:
|
||||
✅ Partial merge works, untouched fields retain defaults
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-007: All 12 presets load and have required fields
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Iterate all entries in `PRESETS`
|
||||
2. Assert each is a `SimConfig` instance with `n_nodes >= 2`
|
||||
|
||||
**Expected Result**:
|
||||
✅ All 12 presets (default, urban, rural, debug, throughput, tactical, wifi-*) valid
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-008: mac_mode="adhoc" is forced to "mesh"
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `cfg = SimConfig(mac_mode="adhoc")`
|
||||
2. Assert `cfg.mac_mode == "mesh"`
|
||||
|
||||
**Expected Result**:
|
||||
✅ NS-3.47 + cppyy incompatibility workaround active
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-009: SimConfig.model_dump(by_alias=True) outputs camelCase
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `dumped = SimConfig().model_dump(by_alias=True)`
|
||||
2. Assert `"nNodes"` in dumped, `"simulationTime"` in dumped
|
||||
3. Assert no snake_case keys
|
||||
|
||||
**Expected Result**:
|
||||
✅ All keys are camelCase when serialized for API/JSON
|
||||
|
||||
---
|
||||
|
||||
## TC-CFG-010: FIELD_DESCRIPTIONS keys are in sync with SimConfig fields
|
||||
|
||||
**Priority**: P3
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Collect all SimConfig field names via `model_fields`
|
||||
2. Check all field names exist in `FIELD_DESCRIPTIONS`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Every field has a description entry (no silent omission)
|
||||
|
||||
---
|
||||
@@ -1,240 +0,0 @@
|
||||
# API Routes Test Cases (TC-API-001 ~ TC-API-015)
|
||||
|
||||
Covers `controller/api/routes_sim.py`, `routes_config.py`, `routes_nodes.py`.
|
||||
|
||||
## TC-API-001: GET /api/health returns {"ok": true}
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Controller module imports successfully
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/health`
|
||||
2. Assert status 200 and body `{"ok": true}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Health endpoint responds correctly
|
||||
|
||||
---
|
||||
|
||||
## TC-API-002: POST /api/sim/start launches simulation
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 2 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Mock session with `running=False`
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with empty body
|
||||
2. Assert status 200, `{"ok": true, "nNodes": 5}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Returns ok=True immediately
|
||||
|
||||
---
|
||||
|
||||
## TC-API-003: POST /api/sim/start while running returns 409
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Set mock session `running=True`
|
||||
2. `POST /api/sim/start`
|
||||
3. Assert status 409 Conflict
|
||||
|
||||
**Expected Result**:
|
||||
✅ Duplicate start rejected cleanly
|
||||
|
||||
---
|
||||
|
||||
## TC-API-004: POST /api/sim/start with unknown preset returns 400
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with `{"preset": "nonexistent"}`
|
||||
2. Assert status 400
|
||||
|
||||
**Expected Result**:
|
||||
✅ KeyError from load_config caught and converted to HTTP 400
|
||||
|
||||
---
|
||||
|
||||
## TC-API-005: GET /api/sim/status returns current simulation state
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/sim/status` with no simulation running
|
||||
2. Assert `running=false`, `totalNodes=0`
|
||||
3. With running sim: `running=true`, `elapsed>0`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Status reflects actual session state
|
||||
|
||||
---
|
||||
|
||||
## TC-API-006: GET /api/sim/presets returns all 12 presets
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/sim/presets`
|
||||
2. Assert keys include `debug`, `default`, `tactical`, `urban`, `rural`
|
||||
3. Each preset has `nNodes`, `macMode`, `routingProtocol`, `simulationTime`
|
||||
|
||||
**Expected Result**:
|
||||
✅ All 12 presets exposed with required fields
|
||||
|
||||
---
|
||||
|
||||
## TC-API-007: GET /api/sim/path returns BFS path between nodes
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Start sim with MockSim (src=0→dst=4 returns [0,2,4])
|
||||
2. `GET /api/sim/path?src=0&dst=4`
|
||||
3. Assert `reachable=true`, `hops=2`, `path=[0,2,4]`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Path computation and IP mapping work
|
||||
|
||||
---
|
||||
|
||||
## TC-API-008: POST /api/sim/stop stops simulation and cleans up
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 2 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/stop`
|
||||
2. Assert status 200, `{"ok": true, "running": false}`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Stop cleans up all docker/bridge/veth/tap resources
|
||||
|
||||
---
|
||||
|
||||
## TC-API-009: GET /api/nodes returns node list
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. With simulation running, `GET /api/nodes`
|
||||
2. Assert JSON array with node id, ip, role fields
|
||||
|
||||
**Expected Result**:
|
||||
✅ NodeSpec list returned correctly
|
||||
|
||||
---
|
||||
|
||||
## TC-API-010: POST /api/nodes/{id}/exec runs command in container
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 2 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/nodes/0/exec` with `{"cmd": "ip -4 addr show eth0"}`
|
||||
2. Assert status 200, output contains IP address
|
||||
|
||||
**Expected Result**:
|
||||
✅ docker exec works, output returned
|
||||
|
||||
---
|
||||
|
||||
## TC-API-011: GET /api/logs returns node logs
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/logs?node=0&tail=20`
|
||||
2. Assert status 200, log text returned
|
||||
|
||||
**Expected Result**:
|
||||
✅ Logs streamed from container
|
||||
|
||||
---
|
||||
|
||||
## TC-API-012: GET /api/flows returns FlowMonitor statistics
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/flows`
|
||||
2. Assert JSON with flow stats (tx_packets, rx_packets, lost_packets)
|
||||
|
||||
**Expected Result**:
|
||||
✅ FlowMonitor stats exposed
|
||||
|
||||
---
|
||||
|
||||
## TC-API-013: WebSocket /ws/telemetry pushes 1Hz telemetry frames
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 3 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Connect WebSocket to `/ws/telemetry`
|
||||
2. Wait 2 seconds
|
||||
3. Assert at least 1 JSON frame received
|
||||
|
||||
**Expected Result**:
|
||||
✅ Frames arrive at ~1Hz with nodes/flows/status data
|
||||
|
||||
---
|
||||
|
||||
## TC-API-014: PUT /api/config rejected while simulation running
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Set `running=True`
|
||||
2. `PUT /api/config` with new body
|
||||
3. Assert status 409 Conflict
|
||||
|
||||
**Expected Result**:
|
||||
✅ Runtime config change prevented
|
||||
|
||||
---
|
||||
|
||||
## TC-API-015: GET /api/config returns current configuration
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: Integration
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `GET /api/config`
|
||||
2. Assert JSON matches current SimConfig (camelCase)
|
||||
|
||||
**Expected Result**:
|
||||
✅ Full config serialised as camelCase JSON
|
||||
|
||||
---
|
||||
@@ -1,196 +0,0 @@
|
||||
# Netns / DockerMgr / E2E Test Cases (TC-NET, TC-DCK, TC-E2E)
|
||||
|
||||
Covers `controller/orchestrator/netns.py`, `docker_mgr.py`, and integration tests.
|
||||
|
||||
---
|
||||
|
||||
## TC-NET-001: node_bridge_name returns correct format mesh-br-{id}
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Call `node_bridge_name(0)`, `node_bridge_name(5)`, `node_bridge_name(15)`
|
||||
2. Assert `"mesh-br-0"`, `"mesh-br-5"`, `"mesh-br-15"`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Format matches Linux bridge naming convention
|
||||
|
||||
---
|
||||
|
||||
## TC-NET-002: ensure_node_bridge creates bridge idempotently
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Integration* (requires --privileged Linux)
|
||||
**Estimated Time**: 3 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `ensure_node_bridge(0, ip="192.168.100.1", prefixlen=24)`
|
||||
2. Repeat same call
|
||||
3. `ip link show mesh-br-0` — verify bridge exists
|
||||
|
||||
**Expected Result**:
|
||||
✅ Second call is no-op (idempotent), no error
|
||||
|
||||
---
|
||||
|
||||
## TC-NET-007: _normalize_keys converts snake_case to camelCase
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Unit
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `_normalize_keys({"hello_world": 1})` → `{"helloWorld": 1}`
|
||||
2. `_normalize_keys({"foo_bar_baz": 2})` → `{"fooBarBaz": 2}`
|
||||
3. `_normalize_keys({"camelKey": 1})` → passthrough
|
||||
|
||||
**Expected Result**:
|
||||
✅ Consistent key normalization for MAC lookup compatibility
|
||||
|
||||
---
|
||||
|
||||
## TC-DCK-001: start_one creates --net=none container
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration* (requires Docker daemon)
|
||||
**Estimated Time**: 5 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Call `docker_mgr.start_one(NodeSpec(id=0, ip="192.168.100.10"), SimConfig())`
|
||||
2. `docker ps` shows `manet-node-0` with `--network none`
|
||||
3. `docker inspect manet-node-0` shows `NetworkMode: none`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Container isolated with no Docker bridge networking
|
||||
|
||||
---
|
||||
|
||||
## TC-DCK-002: stop_all removes all containers
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: Integration* (requires Docker daemon)
|
||||
**Estimated Time**: 5 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Start 5-node simulation
|
||||
2. `POST /api/sim/stop`
|
||||
3. `docker ps | grep manet-node` → empty
|
||||
|
||||
**Expected Result**:
|
||||
✅ All containers cleaned up
|
||||
|
||||
---
|
||||
|
||||
## TC-DCK-003: is_running returns correct status from cache
|
||||
|
||||
**Priority**: P1
|
||||
**Type**: Unit (mocked)
|
||||
**Estimated Time**: 1 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Pre-populate `docker_mgr._status_cache[0] = True`
|
||||
2. Call `is_running(0)` without Docker API
|
||||
3. Assert `True`, no `containers.get` call
|
||||
|
||||
**Expected Result**:
|
||||
✅ Cache hit avoids Docker API round-trip
|
||||
|
||||
---
|
||||
|
||||
## TC-E2E-001: debug preset — 5 node / 60s simulation smoke test
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: E2E
|
||||
**Estimated Time**: 10 min
|
||||
|
||||
**Prerequisites**:
|
||||
- Linux host with Docker, 5+ GB RAM
|
||||
- Controller running: `docker compose up -d controller`
|
||||
- Can access `localhost:8000`
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with `{"preset": "debug"}`
|
||||
2. Wait 5s, verify `mesh-br-*`, `mesh-tap-*`, `mesh-veth*` exist via `ip link`
|
||||
3. Verify 5 containers via `docker ps`
|
||||
4. `docker exec manet-node-0 ping -c 3 192.168.100.11`
|
||||
5. `POST /api/sim/stop`
|
||||
6. `ip link | grep mesh-br` → empty (clean)
|
||||
|
||||
**Expected Result**:
|
||||
✅ Full lifecycle works end-to-end, no resource leak
|
||||
|
||||
---
|
||||
|
||||
## TC-E2E-002: default preset — 6 node ping across topology
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: E2E
|
||||
**Estimated Time**: 10 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with `{"preset": "default"}`
|
||||
2. Wait 10s for routing to converge
|
||||
3. `docker exec manet-node-0 ping -c 3 192.168.100.15` (node 5)
|
||||
4. Verify ping success or proper path loss
|
||||
|
||||
**Expected Result**:
|
||||
✅ Multi-hop mesh routing functional
|
||||
|
||||
---
|
||||
|
||||
## TC-E2E-008: br-ns3/tap-*/veth* cleaned after stop
|
||||
|
||||
**Priority**: P0
|
||||
**Type**: E2E
|
||||
**Estimated Time**: 5 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with `{"preset": "debug"}`
|
||||
2. Verify resources present
|
||||
3. `POST /api/sim/stop`
|
||||
4. `ip link | grep -E 'mesh-br|mesh-tap|mesh-veth' || echo "clean"`
|
||||
|
||||
**Expected Result**:
|
||||
✅ Output is "clean" — no stale interfaces
|
||||
|
||||
---
|
||||
|
||||
## TC-E2E-009: bind mode user software load works
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: E2E
|
||||
**Estimated Time**: 5 min
|
||||
|
||||
**Test Steps**:
|
||||
1. Host: `mkdir -p /tmp/uatest && echo 'echo hello' > /tmp/uatest/run.sh`
|
||||
2. `POST /api/sim/start` with:
|
||||
```json
|
||||
{"preset": "debug", "nodes": [{"id": 0, "userAppMode": "bind", "userAppBindPath": "/tmp/uatest"}]}
|
||||
```
|
||||
3. `docker exec manet-node-0 /opt/userapp/run.sh` → "hello"
|
||||
|
||||
**Expected Result**:
|
||||
✅ Bind mount makes host directory available in container
|
||||
|
||||
---
|
||||
|
||||
## TC-E2E-010: exec mode — docker exec delivers commands
|
||||
|
||||
**Priority**: P2
|
||||
**Type**: E2E
|
||||
**Estimated Time**: 3 min
|
||||
|
||||
**Test Steps**:
|
||||
1. `POST /api/sim/start` with `{"preset": "debug"}`
|
||||
2. `POST /api/nodes/0/exec` with `{"cmd": "echo hi"}`
|
||||
3. Assert `"hi"` in response
|
||||
|
||||
**Expected Result**:
|
||||
✅ Command execution API works
|
||||
|
||||
---
|
||||
|
||||
*Integration tests marked (*) require a privileged Linux environment with Docker daemon.
|
||||
Unit tests run in any environment with mocks.
|
||||
@@ -1,36 +0,0 @@
|
||||
{
|
||||
"name": "manet-30ns3",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"test:coverage": "vitest run --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.56.2",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.441.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"tailwind-merge": "^2.5.3",
|
||||
"zustand": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^6.5.0",
|
||||
"@testing-library/react": "^16.0.0",
|
||||
"@types/node": "^22.5.4",
|
||||
"@types/react": "^19.0.0",
|
||||
"@types/react-dom": "^19.0.0",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"vitest": "^2.1.1",
|
||||
"jsdom": "^25.0.0",
|
||||
"typescript": "~5.6.0",
|
||||
"vite": "^5.4.3"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSimConfig } from '@/hooks/useSimConfig';
|
||||
@@ -42,14 +42,6 @@ function App() {
|
||||
const [activePage, setActivePage] = useState<PageKey>('dashboard');
|
||||
const [nodeSpecs, setNodeSpecs] = useState<NodeSpec[] | undefined>(undefined);
|
||||
|
||||
// Load node specs from backend on mount (so Start always includes remote-host config)
|
||||
useEffect(() => {
|
||||
fetch('/api/nodes/specs')
|
||||
.then(r => r.ok ? r.json() : [])
|
||||
.then(data => { if (Array.isArray(data) && data.length > 0) setNodeSpecs(data); })
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const handleStart = () => {
|
||||
startSimulation(config, undefined, nodeSpecs);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user