# 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. xtts v4for oracle 11g&12c(文档ID 2471245

    xtts v4for oracle 11g&12c(文档ID 2471245.1) 序号 主机 操作项目 操作内容 备注: 阶段一:初始阶段 1.1 源端 环境验证 migrate_check ...

  2. 《大数据日知录》读书笔记-ch3大数据常用的算法与数据结构

    布隆过滤器(bloom filter,BF): 二进制向量数据结构,时空效率很好,尤其是空间效率极高.作用:检测某个元素在某个巨量集合中存在. 构造: 查询: 不会发生漏判(false negativ ...

  3. Rabbitmq的五种模式和案例

    消息生产者p将消息放入队列 消费者监听队列,如果队列中有消息,就消费掉,消息被拿走后,自动从队列删除 (缺点:消息可能没有被消费者正确处理,已经消失了,无法恢复) 应用场景:聊天室 1.引入依赖 &l ...

  4. JS框架设计之主流框架的引入机制DomeReady一种子模块

    DomReady其实是一种名为"DomContentLoaded"事件的名称,不过由于框架的需要,它与真正的DomContentLoaded有区别,在旧的JS书籍中m都会让我们把J ...

  5. 2019美国大学生数学建模竞赛B题(思路)

    建模比赛已经过去三天了,但留校的十多天里,自己的收获与感受依然长存于心.下面的大致流程,很多并没有细化,下面很多情况都是在假设下进行的,比如假设飞机能够来回运送药品,运货无人机就只运货,在最大视距下侦 ...

  6. D3学习笔记一

    D3学习笔记一 什么是D3? D3(全称Data Driven Documents)是一个用来做Web数据可视化的JavaScript函数库.D3也称之为D3.js. D3是2011年由Mike Bo ...

  7. 【c++】流状态的查询和控制

    源自 c++primer 4th, 248页 代码 #include <iostream> #include <limits> #include <stdexcept&g ...

  8. web_01Java ee实现登陆注册功能

    Web Web_01版本: 实现功能 用户注册 用户登录 设计内容 数据库:mysql 服务器: tomact7 配置 : xml 页面 : jsp+html/css *重点: 数据库相关: 数据库操 ...

  9. ddddddeeeessssssttttrrrrrrooooooyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

    我遥远的 POI 计划啊 https://loj.ac/problems/search?keyword=POI2011 atcoder 一套 动态 DP SAM 随便看 XSY 的题 UOJ Roun ...

  10. js 屏蔽浏览器事件汇总

    //js 屏蔽 window.document.oncontextmenu = function () { event.returnValue = false; }//屏蔽鼠标右键 window.do ...