- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- Send real stuff in NS2
wishlog
Participant
I would like to ask how can I send real data through ns2,
“Refer Agent message passing” Is there have any sample code in this topic? thank you very much.
CharlesPandian
Keymaster
The following code segment shows the usage of Message Passing Agent.
You can refer the whole example script ‘flooding.tcl’ under the directory ns-allinone-x.xxns-x.xxtclex
# subclass Agent/MessagePassing to make it do flooding
Class Agent/MessagePassing/Flooding -superclass Agent/MessagePassing
Agent/MessagePassing/Flooding instproc send_message {size msgid msg} {
$self instvar messages_seen node_
global ns MESSAGE_PORT
$ns trace-annotate "Node [$node_ node-addr] is sending {$msgid:$msg}"
lappend messages_seen $msgid
$self send_to_neighbors -1 $MESSAGE_PORT $size "$msgid:$msg"
}
Agent/MessagePassing/Flooding instproc send_to_neighbors {skip port size data} {
$self instvar node_
foreach x [$node_ neighbors] {
set addr [$x set address_]
if {$addr != $skip} {
$self sendto $size $data $addr $port
}
}
}
Agent/MessagePassing/Flooding instproc recv {source sport size data} {
$self instvar messages_seen node_
global ns
# extract message ID from message
set message_id [lindex [split $data ":"] 0]
if {[lsearch $messages_seen $message_id] == -1} {
lappend messages_seen $message_id
$ns trace-annotate "Node [$node_ node-addr] received {$data}"
$self send_to_neighbors $source $sport $size $data
} else {
$ns trace-annotate "Node [$node_ node-addr] received redundant copy of message #$message_id"
}
}
thinkpader
Participant
@wishlog wrote:
I would like to ask how can I send real data through ns2,
“Refer Agent message passing” Is there have any sample code in this topic? thank you very much.
I also want to know how to perform real data transmission in ns2. can anyone give me a hint?
Thanks in advance!