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

📄 dsexample2.tcl

📁 主要改进了算法
💻 TCL
字号:
# This is a simple example in which I want to illustrate the use# of EF and BE traffic using the ds patches to ns that I wrote.## In this simple experiment, there are two EF sources and three BE# sources. The EF sources are both of rate 100kb/s and the BE sources# are infinite FTP sources. All the sources are transmitting in the same# direction - there is no traffic (other than ACKs) going in the other# direction. The EF sources have policers - if the rate of the EF# sources is increased the EF throughput remains unchanged.# This is not meant be representative of a# real world situation, but merely a simple example to illustrate# the use of the DS EF class.## Sean Murphy# 17/11/99.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]#    if {$now >3.3} {#	set tempbytes [expr $tempbytes+$byte]#    }    #    if {$now > 8.9 && $now <9.5} {#	puts "$self: tempbytes = $tempbytes"#    }        $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 default_options {} {	global opts opt_wants_arg	set raw_opt_info {	    end 200.0	    warmup 20.0	    seed 1	    bottlenecklink 1Mb	}	while {$raw_opt_info != ""} {		if {![regexp "^\[^\n\]*\n" $raw_opt_info line]} {			break		}		regsub "^\[^\n\]*\n" $raw_opt_info {} raw_opt_info		set line [string trim $line]		if {[regexp "^\[ \t\]*#" $line]} {			continue		}		if {$line == ""} {			continue		} elseif [regexp {^([^ ]+)[ ]+([^ ]+)$} $line dummy \			      key value] {			set opts($key) $value			set opt_wants_arg($key) 1		} else {			set opt_wants_arg($key) 0			# die "unknown stuff in raw_opt_info\n"		}	}}proc process-args {} {	global argc argv opts opt_wants_arg	default_options	for {set i 0} {$i < $argc} {incr i} {		set key [lindex $argv $i]		if {$key == "-?" || $key == "--help" || $key == "-help" || $key == "-h"} {			usage		}		regsub {^-} $key {} key		if {![info exists opt_wants_arg($key)]} {			puts stderr "unknown option $key";			usage		}		if {$opt_wants_arg($key)} {			incr i			set opts($key) [lindex $argv $i]		} else {			set opts($key) [expr !opts($key)]		}	}}proc create_topology {} {    global ns source_node dest_node opts mux1 mux2    set mux1 [$ns node]    set mux2 [$ns node]    $ns DSSchedulerLink-duplex-link $mux1 $mux2 $opts(bottlenecklink) 1ms    for {set i 0} {$i < 5} {incr i} {	set source_node($i) [$ns node]	$ns duplex-link $source_node($i) $mux1 10Mb 0.1ms DropTail	set dest_node($i) [$ns node]	$ns duplex-link $dest_node($i) $mux2 10Mb 0.1ms DropTail    }}proc create_agents {} {    global ns source_node dest_node agent sink    for {set i 0} {$i < 5} {incr i} {	if {$i < 2} {	    set agent($i) [new Agent/UDP]	    $agent($i) set-DSCP EF	    $agent($i) set packetSize_ 200	    set sink($i) [new Agent/Null]	} else {	    set agent($i) [new Agent/TCP/Reno]	    # following line not necessary, since BE is the default,	    # but it's included here for clarity	    $agent($i) set-DSCP BE	    set sink($i) [new Agent/TCPSink]	    $sink($i) set-DSCP BE	}	$ns attach-agent $source_node($i) $agent($i)	$ns attach-agent $dest_node($i) $sink($i)	$ns connect $agent($i) $sink($i)    }}proc create_sources {} {    global agent sink ns source opts tracer    for {set i 0} {$i < 5} {incr i} {	if {$i < 2} {	    set source($i) [new Application/Traffic/CBR]	    $source($i) set packet_size_ 200	    $source($i) set rate_ 100kb	} else {	    set source($i) [new Application/FTP]	    $source($i) set packetSize_ 576	}	$source($i) attach-agent $agent($i)        $ns at 0.0 "$source($i) start"	set tracer($i) [new TraceApp]	$tracer($i) attach-agent $sink($i)	$ns at $opts(warmup) "$tracer($i) start"    }}proc create_conditioners {} {    global ns conditioner profile agent source_node mux1    for {set i 0} {$i < 2} {incr i} {	set profile($i) [new DSPeakRateProfile]	$profile($i) set src_ [$agent($i) set agent_addr_]	$profile($i) set-scope ONE_TO_ANY	$profile($i) set peak_ 100kb	$profile($i) set-DSCP EF	# bucket size currenltly measured in bits - I should change	# this to bytes	$profile($i) set bucket_size_ 5000	# this is necessary to fill the bucket at the start time -	# I should move this functionality into the conditioner, so that	# the conditioner only needs to be initialised rather than each	# profile individually.	$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) $mux1    }}proc end {} {    global tracer opts    set total_rate 0    for {set i 0} {$i < 5} {incr i} {	set bytes [$tracer($i) get_bytes]	set rate [expr ($bytes*8)/(1000*($opts(end)-$opts(warmup)))]	set total_rate [expr $total_rate+$rate]	puts "Rate for source $i: $rate kb/s"    }    puts "Total goodput: $total_rate kb/s"    exit 0}proc configure_schedulers {} {    global ns mux1 mux2    set scheduler1 [[$ns link $mux1 $mux2] queue]    set scheduler2 [[$ns link $mux2 $mux1] queue]    $scheduler1 set-ef-queue-length 10    $scheduler1 set-be-queue-length 100    $scheduler1 be-queue-red-params 0.002 45 90 20    $scheduler1 set ef_queue_weight_ 2    $scheduler1 set af_queue_weight_ 0    $scheduler1 set be_queue_weight_ 8    $scheduler1 set aggregate-bytes-thresh 1000    # the following are not used    $scheduler1 set-af-queue-length 0    $scheduler1 af-queue-rio-params 0.002 45 90 50 20 40 25    # this scheduler is used by the ACK traffic travelling in the    # other direction - the only thing that is important here is    # that the be traffic queue is non 0 and that the be queue has    # some capacity assigned to it    $scheduler2 set-ef-queue-length 10    $scheduler2 set-be-queue-length 100    $scheduler2 be-queue-red-params 0.002 45 90 20    $scheduler2 set ef_queue_weight_ 2    $scheduler2 set af_queue_weight_ 0    $scheduler2 set be_queue_weight_ 8    $scheduler2 set aggregate-bytes-thresh 1000    # completely redundant    $scheduler2 set-af-queue-length 0    $scheduler2 af-queue-rio-params 0.002 45 90 50 20 40 25}process-argsset ns [new Simulator]$defaultRNG seed $opts(seed)puts "Creating topology..."create_topologyputs "Creating agents..."create_agentsputs "Creating sources..."create_sourcesputs "Creating conditioners..."create_conditionersputs "Configuring schedulers..."configure_schedulers$ns at $opts(end) "end"puts "Starting simulation..."$ns run

⌨️ 快捷键说明

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