How to Implement MANET IoT in NS2

To implement the Mobile Ad Hoc Network (MANET) for Internet of Things (IoT) within NS2 that has to mimicking a network of mobile nodes, which can communicate with each other in a decentralized manner that don’t require for fixed infrastructure such as access points or base stations. In the context of IoT, this nodes (IoT devices) can be sensors, actuators, or other smart devices, which communicate to attain particular tasks, like data collection, observing, or controlling applications in a dynamic environment.

Given below is a step-by-step approach on how to execute MANET IoT in NS2:

Step-by-Step Implementation:

Key Features of MANET IoT:

  1. Mobile Nodes: IoT devices are mobile and communicate using ad-hoc networking principles.
  2. Dynamic Topology: These nodes can connect or leave the network actively.
  3. Routing Protocol: Execute the AODV (Ad hoc On-Demand Distance Vector) or DSR (Dynamic Source Routing) that are generally used for the MANETs.
  4. IoT Traffic: We can use the UDP, CBR (Constant Bit Rate), or TCP traffic to replicate the data transmission among IoT devices.
  1. NS2 Setup for MANET IoT

Initially, configure a simple example containing the necessary set up for mobile nodes, the wireless channel, and the MANET routing protocol (such as AODV).

# Create an NS2 simulator instance

set ns [new Simulator]

# Open trace files to log the simulation

set tracefile [open “manet_iot.tr” w]

set namfile [open “manet_iot.nam” w]

$ns trace-all $tracefile

$ns namtrace-all-wireless $namfile 1000 1000

# Define the wireless channel for communication

set chan_1_ [new Channel/WirelessChannel]

# Define the topography (e.g., a 1000×1000 grid)

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Define propagation, link, MAC, and queue parameters

set prop [new Propagation/TwoRayGround]   ;# Propagation model for wireless communication

set netif [new Phy/WirelessPhy]

set mac [new Mac/802_11]                  ;# MAC protocol simulating Wi-Fi for IoT

set ll [new LL]

set ifq [new Queue/DropTail/PriQueue]     ;# Priority queue

set ant [new Antenna/OmniAntenna]         ;# Omni-directional antenna

# Configure node parameters for MANET IoT

$ns node-config -adhocRouting AODV \      ;# Ad hoc routing protocol (AODV)

-llType $ll \

-macType $mac \

-ifqType $ifq \

-ifqLen 50 \              ;# Queue length for packet management

-antType $ant \

-propType $prop \

-phyType $netif \

-channel $chan_1_ \

-topoInstance $topo

  1. Defining Mobile IoT Nodes

In the simulation, describe the IoT devices as mobile nodes. This devices will perform as sensors, actuators, or other smart devices.

# Create mobile nodes representing IoT devices

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

# Set initial positions for the nodes (optional)

$node1 set X_ 100

$node1 set Y_ 200

$node2 set X_ 200

$node2 set Y_ 300

$node3 set X_ 300

$node3 set Y_ 400

$node4 set X_ 400

$node4 set Y_ 500

  1. Mobility Model for IoT Devices

In an IoT MANET, these IoT devices are mobile and move around actively. We can use the setdest commands to replicate the mobility for the IoT devices.

# Define mobility for the IoT nodes

$node1 setdest 400 500 10  ;# Move node1 to position (400,500) at speed 10 m/s

$node2 setdest 300 400 15  ;# Move node2 to position (300,400) at speed 15 m/s

$node3 setdest 200 300 12  ;# Move node3 to position (200,300) at speed 12 m/s

$node4 setdest 100 200 8   ;# Move node4 to position (100,200) at speed 8 m/s

  1. Traffic Setup for IoT Communication

Configure the traffic generation among the IoT devices to mimic communication among them and we can use UDP and CBR (Constant Bit Rate) to replicate usual IoT data exchanges.

Example: UDP Traffic between IoT Devices

# Create UDP agents for IoT communication

set udp1 [new Agent/UDP]

set udp2 [new Agent/UDP]

set null1 [new Agent/Null]

set null2 [new Agent/Null]

# Attach agents to IoT devices (node1 to node2 communication)

$ns attach-agent $node1 $udp1

$ns attach-agent $node2 $null1

# Connect UDP agent to the sink (null agent)

$ns connect $udp1 $null1

# Create a CBR traffic source to simulate continuous data transmission between IoT devices

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512         ;# Packet size of 512 bytes

$cbr1 set rate_ 100Kb             ;# Data rate of 100Kb/s

# Start the traffic at time 1.0 seconds and stop at 20.0 seconds

$ns at 1.0 “$cbr1 start”

$ns at 20.0 “$cbr1 stop”

Example: TCP Communication Between IoT Devices

# Create TCP agents for reliable IoT communication (node3 to node4)

set tcp1 [new Agent/TCP]

set tcpSink [new Agent/TCPSink]

# Attach TCP agents to IoT devices

$ns attach-agent $node3 $tcp1

$ns attach-agent $node4 $tcpSink

# Connect TCP agent to TCPSink (node3 to node4 communication)

$ns connect $tcp1 $tcpSink

# Use FTP application to simulate file transfer between IoT devices

set ftp [new Application/FTP]

$ftp attach-agent $tcp1

# Start FTP communication at time 5.0 seconds and stop at 25.0 seconds

$ns at 5.0 “$ftp start”

$ns at 25.0 “$ftp stop”

  1. Routing Protocol for MANET IoT

As the devices are mobile, a routing protocol is required to find and maintain routes. The AODV (Ad hoc On-Demand Distance Vector) protocol is used in this sample, however we can also use another protocols such as DSR.

# AODV is configured as the routing protocol in the node-config section

# No further routing configuration is required unless specific modifications are needed.

  1. Running the Simulation

Place the simulation duration and run the simulation. Finally, complete the simulation then close the trace files.

# Set the simulation end time

$ns at 30.0 “finish”

# Finish procedure to close trace files and end simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exit 0

}

# Run the simulation

$ns run

  1. Analysing the Results

We can be examined the trace files and network animation (NAM), after running the simulation that to estimate the performance of the MANET IoT network:

  • Throughput: Calculate the amount of data efficiently transmitted among the IoT devices.
  • Latency: Verify for the delays in the packet transmission.
  • Routing Performance: Compute how successfully AODV manages the route discovery and maintenance.
  • Packet Loss: Investigate packet loss in the network because of the mobility and topology changes.

In this presented manual, we had shown and focussed on comprehensive explanation related to the implement of MANET IoT with the support of ns2 simulator. We will deliver additional valuable informations on this protocol, if needed.

Our experts can provide advise on the context of IoT, including nodes such as sensors, actuators, and other smart devices relevant to your project. We focus on improving your network performance, so provide us your project information for the best results. Ns2project.com will be your finest support partner for MANET IoT implementation in ns2tool. Our developers provide the greatest thesis ideas and themes matched to your requirements.