Skip to content

Message Flooding Simulation Under Wireless Network using ns2

Flooding is a reliable mechanism to forward a message in a wired or wireless network.

There are generally two types of flooding available, uncontrolled flooding and controlled flooding.[1] In uncontrolled flooding each node unconditionally distributes packets to each of its neighbours. Without conditional logic to prevent indefinite recirculation of the same packet and may lead to broadcast storms. On  the other hand, Controlled flooding has its own logic to make it muchreliable,

The Message Flooding Algorithm

The following steps explain a simple message flooding logic:

  1. The  Flooding algorithm starts with a source node broadcasting a packet to all its neighbours within its broadcast range. 
  2. The neighbouring nodes that are receiving a broadcast message simply rebroadcast the packet exactly one time.
  3. If the same packet is received again by a node, then simply it will drop the packet without rebroadcasting it again.
  4. This process continues until the message reaches all the nodes in the network.

In this example, we will see an ns-2 implementation of this above message flooding algorithm under Wireless Adhoc Network. In fact, a wired version of the flooding algorithm is already available in the example section of ns-2 code. What I present here is a simple wireless version of the flooding algorithm.

The Main Code Segments of the the ns-2 Simulation

Some Parameters of the Simulation

set MESSAGE_PORT 42
set BROADCAST_ADDR -1
set NamAnimationSpeed 250u ;#in Micro Seconds
set MessageSize 100 ;# in bytes Max 1500
set NodeVeocity 20 ; # meters per second
set val(chan) Channel/WirelessChannel ;#Channel Type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/Simple
Mac/Simple set bandwidth_ 1Mb
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(rp) DumbAgent

Setting Even Trace and Nam Trace

set ns [new Simulator]
set f [open FloodingAlgorithm.tr w]
$ns trace-all $f
set nf [open FloodingAlgorithm.nam w]
$ns namtrace-all-wireless $nf $val(x) $val(y)
$ns use-newtrace

Setting Default Node Parameters

# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $num_nodes
set chan_1_ [new $val(chan)]

$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1_

Deriving Our Flooding Agent from Agent/MessagePassing

Flooding instproc recv Function

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

Create a Some Nodes

# create a bunch of nodes
for {set i 0} {$i < $num_nodes} {incr i} {
set n($i) [$ns node]
$n($i) color “black”
$n($i) set Y_ [expr 150*floor($i/$group_size) + 100*(($i%$group_size)>=($group_size/2))]
$n($i) set X_ [expr (20*$group_size)*($i/$group_size%2) + 100*($i%($group_size/2))]
$n($i) set Z_ 0.0
$ns initial_node_pos $n($i) 30
}

Attach Agent/MessagePassing/Flooding to each node

# attach a new Agent/MessagePassing/Flooding to each node on port $MESSAGE_PORT
for {set i 0} {$i < $num_nodes} {incr i} {
set a($i) [new Agent/MessagePassing/Flooding]
$n($i) attach $a($i) $MESSAGE_PORT
$a($i) set messages_seen {}
}

Start the Flooding Process

$ns at 5.1 “$a(1) send_message $MessageSize 1 {BroadcastMessageI} $MESSAGE_PORT”

Close Files at End

$ns at 10.0 “finish”

proc finish {} {
global ns f nf val NamAnimationSpeed 
$ns flush-trace
close $f
close $nf
exit 0
}

$ns run

The Network Animation of Flooding Algorithm Simulation

The following gif animation shows the nam output of the network simulation. The node 1 starts the flooding process. The receiving nodes will become brown for an instant and them become blue. The retransmitting nodes will become red for an instant and then again become blue. In this way, the propagation of the flooding message over time. can be visualized on nam.

The following article discuss about k-mean based clustering implementation on ns-2

Example of k-mean Clustering Algorithm Implementation on ns2

References:

  1. https://en.wikipedia.org/wiki/Flooding_(computer_networking)
WhatsApp Discuss Through WhatsApp