⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsexample1.tcl

📁 主要改进了算法
💻 TCL
字号:
# This is a simple example script that demonstrates the functionality# of the ds patch to the ns software that I developed.## This example script was written for the ns-2.1b5 release of my software# It should work with the ns-2.1b6-snapshot if the any [$agent set addr_]# commands are changed to [$agent set agent_addr_]## The network topology is a simple so-called dumb-bell configuration -# there are 10 hosts on either side of a bottleneck link; 10 of the hosts# are sources and the other 10 are destinations. In this example, 2 of# the sources generate EF traffic, 3 generate AF traffic and the remaining# 5 generate BE traffic.## The network topology looks like this# # s1 -\               /-d1#      \             /# ..    r1---------r2   ..#      /             \ # s10-/               \-d10### The bottleneck link is 3Mb with a delay of 1ms, the access links are# 10Mb with 0.1ms delay. The EF traffic is CBR and the AF and BE traffics# are infinite FTPs with TCPReno (the simple variant) flow control.## This is not meant to be representative of any real life scenario, merely# a demonstration of how the diffserv functionality works.## Sean Murphy# 5/11/99.# this TraceApp class is merely a byte counter - it sits on top of either# an Agent/Null or Agent/TCPSink and counts incoming bytes - it's used for# measuring goodput - Haobo Yu mailed this to the list - I'm working on# getting this functionality implemented at the c++ layer and integrated# into ns - working at the Otcl layer slows things down very considerably.Class TraceApp -superclass ApplicationTraceApp instproc init {args} {    $self instvar bytes_    $self instvar tempbytes    $self set bytes_ 0    $self set tempbytes 0    eval $self next $args}TraceApp instproc recv {byte} {    global ns    $self instvar tempbytes    set now [$ns now]        $self instvar bytes_    set bytes_ [expr $bytes_ + $byte]        return $bytes_}TraceApp instproc get_bytes {} {    $self instvar bytes_    return $bytes_}TraceApp instproc reset {} {    $self instvar bytes_    set bytes_ 0}proc create_agent { type codepoint node } {    global ns    set agent [new $type]    $agent set-DSCP $codepoint    $ns attach-agent $node $agent    return $agent}proc make-profile {scope srcaddr rate bucketsize codepoint} {    global ns    set profile [new DSPeakRateProfile]    $profile set-scope $scope    $profile set src_ $srcaddr    $profile set peak_ $rate    $profile set bucket_size_ $bucketsize    $profile set-DSCP $codepoint    $ns at 0.0 "$profile start"    return $profile}proc create_topology {} {    global source_node dest_node router ns linkrate    set router(0) [$ns node]    set router(1) [$ns node]    $ns DSSchedulerLink-duplex-link $router(0) $router(1) $linkrate 1ms    for {set i 0} {$i < 10} {incr i} {	set source_node($i) [$ns node]	$ns duplex-link $source_node($i) $router(0) 10Mb 0.1ms DropTail	set dest_node($i) [$ns node]	$ns duplex-link $dest_node($i) $router(1) 10Mb 0.1ms DropTail    }}proc create_agents {} {    global source_node dest_node source_agent dest_agent ns    # ef agents    for {set i 0} {$i < 2} {incr i} {	set source_agent($i) [create_agent Agent/UDP EF \				  $source_node($i)]	# the BE parameter here is unused	set dest_agent($i) [create_agent Agent/Null BE \				$dest_node($i)]	$ns connect $source_agent($i) $dest_agent($i)    }    for {set i 2} {$i < 5} {incr i} {	set source_agent($i) [create_agent Agent/TCP AF11 \				  $source_node($i)]	set dest_agent($i) [create_agent Agent/TCPSink AF11 \				$dest_node($i)]	$ns connect $source_agent($i) $dest_agent($i)    }    for {set i 5} {$i < 10} {incr i} {	set source_agent($i) [create_agent Agent/TCP BE \				  $source_node($i)]	set dest_agent($i) [create_agent Agent/TCPSink BE \				$dest_node($i)]	$ns connect $source_agent($i) $dest_agent($i)    }}proc create_sources {} {    global source_agent dest_agent counter source ns warmup end    set source(0) [new Application/Traffic/CBR]    $source(0) attach-agent $source_agent(0)    set source(1) [new Application/Traffic/CBR]    $source(1) attach-agent $source_agent(1)    for {set i 0} {$i < 8} {incr i} {	set source([expr $i+2]) [new Application/FTP]	$source([expr $i+2]) attach-agent $source_agent([expr $i+2])    }    for {set i 0} {$i < 10} {incr i} {	set counter($i) [new TraceApp]	$counter($i) attach-agent $dest_agent($i)	$ns at $warmup "$counter($i) start"	$ns at 0.0 "$source($i) start"    }}proc create_conditioners {} {    global source_agent ns router source_node conditioner    for {set i 0} {$i < 5} {incr i} {	if {($i < 2)} {	    set rate 200kb	    set bucketsize 10000	    set codepoint EF	}	if {($i > 1)} {	    set rate 500kb	    set bucketsize 80000	    set codepoint AF11	}	    	set profile($i) [make-profile ONE_TO_ANY \			     [$source_agent($i) set agent_addr_] \			     $rate $bucketsize $codepoint]	$ns at 0.0 "$profile($i) start"	set conditioner($i) [new DSConditioner]	$conditioner($i) add-profile $profile($i)	$ns insert-conditioner $conditioner($i) \	    $source_node($i) $router(0)    }}proc configure_schedulers {} {    global ns router    # note that the schedulers must be configured in both directions    set scheduler1 [[$ns link $router(0) $router(1)] queue]    set scheduler2 [[$ns link $router(1) $router(0)] queue]    $scheduler1 set-ef-queue-length 10    $scheduler1 set-af-queue-length 100    $scheduler1 set-be-queue-length 200    $scheduler1 af-queue-rio-params 0.002 45 90 50 20 40 25    $scheduler1 be-queue-red-params 0.002 50 180 20    $scheduler1 set ef_queue_weight_ 1    $scheduler1 set af_queue_weight_ 4    $scheduler1 set be_queue_weight_ 5    $scheduler1 set aggregate-bytes-thresh 1000    $scheduler2 set-ef-queue-length 0    $scheduler2 set-af-queue-length 100    $scheduler2 set-be-queue-length 200    $scheduler2 af-queue-rio-params 0.002 45 90 50 20 40 25    $scheduler2 be-queue-red-params 0.002 50 180 20    $scheduler2 set ef_queue_weight_ 1    $scheduler2 set af_queue_weight_ 4    $scheduler2 set be_queue_weight_ 5    $scheduler2 set aggregate-bytes-thresh 1000    }proc end {} {    global ns counter end warmup conditioner    puts "Goodput per source:"    for {set i 0} {$i < 10} {incr i} {	if {($i < 2)} {	    set sourcetype EF	}	if {($i > 1) && ($i < 5)} {	    set sourcetype AF11	}	if {($i > 4)} {	    set sourcetype BE	}	set bytes [$counter($i) get_bytes]	set rate [expr $bytes*8/(1000*($end-$warmup))]	puts "Goodput for source $i ($sourcetype): $rate kb/s"    }    puts "\nConditioner statistics:"    for {set i 0} {$i < 5} {incr i} {	puts "Conditioner $i:-"	if {$i < 2} {	    puts "Scoped ef packets [$conditioner($i) get-scoped-ef-packets]"	    puts "Non conformant EF packets (dropped) [$conditioner($i) get-nonconformant-ef-packets]"	} else {	    puts "Scoped af packets [$conditioner($i) get-scoped-af-packets]"	    puts "Non conformant AF packets (remarked) [$conditioner($i) get-nonconformant-af-packets]"	}    }    exit 0}set end 100.0set warmup 20.0set linkrate 5Mbset ns [new Simulator]puts "Creating topology..."create_topologyputs "Creating agents..."create_agentsputs "Creating sources..."create_sourcesputs "Creating conditioners..."create_conditionersputs "Configuring schedulers..."configure_schedulers$ns at $end "end"puts "Starting simulation..."$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -