Spaces:
Sleeping
Sleeping
|
Download docs/SIM_DESIGN.md from brand0nwalls/NetOps: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/docs/SIM_DESIGN.md
- Command line
-
hf download hf://spaces/brand0nwalls/NetOps/docs/SIM_DESIGN.md
-
curl -L -o SIM_DESIGN.md https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/docs/SIM_DESIGN.md
3.88 kB
| # Python Network Simulator β Design Document | |
| ## Overview | |
| Pure-Python replacement for the Mininet+FRR runtime layer. Runs in any unprivileged environment (Docker, HF Spaces, CI). Toggle with `NETOPS_SIM=1`. | |
| ## What's Simulated vs Reused | |
| | Component | Real (Mininet) | Sim (Python) | | |
| |---|---|---| | |
| | Topology graph | IPMininet IPTopo | **Reused** β same `NetOpsTopo.build()` | | |
| | IP allocation | IPMininet broadcast domains | Replicated from graph structure | | |
| | OSPF state | FRR ospfd process | Timer-based state machine + Dijkstra SPF | | |
| | BGP state | FRR bgpd process | Session state + route selection engine | | |
| | Routing table | Linux FIB + FRR RIB | Merged RIB (connected/static/OSPF/BGP) | | |
| | Packet forwarding | Linux kernel | Hop-by-hop RIB lookup | | |
| | tc netem | Kernel qdisc | Per-interface params, applied to probes | | |
| | iptables | Kernel netfilter | Rule lists per interface | | |
| | Interface counters | Kernel stats | Baseline rate + fault-derived accumulation | | |
| | Ping/traceroute | Real ICMP | Probe simulation through forwarding path | | |
| | telemetry.py | **Unchanged** | **Unchanged** β calls node.cmd() | | |
| | renderer.py | **Unchanged** | **Unchanged** β formats dicts as text | | |
| | health_checker.py | **Unchanged** | **Unchanged** β reads telemetry | | |
| | reward.py | **Unchanged** | **Unchanged** β pure math | | |
| | fault_injector.py | **Unchanged** | Override only OS-level helpers | | |
| ## Architecture | |
| ``` | |
| Environment.reset() / step() | |
| β | |
| NetworkManager (or SimNetworkManager) | |
| β | |
| FaultInjector (or SimFaultInjector) ββ node.cmd("...") | |
| β β | |
| telemetry.py SimNode.cmd() dispatch | |
| β β READ β engine β JSON | |
| renderer.py β WRITE β mutate topology | |
| β | |
| health_checker.py β reward.py | |
| ``` | |
| ## Fault β State Mutation Mapping | |
| | Fault | State Mutation | | |
| |---|---| | |
| | Link failure | `interface.up = False` | | |
| | Latency/loss/corrupt/reorder/dup | `interface.netem_* = N` | | |
| | Bandwidth throttle | `interface.tbf_rate_kbit = N` | | |
| | OSPF cost/timer/area/MTU | `router.ospf_costs/hello/dead/area`, `interface.mtu` | | |
| | OSPF/BGP daemon kill | `router.*_daemon_alive = False` | | |
| | BGP withdrawal | `router.bgp_redistribute_* = False` | | |
| | BGP flood/leak/hijack | `router.bgp_networks.add(prefix)`, `router.static_routes` | | |
| | BGP policy (local-pref/prepend/community) | `router.bgp_peer_config[ip][key] = value` | | |
| | Firewall/ACL | `interface.iptables_*_rules.append(rule)` | | |
| | Routing loop/blackhole | `router.static_routes[prefix] = nexthop/"blackhole"` | | |
| | CPU exhaustion | `router.cpu_exhausted = True` | | |
| | Interface flapping | `router.bg_flapping[intf] = True` | | |
| ## Protocol Engines | |
| ### OSPF (`sim/ospf.py`) | |
| - Neighbor state: Full/Down/ExStart/Init based on daemon alive, link up, iptables, area match, MTU match, timer match | |
| - SPF: Dijkstra on intra-AS links where neighbor is Full | |
| - Dead timer: neighbors transition to Down after `dead_interval` simulated seconds without hellos | |
| ### BGP (`sim/bgp.py`) | |
| - Session state: Established/Active/Idle based on daemon alive, link up, tcp/179 blocked, CPU exhausted | |
| - Route selection: highest local-pref β shortest AS-path β lowest origin β lowest peer IP | |
| - iBGP/eBGP: eBGP routes re-advertised to iBGP peers. AS-path prepend on eBGP receipt. no-export community blocks eBGP re-advertisement. | |
| ### RIB (`sim/rib.py`) | |
| - Preference: connected(0) > static(1) > eBGP(20) > OSPF(110) > iBGP(200) | |
| - Longest prefix match for forwarding lookup | |
| - Blackhole routes installed but drop packets | |
| ## Performance | |
| | Metric | Real Mininet | Python Sim | Speedup | | |
| |---|---|---|---| | |
| | Network startup | 19.2s | 0.1s | 192Γ | | |
| | Episode test (14 tests) | 454s | 5.9s | 77Γ | | |
| | All 69 fault checks | ~40min | <10s | 240Γ | | |
| | Privileges required | root + NET_ADMIN + SYS_ADMIN | None | β | | |