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} ...
随机推荐
- PZ73H-PZ73X刀闸阀厂家,PZ73H-PZ73X刀闸阀价格 - 专题栏目 - 无极资讯网
无极资讯网 首页 最新资讯 最新图集 最新标签 搜索 PZ73H-PZ73X刀闸阀 无极资讯网精心为您挑选了(PZ73H-PZ73X刀闸阀)信息,其中包含了(PZ73H-PZ73X刀闸阀)厂家,( ...
- Ubuntu中screen命令的使用
参考GNU's Screen 官网:GNU's Scree screen的安装 sudo apt install screen 新建窗口1)可直接通过命令screen新建一个窗口,并进入窗口.但通过这 ...
- hive DML
1.load files into tables 把文件中的数据加载到表中(表必须先建好) 语法是: load data [local] inpath 'filepath' [overwrite] i ...
- flow类型检查
https://blog.csdn.net/tangxiujiang/article/details/80778627 Flow的简单介绍 2018年06月22日 21:54:25 tangxiuji ...
- Ajax(Asychronous JavaScript and XML)笔记
1 Ajax简介 1 ajax概念 2 什么是同步?什么是异步? 3 ajax原理 2 JavaScript原生的ajax 1 ajax.html代码 <!DOCTYPE html> &l ...
- 在VIM中添加行号的方法
VIM编辑器是可以显示行号的.但是,有时候我们需要在整个代码的行首添加行号.怎么实现呢?实现的方法有很多,这里就介绍我知道的一种吧. 在每行行首添加某个字符串 :%s/^/your_string/ 在 ...
- Java入门系列-14-深入类和对象
这篇文章用大量的代码帮你搞懂:值传递和引用传递.构造方法.方法重载.static关键字的使用 方法参数传递-值传递和引用传递 1.值传递 敲一敲: /** * 使用方法交换两个变量的值 * @auth ...
- java中的interrupt(),InterruptException和wait(),sleep()
标题中的几个概念大概设计到线程同步以及线程阻塞这两个概念.线程同步,就是同一时刻,只有一个线程能执行指定的代码:另外一个线程阻塞就是当前线程暂时停在某个位置,等待某个条件成立之后再继续往下面执行. ...
- js返回树形结构数据
/** * 树形结构转换 * @param a * @param idStr * @param pidStr * @param chindrenStr * @returns {Array} */ fu ...
- Newtonsoft.Json 全部配置
需要在序列化时候,忽略掉某些字段,对Newtonsoft.Json进行全局配置,如下: 1. 自定 ContractResolver public class MyContractResolver : ...