⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traffic.tcl

📁 R. Lo Cigno, P. Larcheri 802.11e closed-loop scheduling Description: ns-2 package for 802.11e clo
💻 TCL
📖 第 1 页 / 共 2 页
字号:
                set ftp($j) [new Application/FTP]       ;# Creates a new FTP agent                $ftp($j) attach-agent $tcp($j)          ;# Connects the FTP agent over the corresponding TCP one                set ftp([expr -$j]) [new Application/FTP]                $ftp([expr -$j]) attach-agent $tcp([expr -$j])                set web($j,start) $opt(start)                set web([expr -$j],start) $opt(start)                $ns_ at [expr $opt(start) + [expr 0.000050 * $num_tcp]] "start_CS_flows [expr -$j]"                incr num_tcp        }}if {$opt(udp) == 1} {        puts $file(finish) "#\n#\tCBR Flows :\n#"        set num_udp 0        foreach j [range 1 $opt(nn)] {                set udp($j) [new Agent/UDP]     ;# Creates a new UDP agent                set obj(udp,$j) $udp($j)                $udp($j) set fid_ $j            ;# Sets the UDP flow identifier                set null($j) [new Agent/Null]   ;# Creates a new UDP Sink agent (Null Agent)                set obj(null,$j) $null($j)                $null($j) set fid_ $j           ;# Sets the UDP flow identifier                if {[expr $j % 4] == 2 || [expr $j % 4] == 0} {                        puts $file(finish) [format "#\t\t%2d)  0-->WN[expr $j - 1]  :  down-link starting at %f" \                                                        $j [expr 0.000050 * $num_udp]]                        $ns_ attach-agent $W(0) $udp($j)                        $ns_ attach-agent $node_($num_udp) $null($j)    ;#                        set udp_fl($j) "0-->WN[expr $j - 1]"                        set cbr($j) [new Application/Traffic/CBR]       ;# Creates a new CBR agent                        $cbr($j) set rate_ 300000                       ;# Transmission rate (bit/sec)                } else {                        puts $file(finish) [format "#\t\t%2d)  WN[expr $j - 1]-->0  :  down-link starting at %f" \                                                        $j [expr 0.000050 * $num_udp]]                        $ns_ attach-agent $W(0) $udp($j)                        $ns_ attach-agent $node_($num_udp) $null($j)               ;#                        set udp_fl($j) "0-->WN[expr $j - 1]"                        set cbr($j) [new Application/Traffic/CBR]       ;# Creates a new CBR agent                        $cbr($j) set rate_ 64000                        ;# Transmission rate (bit/sec)                }                $ns_ connect $udp($j) $null($j)     ;# Creates the transport level connection between the source and the destination                $cbr($j) attach-agent $udp($j)                  ;# Connects the CBR agent over the corresponding UDP one                $ns_ at [expr $opt(start) + [expr 0.000050 * $num_udp]] "$cbr($j) start"                $ns_ at $opt(stop) "$cbr($j) stop"                                                        ;# Departure times of CBR sources are diversified among                                                        ;#   stations to avoid a common collision at the beginning                incr num_udp        }}if {$opt(voip) == 1} {        VoiceTracefile set debug_ 0        VoiceTracefile set paretomean_ 4        VoiceTracefile set paretoshape_ 2.5        Application/Traffic/Trace/Voice set debug_ 0        puts $file(finish) "#\n#\tVOIP Flows :\n#"        set num_voip 0        foreach j [range 1 $opt(nn)] {                set voipc($j) [new Agent/UDP]     ;# Creates a new UDP agent                set obj(voipc,$j) $voipc($j)                $voipc($j) set fid_ $j            ;# Sets the UDP flow identifier                set voips($j) [new Agent/UDP]                set obj(voips,$j) $voips($j)                $voips($j) set fid_ $j           ;# Sets the UDP flow identifier                if {[expr $j % 4] == 2 || [expr $j % 4] == 0} {                        puts $file(finish) [format "#\t\t%2d)  0-->WN[expr $j - 1]  :  down-link starting at %f" \                                                        $j [expr 0.000050 * $num_voip]]                        $ns_ attach-agent $W(0) $voipc($j)                        $ns_ attach-agent $node_($num_voip) $voips($j)    ;#                        set voip_fl($j) "0-->WN[expr $j - 1]"                } else {                        puts $file(finish) [format "#\t\t%2d)  WN[expr $j - 1]-->0  :  up-link starting at %f" \                                                        $j [expr 0.000050 * $num_voip]]                        $ns_ attach-agent $node_($num_voip) $voipc($j)                        $ns_ attach-agent $W(0) $voips($j)               ;#                        set voip_fl($j) "WN[expr $j - 1]-->0"                }                $ns_ connect $voipc($j) $voips($j)     ;# Creates the transport level connection between the source and the destination                set tfile($j) [new VoiceTracefile]		if {$opt(vocoder) == "g729"} {                	$tfile($j) filename "g.729-vad.log"		}		if {$opt(vocoder) == "g711"} {			$tfile($j) filename "g.711alaw-vad.log"		}                set t1($j) [new Application/Traffic/Trace/Voice]                $t1($j) id 1                $t1($j) attach-tracefile $tfile($j)                $t1($j) attach-agent $voipc($j)                set t2($j) [new Application/Traffic/Trace/Voice]                $t2($j) id 2                $t2($j) attach-tracefile $tfile($j)                $t2($j) attach-agent $voips($j)                $ns_ at [expr $opt(start) + [expr 0.000050 * $num_voip]] "$t1($j) start"                $ns_ at [expr $opt(start) + [expr 0.000050 * $num_voip]] "$t2($j) start"                $ns_ at $opt(stop) "$t1($j) stop"                $ns_ at $opt(stop) "$t2($j) stop"                incr num_voip        }}set rng [new RNG]       ;# Creates a new random number generator$rng seed $opt(seed)    ;# Sets the seed of the random number generator#######################################################################                                                                    ## start_HTTP_flows: when the TCP on/off model is used, this          ##                   function starts a new flow over the connection   ##                                                                    ##          fid: the flow identifier of this TCP connection           ##                                                                    #######################################################################proc start_HTTP_flows {fid} {	global rng web ns_ avg opt ftp tcp obj stat	set DELAY($fid) [expr $opt(avg_wait) * [$rng exponential]]        ;# The silence period between two consecutive flows is	set next [expr [$ns_ now] + $DELAY($fid)]                         ;# chosen according to an exponential distribution with        set B2S $avg(flow_length,[$rng integer $web(npkt)])               ;# average value equal to 'opt(avg_wait)'        set P2S [expr 1 + int($B2S/$opt(tcp_size))]        set web($fid,start) $next                                         ;# The number of packet to send is uniformly extracted        set web($fid,p2s) $P2S                                            ;# among the ones defined in HTTP_model_init	if {$next <= $opt(stop)} {                set stat(tcp,idle_time,$fid) [expr $stat(tcp,idle_time,$fid) + $DELAY($fid)]                incr stat(tcp,n_flow,$fid)                $ns_ at $next "$obj(tcp,$fid) reset"              ;# Before transmit again, we reset the TCP variables                $ns_ at $next "$obj(tcp_sink,$fid) reset"		$ns_ at $next "$ftp($fid) producemore $P2S"       ;# Gives to FTP the command to produce new packets	} elseif {[$ns_ now] < $opt(stop)} {                set stat(tcp,idle_time,$fid) [expr $stat(tcp,idle_time,$fid) + $opt(stop) - [$ns_ now]]        }}proc start_CS_flows {fid} {	global rng web ns_ avg opt ftp tcp obj stat        if {$fid < 0} {	        set B2S $avg(flow_length,[$rng integer 10])        } else {	        set B2S $avg(flow_length,[$rng integer 15])        }        set P2S [expr 1 + int($B2S/$opt(tcp_size))]        set web([expr -$fid],start) [$ns_ now]        set web([expr -$fid],p2s) $P2S	if {[$ns_ now] <= $opt(stop)} {                set stat(tcp,idle_time,[expr -$fid]) [expr $stat(tcp,idle_time,[expr -$fid]) + [$ns_ now] - $web($fid,start)]                incr stat(tcp,n_flow,[expr -$fid])                $ns_ at [$ns_ now] "$obj(tcp,[expr -$fid]) reset"                $ns_ at [$ns_ now] "$obj(tcp_sink,[expr -$fid]) reset"		$ns_ at [$ns_ now] "$ftp([expr -$fid]) producemore $P2S"	} else {                set stat(tcp,idle_time,[expr -$fid]) [expr $stat(tcp,idle_time,[expr -$fid]) + $opt(stop) - $web($fid,start)]        }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -