incast.tcl
# 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的更多相关文章
- Tcl internal variables
Tcl internal variables eryar@163.com 在Tcl中内置了一些变量,并赋予了一定的功能.内置变量列表如下: 变量名称 功能描述 argc 指命令行参数的个数. argv ...
- SDC Tcl package of Timequest
Tcl comand Tcl Commands all_clocks all_inputs all_outputs all_registers create_clock create_generate ...
- Oracle数据库操作分类DDL、DML、DCL、TCL类别清单异同
DDL Data Definition Language (DDL) statements are used to define the database structure or schema. S ...
- linux tcl expect 安装(转)
linux tcl expect 安装 一.Tcl安装 1. 下载:tcl8.4.20-src.tar.gz http://www.tcl.tk/software/tcltk/downloadnow ...
- 为Tcl编写C的扩展库
Tcl是一个比较简洁的脚本语言,官方地址 http://www.tcl.tk. tcl脚本加载C实现的动态库非常方便. 1. 为Tcl编写一个用C实现的扩展函数. #include <stdio ...
- Tcl
Tcl(发音 tickle)是一种脚本语言.由John Ousterhout创建.TCL经常被用于快速原型开发 RAD.脚本编程.GUI编程和测试等方面. Expect Expect是 另外一种非常流 ...
- MySQL TCL 整理
TCL(Transaction Control Language)事务控制语言SAVEPOINT 设置保存点ROLLBACK 回滚SET TRANSACTION
- TCL:使用、添加库文件
>直接引用工具自带的库文件 通过指令: .1查看能直接调用的库文件路径 #可以查到工具默认库文件路径,一般包括回显中的路径以及回显中路径的父路径. info library #D:/Script ...
- 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} ...
随机推荐
- 转 oracle ASM中ASM_POWER_LIMIT参数
https://daizj.iteye.com/blog/1753434 ASM_POWER_LIMIT 该初始化参数用于指定ASM例程平衡磁盘所用的最大权值,其数值范围为0~11,默认值为1.该初始 ...
- 关于DES加密
数据加密算法(Data Encryption Algorithm,DEA)是一种对称加密算法,很可能是使用最广泛的密钥系统,特别是在保护金融数据的安全中,最初开发的DEA是嵌入硬件中的.通常,自动取款 ...
- WCF系列教程之初识WCF
本随笔参考自WCF编程系列(一)初识WCF,纯属读书笔记,加深记忆. 1.简介:Windows Communication Foundation(WCF)是微软为构建面向服务的应用程序所提供的统一编程 ...
- 游戏反编译工具dnSpy
dnSpy使用的工具下载地址为: https://github.com/cnxy/dnSpy/archive/v4.0.0.zip 或 dnSpy官方下载地址: https://github.com/ ...
- c#静态扩展方法,字典的克隆扩展方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- PHP读取文件的多种方法
1.传统的方法 fopen, fclose feof:file.end of file 例子: $file_handle = fopen("c:\\myfile.txt", &qu ...
- a[i]==i[a]==*(i+a)==*(a+i)
在C语言中,如果我们要访问一个数组的某个下标对应的元素,通常的写法是a[i].但从汇编的角度看,写成i[a]一点问题都没有. 下面通过代码给出证明. o foo1.c int main(int arg ...
- Eclipse更改颜色主题
通过在线安装的方式 Help -> Install New Software Work with: 输入 http://eclipse-color-theme.github.com/update ...
- C#发送GET与POST请求
////////HTTPGET HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = ...
- C#泛型List的介绍
一.List<T>描述 1).表示可通过索引访问的对象的强类型列表:提供用于对列表进行搜索.排序和操作的方法.2).是ArrayList类的泛型等效类.3).可以使用一个整数索引访问此集合 ...