Skip to content

Latest commit

ย 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Priority-Coupled Elastic Routing (PCER) for IoT-Blockchain Networks

A tag-aware, energy-conscious routing protocol that dynamically balances latency and battery life in IoT networks โ€” simulated in NS-3.

Deploy with Vercel


๐Ÿ“„ Abstract

IoT networks face a fundamental trade-off: speed vs. battery life. A fire-alarm packet cannot wait in queue behind bulk sensor logs, yet routing everything at maximum speed drains resource-constrained nodes within hours.

PCER solves this by tagging every data packet with an urgency level and feeding it into a weighted cost function that selects the optimal next-hop. Critical alerts get the fastest path; bulk data takes the most energy-efficient route; standard traffic strikes a balance โ€” all while avoiding nodes whose batteries are about to die.


โœจ Key Features

Feature Description
Priority Tagging Packets are classified as Critical (0), Standard (1), or Bulk (2) at the source
Weighted 5-Component Cost Incorporates Delay, Energy (Sigmoid), Trust, ETX, and Queue Load
Bi-directional Backpressure L3 signals L7 to throttle injection when queue occupancy exceeds 60%
Dynamic Route Switching The protocol re-evaluates every hop in real time, guarded by Hysteresis
Standalone Demo A self-contained C++ binary demonstrates the routing logic without NS-3
Traffic Generator Python script simulates realistic IoT traffic distributions
Automated Analysis Matplotlib scripts produce publication-ready latency & network-life graphs

๐ŸŽฎ Live Demo

Open index.html in any browser โ€” no server or dependencies needed. The interactive demo features:

  • 5-node network with animated packets color-coded by priority (๐Ÿ”ด Critical, ๐ŸŸก Standard, ๐Ÿ”ต Bulk)
  • Live battery drain on Node 2 with automatic route-switch when it drops below 5 %
  • Real-time cost calculator panel showing the exact CalculateCost() math per hop
  • Playback controls โ€” Play / Pause / Speed / Reset + manual "Send Packet" button
  • 5-phase auto-play that tells the complete PCER story in 12 seconds

๐Ÿš€ Deploy to Vercel

You can deploy this entire simulation to your own Vercel account with one click:

  1. Push this code to your GitHub.
  2. Connect your repository to Vercel.
  3. Vercel will automatically detect the index.html and deploy it as a static site.
  4. Access different versions at:
    • / -> Latest (index.html)
    • /v2 -> Version 2
    • /v3 -> PCER-T v4 (Advanced)

๐Ÿ—๏ธ Architecture & Design

How PCER Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     Tag 0 (Critical)     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Source   โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”‚  Fastest Path (low   โ”‚
โ”‚  Node    โ”‚                          โ”‚  delay, ignore energy)โ”‚
โ”‚          โ”‚     Tag 1 (Standard)     โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚          โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”‚  Balanced Path       โ”‚
โ”‚          โ”‚                          โ”‚  (delay โ‰ˆ energy)    โ”‚
โ”‚          โ”‚     Tag 2 (Bulk)         โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚          โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”‚  Energy-Optimal Path โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                          โ”‚  (ignore delay)      โ”‚
                                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Cost Function

The heart of PCER lives in CalculateCost():

Cost = (wโ‚ ร— delay) + (wโ‚‚ ร— 1/energy)
Tag Traffic Type wโ‚ (Delay) wโ‚‚ (Energy) Behaviour
0 Critical 100 0 Pure speed โ€” pick the fastest neighbour
1 Standard 1 1 Balanced โ€” weigh both factors equally
2 Bulk 0 100 Pure efficiency โ€” pick the highest-battery neighbour

Survival Threshold

If a neighbour's battery drops below 5 %, its cost is set to โˆž regardless of tag. This prevents critical packets from being routed through a node that might die mid-transmission.

Dynamic Route Switching (Demo Scenario)

The standalone demo shows this in action over 10 simulated seconds:

Node 2: 5 ms delay, starts at 10 % battery (preferred for speed)
Node 3: 50 ms delay, starts at 100 % battery (backup)

As Node 2 drains below 5 %, PCER automatically switches all traffic โ€” including Critical โ€” to Node 3, trading latency for reliability.


๐Ÿ“‚ Repository Structure

Dynamic_routing_in_blockChain/
โ”‚
โ”œโ”€โ”€ traffic_generator.py        # Generates IoT traffic trace (100 events)
โ”œโ”€โ”€ traffic_trace.txt            # Sample output: [Time Src Dst Size Tag]
โ”‚
โ”œโ”€โ”€ ns3/                         # NS-3 implementation files
โ”‚   โ”œโ”€โ”€ pcer_tag.h               # PcErTag class โ€” urgency tag (0/1/2)
โ”‚   โ”œโ”€โ”€ pcer-routing-protocol.h  # Protocol header โ€” NeighborInfo, API
โ”‚   โ”œโ”€โ”€ pcer-routing-protocol.cc # โ˜… Core logic โ€” CalculateCost(), RouteOutput()
โ”‚   โ”œโ”€โ”€ pcer-helper.h            # NS-3 helper to install protocol on nodes
โ”‚   โ”œโ”€โ”€ pcer_sim.cc              # Full NS-3 simulation script (5 nodes, UDP)
โ”‚   โ””โ”€โ”€ pcer_routing.cc          # Auxiliary routing utilities
โ”‚
โ”œโ”€โ”€ pcer_demo.cpp                # Standalone demo (no NS-3 required)
โ”œโ”€โ”€ pcer_demo                    # Pre-compiled demo binary
โ”‚
โ”œโ”€โ”€ plot_results.py              # Matplotlib analysis script
โ”œโ”€โ”€ pcer_results.csv             # Baseline vs PCER comparison data
โ”‚
โ”œโ”€โ”€ latency_comparison.png       # Graph: Critical traffic latency
โ”œโ”€โ”€ network_life_comparison.png  # Graph: Battery remaining
โ”‚
โ”œโ”€โ”€ index.html                   # โ˜… Interactive animated demo (open in browser)
โ”œโ”€โ”€ final_documentation.md       # Step-by-step setup guide
โ””โ”€โ”€ README.md                    # โ† You are here

๐Ÿ“‹ Prerequisites

Tool Version Purpose
NS-3 โ‰ฅ 3.35 Network simulation (only for full sim)
g++ C++17 capable Compiling standalone demo
Python 3 โ‰ฅ 3.8 Traffic generation & plotting
matplotlib any Generating result graphs

๐Ÿš€ Quick Start

Option A โ€” Standalone Demo (No NS-3 needed)

The fastest way to see PCER in action:

# Compile
g++ -std=c++17 -o pcer_demo pcer_demo.cpp

# Run
./pcer_demo

Expected output:

=== PCER DYNAMIC SIMULATION (STANDALONE) ===
Scenario: Sending Critical Data (Tag 0).
Node 2: Delay 5ms (Preferred)
Node 3: Delay 50ms (Backup)
-----------------------------------------------------------------
| Time | Node 2 Bat | Cost (N2) | Cost (N3) | Routing Decision    |
-----------------------------------------------------------------
|   0s |     10%    |       500 |      5000 | Node 2 (Fast)       |
|   1s |      9%    |       500 |      5000 | Node 2 (Fast)       |
  ...
|   6s |      4%    |       INF |      5000 | -> SWITCH -> Node 3 |
  ...
-----------------------------------------------------------------

At t = 6 s, Node 2's battery hits 4 % โ†’ the survival threshold kicks in โ†’ PCER switches to Node 3.


Option B โ€” Full NS-3 Simulation

1. Generate Traffic

python3 traffic_generator.py
# โ†’ Creates traffic_trace.txt (100 IoT events with mixed tags)

2. Integrate with NS-3

Copy files into your NS-3 workspace:

# Copy simulation script
cp ns3/pcer_sim.cc  <NS3_DIR>/scratch/pcer_sim.cc

# Copy protocol files (easiest: put everything in scratch/)
cp ns3/pcer_tag.h                <NS3_DIR>/scratch/
cp ns3/pcer-routing-protocol.h   <NS3_DIR>/scratch/
cp ns3/pcer-routing-protocol.cc  <NS3_DIR>/scratch/
cp ns3/pcer-helper.h             <NS3_DIR>/scratch/

# Copy traffic trace
cp traffic_trace.txt <NS3_DIR>/

3. Compile & Run

cd <NS3_DIR>
./waf --run scratch/pcer_sim
# โ†’ Generates pcer_results_real.csv

4. Analyse Results

python3 plot_results.py
# โ†’ Generates latency_comparison.png & network_life_comparison.png

๐Ÿ“Š Results

Baseline vs PCER Comparison

Method Tag Avg Latency (ms) Network Life (%)
Baseline Critical 150.5 80
Baseline Standard 120.0 80
Baseline Bulk 200.0 80
PCER Critical 45.2 95
PCER Standard 110.0 95
PCER Bulk 210.0 95

Key takeaway: PCER reduces critical-traffic latency by 70 % (150.5 โ†’ 45.2 ms) while increasing overall network lifetime by 19 % (80 โ†’ 95 %).

Latency Comparison (Critical Traffic)

Latency Comparison โ€” Critical traffic is 70% faster under PCER

Network Lifetime

Network Life Comparison โ€” PCER maintains 95% battery vs 80% baseline


๐Ÿ”ฌ Cost Function Deep Dive

The core routing decision is made in pcer-routing-protocol.cc:

double PcerRoutingProtocol::CalculateCost(uint8_t tag, const NeighborInfo &neighbor) {
    double w1_delay = 1.0, w2_energy = 1.0;

    if (tag == 0) {        // CRITICAL โ†’ pure speed
        w1_delay = 100.0;
        w2_energy = 0.0;
    } else if (tag == 2) { // BULK โ†’ pure efficiency
        w1_delay = 0.0;
        w2_energy = 100.0;
    }
    // STANDARD keeps w1 = w2 = 1.0 (balanced)

    // Survival Threshold: dying nodes are avoided entirely
    if (neighbor.energy < 0.05)
        return std::numeric_limits<double>::max();

    double energy_cost = (neighbor.energy > 0.0001) ? (1.0 / neighbor.energy) : 10000.0;
    return (w1_delay * neighbor.delay) + (w2_energy * energy_cost);
}

Tuning guide: Adjust the weight constants (100.0, 0.0, 1.0) and the survival threshold (0.05) to match your specific network characteristics.


๐Ÿ”ฎ Future Work

  • Multi-hop path computation โ€” extend beyond direct-neighbour routing to full shortest-path trees
  • Multi-Agent Reinforcement Learning (MARL) โ€” replace static multi-component weights with adaptive RL layers
  • Hardware testbed โ€” validate on real IoT boards (ESP32 / Raspberry Pi mesh)

๐Ÿ“ License

This project is open-source and available under the MIT License.

Releases

Packages

Contributors

Languages