Study Notes on the mflood part of the test code in Xu leiming's book

Source: Internet
Author: User
Tags add time tcl code

The trace file obtained by testing the Tcl code in chapter 7 of Xu leiming,

1. After receiving the packet, The RTR routing layer adds a 20-byte IP header, so the package Length changes from 512 to 532.

Lines 6th and 7 are discarded because node 0 receives the packet sent by itself.In mflood. CC, ch-> num_forwards () = 0 is used to determine how many times the forwarding has been performed, but this number does not increase?

Use shell batch processing to set scenarios, traffic, run ns, and awk to process lab data

Sender

#!/bin/bash############################################### Shell grammar: #test expr is logic expression#lt means lower than##############################################i=1while (test $i -lt 2)doscn/setdest -v 1 -n 50 -p 0 -M 5 -t 100 -x 1000 -y 1000 > scn/scene-50n-0p-5s-100t-1000-1000ns scn/cbrgen.tcl -type cbr -nn 50 -seed $i -mc 30 -rate 1.0 > scn/cbr-50n-30c-1pns mflood-scene.tclawk -f getRatio.awk mflood-scene.tr    let i=i+1done

The TCL code is the code in Xu leiming's book.

#Agent/UDP set packetSize_ 6000# ======================================================================# Define options# ======================================================================set val(chan)       Channel/WirelessChannelset val(prop)       Propagation/TwoRayGroundset val(netif)      Phy/WirelessPhyset val(mac)        Mac/802_11set val(ifq)        Queue/DropTail/PriQueueset val(ll)         LLset val(ant)        Antenna/OmniAntennaset val(x)             1200   ;# X dimension of the topographyset val(y)             1200   ;# Y dimension of the topographyset val(ifqlen)         50            ;# max packet in ifqset val(seed)           0.0set val(rp)   MFloodset val(nn)             50             ;# how many nodes are simulatedset val(cp)             "scn/cbr-50n-30c-1p"set val(sc)             "scn/scene-50n-0p-5s-100t-1000-1000"set val(stop)    100# ======================================================================# Main Program# ======================================================================#ns-random 0# Initialize Global Variablesset ns_ [new Simulator]set tracefd [open mflood-scene.tr w]$ns_ trace-all $tracefd# set up topographyset topo [new Topography]$topo load_flatgrid $val(x) $val(y)set namtrace    [open mflood-scene.nam w]$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)## Create God#set god_ [create-god $val(nn)]# Create the specified number of mobilenodes [$val(nn)] and "attach" them# to the channel. # configure nodeset channel [new Channel/WirelessChannel]$channel set errorProbability_ 0.0        $ns_ node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channel $channel \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON\ -macTrace OFF \ -movementTrace OFF for {set i 0} {$i < $val(nn) } {incr i} {set node_($i) [$ns_ node]$node_($i) random-motion 0;}## Define node movement model#puts "Loading connection pattern..."source $val(cp)## Define traffic model#puts "Loading scenario file..."source $val(sc)# Define node initial position in namfor {set i 0} {$i < $val(nn)} {incr i} {    # 20 defines the node size in nam, must adjust it according to your scenario    # The function must be called after mobility model is defined    $ns_ initial_node_pos $node_($i) 20}# Tell nodes when the simulation endsfor {set i 0} {$i < $val(nn) } {incr i} {    $ns_ at $val(stop).0 "$node_($i) reset";}$ns_ at $val(stop).0 "stop"$ns_ at $val(stop).01 "puts \"NS EXITING...\" ; $ns_ halt"proc stop {} {    global ns_ tracefd namtrace    $ns_ flush-trace    close $tracefdclose $namtraceexit 0}puts "Starting Simulation..."$ns_ run

The getratio. awk file is the code in Xu leiming's book, with some comments added.

######################################## ################## Awk grammar: exp ~ /Regexp/If exp matches Regexp, the result is true # awk grammar: EXP !~ /Regexp/If exp does not match Regexp, the result is true # Regular Expression: # ^ escape character. Only strings at the beginning of the line can be matched #. match with any character # * match with any 0 or n characters #. * matching with any number of strings ################################## ######################## begin {sendline = 0; recvline = 0; fowardline = 0; If (mseq = 0) # If the maximum seq is not specified, set it to 1000 mseq = 10000; for (I = 0; I <mseq; I ++) {# initialize the cache array sseq [I] =-1; rseq [I] =-1 ;}}$ 0 ~ /^ S. * AGT/{If (sseq [$6] =-1) {sendline ++; sseq [$6] = $6 ;}}$ 0 ~ /^ R. * AGT/{If (rseq [$6] =-1) {recvline ++; rseq [$6] = $6 ;}}$ 0 ~ /^ F. * RTR/{fowardline ++;} end {printf "cbr s: % d r: % d, R/S ratio: %. 4f, F: % d \ n ", sendline, recvline, (recvline/sendline), fowardline ;}

Output result:

Cbr s: 1169 R: 809, R/sratio: 0.6920, F: 38242

The above is an analysis of the overall throughput, the following analysis of a source node and the target node:

Awk-V src = 1-v dst = 2-voutfile = 1-2data-F getnoderecv. awk mflood-scene.tr

Getnoderecv. awk file:

# Getnoderecv. awkbegin {If (step = 0) step = 10; base = 0; Start = 0; bytes = 0; total_bytes = 0; max = 0; calc = 0 ;} $0 ~ /^ S. * AGT/{If (base = 0 & $3 = ("_" src "_") {base = $2; Start = $2; calc = 1 ;}}$ 0 ~ /^ R. * AGT/& calc = 1 {time = $2; # I don't understand how to calculate it # the previous regular expression is only used to get the start time of sending # The first time period must be 0, because byte has not been added # later time period, set base to the current step. # Then, add time 1.1 and count the number of SRC packages received by DST. # When time exceeds step, calculate the throughput of the previous period # Time --> # base + step | if (Time> base) {BW = Bytes/(Step * 1000.0 ); if (max <BW) max = bw; printf "%. 9f %. 9f \ n ", base, BW> OUTFILE; base + = step; bytes = 0 ;}# Number of SRC packets received by DST # match [31: 0. if ($3 = ("_" DST "_") & match ($14 ,". "src": ")> = 0) {total_bytes + = $8; bytes + = $8 ;}} end {If (total_bytes) printf "# avg B/W = %. 3fkb/s \ n ", (total_bytes/1000.0)/(time-Start)> OUTFILE; elseprintf" avg B/W = 0.0kb/s \ n "; printf "# Max B/W = %. 3fkb/s \ n ", Max >>> OUTFILE ;}

Plot. Sh code:

#!/bin/bashgnuplot -persist<<EOFset terminal gifset output "thrpt.gif"set title "throughput"set xlabel "time"set ylabel "throughput/kbps"#unset keyplot "1-2data" title "1->2" with linespointsEOF

Drawing:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.