DSR source code analysis [reprint]

Source: Internet
Author: User
Dtin NS-2


Source code:

Not all flies in./DSR/directory are used by the NS-2. The routing agent is implemented as agent/dsragent.
Thus, the source codes include:

  • Dsragent. CC (h): DSR agent class. major State Machine handling routings. important variables; net_id, mac_id in ID type. (IP and MAC address), both of them are initialzied by TCL commands to set the initla valie, The commads are "ADDR" amd "mac_addr"
  • Hdr_sr.cc (h): Define hdr_sr class.
  • Request_table.cc (h)
  • Path. H (CC ):Path class. first, define struct ID, it has an unsigned long addr a Enum of id_type, and a time stamp T. and then in path class, Id [] is the key members of the path, and operator [] is defined to return an element of ID array. thus whenever the srpacket. route [N] will return to the reference of ID [N]. other member variables include cur_index, Len,
  • Srpacket. h: Just define srpacket class which enclose the hdr_sr as a full packet. the srpacket construct has two parameters, a normal packet and a SR (source route) header (a path variable ). the constructor of "path" class makes a path from the bits of an NS Source Route Header. and the other two variables of the SR packet are "DST" and "src" IP addresses.

Data Structure for Route

It is found that SRH-> ADDR and P. route are two different structures. SRH () is always along with the packet. However, when DSR agent has ed a packet, it will

       SRPacket p(packet, srh);

This generate a "P" which is frequently used by all other functions. remember P does not go along with the packet leaving DSR agent. before the packet was sent out of the agent, another statement will be used to update "SRH" inSendoutpacketwithroute

 p.route.fillSR(srh);

Also, the tap () entry is also generate a p for its use. However, another entry point of agent "xmitfailed" use SRH () directly.

Special TCL interface.

Unless other routing protocol, the ns-2.1b9a, has a special node type named as "srnodenew ". from those routines in the ns-lib.tcl. we can see that speical. also, there is a Tcl file in mobiloty/DSR. TCL is also related.

Simulator instproc create-node-instance args {
$self instvar routingAgent_
# DSR is a special case
if {$routingAgent_ == "DSR"} {
set nodeclass [$self set-dsr-nodetype]
} else {
set nodeclass Node/MobileNode
}
return [eval new $nodeclass $args]
}

Simulator instproc set-dsr-nodetype {} {
$self instvar wiredRouting_
set nodetype SRNodeNew
# MIP mobilenode
if [Simulator set mobile_ip_] {
set nodetype SRNodeNew/MIPMH
}
# basestation dsr node
if { [info exists wiredRouting_] && $wiredRouting_ == "ON"} {
set nodetype Node/MobileNode/BaseStationNode
}
return $nodetype
}

DSR signaling packets in brief:

  • Route-request. The packet itself is a Layer 3 packet with a unique destination address, but mac_broadcast (labeled in common header's next_hop ())
  • Route-reply: unicasting in both Layer 2 and 3.
  • Route-error. unicasting in both Layer 2 and 3. generated when tx_failure in lower layer.

Entry points for DSR agent:

  1. First, as normal, the Recv () function which means a packet with a address destine to this node or from upper-target.
  2. Xmitfailed (). This is the callback function when a MAC transmission failes. Based on this chance, route-error message generated
  3. Tap (). This is a hidden entry when you turn promiscuous on. Snooping the route and shorten the path.

Basic functions:

  • Recv (), The entry for a Receving packet. Depends on the IP address of the packet and the SR (source route) header, call different functions to handle it. Like the dimo-below:

    The route-reply, route-request messages need special handling routines written inHandlepacketreceipt () Funciton. Note that if the rrequest message reached the destination, the receiptent shoshould send a rreply message, this is done by a function namedReturnscroutetorequestor (P)Which is called inHandlepacketreceipt (). Otherwise, if the route-request and route-err
  • Or are not destined to us, for route-request, the functionHandlerouterequest ()Is called
  • Handlepacketreceipt (). A signaling reached its destination. There are two case:
    • If it is a route-request and "not processed", sends back a route-reply, Pkt "P" is forged in this function andReturnscroutetorequestor (P)
    • If it is a route-reply, call functiuonAcceptroutereply (P );
  • Handlerouterequest (): From the version 2.27, we see some unused codes but probably under develop for future versions. it nodes more close Mac-routing cooperation, such as neighbor identity (is_neighnor (), and channel status (air_time_free ()).
    Basically, this function has three branches:
    1. Already processed, checked by functionIgnorerouterequestp (P).
    2. Has a cached route, doneReplyfromroutecache (P), And "cached route" is enabled by the flagDsragent_reply_from_cache_on_propagating.
    3. Append myself in routeP. route. appendtopath (net_id );AndSendoutpacketwithroute (p, false );
  • Handleforwarding. Forward packet on to next host in source route and snooping as appropriate. so, a route-reply message is not treat as predictional. it is a normal packet with SR header and be snooped by this node. the snooping is enabled by the flag"Dsragent_snoop_source_routes".
    Handleforwarding is dcallin "handledefaultforwarding" for doing some simple operations for DSR rules. At last, the packet will be sentSendoutpacketwithroute
  • Sendoutpacketwithroute: The function is used as for send packets, take packet and send it out, packet must a have a route in it. return value is not very meaningful. if fresh is true then reset the path before using it, if fresh is false then our caller wants us use a path with the index set as it currently is. basically,
    • CEN header's failure callback functon and data are set
    • CEN header's next hop is set to ADDR of next-hop in DSR header. Address type are also set.
    • Move the pointer in SR header to the next (increase 1 ).

    Actually, the third operation is not valid in real DSR implementations. to undo this effect in error-handing, we 'd better find current IP address first and locate the position of this address in SR header. the other two operations are also invalid, because there are no common headers in a real packet. for the "next_hop ()" In common header, it is used by DSR only for those packets without valid SR header, referRecv ().

  • Returnscroutetorequestor (); This function
  • Xmitfailed (): When the common header-> xmit_failure _ point to a callback function, thus, when the packet cannot be delivered, the callback function is used, and finally will generate a route-error messages. there is always a pointer in the SR header curr (). (Refer Manet-IETF-DSR draft,There is no such a pointer in DSR source route option, but has"Segments left"Field to indicate how should nodes still to visit to reach the destination .). thus, an innovation needs to be done to re-interprete the "SRH-> cur_addr ()" as a index number of the position in the path where fail happens. so, when not all nodes along the path handle the SR header, we need find the IP address of the node from SRH. and set that index as cur_addr ();
  • Processbrokenrouteerror (P); This shoshould be another branch under the main Recv () entry. it gives what to do when a route error message is receoived or heard (snooped ). snoop means the message was sent to another node but it passes myself, so I heard it.
  • Tap (const packet * packet): This is another entry point for DSR. When dsragent_use_tap flag is true. The Mac is working in promiscuous mode and all overhearing packets will be processed if there is a SR header in it.

Other:
The longest route we can handle is defined in: Define max_sr_len 16 // longest source route we can handle

Possible reason for xmit_failure below IP layer:

  • ARP failure
  • Interface queue is full
  • MAC transmission failure (exceed the retry-limit)

DSR scheme options:
In the beginning of dsragent. CC, it define tuning bool selectors of some options like:



/*************** selectors ******************/
bool dsragent_snoop_forwarded_errors = true;
// give errors we forward to our cache?
bool dsragent_snoop_source_routes = true;
// should we snoop on any source routes we see?
bool dsragent_reply_only_to_first_rtreq = false;
// should we only respond to the first route request we receive from a host?
bool dsragent_propagate_last_error = true;
// should we take the data from the last route error msg sent to us
// and propagate it around on the next propagating route request we do?
// this is aka grat route error propagation
bool dsragent_send_grat_replies = true;
// should we send gratuitous replies to effect route shortening?
bool dsragent_salvage_with_cache = true;
// should we consult our cache for a route if we get a xmitfailure
// and salvage the packet using the route if possible
bool dsragent_use_tap = true;
// should we listen to a promiscuous tap?
bool dsragent_reply_from_cache_on_propagating = true;
// should we consult the route cache before propagating rt req's and
// answer if possible?
bool dsragent_ring_zero_search = true;
// should we send a non-propagating route request as the first action
// in each route discovery action?

// NOTE: to completely turn off replying from cache, you should
// set both dsragent_ring_zero_search and
// dsragent_reply_from_cache_on_propagating to false

bool dsragent_dont_salvage_bad_replies = true;
// if we have an xmit failure on a packet, and the packet contains a
// route reply, should we scan the reply to see if contains the dead link?
// if it does, we won't salvage the packet unless there's something aside
// from a reply in it (in which case we salvage, but cut out the rt reply)
bool dsragent_require_bi_routes = true;
// do we need to have bidirectional source routes?
// [XXX this flag doesn't control all the behaviors and code that assume
// bidirectional links -dam 5/14/98]

#if 0
bool lsnode_holdoff_rt_reply = true;
// if we have a cached route to reply to route_request with, should we
// hold off and not send it for a while?
bool lsnode_require_use = true;
// do we require ourselves to hear a route requestor use a route
// before we withold our route, or is merely hearing another (better)
// route reply enough?
#endif

About flow state:

It is also desirable to disable the flow state stuff. It make the DSR code messy. Flow State is not an orginal idea.

static const bool dsragent_enable_flowstate = false;
static const bool dsragent_prefer_default_flow = false;


About packet Salvage

It's unknown how to complete disable the packet retransmission in Layer 3. Even you change three expressions in dsragent. CC.

  1. Salvage_with_cache = false (from true)
  2. Salvage_max_request = 0 (from 1)
  3. Salvage_times = 0 (from 15)

The trace file still show that the routing agent sends a undeliverable packet again. See xmitfail () function. I guess, it is necessary to disable "God" also.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.