How to Create Selfish Attack in MANET using NS2?

Description

Selfish nodes are the nodes that do not cooperate in network operations. The code given below deals with the selfish attack in which the selfish node drops the RREP packet instead of forwarding it thereby not participating in routing operation.

TCL part :

set now 3.0
set time 3.0
#*******Data Transmission from Source to Destination*****
set udp [new Agent/UDP]
$ns attach-agent $node_($source) $udp
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr attach-agent $udp
set null [new Agent/Null]
$ns attach-agent $node_($destination) $null
$ns connect $udp $null
$ns at $now "$cbr start"
$ns at 3.1 "$ns trace-annotate \" Data transmission from source node to destination node\""
$ns at 3.0 "[$node_(2) set ragent_] selfish"
$ns at 3.0 "$node_(2) color red"
$ns at 3.0 "$node_(2) label Attacker"
$ns at 4.1 "$ns trace-annotate \" Node_2 is selfish node which node drops reply packets \""
$ns at [expr $now + $time] "$cbr stop"

C++ part :

if (selfish == true) {
printf("Reply received by node is selfish node %d So it drops the packet time %f\n",index,Scheduler::instance().clock());
drop(p, DROP_RTR_ROUTE_LOOP);
return;
}

Screenshot

Create Selfish Attack Creation in MANET using NS2

Create Selfish Attack Creation in MANET using NS2

Create Selfish Attack Creation in MANET using NS2