Yes
The following is the Tcl code:
#Create a simulator objectset ns [new Simulator]#Set different color for dif flow$ns color 1 Blue$ns color 2 Redset tracefd [open example1.tr w]$ns trace-all $tracefdset namtracefd [open example1.nam w]$ns namtrace-all $namtracefdproc finish {} {global ns tracefd namtracefd$ns flush-traceclose $tracefdclose $namtracefdexec nam example1.nam &exit 0}# Set nodes, s1's id is 0, s2'id is 1set s1 [$ns node]set s2 [$ns node]# Set router node, id of r is 2set r [$ns node]# Set dest node, id of r is 3set d [$ns node]# Set link parameters$ns duplex-link $s1 $r 2Mb 10ms DropTail$ns duplex-link $s2 $r 2Mb 10ms DropTail$ns duplex-link $r $d 1.7Mb 20ms DropTail# Set Queue limit 10 for r and d$ns queue-limit $r $d 10# Set Node pos for NAM$ns duplex-link-op $s1 $r orient right-down$ns duplex-link-op $s2 $r orient right-up$ns duplex-link-op $r $d orient right# Observe the change of queue between r and d for NAM$ns duplex-link-op $r $d queuePos 0.5# Setup TCP agent and FTP trafficset tcp [new Agent/TCP]$ns attach-agent $s1 $tcpset sink [new Agent/TCPSink]$ns attach-agent $d $sink$ns connect $tcp $sink# In NAM, TCP will diplay in Blue$tcp set fid_ 1set ftp [new Application/FTP]$ftp attach-agent $tcp$ftp set type_ FTP# Setup a UDP Agent and CBR Trafficset udp [new Agent/UDP]$ns attach-agent $s2 $udpset null [new Agent/Null]$ns attach-agent $d $null$ns connect $udp $null$udp set fid_ 2set cbr [new Application/Traffic/CBR]$cbr attach-agent $udp$cbr set type_ CBR$cbr set packetSize_ 1000$cbr set rate_ 1mb$cbr set random_ false# Setup time line$ns at 0.1 "$cbr start"$ns at 1.0 "$ftp start"$ns at 4.0 "$ftp stop"$ns at 4.5 "$cbr stop"$ns at 5.0 "finish"$ns run
After Tcl is run, the. tr file is generated and the. tr file is analyzed using awk. The awk code is as follows to calculate the awk of cbr_delay:
# Measure the end to end delay by the trace filebegin {# program initializehighest_packet_id = 0 ;}{# awk will automatically execute this loop {} action = $1; time = $2; from = $3; To = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; DST = $10; seq_no = $11; packet_id = $12; # record the current Max packet idif (packet_id> highest_packet_id) highest_packet_id = packet_id; # record the Tx time of packetif (start_time [packet_id] = 0) Start_time [packet_id] = time; # record CBR flow_id = 2 RX time # both flow = 2, no drop, and Recv # Drop are required, because it is possible that 1-2 Recv, 2-3 drop # CBR path is 1-2-3, the entire path may be dropif (flow_id = 2 & Action! = "D") {If (Action = "R") {end_time [packet_id] = Time ;}} elseend_time [packet_id] =-1 ;} end {# When read over, start to calculatefor (packet_id = 0; packet_id <= highest_packet_id; packet_id ++) {start = start_time [packet_id]; end = end_time [packet_id]; duration = start-end; If (start <End) printf ("% F \ n", start, duration );}}
The shell file for running awk is as follows:
#!/bin/bashawk -f cbr_delay.awk example1.tr > cbr_delay
The shell file for gnuplot plotting is as follows:
#!/bin/bashgnuplot -persist<<EOFset terminal gifset output "cbr_delay.gif"set title "cbr_delay"set xlabel "simulation time"set ylabel "throughput/kbps"unset keyplot "cbr_delay" with linespointsEOF
The one above
-persist<<EOF
It can prevent gnuplot from popping up a bunch of things. The specific reason is not found. I found the gnuplot manual, but I didn't understand what persist means? The manual is explained as follows:
To give gnuplot commands directly in the command line, using the "-persist" option so that the plot remains
On the screen afterwards:
Gnuplot-persist-e "set title 'sine curve'; plot sin (x )"
After persist is added, you do not need to pop up a bunch of information, that is, you will not enter the gnuplot session
What is the meaning of <EOF?
CBR delay graphics