You are on page 1of 7

Linkping University, Dept. of Science & Technology T !-0"2# et$ork Si%&l'tion, ( )*TS cre+its ),'%iner# Di -&'n. Se%in'rs# .

'ngelis /ngel'kis. L'0s# 1ing He.

HT1-2011

TNK092 NETWORK SIMULATION LAB ASSIGNMENT #2


S)2T. 13 2011
th

NS2 Adding modules nd !esul"s m ni#ul "ion$ The st&+ents $ill foc&s on ho$ to '++ their o$n %o+&les in S2. They $ill le'rn ho$ to '++ ' ne$ 'gent into S2 'n+ ho$ to '+'pt so&rce co+es 'ccor+ingly. 4or the p&rpose of reporting, st&+ents $ill 'lso le'rn ho$ to &se '$k to 'n'ly5e syste% perfor%'nce &sing the tr'ce file. Re%ui!emen"s& Lin&, co%%'n+s 4'%ili'rity $ith tcl 6'sic S2 &n+erst'n+ing O'(e)"i*es 4ollo$ing the step-0y-step instr&ctions 0elo$ yo& $ill i%ple%ent ' ne$ UD2 'n+ ' ne$ *67 'gent in S2, 'n+ reco%pile the soft$'re. -o& $ill &se the '$k co+e provi+e+ in the lect&res to c'lc&l'te syste% p'r'%eters 8thro&ghp&t, 9itter, +el'y:; -o& $ill vis&'li5e the res&lt 0y &sing gn&plot 8prefer'0ly;, or other gr'ph-plotting soft$'re yo& 're f'%ili'r $ith. <refer to assignment #1, on how results should be presented in the report.= Det'ile+ instr&ctions see 0elo$ 8'lso 'v'il'0le fro% ns 0y e,'%ple 8slightly ch'nge+;; Re#o!"ing& The e,pecte+ res&lt of this 'ssign%ent is the s&ccessf&lly i%ple%ent'tion of the ne$ %o+&le 'n+ &se the '$k co+es. >ncl&+e the si%&l'tion scen'rio sn'pshot fro% n'%, perfor%'nce gr'phs 8%ini%&% re?&ire%ent is# to present# 81; thro&ghp&t, 82; 9itter, 'n+ 83; +el'y; into yo&r report. Go l @e $'nt to 0&il+ ' %&lti%e+i' 'pplic'tion th't r&ns over ' UD2 connection, $hich si%&l'tes the 0eh'vior of 'n i%'gin'ry %&lti%e+i' 'pplic'tion th't i%ple%ents ' Afive rate media scalingA sche%e $hich c'n, to so%e e,tent, respon+ to net$ork congestion, 0y ch'nging enco+ing 'n+ tr'ns%ission policy p'irs 'ssoci'te+ $ith the sc'le p'r'%eter v'l&es. >n this i%ple%ent'tion, it is 'ss&%e+ th't $hen ' connection is est'0lishe+, the sen+er 'n+ the receiver 'gree on B +ifferent sets of enco+ing 'n+ tr'ns%ission policy p'irs, 'n+ 'ssoci'te the% $ith B integers C0..DE. 4or si%plicity re'sons, it is 'lso 'ss&%e+ th't ' )ons" n" "! nsmission ! "e is +eter%ine+ for e'ch of the enco+ing 'n+ tr'ns%ission policy p'irs, 'n+ every p'ir &ses # )+e"s o, "-e s me si.e reg'r+less of the enco+ing sche%e. 6'sic'lly, this Afive r'te %e+i' sc'lingA $orks 's follo$s. The sen+er st'rts $ith the tr'ns%ission r'te 'ssoci'te+ $ith sc'le 0, 'n+ ch'nges r'tes 'ccor+ing to the sc'le v'l&e th't the receiver sen+s 0'ck. The receiver is responsi0le for %onitoring net$ork congestion 'n+ +eter%ining the sc'le f'ctor. 4or congestion %onitoring, ' si%ple perio+ic'l 8for every 7TT secon+; p'cket loss %onitoring is &se+, 'n+ even single # )+e" loss " e )- #e!iod is !eg !ded s ne"/o!+ )onges"ion. >f congestion is +etecte+, the receiver re+&ces the sc'le p'r'%eter v'l&e to h'lf 'n+ notifies the sen+er of this v'l&e. >f no p'cket loss is +etecte+, the receiver incre'ses the v'l&e 0y one 'n+ notifies the sen+er. An l0sis 6efore i%ple%enting this 'pplic'tion, e,'%ining the UD2 'gent i%ple%ent'tion reve'ls one %'9or pro0le%# Since ' UD2 'gent 'lloc'tes 'n+ sen+s net$ork p'ckets, 'll the infor%'tion nee+e+ for

'pplic'tion level co%%&nic'tion sho&l+ 0e h'n+e+ to the UD2 'gent 's ' +'t' stre'%. Ho$ever, the UD2 i%ple%ent'tion 'lloc'tes p'ckets th't only h've ' he'+er st'ck. Therefore, /e need "o modi,0 "-e U12 im#lemen" "ion to '++ ' %ech'nis% to sen+ the +'t' receive+ fro% the 'pplic'tion. >t is 'lso note+ th't $e %ight $'nt to &se this 'pplic'tion for f&rther rese'rch on >2 ro&ter ?&e&e %'n'ge%ent %ech'nis%s. Therefore, $e nee+ ' $'y to +isting&ish this type of %&lti%e+i' stre'% fro% other types of stre'%s. Th't is, /e lso need "o modi,0 U12 gen" "o !e)o!d d " "0#e in one o, I2 -e de! ,ields "- " is )u!!en"l0 no" used.

A$ Im#lemen" "ion
4or this 'pplic'tion, $e t'ke the *67 i%ple%ent'tion 'n+ %o+ify it to h've the Afive level %e+i' sc'lingA fe't&re. @e e,'%ine+ the *FF cl'ss hier'rchy. @e n'%e the cl'ss of this 'pplic'tion 's AMmAppA 'n+ i%ple%ent 's ' chil+ cl'ss of AApplicationA. The %'tching GTcl hier'rchy n'%e is therefore AApplication/MmAppA. The sen+er 'n+ receiver 0eh'vior of the 'pplic'tion 're i%ple%ente+ together in MmApp. @e n'%e the %o+ifie+ UD2 'gent $ho $ill s&pport MmApp, 's AUdpMmAgentA 'n+ i%ple%ent it 's ' chil+ cl'ss of UdpAgent. The %'tching GTcl hier'rchy n'%e is AAgent/UDP/UDPmmA. 3$ MmA## 4e de!& 4or the 'pplic'tion level co%%&nic'tion, $e +efine ' p'cket he'+er $hose str&ct&re in *FF is hdr_mm. @henever the 'pplic'tion h's infor%'tion to tr'ns%it, it $ill h'n+ it to the UdpMmAgent &sing the hdr_mm str&ct&re for%'t. Then, UdpMmAgent 'lloc'tes one or %ore p'ckets 8+epen+ing on the +'t' p'cket si5e; 'n+ $rites the +'t' to the %&lti%e+i' he'+er of e'ch p'cket. T 'le 3& HH 2'cket He'+er Str&ct&re, fro% udp-mm.h Isee 'tt'che+ files
// Multimedia Header Structure struct hdr_mm { int ack; // is it ack packet? int seq; // mm sequence number int nbytes; // bytes or mm pkt double time; // current time int scale; // scale !"-#$ associated %ith data rates // &acket header access unctions static int o set_; inline static int' o set!$ { return o set_; ( inline static hdr_mm) access!const &acket) p$ { return !hdr_mm)$ p-*access!o set_$; ( (;

T 'le 2# HH *l'ss, fro% udp-mm.cc


// Mulitmedia Header +lass static class MultimediaHeader+lass , public &acketHeader+lass { public, MultimediaHeader+lass!$ , &acketHeader+lass!-&acketHeader/Multimedia-. si/eo !hdr_mm$$ { bind_o set!'hdr_mm,,o set_$; ( ( class_mmhdr;

T'0le 1 '0ove sho$s the he'+er +efinition, in $hich ' str&ct&re for the he'+er, 'n+ ' he'+er cl'ss o09ect, MultimediaHeaderClass 8+erive+ fro% PacketHeaderClass;'re +efine+. >n +efining this cl'ss, the GTcl n'%e for the he'+er 8APacketHeader/MultimediaA; 'n+ the si5e of the he'+er str&ct&re +efine+ 're presente+. Do notice th't bind_offset() must 0e c'lle+ in the constr&ctor of this cl'ss.

@e 'lso '++ the follo$ing !ed 'old lines to packet.h 'n+ ns-packet.tcl 's sho$n in T'0le 3 8see 'lso Sli+es fro% se%in'r J2; to '++ o&r AMultimediaA he'+er to the he'+er st'ck. /t this point, the he'+er cre'tion is co%plete, 'n+ UdpMmAgent c'n 'ccess the ne$ he'+er &sing the hdr_mm::access() %e%0er f&nction. -Refer to the NS Manual for detailed information on header creation and access methods. 4or the rest of the 'pplic'tion 'n+ the co%plete %o+ifie+ UD2 'gent +escription, refer +irectly to the mm-app.h, mm-app.cc, udp-mm.h 'n+ udp-mm.cc files, 's yo& feel is nee+e+. T 'le 5& the p'cket he'+er 'n+ tcl co+es
1. In packet. packet.h h A. Look for: // insert ne% packet types here Static packet_t &0_102&3 4 56; // 0his M7S0 be the 8AS0 one And insert new packet types between those 2 lines: static const packet_t &0_Multimedia 4 9"; B. Look for: class p_info { In public, In static :oid init1ame!$ in the long list of name_ add: name_;&0_Multimedia< 4 -Multimedia-; 2. In ns ns-packet.tcl - Look for: oreach prot { And in the list of protocols add: Multimedia

2$ MmA## Sende!& The sen+er &ses ' ti%er for sche+&ling the ne,t tr'ns%ission of 'n 'pplic'tion +'t' p'cket. @e +efine+ the ASendTimerA cl'ss +erive+ fro% the TimerHandler cl'ss, 'n+ $rote its Aexpire()A %e%0er f&nction to c'll the send_mm_pkt() %e%0er f&nction of the MmApp o09ect. Then, $e incl&+e+ 'n inst'nce of this o09ect 's ' private member of the MmApp o09ect referre+ to 's Asnd_timer_A. T'0le D sho$s the SendTimer i%ple%ent'tion. T 'le 6& the SendTimer i%ple%ent'tion.
class Send0imer , public 0imerHandler { public, Send0imer!MmApp) t$ , 0imerHandler!$. t_!t$ {( =nline :irtual :oid e>pire!3:ent)$; protected, MmApp) t_; (; :oid Sedn0imer,,e>pire!3:ent)$ { t_-*send_mm_pkt!$; (; class MmA&& , public Application{ public, MmApp!$; ? pri:ate ? Send0imer snd_timer_; ? (; MmApp,, MmApp!$ , runnin@_!"$. snd_timer_!this$. ack_timer_!this$ { bind_b%!Arate"_B. 'rate;"<$; ? bind_b%!Arate#_B. 'rate;#<$; bind! Apktsi/e_B. 'pktsi/e_$; bind_bool! Arandom_B. 'random$; (

:oid MmApp,,send_mm_pkt!$ { hdr_mm mh_bu ; i !runnin@_$ { a@ent_-*sendms@!pktsi/e_. !char)$ 'mh_bu $; //send to 7C& // Deschedule the send_pkt time double ne>t_time_ 4 ne>t_snd_time!$; i !ne>t_time_ * "$ snd_timer_.resched!ne>t_time_$; ( (

6efore setting this ti%er, MmApp re-c'lc&l'tes the ne,t tr'ns%ission ti%e &sing the tr'ns%ission r'te 'ssoci'te+ $ith the c&rrent sc'le v'l&e 'n+ the si5e of 'pplic'tion +'t' p'cket th't is given in the inp&t si%&l'tion script 8or &sing the +ef'&lt si5e;. The MmApp sen+er &p+'tes the sc'le p'r'%eter, $hen 'n 'pplic'tion-/*! p'cket 'rrives fro% the receiver si+e. 5$ MmA## Re)ei*e!& The receiver &ses ' ti%er, n'%e+ Aack_timer_A, to sche+&le the ne,t 'pplic'tion-/*! p'cket tr'ns%ission of $hich the interv'l is e?&'l to the %e'n 7TT. @hen receiving 'n 'pplic'tion-+'t' p'cket fro% the sen+er, the receiver co&nts the n&%0er of receive+ p'ckets 'n+ 'lso co&nts the n&%0er of lost p'ckets &sing the p'cket se?&ence n&%0er. @hen the ack_timer_ e,pires, it invokes the send_ack_pkt %e%0er f&nction of MmApp, $hich '+9&sts the sc'le v'l&e looking 't the receive+ 'n+ lost p'cket 'cco&nting infor%'tion, resets the receive+ 'n+ the lost co&nters to 0, 'n+ sen+s 'n /*! p'cket $ith the '+9&ste+ sc'le v'l&e. ote th't the receiver doesn't have an connection establishment or closing methods. Therefore, st'rting fro% the first p'cket 'rriv'l, the receiver perio+ic'lly sen+s /*! p'ckets 'n+ never stops 8this is ' K?&ick 'n+ +irty sol&tionL;. 6$ Ud#MmAgen"& The UdpMmAgent is %o+ifie+ fro% the UdpAgent to h've the follo$ing '++ition'l fe't&res# 81; $riting to the sen+ing +'t' p'cket HH he'+er the infor%'tion receive+ fro% ' MmApp 8or re'+ing infor%'tion fro% the receive+ +'t' p'cket HH he'+er 'n+ h'n+ing it to the MmApp;, 82; seg%ent'tion 'n+ re'sse%0ly 8the UdpAgent only i%ple%ents seg%ent'tion;, 'n+ 83; setting the priority 0it to 1B 8%', priority; for the MmApp p'ckets. 7$ Modi,0 8 gen"$-8& To %'ke the ne$ 'pplic'tion 'n+ 'gent r&nning $ith yo&r S +istri0&tion, yo& sho&l+ '++ t$o %etho+s to Agent cl'ss 's #u'li). >n the command %e%0er f&nction of the MmApp cl'ss, there is +efine+ 'n attach-agent GTcl co%%'n+. @hen this co%%'n+ is receive+ fro% GTcl, the MmApp tries to 'tt'ch itself to the &n+erlying 'gent. 6efore the 'tt'ch%ent, it invokes the supportMM() %e%0er f&nction of the &n+erlying 'gent to check if the &n+erlying 'gent s&pport for %&lti%e+i' tr'ns%ission 8i.e. c'n it c'rry +'t' fro% 'pplic'tion to 'pplic'tion;, 'n+ invokes enableMM() if it +oes. )ven tho&gh these t$o %e%0er f&nctions 're +efine+ in the UdpMmAgnet cl'ss, it is not +efine+ in its 0'se 'ncestor Agent cl'ss, 'n+ the t$o %e%0er f&nctions of the gener'l Agent cl'ss 're c'lle+. Therefore, $hen trying to co%pile the co+e, it $ill give 'n error %ess'ge. >nserting the t$o %etho+s 's p&0lic %e%0er f&nctions of the /genA cl'ss 8in agent.h 's follo$s $ill solve this pro0le%. T'0le B./++ing t$o %e%0er f&nctions to A/gentA cl'ss.
class A@ent , public +onnector { public, A@ent!int pkt0ype$; ?.. :irtual int supportMM!$ {return " ;( ;( :irtual :oid enableMM!$ {( :irtual :oid sendms@!int nbytes. const char ) la@s 4 "$; (

9$ Modi,0 app.h & -o& 'lso nee+ to '++ 'n '++ition'l %e%0er f&nction Arec:_ms@!int nbytes. const char )ms@$A to the Application cl'ss 's sho$n in T'0le (. This %e%0er f&nction, $hich $'s incl&+e+ in the /pplic'tion cl'ss in the ol+ versions of S 8ns-2.10D' for s&re;, is re%ove+ fro% the cl'ss in the l'test versions 8ns-2.10M' for s&re;. G&r %&lti%e+i' 'pplic'tion $'s initi'lly $ritten for the ns-2.1.0D', 'n+ therefore re?&ires the Application,,rec:_ms@!$ Application,,rec:_ms@!$ %e%0er f&nction for versions 'fter ns-2.10M' T'0le (. /++ing ' %e%0er f&nction to A/pplic'tionA cl'ss.
class Application , public &rocess { public, Application!$; :irtual :oid send !int nbytes$; :irtual :oid rec: !int nbytes$; :irtual :oid rec:_ms@!int rec:_ms@!int nbytes. const char )ms@ 4 "${( :irtual :oid resume!$; ? (

:$ Se" de, ul" * lues ,o! ne/ # ! me"e!s in "-e ns ns-de ault.tcl & /fter i%ple%enting 'll the p'rts of the 'pplic'tion 'n+ 'gent, the l'st thing to +o is to set +ef'&lt v'l&es for the ne$ly intro+&ce+ config&r'0le p'r'%eters in the ns-de ault.tcl file. T'0le N sho$s 'n e,'%ple of setting the +ef'&lt v'l&es for config&r'0le p'r'%eters intro+&ce+ 0y MmApp. T'0le N. Settings Def'&lt p'r'%eter v'l&es.
? Application/MmApp Application/MmApp Application/MmApp Application/MmApp Application/MmApp set set set set set rate"_ rateF_ rate6_ rateE_ rate#_ ".Emb ".5mb ".Gmb F.6mb F.Hmb

Application/MmApp set pktsi/e_ F""" Application/MmApp set random_ alse

B$ 1o/nlo d nd ;om#ile
Here is ' checklist th't sho&l+ 0e +one 0efore reco%piling yo&r S. 0$ Do$nlo'+ mm mmmmudpudp-app.h, mm -app.cc, udp -mm.h 'n+ udp -mm.cc to yo&r ns +irectory. 3$ H'ke s&re yo& registere+ the ne$ 'pplic'tion he'+er 0y %o+ifying packet.h 'n+ ns nspacket.tcl 's sho$n in " 'le 5. 2$ /++ the supportMM() 'n+ enableMM() %etho+s to the Agent cl'ss in a@ent.h 's sho$n in " 'le 7$ 5$ /++ the recv_msg() %etho+ to the Application cl'ss in app.h 's sho$n in " 'le 9 6$ Set +ef'&lt v'l&es for the ne$ly intro+&ce+ config&r'0le p'r'%eters in ns-de ault.tcl 's +escri0e+ in " 'le :. 6e SU7) to co%plete this l'st step. Gther$ise, 'll five-sc'le r'tes 're initi'li5e+ to 5ero &nless specifie+ in the inp&t si%&l'tion script 8i.e., the test si%&l'tion script given 0elo$ $ill no" tr'ns%it 'ny fr'%es;. /fter yo&Ove +one 'll things in the checklist, %o+ify yo&r Make ile 's nee+e+ 8see lect&re J2; 'n+ reco%pile yo&r S. 6e SU7) to r&n Amake cleanA 'n+ Amake dependA 0efore yo& re-co%pile yo&r %o+ifie+ S, other$ise the ne$ 'pplic'tion %'y not tr'ns%it 'ny p'ckets. ;$ Tes" Simul "ion < !e#o!"ing 4ig&re 1 0elo$ sho$s ' si%&l'tion topology 'n+ scen'rio th't is &se+ to test AH%/ppA, $hile in t'0le M the test si%&l'tion script is incl&+e+. Do$nlo'+ this script fro% the 'ssign%ent $e0 p'ge of the co&rse 'n+ test yo&r ne$ly '++e+ co%ponents. 2erfor% 'ny '++ition'l ch'nges yo& see fit to incl&+e in yo&r report, i%ple%enting the re?&ire+ '$k co+es.

Poo+ L&ckQ L'0 /ssign%ents *ont'ct# 1ing He, S2M202


tnk"G6I@mail.com

T 'le =& the test script


set ns [new Simulator] #Define different colors for data flows $ns color 1 Red $ns color 2 Blue #Open the nam trace file set nf [open out.nam w] set tf [open out.tr w] $ns namtrace-all $nf $ns trace-all $tf #Define a 'finish' procedure proc finish {} { global ns nf tf $ns flush-trace #Close the trace file close $nf close $tf #Execute nam on the trace file exec nam out.nam & exit 0 } set set set set set set $ns $ns $ns $ns $ns node_(s1) node_(s2) node_(r1) node_(r2) node_(s3) node_(s4) [$ns [$ns [$ns [$ns [$ns [$ns node] node] node] node] node] node] $node_(r1) $node_(r1) $node_(r2) $node_(r2) $node_(r2) 5Mb 5Mb 2Mb 5Mb 5Mb 3ms DropTail 3ms DropTail 10ms RED 3ms DropTail 3ms DropTail

duplex-link duplex-link duplex-link duplex-link duplex-link

$node_(s1) $node_(s2) $node_(r1) $node_(s3) $node_(s4)

#Setup RED queue parameter $ns queue-limit $node_(r1) $node_(r2) 20 Queue/RED set thresh_ 5 Queue/RED set maxthresh_ 10 Queue/RED set q_weight_ 0.002 Queue/RED set ave_ 0 $ns duplex-link-op $node_(r1) $node_(r2) queuePos 0.5 $ns $ns $ns $ns $ns duplex-link-op duplex-link-op duplex-link-op duplex-link-op duplex-link-op $node_(s1) $node_(s2) $node_(r1) $node_(s3) $node_(s4) $node_(r1) $node_(r1) $node_(r2) $node_(r2) $node_(r2) orient orient orient orient orient right-down right-up right left-down left-up

#Setup a MM UDP connection set udp_s [new Agent/UDP/UDPmm] set udp_r [new Agent/UDP/UDPmm] $ns attach-agent $node_(s1) $udp_s $ns attach-agent $node_(s3) $udp_r $ns connect $udp_s $udp_r $udp_s set packetSize_ 1000 $udp_r set packetSize_ 1000 $udp_s set fid_ 1 $udp_r set fid_ 1 #Setup a MM Application set mmapp_s [new Application/MmApp] set mmapp_r [new Application/MmApp] $mmapp_s attach-agent $udp_s $mmapp_r attach-agent $udp_r $mmapp_s set pktsize_ 1000 $mmapp_s set random_ false #Setup a TCP connection set tcp [$ns create-connection TCP/Reno $node_(s2) TCPSink $node_(s4) 0] $tcp set window_ 15 $tcp set fid_ 2 #Setup a FTP Application set ftp [$tcp attach-source FTP] #Simulation Scenario $ns at 0.0 "$ftp start" $ns at 1.0 "$mmapp_s start" $ns at 7.0 "finish" $ns run

You might also like