📄 diffnet.tcl
字号:
set ns [new Simulator]
################# parameter settings######################
# Simulated seconds and random seed to be used (0 := random seed for every run)
set testTime 1200.0
$defaultRNG seed 0
set av_BW 5000000; # GGSN-SGSN bottle-neck BW is 5Mbpsset Block_sess 0; # total blocked session numberset Arv_sess 0; # total arrived session numberset Active_sess 0; # current active session number# Committed transfer rates for applications (per connection pair)
set cir_VoIP 30000set cir_video 128000
set cir_http 100000
set cir_ftp 200000set EB_VoIP [expr $cir_VoIP / 2.0]set EB_video [expr $cir_video / 2.0]
set EB_http 12000
set EB_ftp 12000 # create empty session listarray set VoipSess {}array set VideoSess {}array set FTPSess {}array set HttpSess {}# create q handles array for all diffserv q minitoringarray set q {}########### load procedures #############################################
# Get procedures for creating HTTP, FTP and VoIP traffic
source peer_setup.tcl
# Load DiffServ-specific procedures
#source 4q2p.tcl source 4q2pA.tcl
# Create topology
source topology.tcl
# Load monitor-functions for queue- and flowmonitors
source monitoring.tcl # Load Call admission control functionsource cac.tcl
#############creat event list, src, dst##################CreatRTSessList VoipSess $voipS 5.5 120 CreatRTSessList VideoSess $videoS 22 300 CreatNRTSessList HttpSess $httpS HTTP 32 300 2.5CreatNRTSessList FTPSess $ftpS FTP 25 5 1.1 # Creat all application sessions in the session listfor {set j 1} {$j<=[array size VoipSess]} {incr j} { set dst [$VoipSess($j) set Dst] launchVoip $VoipSess($j) $voipS $dst $j}for {set j 1} {$j<=[array size VideoSess]} {incr j} { set dst [$VideoSess($j) set Dst] launchVideo $VideoSess($j) $videoS $dst $j }for {set j 1} {$j<=[array size HttpSess]} {incr j} { set dst [$HttpSess($j) set Dst] launchHttp $HttpSess($j) $httpS $dst $j}for {set j 1} {$j<=[array size FTPSess]} {incr j} { set dst [$FTPSess($j) set Dst] launchFtp $FTPSess($j) $ftpS $dst $j}############## config diffserv related settings #########################
# Configure queue and policy management
# core queue
confDSCore $GGSN $SGSN
confDSEdges $voipS $cir_VoIP EFconfDSEdges $videoS $cir_video AF1
confDSEdges $httpS $cir_http AF2
confDSEdges $ftpS $cir_ftp BE
################################################################################ schedule all events in session list, do the CAC and release BW at its end ################################################################################for {set j 1} {$j<=[array size VoipSess]} {incr j} { $ns at [$VoipSess($j) set StartT] "$VoipSess($j) set started [CAC $VoipSess($j) $EB_VoIP [$VoipSess($j) set EndT]]" }for {set j 1} {$j<=[array size VideoSess]} {incr j} { $ns at [$VideoSess($j) set StartT] "$VideoSess($j) set started [CAC $VideoSess($j) $EB_video [$VideoSess($j) set EndT]]" }for {set j 1} {$j<=[array size HttpSess]} {incr j} { $ns at [$HttpSess($j) set StartT] "$HttpSess($j) set started [CAC $HttpSess($j) $EB_http [$HttpSess($j) set EndT]]" }for {set j 1} {$j<=[array size FTPSess]} {incr j} { $ns at [$FTPSess($j) set StartT] "$FTPSess($j) set started [CAC $FTPSess($j) $EB_ftp [$FTPSess($j) set EndT]]" }############### End of session scheduling ###################################### ######### set queue monitoring ##################################################
# Set monitoring for queue length (some performance cost - adjust 'q_interval' below)
# Outputfiles: q_GGSNSGSN.mon, q_GGSNSGSN_avg.mon, q_SGSNGGSN.mon, q_SGSNGGSN_avg.mon.
set monitor_qlengths true
set trace_bn trueset trace_nam_all falseset trace_all false#if {$trace_all} {# set tf [open tr_all.tr w]# $ns trace-all $tf#}
if {$trace_bn} {
set tqf [open "tr_bottleneck.out" w]
$ns trace-queue $GGSN $SGSN $tqf
} # Queue-monitoring (for bottleneck link)
set qf [open "qmon_bottleneck.mon" w]
set qmon [$ns monitor-queue $GGSN $SGSN $qf]
$ns at 1.0 "record $qmon $GGSN $SGSN 1 $qf"
if {$trace_nam_all} { set namf [open tr_diffnet.nam w] $ns namtrace-all $namf} # Some diffserv-specific monitoring stuff
#diffservStats
#set pf [open AvBWActSess.tr w]
#$ns at 10 "timeStats 5 $pf"############open trace files for send/receive data packet records##########set df [open all_Tx_Rx.out w]TxRxStats $df
################# end of monitoring settings################# A procedure for finishing up the simulation
proc finish {} {
global ns q GGSN SGSN Arv_sess Block_sess VoipSess VideoSess HttpSess FTPSess #namf
puts "Arrived session #: $Arv_sess " puts "Blocked session #: $Block_sess "
# Print final DiffServ queue statictics from the bottleneck link puts "Core queue: GGSN->SGSN link Pkt Statistics"
$q($GGSN$SGSN) printStats set f1 [open voipSess.tr w] printAdmitFlow VOIP VoipSess $f1 close $f1
set f2 [open videoSess.tr w] printAdmitFlow VIDEO VideoSess $f2 close $f2 set f3 [open httpSess.tr w] printAdmitFlow HTTP HttpSess $f3 close $f3 set f4 [open ftpSess.tr w] printAdmitFlow FTP FTPSess $f4 close $f4 $ns flush-trace
exit 0
}
$ns at [expr $testTime + 1] "finish" ;# End the simulation
$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -