LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-25-2014, 02:55 AM   #1
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Rep: Reputation: Disabled
error : ns: record can not find firstPkttime_ no such variable


Hello friends

I tried a example in ns-2.34
How to get the system throughput without parsing the trace file? (For UDP-based application)
Code:
set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/TwoRayGround   ;# radio-propagationmodel
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)         1000                       ;# max packet in ifq
set val(nn)             5                          ;# number of mobilenodes
set val(rp)             DSDV                       ;# routing protocol
 
Mac/802_11 set RTSThreshold_          3000             ;# bytes
Mac/802_11 set ShortRetryLimit_       7               ;# retransmittions
Mac/802_11 set LongRetryLimit_        4               ;# retransmissions
Mac/802_11 set PreambleLength_        144             ;# 144 bit
Mac/802_11 set PLCPHeaderLength_      48              ;# 48 bits
Mac/802_11 set PLCPDataRate_  1Mb                         ;# 1Mbps
Mac/802_11 set dataRate_      1Mb
Mac/802_11 set basicRate_     1Mb
Mac/802_11 set CWMin_         31
Mac/802_11 set CWMax_         1023
Mac/802_11 set SlotTime_      0.000020        ;# 20us
Mac/802_11 set SIFS_          0.000010        ;# 10us
 
set ns_              [new Simulator]
 
set tracefd     [open simple.tr w]
$ns_ trace-all $tracefd
 
set nf [open out.nam w]
$ns_ namtrace-all-wireless $nf 300 300
 
set topo       [new Topography]
 
$topo load_flatgrid 300 300
 
create-god $val(nn)
set chan_1_ [new $val(chan)]
 
        $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) \
                         -channel $chan_1_ \
                         -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
        }
      
set  rng  [new RNG]
$rng seed 1
set  rand1  [new RandomVariable/Uniform]
 
for {set i 0} {$i < $val(nn) } {incr i} {
    puts "wireless node $i created ..."
    set x [expr 150+[$rand1 value]*4]
    set y [expr 150+[$rand1 value]*1]
    $node_($i) set X_ $x
    $node_($i) set Y_ $y
    $node_($i) set Z_ 0.0
    puts "X_:$x Y_:$y"
}
 
for {set i 0} {$i < $val(nn) } {incr i} {
    set udp_($i) [new Agent/UDP]
    $ns_ attach-agent $node_($i) $udp_($i)
    set null_($i) [new Agent/LossMonitor]
    $ns_ attach-agent $node_($i) $null_($i)
}
 
for {set i 0} {$i < $val(nn) } {incr i} {
    if {$i == ($val(nn)-1)} {
            $ns_ connect $udp_($i) $null_(0)
    } else {
            set j [expr $i+1]
            $ns_ connect $udp_($i) $null_($j)
    }
   
    set cbr_($i) [new Application/Traffic/CBR]
    $cbr_($i) attach-agent $udp_($i)
    $cbr_($i) set type_ CBR
    $cbr_($i) set packet_size_ 1000
    $cbr_($i) set rate_ 500kb
    $cbr_($i) set random_ false
}
 
for {set i 0} {$i < $val(nn) } {incr i} {   
    $ns_ at 1.0  "$cbr_($i) start"
    $ns_ at 50.0 "$cbr_($i) stop"
}
 
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 100.0 "$node_($i) reset";
}
 
$ns_ at 100.0 "stop"
$ns_ at 100.01 "puts \"NS EXITING...\" ; $ns_ halt"
 
$ns_ at 45.0 "record"
 
proc record {} {
        global ns_ null_ val
       set sum 0
            for {set i 0} {$i < $val(nn) } {incr i} {
                    set th 0
                    set a [$null_($i) set bytes_]
                    set b [$null_($i) set lastPktTime_]
                    set c [$null_($i) set firstPktTime_]
                    set d [$null_($i) set npkts_]
                    if {$b>$c} {
                           set th [expr ($a-$d*20)*8/($b-$c)]
                           puts "flow $i has $th bps"
            }
            set sum [expr $sum+$th]
    }
    puts "total throughput:$sum bps"
}
 
proc stop {} {
    global ns_  tracefd
    $ns_ flush-trace
    close $tracefd
}
 
puts "Starting Simulation..."
$ns_ run
I did these instructions before executing this program
Code:
1.      Modify the tools/loss-monitor.h
class LossMonitor : public Agent {
public:
        LossMonitor();
        virtual int command(int argc, const char*const* argv);
        virtual void recv(Packet* pkt, Handler*);
protected:
        int nlost_;
        int npkts_;
        int expected_;
        int bytes_;
        int seqno_;
        double last_packet_time_;
//add the following two lines
        double first_packet_time_;
        int first;
};
 
2.      Modify the tools/loss-monitor.cc
LossMonitor::LossMonitor() : Agent(PT_NTYPE)
{
        bytes_ = 0;
        nlost_ = 0;
        npkts_ = 0;
        expected_ = -1;
        last_packet_time_ = 0.;
        first_packet_time_ = 0.;
        first=0;
        seqno_ = 0;
        bind("nlost_", &nlost_);
        bind("npkts_", &npkts_);
        bind("bytes_", &bytes_);
        bind("lastPktTime_", &last_packet_time_);
        bind("firstPktTime_", &first_packet_time_);
        bind("expected_", &expected_);
}
 
void LossMonitor::recv(Packet* pkt, Handler*)
{
        hdr_rtp* p = hdr_rtp::access(pkt);
        seqno_ = p->seqno();
        bytes_ += hdr_cmn::access(pkt)->size();
        ++npkts_;
       
        if(first==0){
                first_packet_time_=Scheduler::instance().clock();
                first=1;
        }
        /*
         * Check for lost packets
         */
        if (expected_ >= 0) {
                int loss = seqno_ - expected_;
                if (loss > 0) {
                        nlost_ += loss;
                        Tcl::instance().evalf("%s log-loss", name());
                }
        }
        last_packet_time_ = Scheduler::instance().clock();
        expected_ = seqno_ + 1;
        Packet::free(pkt);
}
4. Recomplie NS2
cd ns-allinone-2.34/ns-2.34
make clean; make

but i am getting error
firstPktTime not found

please reply

If any one has a solution for this

Last edited by Aska123; 02-25-2014 at 01:53 PM.
 
Old 02-25-2014, 05:29 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
You now have 124 posts, and should know that code must be inside code tags
* http://www.linuxquestions.org/questi....php?do=bbcode
* http://www.linuxquestions.org/questi...gs-4175464257/
* I.e. code tags : The # button in the 'Advanced Editor'.
* Or : Type [/code] at code text end, and [code] at code start.
***** Post #1 must be edited to use code tags.


Quote:
3. Recomplie NS2 (If you are using ns-2.28)
cd ns-allinone-2.28/ns-2.28
make clean; make
4. Recomplie NS2
cd ns-allinone-2.34/ns-2.34
.
Some essential information is missing : What did you add ?
Like patch name ? Changes described in ??? A link please.
http://www.linuxquestions.org/linux/...Ask_a_Question
http://linuxsilo.net/docs/smart-questions_en.html

Where did you get the tcl code ?
What is ? : "set c [$null_($i) set firstPktTime_]" → → ? firstPktTime_ ?

-

Last edited by knudfl; 02-25-2014 at 05:31 AM.
 
Old 02-25-2014, 07:23 AM   #3
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
Sorry Kundfi
I was not aware of code tags.

I have re-compiled ns-2.34
after making changes to tools/loss-monitor.h

and tools/loss-monitor.cc

and tcl/ns-default.tcl

changes made by me are as follows

Code:
1. Modify the tools/loss-monitor.h
class LossMonitor : public Agent {
public:
LossMonitor();
virtual int command(int argc, const char*const* argv);
virtual void recv(Packet* pkt, Handler*);
protected:
int nlost_;
int npkts_;
int expected_;
int bytes_;
int seqno_;
double last_packet_time_;
//add the following two lines
double first_packet_time_;
int first;
};

2. Modify the tools/loss-monitor.cc
LossMonitor::LossMonitor() : Agent(PT_NTYPE)
{
bytes_ = 0;
nlost_ = 0;
npkts_ = 0;
expected_ = -1;
last_packet_time_ = 0.;
first_packet_time_ = 0.;
first=0;
seqno_ = 0;
bind("nlost_", &nlost_);
bind("npkts_", &npkts_);
bind("bytes_", &bytes_);
bind("lastPktTime_", &last_packet_time_);
bind("firstPktTime_", &first_packet_time_);
bind("expected_", &expected_);
}

void LossMonitor::recv(Packet* pkt, Handler*)
{
hdr_rtp* p = hdr_rtp::access(pkt);
seqno_ = p->seqno();
bytes_ += hdr_cmn::access(pkt)->size();
++npkts_;

if(first==0){
first_packet_time_=Scheduler::instance().clock();
first=1;
}
/*
* Check for lost packets
*/
if (expected_ >= 0) {
int loss = seqno_ - expected_;
if (loss > 0) {
nlost_ += loss;
Tcl::instance().evalf("%s log-loss", name());
}
}
last_packet_time_ = Scheduler::instance().clock();
expected_ = seqno_ + 1;
Packet::free(pkt);
}
3. Modify ns-default.tcl file
add
Agent/LossMonitor set firstPktTime_ 0
I took this example from
http://hpds.ee.ncku.edu.tw/~smallko/..._throghput.htm
 
Old 02-25-2014, 07:41 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Please edit post #1, to use code tags for the c++ code.

And please replace the "c++ text" with the real c++ code :
Looks like some indents are missing :
Code:
 public:

        LossMonitor();

        virtual int command(int argc, const char*const* argv);

        virtual void recv(Packet* pkt, Handler*);

protected:

        int nlost_;
I.e. you will have to use the indents shown in
http://hpds.ee.ncku.edu.tw/~smallko/..._throghput.htm
** Which line numbers were edited ?

Also : Please attach the edited files as :
`loss-monitor.h.txt' , loss-monitor.cc.txt ,
i.e. suffix .txt is a must : No .txt, and you cannot attach the file.

Attachments : That's the 'Paper clip' button.

-
 
Old 02-25-2014, 08:44 AM   #5
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
loss-monitor.h loss-monitor.cc and ns-default.tcl

ok

.cc file I saved as loss-monitor-cc.txt

It was showing invalid file for loss-monitor.cc.txt
Attached Files
File Type: txt loss-monitor.h.txt (2.4 KB, 15 views)
File Type: txt loss-monitor-cc.txt (3.7 KB, 16 views)
 
Old 02-25-2014, 08:50 AM   #6
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
ns-default.tcl and loss-monitor.cc

ns-default.tcl and loss-monitor.cc
Attached Files
File Type: txt ns-default.tcl.txt (54.4 KB, 19 views)
 
Old 02-25-2014, 10:02 AM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
#5, #6 , #1 .

I don't see any "2.34" in http://hpds.ee.ncku.edu.tw/~smallko/..._throghput.htm

And : You will still have to edit post #1 : All c++ code into code tags, please.


-

Last edited by knudfl; 02-25-2014 at 11:12 AM.
 
Old 02-25-2014, 11:25 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Testing with ns-2.28, your OK "test.tcl" from post #1 : No errors.
Code:
./ns-throughput 1test_UDP_trace.tcl 
num_nodes is set 5
INITIALIZE THE LIST xListHead
wireless node 0 created ...
X_:150.00135830880001 Y_:150.55588069999999
wireless node 1 created ...
X_:150.05681863999999 Y_:150.08812266999999
wireless node 2 created ...
X_:151.76469359999999 Y_:150.79915550000001
wireless node 3 created ...
X_:151.25184719999999 Y_:150.81647609999999
wireless node 4 created ...
X_:150.9384072 Y_:150.6388651
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 550.0
SORTING LISTS ...DONE!
flow 0 has 155383.0204194377 bps
flow 1 has 178659.06307888444 bps
flow 2 has 153833.50654319464 bps
flow 3 has 164968.86779817566 bps
flow 4 has 154617.6097945378 bps
total throughput:807462.06763423025 bps
NS EXITING...

The edited files, throughput-without-parsing-the-trace-file-ns228.tar.bz2 are attached.
-

Last edited by knudfl; 02-25-2014 at 11:31 AM.
 
Old 02-25-2014, 12:58 PM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
The test with ns-2.34 is equally OK. Same output as above from "test.tcl".

New files were created : throughput-without-parsing-the-trace-file-ns234.tar.bz2
https://drive.google.com/file/d/0B7S...it?usp=sharing

Using : 1)
cd ns-allinone-2.34/ && tar xvf throughput-without-parsing-the-trace-file-ns234.tar.bz2
2) ./install ( .. do a make clean in ns-2.34/ before ./install, if it's a remake.)
... ( My actual command was $ export CC=gcc41 CXX=g++41 && ./install ).


About your errors, ref. post #1 . ""firstPktTime_": no such variable " :
* There are some indents in your c++ files that are <space>'s instead of a <TAB>.
* And the comment in ns-default.tcl : "//<text>" , should instead be ";# added ..":
Like my line 1315 → Agent/LossMonitor set firstPktTime_ 0 ;# added ...

-

Last edited by knudfl; 02-25-2014 at 01:06 PM.
 
Old 02-25-2014, 01:45 PM   #10
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
Hello knudfi

I followed your steps.

1. cd ns-allinone-2.34/ && tar xvf throughput-without-parsing-the-trace-file-ns234.tar.bz2
2. make clean in ns-2.34
3. when I did $ export CC=gcc41 CXX=g++41 && ./install in ns-allinone-2.34

I got errors

configure: error: in `/home/ro/ns-allinone-2.34/tcl8.4.18/unix':
configure: error: C compiler cannot create executables
See `config.log' for more details.
tcl8.4.18 configuration failed! Exiting ...
Tcl is not part of the ns project. Please see www.Scriptics.com

Then in ns-allinone-2.34
I did sudo su
./install

installed successfully but again I am facing same error

Code:
ns: record: can't read "firstPktTime_": no such variable
    while executing
"subst $[subst $var]"
    (procedure "_o99" line 5)
    (Object next line 5)
    invoked from within
"_o99 next firstPktTime_"
    ("eval" body line 1)
    invoked from within
"eval $self next $args"
    (procedure "_o99" line 18)
    (Agent set line 18)
    invoked from within
"$null_($i) set firstPktTime_"
    (procedure "record" line 8)
    invoked from within
"record"

Last edited by Aska123; 02-25-2014 at 02:26 PM.
 
Old 02-25-2014, 02:14 PM   #11
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 10 .
Quote:
configure: error: C compiler cannot create executables
Well, a tool has to be present , before you can use it.

Which OS ? Please show the output from : $ uname -m <Enter>
... And also specify the OS name and version.
 
Old 02-25-2014, 02:34 PM   #12
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by knudfl View Post
#5, #6 , #1 .

I don't see any "2.34" in http://hpds.ee.ncku.edu.tw/~smallko/..._throghput.htm

-
there is no ns-2.34 in this post . I was trying to run it on ns-2.34.

because I have ns-2.34 installed on my system.
 
Old 02-25-2014, 02:36 PM   #13
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
My OS is ubuntu 10.0.4
command

$ uname -m <Enter>
gives
i686

Last edited by Aska123; 02-25-2014 at 02:41 PM.
 
Old 02-25-2014, 02:51 PM   #14
Aska123
Member
 
Registered: Apr 2013
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by knudfl View Post
The edited files, throughput-without-parsing-the-trace-file-ns228.tar.bz2 are attached.
-
This file is showing nothing
 
Old 02-25-2014, 03:09 PM   #15
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 14 .

HOWTO unpack an attached file name.tar.bz2.txt :
Code:
$ mv throughput-without-parsing-the-trace-file-ns228.tar.bz2.txt throughput-without-parsing-the-trace-file-ns228.tar.bz2
$ tar xvf throughput-without-parsing-the-trace-file-ns228.tar.bz2
I.e. you will have to remove .txt , to unpack the package.

.

Last edited by knudfl; 02-25-2014 at 03:10 PM.
 
1 members found this post helpful.
  


Reply

Tags
ns2, ns228, throughput-ns2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why directory record length is variable in ext2 filesystem? password636 Programming 7 01-11-2011 08:24 AM
[SOLVED] How to parse files with variable record length btacuso Programming 4 08-11-2010 11:49 AM
Find variable name by variable content using a subshell UltramaticOrange Programming 3 11-17-2008 04:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration