Skip to main content

PyTorch Code for Simple Neural Networks for MNIST Dataset

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. He is right ....after the configure command try - sudo make install in ns2.35.
      then run your tcl file it will work.

      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
  25. Hi Sir,

    I want to collect packets at cluster head and forward it to mobile sink, how can I implement it. Please help

    ReplyDelete
  26. Hi sir i have mailed you the file sir.
    "Failed_shadow_error"

    ReplyDelete

Post a Comment

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it&#