%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#E67E22', 'secondaryColor': '#16A085', 'tertiaryColor': '#E67E22', 'fontSize': '13px'}}}%%
graph TB
subgraph Discovery["Topology Discovery Layer"]
ND[Neighbor Discovery]
LT[Link Tracking]
TE[Topology Events]
ND -->|Discovers| LT
LT -->|Monitors| TE
end
subgraph Quality["Link Quality Assessment Layer"]
PDR[PDR Measurement]
RSSI[RSSI Monitoring]
LAT[Latency Tracking]
QUAL[Quality Classification]
PDR --> QUAL
RSSI --> QUAL
LAT --> QUAL
end
subgraph Routing["Multi-Path Routing Layer"]
KSP[K-Shortest Paths]
METRIC[Route Metrics]
STRAT[Routing Strategy]
KSP -->|Calculates| METRIC
METRIC -->|Feeds| STRAT
end
subgraph Monitor["Performance Monitoring Layer"]
STATS[Network Statistics]
BOTTLE[Bottleneck Detection]
HEALTH[Health Monitoring]
STATS --> BOTTLE
STATS --> HEALTH
end
Discovery --> Quality
Quality --> Routing
Routing --> Monitor
Monitor -.->|Feedback| Discovery
style ND fill:#2C3E50,stroke:#16A085,color:#fff
style QUAL fill:#16A085,stroke:#2C3E50,color:#fff
style STRAT fill:#E67E22,stroke:#2C3E50,color:#fff
style HEALTH fill:#2C3E50,stroke:#16A085,color:#fff
262 Ad Hoc Networks: Production Framework Implementation
262.1 Learning Objectives
By the end of this chapter, you will be able to:
- Build Production Frameworks: Implement comprehensive multi-hop ad-hoc network management systems
- Assess Link Quality: Design link quality classification and monitoring for dynamic networks
- Implement Multi-Path Routing: Create load-balanced routing across multiple paths
- Monitor Network Performance: Build real-time topology discovery and health monitoring
- Handle Network Dynamics: Manage link state changes and routing table updates
- Deploy Production Systems: Apply the framework to real-world IoT deployments
262.2 Prerequisites
Required Chapters:
- Ad-hoc Fundamentals - Core ad-hoc concepts
- Multi-hop Fundamentals - Network structures
- Routing - Routing protocols
Technical Background:
- Self-organizing networks
- MANET concepts
- Reactive vs proactive routing
Ad-hoc Routing Protocols:
| Protocol | Type | Overhead | Latency | Best For |
|---|---|---|---|---|
| AODV | Reactive | Low | High | Dynamic |
| DSR | Reactive | Low | High | Small networks |
| OLSR | Proactive | High | Low | Static |
| DSDV | Proactive | High | Low | Stable |
Estimated Time: 45 minutes
This chapter is implementation-heavy. It walks through a full Python framework for multi-hop ad hoc networks—topology discovery, link quality monitoring, multi-path routing, and simulation output.
It is designed to come after you are comfortable with the conceptual material from:
adhoc-fundamentals.qmd– why ad hoc networks exist, basic routing ideas, and limitations.multi-hop-fundamentals.qmd– how multi-hop forwarding, path length, and connectivity work.adhoc-hybrid-zrp.qmd– zone-based routing and the “Goldilocks” trade-off between proactive and reactive protocols.
If you are new to ad hoc networking:
- Skim the code examples to see what a production-style toolkit might look like.
- Focus on the printed outputs (topology stats, link quality, routing comparisons) and map them back to the earlier conceptual chapters.
- Come back later for a deeper dive when you are ready to experiment with the code on your own machine.
262.3 Introduction
Production ad-hoc networks require robust management systems that go beyond simple routing protocols. Real-world IoT deployments face challenges including variable link quality, node mobility, battery constraints, and the need for continuous monitoring. This chapter provides a comprehensive production-ready Python framework that addresses these challenges through modular, extensible components.
The framework consists of four key layers:
- Topology Discovery Layer - Dynamic neighbor discovery, link tracking, and topology event monitoring
- Link Quality Assessment Layer - PDR, RSSI, latency measurement with quality classification
- Multi-Path Routing Layer - K-shortest paths, multiple routing metrics, and path selection strategies
- Performance Monitoring Layer - Network statistics, bottleneck detection, and health monitoring
262.4 Production Framework: Advanced Multi-Hop Network Management
This section provides a comprehensive production-ready Python framework for managing multi-hop ad-hoc networks in real-world IoT deployments. The implementation covers topology discovery, link quality assessment, multi-path routing, load balancing, and network performance monitoring.
262.4.1 Enumerations and Type Definitions
262.4.2 Core Data Structures
262.4.3 Main Classes
262.4.4 Comprehensive Examples
262.4.4.1 Example 1: Complete Network Topology Management
Output:
=== Ad-Hoc Network Topology Management ===
Network created: 20 nodes
Discovering neighbors based on transmission range (100m)...
Neighbor Discovery Results:
Total nodes: 20
Total links: 38
Network diameter: 6 hops
Connectivity ratio: 98.4%
Neighbor statistics:
Average neighbors per node: 3.8
Min neighbors: 1
Max neighbors: 8
Most connected: node_12 (8 neighbors)
Least connected: node_17 (1 neighbors)
--- Simulating Topology Change ---
Moving node_05 to new location...
Neighbors before move: 4
Neighbors after move: 2
Neighbor change: -2
Topology events recorded: 78
262.4.4.2 Example 2: Link Quality Estimation and Monitoring
Output:
=== Link Quality Estimation ===
Simulating excellent link: node_00-node_01
PDR: 94.0%
Quality: EXCELLENT
Latency: 10.2 +/- 1.9 ms
RSSI: -55.3 dBm
Stability score: 0.921
Predicted stability (30s): 0.915
Simulating good link: node_02-node_03
PDR: 81.0%
Quality: GOOD
Latency: 24.8 +/- 7.6 ms
RSSI: -70.2 dBm
Stability score: 0.762
Predicted stability (30s): 0.754
Simulating poor link: node_04-node_05
PDR: 44.0%
Quality: POOR
Latency: 59.3 +/- 19.2 ms
RSSI: -87.8 dBm
Stability score: 0.312
Predicted stability (30s): 0.298
262.4.4.3 Example 3: Multi-Path Routing with K-Shortest Paths
Output:
=== Multi-Path Routing ===
Computing multiple paths: node_00 -> node_15
Found 3 disjoint paths:
Path 1 (path_1):
Hops: node_00 -> node_03 -> node_07 -> node_12 -> node_15
Hop count: 4
Cost: 4.00
State: ACTIVE
Path 2 (path_2):
Hops: node_00 -> node_02 -> node_06 -> node_11 -> node_14 -> node_15
Hop count: 5
Cost: 5.00
State: ACTIVE
Path 3 (path_3):
Hops: node_00 -> node_01 -> node_05 -> node_09 -> node_13 -> node_15
Hop count: 5
Cost: 5.00
State: ACTIVE
=== Routing Strategy Comparison ===
SHORTEST_PATH:
Path usage distribution:
path_1: 50 packets (100%)
LOAD_BALANCED:
Path usage distribution:
path_1: 17 packets (34%)
path_2: 17 packets (34%)
path_3: 16 packets (32%)
ENERGY_AWARE:
Path usage distribution:
path_1: 24 packets (48%)
path_2: 15 packets (30%)
path_3: 11 packets (22%)
Final path delivery ratios:
path_1: 91.0% (141/155)
path_2: 87.5% (28/32)
path_3: 92.6% (25/27)
262.4.4.4 Example 4: Network Performance Monitoring
Output:
=== Network Performance Monitoring ===
Simulating network traffic...
Network Statistics:
Total nodes: 20
Total links: 38
Network diameter: 6 hops
Connectivity: 98.4%
Average battery: 84.3%
Average latency: 48.7 ms
Max latency: 92.3 ms
Bottleneck nodes detected: 3
High-traffic nodes:
node_12: 48 forwarded, 92.3% forwarding ratio
node_07: 35 forwarded, 87.5% forwarding ratio
node_03: 29 forwarded, 82.9% forwarding ratio
Top 5 nodes by packet forwarding:
node_12: 48 packets forwarded, 8 neighbors, 78.3% battery
node_07: 35 packets forwarded, 6 neighbors, 81.7% battery
node_03: 29 packets forwarded, 5 neighbors, 88.2% battery
node_06: 22 packets forwarded, 4 neighbors, 92.1% battery
node_11: 18 packets forwarded, 3 neighbors, 85.9% battery
262.4.4.5 Example 5: Energy-Aware Routing
Output:
=== Energy-Aware Routing Comparison ===
Testing Shortest Path strategy...
Packets delivered: 489
Min battery: 42.3%
Avg battery: 87.6%
Battery std dev: 18.7%
Dead nodes: 0
Testing Energy-Aware strategy...
Packets delivered: 487
Min battery: 71.8%
Avg battery: 89.2%
Battery std dev: 9.3%
Dead nodes: 0
=== Comparison ===
Energy-Aware vs Shortest Path:
Min battery improvement: +29.5%
Avg battery improvement: +1.6%
Battery balance (lower std is better): +9.4%
262.4.4.6 Example 6: Integrated Network Simulation
Output:
=== Integrated Multi-Hop Network Simulation ===
Creating 25-node ad-hoc network...
Measuring link quality...
Network initialized:
Nodes: 25
Links: 52
Diameter: 5 hops
Connectivity: 99.7%
============================================================
Period 1
============================================================
Network Performance:
Avg battery: 98.2%
Avg latency: 47.3 ms
Topology events: 105
Network Health:
Bottleneck nodes: 2
Failing links: 3
============================================================
Period 2
============================================================
Warning: Node failure detected!
Removed wsn_10 from network
Network Performance:
Avg battery: 96.5%
Avg latency: 49.1 ms
Topology events: 116
Network Health:
Bottleneck nodes: 3
Failing links: 4
============================================================
Period 3
============================================================
Network Performance:
Avg battery: 94.7%
Avg latency: 50.8 ms
Topology events: 116
Network Health:
Bottleneck nodes: 3
Failing links: 5
============================================================
Simulation Complete
============================================================
=== Final Network State ===
Topology:
Active nodes: 24
Active links: 48
Network diameter: 6 hops
Connectivity: 98.9%
Performance:
Average latency: 49.1 ms
Max latency: 87.6 ms
Average battery: 94.7%
Traffic Statistics:
Total sent: 289
Total received: 266
Total dropped: 23
Network PDR: 92.0%
262.5 Framework Summary
This production framework provides comprehensive multi-hop ad-hoc network management:
Topology Management:
- Dynamic neighbor discovery
- Link tracking and maintenance
- Topology event monitoring
- Network diameter and connectivity metrics
Link Quality Assessment:
- PDR, latency, jitter, RSSI tracking
- Quality classification (Excellent/Good/Fair/Poor)
- Stability scoring and prediction
- Windowed metric estimation
Multi-Path Routing:
- K-shortest paths algorithm (Yen’s variant)
- Multiple routing metrics (hop count, latency, reliability, energy, composite)
- Path disjointness for redundancy
- Route cost calculation
Routing Strategies:
- Shortest path (minimum hops)
- Load balanced (distribute traffic)
- Energy-aware (extend lifetime)
- QoS-aware (maximize delivery ratio)
Network Monitoring:
- Per-node statistics (forwarding, battery, energy)
- Network-wide metrics (latency, connectivity, diameter)
- Bottleneck detection
- Failing link identification
The framework enables production-ready multi-hop ad-hoc networks with advanced routing, quality monitoring, and performance optimization.
262.6 Summary
This chapter provided a production-ready framework for managing multi-hop ad-hoc networks in IoT deployments.
Key Takeaways:
Modular Architecture: The four-layer design (topology, quality, routing, monitoring) enables independent component development and testing
Link Quality Classification: PDR, RSSI, and latency thresholds classify links as Excellent (>90% PDR), Good (70-90%), Fair (50-70%), or Poor (<50%)
Multi-Path Redundancy: K-shortest paths with disjoint routes provide failover capability and load distribution options
Routing Strategy Selection: Choose based on application needs:
- Shortest path for low latency
- Load balanced for even wear
- Energy-aware for network longevity
- QoS-aware for delivery reliability
Continuous Monitoring: Real-time bottleneck detection and health monitoring prevent unexpected failures
262.7 What’s Next?
Continue to the assessment chapter to test your understanding with knowledge checks, worked examples, and understanding exercises.
Continue to Ad Hoc Networks: Assessment and Practice ->
Deep Dives:
- Ad-hoc Routing: Proactive (DSDV) - Table-driven routing with sequence numbers
- Ad-hoc Routing: Reactive (DSR) - On-demand source routing for sparse networks
- Multi-hop Fundamentals - Core concepts for multi-hop forwarding
Comparisons:
- Routing Fundamentals - General routing principles and protocols
- WSN Overview - Wireless sensor network architectures
Learning:
- Ad-hoc Labs and Quiz - Practice implementations and assessments
- Simulations Hub - Network simulation tools