Hi All, Our website moved to a new URL. Please bookmark the new link: https://ns2bloggers.blogspot.com/

Showing posts with label nodes. Show all posts
Showing posts with label nodes. Show all posts

Thursday, 7 October 2021

SELFISH NODES IN ADHOC NETWORKS

 Hey All, In this post we discuss about selfish nodes and how to simulate selfish node scenario using ns2. 

MANET is self-constrained network, each node should collaborate with each other to perform functions of the network but sometimes node may behave selfishly to conserve their resource like batter power, bandwidth etc. Such nodes are called selfish node and selfishness disturb the network and take away the network from their regular mission. 

The term selfish node mainly comes from a  specific class of AdHoc Networks known as cooperative networks,  where different autonomous and as well as heterogeneous nodes (possibly owned by different individuals)  form a network and agree to forward each others packet   in cooperative manner.
The biggest problem in this type of network  is "selfish node problem", where some may start dropping the packets of others just for its own benefit (to save the power)
There are two commonly known techniques to with the selfish node problem:  
  1. Reputation based
  2. Incentive based 
  3. The combination of both
This particular area of research is closely related with game theoretic approaches to solve as well analyze the problem.


Selfish node does not forward any data packets to other nodes except itself. Selfish nodes helps to optimize their own gain, with neglect for the welfare of other nodes in a network. Selfish Nodes cooperates during the route discovery cycle to maintain a concise routing table and to be present in other routing tables in a network.

Behavior of selfish nodes

  • It does not forward the RREQ messages.
  • Do not forward data messages.
  • Delayed forwarding RREQ messages.
  • Do not forward RREP messages.
Code for Selfish Nodes

#define options
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ant) Antenna/OmniAntenna
set val(ll) LL
set val(ifqlen) 150
set val(nn) 10
set val(rp) DSR
set val(X) 600
set val(Y) 600
set val(cstop) 50
set val(stop) 50
set val(cp) "scen-20-10"

# Initialize Global Variables
set ns_ [new Simulator]

set tracefd [open DSR.tr w] $ns_ trace-all $tracefd
set namtrace [open DSR.nam w] $ns_ namtrace-all-wireless $namtrace $val(X) $val(Y)
#set up top
set topo [new Topography] $topo load_flatgrid $val(X) $val(Y)
# Create God
set god_ [create-god $val(nn)] #create channel
set chan_1_ [new $val(chan)] set chan_2_ [new $val(chan)]

if {$val(rp) == "DSR"
} {

set val(ifq) CMUPriQueue
} else {

set val(ifq) Queue/DropTail/PriQueue
}
#configure nodes
$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 ON \
-channel $chan_1_
# create nodes
for {
set i 0
} {
$i < $val(nn)
} {
incr i
} {

set node_($i) [$ns_ node] $node_($i) random-motion 0;
}
puts "loading random connection pattern..."
source $val(cp)
source "cbr"
#Define initial node position
for {
set i 0
} {
$i<$val(nn)
} {
incr i
} {
$ns_ initial_node_pos $node_($i) 30
}
#$ns_ at 0.0 "[$node_(4) set ragent_] hacker"
for {
set i 0
} {
$i<4
} {
incr i
} {
$ns_ at $val(cstop) "$cbr_($i) stop"
}
for {
set i 0
} {
$i<$val(nn)
} {
incr i
} {
$ns_ at $val(stop).000000001 "$node_($i) reset";
}
$ns_ at 0.01 "$node_(0) add-mark m brown circle"
$ns_ at 0.01 "$node_(1) add-mark m brown circle"
$ns_ at 0.01 "$node_(2) add-mark m brown circle"
$ns_ at 0.01 "$node_(3) add-mark m brown circle"
$ns_ at 0.01 "$node_(4) add-mark m brown circle"
$ns_ at 0.01 "$node_(5) add-mark m brown circle"
$ns_ at 0.01 "$node_(6) add-mark m brown circle"
$ns_ at 0.01 "$node_(7) add-mark m brown circle"
$ns_ at 0.01 "$node_(8) add-mark m brown circle"
$ns_ at 0.01 "$node_(9) add-mark m brown circle"

$ns_ at 40.5 "$ns_ trace-annotate \" NODE 0 IS DETECTED AS SELFISH NODE AT TIME 40.5\""
$ns_ at 45.5 "$ns_ trace-annotate \" NODE 4 IS DETECTED AS SELFISH NODE AT TIME 45.5\""
$ns_ at 45.0 "$ns_ trace-annotate \" NODE 7 IS DETECTED AS SELFISH NODE AT TIME 45.0\""
$ns_ at 45.5 "$ns_ trace-annotate \" NODE 9 IS DETECTED AS SELFISH NODE AT TIME 45.5\""

$ns_ at 40.5 "$node_(0) delete-mark m"
$ns_ at 40.5 "$node_(0) add-mark m red circle"
$ns_ at 48.5 "$node_(4) delete-mark m"
$ns_ at 45.5 "$node_(4) add-mark m red circle"
$ns_ at 48.5 "$node_(7) delete-mark m"
$ns_ at 45.5 "$node_(7) add-mark m red circle"
$ns_ at 48.5 "$node_(9) delete-mark m"
$ns_ at 45.5 "$node_(9) add-mark m red circle"

$ns_ at $val(stop) "finish"
$ns_ at $val(stop).0 "$ns_ trace-annotate \"Simulation has ended\""
$ns_ at $val(stop).00000001 "puts \"NS exiting...\"; $ns_ halt"
proc finish {

} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
exit 0
}
puts "Starting simulation..."
$ns_ run





Friday, 23 May 2014

DATA ABOUT NEIGHBOR NODES

Here we developed a program to find the details of neighbor nodes especially current location and distance from a particular nodes.We think its helpful for you all.


proc neighbor {} {
set ns [Simulator instance]
global x1 x2 y1 y2 d n i j nn val
for {set i 0} {$i <$val(nn)} {incr i} {
puts "\n Neighbor list of node: $i"
   for {set j 0} {$j <$val(nn)} {incr j} {
if {$i != $j} {
set x1 [expr int([$n($i) set X_])]
set y1 [expr int([$n($i) set Y_])]
set x2 [expr int([$n($j) set X_])]
set y2 [expr int([$n($j) set Y_])]
set d [expr int(sqrt(pow(($x2-$x1),2)+pow(($y2-$y1),2)))]
puts "node: $j ==> position:- X: $x2 Y: $y2 Z= 0 \t distance: $d"
}
}
}
}
$ns at 10 "neighbor"



For script, Click here

SCREEN SHOT: 




Wednesday, 21 May 2014

DISTANCE CALCULATION BETWEEN NODES

Lot of people mailed us about how to calculate distance between neighbor nodes or between source and destination?? Now we added some scripts in front end program i.e in tcl script to find out distance between source and destination or with neighbor nodes. 

We used distance calculation equation to find out the distance between two nodes.If (x1,y1) be the position of first node and (x2,y2) be the position of second node.Then,distance (d) between two nodes is given as;

d=[ (x2-x1)2+(y2-y1)]1/2

For Script ,Click here.


Screen Shot :