[ns] Help on routing protocol
Dheerendra Kulkarni
pcs02861@nitk.ac.in
Mon Jan 12 01:40:06 PST 2004
I am trying to implement a routing protocol at beginning I just want to
send and recieve a hello message. I am using the folllowing code below.'
make' completes without any errors. But when I try to set nodes in Tcl
Script the errors are shown. I am sending C code,Tcl and Errors please
verify and reply.
*************************************************
C CODE
*************************************************
#include<agent.h>
#include<scheduler.h>
#include<packet.h>
#include<ip.h>
struct hdr_antr
{
int src;
static int offset_;
inline static int& offset() { return offset_;}
inline static hdr_antr* access(const Packet *p)
{
return((hdr_antr*)p->access(offset_));
}
};
int hdr_antr::offset_;
class ANTR: public Agent
{
public:
ANTR();
void recv(Packet *p,Handler *);
void sendHello();
private:
int command(int,const char* const*);
};
static class ANTRHeaderClass:public PacketHeaderClass
{
public:
ANTRHeaderClass():PacketHeaderClass("PacketHeader/ANTR",sizeof(hdr_antr))
{
bind_offset(&hdr_antr::offset_);
}
}class_rtProtoANTR_hdr;
static class ANTRclass:public TclClass
{
public:
ANTRclass():TclClass("Agent/ANTR"){ }
TclObject * create(int argc, const char *const* argv)
{
return(new ANTR());
}
}class_rtProtoANTR;
ANTR::ANTR():Agent(PT_ANTR)
{
}
void ANTR::recv(Packet *p,Handler *)
{
struct hdr_cmn *ch=HDR_CMN(p);
struct hdr_ip *ih=HDR_IP(p);
if(ch->ptype()==PT_ANTR)
{
printf("Recived ANTR packet at\n");
}
}
int ANTR::command(int argc, const char *const *argv)
{
if (argc == 2)
{
if (strcmp(argv[1], "start") == 0)
{
printf("start command found\n");
sendHello();
return TCL_OK;
}
}
if(strcmp(argv[1],"target")==0)
{
TclObject *obj=0;
Tcl& tcl = Tcl::instance();
if( (obj = TclObject::lookup(argv[2])) == 0)
{
fprintf(stderr, "%s lookup failed\n", argv[1]);
return TCL_ERROR;
}
target_ = (NsObject*) obj;
if (target_ == 0)
{
tcl.resultf("no such object %s\n", argv[2]);
return (TCL_ERROR);
}
return (TCL_OK);
}
printf("Command not found in ANTR \n");
return Agent::command(argc,argv);
}
void ANTR::sendHello()
{
Packet *p=Packet::alloc();
struct hdr_cmn *ch HDR_CMN(p);
struct hdr_ip *ih=HDR_IP(p);
ch->ptype()=PT_ANTR;
ih->daddr()=IP_BROADCAST;
Scheduler::instance().schedule(target_,p,0.0);
}
*******************************************************
Tcl Script (Not completely)
*******************************************************
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) Queue/DropTail/PriQueue ;# 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) 10 ;# number of nodes
set val(rp) ANTR ;# routing protocol
set val(x) 800
set val(y) 800
# Initialize Global Variables
set ns_ [new Simulator]
set tracefd [open anm.tr w]
$ns_ trace-all $tracefd
set namtrace [open anm.nam w]
$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
create-god $val(nn)
# Create channel #1 and #2
set chan_1_ [new $val(chan)]
# Create node(0) "attached" to channel #1
# configure node
$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) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-energyModel "EnergyModel"\
-initialEnergy 1000\
-rxPower 0.4\
-txPower 0.7\
-channel $chan_1_
#-energyModel "EnergyModel"
# -initialEnergy (in Joules)
# -rxPower (in W)
# -txPower (in W)
# -idlePower (in W)
#
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0
$node_($i) radius 1000
}
puts "AFTER FOR LOOP"
More code is there but error is in the for loop above
************************************************************
Error Image
************************************************************
num_nodes is set 10
Command not found in ANTR
Command not found in ANTR
(_o17 cmd line 1)
invoked from within
"-o17 cmd tracetarget _o35"
invoked from within
"catch "$self cmd $args" ret"
(procedure "_o17" line 2)
(SplitObject unknown line 2)
invoked from within
"$ragent tracetarget $T"
(procedure "_o14" line 14)
(Node/MobileNode agenttrace line 14)
invoked from within
"$node agenttrace $tracefd"
(procedure "_o3" line 96)
(Simulator create-wireless-node line 96)
invoked from within
"_o3 create-wireless-node"
("eval" body line 1)
invoked from within
"eval $self create-wireless-node $args"
(procedure "_o3" line 14)
(Simulator node line 14)
invoked from within
"$ns_ node"
("for" body line 2)
invoked from within
"for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0
$node_($i) radius 1000
}"
(file "antr.tcl" line 67)
Now can somebody figure out what error I have done and help me in
continuing my project
--
Dheerendra Kulkarni
3rd Mtech CSE
NITK
Surathkal-525075
Karnataka
-----------------------------------------
This email was sent from NITK Surathkal
"Webmail "
http://krec.ac.in/
More information about the Ns-users
mailing list