[ns] Help :Command Problem for awk script

Erico Augusto ericosign at gmail.com
Fri Feb 15 21:17:17 PST 2008


Copy and paste this:

gawk -f throughput.awk  out.tr

Execute it.

2008/2/12, LoTuS SwEeT <vipz_genius002 at yahoo.com>:
>
>
>
>    Hi there,
>
> I got this problem when i was simulating this script.
>
>
> #Create a simulator object
>
> set ns [new Simulator]
>
>
>
> #Define different colors for data flows (for NAM)
>
> $ns color 1 Blue
>
> $ns color 2 Red
>
>
>
> #Open the NAM trace file
>
> set nf [open out.nam w]
>
> $ns namtrace-all $nf
>
>
>
> #Open the traffic trace file to record all events
>
> set nd [open out.tr w]
>
> $ns trace-all $nd
>
>
>
> #Define a 'finish' procedure
>
> proc finish {} {
>
>         global ns nf nd
>
>         $ns flush-trace
>
>         #Close the NAM trace file
>
>         close $nf
>
>         close $nd
>
>         #Execute NAM on the trace file
>
>         exec nam out.nam &
>
>         exit 0
>
> }
>
>
>
> #Create four nodes
>
> set n0 [$ns node]
>
> set n1 [$ns node]
>
> set n2 [$ns node]
>
> set n3 [$ns node]
>
>
>
> #Create links between the nodes
>
> $ns duplex-link $n0 $n2 2Mb 10ms DropTail
>
> $ns duplex-link $n1 $n2 2Mb 10ms DropTail
>
> $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
>
>
>
> #Set Queue Size of link (n2-n3) to 10
>
> $ns queue-limit $n2 $n3 10
>
>
>
> #Give node position (for NAM)
>
> $ns duplex-link-op $n0 $n2 orient right-down
>
> $ns duplex-link-op $n1 $n2 orient right-up
>
> $ns duplex-link-op $n2 $n3 orient right
>
>
>
> #Monitor the queue for link (n2-n3). (for NAM)
>
> $ns duplex-link-op $n2 $n3 queuePos 0.5
>
>
>
> #Setup a TCP connection
>
> set tcp [new Agent/TCP]
>
> $tcp set class_ 2
>
> $ns attach-agent $n0 $tcp
>
> set sink [new Agent/TCPSink]
>
> $ns attach-agent $n3 $sink
>
> $ns connect $tcp $sink
>
> $tcp set fid_ 1
>
>
>
> #Setup a FTP over TCP connection
>
> set ftp [new Application/FTP]
>
> $ftp attach-agent $tcp
>
> $ftp set type_ FTP
>
>
>
> #Setup a UDP connection
>
> set udp [new Agent/UDP]
>
> $ns attach-agent $n1 $udp
>
> set null [new Agent/Null]
>
> $ns attach-agent $n3 $null
>
> $ns connect $udp $null
>
> $udp set fid_ 2
>
>
>
> #Setup a CBR over UDP connection
>
> set cbr [new Application/Traffic/CBR]
>
> $cbr attach-agent $udp
>
> $cbr set type_ CBR
>
> $cbr set packet_size_ 1000
>
> $cbr set rate_ 1mb
>
> $cbr set random_ false
>
>
>
> #Schedule events for the CBR and FTP agents
>
> $ns at 0.1 "$cbr start"
>
> $ns at 1.0 "$ftp start"
>
> $ns at 4.0 "$ftp stop"
>
> $ns at 4.5 "$cbr stop"
>
>
>
> #Detach tcp and sink agents (not really necessary)
>
> $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
>
>
>
> #Call the finish procedure after 5 seconds of simulation time
>
> $ns at 5.0 "finish"
>
>
>
> #Print CBR packet size and interval
>
> puts "CBR packet size = [$cbr set packet_size_]"
>
> puts "CBR interval = [$cbr set interval_]"
>
>
>
> #Run the simulation
>
> $ns run
> -------------------------------------------------------------------------
>
> Script for measuring throughput
>
> ---------------------------
> throughput.awk------------------------------------------------------
> BEGIN {
> >         recv = 0
> > }
> >
> > {
> >         # Trace line format: normal
> >         if ($2 != "-t") {
> >                 event = $1
> >                 time = $2
> >                 if (event == "+" || event == "-") node_id = $3
> >                 if (event == "r" || event == "d") node_id = $4
> >                 flow_id = $8
> >                 pkt_id = $12
> >                 pkt_size = $6
> >         }
> >         # Trace line format: new
> >         if ($2 == "-t") {
> >                 event = $1
> >                 time = $3
> >                 node_id = $5
> >                 flow_id = $39
> >                 pkt_id = $41
> >                 pkt_size = $37
> >         }
> >
> >         # Calculate total received packets' size
> >         if (flow_id == flow && event == "r" && node_id == dst) {
> >                 if (flow_t != "sctp") {
> >                         recv += pkt_size - hdr_size
> >                         #printf("recv[%g] = %g --> tot:
> > %g\n",node_id,pkt_size-hdr_size,recv)
> >                 } else {
> >                         # Rip off SCTP header, whose size depends
> >                         # on the number of chunks in each packet
> >                         if (pkt_size == 40) pkt_size = 0
> >                         if (pkt_size == 448) pkt_size = 400
> >                         if (pkt_size == 864) pkt_size = 800
> >                         if (pkt_size == 1280) pkt_size = 1200
> >                         recv += pkt_size
> >                         #printf("recv[%g] = %g --> tot:
> > %g\n",node_id,pkt_size,recv)
> >                 }
> >         }
> > }
> >
> > END {
> >         printf("%10g %10s %10g\n",flow,flow_t,(recv/simtime)*(8/1000))
> > }
>
> ----------------------------------------------------------------------------------------------------
> I used following command for throughput and i got following error
>
> $gawk  –f  throughput.awk  out.tr
>
> bash: –f: command not found
>
>
> LoTuSwEeT at GmAiL.CoM
>
>
>
>
>       ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
>


More information about the Ns-users mailing list