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} ...
随机推荐
- module.exports,exports,export和export default,import与require区别与联系
还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...
- mysql并发更新问题
问题背景: 假设MySQL数据库有一张会员表vip_member(InnoDB表),结构如下: 当一个会员想续买会员(只能续买1个月.3个月或6个月)时,必须满足以下业务要求: •如果end_at ...
- Android ListView中EditView再次焦点获取
问题:在ListView中使用EditView,当第一次将焦点给到EditView的时候弹出小键盘.使得EditView失去焦点. 分析:因为在第一次使用EditView弹出小键盘之后,会重新的调用一 ...
- OSI与TCP/IP协议区别
1 OSI参考模型 谈到网络不能不谈OSI参考模型,虽然OSI参考模型的实际应用意义不是很大,但其的确对于理解网络协议内部的运作很有帮助,也为我们学习网络协议提供了一个很好的参考.在现实网络世界里,T ...
- WPF的布局--StackPanel
1. StackPanel是以堆叠的方式来显示控件(从左到右,或者从上到下) 默认是从上到下显示的,并且宽度为StackPanel的宽度,高度自动适应控件中内容的高度(未对控件进行设置时) 如图: 代 ...
- GridView 基本使用
项目中实例一 <asp:GridView ID="gvBatchReceive" runat="server" AutoGenerateColumns=& ...
- java 配置在.properties文件中的常量
不让用常量类,那就用.properties文件配置,放在根目录. import java.util.HashMap; import java.util.Iterator; import java.ut ...
- [转]Supporting OData Query Options in ASP.NET Web API 2
本文转自:https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/suppor ...
- [android] 练习PopupWindow实现对话框
练习使用Dialog实习对话框 package com.example.tsh; import android.app.Activity; import android.app.Dialog; imp ...
- Java API 之 Annotation功能
JDK1.5开始增加了Annotation功能,该功能可用于: 1.类: 2.构造方法: 3.成员变量: 4.方法 5.参数 等的声明: 该功能并不影响程序的运行,但是会对编译器警告等辅助工具产生影响 ...