📄 traffic.tcl
字号:
# Traffic Agents configurationAgent set fid_ 0 ;# For IPv6 flow id fieldAgent set agent_addr_ -1 ;# Address of this agentAgent set agent_port_ -1 ;# Port of this agentAgent set dst_addr_ -1 ;# Destination address for pkt flowAgent set dst_port_ -1 ;# Destination port for pkt flowAgent set ttl_ 32 ;# Default ttl for outgoing pktsAgent/TCP set maxcwnd_ 0 ;# Max # cwnd can ever be --- 0 to ignore (default)Agent/TCP set numdupacks_ 3 ;# Dup ACKs before fast retransmitAgent/TCP set window_ 100 ;# The upper bound on the advertised window (default 20)Agent/TCP set windowInit_ 1 ;# The initial size of the congestion window on slow-start (default 2)Agent/TCP set windowInitOption_ 1 ;# Congestion avoidance algorithm --- 1 for using wnd_init_ --- 2 for ;# using large initial windowsAgent/TCP set syn_ 0 ;# 1 for modeling SYN/ACK exchange (default 1)Agent/TCP set windowOption_ 1 ;# The algorithm to use for managing the congestion windowAgent/TCP set ecn_ 0 ;# Explicit Congestion Notification. This allows a Fast Retransmit after a ;# quench() due to an ECN bitAgent/TCP set packetSize_ $opt(tcp_size) ;# Fixed packet size (bytes)Agent/TCP set tcpip_base_hdr_size_ 40 ;# Size of base TCP/IP headerAgent/TCP set slow_start_restart_ true ;# Boolean: re-init cwnd after connection goes idle. On by defaultAgent/TCP set tcpTick_ 0.01 ;# Clock granularity for measuring roundtrip timesAgent/TCP set maxrto_ 100000 ;# Max value of an RTO (sec.)Agent/TCP set minrto_ 1 ;# Min value of an RTOAgent/TCP set srtt_init_ 0 ;# Initial value for computing t_srtt_Agent/TCP set rttvar_init_ 12 ;# Initial value for computing t_rttvar_Agent/TCP set rtxcur_init_ 3.0 ;# Initial value for t_rtxcur_Agent/TCP set T_SRTT_BITS 3 ;# Exponent of weight for updating t_srtt_Agent/TCP set T_RTTVAR_BITS 2 ;# Exponent of weight for updating t_rttvar_Agent/TCP set rttvar_exp_ 2 ;# Exponent of multiple for t_rtxcur_Agent/TCP set useHeaders_ true ;# Boolean: Add TCP/IP header sizesAgent/TCPSink set sport_ 0 ;# Source portAgent/TCPSink set dport_ 0 ;# Destination portAgent/TCPSink set packetSize_ 40 ;# Fixed packet size (bytes)Agent/TCPSink set RFC2581_immediate_ack_ true ;# Used to generate ACKs immediately for RFC2581-compliant gap-fillingAgent/TCP/Newreno set newreno_changes_ 0 ;# 0 for fixing unnecessary fast retransmits; 1 for additional code from Allman, ;# to implement other algorithms from Hoe's paper, including sending a new packet ;# for every two duplicate ACKs. The default is set to 0.Agent/TCP/Newreno set newreno_changes1_ 0 ;# Newreno_changes1_ set to 0 gives the Slow-but-Steady variant of NewReno ;# from RFC 2582, with the retransmit timer reset after each partial new ack. ;# Newreno_changes1_ set to 1 gives the Impatient variant of NewReno from RFC 2582, ;# with the retransmit timer reset only for the first partial new ack. ;# The default is set to 0Agent/TCP/Newreno set partial_window_deflation_ 0 ;# 0 if set cwnd to ssthresh upon partial new ack (default). 1 if deflate ;# (cwnd + dupwnd) by amount of data acked "Partial window deflation" is discussed ;# in RFC 2582.Agent/TCP/Newreno set exit_recovery_fix_ 0 ;# 0 for setting cwnd to ssthresh upon leaving fast recovery (default). 1 for ;# setting cwnd to min(ssthresh, amnt. of data in network) when leavingAgent/UDP set packetSize_ $opt(udp_size) ;# Max. UDP packet size (bytes)Application/Traffic/CBR set packetSize_ $opt(udp_size) ;# Fixed packet size (bytes)Application/Traffic/CBR set random_ 1 ;# Introduces random noise in the scheduled departure times####################################################################### ## HTTP_model_init: when the TCP on/off model is used, this function ## is responsable of the model initialization ## #######################################################################proc HTTP_model_init {} { global web avg opt ;#(bytes) set avg(flow_length,0) 119 ;# This flow length distribution is the result set avg(flow_length,1) 179 ;# of a real traffic measurement executed on the backbone set avg(flow_length,2) 251 ;# network of the Politecnico of Torino set avg(flow_length,3) 334 set avg(flow_length,4) 428 set avg(flow_length,5) 529 set avg(flow_length,6) 658 set avg(flow_length,7) 948 set avg(flow_length,8) 1650 set avg(flow_length,9) 2861 set avg(flow_length,10) 4706 set avg(flow_length,11) 8015 set avg(flow_length,12) 13681 set avg(flow_length,13) 26641 set avg(flow_length,14) 284454 set total 0 set web(npkt) 0 foreach k [array names avg "flow_length,*"] { incr total [expr 1 + int($avg($k)/$opt(tcp_size))] incr web(npkt) } set web(avg_ptos) [expr $total.0 / $web(npkt).0] ;# computes the average flow length of the model}if {$opt(tcp) == 1 && $opt(onoff) != 2} { puts $file(finish) "#\n#\tTCP Flows :\n#" if {$opt(onoff) > 0} { HTTP_model_init } set num_tcp 0 foreach j [range 1 $opt(nn)] { set tcp($j) [new Agent/TCP/Newreno] ;# Creates a new TCP NewReno agent set obj(tcp,$j) $tcp($j) $tcp($j) set fid_ $j ;# Sets the TCP flow identifier set sink($j) [new Agent/TCPSink] ;# Creates a new TCP Sink agent set obj(tcp_sink,$j) $sink($j) $sink($j) set fid_ $j ;# Sets the TCP flow identifier if {[expr $j % 4] == 3 || [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_tcp]] $ns_ attach-agent $W(0) $tcp($j) $ns_ attach-agent $node_($num_tcp) $sink($j) ;# Down-Link flows: the source TCP agent is attached to the wired node set 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_tcp]] $ns_ attach-agent $node_($num_tcp) $tcp($j) $ns_ attach-agent $W(0) $sink($j) ;# Up-Link flows: the source TCP agent is attached to the wireless station set fl($j) "WN[expr $j - 1]-->0" } $ns_ connect $tcp($j) $sink($j) ;# Creates the transport level connection between the source and the destination 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 if {$opt(onoff) == 0} { $ns_ at [expr $opt(start) + [expr 0.000050 * $num_tcp]] "$ftp($j) start" $ns_ at $opt(stop) "$ftp($j) stop" ;# TCP greedy: departure times of TCP sources are diversified among ;# stations to avoid a common collision at the beginning } else { $ns_ at [expr $opt(start) + [expr 0.000050 * $num_tcp]] "start_HTTP_flows $j" } ;# TCP on/off: here we schedule the departure of the first flow ;# for each connection incr num_tcp }}if {$opt(tcp) == 1 && $opt(onoff) == 2} { puts $file(finish) "#\n#\tTCP Flows :\n#" HTTP_model_init set num_tcp 0 foreach j [range 1 $opt(nn)] { set tcp($j) [new Agent/TCP/Newreno] ;# Creates a new TCP NewReno agent CLIENT set obj(tcp,$j) $tcp($j) $tcp($j) set fid_ $j ;# Sets the TCP flow identifier set sink($j) [new Agent/TCPSink] ;# Creates a new TCP Sink agent set obj(tcp_sink,$j) $sink($j) $sink($j) set fid_ $j ;# Sets the TCP flow identifier set tcp([expr -$j]) [new Agent/TCP/Newreno] ;# Creates a new TCP NewReno agent SERVER set obj(tcp,[expr -$j]) $tcp([expr -$j]) $tcp([expr -$j]) set fid_ [expr -$j] ;# Sets the TCP flow identifier set sink([expr -$j]) [new Agent/TCPSink] ;# Creates a new TCP Sink agent set obj(tcp_sink,[expr -$j]) $sink([expr -$j]) $sink($j) set fid_ [expr -$j] ;# Sets the TCP flow identifier puts $file(finish) [format "#\t\t%2d) WN[expr $j - 1]-->0 : client starting at %f" $j [expr 0.000050 * $num_tcp]] $ns_ attach-agent $node_($num_tcp) $tcp($j) $ns_ attach-agent $W(0) $sink($j) set fl($j) "WN[expr $j - 1]-->0" puts $file(finish) [format "#\t\t%2d) 0-->WN[expr $j - 1] : server waiting" $j] $ns_ attach-agent $W(0) $tcp([expr -$j]) $ns_ attach-agent $node_($num_tcp) $sink([expr -$j]) set fl([expr -$j]) "0-->WN[expr $j - 1]" $ns_ connect $tcp($j) $sink($j) ;# Creates the transport level connection between the source and the destination $ns_ connect $tcp([expr -$j]) $sink([expr -$j])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -