Skip to main content

Creating a New Agent in Network Simulator 2

How to create a new agent in NS2. You can use any version of the Simulator. The following codes will make you to understand the writing of a sample agent.

Requirements:

  • NS2 Simulator
  • A tcl file to test the compiled agent

If any two values are supplied from the TCL file, the agent computes the Surface area of the Cylinder which is nothing but (2* PI * r * h).  The supplied values from TCL file are r and h.

How to do that.

1. Copy the newagent.cc (given below ) file in ~ns-allinone-2.34/ns-2.34/newfolder
2. Make an entry in the ~ns-2.34/Makefile.in
    Make an entry in the OBJ_CC =
            newfolder/newagent.o \
3. in the shell prompt, go to ~ns-2.34 and give the command
./configure
make
4. run the file agent_new.tcl (given below)
you can see the output

Here is the C++ code to be written and compiled

//Name of the file is newagent.cc and put it in a folder inside ~ns-2.34/newfolder/
#include <stdio.h>
#include <string.h>
#include "agent.h"
class TSPAgent : public Agent {
public:
        TSPAgent();
protected:
        int command(int argc, const char*const* argv);
private:
        int    tsp_var1;
        double tsp_var2;
        void   TSPPrivFunc(void);
};

static class TSPAgentClass : public TclClass {
public:
       TSPAgentClass() : TclClass("Agent/TSPAgentOtcl") {}
        TclObject* create(int, const char*const*) {
                return(new TSPAgent());
        }
} class_tsp_agent;

TSPAgent::TSPAgent() : Agent(PT_UDP) {
       bind("tsp_var1_otcl", &tsp_var1);
       bind("tsp_var2_otcl", &tsp_var2);
}
int TSPAgent::command(int argc, const char*const* argv) {
      if(argc == 2) {
           if(strcmp(argv[1], "call-tsp-priv-func") == 0) {
                  TSPPrivFunc();
                  return(TCL_OK);
           }
      }
     return(Agent::command(argc, argv));
}

void TSPAgent::TSPPrivFunc(void) {
      Tcl& tcl = Tcl::instance();
      tcl.eval("puts \"Message From TSPPrivFunc\"");
      tcl.evalf("puts \"     Area of the Cylinder is = %f\"", tsp_var1*tsp_var2*2*3.14);
}

TCL Code to Test the above C++ Program (Agent)

# Create MyAgent (This will give two warning messages that
set myagent [new Agent/TSPAgentOtcl]

# Set configurable parameters of MyAgent
$myagent set tsp_var1_otcl 2
$myagent set tsp_var2_otcl 6.5

# Give a command to MyAgent
$myagent call-tsp-priv-func

Comments

  1. Sir
    can you please tell me how to implement fuzzy logic rules and membership functions in network simulator2

    ReplyDelete
  2. Sir

    I am working in wireless sensor networks. Can you guide me about scenario generation in ns2.

    ReplyDelete
  3. I did not understand how ı will run the file agent_new.tcl

    ReplyDelete
  4. I created new agent Application i made appropriate changes in Makefile.in but still it is giving me error :

    invalid command name "Application/Test"
    while executing
    "Application/Test create _o59 _o10"
    invoked from within
    "catch "$className create $o $args" msg"
    invoked from within
    "if [catch "$className create $o $args" msg] {
    if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
    delete $o
    return ""

    ReplyDelete
  5. I am having same problem as posted above :( Please help

    ReplyDelete
  6. I am having same problem, i.e., "invalid command name". I am using ns2.35 with ubuntu. can anyone help me please

    ReplyDelete
    Replies
    1. show me the exact output or send me the files that you have used for recompilation

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. in terminal give like this
      ./configure
      make
      make install

      Delete
  7. Hello Pradeepkumar!!
    Below is the code and output.
    --------------------------------------------
    My exlinkage.cc file is:

    #include
    #include
    #include "agent.h"

    class MyAgent : public Agent {
    public:
    MyAgent();
    protected:
    int command(int argc, const char*const* argv);
    private:
    int my_var1;
    double my_var2;
    void MyPrivFunc(void);
    };


    static class MyAgentClass : public TclClass {
    public:
    MyAgentClass() : TclClass("Agent/MyAgentOtcl") {}
    TclObject* create(int, const char*const*) {
    return(new MyAgent());
    }
    } class_my_agent;

    MyAgent::MyAgent() : Agent(PT_UDP) {
    bind("my_var1_otcl", &my_var1);
    bind("my_var2_otcl", &my_var2);
    }

    int MyAgent::command(int argc, const char*const* argv) {
    if(argc == 2) {
    if(strcmp(argv[1], "call-my-priv-func") == 0) {
    MyPrivFunc();
    return(TCL_OK);
    }
    }
    return(Agent::command(argc, argv));
    }


    void MyAgent::MyPrivFunc(void) {
    Tcl& tcl = Tcl::instance();
    tcl.eval("puts \"Message From MyPrivFunc\"");
    tcl.evalf("puts \" my_var1 = %d\"", my_var1);
    tcl.evalf("puts \" my_var2 = %f\"", my_var2);
    }
    ----------------------------------------------------------

    The corresponding tcl file is, ex-linkage.tcl:

    set myagent [new ./Agent/MyAgentOtcl]

    # Set configurable parameters of MyAgent

    $myagent set my_var1_otcl 2

    $myagent set my_var2_otcl 3.14

    # Give a command to MyAgent

    $myagent call-my-priv-func
    ----------------------------------------------------------
    And the output after running is:

    ~/ns-allinone-2.35/ns-2.35/common$ ns ex-linkage.tcl
    invalid command name "./Agent/MyAgentOtcl"
    while executing
    "./Agent/MyAgentOtcl create _o3 "
    invoked from within
    "catch "$className create $o $args" msg"
    invoked from within
    "if [catch "$className create $o $args" msg] {
    if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
    delete $o
    return ""
    }
    global errorInfo
    error "class $..."
    (procedure "new" line 3)
    invoked from within
    "new ./Agent/MyAgentOtcl"
    invoked from within
    "set myagent [new ./Agent/MyAgentOtcl]"
    (file "ex-linkage.tcl" line 7)
    --------------------------------------------
    I saved the file in ns2.35/common and made the required changes in makefile.in.

    Thanks in advance
    --
    Bilal

    ReplyDelete
    Replies
    1. hi bilal,
      change the folloiwng line to
      set myagent [new ./Agent/MyAgentOtcl]
      this line
      set myagent [new Agent/MyAgentOtcl]

      Delete
    2. Thanks for your quick reply.
      but it still doesn't work.

      almost the same error

      ~/ns-allinone-2.35/ns-2.35/common$ ns ex-linkage.tcl
      invalid command name "Agent/MyAgentOtcl"
      while executing..

      Delete
    3. but it is executing in my machine. have you recompiled the .cc code. check for the .o file which was created from your .cc file.

      Delete
    4. Yes,I checked the .o in makefile.in, it is correct. I also executed configure and make commands. The problems is still there.
      I also used different directories to test my code. I saved .cc and .tcl files in ns-allinone-2.35/ns-2.35 but failed then i tried saving these files in ns-allinone-2.35/ns-2.35/common yet they didn't work.
      Any other reason for failure, like ubuntu version etc..??

      Delete
    5. Since the error is "failed shadow object" it means the object is not known to the tcl file. in the Makefile.in, in which variable you set the .o. you have to set the .o entry in the OBJ_CC varaible.

      Delete
    6. I put it under OBJ_CC. Here it is:


      OBJ_CC = \
      common/ex-linkage.o \

      Delete
    7. I had the same problem. I run only configure and make commands. But when i run make install it worked for me.

      Delete
  8. Dear sir,
    i have encountered the following error while trying to run a tcl script for wireless networks...


    num_nodes is set 25
    can't read "node_(0)": no such variable
    while executing
    "$node_($j) set X_ $k"
    ("for" body line 2)
    invoked from within
    "for {set j 0} {$j < 5 } {incr j} {
    $node_($j) set X_ $k
    $node_($j) set Y_ 5.0
    $node_($j) set Z_ 0.0
    incr k 10
    } "
    (file "test.tcl" line 60)


    this is the part of the code that is having the problem

    # Configure node position - assume static node
    set k 5
    for {set j 0} {$j < 5} {incr j} {
    $node_($j) set X_ $k
    $node_($j) set Y_ 5.0
    $node_($j) set Z_ 0.0
    incr k 10
    }
    set l 5
    for {set j 5} {$j < 10} {incr j} {
    $node_($j) set X_ $l
    $node_($j) set Y_ 15.0
    $node_($j) set Z_ 0.0
    incr l 10
    }
    set m 5
    for {set j 10} {$j < 15} {incr j} {
    $node_($j) set X_ $m
    $node_($j) set Y_ 25.0
    $node_($j) set Z_ 0.0
    incr m 10
    }
    set n 5
    for {set j 15} {$j < 20} {incr j} {
    $node_($j) set X_ $n
    $node_($j) set Y_ 35.0
    $node_($j) set Z_ 0.0
    incr n 10
    }
    set o 5
    for {set j 20} {$j < $val(nn)} {incr j} {
    $node_($j) set X_ $o
    $node_($j) set Y_ 45.0
    $node_($j) set Z_ 0.0
    incr o 10
    }
    for {set i 0} {$i < $val(nn) } {incr i} {
    $ns initial_node_pos $node_($i) 3

    }

    Sir, kindly help me rectify the problem...
    thanks for your time..
    thanks for your time

    ReplyDelete
    Replies
    1. this part of the code is correct, send me the code where you have created the node. the issue is there only. if you want to send, send it to tspembedded @ gmail dot com.

      Delete
    2. Sir kindly check your mail..i have sent the file..my email is eliza.maxwell17@gmail.com

      Delete
    3. Hey Liz, check your email for corrected code.

      Delete
  9. Hello everyone,

    Is there any means to access the port number of an agent? if I have an agent creation like the following
    MyAgentClass() : TclClass("Agent/MyAgentOtcl") {}
    TclObject* create(int, const char*const*) {
    return(new MyAgent());
    }
    How can I access the port number of this agent instance in c++?

    ReplyDelete
  10. hi, i try send a broadcast packet on new agent, but i dont made

    any idea


    tks

    Gabriel

    ReplyDelete
  11. sir ,do have any example daytimeserver kind of app code in c++ created and attached with the node and called from tcl??

    i.e .creating a sample application using c++ and calling from tcl??

    ReplyDelete
  12. i dont have a code like that, but it is possible to implement

    ReplyDelete
    Replies
    1. sir,

      because multimedia kind of apps r complex in nature & difficult to understand ,so like simple TSPAgent example,we need it for Application also.

      Delete
    2. i have code for Multimedia app also, which runs on UDP with five different rates of streaming....

      Delete
    3. sir

      Is it possible to implement cross layer approach like, i want to implement Tcp protocol above RTP protocol so that i can improve the performance of RTP ???

      Delete
  13. Sir,

    I am in need of cbrp implementation for ns2 . I have to make changes in the existing protocol implementation ,but i am not able to find cbrp patch for ns2 .Can you help or suggest any method how to implement cluster head election process in ns2 ?

    ReplyDelete
  14. Hi Sir
    I am doing my master project "Performance analysis for VoIP - User level" on NS2.
    I am looking for a VoIP code. kindly suggest me a simple voip topology..

    Thanks,
    Justin

    ReplyDelete
  15. I Created a new agent in ns2.35. While compiling tcl file im getting the following errors

    invalid command name "Mac/RRfid"
    while executing
    "Mac/RRfid create _o19 "
    invoked from within
    "catch "$className create $o $args" msg"
    invoked from within
    "if [catch "$className create $o $args" msg] {
    if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
    delete $o
    return ""
    }
    global errorInfo
    error "class $..."
    (procedure "new" line 3)
    invoked from within
    "new $mactype"
    (procedure "_o14" line 10)
    (Node/MobileNode add-interface line 10)
    invoked from within
    "$node add-interface $chan $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ $inerrProc_ $outerrProc_ $FECProc_"
    (procedure "_o3" line 83)
    (Simulator create-wireless-node line 83)
    invoked from within
    "_o3 create-wireless-node"
    ("eval" body line 1)
    invoked from within
    "eval $self create-wireless-node $args"
    (procedure "_o3" line 23)
    (Simulator node line 23)
    invoked from within
    "$ns node"
    invoked from within
    "set n(0) [$ns node]"

    Please tell some solution for this error. Thanks

    ReplyDelete
    Replies
    1. there is line Mac/RRfid, a new mac protocol wud have been developed and u need to compile ns2 first by including the above protocol and then u run the tcl file.

      Delete
    2. sir

      Actually my concept is to create a new agent that supports RFID concept. For that I have .cc and .h file for reader and tag (ie rfidragent.cc,rfidragent.h, rfidtagent.cc, rfidtagent.h) and also have rmac.cc, rmac.h ,tmac.cc, tmac.h and rfid_hdr.I have added that new mac protocol. Still im getting the same error.

      Delete
    3. actually __FAILED_SHADOW_OBJECT_" means either the name used in the TclClass("") is not matching with your tcl or during recompilation there was some error, if you can share ur code, you may send it to tspembedded @ gmail .com so that i will recompile and correct ur error.

      Delete
    4. sir
      i also got the same error.

      Delete
    5. Sir,

      I made the changes u told, still im getting the same error.

      Delete
  16. Sir

    I have mailed my coding to ur mail id. Thank you

    ReplyDelete
  17. sir i also have the same newagent creation error.
    failed_shadow_object

    ReplyDelete
  18. Sir,

    In my tcl file i mentioned my simulation time as 300 secs, while verifying trace file its generated only for 250 secs. How to clear this error? Thank you.

    ReplyDelete
  19. I am using ns-2.35. I have written the newagent.cc file as u have said and saved under ~ns-2.35/newfolder . But when i am trying to compile there is an error , agent.h not found. I saw that agent .h is in the folder common. I saved the newagent.cc file under common folder but still some header files included inside agent.h are not found while compilation. Please help to solve this problem.

    ReplyDelete
  20. hi
    please can you help me I want to add new AODV protocol with attack
    How can i do that in ns2??
    thanks

    ReplyDelete
  21. Dear Pradeep , This is Saravanan from TVMALAI. I have an error trying this agent. I Have created everything and while ./configure I am getting following error.
    checking minix/config.h presence... no
    checking for minix/config.h... no
    checking whether it is safe to define __EXTENSIONS__... yes
    No .configure file found in current directory
    Continuing with default options...
    checking build system type... i686-pc-linux-gnu
    checking host system type... i686-pc-linux-gnu
    checking target system type... i686-pc-linux-gnu
    checking for gcc... (cached) gcc
    checking whether we are using the GNU C compiler... (cached) yes
    checking whether gcc accepts -g... (cached) yes
    checking for gcc option to accept ISO C89... (cached) none needed
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking for ANSI C header files... (cached) yes
    checking for string.h... (cached) yes
    checking for main in -lXbsd... no
    checking for socket in -lsocket... no
    checking for gethostbyname in -lnsl... yes
    checking for dcgettext in -lintl... no
    checking for getnodebyname in -ldnet_stub... no
    checking that g++ can handle -O2... no
    checking if C++ libraries work without any namespace... no
    checking if C++ libraries work with namespace std... yes
    checking if STL works without any namespace... no
    checking if STL works with namespace std... yes
    checking should use STL... yes
    checking for tcl.h... -I../include
    checking for tclInt.h... -I../include
    checking for libtcl8.4... no
    checking for init.tcl... ../lib/tcl8.5
    checking for http.tcl... ../lib/tcl8.5/http1.0
    checking Tcl http.tcl library... yes
    checking for tclsh8.4.19... no
    checking for tclsh8.4... /usr/bin/tclsh8.4
    configure: error: Installation of tcl seems incomplete or can't be found automatically.
    Please correct the problem by telling configure where tcl is
    using the argument --with-tcl=/path/to/package
    (perhaps after installing it),
    or the package is not required, disable it with --with-tcl=no.
    sharan@ubuntu:~/ns-allinone-2.35/ns-2.35$ make
    Makefile.in is newer than Makefile.
    You need to re-run configure.
    false
    make: *** [Makefile] Error 1


    Let me know the solution. Please its urgent.
    Thanks in advance.

    ReplyDelete
    Replies
    1. did u installed ns2, if not install it.
      and then before giving the make command give this command ./configure

      Delete
    2. I installed ns2.35 as per ur direction and its working properly.

      Delete
    3. whether I need reinstall ns-2.35? But ns command working properly for tcl scripts.only problem with creating agents

      Delete
    4. while giving the ./configure command i am getting the following error
      configure: error: Installation of tcl seems incomplete or can't be found automatically.
      Please correct the problem by telling configure where tcl is
      using the argument --with-tcl=/path/to/package
      (perhaps after installing it),
      or the package is not required, disable it with --with-tcl=no.

      Delete
  22. 1. Instead of editing the makefile.in i done the correction directly in makefile and I succeeded. can u tell me the reason?

    2. I returned the result to tcl script but I could not get it. I listed the coding
    // xx.tcl
    set myobj [new Agent/ShVar]

    $myobj set x_ 5
    $myobj set y_ 10
    $myobj add
    set val(re) res_
    puts "$re"
    --------------------------------------------------------------------------------
    //xx.cc

    #include
    #include
    #include "agent.h"


    class ShAgent : public Agent
    {
    private:
    int x,y,res;
    void add();
    protected:
    int command(int argc, const char*const* argv);
    public:
    ShAgent();
    };


    ShAgent::ShAgent() : Agent(PT_UDP)
    {
    bind("x_", &x);
    bind("y_", &y);
    bind("res_", &res);
    }

    static class ShAgentClass: public TclClass
    {
    public:
    ShAgentClass():TclClass("Agent/ShVar") {}

    TclObject* create (int, const char*const*)
    {
    return (new ShAgent());
    }
    }Sh_obj;

    int ShAgent::command(int argc, const char*const* argv)
    { if(argc==2)
    {
    if(strcmp(argv[1] ,"add") ==0)
    {
    add();
    return (TCL_OK);
    }
    }
    return(Agent::command(argc, argv));
    }

    /* Your member function */
    void ShAgent::add()
    {
    Tcl& tcl = Tcl::instance();
    tcl.eval("puts \" \n From add() \"");
    res=x+y;
    //printf("\n x=%d y = %d x+y = %d\n", x,y,res);
    }
    -----------------------------------------------------------------
    // running tcl

    sharan@ubuntu:~/ns-allinone-2.35$ ns sh_test.tcl
    warning: no class variable Agent/ShVar::x_

    see tcl-object.tcl in tclcl for info about this warning.

    warning: no class variable Agent/ShVar::y_

    warning: no class variable Agent/ShVar::res_


    From add()
    can't read "re": no such variable
    while executing
    "puts $re"
    (file "sh_test.tcl" line 11)
    pls help me in this regard.

    regard P.Saravanan

    ReplyDelete
  23. hello sir
    when i modified in dsragent.cc file in ns 2.34 by using this code then create this type of error which in below

    modification code:

    void MDSRAgent::getRouteForPacket(SRPacket &p, bool retry)
    {
    Entry *e = request_table.getEntry(p.dest);
    Time time = Scheduler::instance().clock();
    if snooze==1&&recv.ACK==1
    SRPacket rrp = p;
    rrp.pkt = p.pkt->copy();
    hdr_sr *srh = hdr_sr::access(rrp.pkt);
    hdr_ip *iph = hdr_ip::access(rrp.pkt);
    hdr_cmn *cmh = hdr_cmn::access(rrp.pkt);
    iph>daddr()=Address::instance().create_ipaddr(p.dest.getNSAddr_t(),RT_PORT);
    iph->dport() = RT_PORT;
    iph>saddr()=Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);
    iph->sport() = RT_PORT;
    cmnh->ptype() = PT_DSR;
    cmnh->size() = size_;
    cmnh->num_forwards() = 0;
    }#endif

    void TcpBuS::RouteError(SRPacket& p)
    {
    hdr_sr *srh = hdr_sr::access(p.pkt);
    if (!srh->route_error())
    return;
    ID who = ID(srh->down_links()[srh->num_route_errors()-1].tell_addr, ::IP);
    if (who != net_id && who != MAC_id)
    {
    return;
    if (ch->num_forwards() > rt->rt_hops) {
    local_rt_repair(rt, p);
    {
    return = RERR_L;
    if(rt->rt_flags == RTF_UP) {
    assert(rt->rt_hops != INFINITY2);
    forward(rt, p, NO_DELAY);
    {
    return = RERR_S;
    }

    void MDSR::newack(Packet* pkt)
    {
    hdr_tcp *tcph = hdr_tcp::access(pkt);
    register int ackno = tcph->ackno();
    int progress = (ackno > highest_ack_);
    if (ackno == maxseq_) {
    cancel_rtx_timer(); // all data ACKd
    } else if (progress) {
    set_rtx_timer();
    }
    if (progress)
    highest_ack_ = ackno;
    if (t_seqno_ < highest_ack_)
    t_seqno_ = highest_ack_; // seq# to send next
    hdr_flags *fh = hdr_flags::access(pkt);
    iph>daddr()=Address::instance().create_ipaddr(p.dest.getNSAddr_t(),RT_PORT);
    iph->dport() = RT_PORT;
    iph>saddr()=Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);
    iph->sport() = RT_PORT;
    }

    when i add this code in this then we get error:

    dsr/dsragent.cc:357:17: error: expected type-specifier before ‘TcpBus’
    dsr/dsragent.cc:357:17: error: expected ‘)’ before ‘TcpBus’
    dsr/dsragent.cc:357:23: error: cannot convert ‘int*’ to ‘TclObject*’ in return
    dsr/dsragent.cc: In member function ‘void DSRAgent::getRouteForPacket(SRPacket&, bool)’:
    dsr/dsragent.cc:1489:5: error: ‘snooze’ was not declared in this scope
    dsr/dsragent.cc:1489:18: error: ‘recvack’ was not declared in this scope
    dsr/dsragent.cc:1530:3: error: ‘endif’ was not declared in this scope
    dsr/dsragent.cc:1532:3: error: expected ‘;’ before ‘srh’
    dsr/dsragent.cc:1519:11: warning: unused variable ‘srh’ [-Wunused-variable]
    dsr/dsragent.cc:1596:6: error: ‘TcpBuS’ has not been declared
    dsr/dsragent.cc:1597:1: error: a function-definition is not allowed here before ‘{’ token
    dsr/dsragent.cc:2852:1: error: expected ‘}’ at end of input
    dsr/dsragent.cc: In member function ‘virtual TclObject* TcpBusClass::create(int, const char* const*)’:
    dsr/dsragent.cc:358:3: warning: control reaches end of non-void function [-Wreturn-type]
    dsr/dsragent.cc: At global scope:
    dsr/dsragent.cc:95:12: warning: ‘dsr_salvage_max_attempts’ defined but not used [-Wunused-variable]
    make: *** [dsr/dsragent.o] Error 1

    ReplyDelete
  24. hello sir
    iwan to modified dsr.cc by using this code

    void MDSRAgent::getRouteForPacket(SRPacket &p, bool retry)
    {
    Entry *e = request_table.getEntry(p.dest);
    Time time = Scheduler::instance().clock();
    if snooze==1&&recv.ACK==1
    SRPacket rrp = p;
    rrp.pkt = p.pkt->copy();
    hdr_sr *srh = hdr_sr::access(rrp.pkt);
    hdr_ip *iph = hdr_ip::access(rrp.pkt);
    hdr_cmn *cmh = hdr_cmn::access(rrp.pkt);
    iph>daddr()=Address::instance().create_ipaddr(p.dest.getNSAddr_t(),RT_PORT);
    iph->dport() = RT_PORT;
    iph>saddr()=Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);
    iph->sport() = RT_PORT;
    cmnh->ptype() = PT_DSR;
    cmnh->size() = size_;
    cmnh->num_forwards() = 0;
    }#endif

    void TcpBuS::RouteError(SRPacket& p)
    {
    hdr_sr *srh = hdr_sr::access(p.pkt);
    if (!srh->route_error())
    return;
    ID who = ID(srh->down_links()[srh->num_route_errors()-1].tell_addr, ::IP);
    if (who != net_id && who != MAC_id)
    {
    return;
    if (ch->num_forwards() > rt->rt_hops) {
    local_rt_repair(rt, p);
    {
    return = RERR_L;
    if(rt->rt_flags == RTF_UP) {
    assert(rt->rt_hops != INFINITY2);
    forward(rt, p, NO_DELAY);
    {
    return = RERR_S;
    }

    void MDSR::newack(Packet* pkt)
    {
    hdr_tcp *tcph = hdr_tcp::access(pkt);
    register int ackno = tcph->ackno();
    int progress = (ackno > highest_ack_);
    if (ackno == maxseq_) {
    cancel_rtx_timer(); // all data ACKd
    } else if (progress) {
    set_rtx_timer();
    }
    if (progress)
    highest_ack_ = ackno;
    if (t_seqno_ < highest_ack_)
    t_seqno_ = highest_ack_; // seq# to send next
    hdr_flags *fh = hdr_flags::access(pkt);
    iph>daddr()=Address::instance().create_ipaddr(p.dest.getNSAddr_t(),RT_PORT);
    iph->dport() = RT_PORT;
    iph>saddr()=Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);
    iph->sport() = RT_PORT;
    }

    when i add this code in this then we get error

    dsr/dsragent.cc:357:17: error: expected type-specifier before ‘TcpBus’
    dsr/dsragent.cc:357:17: error: expected ‘)’ before ‘TcpBus’
    dsr/dsragent.cc:357:23: error: cannot convert ‘int*’ to ‘TclObject*’ in return
    dsr/dsragent.cc: In member function ‘void DSRAgent::getRouteForPacket(SRPacket&, bool)’:
    dsr/dsragent.cc:1489:5: error: ‘snooze’ was not declared in this scope
    dsr/dsragent.cc:1489:18: error: ‘recvack’ was not declared in this scope
    dsr/dsragent.cc:1530:3: error: ‘endif’ was not declared in this scope
    dsr/dsragent.cc:1532:3: error: expected ‘;’ before ‘srh’
    dsr/dsragent.cc:1519:11: warning: unused variable ‘srh’ [-Wunused-variable]
    dsr/dsragent.cc:1596:6: error: ‘TcpBuS’ has not been declared
    dsr/dsragent.cc:1597:1: error: a function-definition is not allowed here before ‘{’ token
    dsr/dsragent.cc:2852:1: error: expected ‘}’ at end of input
    dsr/dsragent.cc: In member function ‘virtual TclObject* TcpBusClass::create(int, const char* const*)’:
    dsr/dsragent.cc:358:3: warning: control reaches end of non-void function [-Wreturn-type]
    dsr/dsragent.cc: At global scope:
    dsr/dsragent.cc:95:12: warning: ‘dsr_salvage_max_attempts’ defined but not used [-Wunused-variable]
    make: *** [dsr/dsragent.o] Error 1

    ReplyDelete

Post a Comment

Popular posts from this blog

AWK Scripts for NS2 to process data from Trace Files

AWK Scripts are very good in processing the data from the log (trace files) which we get from NS2. If you want to process the trace file manually, here is the detailHere is a sample of trace file from NS2 (However ns2 supports a new type of trace file also), but this post will make you understand the old trace format only.r 0.030085562 _0_ MAC  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] r 0.030110562 _0_ RTR  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] s 1.119926192 _0_ RTR  --- 1 message 32 [0 0 0 0] ------- [0:255 -1:255 32 0]
AWK Scripts are very good in processing the data column wise. For example
the first column in the above trace file represents r, s which indicates receive, sent respectively. If we want to trace the entire r and s alone from this trace file we can represent it as $1
So
$1 represents ACTION
$2 Time
$3 Node ID
$4 Layer
$5 Flags
$6 seqno
$7 type
$8 Size
$14 Energy (if the network nodes includes EnergyModel)To run the awk script in Li…

nam installation - Segmentation Fault (Solved)

If you are encountering "Segmentation Fault" error while running nam in Ubuntu 14.04 or Linux Mint 17+ editions, this post will be helpful for you.

Download the nam file from this link

First, remove the nam which was installed earlier using the following command 

pradeep@localhost $] sudo apt-get remove nam

and install the new nam which was downloaded just now. go to the folder where the file was downloaded and issue the following command

pradeep@localhost $]  sudo dpkg --install nam_1.15-10_i386.deb

See the screenshot below to install and use nam

 T S Pradeep Kumar

Installation of ns2 in Ubuntu 18.04 - NS2 Tutorial # 2

ns2 installation in Ubuntu 18.04

Unlike earlier version of ubuntu, the 18,04 version does not support the direct installation of ns2, because of the latest C/C++ compiler (7.x), but the latest C/C++ compiler supported by ns2 is gcc-4.8. So this post and video tells you about the installation of gcc-4.8 version, then ns2 and then configuration.
Here are the steps, Please follow the video given below for more information.

$] tar zxvf ns-allinone-2.35.tar.gz


$] sudo apt install gcc-4.8 g++-4.8

if you have installed ubuntu just now, you can try these commands also in the beginning

$] sudo apt update
$] sudo apt install build-essential autoconf automake libxmu-dev

$] cd ns-allinone-2.35/ns-2.35
$] gedit Makefile.in
$] gedit linkstate/ls.h

line number 137, change erase to this->erase
$] cd ..
$] ./install

export PATH=$PATH:/home/pradeepkumar/ns-allinone-2.35/bin:/home/pradeepkumar/ns-allinone-2.35/tcl8.5.10/unix:/home/pradeepkumar/ns-allinone-2.35/tk8.5.10/unix
export LD_LIBRARY_PATH=$L…