Commit f7d6b348 authored by Mac Newbold's avatar Mac Newbold

Moved from ir/ns2ir

parent d5b7e46e
Class event
# output format is: time operation args
event instproc print {file} {
puts -nonewline $file "[$self set time] [$self set op] "
# we interpret args based on the operation.
# not too many supported at the moment...
switch [$self set op] {
link_up -
link_down {puts $file [$self set link]}
event instproc setlink {l} {
$self set link $l
Class link
#output format is
# link src srcport dst dstport
link instproc print {file} {
global nodeid_map
if {[info exists nodeid_map([$self set src])]} {
set srcname $nodeid_map([$self set src])
} else {
set srcname [$self set src]
if {[info exists nodeid_map([$self set dst])]} {
set dstname $nodeid_map([$self set dst])
} else {
set dstname [$self set dst]
puts $file "l[$self set id] $srcname [$self set srcport] $dstname [$self set dstport] [$self set bw] [$self set bw] [$self set delay] [$self set delay]"
Class node
# output format is: nodeID type link(s)
node instproc print {file} {
global nodeid_map
if {[info exists nodeid_map(n[$self set id])]} {
set nodename $nodeid_map(n[$self set id])
} else {
set nodename n[$self set id]
$self instvar nodelinks
puts -nonewline $file "$nodename [$self set type]"
foreach link $nodelinks {
puts -nonewline $file " $link"
#we have to add ". bandwidth delay" to delay nodes.
if [string match [$self set type] delay] {
puts -nonewline $file " . [$self set bw] [$self set delay]"
puts $file ""
#add link
node instproc addlink {link} {
$self instvar nodelinks
lappend nodelinks $link
if {$argc != 2} {
puts "usage: $argv0 ns_input_file ir_file"
exit 1
set libdir [file dirname [info script]]
source $libdir/tcl-object.tcl
source $libdir/node.tcl
source $libdir/link.tcl
source $libdir/event.tcl
# This some ugly/interesting tcl hacking to figure out what variables the user
# stored the node ids in.
rename set real_set
real_set skipset 0
proc set {args} {
global skipset
global nodeid_map
if {! $skipset} {
real_set skipset 1
real_set var [lindex $args 0]
if {$var != "currnode"} {
if {[llength $args] > 1} {
real_set val [lindex $args 1]
if {[regexp {^n[0-9]+$} $val] != -1} {
if {![info exists nodeid_map($val)]} {
real_set nodeid_map($val) $var
real_set skipset 0
if {[llength $args] == 1} {
return [uplevel real_set [lindex $args 0]]
} else {
return [uplevel real_set [lindex $args 0] \{[lindex $args 1]\}]
#nop is used for unimplemented $ns instprocs that are supposed to
#return things. the instproc returns a nop, which users call in their
#ns input file.
proc nop {args} {}
#begin at 0. 1,2,3... i cheerfully ignore the possibility of wrapping...
set nodeID 0
set linkID 0
set eventID 0
set nodelist {}
set linkslist {}
set eventlist {}
# sim.tcl handles the ns Simulator methods
source $libdir/sim.tcl
# stubs.tcl contains a lot of dummy things to allow execution of
# ns files without going through the trouble of redoing ns or something.
# i fear that it will grow without bound (or at least until I give up and
# make this whole thing into an ns add-on and keep all of the ns behavior)
source $libdir/stubs.tcl
# argv[0] is the ns input file
source [lindex $argv 0]
This diff is collapsed.
#dummy decls and stuff.
Class Agent/Null
Class Agent/TCP
Class Agent/TCPSink
Class Agent/UDP
Class Application/Traffic/CBR
Application/Traffic/CBR instproc attach-agent args {
$self set packet_size_ 3
$self set interval_ 3
return nop
Class Source/FTP
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment