Results 1 to 2 of 2
Hello,
recently I use the ns2 simulator to simulate local area network. I
write the tcl code following the manual downloaded from
The Network Simulator - ns-2 , but I ...
- 12-23-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 6
a problem with ns2 simulation,
Hello,
recently I use the ns2 simulator to simulate local area network. I
write the tcl code following the manual downloaded from
The Network Simulator - ns-2, but I find that every time I run the
code below, the output is 1.7293548387096773Mb/s,but it shouldn't
be,because I have set the bw of the local area network as 1Mb,how can
it achieve 1.7Mb, I am quite puzzled with it
I don't kown whether there should be some more settings or some
other
the code below just simulate a lan which transmits data from node n1
to node n2,the bw between n1 and n2 is set as 1Mb
is there any bugs in the code, please point them out and give me some advice, thanks a lot!
##########################################code#### ####################
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Define a 'finish' procedure
proc finish {} {
global ns file1
$ns flush-trace
close $file1
exec nam out.nam &
exit 0
}
set n1 [$ns node]
set n2 [$ns node]
set lan [$ns newLan "$n1 $n2" 1Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 65536
$tcp set packetSize_ 1024
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
proc get_throughput { tcp } {
#now calculate the average throughtput (in Mb/s)
puts "[expr [$tcp set ndatapack_]*8.0/1000/124]Mb/s"
}
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124 "get_throughput $tcp"
$ns at 125.0 "finish"
$ns run
################################################## ######
- 01-16-2009 #2Just Joined!
- Join Date
- Dec 2008
- Posts
- 6
Help me with my ns2 simulation!!!
Hi All,
I tried to simulate the tcp protocol on Lan network, but the result of simulation puzzled me.
I run the code below, in the code, I calculate the throughput of the tcp connection using
[expr [$tcp set ndatapack_]*8.0/1024/124]( which you can see more clearly in my code below),
here 8.0 represents one byte 8 bits, and 1024 is 1K, 124s is my simulation time,
But each time I run the simulation , I'll get the result 1.7632Mb/s,which is quite absurd,
could anyone point out the errors in my code,
or give me some useful suggestions or advices, thanks a lot.
the code below simulates a ftp application from node1(n1) to node2(n2)
Here is my code:
#================================================= =====
set ns [new Simulator]
proc finish {} {
exit 0
}
#define the nodes and the lan
set n1 [$ns node]
set n2 [$ns node]
set lan [$ns newLan "$n1 $n2" 100Mb 1ms LL Queue/DropTail MAC/Csma/Cd Channel]
#define the TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink
$tcp set window_ 65536
$tcp set packetSize_ 1024
#Setup a FTP over the TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#calculate the average throughtput (in Mb/s)
proc get_throughput { tcp } {
puts "[expr [$tcp set ndatapack_]*8.0/1024/124]Mb/s"
}
#begin to run
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124 "get_throughput $tcp"
$ns at 125.0 "finish"
$ns run
#=================================================


Reply With Quote