- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- How to implement flooding for wired nodes (IP_BROADCAST usag
hi friends,
I am a beginner for ns2. I want to test flooding in wired nodes. I
went through the posts related to it but couldn’t find the solution.
There is a link related to this issue but there is no solution—>
http://mailman.isi.edu/pipermail/ns-users/2006-January/053762.html
There is a script in
~/ns-2.32/tcl/ex/flooding.tcl But this is only for front end tcl.
What I am looking is to send my own created packet and broadcast it first
then i want to improve it to send packet to ***selected neighbors***
To achieve this second phase first i want to test broadcasting .
I tried…! But I am getting the “no slot error” which I am posting here
along with frontend tcl and C++ source code for my new packet….
and another question is —>
is it possible to invoke user defined recv() method implicitly after calling
Connector::send()??
anybody please help how to solve this problem??
I am posting both C++ code and tcl code here..
I defined a new packet header here……
#ifndef BCAST_PKT_H_
#define BCAST_PKT_H_
#include
#define HDR_BCAST_PKT(p) hdr_bcast_pkt::access(p)
struct hdr_bcast_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_; }
inline static hdr_bcast_pkt* access(const Packet* p) {
return (hdr_bcast_pkt*)p->access(offset_);
}
};
#endif /*BCAST_PKT_H_*/
implementation of IP_BROADCAST—-
//not including include files here….
int hdr_bcast_pkt::offset_ ;
class MyAgent : public Agent{
public :
MyAgent();
protected :
int command(int argc,const char*const* argv);
private:
//int my_var1;
//double my_var2;
nsaddr_t ra_addr_;
void my_func(void);
void my_bcast(Packet *p);
void recv(Packet* pkt, Handler*);
};
static class bcastHeaderClass : public PacketHeaderClass {
public:
bcastHeaderClass() : PacketHeaderClass(“PacketHeader/bcast”,
sizeof(hdr_bcast_pkt)) {
bind_offset(&hdr_bcast_pkt::offset_);
}
} class_bcast_hdr;
static class MyAgentClass : public TclClass {
public :
MyAgentClass() : TclClass(“Agent/MyAgentOtcl”) {}
TclObject* create(int argc,const char*const* argv) {
return (new MyAgent()); //(nsaddr_t)Address::instance().str2addr(argv[4])
}
} class_my_agent;
MyAgent::MyAgent() : Agent(PT_bcast) { //nsaddr_t id
//bind(“my_var1_otcl”,&my_var1);
//bind(“my_var2_otcl”,&my_var2);
//ra_addr_ = id;
}
int MyAgent::command(int argc,const char*const* argv) {
if(argc == 2) {
if(strcmp(argv[1],”callmyfunc”) == 0) {
my_func();
return (TCL_OK);
}
if(strcmp(argv[1],”sendpkt”) == 0) {
Packet* newpkt = allocpkt();
//some packet configuration
my_bcast(newpkt);
//recv(newpkt,0);
return (TCL_OK);
}
}
return (Agent::command(argc,argv));
}
void MyAgent::my_func(void) {
Tcl& tcl = Tcl::instance();
tcl.eval(“puts “Message from my_func””);
//tcl.evalf(“puts ” my_var1= %d””,my_var1);
//tcl.evalf(“puts ” my_var2 = %f””,my_var2);
}
void MyAgent::my_bcast(Packet *p)
{
hdr_cmn* hdrcmn = HDR_CMN(p);
hdr_ip* iphdr = HDR_IP(p);
hdr_bcast_pkt* ph = HDR_BCAST_PKT(p);
//ph ->pkt_src_ = ra_addr_;
ph ->pkt_len_ = 64;
// set all the necessary things for the common header
hdrcmn ->size_ = IP_HDR_LEN + ph->pkt_len();
hdrcmn ->ptype_ = PT_bcast;
hdrcmn->next_hop_ = IP_BROADCAST;
hdrcmn->prev_hop_ = this->addr();
hdrcmn->direction() = hdr_cmn::DOWN;
hdrcmn ->size_ = IP_HDR_LEN + ph->pkt_len();
hdrcmn ->ptype_ = PT_bcast;
// setting the ip header
iphdr->saddr() = this->addr();
iphdr->sport() = 254; // 1-254
iphdr->daddr() = IP_BROADCAST;
iphdr->dport() = 254; // 1-254
iphdr->ttl() = 32;
//Scheduler::instance().schedule(target_, p, 0.0);
send(p,0);
Tcl& tcl = Tcl::instance();
tcl.eval(“puts “Message from my_bcast()””);
}
void MyAgent::recv(Packet* pkt, Handler*)
{
Tcl& tcl = Tcl::instance();
tcl.eval(“puts “1Message from recv()””);
hdr_cmn* hdrcmn = HDR_CMN(pkt); //Access the common header for the received
packet:
hdr_ip* hdrip = HDR_IP(pkt); // Access the IP header for the received
packet:
cout << "node " << this->addr() << "received from node " <<
hdrcmn->prev_hop_;
tcl.eval(“puts “2Message from recv()””);
}
Front end Tcl code :
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
set a0 [new Agent/MyAgentOtcl]
$ns attach-agent $n0 $a0
set a1 [new Agent/MyAgentOtcl]
$ns attach-agent $n1 $a1
#$ns connect $a0 $a1
#set myagent [new Agent/MyAgentOtcl]
$a0 set my_var1_otcl 2
$a0 set my_var2_otcl 3.14
$a0 callmyfunc
$a0 sendpkt
I am getting the error:
Message from my_func
— Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) —
_o12: no target for slot -1
_o12 type: Classifier/Hash/Dest
content dump:
classifier _o12
0 offset
0 shift
2147483647 mask
1 slots
slot 0: _o29 (Classifier/Port)
-1 default
Finished standard no-slot{} default handler
Regards
Siva Rupesh
I hope that, you need not implement your won version of flooding. Because, there is already there are tcl level examples for flooding under
ns-x.xxtclex directory.
There is also another flooding based routing agent available under
ns-x.xxdiffusion
Hi Charles,
Thank You for the response.
Yes, I had seen it.
But what I am trying is to create my own protocol. I am trying to implement DVMRP(Distance Vector Multicast Routing).
Ofcourse there is example tcl script in ~ns2.32/tcl/ex for multicasting.
But inorder to modify the packet and embed some info into it and to test it,
I think this script is not sufficient!
So I am trying create my own own packet and first test for broadcasting(RPF) and then try multicasting based on the info in the packet…
To do this I have to start writing in C++ and define the packet first right?
But I am not able send a packet to other node by using Connector::send() and not able to receive the packet using recv()!!
I have posted the C++ source code and the errors in the previous post..
Can you please tell how to send a packet to other node using these predefined methods? Am I doing anything wrong in the code or the front end tcl script???
Thank You
ssr