Tracing A subset of events 6-April- 2014 How to Trace a subset of trace events? We already mentioned how to trace all simulated events. Now, we will indicate ways to trace only a subset of these. 1- The first way to do so is by replacing the command $ns <filename> by the command $ns trace-queue trace-all <first node> <second node> <filename>. For example, the command $ns trace-queue $n2 $n3 $tracefile1, will result in an output trace file that contains only events that occurred over the link between nodes n2 & n3. Important notes:The trace-queue command line should appear of course after the definition of the links!!!. As we will see in the next example: #Create a simulator object set ns [new Simulator] #Open the Trace file set tracefile1 [open output.tr w] #Open the NAM trace file set namfile [open output.nam w] $ns namtrace-all $namfile #Define a 'finish' procedure proc finish {} { global ns tracefile1 namfile $ns flush-trace close $tracefile1 close $namfile exec nam output.nam & exit 0 } Tracing A subset of events #create five nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] #Create a link between the nodes $ns duplex-link $n0 $n1 2.4Mb 40ms DropTail $ns duplex-link $n2 $n1 3.1Mb 35ms DropTail $ns duplex-link $n2 $n3 2.2Mb 13ms DropTail $ns simplex-link $n3 $n4 1.8Mb 21ms DropTail $ns trace-queue $n2 $n3 $tracefile1 #Setup a TCP connection between nodes n0-n3 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink #Setup an FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp #Setup a UDP connection between nodes n2-n4 set udp [new Agent/UDP] $ns attach-agent $n2 $udp set null [new Agent/Null] $ns attach-agent $n4 $null $ns connect $udp $null #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp #scheduling events $ns at 0.5 "$cbr start" $ns at 1.0 "$ftp start" $ns at 45.0 "$ftp stop" 6-April- 2014 Tracing A subset of events 6-April- 2014 $ns at 48.5 "$cbr stop" #Call the finish procedure after 60 seconds of simulation time $ns at 60.0 "finish" #Run the simulation $ns run 2. It is also possible to filter events using unix command "grep" explained previously within the tcl script, so as to make the filtering to be done while the calling of the finish procedure, as we did with the command "exec nam out.nam &" for example the command exec grep "tcp" output.tr > output100.tr could be used inside the finish procedure to filtering the lines existed in the file output.tr and produce a new file called output100.tr that include the lines that have the word "tcp" only, or this could be done to start the processing of data while writing the file. For example, another way to limit the trace file ( or in general, to process them online while they are being written), is to use linux commands related to file processing within the tcl command set tracefile1 [ open out.tr w] with the command Set tracefile1 [ open "| grep \"tcp\" > output.tr" w] This command will result in filtering the lines written to the file "out.tr" and leaving only those that contains the word "tcp", as we will do with the next example: #Create a simulator object set ns [new Simulator] #Open the Trace file Set tracefile1 [ open "| grep \"tcp\" > output.tr" $ns trace-all $tracefile1 w] Tracing A subset of events #Open the NAM trace file set namfile [open output.nam w] $ns namtrace-all $namfile #Define a 'finish' procedure proc finish {} { global ns tracefile1 namfile $ns flush-trace close $tracefile1 close $namfile exec grep "2 3" output.tr > output100.tr exec nam output.nam & exit 0 } #create five nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] #Create a link between the nodes $ns duplex-link $n0 $n1 2.4Mb 40ms DropTail $ns duplex-link $n2 $n1 3.1Mb 35ms DropTail $ns duplex-link $n2 $n3 2.2Mb 13ms DropTail $ns simplex-link $n3 $n4 1.8Mb 21ms DropTail #Setup s TCP connection between nodes n0-n3 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink #Setup an FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp #Setup a UDP connection between nodes n2-n4 6-April- 2014 Tracing A subset of events set $ns set $ns $ns 6-April- 2014 udp [new Agent/UDP] attach-agent $n2 $udp null [new Agent/Null] attach-agent $n4 $null connect $udp $null #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp #scheduling events $ns at 0.5 "$cbr start" $ns at 1.0 "$ftp start" $ns at 45.0 "$ftp stop" $ns at 48.5 "$cbr stop" #Call the finish procedure after 60 seconds of simulation time $ns at 60.0 "finish" #Run the simulation $ns run
© Copyright 2024