NS2仿真实例汇总

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

NS-2仿真模拟实例汇总(以方路平的书为主)1.例4.5a:DropTail队列管理的NS_2模拟实例(P161)setns[newSimulator]setnf[openout.namw]$nsnamtrace-all$nfsettf[openout.trw]setwindowVsTime[openwinw]setparam[openparametersw]$nstrace-all$tfprocfinish{}{globalnsnftf$nsflush-traceclose$nfclose$tfexecnamout.nam&exit0}setn2[$nsnode]setn3[$nsnode]$nsduplex-link$n2$n30.7Mb20msDropTailsetNumbSrc3setDuration50for{setj1}{$j=$NumbSrc}{incrj}{setS($j)[$nsnode]}setrng[newRNG]$rngseed2setRVstart[newRandomVariable/Uniform]$RVstartsetmin_0$RVstartsetmax_7$RVstartuse-rng$rngfor{seti1}{$i=$NumbSrc}{incri}{setstartT($i)[expr[$RVstartvalue]]setdly($i)1puts$paramstartT($i)$startT($i)sec}for{setj1}{$j=$NumbSrc}{incrj}{$nsduplex-link$S($j)$n210Mb$dly($j)msDropTail$nsqueue-limit$S($j)$n220}$nsqueue-limit$n2$n3100for{setj1}{$j=$NumbSrc}{incrj}{settcp_src($j)[newAgent/TCP/Reno]$tcp_src($j)setwindow_8000}for{setj1}{$j=$NumbSrc}{incrj}{settcp_snk($j)[newAgent/TCPSink]}for{setj1}{$j=$NumbSrc}{incrj}{$nsattach-agent$S($j)$tcp_src($j)$nsattach-agent$n3$tcp_snk($j)$nsconnect$tcp_src($j)$tcp_snk($j)}for{setj1}{$j=$NumbSrc}{incrj}{setftp($j)[$tcp_src($j)attach-sourceFTP]}for{setj1}{$j=$NumbSrc}{incrj}{$tcp_src($j)setpacketSize_552}for{seti1}{$i=$NumbSrc}{incri}{$nsat$startT($i)$ftp($i)start$nsat$Duration$ftp($i)stop}procplotWindow{tcpSourcefilek}{globalnsNumbSrcsettime0.03setnow[$nsnow]setcwnd[$tcpSourcesetcwnd_]if{$k==1}{puts-nonewline$file$now\t$cwnd\t}else{if{$k$NumbSrc}{puts-nonewline$file$cwnd\t}}if{$k==$NumbSrc}{puts-nonewline$file$cwnd\n}$nsat[expr$now+$time]plotWindow$tcpSource$file$k}for{setj1}{$j=$NumbSrc}{incrj}{$nsat0.1plotWindow$tcp_src($j)$windowVsTime$j}$nsmonitor-queue$n2$n3[openqueue.trw]0.05[$nslink$n2$n3]queue-sample-timeout$nsat[expr$Duration]finish$nsrun2.例4.5b:RED队列管理的NS-2模拟实例(P164)setns[newSimulator]setnf[openout.namw]$nsnamtrace-all$nfsettf[openout.trw]setwindowVsTime[openwinw]setparam[openparametersw]$nstrace-all$tfprocfinish{}{globalnsnftf$nsflush-traceclose$nfclose$tfexecnamout.nam&exit0}setn2[$nsnode]setn3[$nsnode]$nsduplex-link$n2$n30.7Mb20msREDsetNumbSrc3setDuration50for{setj1}{$j=$NumbSrc}{incrj}{setS($j)[$nsnode]}setrng[newRNG]$rngseed2setRVstart[newRandomVariable/Uniform]$RVstartsetmin_0$RVstartsetmax_7$RVstartuse-rng$rngfor{seti1}{$i=$NumbSrc}{incri}{setstartT($i)[expr[$RVstartvalue]]setdly($i)1puts$paramstartT($i)$startT($i)sec}for{setj1}{$j=$NumbSrc}{incrj}{$nsduplex-link$S($j)$n210Mb$dly($j)msDropTail$nsqueue-limit$S($j)$n220}$nsqueue-limit$n2$n3100for{setj1}{$j=$NumbSrc}{incrj}{settcp_src($j)[newAgent/TCP/Reno]$tcp_src($j)setwindow_8000}for{setj1}{$j=$NumbSrc}{incrj}{settcp_snk($j)[newAgent/TCPSink]}for{setj1}{$j=$NumbSrc}{incrj}{$nsattach-agent$S($j)$tcp_src($j)$nsattach-agent$n3$tcp_snk($j)$nsconnect$tcp_src($j)$tcp_snk($j)}for{setj1}{$j=$NumbSrc}{incrj}{setftp($j)[$tcp_src($j)attach-sourceFTP]}for{setj1}{$j=$NumbSrc}{incrj}{$tcp_src($j)setpacketSize_552}for{seti1}{$i=$NumbSrc}{incri}{$nsat$startT($i)$ftp($i)start$nsat$Duration$ftp($i)stop}procplotWindow{tcpSourcefilek}{globalnsNumbSrcsettime0.03setnow[$nsnow]setcwnd[$tcpSourcesetcwnd_]if{$k==1}{puts-nonewline$file$now\t$cwnd\t}else{if{$k$NumbSrc}{puts-nonewline$file$cwnd\t}}if{$k==$NumbSrc}{puts-nonewline$file$cwnd\n}$nsat[expr$now+$time]plotWindow$tcpSource$file$k}for{setj1}{$j=$NumbSrc}{incrj}{$nsat0.1plotWindow$tcp_src($j)$windowVsTime$j}setredq[[$nslink$n2$n3]queue]settraceq[openred-queue.trw]$redqtracecurq_$redqtraceave_$redqattach$traceq$nsat[expr$Duration]finish$nsrun$grepared-queue.trave.tr$grepQred-queue.trcur.trgnplotsettitlecurrentandaveragequeuesizegnplotsetxlabeltimegnplotsetylabelqueuesizegnplotplot

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功