# Basic Incast Simulation
# Check Args
if {$argc != 5} {
puts "Usage: ns incast <srv_num> <adv_win-pkt> <SRU-KB> <link_buf-pkt> <seed>"
exit 1
} #################################################################
# Argments
# ServerNum: $argv(0)
set svr_num [lindex $argv 0]
# Advertised Window size (pkt): $argv(1)
set adv_win [lindex $argv 1]
# SRU Size (Byte) ... only Payload: $argv(2)
set SRU [expr [lindex $argv 2] * 1024]
# Link Buffer (pkt): $argv(3)
set link_buf [lindex $argv 3]
# Random Seed: $argv(4)
set seed [lindex $argv 4] ################################################################
# Variables
# Create a simulator object
set ns [new Simulator] # Bandwidth (Gbps)
set bw_Gbps 1 # Link Delay (us)
set link_del_us 25
# Maximum Random Link Delay: 0--maxrand (us)
set maxrand_link_del_us 20 # SYN Interval Delay (us) for each Request
set SYN_del_us 0
## For Aggressive Optimization for Goodput (may cause incast)
# set SYN_del_us [expr int(${SRU} * 8 / (${bw_Gbps} * pow(10, 9)) * pow(10, 6))]
## For Conservative Optimization for Goodput (never cause incast)
# set SYN_del_us [expr int(${SRU} * 8 / (${bw_Gbps} * pow(10, 9)) * pow(10, 6)\
# + ${link_del_us} * 4 * (1 + \
# (log10( ${link_del_us} * 4 * pow(10, -6) * ${bw_Gbps} * pow(10, 9) \
# / (1500 * 8) ) / log10(2))))] # Maximum Random SYN Delay: 0--maxrand (us)
set maxrand_SYN_del_us 0 # Total Size of All Servers SRU with TCP/IP Header and Handshake
set Block_trans [expr ((int($SRU / 1460) + 1)* 1500 + 40) * $svr_num] # Link Error Rate (Unit:pkt) 0.001 = 0.1% (a loss in 1000 pkt)
# set err_rate 0.001
set err_rate 0 #############################################
# Random Model
set rng [new RNG]
# seed 0 equal to current OS time (UTC)
# so seed should be more than 1 for repeatability
$rng seed [expr ${seed} * ${svr_num} + 1] #################################################################
# Tracing Message
puts -nonewline "Server: $svr_num, win: ${adv_win}pkt, "
puts -nonewline "SRU: [lindex $argv 2]KB, link_buf: ${link_buf}pkt, "
puts "Seed: $seed, "
puts -nonewline "Block_trans: ${Block_trans}B, "
puts -nonewline "RTT: [expr $link_del_us * 4]us, "
puts -nonewline "RTT_rand: ${maxrand_link_del_us}us, "
puts "SYN_del: ${SYN_del_us}-[expr $SYN_del_us + $maxrand_SYN_del_us]us" Agent/TCP set trace_all_oneline_ true
Agent/TCP set packetSize_ 1460
Agent/TCP set window_ $adv_win
Agent/TCP set singledup_ 0 ; # 0: Disabled Limited Transmit
Agent/TCP set tcpTick_ 0.0000001 ; # 100ns (default 0.01: 10ms)
Agent/TCP set minrto_ 0.2 #Open the ns trace file
set nf [open out.ns w]
$ns trace-all $nf
set ef [open out.et w]
$ns eventtrace-all $ef
set tf [open out.tcp w]
# For Queue Monitoring
# set q_trans [open queue_trans.ns w] proc finish {} {
global ns nf ef tf
# For Queue Monitoring
# global q_trans
$ns flush-trace
close $nf
close $tf
close $ef
# close $q_trans
puts "Done."
exit 0
} #Create two nodes
set nx [$ns node]
set nc [$ns node]
$ns duplex-link $nx $nc ${bw_Gbps}Gb ${link_del_us}us DropTail
$ns queue-limit $nx $nc ${link_buf} # Link Error Module between Switch and Client
set loss_module [new ErrorModel]
$loss_module unit pkt
$loss_module set rate_ $err_rate
set loss_random_variable [new RandomVariable/Uniform]
$loss_random_variable use-rng ${rng}
$loss_module ranvar ${loss_random_variable}
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $nx $nc for {set i 0} {$i < $svr_num} {incr i} {
set n_($i) [$ns node]
$ns duplex-link $nx $n_($i) ${bw_Gbps}Gb ${link_del_us}us DropTail
$ns queue-limit $n_($i) $nx 1000
set tcp_($i) [new Agent/TCP/Newreno]
$tcp_($i) set fid_ $i
$tcp_($i) attach-trace $tf
$tcp_($i) trace maxseq_
$tcp_($i) trace ack_
set ftp_($i) [new Application/FTP]
$ftp_($i) attach-agent $tcp_($i)
$ftp_($i) set type_ FTP
$ns attach-agent $n_($i) $tcp_($i)
set snk_($i) [new Agent/TCPSink]
$ns attach-agent $nc $snk_($i)
$ns connect $tcp_($i) $snk_($i) # Caluclate Delay (us)
set del_us [expr $link_del_us * 2 + $SYN_del_us * $i \
+ [$rng uniform 0 ${maxrand_SYN_del_us}]] $ns at [expr 1.0 + $del_us * 0.000001] "$ftp_($i) send $SRU"
}
$ns at 0.0 "debug"
$ns at 0.99 "check_trans"
$ns at 21.0 "finish" # For Queue Monitoring
# set q_mon [$ns monitor-queue $nx $nc [open queue_mon.ns w] 0.0001]
# [$ns link $nx $nc] queue-sample-timeout proc update_link_del {} {
global ns nx n_ link_del_us maxrand_link_del_us svr_num rng
for {set i 0} {$i < $svr_num} {incr i} {
$ns delay $nx $n_($i) [expr $link_del_us \
+ [$rng uniform 0 ${maxrand_link_del_us}]]us duplex
}
} proc check_trans {} {
global ns Block_trans svr_num snk_
# 0.0001 = 100 us = 1 RTT
set time 0.0001
set now [$ns now] # check traffic to each TCP sink agent
# puts "$now: Server: 0, bytes: [$snk_(0) set bytes_]"
set total_bytes 0
for {set i 0} {$i < $svr_num} {incr i} {
set total_bytes [expr $total_bytes + [$snk_($i) set bytes_]]
} # Is any data to be transmitted?
if {$total_bytes >= $Block_trans} {
# All SRU is transmitted.
if {$total_bytes == $Block_trans} {
# Finish in just.
} else {
# Unnecessary Retransmit is exist.
}
flush stdout
$ns at [expr $now + 1] "finish"
} # For Queue Monitoring
# $q_mon instvar parrivals_ pdepartures_ bdrops_ bdepartures_ pdrops_
# puts $q_trans "$now $bdepartures_" # For update_link
update_link_del $ns at [expr $now+$time] "check_trans"
} proc debug {} {
global ns
set next_time 1.0
set now [$ns now]
puts -nonewline "$now."
flush stdout
$ns at [expr $now+$next_time] "debug"
} #Run the simulation
$ns run

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<NS2网络模拟器的原理和应用>-王辉

这本书P42的例子和P47的基本语法还是很有用的。

Agent简单地说是表示节点的协议Protocol。

incast.tcl的更多相关文章

  1. Tcl internal variables

    Tcl internal variables eryar@163.com 在Tcl中内置了一些变量,并赋予了一定的功能.内置变量列表如下: 变量名称 功能描述 argc 指命令行参数的个数. argv ...

  2. SDC Tcl package of Timequest

    Tcl comand Tcl Commands all_clocks all_inputs all_outputs all_registers create_clock create_generate ...

  3. Oracle数据库操作分类DDL、DML、DCL、TCL类别清单异同

    DDL Data Definition Language (DDL) statements are used to define the database structure or schema. S ...

  4. linux tcl expect 安装(转)

    linux tcl expect 安装 一.Tcl安装 1.  下载:tcl8.4.20-src.tar.gz http://www.tcl.tk/software/tcltk/downloadnow ...

  5. 为Tcl编写C的扩展库

    Tcl是一个比较简洁的脚本语言,官方地址 http://www.tcl.tk. tcl脚本加载C实现的动态库非常方便. 1. 为Tcl编写一个用C实现的扩展函数. #include <stdio ...

  6. Tcl

    Tcl(发音 tickle)是一种脚本语言.由John Ousterhout创建.TCL经常被用于快速原型开发 RAD.脚本编程.GUI编程和测试等方面. Expect Expect是 另外一种非常流 ...

  7. MySQL TCL 整理

    TCL(Transaction Control Language)事务控制语言SAVEPOINT 设置保存点ROLLBACK  回滚SET TRANSACTION

  8. TCL:使用、添加库文件

    >直接引用工具自带的库文件 通过指令: .1查看能直接调用的库文件路径 #可以查到工具默认库文件路径,一般包括回显中的路径以及回显中路径的父路径. info library #D:/Script ...

  9. TCL:表格(xls)中写入数据

    intToChar.tcl # input a number : 1 to 32 , you will get a char A to Z #A-Z:1-32 proc intToChar {int} ...

随机推荐

  1. mp4 格式无法使用html5的video标签播放

     只有视频编码为h264的视频才能在html5中使用video标签播放 我的解决方法为:下载魔影工厂,按照如下图所示步骤操作: width:600px;

  2. 'node' 不是内部或外部命令,也不是可运行的程序或批处理文件

    状况:安装完nodejs之后,命令行输入node -v, 提示 'node' 不是内部或外部命令,也不是可运行的程序或批处理文件原因:检查环境变量没有配置正确配置环境变量: windows系统里, 需 ...

  3. 构造函数与普通函数关于“new”操作符

    javascript中构造函数与普通函数的区别还有关于“new”操作符的一些原理   有一种创建对象的方法叫做工厂模式,例如: 1 function person(name,age){ 2 var o ...

  4. CSAPP阅读笔记-汇编语言初探(算术和逻辑操作类指令)-来自第三章3.5的笔记-P128-P135

    1.算术和逻辑操作类指令分四类:加载有效地址,一元操作,二元操作和移位,如下: 2. leaq指令,类似mov指令,它左侧的数看似是给出一个地址,在内存中从给定的地址取操作数,传给右边的目的地.但其实 ...

  5. Python基础(3) - 数据类型:3列表类型

    Python 列表是序列对象,可包含任意的Python数据信息,如字符串.数字.列表.元组等.列表的数据是可变的,我们可通过对象方法对列表中的数据进行增加.修改.删除等操作.列表用[]包括起来的. 列 ...

  6. BNU27937——Soft Kitty——————【扩展前缀和】

    Soft Kitty Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class n ...

  7. 用jQuery来绑定事件的3种方法和区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. java.lang.RuntimeException Unable to instantiate application Caused by: java

    参考:http://blog.csdn.net/xufazhong/article/details/71155528 dependencies { classpath 'com.android.too ...

  9. wcf 基本配置

    <system.serviceModel> <services> <service name="ServiceUpdater.ServiceUpdate&quo ...

  10. awk如何替换一个字符串的第n个字符?

    方法一: echo "abcdefg" | awk 'BEGIN{FS=OFS=""}$4="h"'    // ""可 ...