Spaces:
Sleeping
Sleeping
Download server/sim/engine.py from brand0nwalls/NetOps: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/server/sim/engine.py
- Command line
-
hf download hf://spaces/brand0nwalls/NetOps/server/sim/engine.py
-
curl -L -o engine.py https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/server/sim/engine.py
2.26 kB
| """SimEngine — central coordinator for the pure-Python network simulator. | |
| Holds the mutable topology, simulated clock, and all protocol sub-engines. | |
| Provides advance() to step the simulated clock forward, triggering timer-based | |
| protocol state transitions and counter accumulation. | |
| """ | |
| from server.sim.topology import Topology | |
| class SimEngine: | |
| def __init__(self, topo: Topology): | |
| self.topo = topo | |
| self.now: float = 0.0 | |
| self._ospf = None | |
| self._bgp = None | |
| self._rib = None | |
| self._counters = None | |
| self._reachability = None | |
| def from_topo_class(cls, topo_class) -> "SimEngine": | |
| topo = Topology.build_from_iptopo(topo_class) | |
| return cls(topo) | |
| def advance(self, seconds: float): | |
| """Advance simulated clock by given seconds. | |
| Updates OSPF/BGP timer states and accumulates interface counters. | |
| Called by environment.py where real Mininet would time.sleep(). | |
| """ | |
| self.now += seconds | |
| self.counters.accumulate(self, seconds) | |
| def reset(self, topo_class): | |
| topo = Topology.build_from_iptopo(topo_class) | |
| self.topo = topo | |
| self.now = 0.0 | |
| if self._counters: | |
| self._counters = None | |
| def ospf(self): | |
| if self._ospf is None: | |
| from server.sim.ospf import OSPFEngine | |
| self._ospf = OSPFEngine(self) | |
| return self._ospf | |
| def bgp(self): | |
| if self._bgp is None: | |
| from server.sim.bgp import BGPEngine | |
| self._bgp = BGPEngine(self) | |
| return self._bgp | |
| def rib(self): | |
| if self._rib is None: | |
| from server.sim.rib import RIBEngine | |
| self._rib = RIBEngine(self) | |
| return self._rib | |
| def counters(self): | |
| if self._counters is None: | |
| from server.sim.counters import CounterEngine | |
| self._counters = CounterEngine(self) | |
| return self._counters | |
| def reachability(self): | |
| if self._reachability is None: | |
| from server.sim.reachability import ReachabilityEngine | |
| self._reachability = ReachabilityEngine(self) | |
| return self._reachability | |