Hi,

I need to send message from node 1 to node 2 (such as "what is your actual
postion ") and the node
2 answer by a message reply.

If anyone have an idea about that please can you forward it to me because
I'm stuck!!

It will be a great help for me to advance in my project.

Thank you in advance and I'm sorry for the inconvenience.

srupesh wrote:
> 
> 
> hi ns users,
>                     I am trying to implement a modified DVMRP protocol
> (wired networks).  I want to access distance vector routing table  from my
> C++ code  so that i can embed my info
> in to my own packet. Can I use aleady implemented dvr in ns-2.32 to use in
> my own code? (by using rtPeer objects or
>                should  i write my own dvr starting from scratch??
> 
>                 I started my C++ part initially by creating an agent and
> packet header  to start  sending a single packet  from one node to another
> by using tcl script.
> But i couldn't send my own packet to a node. I used IP_BROADCAST (does
> wired
> networks support it??)
> 
>                  I am trying hard to find where I am goin wrong .I looked
> in
> to FAQS  and ns2 archives but couldn't  find a solution..
>                   Can anybody help me regarding how to figure out my
> problem??
> 
> I am submitting by trial code for sending a packet here (both C++ and tcl)
> 
> 
> *******packet header**********
> 
> #ifndef BCAST_PKT_H_
> #define BCAST_PKT_H_
> 
> #include <packet.h>
> #include <config.h>
> 
> #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_*/
> 
> 
> #include <tcl.h>
> #include <tclcl.h>
> 
> #include "bcast_pkt.h"
> #include <packet.h>
> #include <config.h>
> #include <address.h>
> #include <agent.h>
> #include  <classifier-port.h>
> #include  <classifier.h>
> #include <iostream>
> int hdr_bcast_pkt::offset_ ;
> class MyAgent : public Agent{
> public :
>     MyAgent();
> protected :
>     int command(int argc,const char*const* argv);
>     MyAgent *agent;
> 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
>             agent->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 +
> sizeof(hdr_bcast_pkt);//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->iface() = -2;
> //hdrcmn->error() = 0;
> 
> //hdrcmn ->ptype_                   = PT_bcast;           // ********my
> packet type**********   i defined it in common/packet.h  and
> tcl/lib/ns-packet.tcl..........
> // 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;
> Tcl& tcl = Tcl::instance();
> tcl.eval("puts \"Message from my_bcast()\"");
> Scheduler::instance().schedule(target_, p, 0.0);    //   ************* To
> send a packet   but i couldn't receive in recv function  or should i
> define
> any time handler  for this to work?? ***************
> //send(p,0);
> ///////***********I used in substitute for  the above  function but
> getting
> error "no slot default handler..."
> 
> }
> 
> 
> void MyAgent::recv(Packet* pkt, Handler*)
> {
>     struct hdr_cmn *ch = HDR_CMN(pkt);
>     struct hdr_ip *ih = HDR_IP(pkt);
>     struct hdr_bcast_pkt *bh = HDR_BCAST_PKT(pkt);
>     Tcl& tcl = Tcl::instance();
>     tcl.eval("puts \"1Message from recv()\"");
>     if(ch->ptype() == PT_bcast)
>     {
>         cout << "node " << this->addr() << "received from node " <<
> ch->prev_hop_;
>     }
> //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 " << ch->prev_hop_;
> 
>     tcl.eval("puts \"2Message from recv()\"");
> }
> 
> 
> tcl part..........###################
> ################################################
> 
> 
> 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    ######*******            for wired nodes i should
> connect every agent right????
> 
> #set  myagent [new Agent/MyAgentOtcl]
> $a0 set my_var1_otcl 2
> $a0 set my_var2_otcl 3.14
> 
> $a0 callmyfunc
> 
> $a0 sendpkt        #command to send a packet...
> 
> 
> Thanks
> Rupesh
> 
> 

-- 
View this message in context: 
http://www.nabble.com/sending-a-packet-to-a-node-tp16869248p25862408.html
Sent from the ns-users mailing list archive at Nabble.com.

Reply via email to