Tải bản đầy đủ (.doc) (11 trang)

Thuật toán tăng giảm

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (86.15 KB, 11 trang )

Phụ lục
PHẦN PHỤ LỤC
Thuật toán tăng giảm
• Tăng cộng giảm nhân AIMD
#define_param a range 0.1 to 1 default 0.1
#define_param b range 0.1 to 0.9 default 0.5
maxrate = 1.0;
if(traffic > 1){
rate = rate * b;
}
else{
rate = rate + a;
rate = min(rate, maxrate);
}
• Tăng cộng giảm cộng AIAD
#define_param a range 0.1 to 0.9 default 0.2
#define_param b range 0.1 to 0.9 default 0.3
maxrate = 1.0;
minrate = 0.0;
if(traffic > 1){
rate = rate - b;
rate = max(rate, minrate);
}
else{
rate = rate + a;
rate = min(rate, maxrate);
}
• Tăng nhân giảm cộng MIAD
#define_param a range 1 to 2 default 1.2
#define_param b range 0.1 to 0.9 default 0.5
maxrate = 1.0;


minrate = 0.0;
if(traffic > 1){
rate = rate - b;
rate = max(rate, minrate);
}
else{
rate = rate * a;
rate = min(rate, maxrate);
}
Phụ lục
• Tăng nhân giảm nhân MIMD
#define_param a range 1 to 2.0 default 1.2
#define_param b range 0.1 to 0.9 default 0.5
maxrate = 1.0;
if(traffic > 1){
rate = rate * b;
}
else{
rate = rate * a;
rate = min(rate, maxrate);
}
Kịch bản xây dựng trong ns2
#--------- So do ket noi mang ----------------------------------------------#
# n0
# \ Bottleneck Dich
# n1--R0-----------------------R1
# /
# n2
#
# Cac luong xcp va tcp dung chung router xcp

Queue/XCP set tcp_xcp_on_ 1
Agent/TCP set minrto_ 1
# Tao doi tuong mo phong
set ns [new Simulator]
$ns use-scheduler Heap
# Tao file trace
set f_all [open out.tr w]
$ns trace-all $f_all
#-----------------------------------------------------------------------------
# Dinh nghia cac ham su dung trong chuong trinh chinh
#-----------------------------------------------------------------------------
# Tao tham so cho hang RED
proc set-red-params { qsize } {
Queue/RED set thresh_ [expr 0.6 * $qsize]
Queue/RED set maxthresh_ [expr 0.8 * $qsize]
Phụ lục
Queue/RED set q_weight_ 0.001
Queue/RED set linterm_ 10
Queue/RED set bytes_ false ;
Queue/RED set queue_in_bytes_ false ;
Agent/TCP set old_ecn_ true
Queue/RED set setbit_ true
}
#----------------------------------------------------------------------------
# Tao topo mang
proc create-topology2 { BW delay qtype qsize numSideLinks deltaDelay } {
global ns

# Thiet lap kich co hang den kich co duong truyen
# Gia su rang kich co goi la 1000Bytes

if { $qsize == 0 } { set qsize [expr round([expr ($BW / 8) * 2 * $delay])] }

#Khai bao 2 nut R0 R1
set i 0
while { $i < 2 } {
global R$i
set R$i [$ns node]
incr i
}
$R0 color red
$R1 color blue
$R0 label "That co chai"
$R1 label "Dich"
# Khai bao link: nodes bw delay queue
$ns duplex-link $R0 $R1 [set BW]Mb [set delay]ms $qtype
$ns queue-limit $R0 $R1 $qsize
$ns queue-limit $R1 $R0 $qsize
# Xu li hang bi that co chai, cho phep thiet lap cac tham so RED
global Bottleneck rBottleneck
set Bottleneck [[$ns link $R0 $R1] queue]
set rBottleneck [[$ns link $R1 $R0] queue]
global l rl
set l [$ns link $R0 $R1]
set rl [$ns link $R1 $R0]
global all_links
set all_links "$l $rl "
Phụ lục
# Duong truyen nha'nh co cung bang thong nhu duong that co chai
set i 0
while { $i < $numSideLinks } {

global n$i q$i rq$i l$i rl$i
set n$i [$ns node]
$ns duplex-link [set n$i] $R0 [set BW]Mb [expr $delay + $i*
$deltaDelay]ms $qtype
$ns queue-limit [set n$i] $R0 $qsize
$ns queue-limit $R0 [set n$i] $qsize
set q$i [[$ns link [set n$i] $R0] queue]
set rq$i [[$ns link $R0 [set n$i]] queue]
set l$i [$ns link [set n$i] $R0]
set rl$i [$ns link $R0 [set n$i]]
set all_links "$all_links [set l$i] [set rl$i]"
incr i
}
}
#------------------------------------------------------------------------------------------
#------Lop GeneralSender: can thiet cho phia goi ftp------------------------------
Class GeneralSender -superclass Agent
GeneralSender instproc init { id node rcvrTCP otherparams } {
global ns
$self next
$self instvar tcp_ id_ ftp_ node_ tcp_rcvr_ tcp_type_
set id_ $id
set node_ $node
if { [llength $otherparams] > 1 } {
set TCP [lindex $otherparams 1]
} else {
set TCP "TCP/Reno"
}
set tcp_type_ $TCP
set tcp_ [new Agent/$TCP]

$tcp_ set packetSize_ 1000
$tcp_ set class_ $id
set ftp_ [new Source/FTP]
$ftp_ set agent_ $tcp_
$ns attach-agent $node $tcp_
$ns connect $tcp_ $rcvrTCP
set tcp_rcvr_ $rcvrTCP
Phụ lục
set startTime [lindex $otherparams 0]
$ns at $startTime "$ftp_ start"
puts " Khoi tao phia goi $id_ tai thoi gian t= $startTime s"
}
GeneralSender instproc trace-xcp parameters {
$self instvar tcp_ id_ tcpTrace_
global ftracetcp$id_ ns
set ftracetcp$id_ [open xcp$id_.tr w]
set tcpTrace_ [set ftracetcp$id_]
$tcp_ attach-trace [set ftracetcp$id_]
if { -1 < [lsearch $parameters cwnd] } { $tcp_ tracevar cwnd_ }
}
#-----------------------------------------------------------------------------------------
#------------------------Thuc hien chuc nang ve do thi----------------------#
# do thi bien trace xcp
proc plot-xcp { TraceName nXCPs PlotTime what } {

exec rm -f xgraph_cwnd.tcp
set f [open xgraph_cwnd.tcp w]
set a cwnd

puts $f "TitleText: $TraceName"

puts $f "Device: Postscript"
foreach i $nXCPs {
# trace TCP duoc flushed khi cac nguon ngung
exec rm -f temp.tcp
exec touch temp.tcp
global ftracetcp$i
if [info exists ftracetcp$i] { flush [set ftracetcp$i] }
set result [exec awk -v PlotTime=$PlotTime -v what=$what {
{
if (( $6 == what ) && ($1 > PlotTime)) {
print $1, $7 >> "temp.tcp";
}
}
} xcp$i.tr]
puts $f \"$what$i
exec cat temp.tcp >@ $f

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×