Selfish Nodes in NS2
Implementing Selfish nodes in NS2 simulatorWhat is Selfish nodes? How to simulate Selfish Nodes using NS2 simulator?
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 .
NS2 Projects Video Output
See our Latest Video Output of Ns2 Projects on Various Domain.
Ns2 Projects
Customized NS2 Projects for B.E/B.Tech/M.E/M.Tech/Ms/PhD Scholars.
Ns2 Projects Screen Shots
Ns2 Projects Screen Shots.Regular Update of NS2 Projects Screenshots here!
Sample code for selfish node:
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
Journal Support for Research Scholars
Ns2 Projects Work Progress
- MANET – Mobile Ad Hoc Network 95%
- VANET – Vechicle Ad Hoc Netwok 97%
- LTE – Long Term Evolution 78%
- IoT – Internet of Things 90%
- Wireless Sensor Network 89%
- Network Security 89%
- Ns2 Attacks 96%
- Cognitive Radio Network 85%
- Parallel and Distributed Computing 73%
- SDN – Software Defined Networking 95%
- P2P , Video Streaming , Peersim 96%
- IPV4 , IPV6 88%
- 4G Network , 5G Network 80%
- Visual , Underwater Sensor Network 79%
- Multicasting Communication 84%
- Wimax, WiFi 90%
- OFDMA 94%