[ns] packet forwarding
Mubashir Rehmani
mshrehmani at gmail.com
Tue Mar 10 10:52:44 PDT 2009
Hi Gaurav Joshi
You need to work on the c++ files of ns2. Let me give you an example of aodv
protocol (its just an example to make you understand and you need to create
your own packet type in order to proceed). Suppose that you are in the
sendRequest() function of AODV. First they are filling the packets fields:
http://rp.lip6.fr/ns-doc/ns226-doc/html/aodv_8cc-source.htm
// Fill out the RREQ packet
// ch->uid() = 0;
ch->ptype() = PT_AODV;
ch->size() = IP_HDR_LEN + rq->size();
ch->iface() = -2;
ch->error() = 0;
ch->addr_type() = NS_AF_NONE;
ch->prev_hop_ = index; // AODV hack
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
// Fill up some more fields.
rq->rq_type = AODVTYPE_RREQ;
rq->rq_hop_count = 1;
rq->rq_bcast_id = bid++;
rq->rq_dst = dst;
rq->rq_dst_seqno = (rt ? rt->rt_seqno : 0);
rq->rq_src = index;
seqno += 2;
assert ((seqno%2) == 0);
rq->rq_src_seqno = seqno;
rq->rq_timestamp = CURRENT_TIME;
Scheduler::instance().schedule(target_, p, 0.);
and then this packet is received and the function recvRequest() is called.
In the recvRequest() you can manipulate all the fields of packet including
ttl and write your logic. For instance, you can decrease the ttl by one and
forward the packet to one of its neighbors.
I hope it helps.
Regards
2009/3/10 Gaurav Joshi <gaurav.84in at gmail.com>
> Dear Mubashir,
> thank you so much for your help. But do we have to set ttl in tcl script or
> in source code. also how do i change the dst and src address dynamically.
> Can you please give me a little more insight about it, or fwd me a link from
> where I can follow in detail.
>
> thanks again,
> Regards,
> Gaurav.
>
>
> On Tue, Mar 10, 2009 at 3:24 AM, Mubashir Rehmani <mshrehmani at gmail.com>wrote:
>
>> Hi Gaurav Joshi,
>>
>> To forward a packet to multi-hops, you need to first set the TTL value of
>> the packet and dst address. Let's suppose you set the TTL=5 and dst=Node 1.
>> Then you send this packet. This packet will be received by Node1. Node 1
>> then reduce the TTL-- and reassign the dst and forward the packet.
>>
>> To forward the packet, you don't need to call sendpkt function. Instead,
>> you need to schedule a packet.
>>
>> Scheduler::instance <http://rp.lip6.fr/ns-doc/ns226-doc/html/classScheduler.htm#SplaySchedulere0>().schedule <http://rp.lip6.fr/ns-doc/ns226-doc/html/classScheduler.htm#SplaySchedulera6>(target_ <http://rp.lip6.fr/ns-doc/ns226-doc/html/classConnector.htm#WRR__CBQueuep27>, p, delay);
>>
>>
>>
>> Hope it helps
>>
>> Regards
>> Mubashir Husain Rehmani
>> Lip6, UPMC, Paris, France
>> www-npa.lip6.fr/~rehmani <http://www-npa.lip6.fr/%7Erehmani>
>>
>> 2009/3/10 Gaurav Joshi <gaurav.84in at gmail.com>
>>
>>
>>> Hello all,
>>>
>>> Does anyone has an idea how to send a packet in multi-hops? This, I guess
>>> will include packet forwarding at the intermediate node.
>>> Please let me know it.
>>> Thanks a lot.
>>>
>>>
>>> --
>>> Warm regards,
>>> Gaurav Joshi
>>> +1-352-214-2527
>>>
>>
>>
>>
>> --
>> Mubashir Husain Rehmani
>>
>>
>>
>
>
> --
> Warm regards,
> Gaurav Joshi
> +1-352-214-2527
>
--
Mubashir Husain Rehmani
More information about the Ns-users
mailing list