please guide me

35 views
Skip to first unread message

Muhammad Rafid

unread,
May 28, 2022, 2:25:01 PM5/28/22
to Network Simulator 2 (NS2)
Can any one tell me the function of this common?
send (p, (Handler*) 0); 
with this in forward function in vanet, my forward function is that which is written below.
and also if the mention of RSU is correct or not.
===============================================================

void
VanetABCAgent::forward (Packet * )
{
   Packet *p = Packet::alloc();
u_int32_t id =10;
  nsaddr_t rsu1=id;
  nsaddr_t rsu2= id+1;
  nsaddr_t rsu3= id +2;
int interval_ =400;
 struct hdr_vanet_abc *hdr = HDR_VANET_ABC(p);

   // access the incoming packet
               
 
  struct hdr_cmn *ch = HDR_CMN (p);
  struct hdr_ip *iph = HDR_IP (p);
nsaddr_t nexthop;


   

hdr->abc_msgtype = VANETTYPE_JOINREQ;   // (necessary for dispatching!)
                                              // this can be read at reception in
  MobileNode *pnode = (MobileNode *) Node::get_node_by_address (index);
  pnode->update_position ();    // update the position, before using it
  hdr->abc_posx = pnode->X ();    // include current own location
  hdr->abc_posy = pnode->Y ();
  hdr->abc_speed = pnode->speed ();
  hdr->abc_dx = pnode->dX ();    // include current own location
  hdr->abc_dy = pnode->dY ();
 double x_S = hdr->abc_posx;
 double     y_S = hdr->abc_posy;
double dist = sqrt (pow ((x_S - 1000), 2) + pow ((y_S - 500), 2));
double dist1 = sqrt (pow ((x_S - 2000), 2) + pow ((y_S - 500), 2));
double dist2 = sqrt (pow ((x_S - 3000), 2) + pow ((y_S - 500), 2));




if (dist < interval_)
{
hdr->abc_receiverID =rsu1;
cout <<  "distf Iid: " << dist  << endl;
}
if (dist1 < interval_)
{
hdr->abc_receiverID =rsu1;
cout <<  "distf Id11: " << dist1  << endl;
}
if (dist2 < interval_)
{
hdr->abc_receiverID =rsu3;
cout <<  "distf Id22: " << dist2  << endl;
}
else {
 hdr->abc_receiverID =index;
}    
                                                     // hdrgen->vn_msgtype
                 
   
ch->prev_hop_ = index;
ch->iface() = -2;
ch->addr_type() = NS_AF_NONE;
ch->ptype () = PT_VANETABC;
ch->size() = IP_HDR_LEN + hdr->size();
iph->saddr() = index;
 iph->daddr() = IP_BROADCAST;
 iph->dport() = iph->sport();

   // IP_BROADCAST == rsu1;          


   hdr->abc_senderID = index;
//hdr->abc_receiverID = rsu1 ;
//hdr->abc_receiverID = rsu2;
//*/
hdr->appID=appID;
       //
// hdr->origSender=hdr1->origSender;
        hdr->abc_timestamp = Scheduler::instance().clock();
 hdr_cmn::access(p)->size() = hdr->size();


iph->ttl_=3;
JOIN_pkt_timer_.resched(1);
send(p, (Handler*) 0);

}

Muhammad Rafid

unread,
May 31, 2022, 4:14:08 AM5/31/22
to Network Simulator 2 (NS2)
 @kundl sir. I'm waiting for your precious response.

knudfl

unread,
May 31, 2022, 4:32:49 AM5/31/22
to Network Simulator 2 (NS2)
Hi.

Sorry, I do not write or understand C++ code.     Some Otcl only, as in ns2 simulations.

Charles Pandian

unread,
May 31, 2022, 6:18:45 AM5/31/22
to ns-u...@googlegroups.com
The line "send (p, (Handler*) 0);" will just send (broadcast) the packet that you built above. 

Charles Pandian,


--
You received this message because you are subscribed to the Google Groups "Network Simulator 2 (NS2)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-users/b64a44a6-db25-4857-8a05-6da77914a502n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages