ns-namsupp.tcl

来自「一款用来进行网络模拟的软件」· TCL 代码 · 共 591 行 · 第 1/2 页

TCL
591
字号
# #  Copyright (c) 1997 by the University of Southern California#  All rights reserved.# #  This program is free software; you can redistribute it and/or#  modify it under the terms of the GNU General Public License,#  version 2, as published by the Free Software Foundation.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#  GNU General Public License for more details.##  You should have received a copy of the GNU General Public License along#  with this program; if not, write to the Free Software Foundation, Inc.,#  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.##  The copyright of this module includes the following#  linking-with-specific-other-licenses addition:##  In addition, as a special exception, the copyright holders of#  this module give you permission to combine (via static or#  dynamic linking) this module with free software programs or#  libraries that are released under the GNU LGPL and with code#  included in the standard release of ns-2 under the Apache 2.0#  license or under otherwise-compatible licenses with advertising#  requirements (or modified versions of such code, with unchanged#  license).  You may copy and distribute such a system following the#  terms of the GNU GPL for this module and the licenses of the#  other code concerned, provided that you include the source code of#  that other code when and as the GNU GPL requires distribution of#  source code.##  Note that people who make modified versions of this module#  are not obligated to grant this special exception for their#  modified versions; it is their choice whether to do so.  The GNU#  General Public License gives permission to release a modified#  version without this exception; this exception also makes it#  possible to release a modified version which carries forward this#  exception.# # ns trace support for nam## Author: Haobo Yu (haoboy@isi.edu)## $Header: /cvsroot/nsnam/ns-2/tcl/lib/ns-namsupp.tcl,v 1.43 2006/02/22 13:23:15 mahrenho Exp $### Support for node tracing## This will only work during initialization. Not possible to change shape # dynamicallyNode instproc shape { shape } {	$self instvar attr_ 	set attr_(SHAPE) $shape}# Returns the current shape of the nodeNode instproc get-shape {} {	$self instvar attr_	if [info exists attr_(SHAPE)] {		return $attr_(SHAPE)	} else {		return ""	}}Node instproc color { color } {	$self instvar attr_ id_	set ns [Simulator instance]	if [$ns is-started] {		# color must be initialized		$ns puts-nam-config \		[eval list "n -t [format "%.15g" [$ns now]] -s $id_ -S COLOR -c $color -o $attr_(COLOR) -i $color -I $attr_(LCOLOR)"]		set attr_(COLOR) $color	        set attr_(LCOLOR) $color	} else {		set attr_(COLOR) $color	        set attr_(LCOLOR) $color	}}Node instproc label { str} {	$self instvar attr_ id_	set ns [Simulator instance]	if [info exists attr_(DLABEL)] {		$ns puts-nam-config "n -t [$ns now] -s $id_ -S DLABEL -l \"$str\" -L $attr_(DLABEL)"	} else {		$ns puts-nam-config "n -t [$ns now] -s $id_ -S DLABEL -l \"$str\" -L \"\""	}	set attr_(DLABEL) \"$str\"}Node instproc label-color { str} {        $self instvar attr_ id_        set ns [Simulator instance]        if [info exists attr_(DCOLOR)] {                $ns puts-nam-config "n -t [$ns now] -s $id_ -S DCOLOR -e \"$str\" -E $attr_(DCOLOR)"        } else {                $ns puts-nam-config "n -t [$ns now] -s $id_ -S DCOLOR -e \"$str\" -E \"\""        }        set attr_(DCOLOR) \"$str\"}Node instproc label-at { str } {        $self instvar attr_ id_        set ns [Simulator instance]        if [info exists attr_(DIRECTION)] {                $ns puts-nam-config "n -t [$ns now] -s $id_ -S DIRECTION -p \"$str\" -P $attr_(DIRECTION)"        } else {                $ns puts-nam-config "n -t [$ns now] -s $id_ -S DIRECTION -p \"$str\" -P \"\""        }        set attr_(DIRECTION) \"$str\"}Node instproc dump-namconfig {} {	$self instvar attr_ id_ address_ X_ Y_ Z_	set ns [Simulator instance]	if ![info exists attr_(SHAPE)] {		set attr_(SHAPE) "circle"	} 	if ![info exists attr_(COLOR)] {		set attr_(COLOR) "black"	        set attr_(LCOLOR) "black"	}        if ![info exists attr_(DCOLOR)] {                set attr_(DCOLOR) "black"        }	if { [info exists X_] && [info exists Y_] } {		if [info exists Z_] {			$ns puts-nam-config \			[eval list "n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR) -x $X_ -y $Y_ -Z $Z_"]		} else {			$ns puts-nam-config \			[eval list "n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR) -x $X_ -y $Y_"]		}	} else {	$ns puts-nam-config \		[eval list "n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR)"]	}}Node instproc change-color { color } {	puts "Warning: Node::change-color is obsolete. Use Node::color instead"	$self color $color}Node instproc get-attribute { name } {	$self instvar attr_	if [info exists attr_($name)] {		return $attr_($name)	} else {		return ""	}}Node instproc get-color {} {	puts "Warning: Node::get-color is obsolete. Please use Node::get-attribute"	return [$self get-attribute "COLOR"]}Node instproc add-mark { name color {shape "circle"} } {	$self instvar id_ markColor_ shape_	set ns [Simulator instance]	$ns puts-nam-config "m -t [$ns now] -s $id_ -n $name -c $color -h $shape"	set markColor_($name) $color	set shape_($name) $shape}Node instproc delete-mark { name } {	$self instvar id_ markColor_ shape_	# Ignore if the mark $name doesn't exist	if ![info exists markColor_($name)] {		return	}	set ns [Simulator instance]	$ns puts-nam-config \		"m -t [$ns now] -s $id_ -n $name -c $markColor_($name) -h $shape_($name) -X"}## Support for link tracing# XXX only SimpleLink (and its children) can dump nam config, because Link# doesn't have bandwidth and delay.#SimpleLink instproc dump-namconfig {} {	# make a duplex link in nam	$self instvar link_ attr_ fromNode_ toNode_	if ![info exists attr_(COLOR)] {		set attr_(COLOR) "black"	}	set ns [Simulator instance]	set bw [$link_ set bandwidth_]	set delay [$link_ set delay_]	if [info exists attr_(ORIENTATION)] {		$ns puts-nam-config \			"l -t * -s [$fromNode_ id] -d [$toNode_ id] -S UP -r $bw -D $delay -c $attr_(COLOR) -o $attr_(ORIENTATION)"	} else {		$ns puts-nam-config \			"l -t * -s [$fromNode_ id] -d [$toNode_ id] -S UP -r $bw -D $delay -c $attr_(COLOR)"	}}Link instproc dump-nam-queueconfig {} {	$self instvar attr_ fromNode_ toNode_	if ![info exists attr_(COLOR)] {		set attr_(COLOR) "black"	}	set ns [Simulator instance]	if [info exists attr_(QUEUE_POS)] {		$ns puts-nam-config "q -t * -s [$fromNode_ id] -d [$toNode_ id] -a $attr_(QUEUE_POS)"	} else {		set attr_(QUEUE_POS) ""	}}## XXX# This function should be called ONLY ONCE during initialization. # The order in which links are created in nam is determined by the calling # order of this function.#Link instproc orient { ori } {	$self instvar attr_	set attr_(ORIENTATION) $ori	[Simulator instance] register-nam-linkconfig $self}Link instproc get-attribute { name } {	$self instvar attr_	if [info exists attr_($name)] {		return $attr_($name)	} else {		return ""	}}Link instproc queuePos { pos } {	$self instvar attr_	set attr_(QUEUE_POS) $pos}Link instproc color { color } {	$self instvar attr_ fromNode_ toNode_ trace_	set ns [Simulator instance]	if [$ns is-started] {		$ns puts-nam-config \			[eval list "l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S COLOR -c $color -o $attr_(COLOR)"]		set attr_(COLOR) $color	} else {		set attr_(COLOR) $color	}}# a link doesn't have its own trace file, write it to global trace fileLink instproc change-color { color } {	puts "Warning: Link::change-color is obsolete. Please use Link::color."	$self color $color}Link instproc get-color {} {	puts "Warning: Node::get-color is obsolete. Please use Node::get-attribute"	return [$self get-attribute "COLOR"]}Link instproc label { label } {        $self instvar attr_ fromNode_ toNode_ trace_        set ns [Simulator instance]        if [info exists attr_(DLABEL)] {            $ns puts-nam-config \            "l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DLABEL -l \"$label\" -L $attr_(DLABEL)"        } else {            $ns puts-nam-config \            "l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DLABEL -l \"$label\" -L \"\""        }

⌨️ 快捷键说明

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