Hi all,
I want to measure the total transmission time from the src to the dst,so
i define the variable "e2e_txtime_sum_" to calculate the time in
loss-monitor.h,and bind it in loss-monitor.cc like this
:bind("e2e_txtime_sum_", &e2e_txtime_sum_);  then in loss-monitor.cc
/lossmonitor:recv() i define the variable e2e_txtime_sum_ as
"e2e_txtime_sum_ += ch->e2e_txtime();"where hdr_cmn* ch = HDR_CMN(pkt);
In packet.h i define the variable "e2e_txtime_" to measure the end to end tx
time for a packet in sec as below :
************************
double e2e_txtime_;
 inline double& e2e_txtime() {return e2e_txtime_;}
**************************
In ns-default.tcl,i set the default value for e2e_txtime_sum_:
Agent/LossMonitor set e2e_txtime_sum_ 0.0
Last i test whether the variable e2e_txtime_sum works,result is 0.0,which
indicating the variable is of no use,i wonder where the error is?Ang clues?
Thanks in advance!
Jiantao Zhou

test script:
**********
# ======================================================================
# Define options
# ======================================================================
set val(chan)       Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        CMUPriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(x)              2000  ;# X dimension of the topography
set val(y)              2000  ;# Y dimension of the topography
set val(ifqlen)         100            ;# max packet in ifq
set val(adhocRouting)  DSR
set val(nn)             3             ;# how many nodes are simulated
set val(cp)             "traffic"
set val(sc)             "topology"
set stop_           250.0           ;# simulation time

#Set the time after which the procedure (record) should be called again
set time_ 4.0
# =====================================================================
# Main Program
# ======================================================================
set val(seed) 1.0
set interv 0.01
set cbr_rate [expr 512.0*8.0/$interv]
set macDataRate 1000000.000000
if {$val(seed) > 0} {
 puts "Seeding Random number generator with $val(seed) \n"
 ns-random $val(seed)
}
# create simulator instance
set ns_  [new Simulator]
set conn_count      2
#Open the output files
#And initialize to zero the variables we'll use to compute averages
for {set i 0} {$i < $conn_count} {incr i} {
 set f_($i) [open out_($i).tr w]
 set avg_($i) 0.0
}
# setup topography object
set topo [new Topography]
# create trace object for ns and nam
$ns_ use-newtrace
set tracefd [open test.tr w]
set namtrace    [open test.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# define topology
$topo load_flatgrid $val(x) $val(y)
#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
#global node setting
set my_chan [new $val(chan)]
$ns_ node-config -adhocRouting $val(adhocRouting) \
                 -llType $val(ll) \
                 -macType $val(mac) \
                 -ifqType $val(ifq) \
                 -ifqLen $val(ifqlen) \
                 -antType $val(ant) \
                 -propType $val(prop) \
                 -phyType $val(netif) \
                 -channel $my_chan \
   -topoInstance $topo \
   -agentTrace ON \
                 -routerTrace ON \
                 -macTrace ON
#
#  Create the specified number of nodes [$val(nn)] and "attach" them
#  to the channel.
Mac/802_11 set dataRate_ $macDataRate
for {set i 0} {$i < $val(nn) } {incr i} {
 set node_($i) [$ns_ node]
 $node_($i) random-motion 0  ;# disable random motion
}
#
# Define node movement model
#
#puts "Loading connection pattern..."
source $val(cp)
#
# Define traffic model
#
#puts "Loading scenario file..."
source $val(sc)
#Define a procedure which periodically records the bandwidth received by the
#traffic sinks and writes it to trace files for plotting
proc record {} {
 global lossMonitor_ f_ conn_count avg_ time_ loss
 #Get an instance of the simulator
 set ns [Simulator instance]
 for {set i 0} {$i < $conn_count } {incr i} {
  set bw_($i) [$lossMonitor_($i) set bytes_]
 }
 #Get the current time
        set now [$ns now]
 #Calculate the bandwidth (in KBit/s) and write it to the files
 for {set i 0} {$i < $conn_count} {incr i} {
  set avg_($i) [expr $avg_($i) + $bw_($i)/$time_*8/1000]
  puts $f_($i) "$now [expr $bw_($i)/$time_*8/1000]"
 }
 #Reset the bytes_ values on the traffic sinks
 for {set i 0} {$i < $conn_count} {incr i} {
  $lossMonitor_($i) set bytes_ 0
 }
 #Re-schedule the procedure
        $ns at [expr $now+$time_] "record"
}
proc finish {} {
 global f_ avg_ conn_count stop_ time_ lossMonitor_ interv macDataRate val
node_
 #Close the output files
 for {set i 0} {$i < $conn_count} {incr i} {
  close $f_($i)
 }
set aggregate_tput 0.0
set sum_loss 0.0
set sum_npkts 0.0
set sum_rcvd 0.0
set txtime_sum 0.0
 for {set i 0} {$i < $conn_count } {incr i} {
  set avg_($i) [expr $avg_($i)/$stop_*$time_]
  set aggregate_tput [expr $aggregate_tput + $avg_($i)]
  set sum_loss [expr $sum_loss + [$lossMonitor_($i) set nlost_] ]
  set sum_npkts [expr $sum_npkts + [$lossMonitor_($i) set npkts_] ]
  set txtime_sum [expr $txtime_sum + [$lossMonitor_($i) set e2e_txtime_sum_]
]

 if {$sum_npkts == 0.0} {
  set loss_avg -1.0
  set avg_e2e_txtime -1.0
 } else {
  set loss_avg [expr 1.0 * $sum_loss/$sum_npkts]
  set avg_e2e_txtime [expr 1.0 * $txtime_sum/($sum_npkts - $sum_loss)]
 }
}

 set j 6
 set f_interv [format "%.*f" $j [expr (1.0/$interv)*512*8/1000000] ]
 set f_macDataRate [format "%.*f" $j [expr $macDataRate/1000000] ]
 set f_aggregate_tput [format "%.*f" $j $aggregate_tput]
 set f_loss_avg [format "%.*f" $j [expr 100.0 * $loss_avg] ]
 #set f_avg_e2e_txtime_msecs [format "%.*f" $j [expr 1000.0 *
$avg_e2e_txtime] ]
 puts "$f_interv $f_macDataRate $f_aggregate_tput $f_loss_avg
$f_avg_e2e_txtime_msecs "
       exit 0
}

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
    # 2 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) 10
}
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $stop_.0 "$node_($i) reset";
}
#$ns_ at  $stop_.0002 "puts \"NS EXITING...\""

##$ns_ halt
#puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
#puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
#puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"

#Start logging the received bandwidth
$ns_ at 0.0 "record"

$ns_ at $stop_.005 "finish"
#puts "Starting Simulation..."
$ns_ run



**********

Reply via email to