442  WSN Routing: Labs and Interactive Games

442.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Compare Routing Protocols: Experiment with AODV, DSR, and LEACH implementations
  • Analyze Energy Trade-offs: Measure energy consumption differences between routing approaches
  • Design Optimal Routes: Apply learned concepts to select paths in interactive simulations
  • Implement Routing Decisions: Code and test routing algorithms on simulated WSN hardware

442.2 Prerequisites

Before diving into this chapter, you should be familiar with:

442.3 WSN Route Optimizer Game

Test your understanding of WSN routing by designing optimal routes in this interactive strategy game. Balance energy consumption, latency, and reliability while learning different routing protocols.

TipHow to Play
  1. Select a level to learn different routing paradigms (Flat, Hierarchical, Geographic)
  2. Click nodes to build routing paths from sources to the sink
  3. Watch packet flow and energy depletion in real-time
  4. Complete objectives while maximizing network lifetime
NoteGame Scenarios

Single-Path vs Multi-Path Routing: In manual mode, try creating redundant paths. Multi-path routing improves reliability but increases energy consumption.

Cluster Head Selection (Level 2): LEACH rotates cluster heads to balance energy drain. Watch how fixed CH selection creates hot spots.

Energy-Aware Route Selection: Avoid nodes with low energy (red). The ETX metric favors reliable links over shortest paths.

Handling Node Failures: When nodes die (turn dark), the network must adapt. Geographic routing can route around voids.

Hot Spot Problem: Nodes near the sink relay more traffic. Use hierarchical routing or multi-path to distribute load.

TipStrategy Tips
  1. Level 1 (Flat): Compare flooding (high overhead, reliable) vs gossiping (low overhead, less reliable). Use Directed Diffusion for a balance.

  2. Level 2 (Hierarchical): Let LEACH auto-select cluster heads. Watch how rotation extends network lifetime vs fixed CH.

  3. Level 3 (Geographic): Observe greedy forwarding toward the sink. Dead nodes create “voids” that require perimeter routing.

  4. Manual Mode: Click nodes to build custom paths. Start from a source, connect through intermediate nodes to the sink. Monitor link quality percentages.


442.4 Hands-On Lab: Multi-Hop Routing Simulation

⏱️ ~45 min | ⭐⭐⭐ Advanced | 🧪 Hands-On Lab

442.4.1 Lab Overview

This hands-on lab simulates a Wireless Sensor Network with multiple ESP32 nodes demonstrating different routing protocols. You’ll experiment with routing decisions, energy-aware path selection, and compare the performance of AODV, DSR, and LEACH protocols in real-time.

What You’ll Learn:

  • How multi-hop routing works in wireless sensor networks
  • Differences between reactive (AODV, DSR) and proactive (LEACH) routing
  • Energy-aware routing decisions and their impact on network lifetime
  • Route discovery, maintenance, and recovery mechanisms
  • Cluster-based routing and aggregation strategies

442.4.2 Lab Setup

The simulation creates a 9-node WSN topology with:

  • 3 Sensor Nodes (S1, S2, S3) - Generate temperature/humidity data
  • 4 Intermediate Nodes (R1, R2, R3, R4) - Forward packets and aggregate data
  • 1 Cluster Head (CH) - Coordinates LEACH protocol
  • 1 Sink Node (SINK) - Destination for all data

Each node has a simulated battery level that depletes with transmission/reception, demonstrating energy-aware routing.

442.4.3 Network Topology

   S1 ──┬── R1 ──┬── CH ── SINK
        │        │    │
   S2 ──┼── R2 ──┤    │
        │        │    │
   S3 ──┴── R3 ──┴── R4

Links: S1↔R1, S1↔R2, S2↔R2, S2↔R3
       S3↔R3, S3↔R4, R1↔R2, R2↔R3
       R3↔R4, R1↔CH, R2↔CH, R4↔CH
       CH↔SINK

442.4.4 Key Code Sections

The complete simulation code is available in the Wokwi editor. Key sections include:

AODV Route Discovery:

void aodvRouteDiscovery(int source, int dest) {
  // Flood RREQ to neighbors
  for (int i = 0; i < NUM_NODES; i++) {
    if (topology[source][i] && nodes[i].active) {
      updateEnergy(source, true);   // TX cost
      updateEnergy(i, false);       // RX cost
      // Forward RREQ...
    }
  }
}

LEACH Cluster Formation:

void leachClusterFormation() {
  // Probabilistic cluster head selection
  for (int i = 0; i < numNodes; i++) {
    if (random(0, 100) < p * 100) {
      nodes[i].isClusterHead = true;
    }
  }
  // Assign members to nearest CH
}

Energy-Aware Forwarding:

int getNextHop(int current, int dest) {
  int bestHop = -1, bestMetric = 999999;
  for (int i = 0; i < MAX_ROUTES; i++) {
    if (routingTable[current][i].valid) {
      int metric = routingTable[current][i].hopCount;
      // Penalize low-energy nodes
      if (nodes[nextHop].energy < 30) metric += 10;
      if (metric < bestMetric) {
        bestMetric = metric;
        bestHop = routingTable[current][i].nextHop;
      }
    }
  }
  return bestHop;
}

442.4.5 Challenge Exercises

WarningHands-On Challenges

Try these modifications to deepen your understanding:

  1. Energy-Aware Path Selection
    • Modify getNextHop() to prioritize high-energy nodes
    • Implement adaptive energy thresholds based on network-wide energy levels
    • Compare network lifetime with and without energy awareness
  2. Route Quality Metrics
    • Add link quality estimation based on signal strength (RSSI)
    • Implement Expected Transmission Count (ETX) metric
    • Update calculateLinkQuality() to factor in packet loss
  3. LEACH Cluster Rotation
    • Implement probabilistic cluster head election (5% probability)
    • Rotate cluster heads based on residual energy
    • Compare energy consumption across nodes
  4. Multipath Routing
    • Modify DSR to maintain multiple routes
    • Implement route splitting for load balancing
    • Measure improvement in delivery rate
  5. Route Recovery
    • Add RERR (Route Error) packet handling for broken links
    • Implement local route repair before triggering new discovery
    • Measure reduction in route discovery overhead
  6. Protocol Comparison
    • Run each protocol for 2 minutes and record statistics
    • Compare delivery rate, latency, and energy consumption
    • Analyze which protocol performs best under different network densities

442.4.6 Expected Learning Outcomes

After completing this lab, you should be able to:

  • Explain the differences between reactive (AODV, DSR) and proactive (LEACH) routing
  • Identify when energy-aware routing improves network lifetime
  • Analyze the trade-offs between hop count and energy consumption
  • Implement route discovery and maintenance mechanisms
  • Evaluate protocol performance under different network conditions
  • Design hierarchical routing strategies for large-scale WSNs

442.4.7 Key Observations

Protocol Route Discovery Energy Efficiency Scalability Best Use Case
AODV On-demand (flooded RREQ) Moderate Good Mobile, dynamic networks
DSR On-demand (source routing) Low overhead Limited Small networks, stable topology
LEACH Cluster-based (periodic) High (aggregation) Excellent Dense, static sensor deployments
TipReal-World Applications
  • AODV: Smart city IoT with mobile nodes (vehicles, wearables)
  • DSR: Indoor sensor networks with stable topology
  • LEACH: Agricultural monitoring with thousands of static sensors
  • Energy-Aware Routing: Battery-powered environmental monitoring

442.5 Comprehensive Review Quiz

Test your understanding of WSN routing protocols with this comprehensive quiz.

Question 1: In LEACH (Low-Energy Adaptive Clustering Hierarchy), how does the protocol distribute energy consumption evenly across all nodes?

Explanation: LEACH uses randomized rotation of cluster head roles. Each round, every node decides independently whether to become cluster head based on probability P and rounds since last time as CH. Over many rounds, every node spends approximately P% of time as CH, balancing energy consumption. Since CH role consumes 3-5x more energy, rotation prevents any single node from dying early.

Question 2: TEEN (Threshold-sensitive Energy Efficient sensor Network) protocol is designed for reactive monitoring. How does it reduce transmissions compared to proactive protocols?

Explanation: TEEN’s threshold-based transmission: (1) Hard threshold (HT): Minimum value to trigger transmission. (2) Soft threshold (ST): Minimum change to trigger transmission. Node transmits only when value crosses HT AND differs by ≥ST from last transmission. During stable periods with temperature below HT: 0 transmissions. Result: 99%+ reduction in transmissions during normal operation.

Question 3: In Directed Diffusion, what is the purpose of the “reinforcement” phase after initial data delivery?

Explanation: Directed Diffusion reinforcement: (1) Interest propagation creates multiple gradients from source to sink. (2) Source sends low-rate exploratory data along ALL gradients. (3) Sink evaluates path quality and sends reinforcement along best path, increasing data rate. (4) Non-reinforced paths expire, focusing traffic on proven path.

Question 4: PEGASIS organizes sensors into a chain. What advantage does chain topology provide over cluster-based approaches like LEACH?

Explanation: PEGASIS chain formation: Data flows along chain from one end to the other, aggregating at each hop. Each node transmits to nearest neighbor (typically 10-20m) instead of cluster head (potentially 50-100m). Since energy is proportional to distance squared or fourth power, short transmissions save significant energy. Trade-off: Higher latency since data traverses entire chain.


442.6 Summary

This chapter provided hands-on experience with WSN routing protocols:

Key Takeaways:

  1. Interactive Learning: The WSN Route Optimizer game lets you experiment with different routing paradigms and see energy trade-offs in real-time

  2. Protocol Comparison: AODV, DSR, and LEACH each have strengths for different network conditions (mobile vs. static, small vs. large)

  3. Energy Awareness: Routing decisions must consider node energy levels to maximize network lifetime

  4. Practical Implementation: The Wokwi lab provides working code for routing algorithms that can be modified and tested

  5. Measurement Matters: Always compare delivery rate, latency, AND energy consumption when evaluating protocols