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

📄 ns-lib.tcl

📁 NS-2.28的802.11e协议扩展源代码
💻 TCL
📖 第 1 页 / 共 4 页
字号:
		set n1 [$n1 id]	}        if { ![catch "$n2 info class Node"] } {		set n2 [$n2 id]	}	if [info exists link_($n1:$n2)] {		return $link_($n1:$n2)	}	return ""}# Creates connection. First creates a source agent of type s_type and binds# it to source.  Next creates a destination agent of type d_type and binds# it to dest.  Finally creates bindings for the source and destination agents,# connects them, and  returns the source agent.Simulator instproc create-connection {s_type source d_type dest pktClass} {	set s_agent [new Agent/$s_type]	set d_agent [new Agent/$d_type]	$s_agent set fid_ $pktClass	$d_agent set fid_ $pktClass	$self attach-agent $source $s_agent	$self attach-agent $dest $d_agent	$self connect $s_agent $d_agent		return $s_agent}# Creates connection. First creates a source agent of type s_type and binds# it to source.  Next creates a destination agent of type d_type and binds# it to dest.  Finally creates bindings for the source and destination agents,# connects them, and  returns a list of source agent and destination agent.Simulator instproc create-connection-list {s_type source d_type dest pktClass} {    set s_agent [new Agent/$s_type]    set d_agent [new Agent/$d_type]    $s_agent set fid_ $pktClass    $d_agent set fid_ $pktClass    $self attach-agent $source $s_agent    $self attach-agent $dest $d_agent    $self connect $s_agent $d_agent    return [list $s_agent $d_agent]}   # This seems to be an obsolete procedure.Simulator instproc create-tcp-connection {s_type source d_type dest pktClass} {	set s_agent [new Agent/$s_type]	set d_agent [new Agent/$d_type]	$s_agent set fid_ $pktClass	$d_agent set fid_ $pktClass	$self attach-agent $source $s_agent	$self attach-agent $dest $d_agent#	$self connect $s_agent $d_agent		return "$s_agent $d_agent"}Classifier instproc no-slot slot {	#XXX should say something better for routing problem	puts stderr \		"tcl/lib/ns-lib.tcl -- Classfier::no-slot{} default handler --"	puts stderr "    $self: no target for slot $slot"	exit 1}## Other classifier methods overload the instproc-likes to track # and return the installed objects.#Classifier instproc install {slot val} {	$self set slots_($slot) $val	$self cmd install $slot $val}Classifier instproc installNext val {	set slot [$self cmd installNext $val]	$self set slots_($slot) $val	set slot}Classifier instproc adjacents {} {	$self array get slots_}Classifier instproc in-slot? slot {	$self instvar slots_	set ret ""	if {[array size slots_] < $slot} {		set ret slots_($slot)	}	set ret}# Why don't we have an "unknown-flow" method for Classifier?# dump is for debugging purposesClassifier instproc dump {} {	$self instvar slots_ offset_ shift_ mask_	puts "classifier $self"	puts "\t$offset_ offset"	puts "\t$shift_ shift"	puts "\t$mask_ mask"	puts "\t[array size slots_] slots"	foreach i [lsort -integer [array names slots_]] {		set iv $slots_($i)		puts "\t\tslot $i: $iv"	}}Classifier/Hash instproc dump args {	eval $self next $args	$self instvar default_	puts "\t$default_ default"}Classifier/Hash instproc init nbuck {	# we need to make sure that port shift/mask values are there	# so we set them after they get their default values	$self next $nbuck	$self instvar shift_ mask_	set shift_ [AddrParams set NodeShift_(1)]	set mask_ [AddrParams set NodeMask_(1)]}Simulator instproc makeflowmon { cltype { clslots 29 } } {		set flowmon [new QueueMonitor/ED/Flowmon]	set cl [new Classifier/Hash/$cltype $clslots]		$cl proc unknown-flow { src dst fid }  {		set fdesc [new QueueMonitor/ED/Flow]		set dsamp [new Samples]		$fdesc set-delay-samples $dsamp		set slot [$self installNext $fdesc] 		$self set-hash auto $src $dst $fid $slot	}		$cl proc no-slot slotnum {		#		# note: we can wind up here when a packet passes		# through either an Out or a Drop Snoop Queue for		# a queue that the flow doesn't belong to anymore.		# Since there is no longer hash state in the		# hash classifier, we get a -1 return value for the		# hash classifier's classify() function, and there		# is no node at slot_[-1].  What to do about this?		# Well, we are talking about flows that have already		# been moved and so should rightly have their stats		# zero'd anyhow, so for now just ignore this case..		# puts "classifier $self, no-slot for slotnum $slotnum"	}	$flowmon classifier $cl	return $flowmon}# attach a flow monitor to a link# 3rd argument dictates whether early drop support is to be usedSimulator instproc attach-fmon {lnk fm { edrop 0 } } {	set isnoop [new SnoopQueue/In]	set osnoop [new SnoopQueue/Out]	set dsnoop [new SnoopQueue/Drop]	$lnk attach-monitors $isnoop $osnoop $dsnoop $fm	if { $edrop != 0 } {	    set edsnoop [new SnoopQueue/EDrop]	    $edsnoop set-monitor $fm	    [$lnk queue] early-drop-target $edsnoop	    $edsnoop target [$self set nullAgent_]	}	[$lnk queue] drop-target $dsnoop}# Added by Yun WangSimulator instproc maketbtagger { cltype { clslots 29 } } {        set tagger [new QueueMonitor/ED/Tagger]        set cl [new Classifier/Hash/$cltype $clslots]        $cl proc unknown-flow { src dst fid }  {                set fdesc [new QueueMonitor/ED/Flow/TB]                set dsamp [new Samples]                $fdesc set-delay-samples $dsamp                set slot [$self installNext $fdesc]                $self set-hash auto $src $dst $fid $slot        }        $cl proc set-rate { src dst fid hashbucket rate depth init} {                set fdesc [new QueueMonitor/ED/Flow/TB]                set dsamp [new Samples]                $fdesc set-delay-samples $dsamp                $fdesc set target_rate_ $rate                $fdesc set bucket_depth_ $depth                # Initialize the bucket as full                $fdesc set tbucket_ $init                  set slot [$self installNext $fdesc]                $self set-hash $hashbucket $src $dst $fid $slot        }        $cl proc no-slot slotnum {                #                # note: we can wind up here when a packet passes                # through either an Out or a Drop Snoop Queue for                # a queue that the flow doesn't belong to anymore.                # Since there is no longer hash state in the                # hash classifier, we get a -1 return value for the                # hash classifier's classify() function, and there                # is no node at slot_[-1].  What to do about this?                # Well, we are talking about flows that have already                # been moved and so should rightly have their stats                # zero'd anyhow, so for now just ignore this case..                # puts "classifier $self, no-slot for slotnum $slotnum"        }        $tagger classifier $cl        return $tagger}# Added by Yun WangSimulator instproc maketswtagger { cltype { clslots 29 } } {        set tagger [new QueueMonitor/ED/Tagger]        set cl [new Classifier/Hash/$cltype $clslots]        $cl proc unknown-flow { src dst fid hashbucket }  {                set fdesc [new QueueMonitor/ED/Flow/TSW]                set dsamp [new Samples]                $fdesc set-delay-samples $dsamp                set slot [$self installNext $fdesc]                $self set-hash $hashbucket $src $dst $fid $slot        }        $cl proc no-slot slotnum {                #                # note: we can wind up here when a packet passes                # through either an Out or a Drop Snoop Queue for                # a queue that the flow doesn't belong to anymore.                # Since there is no longer hash state in the                # hash classifier, we get a -1 return value for the                # hash classifier's classify() function, and there                # is no node at slot_[-1].  What to do about this?                # Well, we are talking about flows that have already                # been moved and so should rightly have their stats                # zero'd anyhow, so for now just ignore this case..                # puts "classifier $self, no-slot for slotnum $slotnum"        }        $tagger classifier $cl        return $tagger}# attach a Tagger to a link# Added by Yun WangSimulator instproc attach-tagger {lnk fm} {        set isnoop [new SnoopQueue/Tagger]        $lnk attach-taggers $isnoop $fm}# Imported from session.tcl. It is deleted there.### to insert loss module to regular links in detailed SimulatorSimulator instproc lossmodel {lossobj from to} {	set link [$self link $from $to]	$link errormodule $lossobj}# This function generates losses that can be visualized by nam.Simulator instproc link-lossmodel {lossobj from to} {	set link [$self link $from $to]	$link insert-linkloss $lossobj}Simulator instproc bw_parse { bspec } {        if { [scan $bspec "%f%s" b unit] == 1 } {                set unit b        }	# xxx: all units should support X"ps" --johnh        switch $unit {        b  { return $b }        bps  { return $b }        kb { return [expr $b*1000] }        Mb { return [expr $b*1000000] }        Gb { return [expr $b*1000000000] }        default {                   puts "error: bw_parse: unknown unit `$unit'"                   exit 1                }        }}Simulator instproc delay_parse { dspec } {        if { [scan $dspec "%f%s" b unit] == 1 } {                set unit s        }        switch $unit {        s  { return $b }        ms { return [expr $b*0.001] }        ns { return [expr $b*0.000001] }        default {                   puts "error: bw_parse: unknown unit `$unit'"                   exit 1                }        }}#### Polly Huang: Simulator class instproc to support abstract tcp simulationsSimulator instproc rtt { src dst } {    $self instvar routingTable_ delay_    set srcid [[$src set node_] id]    set dstid [[$dst set node_] id]    set delay 0    set tmpid $srcid    while {$tmpid != $dstid} {        set nextid [$routingTable_ lookup $tmpid $dstid]        set tmpnode [$self get-node-by-id $tmpid]        set nextnode [$self get-node-by-id $nextid]        set tmplink [[$self link $tmpnode $nextnode] link]        set delay [expr $delay + [expr 2 * [$tmplink set delay_]]]        set delay [expr $delay + [expr 8320 / [$tmplink set bandwidth_]]]        set tmpid $nextid    }    $src rtt $delay    return $delay}Simulator instproc abstract-tcp {} {    $self instvar TahoeAckfsm_ RenoAckfsm_ TahoeDelAckfsm_ RenoDelAckfsm_ dropper_     $self set TahoeAckfsm_ [new FSM/TahoeAck]    $self set RenoAckfsm_ [new FSM/RenoAck]    $self set TahoeDelAckfsm_ [new FSM/TahoeDelAck]    $self set RenoDelAckfsm_ [new FSM/RenoDelAck]    $self set nullAgent_ [new DropTargetAgent]}#### Chalermek: For Diffusion, Flooding, and Omnicient Multicast Simulator instproc create-diffusion-rate-agent {node} {    set diff [new Agent/Diffusion/RateGradient]    $node set diffagent_ $diff    $node set ragent_ $diff    $diff on-node $node    if [info exist opt(enablePos)] {	if {$opt(enablePos) == "true"} {	    $diff enable-pos	} else {	    $diff disable-pos	}    }     if [info exist opt(enableNeg)] {	if {$opt(enableNeg) == "true"} {	    $diff enable-neg	} else {	    $diff disable-neg	}    }     if [info exist opt(suppression)] {	if {$opt(suppression) == "true"} {	    $diff enable-suppression	} else {	    $diff disable-suppression	}    }     if [info exist opt(subTxType)] {	$diff set-sub-tx-type $opt(subTxType)    }     if [info exist opt(orgTxType)] {	$diff set-org-tx-type $opt(orgTxType)    }     if [info exist opt(posType)] {	$diff set-pos-type $opt(posType)    }     if [info exist opt(posNodeType)] {	$diff set-pos-node-type $opt(posNodeType)    }     if [info exist opt(negWinType)] {	$diff set-neg-win-type $opt(negWinType)    }     if [info exist opt(negThrType)] {	$diff set-neg-thr-type $opt(negThrType)    }     if [info exist opt(negMaxType)] {	$diff set-neg-max-type $opt(negMaxType)    }     $self put-in-list $diff    $self at 0.0 "$diff start"    return $diff}Simulator instproc create-diffusion-probability-agent {node} {    set diff [new Agent/Diffusion/ProbGradient]    $node set diffagent_ $diff    $node set ragent_ $diff    $diff on-node $node    if [info exist opt(enablePos)] {	if {$opt(enablePos) == "true"} {	    $diff enable-pos	} else {	    $diff disable-pos	}    }     if [info exist opt(enableNeg)] {	if {$opt(enableNeg) == "true"} {	    $diff enable-neg	} else {	    $diff disable-neg	}    }     $self put-in-list $diff    $self at 0.0 "$diff start"    return $diff}Simulator instproc create-flooding-agent {node} {    set flood [new Agent/Flooding]    $node set ragent_ $flood    $flood on-node $node    $self put-in-list $flood    $self at 0.0 "$flood start"    return $flood}Simulator instproc create-omnimcast-agent {node} {    set omni [new Agent/OmniMcast]    $node set ragent_ $omni    $omni on-node $node    $self put-in-list $omni    $self at 0.0 "$omni start"    return $omni}Simulator instproc put-in-list {agent} {    $self instvar lagent    lappend lagent $agent}Simulator instproc terminate-all-agents {} {    $self instvar lagent    foreach i $lagent {	$i terminate    }}Simulator instproc prepare-to-stop {} {    $self instvar lagent    foreach i $lagent {	$i stop    }}

⌨️ 快捷键说明

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