Dear all,
I have been trying to simulate a reliable data tranport protocol (the
rdt2.xprotocols from Kurose-Ross's
*Computer Networking* text). To simulate a lossless channel with bit-errors,
I need the ErrorModel object in my Tcl script to only mark the error_ flag
of packet and then forward it to the sink agent. The NS manual says the if
no drop-target is specified, then the sink agent should receive the
corrupted packet. But according to my simulation, the corrupted packet is *
always* dropped (confirmed by nam and trace files), whether or not
a drop-target is specified. If my script had worked correctly, then it would
have displayed the contents and error flag of all packets received by a sink
agent - it doesn't do that and I don't understand why. Can anyone please
help me out?
(I'm using ns-2.29, on Win XP through cygwin)


======================================TCL
CODE=====================================

#Create a simulator object
set ns [new Simulator]

set tracef [open out1.tr w]

$ns trace-all $tracef

#Open a nam trace file
set nf [open out.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}

#Create three nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail

#Define a 'recv' function for the class 'Agent/RDT1'
Agent/RDT1 instproc recv {from data err} {
$self instvar node_
puts "node [$node_ id] received ping answer from \
$from with data: $data. Error status: $err."
}

#Create two rdt agents and attach them to the nodes n0 and n2
set p0 [new Agent/RDT1]
$p0 set off_rdt1_ 0
$ns attach-agent $n0 $p0
set p1 [new Agent/RDT1]
$p1 set off_rdt1_ 0
$ns attach-agent $n2 $p1

#Create an ErrorModel modelling an error-prone but lossless virtual n0-n1
link
set em [new ErrorModel]
$em set unit pkt
$em set rate_ 0.1
$em ranvar [new RandomVariable/Uniform]
#$em drop-target $p1

$ns link-lossmodel $em $n0 $n1
#$ns lossmodel $em $n0 $n1

#Connect the two agents
$ns connect $p0 $p1

#Schedule events
$ns at 0.1 "$p0 send umayr"
$ns at 0.2 "$p0 send a"
$ns at 0.4 "$p0 send ab"
$ns at 0.5 "$p1 send a"
$ns at 0.6 "$p0 send cd"
$ns at 0.6 "$p1 send e"
$ns at 1.0 "finish"

#Run the simulation
$ns run

======================================OUTPUT=====================================

$ ns rdt1-err.tcl
warning: no class variable Agent/RDT1::off_rdt1_

        see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/RDT1::off_rdt1_

        see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/RDT1::off_rdt1_

        see tcl-object.tcl in tclcl for info about this warning.

node 2 received ping answer from  0 with data: ab. Error status: 0.
node 0 received ping answer from  2 with data: a. Error status: 0.
node 2 received ping answer from  0 with data: cd. Error status: 0.
node 0 received ping answer from  2 with data: e. Error status: 0.

======================================TRACE=====================================

+ 0.1 0 1 undefined 64 ------- 0 0.0 2.0 -1 0
- 0.1 0 1 undefined 64 ------- 0 0.0 2.0 -1 0
d 0.1 0 1 undefined 64 ------- 0 0.0 2.0 -1 0
+ 0.2 0 1 undefined 64 ------- 0 0.0 2.0 -1 1
- 0.2 0 1 undefined 64 ------- 0 0.0 2.0 -1 1
d 0.2 0 1 undefined 64 ------- 0 0.0 2.0 -1 1
+ 0.4 0 1 undefined 64 ------- 0 0.0 2.0 -1 2
- 0.4 0 1 undefined 64 ------- 0 0.0 2.0 -1 2
r 0.410512 0 1 undefined 64 ------- 0 0.0 2.0 -1 2
+ 0.410512 1 2 undefined 64 ------- 0 0.0 2.0 -1 2
- 0.410512 1 2 undefined 64 ------- 0 0.0 2.0 -1 2
r 0.421024 1 2 undefined 64 ------- 0 0.0 2.0 -1 2
...

Reply via email to