- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- how to set the probabilty by useing neighbors variables
Hi all,
I want to use the neighbors variables which was wrote by Vagabon in Probabilistic Broadcast Agent class. I want to set the probability in the Agent/MessagePassing/MyPBCast instproc init function according to the number of neighbors, for instance if the number of neighbors equal 10 set prob_ 0.5 ,else set prob_ 1.
I do not know how could I use the neighbors variable in this class.
#Probabilistic Broadcast Agent
#V.B., 2005
Class Agent/MessagePassing/MyPBCast -superclass { Agent/MessagePassing }
Agent/MessagePassing/MyPBCast instproc init {} {
$self instvar prob_
$self instvar seqno_
$self instvar flag_
$self next
set seqno_ 0
set flag_ 0
$self instvar agent_addr_
set prob_ 1
$self set_pkttype 13
$self set packetSize_ 256
}
Agent/MessagePassing/MyPBCast instproc setprob {prob} {
$self instvar prob_
set prob_ $prob
}
Agent/MessagePassing/MyPBCast instproc setseed {seed} {
$self instvar seed_
set seed_ $seed
expr srand($seed_)
}
Agent/MessagePassing/MyPBCast instproc send {} {
$self instvar seqno_
$self instvar agent_addr_
set msg “pbcast:$agent_addr_:$agent_addr_:$seqno_:”
set flag_ 1
$self sendto 256 $msg -1 90
}
Agent/MessagePassing/MyPBCast instproc recv { flg port len p } {
# receiver function
$self instvar agent_addr_
$self instvar flag_
$self instvar prob_
set L [split $p :]
set src_ [lindex $L 2]
set seqno_ [lindex $L 3]
if {$flag_ == 1} { return }
set flag_ 1
#here toss a coin and make probabilistic decision
set coin [expr rand()]
#puts $coin
#puts $prob_
if {$coin > $prob_} { return }
set msg “pbcast:$agent_addr_:$src_:$seqno_:”
$self sendto 256 $msg -1 90
}
thanks
If it is a wired network, then you may easily resolve neighbor list.
But in MANET, resolving neighbor list is not that much simple.
You can prepare a neighbor list by sending one hop hello broadcast and receiving reply messages of neighbor nodes.
You can directly derive the neighbors from global ns environment using “god”. You may refer the following link for how to use “god” for deriving neighbor list in MANET. But it will also require good knowledge about compiling ns2.
In wireless network, (AODV ) the nodes send HELLO message (broadcast) every 1 second. There is a neighbor table in AODV.cc . I hope you can use that for your purpose.