[How To] Implementing a New Unicast Routing Protocol for MANETs* in ns-2.34.. (With tcl file)

Hi Folks,

In this post I would tell u about how to successfully perform the steps to Implement a New Unicast Routing Protocol for MANETs by F. J. Ros and P. M. Ruiz While performing this task I faced a no. of problems. The tutorial by F. J. Ros and P. M. Ruiz is complete for a beginner to start working with. However it has certain anomalies (not in the code) such as typographical errors or case sensitivity problems. The tutorial is also designed for earlier versions of ns2. So I tried working on this tutorial which is quite excellent and and after facing a lot of problems and issues I successfully implemented it in ns-2.34.

If u perform the steps according to this post. U shall be able to implement the protocol succesfully. I shall not go into explaining the source code as it has already been beautifully explained in the original document. The source of  the document is given at the end of this post. Thus, for successfull implementation u should read this post very carefully.

NOTE: Beware of Case Sensitiveness and perform as I shall tell below.

Step 1) First of all create a directory in your ns-2.34 directory with the following files.

protoname_pkt.h
protoname_rtable.cc
protoname_rtable.h
Protoname.cc        \\ Note the capital P in the beginning (it should be capital P)
protoname.h

Step 2) The code for protoname_pkt.h is given below (u can copy paste)

#ifndef PROTONAME_PKT_H_
#define PROTONAME_PKT_H_

#include <packet.h>
#include <config.h>
#include <random.h>
#include <timer-handler.h>
#include <trace.h>
#include <classifier-port.h>

#define HDR_PROTONAME_PKT(p) hdr_protoname_pkt::access(p)

struct hdr_protoname_pkt {

nsaddr_t pkt_src_;       //Node which originated this packet
u_int16_t pkt_len_;    //Packet length (in bytes)
u_int8_t pkt_seq_num_; //Packet Sequence Number

inline nsaddr_t& pkt_src() {return pkt_src_;}
inline u_int16_t& pkt_len() {return pkt_len_;}
inline u_int8_t& pkt_seq_num() {return pkt_seq_num_;}

static int offset_;
inline static int& offset() {return offset_;}

// To access the hdr_protoname_pkt packet header in a packet pointed by p, we use the access fn
inline static hdr_protoname_pkt* access(const Packet* p) {
return (hdr_protoname_pkt*)p->access(offset_);
}
};

#endif /* PROTONAME_PKT_H_ */

Step 3) The code for protoname_rtable.cc is given below

#include "protoname_rtable.h"
#include "ip.h"

protoname_rtable::protoname_rtable() { }

void protoname_rtable::print(Trace* out) {
sprintf(out->pt_->buffer(), "p\tdest\tnext");
out->pt_->dump();
for (rtable_t::iterator it = rt_.begin(); it != rt_.end(); it++) {
sprintf(out->pt_->buffer(), "P\t%d\t%d", (*it).first, (*it).second);
out->pt_->dump();
}
}

void
protoname_rtable::clear() {
rt_.clear();
}

void
protoname_rtable::rm_entry(nsaddr_t dest) {
rt_.erase(dest);
}

void
protoname_rtable::add_entry(nsaddr_t dest, nsaddr_t next) {
rt_[dest] = next;
}

nsaddr_t
protoname_rtable::lookup(nsaddr_t dest) {
rtable_t::iterator it = rt_.find(dest);
if (it == rt_.end())
return IP_BROADCAST;
else
return (*it).second;
}

u_int32_t
protoname_rtable::size() {
return rt_.size();
}

Step 4) The code for protoname_rtable.h is given below

#ifndef PROTONAME_RTABLE_H_
#define PROTONAME_RTABLE_H_

#include <trace.h>
#include <map>
#include <ip.h>

typedef std::map<nsaddr_t, nsaddr_t> rtable_t;

class protoname_rtable {
rtable_t rt_;

public:
protoname_rtable();
void print(Trace*);
void clear();
void rm_entry(nsaddr_t);
void add_entry(nsaddr_t, nsaddr_t);
nsaddr_t lookup(nsaddr_t);
u_int32_t size();
};

#endif /* PROTONAME_RTABLE_H_ */

Step 5) The code for Protoname.cc is given below

#include "protoname.h"
#include "protoname_pkt.h"
#include "protoname_rtable.h"
#include <timer-handler.h>
#include <node.h>
#include <random.h>
#include <cmu-trace.h>
#include <iostream>
#include <classifier-port.h>
#include <packet.h>
#include <address.h>

// To Bind our packet in OTcl Interface
int hdr_protoname_pkt::offset_;
static class ProtonameHeaderClass : public PacketHeaderClass {
public:
ProtonameHeaderClass() : PacketHeaderClass("PacketHeader/PROTONAME", sizeof(hdr_protoname_pkt)) {
bind_offset(&hdr_protoname_pkt::offset_);
}
}class_rtProtoProtoname_hdr;

static class ProtonameClass : public TclClass
{
public:
ProtonameClass() : TclClass("Agent/PROTONAME") {}
TclObject* create(int argc, const char*const* argv) {
assert(argc==5);
return(new Protoname((nsaddr_t)Address::instance().str2addr(argv[4])));
}
}class_rtProtoProtoname;

void
Protoname_PktTimer::expire(Event* e) {
agent_->send_protoname_pkt();
agent_->reset_protoname_pkt_timer();
}

Protoname::Protoname(nsaddr_t id) : Agent(PT_PROTONAME), pkt_timer_(this) {
bind_bool("accessible_var_", &accessible_var_);
ra_addr_ = id;
}

int
Protoname::command(int argc, const char*const* argv) {
if(argc == 2) {
if (strcasecmp(argv[1], "start") == 0) {
pkt_timer_.resched(0.0);
return TCL_OK;
}
else if (strcasecmp(argv[1],"print_rtable") == 0) {
if(logtarget_ != 0) {
sprintf(logtarget_->pt_->buffer(), "P %f _%d_ Routing Table", CURRENT_TIME, ra_addr());
logtarget_->pt_->dump();
rtable_.print(logtarget_);
}
else {
fprintf(stdout, "%f _%d_ If you want to print this routing table ""you must create a trace file in your TCL Script",CURRENT_TIME, ra_addr());
}
return TCL_OK;
}
}
else if (argc == 3) {
//Obtains corresponding dmux to carry packets to upper layer
if (strcmp(argv[1], "port-dmux") == 0) {
dmux_ = (PortClassifier*)TclObject::lookup(argv[2]);
if (dmux_ == 0) {
fprintf(stderr, "%s: %s lookup of %s failed \n", __FILE__,argv[1],argv[2]);
return TCL_ERROR;
}
return TCL_OK;
}
//Obtains corresponding tracer
else if (strcmp(argv[1], "log-target") == 0 || strcmp(argv[1], "tracetarget") == 0) {
logtarget_ = (Trace*)TclObject::lookup(argv[2]);
if (logtarget_ == 0)
return TCL_ERROR;
return TCL_OK;
}
}
//Pass the command to the base class
return Agent::command(argc, argv);
}

void
Protoname::recv(Packet* p, Handler* h) {
struct hdr_cmn* ch    = HDR_CMN(p);
struct hdr_ip* ih     = HDR_IP(p);

if (ih->saddr() == ra_addr()){
//If there exists a routing loop, drop the packet
if(ch->num_forwards() > 0) {
drop(p, DROP_RTR_ROUTE_LOOP);
return;
}

//else if this is a packet I am originating, must add IP header
else if(ch->num_forwards() == 0)
ch->size() += IP_HDR_LEN;
}

// If it is a protoname packet, must process it
if(ch->ptype() == PT_PROTONAME)
recv_protoname_pkt(p);

//Otherwise, must forward the packet (unless TTL reaches zero
else {
ih->ttl_--;
if(ih->ttl_ == 0) {
drop(p, DROP_RTR_TTL);
return;
}
forward_data(p);
}
}

void
Protoname::recv_protoname_pkt(Packet* p) {
struct hdr_ip* ih                = HDR_IP(p);
struct hdr_protoname_pkt* ph    = HDR_PROTONAME_PKT(p);

// All routing messages are sent from and to port RT_PORT, so we shall check it
assert(ih->sport() == RT_PORT);
assert(ih->dport() == RT_PORT);

/* processing of protoname packet */

// Release resources
Packet::free(p);
}

void
Protoname::send_protoname_pkt() {
Packet* p                        = allocpkt();
struct hdr_cmn* ch                = HDR_CMN(p);
struct hdr_ip* ih                = HDR_IP(p);
struct hdr_protoname_pkt* ph     = HDR_PROTONAME_PKT(p);

ph->pkt_src()                     = ra_addr();
ph->pkt_len()                    = 7;
ph->pkt_seq_num()                = seq_num_++;

ch->ptype()                        = PT_PROTONAME;
ch->direction()                    = hdr_cmn::DOWN;
ch->size()                        = IP_HDR_LEN + ph->pkt_len();
ch->error()                        = 0;
ch->next_hop()                    = IP_BROADCAST;
ch->addr_type()                    = NS_AF_INET;

ih->saddr()                     = ra_addr();
ih->daddr()                        = IP_BROADCAST;
ih->sport()                        = RT_PORT;
ih->dport()                        = RT_PORT;
ih->ttl()                        = IP_DEF_TTL;

Scheduler::instance().schedule(target_, p, JITTER);
}

void
Protoname::reset_protoname_pkt_timer() {
pkt_timer_.resched((double)5.0);
}

void
Protoname::forward_data(Packet* p) {
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_ip* ih = HDR_IP(p);

if(ch->direction() == hdr_cmn::UP && ((u_int32_t)ih->daddr() == IP_BROADCAST || ih->daddr() == ra_addr())) {
dmux_->recv(p, NULL);
return;
}
else {
ch->direction() = hdr_cmn::DOWN;
ch->addr_type() = NS_AF_INET;
if ((u_int32_t)ih->daddr() == IP_BROADCAST)
ch->next_hop() = IP_BROADCAST;
else {
nsaddr_t next_hop = rtable_.lookup(ih->daddr());
if(next_hop == IP_BROADCAST) {
debug("%f: Agent %d can not forward a packet destined to %d \n", CURRENT_TIME,ra_addr(),ih->daddr());
drop(p, DROP_RTR_NO_ROUTE);
return;
}
else
ch->next_hop() =  next_hop;
}
Scheduler::instance().schedule(target_, p, 0.0);
}
}

Step 6) The code for protoname.h is given below

#ifndef PROTONAME_H_
#define PROTONAME_H_

#include "protoname_pkt.h"
#include "protoname_rtable.h"
#include <agent.h>
#include <packet.h>
#include <trace.h>
#include <timer-handler.h>
#include <random.h>
#include <classifier-port.h>
#include "arp.h"
#include "ll.h"
#include "mac.h"
#include "ip.h"
#include "delay.h"

#define CURRENT_TIME Scheduler::instance().clock()
#define JITTER (Random::uniform()*0.5)

class Protoname;    //Forward Declaration

/* TIMERS */

class Protoname_PktTimer : public TimerHandler {
public :
Protoname_PktTimer(Protoname* agent) : TimerHandler() {
agent_ = agent;
}
protected:
Protoname* agent_;
virtual void expire(Event* e);
};

/* Agent */
class Protoname : public Agent {
/* Friends */
friend class Protoname_PktTimer;

/*Private Members*/
nsaddr_t             ra_addr_;
//protoname_state     state_;
protoname_rtable     rtable_;
int                 accessible_var_;
u_int8_t             seq_num_;

protected :

PortClassifier*     dmux_;            //For Passing Packets Up To Agents
Trace*                logtarget_;        //For Logging
Protoname_PktTimer     pkt_timer_;        //Timer for sending packets

inline nsaddr_t&         ra_addr()             {return ra_addr_; }
//inline protoname_state& state()                {return state_;}
inline int&             accessible_var()     {return accessible_var_;}

void forward_data(Packet*);
void recv_protoname_pkt(Packet*);
void send_protoname_pkt();

void reset_protoname_pkt_timer();

public:
Protoname(nsaddr_t);
int command(int, const char*const*);
void recv(Packet*, Handler*);

};

#endif /* PROTONAME_H_ */

Note: Now we have to make changes to certain ns-2.34 files. The steps given below are most important for successful implementation so perform them very carefully.

Step 7) Open file packet.h under ns-2.34/common/packet.h. Do the changes given below.

Under typedef unsigned int packet_t; lots of constants would have been defined.

Go down and at Line 182 u will find

// AOMDV packet
static const packet_t PT_AOMDV = 61;

After it insert the line as follows

// insert new packet types here
static const packet_t    PT_PROTONAME = 62;

and change PT_NTYPE value from 62 (earlier) to 63 now.

static packet_t PT_NTYPE = 63; // This MUST be the LAST one

Then in the same file move down till u find p_info(). In it search for the function
static packetClass classify(packet_t type) {

and perform the following changes in it by entering the 2nd line below.

type == PT_AODV ||
type == PT_PROTONAME)
return ROUTING;

In the same file, go below and search for the function static void initName(). Now at the end of this function u shall find this

// AOMDV patch
name_[PT_AOMDV]= "AOMDV";

After this enter the following line.

name_[PT_PROTONAME] = "PROTONAME";
name_[PT_NTYPE]= "undefined"; // let it remain as it is

Step 8) Open the file cmu-trace.h under ns-2.34/trace/cmu-trace.h

At line 162 u shall find

void    format_aomdv(Packet *p, int offset);

After it enter the following line

void format_protoname(Packet *p, int offset);

Step 9) Now open the file cmu-trace.cc in the same folder ns-2.34/trace/cmu-trace.h

Include the following header file at the beginning.

#include <protoname/protoname_pkt.h>

Now at the end write the following code ( u can always copy-paste) 🙂

void
CMUTrace::format_protoname(Packet* p, int offset)
{
struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p);

if(pt_->tagged()) {
sprintf(pt_->buffer() + offset, “-PROTONAME:o %d -PROTONAME:s %d -PROTONAME:l %d”, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
else if (newtrace_) {
sprintf(pt_->buffer() + offset, “-P PROTONAME -Po %d -Ps %d -Pl %d “, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
else {
sprintf(pt_->buffer() + offset, “[PROTONAME %d %d %d] “, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
}

After the above steps search for the function (in the same file) at Line 1305 (most probably)

void CMUTrace::format(Packet* p, const char *why)

move down and after

case PT_PING:
break;

Enter the following lines

case PT_PROTONAME:
format_protoname(p, offset);
break;

Step 10) Open the file ns-packet.tcl under ns-2.34/tcl/lib/ns-packet.tcl

Search at Line 113 for
foreach prot {

Enter the following after to it to make it look like this

foreach prot {
PROTONAME
# Common:
Common
Flags
IP     # IP
# Routing Protocols:
NV     # NixVector classifier for stateless routing
....

Step 11) Open the file ns-default.tcl under ns-2.34/tcl/lib/ns-default.tcl

In the end of the file enter the following line

Agent/PROTONAME set accessible_var_ true

Step 12) Open the file ns-lib.tcl under ns-2.34/tcl/lib/ns-lib.tcl

Search at Line 604 for the function
Simulator instproc create-wireless-node args {

Go below and after

switch -exact $routingAgent_ {

Enter the following lines

PROTONAME {
set ragent [$self create-protoname-agent $node]
}

To make it look like this
switch -exact $routingAgent_ {
PROTONAME {
set ragent [$self create-protoname-agent $node]
}
DSDV {
set ragent [$self create-dsdv-agent $node]
}

Now in the same file go at last or end and enter the following lines

Simulator instproc create-protoname-agent { node } {
# Create Protoname Routing Agent
set ragent [new Agent/PROTONAME [$node node-addr]]
$self at 0.0 "$ragent start"
$node set ragent_ $ragent
return $ragent
}

Step 13) Open file priqueue.cc under ns-2.34/queue/priqueue.cc

Search for the function at Line 82.
PriQueue::recv(Packet *p, Handler *h)

After case PT_AOMDV: enter the following line

case PT_PROTONAME:

It should look like this

case PT_AOMDV:
case PT_PROTONAME:
recvHighPriority(p, h);
break;

Step 14) Now changes to be done in Makefile.in

Under INCLUDES add the following directory

-I./wpan \
-I./protoname

Under OBJ_CC do the following changes at the end.

protoname/Protoname.o protoname/protoname_rtable.o \
@V_STLOBJ@

Step 15) Now save your project and move to the command line Ctrl + Alt + T.

Browse to directory ns-2.34 under ns-allinone-2.34 directory.

Perform the following commands in order.

./configure

make clean

make depend // Optional

make

sudo make install

U shall get no errors. If you are getting any errors ask in the comments section.

Step 16) Now we have to make a tcl file to test the protocol.

In home directory. Create a tcl file with the name exproto.tcl. The contents of the tcl file are as follows (I have defined 6 nodes)

# 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) CMUPriQueue ;# 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) 6 ;# number of mobilenodes
set val(rp) PROTONAME ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

set ns [new Simulator]
set tracefd [open simple.tr w]
set namtrace [open simwrls.nam w]

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes
$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 ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } {
set n($i) [$ns node]
}

# Provide initial location of mobilenodes
$n(0) set X_ 100.0
$n(0) set Y_ 200.0
$n(0) set Z_ 0.0

$n(1) set X_ 200.0
$n(1) set Y_ 400.0
$n(1) set Z_ 0.0

$n(2) set X_ 500.0
$n(2) set Y_ 600.0
$n(2) set Z_ 0.0

$n(3) set X_ 400.0
$n(3) set Y_ 500.0
$n(3) set Z_ 0.0

$n(4) set X_ 700.0
$n(4) set Y_ 400.0
$n(4) set Z_ 0.0

$n(5) set X_ 500.0
$n(5) set Y_ 800.0
$n(5) set Z_ 0.0

# Set a TCP connection between n(1) and n(3)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(1) $tcp
$ns attach-agent $n(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 “$ftp start”

# Set a TCP connection between n(2) and n(4)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(2) $tcp
$ns attach-agent $n(4) $sink
$ns connect $tcp $sink

#defining heads
$ns at 0.0 “$n(0) label CH”
$ns at 0.0 “$n(1) label Source”
#$ns at 0.0 “$n(2) label N2”

$ns at 10.0 “$n(2) setdest 785.0 228.0 5.0”
$ns at 13.0 “$n(4) setdest 700.0 20.0 5.0”
$ns at 15.0 “$n(3) setdest 115.0 85.0 5.0”

#Color change while moving from one group to another
$ns at 73.0 “$n(2) delete-mark N2”
$ns at 73.0 “$n(2) add-mark N2 pink circle”
$ns at 124.0 “$n(1) delete-mark N11”
$ns at 124.0 “$n(1) add-mark N11 purple circle”
$ns at 103.0 “$n(5) delete-mark N5”
$ns at 103.0 “$n(5) add-mark N5 white circle”
$ns at 87.0 “$n(3) delete-mark N26”
$ns at 87.0 “$n(3) add-mark N26 yellow circle”
$ns at 92.0 “$n(0) delete-mark N14”
$ns at 92.0 “$n(0) add-mark N14 green circle”

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 20 defines the node size for nam
$ns initial_node_pos $n($i) 20
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) “$n($i) reset”;
}

# ending nam and the simulation
$ns at $val(stop) “$ns nam-end-wireless $val(stop)”
$ns at $val(stop) “stop”
$ns at 150.01 “puts \”end simulation\” ; $ns halt”
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam simwrls.nam &
}

$ns run

Save and close it.

Step 17) Now open terminal and type ns exproto.tcl

It shall run perfectly and nam should open.

The trace file should look as follows.

s 0.007102330 _0_ RTR  --- 0 PROTONAME 27 [0 0 0 0] ------- [0:255 -1:255 32 0] [PROTONAME 0 0 7]
r 0.008123076 _1_ RTR  --- 0 PROTONAME 27 [0 ffffffff 0 800] ------- [0:255 -1:255 32 0] [PROTONAME 0 0 7]
s 0.044061336 _1_ RTR  --- 1 PROTONAME 27 [0 0 0 0] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
r 0.045102081 _0_ RTR  --- 1 PROTONAME 27 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
r 0.045102081 _3_ RTR  --- 1 PROTONAME 27 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
...........
...........

Step 18) Now u have successfully implemented the unicast routing protocol for MANETs. U should not face any problems if you follow the above steps. However I have used Eclipse Galileo for the developing environment and prefer u to also use the same. Search my blog for configuring ns-2.34 with eclipse.

* Source – Implementing a New Manet Unicast Routing Protocol in NS2 by Francisco J. Ros, and Pedro M. Ruiz <download tutorial>

41 thoughts on “[How To] Implementing a New Unicast Routing Protocol for MANETs* in ns-2.34.. (With tcl file)

  1. anbumathi

    Thank u for giving this material. But after running ./configure command i get this error–
    configure: error: Installation of tclcl seems incomplete or can’t be found automatically.
    Please correct the problem by telling configure where tclcl is
    using the argument –with-tclcl=/path/to/package
    (perhaps after installing it),
    or the package is not required, disable it with –with-tclcl=no.

    Reply
    1. metagoth Post author

      have u successfully installed ns2 on your linux version. Try running configure from the ns-2.34 directory and if error comes please reinstall ns-2.34. Or u can configure using the command ./configure -with-tclcl = no

      Reply
  2. nageswararao

    Sir, thanks for sharing good file, but when i am running ./configure i am getting “no .configure file in the current directory” error and while running make commnd it s showing ” Makefile.in is newer than Makefile. you need to rerun configure”, can u plz suggest me what to do.

    Reply
  3. swarup

    trace/cmu-trace.cc:963: error: stray ‘\342’ in program
    trace/cmu-trace.cc:963: error: stray ‘\200’ in program
    trace/cmu-trace.cc:963: error: stray ‘\234’ in program
    trace/cmu-trace.cc:963: error: stray ‘\342’ in program
    trace/cmu-trace.cc:963: error: stray ‘\200’ in program
    trace/cmu-trace.cc:963: error: stray ‘\235’ in program
    trace/cmu-trace.cc:967: error: stray ‘\342’ in program
    trace/cmu-trace.cc:967: error: stray ‘\200’ in program
    trace/cmu-trace.cc:967: error: stray ‘\234’ in program
    trace/cmu-trace.cc:967: error: stray ‘\342’ in program
    trace/cmu-trace.cc:967: error: stray ‘\200’ in program
    trace/cmu-trace.cc:967: error: stray ‘\234’ in program
    trace/cmu-trace.cc:970: error: stray ‘\342’ in program
    trace/cmu-trace.cc:970: error: stray ‘\200’ in program
    trace/cmu-trace.cc:970: error: stray ‘\234’ in program
    trace/cmu-trace.cc:970: error: stray ‘\342’ in program
    trace/cmu-trace.cc:970: error: stray ‘\200’ in program
    trace/cmu-trace.cc:970: error: stray ‘\234’ in program
    trace/cmu-trace.cc: In member function ‘void CMUTrace::format_protoname(Packet*, int)’:
    trace/cmu-trace.cc:963: error: ‘protoname’ was not declared in this scope
    trace/cmu-trace.cc:967: error: ‘P’ was not declared in this scope
    trace/cmu-trace.cc:970: error: expected primary-expression before ‘[’ token
    trace/cmu-trace.cc:970: error: ‘protoname’ was not declared in this scope
    trace/cmu-trace.cc:970: error: ‘d’ was not declared in this scope
    make: *** [trace/cmu-trace.o] Error 1

    this error is occuring..please send the solution…thank you..

    Reply
      1. Mohamad

        It is the quotation (“…”) after copying and pasting the code in cmu-trace.cc
        Delete them and then re-insert them (if you insist to copy paste the code, a thing I never recommend while coding) and “make” should work fine…

  4. Arul Treesa Mathew

    common/packet.cc: In static member function ‘static int p_info::addPacket(char*)’:
    common/packet.cc:54:13: error: assignment of read-only variable ‘PT_NTYPE’
    make: *** [common/packet.o] Error 1

    this is the error i received when i gave the make command.. can u pls tell how to solve it??

    Reply
  5. vamsi

    i am getting an error like this
    (
    trace/cmu-trace.cc:39:37: fatal error: protoname/protoname_pkt.h: No such file or directory
    compilation terminated.
    make: *** [trace/cmu-trace.o] Error 1
    )
    how can i resolve this problem. Will any one can give a solution for that one?

    Reply
    1. metagoth Post author

      U need to create the protoname_pkt.h file in the same directory protoname. U should follow the steps as in ns2.34. Believe me u wont get any errors. The error you have is just a file not found kind of an error.

      Reply
  6. padman

    Create a folder named ‘protname’ in NS2.34 directory. In that protoname directory you have to add all five files named, protoname_pkt.h, protoname.h, Protoname.cc, protoname_rtable.h and another 1 more file. so that you will get rid of these error.

    Reply
  7. Anu

    Hello Sir, I’m getting the same error posted by Vamsi :
    trace/cmu-trace.cc:39:48: fatal error: protoname/protoname_pkt.h: No such file or directory
    compilation terminated.
    make: *** [trace/cmu-trace.o] Error 1

    i’ve included the protoname_pkt.h file in protoname folder, after doing that also while giving “make” command i’m getting the above error. Can you please help me to resolve this problem.

    Reply
  8. metagoth Post author

    after putiing all these files in the protoname directory and making all the changes given above.
    move to the n-2.34 directory in ns-allinone-2.34 folder.
    then type the following commands:

    sudo ./configure]
    sudo make depend
    sudo make clean
    make
    sudo make install
    All the files should run successfully. After that run your tcl file.

    Reply
  9. Syed Arshad

    @Anu & @vamsi, The problem is that there are non-ASCII characters in your trace/cmu-trace.cc file.

    Try the following code in your cmutrace.cc file:
    ———————————————————————————————————————
    // trace/cmu-trace.cc – after line 1514 by Arshad
    void CMUTrace::format_protoname(Packet* p, int offset)
    {
    struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p);

    if(pt_->tagged()){
    sprintf(pt_->buffer()+offset,”-PROTONAME:o %d -PROTONAME:s %d -PROTONAME:l %d”,ph->pkt_src(),ph->pkt_seq_num(),ph->pkt_len());
    }
    else if(newtrace_){
    sprintf(pt_->buffer()+offset,”-P PROTONAME -Po %d -Ps %d -Pl %d”,ph->pkt_src(),ph->pkt_seq_num(),ph->pkt_len());
    }
    else {
    sprintf(pt_->buffer()+offset,”[PROTONAME %d %d %d]”,ph->pkt_src(),ph->pkt_seq_num(),ph->pkt_len());
    }
    }

    Reply
    1. Syed Arshad

      If same problem persists, then the easiest fix is to delete all the stray quote [” “] (Quotation marks) in the above code and insert new ones.

      “-PROTONAME:o %d -PROTONAME:s %d -PROTONAME:l %d”

      “-P PROTONAME -Po %d -Ps %d -Pl %d”

      and

      “[PROTONAME %d %d %d]”

      If u replace the above 6 stray quotes and insert new ones it may work for you guys.

      Cheers.

      Reply
      1. Syed Arshad

        And you may encounter errors in the tcl file to test the protocol.

        Note: I have named the new tcl as [protoname_test.tcl] instead of [exproto.tcl] !

        ——————————————————————-
        arshad@Dell-Studio-15:~/ns2/ns-allinone-2.34/ns-2.34$ cd
        arshad@Dell-Studio-15:~$ cd new_proto/
        arshad@Dell-Studio-15:~/new_proto$ ns protoname_test.tcl
        num_nodes is set 6
        warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
        INITIALIZE THE LIST xListHead

        (_o5 cmd line 1)
        invoked from within
        “_o5 cmd at 10.0 “_o128 start””
        invoked from within
        “catch “$self cmd $args” ret”
        invoked from within
        “if [catch “$self cmd $args” ret] {
        set cls [$self info class]
        global errorInfo
        set savedInfo $errorInfo
        error “error when calling class $cls: $args” $…”
        (procedure “_o5” line 2)
        (SplitObject unknown line 2)
        invoked from within
        “_o5 at 10.0 “_o128 start””
        (“eval” body line 1)
        invoked from within
        “eval $scheduler_ at $args”
        (procedure “_o3” line 3)
        (Simulator at line 3)
        invoked from within
        “$ns at 10.0 “$ftp start””
        (file “protoname_test.tcl” line 86)

        ——————————————————————-

        The errors are due to the same reasons – STRAY QUOTES ” ”

        You have to search and replace all the stray quotes in the tcl.

  10. Arnab Das

    I got an error of “ns2.34/indep-utils/cmu-scan/”. I wrote the code as written but failed.So can anyone please help?

    Reply
  11. Santosh

    Hello Sir,
    Thanks for giving me use full information about how to routing protocol…….
    i need description / explanation of DSR source code in ns2…….

    Reply
  12. puteri

    hai. i get this error

    for d in /usr/local/man/man1; do \
    if [ ! -d $d ]; then \
    mkdir -p $d ;\
    fi;\
    done
    /usr/bin/install -c -m 755 ns /usr/local/bin
    /usr/bin/install: cannot stat `ns’: No such file or directory
    make: *** [install-ns] Error 1

    what is the solution ?

    Reply
  13. puteri

    and i get the same error like them…

    In file included from trace/cmu-trace.cc:40:0:
    ./protoname/protoname_pkt.h:32:8: error: unterminated comment
    trace/cmu-trace.cc:1522:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1522:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1522:1: error: stray ‘\234’ in program
    trace/cmu-trace.cc:1522:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1522:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1522:1: error: stray ‘\235’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\234’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1525:1: error: stray ‘\234’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\234’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\342’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\200’ in program
    trace/cmu-trace.cc:1528:1: error: stray ‘\234’ in program
    trace/cmu-trace.cc: In member function ‘void CMUTrace::format(Packet*, const char*)’:
    trace/cmu-trace.cc:1366:29: error: ‘format_protoname’ was not declared in this scope
    trace/cmu-trace.cc: At global scope:
    trace/cmu-trace.cc:1517:49: error: no ‘void CMUTrace::format_protoname(Packet*, int)’ member function declared in class ‘CMUTrace’
    make: *** [trace/cmu-trace.o] Error 1

    how ?

    Reply
  14. Amitha

    Hello Sir,
    Thank you for sharing this useful tutorial….
    But in the tcl file, I got the same error, even after replacing the quotes with new one…
    The error is given below..can you help me to rectify this?…(I’ve changed ‘protoname’ to ‘drina’).

    num_nodes is set 6
    warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl

    (_o14 cmd line 1)
    invoked from within
    “_o14 cmd addr”
    invoked from within
    “catch “$self cmd $args” ret”
    invoked from within
    “if [catch “$self cmd $args” ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error “error when calling class $cls: $args” $…”
    (procedure “_o14” line 2)
    (SplitObject unknown line 2)
    invoked from within
    “_o14 addr”
    (“eval” body line 1)
    invoked from within
    “eval $node addr $args”
    (“default” arm line 2)
    invoked from within
    “switch -exact $routingAgent_ {
    DRINA {
    set ragent [$self create-drina-agent $node]
    }
    DSDV {
    set ragent [$self create-dsdv-agent $node]
    }
    DSR {
    $self a…”
    (procedure “_o3” line 14)
    (Simulator create-wireless-node line 14)
    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”
    (“for” body line 2)
    invoked from within
    “for {set i 0} {$i < $val(nn) } { incr i } {
    set n($i) [$ns node]
    }"
    (file "drina.tcl" line 46)

    Reply
  15. Amitha M.D.

    SIr,
    Thank you for the response…
    My drina.tcl file is given below:
    …………………………………………….
    # 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) CMUPriQueue ;# 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) 6 ;# number of mobilenodes
    set val(rp) drina ;# routing protocol
    set val(x) 1000 ;# X dimension of topography
    set val(y) 1000 ;# Y dimension of topography
    set val(stop) 150 ;# time of simulation end

    set ns [new Simulator]
    set tracefd [open drina.tr w]
    set namtrace [open drina.nam w]

    $ns trace-all $tracefd
    $ns namtrace-all-wireless $namtrace $val(x) $val(y)

    # set up topography object
    set topo [new Topography]

    $topo load_flatgrid $val(x) $val(y)

    create-god $val(nn)

    # configure the nodes
    $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 ON \
    -macTrace OFF \
    -movementTrace ON

    for {set i 0} {$i < $val(nn) } { incr i } {
    set n($i) [$ns node]
    }

    # Provide initial location of mobilenodes
    $n(0) set X_ 100.0
    $n(0) set Y_ 200.0
    $n(0) set Z_ 0.0

    $n(1) set X_ 200.0
    $n(1) set Y_ 400.0
    $n(1) set Z_ 0.0

    $n(2) set X_ 500.0
    $n(2) set Y_ 600.0
    $n(2) set Z_ 0.0

    $n(3) set X_ 400.0
    $n(3) set Y_ 500.0
    $n(3) set Z_ 0.0

    $n(4) set X_ 700.0
    $n(4) set Y_ 400.0
    $n(4) set Z_ 0.0

    $n(5) set X_ 500.0
    $n(5) set Y_ 800.0
    $n(5) set Z_ 0.0

    # Set a TCP connection between n(1) and n(3)
    set tcp [new Agent/TCP/Newreno]
    $tcp set class_ 2
    set sink [new Agent/TCPSink]
    $ns attach-agent $n(1) $tcp
    $ns attach-agent $n(3) $sink
    $ns connect $tcp $sink
    set ftp [new Application/FTP]
    $ftp attach-agent $tcp
    $ns at 10.0 "$ftp start"

    # Set a TCP connection between n(2) and n(4)
    set tcp [new Agent/TCP/Newreno]
    $tcp set class_ 2
    set sink [new Agent/TCPSink]
    $ns attach-agent $n(2) $tcp
    $ns attach-agent $n(4) $sink
    $ns connect $tcp $sink

    #defining heads
    $ns at 0.0 "$n(0) label CH"
    $ns at 0.0 "$n(1) label Source"
    #$ns at 0.0 "$n(2) label N2"

    $ns at 10.0 "$n(2) setdest 785.0 228.0 5.0"
    $ns at 13.0 "$n(4) setdest 700.0 20.0 5.0"
    $ns at 15.0 "$n(3) setdest 115.0 85.0 5.0"

    #Color change while moving from one group to another
    $ns at 73.0 "$n(2) delete-mark N2"
    $ns at 73.0 "$n(2) add-mark N2 pink circle"
    $ns at 124.0 "$n(1) delete-mark N11"
    $ns at 124.0 "$n(1) add-mark N11 purple circle"
    $ns at 103.0 "$n(5) delete-mark N5"
    $ns at 103.0 "$n(5) add-mark N5 white circle"
    $ns at 87.0 "$n(3) delete-mark N26
    $ns at 87.0 "$n(3) add-mark N26 yellow circle"
    $ns at 92.0 "$n(0) delete-mark N14"
    $ns at 92.0 "$n(0) add-mark N14 green circle"

    # Define node initial position in nam
    for {set i 0} {$i < $val(nn)} { incr i } {
    # 20 defines the node size for nam
    $ns initial_node_pos $n($i) 20
    }

    # Telling nodes when the simulation ends
    for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$n($i) reset";
    }

    # ending nam and the simulation
    $ns at $val(stop) "$ns nam-end-wireless $val(stop)"
    $ns at $val(stop) "stop"
    $ns at 150.01 puts "\"end simulation\" ; $ns halt"
    proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
    exec nam drina.nam &
    }

    $ns run

    Reply
    1. metagoth Post author

      The TCL file has no problem. It becomes quite difficult to debug errors this way. There’s some problem in the create-wireless-node procedure. Hope that you have completed the changes made to files as i have given in the tutorial. And do a make clean and if any errors occur post them here

      Reply
  16. Amitha M.D.

    And one more thing sir, I am using ns2.35 version. But this blog is about ns2.34 na? So, is this version (2.35) make any problem?

    Reply
  17. Amitha M.D.

    I have done ‘make depend’ command…Now I got the error as

    emulate/net-pcap.cc:64:18: fatal error: pcap.h: No such file or directory
    compilation terminated.

    Reply
    1. AMitha M D

      Hello Maa’m,
      First of all I am thanking you for your valuable reply….
      Now I am stuck for 3 weeks with the following error….
      I couldn’t correct it…Also, I repeated the above procedure after installing ns2.35 multiple times.
      I don’t know what to do now.. I fear whether I can complete my thesis work..

      The error is…..

      (_o14 cmd line 1)
      invoked from within
      “_o14 cmd addr”
      invoked from within
      “catch “$self cmd $args” ret”
      invoked from within
      “if [catch “$self cmd $args” ret] {
      set cls [$self info class]
      global errorInfo
      set savedInfo $errorInfo
      error “error when calling class $cls: $args” $…”
      (procedure “_o14″ line 2)
      (SplitObject unknown line 2)
      invoked from within
      “_o14 addr”
      (“eval” body line 1)
      invoked from within
      “eval $node addr $args”
      (“default” arm line 2)
      invoked from within
      “switch -exact $routingAgent_ {
      DRINA {
      set ragent [$self create-drina-agent $node]
      }
      DSDV {
      set ragent [$self create-dsdv-agent $node]
      }
      DSR {
      $self a…”
      (procedure “_o3″ line 14)
      (Simulator create-wireless-node line 14)
      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”
      (“for” body line 2)
      invoked from within
      “for {set i 0} {$i < $val(nn) } { incr i } {
      set n($i) [$ns node]
      }"
      (file "drina.tcl" line 46)
      ===============================Plz help me======================

      Reply
  18. amithamd

    Thank you so much dear Mamatha…… The error shown while executing ‘make depend’ is cleared…but the the error is still there while executing TCL file as shown in my previous post..

    Reply
  19. sathya

    Sir,
    My tcl code runs fine but the problem is I am not able to the packets getting transferred in NAM.can u please help on this?

    Reply
  20. meritahoxha15

    hi.I want to add a new protocol in ns-2.35 but if i type make in terminal i get the error
    make***:No rule to make target ‘trace/cmu-trace.o’ needed by ‘ns’ Stop
    Thank you

    Reply
  21. yasmine

    Hello
    Now I am stuck with the following error….
    I couldn’t correct it… I use procedure after installing ns2.35 .
    I don’t know what to do now..
    The error is…..
    (_o14 cmd line 1)
    invoked from within
    “_o14 cmd addr”
    invoked from within
    “catch “$self cmd $args” ret”
    invoked from within
    “if [catch “$self cmd $args” ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error “error when calling class $cls: $args” $…”
    (procedure “_o14” line 2)
    (SplitObject unknown line 2)
    invoked from within
    “_o14 addr”
    (“eval” body line 1)
    invoked from within
    “eval $node addr $args”
    (“default” arm line 2)
    invoked from within
    “switch -exact $routingAgent_ {
    DSDV {
    set ragent [$self create-dsdv-agent $node]
    }
    DSR {
    $self at 0.0 “$node start-dsr”
    }
    AODV {
    set ragent [$self cre…”
    (procedure “_o3” line 14)
    (Simulator create-wireless-node line 14)
    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”
    (“for” body line 2)
    invoked from within
    “for {set i 0} {$i < $val(nn) } { incr i } {
    set n($i) [$ns node]
    }"
    (file "test.tcl" line 48)

    please help me

    Reply

Leave a comment