How nivx18818/routing works
Project type and purpose
• This is a Python-based network simulator for intra-domain routing algorithms.
• It lets you plug in two routing-algorithm implementations (distance-vector in DVrouter.py or link-state in LSrouter.py) and then simulates a small autonomous system to test correctness.
• Key use case: students implement routing logic and then run the provided simulator (network.py or visualize_network.py) on JSON topologies, observe packet forwarding and convergence.
File structure
• Top-level files:
• DVrouter.py, LSrouter.py ← your algorithm implementations
• router.py ← abstract base class for routers
• client.py, link.py, packet.py, network.py, visualize_network.py
• JSON files (01_small_net.json, … _events.json) hold topology + event specs
• test_scripts/test_dv_ls.sh ← batch runner for all scenarios
• apps/ directory (possibly helper scripts or sample apps)
• Patterns:
• router.py defines the Router interface (hook methods: handle_packet, handle_time, etc.)
• DVrouter & LSrouter subclass Router and override its methods
• network.py / visualize_network.py instantiate a Simulator, load a JSON, spawn Router threads + Clients/Links, schedule events
README for additional insights
• The simulator is event-driven: routers receive calls for packet arrival, link up/down, periodic time ticks.
• Packets are Python objects (Packet.ROUTING for control, traceroute-style for data) passed via send(port, packet).
• JSONs define nodes, links, link costs, and scheduled link-failure/add events.
• visualize_network.py adds a GUI showing clients (blue), routers (red), packet flows, link costs.
• Main components:
A. Simulator Core
• JSON Config Loader
• Event Scheduler (link events, heartbeats)
• Topology Manager (creates Link/Client/Router objects)
B. Router Abstraction
• Base class (router.py) exposing hooks
• Subclasses: DVrouter, LSrouter
C. Packet Engine
• Packet class (packet.py)
• send/receive API hiding link latencies
D. Network Entities
• Clients (client.py) – generate traceroute traffic
• Links (link.py) – model cost/latency, reliability
E. UI & CLI
• visualize_network.py – GUI front end
• network.py – headless run + final-routes output
F. Test Harness
• test_scripts/test_dv_ls.sh – automated batch runs
• Relationships & data flows:
1. User launches network.py or visualize_network.py, passes JSON + “DV” or “LS”
2. Simulator Core loads JSON → instantiates Link, Client, Router base-class instances
3. Depending on argument, Router instances are actual DVrouter or LSrouter objects
4. Clients periodically send data packets into the topology (via Router send API)
5. Routers exchange control packets (distance-vector or link-state messages) via Packet Engine
6. Event Scheduler invokes handle_time, handle_new_link, handle_remove_link, handle_packet on each Router
7. At simulation end, network.py collects traceroute results and prints correctness
8. visualize_network.py additionally subscribes to packet events to animate flows
• Architectural patterns & principles:
• Plugin / Strategy Pattern: routing algorithm is pluggable via subclassing Router
• Event-driven simulation: discrete events trigger router callbacks
• Separation of concerns: topology & event scheduling (network.py) vs. routing logic (DVrouter/LSrouter) vs. packet format (packet.py)
• Dependency injection via JSON configs – topology is data, not hard-coded
Essential details to capture
• The hook methods in Router (handle_packet, handle_time, handle_new_link/remove_link) are critical extension points
• The periodic heartbeat mechanism: Simulator Core triggers handle_time every heartbeat_time
• The bidirectional nature of Links (latency, cost) on which Packet objects travel
• The final route-validation step in network.py