- Home Page of ProjectGuideline.com ›
- Forums ›
- General Discussion Forum ›
- Programming Competition For Students ›
- how to run two tcl files
Hi all,
I repeated this topic because it has some typos.
I have two files :
the first one is p_bcast.tcl which has the following code :
#Probabilistic Broadcast Agent
#V.B., 2005
Class Agent/MessagePassing/MyPBCast -superclass { Agent/MessagePassing }
Agent/MessagePassing/MyPBCast instproc init {} {
$self instvar prob_
$self instvar seqno_
$self instvar flag_
$self next
set seqno_ 0
set flag_ 0
$self instvar agent_addr_
set prob_ 1
$self set_pkttype 13
$self set packetSize_ 256
}
Agent/MessagePassing/MyPBCast instproc setprob {prob} {
$self instvar prob_
set prob_ $prob
}
Agent/MessagePassing/MyPBCast instproc setseed {seed} {
$self instvar seed_
set seed_ $seed
expr srand($seed_)
}
Agent/MessagePassing/MyPBCast instproc send {} {
$self instvar seqno_
$self instvar agent_addr_
set msg “pbcast:$agent_addr_:$agent_addr_:$seqno_:”
set flag_ 1
$self sendto 256 $msg -1 90
}
Agent/MessagePassing/MyPBCast instproc recv { flg port len p } {
# receiver function
$self instvar agent_addr_
$self instvar flag_
$self instvar prob_
set L [split $p :]
set src_ [lindex $L 2]
set seqno_ [lindex $L 3]
if {$flag_ == 1} { return }
set flag_ 1
#here toss a coin and make probabilistic decision
set coin [expr rand()]
#puts $coin
#puts $prob_
if {$coin > $prob_} { return }
set msg “pbcast:$agent_addr_:$src_:$seqno_:”
$self sendto 256 $msg -1 90
}
and I have the second file pbcast_sim.tcl which has the following code :
# Script to study probabilistic broadcast in a grid network
# V.B., 2005
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 400 ;# default number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(sc) “./scenario” ;# scenario file
set val(x) 2500.0 ;
set val(y) 2500.0 ;
set val(simtime) 10.0 ; #sim time
set val(rlen) 20 ;
# ======================================================================
# Main Program
# ======================================================================
source “./p_bcast.tcl”
if { $argc != 2 } {
puts “Wrong no. of cmdline args.”
puts “Usage: ns pbcast_sim.tcl -prob
exit 0
}
proc getopt {argc argv} {
global val
lappend optlist prob
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != “-“} continue
set name [string range $arg 1 end]
set val($name) [lindex $argv [expr $i+1]]
}
}
getopt $argc $argv
#
# Initialize Global Variables
#
set ns_ [new Simulator]
set tracefd [open pbsim.tr w]
$ns_ trace-all $tracefd
set namtrace [open pbsim.nam w] ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$ns_ use-newtrace
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#
# Create God
#
set god_ [ create-god $val(nn) ]
$val(mac) set bandwidth_ 22.0e6
#
# Create the specified number of mobilenodes [$val(nn)] and “attach” them
# to the channel.
# configure node
$ns_ node-config -adhocRouting $val(rp)
-llType $val(ll)
-macType $val(mac)
-ifqType $val(ifq)
-ifqLen $val(ifqlen)
-antType $val(ant)
-propType $val(prop)
-phyType $val(netif)
-channelType $val(chan)
-topoInstance $topo
-agentTrace ON
-routerTrace OFF
-macTrace OFF
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
# Provide initial (X,Y, Z=0) co-ordinates for mobilenodes
#
set gridspace [expr $val(x) / $val(rlen)]
for {set i 0} {$i < $val(rlen) } {incr i} {
for {set j 0} {$j < $val(rlen) } {incr j} {
set a [expr $j + [expr $i * $val(rlen)]]
$node_($a) set X_ [expr 0.0 + [ expr $i * $gridspace]]
$node_($a) set Y_ [expr 0.0 + [ expr $j * $gridspace]]
$node_($i) set Z_ 0.0
}
}
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 20 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 20
set pbcast_($i) [new Agent/MessagePassing/MyPBCast]
$ns_ attach-agent $node_($i) $pbcast_($i)
$node_($i) attach $pbcast_($i) 90
$pbcast_($i) set agent_port_ 90
$pbcast_($i) setprob $val(prob)
}
# Tell nodes when the simulation ends
#
$ns_ at 0.0 “$pbcast_(210) send”
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(simtime) “$node_($i) reset”;
}
$ns_ at $val(simtime) “stop”
$ns_ at $val(simtime).01 “puts “NS EXITING…” ; $ns_ halt”
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
}
puts “Starting Simulation…”
$ns_ run
two files is related to each other and I do not know how could I run them and get the result. when I run them I got this message “Wrong no. of cmdline args.
Usage: ns pbcast_sim.tcl -prob
could anyone help me?
thanks
Try to run the script as follows :
#ns pbcast_sim.tcl -prob 50
or
ns pbcast_sim.tcl -prob 0.5
@CharlesPandian wrote:
Try to run the script as follows :
#ns pbcast_sim.tcl -prob 50
or
ns pbcast_sim.tcl -prob 0.5
thank you for your posting, I did this way, but I need to set probability dynamically at
simulation time according to the number of neighbors as I explained in previous topic.
thank you again for your efforts .