From 67e0e1e5743e335a88b74c74518ee13e681b87de Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 2 Jul 2009 13:36:19 +0400 Subject: [PATCH 001/191] RFC added --- src/routing/aodv/rfc3561.txt | 2075 ++++++++++++++++++++++++++++++++++ 1 file changed, 2075 insertions(+) create mode 100644 src/routing/aodv/rfc3561.txt diff --git a/src/routing/aodv/rfc3561.txt b/src/routing/aodv/rfc3561.txt new file mode 100644 index 000000000..3b984ddb6 --- /dev/null +++ b/src/routing/aodv/rfc3561.txt @@ -0,0 +1,2075 @@ + + + + + + +Network Working Group C. Perkins +Request for Comments: 3561 Nokia Research Center +Category: Experimental E. Belding-Royer + University of California, Santa Barbara + S. Das + University of Cincinnati + July 2003 + + + Ad hoc On-Demand Distance Vector (AODV) Routing + +Status of this Memo + + This memo defines an Experimental Protocol for the Internet + community. It does not specify an Internet standard of any kind. + Discussion and suggestions for improvement are requested. + Distribution of this memo is unlimited. + +Copyright Notice + + Copyright (C) The Internet Society (2003). All Rights Reserved. + +Abstract + + The Ad hoc On-Demand Distance Vector (AODV) routing protocol is + intended for use by mobile nodes in an ad hoc network. It offers + quick adaptation to dynamic link conditions, low processing and + memory overhead, low network utilization, and determines unicast + routes to destinations within the ad hoc network. It uses + destination sequence numbers to ensure loop freedom at all times + (even in the face of anomalous delivery of routing control messages), + avoiding problems (such as "counting to infinity") associated with + classical distance vector protocols. + +Table of Contents + + 1. Introduction ............................................... 2 + 2. Overview .................................................. 3 + 3. AODV Terminology ........................................... 4 + 4. Applicability Statement .................................... 6 + 5. Message Formats ............................................ 7 + 5.1. Route Request (RREQ) Message Format ................... 7 + 5.2. Route Reply (RREP) Message Format ..................... 8 + 5.3. Route Error (RERR) Message Format ..................... 10 + 5.4. Route Reply Acknowledgment (RREP-ACK) Message Format .. 11 + 6. AODV Operation ............................................. 11 + 6.1. Maintaining Sequence Numbers .......................... 11 + 6.2. Route Table Entries and Precursor Lists ............... 13 + + + +Perkins, et. al. Experimental [Page 1] + +RFC 3561 AODV Routing July 2003 + + + 6.3. Generating Route Requests ............................. 14 + 6.4. Controlling Dissemination of Route Request Messages ... 15 + 6.5. Processing and Forwarding Route Requests .............. 16 + 6.6. Generating Route Replies .............................. 18 + 6.6.1. Route Reply Generation by the Destination ...... 18 + 6.6.2. Route Reply Generation by an Intermediate + Node ........................................... 19 + 6.6.3. Generating Gratuitous RREPs .................... 19 + 6.7. Receiving and Forwarding Route Replies ................ 20 + 6.8. Operation over Unidirectional Links ................... 21 + 6.9. Hello Messages ........................................ 22 + 6.10 Maintaining Local Connectivity ........................ 23 + 6.11 Route Error (RERR) Messages, Route Expiry and Route + Deletion .............................................. 24 + 6.12 Local Repair .......................................... 26 + 6.13 Actions After Reboot ................................. 27 + 6.14 Interfaces ............................................ 28 + 7. AODV and Aggregated Networks ............................... 28 + 8. Using AODV with Other Networks ............................. 29 + 9. Extensions ................................................. 30 + 9.1. Hello Interval Extension Format ....................... 30 + 10. Configuration Parameters ................................... 31 + 11. Security Considerations .................................... 33 + 12. IANA Considerations ........................................ 34 + 13. IPv6 Considerations ........................................ 34 + 14. Acknowledgments ............................................ 34 + 15. Normative References ....................................... 35 + 16. Informative References ..................................... 35 + 17. Authors' Addresses ......................................... 36 + 18. Full Copyright Statement ................................... 37 + +1. Introduction + + The Ad hoc On-Demand Distance Vector (AODV) algorithm enables + dynamic, self-starting, multihop routing between participating mobile + nodes wishing to establish and maintain an ad hoc network. AODV + allows mobile nodes to obtain routes quickly for new destinations, + and does not require nodes to maintain routes to destinations that + are not in active communication. AODV allows mobile nodes to respond + to link breakages and changes in network topology in a timely manner. + The operation of AODV is loop-free, and by avoiding the Bellman-Ford + "counting to infinity" problem offers quick convergence when the ad + hoc network topology changes (typically, when a node moves in the + network). When links break, AODV causes the affected set of nodes to + be notified so that they are able to invalidate the routes using the + lost link. + + + + + +Perkins, et. al. Experimental [Page 2] + +RFC 3561 AODV Routing July 2003 + + + One distinguishing feature of AODV is its use of a destination + sequence number for each route entry. The destination sequence + number is created by the destination to be included along with any + route information it sends to requesting nodes. Using destination + sequence numbers ensures loop freedom and is simple to program. + Given the choice between two routes to a destination, a requesting + node is required to select the one with the greatest sequence number. + +2. Overview + + Route Requests (RREQs), Route Replies (RREPs), and Route Errors + (RERRs) are the message types defined by AODV. These message types + are received via UDP, and normal IP header processing applies. So, + for instance, the requesting node is expected to use its IP address + as the Originator IP address for the messages. For broadcast + messages, the IP limited broadcast address (255.255.255.255) is used. + This means that such messages are not blindly forwarded. However, + AODV operation does require certain messages (e.g., RREQ) to be + disseminated widely, perhaps throughout the ad hoc network. The + range of dissemination of such RREQs is indicated by the TTL in the + IP header. Fragmentation is typically not required. + + As long as the endpoints of a communication connection have valid + routes to each other, AODV does not play any role. When a route to a + new destination is needed, the node broadcasts a RREQ to find a route + to the destination. A route can be determined when the RREQ reaches + either the destination itself, or an intermediate node with a 'fresh + enough' route to the destination. A 'fresh enough' route is a valid + route entry for the destination whose associated sequence number is + at least as great as that contained in the RREQ. The route is made + available by unicasting a RREP back to the origination of the RREQ. + Each node receiving the request caches a route back to the originator + of the request, so that the RREP can be unicast from the destination + along a path to that originator, or likewise from any intermediate + node that is able to satisfy the request. + + Nodes monitor the link status of next hops in active routes. When a + link break in an active route is detected, a RERR message is used to + notify other nodes that the loss of that link has occurred. The RERR + message indicates those destinations (possibly subnets) which are no + longer reachable by way of the broken link. In order to enable this + reporting mechanism, each node keeps a "precursor list", containing + the IP address for each its neighbors that are likely to use it as a + next hop towards each destination. The information in the precursor + lists is most easily acquired during the processing for generation of + a RREP message, which by definition has to be sent to a node in a + precursor list (see section 6.6). If the RREP has a nonzero prefix + + + + +Perkins, et. al. Experimental [Page 3] + +RFC 3561 AODV Routing July 2003 + + + length, then the originator of the RREQ which solicited the RREP + information is included among the precursors for the subnet route + (not specifically for the particular destination). + + A RREQ may also be received for a multicast IP address. In this + document, full processing for such messages is not specified. For + example, the originator of such a RREQ for a multicast IP address may + have to follow special rules. However, it is important to enable + correct multicast operation by intermediate nodes that are not + enabled as originating or destination nodes for IP multicast + addresses, and likewise are not equipped for any special multicast + protocol processing. For such multicast-unaware nodes, processing + for a multicast IP address as a destination IP address MUST be + carried out in the same way as for any other destination IP address. + + AODV is a routing protocol, and it deals with route table management. + Route table information must be kept even for short-lived routes, + such as are created to temporarily store reverse paths towards nodes + originating RREQs. AODV uses the following fields with each route + table entry: + + - Destination IP Address + - Destination Sequence Number + - Valid Destination Sequence Number flag + - Other state and routing flags (e.g., valid, invalid, repairable, + being repaired) + - Network Interface + - Hop Count (number of hops needed to reach destination) + - Next Hop + - List of Precursors (described in Section 6.2) + - Lifetime (expiration or deletion time of the route) + + Managing the sequence number is crucial to avoiding routing loops, + even when links break and a node is no longer reachable to supply its + own information about its sequence number. A destination becomes + unreachable when a link breaks or is deactivated. When these + conditions occur, the route is invalidated by operations involving + the sequence number and marking the route table entry state as + invalid. See section 6.1 for details. + +3. AODV Terminology + + This protocol specification uses conventional meanings [1] for + capitalized words such as MUST, SHOULD, etc., to indicate requirement + levels for various protocol features. This section defines other + terminology used with AODV that is not already defined in [3]. + + + + + +Perkins, et. al. Experimental [Page 4] + +RFC 3561 AODV Routing July 2003 + + + active route + + A route towards a destination that has a routing table entry + that is marked as valid. Only active routes can be used to + forward data packets. + + broadcast + + Broadcasting means transmitting to the IP Limited Broadcast + address, 255.255.255.255. A broadcast packet may not be + blindly forwarded, but broadcasting is useful to enable + dissemination of AODV messages throughout the ad hoc network. + + destination + + An IP address to which data packets are to be transmitted. + Same as "destination node". A node knows it is the destination + node for a typical data packet when its address appears in the + appropriate field of the IP header. Routes for destination + nodes are supplied by action of the AODV protocol, which + carries the IP address of the desired destination node in route + discovery messages. + + forwarding node + + A node that agrees to forward packets destined for another + node, by retransmitting them to a next hop that is closer to + the unicast destination along a path that has been set up using + routing control messages. + + forward route + + A route set up to send data packets from a node originating a + Route Discovery operation towards its desired destination. + + invalid route + + A route that has expired, denoted by a state of invalid in the + routing table entry. An invalid route is used to store + previously valid route information for an extended period of + time. An invalid route cannot be used to forward data packets, + but it can provide information useful for route repairs, and + also for future RREQ messages. + + + + + + + + +Perkins, et. al. Experimental [Page 5] + +RFC 3561 AODV Routing July 2003 + + + originating node + + A node that initiates an AODV route discovery message to be + processed and possibly retransmitted by other nodes in the ad + hoc network. For instance, the node initiating a Route + Discovery process and broadcasting the RREQ message is called + the originating node of the RREQ message. + + reverse route + + A route set up to forward a reply (RREP) packet back to the + originator from the destination or from an intermediate node + having a route to the destination. + + sequence number + + A monotonically increasing number maintained by each + originating node. In AODV routing protocol messages, it is + used by other nodes to determine the freshness of the + information contained from the originating node. + + valid route + + See active route. + +4. Applicability Statement + + The AODV routing protocol is designed for mobile ad hoc networks with + populations of tens to thousands of mobile nodes. AODV can handle + low, moderate, and relatively high mobility rates, as well as a + variety of data traffic levels. AODV is designed for use in networks + where the nodes can all trust each other, either by use of + preconfigured keys, or because it is known that there are no + malicious intruder nodes. AODV has been designed to reduce the + dissemination of control traffic and eliminate overhead on data + traffic, in order to improve scalability and performance. + + + + + + + + + + + + + + + +Perkins, et. al. Experimental [Page 6] + +RFC 3561 AODV Routing July 2003 + + +5. Message Formats + +5.1. Route Request (RREQ) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |J|R|G|D|U| Reserved | Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | RREQ ID | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + The format of the Route Request message is illustrated above, and + contains the following fields: + + Type 1 + + J Join flag; reserved for multicast. + + R Repair flag; reserved for multicast. + + G Gratuitous RREP flag; indicates whether a + gratuitous RREP should be unicast to the node + specified in the Destination IP Address field (see + sections 6.3, 6.6.3). + + D Destination only flag; indicates only the + destination may respond to this RREQ (see + section 6.5). + + U Unknown sequence number; indicates the destination + sequence number is unknown (see section 6.3). + + Reserved Sent as 0; ignored on reception. + + Hop Count The number of hops from the Originator IP Address + to the node handling the request. + + + + + + +Perkins, et. al. Experimental [Page 7] + +RFC 3561 AODV Routing July 2003 + + + RREQ ID A sequence number uniquely identifying the + particular RREQ when taken in conjunction with the + originating node's IP address. + + Destination IP Address + The IP address of the destination for which a route + is desired. + + Destination Sequence Number + The latest sequence number received in the past + by the originator for any route towards the + destination. + + Originator IP Address + The IP address of the node which originated the + Route Request. + + Originator Sequence Number + The current sequence number to be used in the route + entry pointing towards the originator of the route + request. + +5.2. Route Reply (RREP) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |R|A| Reserved |Prefix Sz| Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Lifetime | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + The format of the Route Reply message is illustrated above, and + contains the following fields: + + Type 2 + + R Repair flag; used for multicast. + + A Acknowledgment required; see sections 5.4 and 6.7. + + Reserved Sent as 0; ignored on reception. + + + +Perkins, et. al. Experimental [Page 8] + +RFC 3561 AODV Routing July 2003 + + + Prefix Size If nonzero, the 5-bit Prefix Size specifies that the + indicated next hop may be used for any nodes with + the same routing prefix (as defined by the Prefix + Size) as the requested destination. + + Hop Count The number of hops from the Originator IP Address + to the Destination IP Address. For multicast route + requests this indicates the number of hops to the + multicast tree member sending the RREP. + + Destination IP Address + The IP address of the destination for which a route + is supplied. + + Destination Sequence Number + The destination sequence number associated to the + route. + + Originator IP Address + The IP address of the node which originated the RREQ + for which the route is supplied. + + Lifetime The time in milliseconds for which nodes receiving + the RREP consider the route to be valid. + + Note that the Prefix Size allows a subnet router to supply a route + for every host in the subnet defined by the routing prefix, which is + determined by the IP address of the subnet router and the Prefix + Size. In order to make use of this feature, the subnet router has to + guarantee reachability to all the hosts sharing the indicated subnet + prefix. See section 7 for details. When the prefix size is nonzero, + any routing information (and precursor data) MUST be kept with + respect to the subnet route, not the individual destination IP + address on that subnet. + + The 'A' bit is used when the link over which the RREP message is sent + may be unreliable or unidirectional. When the RREP message contains + the 'A' bit set, the receiver of the RREP is expected to return a + RREP-ACK message. See section 6.8. + + + + + + + + + + + + +Perkins, et. al. Experimental [Page 9] + +RFC 3561 AODV Routing July 2003 + + +5.3. Route Error (RERR) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |N| Reserved | DestCount | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination IP Address (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination Sequence Number (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| + | Additional Unreachable Destination IP Addresses (if needed) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |Additional Unreachable Destination Sequence Numbers (if needed)| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + The format of the Route Error message is illustrated above, and + contains the following fields: + + Type 3 + + N No delete flag; set when a node has performed a local + repair of a link, and upstream nodes should not delete + the route. + + Reserved Sent as 0; ignored on reception. + + DestCount The number of unreachable destinations included in the + message; MUST be at least 1. + + Unreachable Destination IP Address + The IP address of the destination that has become + unreachable due to a link break. + + Unreachable Destination Sequence Number + The sequence number in the route table entry for + the destination listed in the previous Unreachable + Destination IP Address field. + + The RERR message is sent whenever a link break causes one or more + destinations to become unreachable from some of the node's neighbors. + See section 6.2 for information about how to maintain the appropriate + records for this determination, and section 6.11 for specification + about how to create the list of destinations. + + + + + + + +Perkins, et. al. Experimental [Page 10] + +RFC 3561 AODV Routing July 2003 + + +5.4. Route Reply Acknowledgment (RREP-ACK) Message Format + + The Route Reply Acknowledgment (RREP-ACK) message MUST be sent in + response to a RREP message with the 'A' bit set (see section 5.2). + This is typically done when there is danger of unidirectional links + preventing the completion of a Route Discovery cycle (see section + 6.8). + + 0 1 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + Type 4 + + Reserved Sent as 0; ignored on reception. + +6. AODV Operation + + This section describes the scenarios under which nodes generate Route + Request (RREQ), Route Reply (RREP) and Route Error (RERR) messages + for unicast communication towards a destination, and how the message + data are handled. In order to process the messages correctly, + certain state information has to be maintained in the route table + entries for the destinations of interest. + + All AODV messages are sent to port 654 using UDP. + +6.1. Maintaining Sequence Numbers + + Every route table entry at every node MUST include the latest + information available about the sequence number for the IP address of + the destination node for which the route table entry is maintained. + This sequence number is called the "destination sequence number". It + is updated whenever a node receives new (i.e., not stale) information + about the sequence number from RREQ, RREP, or RERR messages that may + be received related to that destination. AODV depends on each node + in the network to own and maintain its destination sequence number to + guarantee the loop-freedom of all routes towards that node. A + destination node increments its own sequence number in two + circumstances: + + - Immediately before a node originates a route discovery, it MUST + increment its own sequence number. This prevents conflicts with + previously established reverse routes towards the originator of a + RREQ. + + + + +Perkins, et. al. Experimental [Page 11] + +RFC 3561 AODV Routing July 2003 + + + - Immediately before a destination node originates a RREP in + response to a RREQ, it MUST update its own sequence number to the + maximum of its current sequence number and the destination + sequence number in the RREQ packet. + + When the destination increments its sequence number, it MUST do so by + treating the sequence number value as if it were an unsigned number. + To accomplish sequence number rollover, if the sequence number has + already been assigned to be the largest possible number representable + as a 32-bit unsigned integer (i.e., 4294967295), then when it is + incremented it will then have a value of zero (0). On the other + hand, if the sequence number currently has the value 2147483647, + which is the largest possible positive integer if 2's complement + arithmetic is in use with 32-bit integers, the next value will be + 2147483648, which is the most negative possible integer in the same + numbering system. The representation of negative numbers is not + relevant to the increment of AODV sequence numbers. This is in + contrast to the manner in which the result of comparing two AODV + sequence numbers is to be treated (see below). + + In order to ascertain that information about a destination is not + stale, the node compares its current numerical value for the sequence + number with that obtained from the incoming AODV message. This + comparison MUST be done using signed 32-bit arithmetic, this is + necessary to accomplish sequence number rollover. If the result of + subtracting the currently stored sequence number from the value of + the incoming sequence number is less than zero, then the information + related to that destination in the AODV message MUST be discarded, + since that information is stale compared to the node's currently + stored information. + + The only other circumstance in which a node may change the + destination sequence number in one of its route table entries is in + response to a lost or expired link to the next hop towards that + destination. The node determines which destinations use a particular + next hop by consulting its routing table. In this case, for each + destination that uses the next hop, the node increments the sequence + number and marks the route as invalid (see also sections 6.11, 6.12). + Whenever any fresh enough (i.e., containing a sequence number at + least equal to the recorded sequence number) routing information for + an affected destination is received by a node that has marked that + route table entry as invalid, the node SHOULD update its route table + information according to the information contained in the update. + + + + + + + + +Perkins, et. al. Experimental [Page 12] + +RFC 3561 AODV Routing July 2003 + + + A node may change the sequence number in the routing table entry of a + destination only if: + + - it is itself the destination node, and offers a new route to + itself, or + + - it receives an AODV message with new information about the + sequence number for a destination node, or + + - the path towards the destination node expires or breaks. + +6.2. Route Table Entries and Precursor Lists + + When a node receives an AODV control packet from a neighbor, or + creates or updates a route for a particular destination or subnet, it + checks its route table for an entry for the destination. In the + event that there is no corresponding entry for that destination, an + entry is created. The sequence number is either determined from the + information contained in the control packet, or else the valid + sequence number field is set to false. The route is only updated if + the new sequence number is either + + (i) higher than the destination sequence number in the route + table, or + + (ii) the sequence numbers are equal, but the hop count (of the + new information) plus one, is smaller than the existing hop + count in the routing table, or + + (iii) the sequence number is unknown. + + The Lifetime field of the routing table entry is either determined + from the control packet, or it is initialized to + ACTIVE_ROUTE_TIMEOUT. This route may now be used to send any queued + data packets and fulfills any outstanding route requests. + + Each time a route is used to forward a data packet, its Active Route + Lifetime field of the source, destination and the next hop on the + path to the destination is updated to be no less than the current + time plus ACTIVE_ROUTE_TIMEOUT. Since the route between each + originator and destination pair is expected to be symmetric, the + Active Route Lifetime for the previous hop, along the reverse path + back to the IP source, is also updated to be no less than the current + time plus ACTIVE_ROUTE_TIMEOUT. The lifetime for an Active Route is + updated each time the route is used regardless of whether the + destination is a single node or a subnet. + + + + + +Perkins, et. al. Experimental [Page 13] + +RFC 3561 AODV Routing July 2003 + + + For each valid route maintained by a node as a routing table entry, + the node also maintains a list of precursors that may be forwarding + packets on this route. These precursors will receive notifications + from the node in the event of detection of the loss of the next hop + link. The list of precursors in a routing table entry contains those + neighboring nodes to which a route reply was generated or forwarded. + +6.3. Generating Route Requests + + A node disseminates a RREQ when it determines that it needs a route + to a destination and does not have one available. This can happen if + the destination is previously unknown to the node, or if a previously + valid route to the destination expires or is marked as invalid. The + Destination Sequence Number field in the RREQ message is the last + known destination sequence number for this destination and is copied + from the Destination Sequence Number field in the routing table. If + no sequence number is known, the unknown sequence number flag MUST be + set. The Originator Sequence Number in the RREQ message is the + node's own sequence number, which is incremented prior to insertion + in a RREQ. The RREQ ID field is incremented by one from the last + RREQ ID used by the current node. Each node maintains only one RREQ + ID. The Hop Count field is set to zero. + + Before broadcasting the RREQ, the originating node buffers the RREQ + ID and the Originator IP address (its own address) of the RREQ for + PATH_DISCOVERY_TIME. In this way, when the node receives the packet + again from its neighbors, it will not reprocess and re-forward the + packet. + + An originating node often expects to have bidirectional + communications with a destination node. In such cases, it is not + sufficient for the originating node to have a route to the + destination node; the destination must also have a route back to the + originating node. In order for this to happen as efficiently as + possible, any generation of a RREP by an intermediate node (as in + section 6.6) for delivery to the originating node SHOULD be + accompanied by some action that notifies the destination about a + route back to the originating node. The originating node selects + this mode of operation in the intermediate nodes by setting the 'G' + flag. See section 6.6.3 for details about actions taken by the + intermediate node in response to a RREQ with the 'G' flag set. + + A node SHOULD NOT originate more than RREQ_RATELIMIT RREQ messages + per second. After broadcasting a RREQ, a node waits for a RREP (or + other control message with current information regarding a route to + the appropriate destination). If a route is not received within + NET_TRAVERSAL_TIME milliseconds, the node MAY try again to discover a + route by broadcasting another RREQ, up to a maximum of RREQ_RETRIES + + + +Perkins, et. al. Experimental [Page 14] + +RFC 3561 AODV Routing July 2003 + + + times at the maximum TTL value. Each new attempt MUST increment and + update the RREQ ID. For each attempt, the TTL field of the IP header + is set according to the mechanism specified in section 6.4, in order + to enable control over how far the RREQ is disseminated for the each + retry. + + Data packets waiting for a route (i.e., waiting for a RREP after a + RREQ has been sent) SHOULD be buffered. The buffering SHOULD be + "first-in, first-out" (FIFO). If a route discovery has been + attempted RREQ_RETRIES times at the maximum TTL without receiving any + RREP, all data packets destined for the corresponding destination + SHOULD be dropped from the buffer and a Destination Unreachable + message SHOULD be delivered to the application. + + To reduce congestion in a network, repeated attempts by a source node + at route discovery for a single destination MUST utilize a binary + exponential backoff. The first time a source node broadcasts a RREQ, + it waits NET_TRAVERSAL_TIME milliseconds for the reception of a RREP. + If a RREP is not received within that time, the source node sends a + new RREQ. When calculating the time to wait for the RREP after + sending the second RREQ, the source node MUST use a binary + exponential backoff. Hence, the waiting time for the RREP + corresponding to the second RREQ is 2 * NET_TRAVERSAL_TIME + milliseconds. If a RREP is not received within this time period, + another RREQ may be sent, up to RREQ_RETRIES additional attempts + after the first RREQ. For each additional attempt, the waiting time + for the RREP is multiplied by 2, so that the time conforms to a + binary exponential backoff. + +6.4. Controlling Dissemination of Route Request Messages + + To prevent unnecessary network-wide dissemination of RREQs, the + originating node SHOULD use an expanding ring search technique. In + an expanding ring search, the originating node initially uses a TTL = + TTL_START in the RREQ packet IP header and sets the timeout for + receiving a RREP to RING_TRAVERSAL_TIME milliseconds. + RING_TRAVERSAL_TIME is calculated as described in section 10. The + TTL_VALUE used in calculating RING_TRAVERSAL_TIME is set equal to the + value of the TTL field in the IP header. If the RREQ times out + without a corresponding RREP, the originator broadcasts the RREQ + again with the TTL incremented by TTL_INCREMENT. This continues + until the TTL set in the RREQ reaches TTL_THRESHOLD, beyond which a + TTL = NET_DIAMETER is used for each attempt. Each time, the timeout + for receiving a RREP is RING_TRAVERSAL_TIME. When it is desired to + have all retries traverse the entire ad hoc network, this can be + achieved by configuring TTL_START and TTL_INCREMENT both to be the + same value as NET_DIAMETER. + + + + +Perkins, et. al. Experimental [Page 15] + +RFC 3561 AODV Routing July 2003 + + + The Hop Count stored in an invalid routing table entry indicates the + last known hop count to that destination in the routing table. When + a new route to the same destination is required at a later time + (e.g., upon route loss), the TTL in the RREQ IP header is initially + set to the Hop Count plus TTL_INCREMENT. Thereafter, following each + timeout the TTL is incremented by TTL_INCREMENT until TTL = + TTL_THRESHOLD is reached. Beyond this TTL = NET_DIAMETER is used. + Once TTL = NET_DIAMETER, the timeout for waiting for the RREP is set + to NET_TRAVERSAL_TIME, as specified in section 6.3. + + An expired routing table entry SHOULD NOT be expunged before + (current_time + DELETE_PERIOD) (see section 6.11). Otherwise, the + soft state corresponding to the route (e.g., last known hop count) + will be lost. Furthermore, a longer routing table entry expunge time + MAY be configured. Any routing table entry waiting for a RREP SHOULD + NOT be expunged before (current_time + 2 * NET_TRAVERSAL_TIME). + +6.5. Processing and Forwarding Route Requests + + When a node receives a RREQ, it first creates or updates a route to + the previous hop without a valid sequence number (see section 6.2) + then checks to determine whether it has received a RREQ with the same + Originator IP Address and RREQ ID within at least the last + PATH_DISCOVERY_TIME. If such a RREQ has been received, the node + silently discards the newly received RREQ. The rest of this + subsection describes actions taken for RREQs that are not discarded. + + First, it first increments the hop count value in the RREQ by one, to + account for the new hop through the intermediate node. Then the node + searches for a reverse route to the Originator IP Address (see + section 6.2), using longest-prefix matching. If need be, the route + is created, or updated using the Originator Sequence Number from the + RREQ in its routing table. This reverse route will be needed if the + node receives a RREP back to the node that originated the RREQ + (identified by the Originator IP Address). When the reverse route is + created or updated, the following actions on the route are also + carried out: + + 1. the Originator Sequence Number from the RREQ is compared to the + corresponding destination sequence number in the route table entry + and copied if greater than the existing value there + + 2. the valid sequence number field is set to true; + + 3. the next hop in the routing table becomes the node from which the + RREQ was received (it is obtained from the source IP address in + the IP header and is often not equal to the Originator IP Address + field in the RREQ message); + + + +Perkins, et. al. Experimental [Page 16] + +RFC 3561 AODV Routing July 2003 + + + 4. the hop count is copied from the Hop Count in the RREQ message; + + Whenever a RREQ message is received, the Lifetime of the reverse + route entry for the Originator IP address is set to be the maximum of + (ExistingLifetime, MinimalLifetime), where + + MinimalLifetime = (current time + 2*NET_TRAVERSAL_TIME - + 2*HopCount*NODE_TRAVERSAL_TIME). + + The current node can use the reverse route to forward data packets in + the same way as for any other route in the routing table. + + If a node does not generate a RREP (following the processing rules in + section 6.6), and if the incoming IP header has TTL larger than 1, + the node updates and broadcasts the RREQ to address 255.255.255.255 + on each of its configured interfaces (see section 6.14). To update + the RREQ, the TTL or hop limit field in the outgoing IP header is + decreased by one, and the Hop Count field in the RREQ message is + incremented by one, to account for the new hop through the + intermediate node. Lastly, the Destination Sequence number for the + requested destination is set to the maximum of the corresponding + value received in the RREQ message, and the destination sequence + value currently maintained by the node for the requested destination. + However, the forwarding node MUST NOT modify its maintained value for + the destination sequence number, even if the value received in the + incoming RREQ is larger than the value currently maintained by the + forwarding node. + + Otherwise, if a node does generate a RREP, then the node discards the + RREQ. Notice that, if intermediate nodes reply to every transmission + of RREQs for a particular destination, it might turn out that the + destination does not receive any of the discovery messages. In this + situation, the destination does not learn of a route to the + originating node from the RREQ messages. This could cause the + destination to initiate a route discovery (for example, if the + originator is attempting to establish a TCP session). In order that + the destination learn of routes to the originating node, the + originating node SHOULD set the "gratuitous RREP" ('G') flag in the + RREQ if for any reason the destination is likely to need a route to + the originating node. If, in response to a RREQ with the 'G' flag + set, an intermediate node returns a RREP, it MUST also unicast a + gratuitous RREP to the destination node (see section 6.6.3). + + + + + + + + + +Perkins, et. al. Experimental [Page 17] + +RFC 3561 AODV Routing July 2003 + + +6.6. Generating Route Replies + + A node generates a RREP if either: + + (i) it is itself the destination, or + + (ii) it has an active route to the destination, the destination + sequence number in the node's existing route table entry + for the destination is valid and greater than or equal to + the Destination Sequence Number of the RREQ (comparison + using signed 32-bit arithmetic), and the "destination only" + ('D') flag is NOT set. + + When generating a RREP message, a node copies the Destination IP + Address and the Originator Sequence Number from the RREQ message into + the corresponding fields in the RREP message. Processing is slightly + different, depending on whether the node is itself the requested + destination (see section 6.6.1), or instead if it is an intermediate + node with an fresh enough route to the destination (see section + 6.6.2). + + Once created, the RREP is unicast to the next hop toward the + originator of the RREQ, as indicated by the route table entry for + that originator. As the RREP is forwarded back towards the node + which originated the RREQ message, the Hop Count field is incremented + by one at each hop. Thus, when the RREP reaches the originator, the + Hop Count represents the distance, in hops, of the destination from + the originator. + +6.6.1. Route Reply Generation by the Destination + + If the generating node is the destination itself, it MUST increment + its own sequence number by one if the sequence number in the RREQ + packet is equal to that incremented value. Otherwise, the + destination does not change its sequence number before generating the + RREP message. The destination node places its (perhaps newly + incremented) sequence number into the Destination Sequence Number + field of the RREP, and enters the value zero in the Hop Count field + of the RREP. + + The destination node copies the value MY_ROUTE_TIMEOUT (see section + 10) into the Lifetime field of the RREP. Each node MAY reconfigure + its value for MY_ROUTE_TIMEOUT, within mild constraints (see section + 10). + + + + + + + +Perkins, et. al. Experimental [Page 18] + +RFC 3561 AODV Routing July 2003 + + +6.6.2. Route Reply Generation by an Intermediate Node + + If the node generating the RREP is not the destination node, but + instead is an intermediate hop along the path from the originator to + the destination, it copies its known sequence number for the + destination into the Destination Sequence Number field in the RREP + message. + + The intermediate node updates the forward route entry by placing the + last hop node (from which it received the RREQ, as indicated by the + source IP address field in the IP header) into the precursor list for + the forward route entry -- i.e., the entry for the Destination IP + Address. The intermediate node also updates its route table entry + for the node originating the RREQ by placing the next hop towards the + destination in the precursor list for the reverse route entry -- + i.e., the entry for the Originator IP Address field of the RREQ + message data. + + The intermediate node places its distance in hops from the + destination (indicated by the hop count in the routing table) Count + field in the RREP. The Lifetime field of the RREP is calculated by + subtracting the current time from the expiration time in its route + table entry. + +6.6.3. Generating Gratuitous RREPs + + After a node receives a RREQ and responds with a RREP, it discards + the RREQ. If the RREQ has the 'G' flag set, and the intermediate + node returns a RREP to the originating node, it MUST also unicast a + gratuitous RREP to the destination node. The gratuitous RREP that is + to be sent to the desired destination contains the following values + in the RREP message fields: + + Hop Count The Hop Count as indicated in the + node's route table entry for the + originator + + Destination IP Address The IP address of the node that + originated the RREQ + + Destination Sequence Number The Originator Sequence Number from + the RREQ + + Originator IP Address The IP address of the Destination + node in the RREQ + + + + + + +Perkins, et. al. Experimental [Page 19] + +RFC 3561 AODV Routing July 2003 + + + Lifetime The remaining lifetime of the route + towards the originator of the RREQ, + as known by the intermediate node. + + The gratuitous RREP is then sent to the next hop along the path to + the destination node, just as if the destination node had already + issued a RREQ for the originating node and this RREP was produced in + response to that (fictitious) RREQ. The RREP that is sent to the + originator of the RREQ is the same whether or not the 'G' bit is set. + +6.7. Receiving and Forwarding Route Replies + + When a node receives a RREP message, it searches (using longest- + prefix matching) for a route to the previous hop. If needed, a route + is created for the previous hop, but without a valid sequence number + (see section 6.2). Next, the node then increments the hop count + value in the RREP by one, to account for the new hop through the + intermediate node. Call this incremented value the "New Hop Count". + Then the forward route for this destination is created if it does not + already exist. Otherwise, the node compares the Destination Sequence + Number in the message with its own stored destination sequence number + for the Destination IP Address in the RREP message. Upon comparison, + the existing entry is updated only in the following circumstances: + + (i) the sequence number in the routing table is marked as + invalid in route table entry. + + (ii) the Destination Sequence Number in the RREP is greater than + the node's copy of the destination sequence number and the + known value is valid, or + + (iii) the sequence numbers are the same, but the route is is + marked as inactive, or + + (iv) the sequence numbers are the same, and the New Hop Count is + smaller than the hop count in route table entry. + + If the route table entry to the destination is created or updated, + then the following actions occur: + + - the route is marked as active, + + - the destination sequence number is marked as valid, + + - the next hop in the route entry is assigned to be the node from + which the RREP is received, which is indicated by the source IP + address field in the IP header, + + + + +Perkins, et. al. Experimental [Page 20] + +RFC 3561 AODV Routing July 2003 + + + - the hop count is set to the value of the New Hop Count, + + - the expiry time is set to the current time plus the value of the + Lifetime in the RREP message, + + - and the destination sequence number is the Destination Sequence + Number in the RREP message. + + The current node can subsequently use this route to forward data + packets to the destination. + + If the current node is not the node indicated by the Originator IP + Address in the RREP message AND a forward route has been created or + updated as described above, the node consults its route table entry + for the originating node to determine the next hop for the RREP + packet, and then forwards the RREP towards the originator using the + information in that route table entry. If a node forwards a RREP + over a link that is likely to have errors or be unidirectional, the + node SHOULD set the 'A' flag to require that the recipient of the + RREP acknowledge receipt of the RREP by sending a RREP-ACK message + back (see section 6.8). + + When any node transmits a RREP, the precursor list for the + corresponding destination node is updated by adding to it the next + hop node to which the RREP is forwarded. Also, at each node the + (reverse) route used to forward a RREP has its lifetime changed to be + the maximum of (existing-lifetime, (current time + + ACTIVE_ROUTE_TIMEOUT). Finally, the precursor list for the next hop + towards the destination is updated to contain the next hop towards + the source. + +6.8. Operation over Unidirectional Links + + It is possible that a RREP transmission may fail, especially if the + RREQ transmission triggering the RREP occurs over a unidirectional + link. If no other RREP generated from the same route discovery + attempt reaches the node which originated the RREQ message, the + originator will reattempt route discovery after a timeout (see + section 6.3). However, the same scenario might well be repeated + without any improvement, and no route would be discovered even after + repeated retries. Unless corrective action is taken, this can happen + even when bidirectional routes between originator and destination do + exist. Link layers using broadcast transmissions for the RREQ will + not be able to detect the presence of such unidirectional links. In + AODV, any node acts on only the first RREQ with the same RREQ ID and + ignores any subsequent RREQs. Suppose, for example, that the first + + + + + +Perkins, et. al. Experimental [Page 21] + +RFC 3561 AODV Routing July 2003 + + + RREQ arrives along a path that has one or more unidirectional + link(s). A subsequent RREQ may arrive via a bidirectional path + (assuming such paths exist), but it will be ignored. + + To prevent this problem, when a node detects that its transmission of + a RREP message has failed, it remembers the next-hop of the failed + RREP in a "blacklist" set. Such failures can be detected via the + absence of a link-layer or network-layer acknowledgment (e.g., RREP- + ACK). A node ignores all RREQs received from any node in its + blacklist set. Nodes are removed from the blacklist set after a + BLACKLIST_TIMEOUT period (see section 10). This period should be set + to the upper bound of the time it takes to perform the allowed number + of route request retry attempts as described in section 6.3. + + Note that the RREP-ACK packet does not contain any information about + which RREP it is acknowledging. The time at which the RREP-ACK is + received will likely come just after the time when the RREP was sent + with the 'A' bit. This information is expected to be sufficient to + provide assurance to the sender of the RREP that the link is + currently bidirectional, without any real dependence on the + particular RREP message being acknowledged. However, that assurance + typically cannot be expected to remain in force permanently. + +6.9. Hello Messages + + A node MAY offer connectivity information by broadcasting local Hello + messages. A node SHOULD only use hello messages if it is part of an + active route. Every HELLO_INTERVAL milliseconds, the node checks + whether it has sent a broadcast (e.g., a RREQ or an appropriate layer + 2 message) within the last HELLO_INTERVAL. If it has not, it MAY + broadcast a RREP with TTL = 1, called a Hello message, with the RREP + message fields set as follows: + + Destination IP Address The node's IP address. + + Destination Sequence Number The node's latest sequence number. + + Hop Count 0 + + Lifetime ALLOWED_HELLO_LOSS * HELLO_INTERVAL + + A node MAY determine connectivity by listening for packets from its + set of neighbors. If, within the past DELETE_PERIOD, it has received + a Hello message from a neighbor, and then for that neighbor does not + receive any packets (Hello messages or otherwise) for more than + + + + + + +Perkins, et. al. Experimental [Page 22] + +RFC 3561 AODV Routing July 2003 + + + ALLOWED_HELLO_LOSS * HELLO_INTERVAL milliseconds, the node SHOULD + assume that the link to this neighbor is currently lost. When this + happens, the node SHOULD proceed as in Section 6.11. + + Whenever a node receives a Hello message from a neighbor, the node + SHOULD make sure that it has an active route to the neighbor, and + create one if necessary. If a route already exists, then the + Lifetime for the route should be increased, if necessary, to be at + least ALLOWED_HELLO_LOSS * HELLO_INTERVAL. The route to the + neighbor, if it exists, MUST subsequently contain the latest + Destination Sequence Number from the Hello message. The current node + can now begin using this route to forward data packets. Routes that + are created by hello messages and not used by any other active routes + will have empty precursor lists and would not trigger a RERR message + if the neighbor moves away and a neighbor timeout occurs. + +6.10. Maintaining Local Connectivity + + Each forwarding node SHOULD keep track of its continued connectivity + to its active next hops (i.e., which next hops or precursors have + forwarded packets to or from the forwarding node during the last + ACTIVE_ROUTE_TIMEOUT), as well as neighbors that have transmitted + Hello messages during the last (ALLOWED_HELLO_LOSS * HELLO_INTERVAL). + A node can maintain accurate information about its continued + connectivity to these active next hops, using one or more of the + available link or network layer mechanisms, as described below. + + - Any suitable link layer notification, such as those provided by + IEEE 802.11, can be used to determine connectivity, each time a + packet is transmitted to an active next hop. For example, absence + of a link layer ACK or failure to get a CTS after sending RTS, + even after the maximum number of retransmission attempts, + indicates loss of the link to this active next hop. + + - If layer-2 notification is not available, passive acknowledgment + SHOULD be used when the next hop is expected to forward the + packet, by listening to the channel for a transmission attempt + made by the next hop. If transmission is not detected within + NEXT_HOP_WAIT milliseconds or the next hop is the destination (and + thus is not supposed to forward the packet) one of the following + methods SHOULD be used to determine connectivity: + + * Receiving any packet (including a Hello message) from the next + hop. + + * A RREQ unicast to the next hop, asking for a route to the next + hop. + + + + +Perkins, et. al. Experimental [Page 23] + +RFC 3561 AODV Routing July 2003 + + + * An ICMP Echo Request message unicast to the next hop. + + If a link to the next hop cannot be detected by any of these methods, + the forwarding node SHOULD assume that the link is lost, and take + corrective action by following the methods specified in Section 6.11. + +6.11. Route Error (RERR) Messages, Route Expiry and Route Deletion + + Generally, route error and link breakage processing requires the + following steps: + + - Invalidating existing routes + + - Listing affected destinations + + - Determining which, if any, neighbors may be affected + + - Delivering an appropriate RERR to such neighbors + + A Route Error (RERR) message MAY be either broadcast (if there are + many precursors), unicast (if there is only 1 precursor), or + iteratively unicast to all precursors (if broadcast is + inappropriate). Even when the RERR message is iteratively unicast to + several precursors, it is considered to be a single control message + for the purposes of the description in the text that follows. With + that understanding, a node SHOULD NOT generate more than + RERR_RATELIMIT RERR messages per second. + + A node initiates processing for a RERR message in three situations: + + (i) if it detects a link break for the next hop of an active + route in its routing table while transmitting data (and + route repair, if attempted, was unsuccessful), or + + (ii) if it gets a data packet destined to a node for which it + does not have an active route and is not repairing (if + using local repair), or + + (iii) if it receives a RERR from a neighbor for one or more + active routes. + + For case (i), the node first makes a list of unreachable destinations + consisting of the unreachable neighbor and any additional + destinations (or subnets, see section 7) in the local routing table + that use the unreachable neighbor as the next hop. In this case, if + a subnet route is found to be newly unreachable, an IP destination + address for the subnet is constructed by appending zeroes to the + + + + +Perkins, et. al. Experimental [Page 24] + +RFC 3561 AODV Routing July 2003 + + + subnet prefix as shown in the route table entry. This is + unambiguous, since the precursor is known to have route table + information with a compatible prefix length for that subnet. + + For case (ii), there is only one unreachable destination, which is + the destination of the data packet that cannot be delivered. For + case (iii), the list should consist of those destinations in the RERR + for which there exists a corresponding entry in the local routing + table that has the transmitter of the received RERR as the next hop. + + Some of the unreachable destinations in the list could be used by + neighboring nodes, and it may therefore be necessary to send a (new) + RERR. The RERR should contain those destinations that are part of + the created list of unreachable destinations and have a non-empty + precursor list. + + The neighboring node(s) that should receive the RERR are all those + that belong to a precursor list of at least one of the unreachable + destination(s) in the newly created RERR. In case there is only one + unique neighbor that needs to receive the RERR, the RERR SHOULD be + unicast toward that neighbor. Otherwise the RERR is typically sent + to the local broadcast address (Destination IP == 255.255.255.255, + TTL == 1) with the unreachable destinations, and their corresponding + destination sequence numbers, included in the packet. The DestCount + field of the RERR packet indicates the number of unreachable + destinations included in the packet. + + Just before transmitting the RERR, certain updates are made on the + routing table that may affect the destination sequence numbers for + the unreachable destinations. For each one of these destinations, + the corresponding routing table entry is updated as follows: + + 1. The destination sequence number of this routing entry, if it + exists and is valid, is incremented for cases (i) and (ii) above, + and copied from the incoming RERR in case (iii) above. + + 2. The entry is invalidated by marking the route entry as invalid + + 3. The Lifetime field is updated to current time plus DELETE_PERIOD. + Before this time, the entry SHOULD NOT be deleted. + + Note that the Lifetime field in the routing table plays dual role -- + for an active route it is the expiry time, and for an invalid route + it is the deletion time. If a data packet is received for an invalid + route, the Lifetime field is updated to current time plus + DELETE_PERIOD. The determination of DELETE_PERIOD is discussed in + Section 10. + + + + +Perkins, et. al. Experimental [Page 25] + +RFC 3561 AODV Routing July 2003 + + +6.12. Local Repair + + When a link break in an active route occurs, the node upstream of + that break MAY choose to repair the link locally if the destination + was no farther than MAX_REPAIR_TTL hops away. To repair the link + break, the node increments the sequence number for the destination + and then broadcasts a RREQ for that destination. The TTL of the RREQ + should initially be set to the following value: + + max(MIN_REPAIR_TTL, 0.5 * #hops) + LOCAL_ADD_TTL, + + where #hops is the number of hops to the sender (originator) of the + currently undeliverable packet. Thus, local repair attempts will + often be invisible to the originating node, and will always have TTL + >= MIN_REPAIR_TTL + LOCAL_ADD_TTL. The node initiating the repair + then waits the discovery period to receive RREPs in response to the + RREQ. During local repair data packets SHOULD be buffered. If, at + the end of the discovery period, the repairing node has not received + a RREP (or other control message creating or updating the route) for + that destination, it proceeds as described in Section 6.11 by + transmitting a RERR message for that destination. + + On the other hand, if the node receives one or more RREPs (or other + control message creating or updating the route to the desired + destination) during the discovery period, it first compares the hop + count of the new route with the value in the hop count field of the + invalid route table entry for that destination. If the hop count of + the newly determined route to the destination is greater than the hop + count of the previously known route the node SHOULD issue a RERR + message for the destination, with the 'N' bit set. Then it proceeds + as described in Section 6.7, updating its route table entry for that + destination. + + A node that receives a RERR message with the 'N' flag set MUST NOT + delete the route to that destination. The only action taken should + be the retransmission of the message, if the RERR arrived from the + next hop along that route, and if there are one or more precursor + nodes for that route to the destination. When the originating node + receives a RERR message with the 'N' flag set, if this message came + from its next hop along its route to the destination then the + originating node MAY choose to reinitiate route discovery, as + described in Section 6.3. + + Local repair of link breaks in routes sometimes results in increased + path lengths to those destinations. Repairing the link locally is + likely to increase the number of data packets that are able to be + delivered to the destinations, since data packets will not be dropped + as the RERR travels to the originating node. Sending a RERR to the + + + +Perkins, et. al. Experimental [Page 26] + +RFC 3561 AODV Routing July 2003 + + + originating node after locally repairing the link break may allow the + originator to find a fresh route to the destination that is better, + based on current node positions. However, it does not require the + originating node to rebuild the route, as the originator may be done, + or nearly done, with the data session. + + When a link breaks along an active route, there are often multiple + destinations that become unreachable. The node that is upstream of + the lost link tries an immediate local repair for only the one + destination towards which the data packet was traveling. Other + routes using the same link MUST be marked as invalid, but the node + handling the local repair MAY flag each such newly lost route as + locally repairable; this local repair flag in the route table MUST be + reset when the route times out (e.g., after the route has been not + been active for ACTIVE_ROUTE_TIMEOUT). Before the timeout occurs, + these other routes will be repaired as needed when packets arrive for + the other destinations. Hence, these routes are repaired as needed; + if a data packet does not arrive for the route, then that route will + not be repaired. Alternatively, depending upon local congestion, the + node MAY begin the process of establishing local repairs for the + other routes, without waiting for new packets to arrive. By + proactively repairing the routes that have broken due to the loss of + the link, incoming data packets for those routes will not be subject + to the delay of repairing the route and can be immediately forwarded. + However, repairing the route before a data packet is received for it + runs the risk of repairing routes that are no longer in use. + Therefore, depending upon the local traffic in the network and + whether congestion is being experienced, the node MAY elect to + proactively repair the routes before a data packet is received; + otherwise, it can wait until a data is received, and then commence + the repair of the route. + +6.13. Actions After Reboot + + A node participating in the ad hoc network must take certain actions + after reboot as it might lose all sequence number records for all + destinations, including its own sequence number. However, there may + be neighboring nodes that are using this node as an active next hop. + This can potentially create routing loops. To prevent this + possibility, each node on reboot waits for DELETE_PERIOD before + transmitting any route discovery messages. If the node receives a + RREQ, RREP, or RERR control packet, it SHOULD create route entries as + appropriate given the sequence number information in the control + packets, but MUST not forward any control packets. If the node + receives a data packet for some other destination, it SHOULD + broadcast a RERR as described in subsection 6.11 and MUST reset the + waiting timer to expire after current time plus DELETE_PERIOD. + + + + +Perkins, et. al. Experimental [Page 27] + +RFC 3561 AODV Routing July 2003 + + + It can be shown [4] that by the time the rebooted node comes out of + the waiting phase and becomes an active router again, none of its + neighbors will be using it as an active next hop any more. Its own + sequence number gets updated once it receives a RREQ from any other + node, as the RREQ always carries the maximum destination sequence + number seen en route. If no such RREQ arrives, the node MUST + initialize its own sequence number to zero. + +6.14. Interfaces + + Because AODV should operate smoothly over wired, as well as wireless, + networks, and because it is likely that AODV will also be used with + multiple wireless devices, the particular interface over which + packets arrive must be known to AODV whenever a packet is received. + This includes the reception of RREQ, RREP, and RERR messages. + Whenever a packet is received from a new neighbor, the interface on + which that packet was received is recorded into the route table entry + for that neighbor, along with all the other appropriate routing + information. Similarly, whenever a route to a new destination is + learned, the interface through which the destination can be reached + is also recorded into the destination's route table entry. + + When multiple interfaces are available, a node retransmitting a RREQ + message rebroadcasts that message on all interfaces that have been + configured for operation in the ad-hoc network, except those on which + it is known that all of the nodes neighbors have already received the + RREQ For instance, for some broadcast media (e.g., Ethernet) it may + be presumed that all nodes on the same link receive a broadcast + message at the same time. When a node needs to transmit a RERR, it + SHOULD only transmit it on those interfaces that have neighboring + precursor nodes for that route. + +7. AODV and Aggregated Networks + + AODV has been designed for use by mobile nodes with IP addresses that + are not necessarily related to each other, to create an ad hoc + network. However, in some cases a collection of mobile nodes MAY + operate in a fixed relationship to each other and share a common + subnet prefix, moving together within an area where an ad hoc network + has formed. Call such a collection of nodes a "subnet". In this + case, it is possible for a single node within the subnet to advertise + reachability for all other nodes on the subnet, by responding with a + RREP message to any RREQ message requesting a route to any node with + the subnet routing prefix. Call the single node the "subnet router". + In order for a subnet router to operate the AODV protocol for the + whole subnet, it has to maintain a destination sequence number for + the entire subnet. In any such RREP message sent by the subnet + router, the Prefix Size field of the RREP message MUST be set to the + + + +Perkins, et. al. Experimental [Page 28] + +RFC 3561 AODV Routing July 2003 + + + length of the subnet prefix. Other nodes sharing the subnet prefix + SHOULD NOT issue RREP messages, and SHOULD forward RREQ messages to + the subnet router. + + The processing for RREPs that give routes to subnets (i.e., have + nonzero prefix length) is the same as processing for host-specific + RREP messages. Every node that receives the RREP with prefix size + information SHOULD create or update the route table entry for the + subnet, including the sequence number supplied by the subnet router, + and including the appropriate precursor information. Then, in the + future the node can use the information to avoid sending future RREQs + for other nodes on the same subnet. + + When a node uses a subnet route it may be that a packet is routed to + an IP address on the subnet that is not assigned to any existing node + in the ad hoc network. When that happens, the subnet router MUST + return ICMP Host Unreachable message to the sending node. Upstream + nodes receiving such an ICMP message SHOULD record the information + that the particular IP address is unreachable, but MUST NOT + invalidate the route entry for any matching subnet prefix. + + If several nodes in the subnet advertise reachability to the subnet + defined by the subnet prefix, the node with the lowest IP address is + elected to be the subnet router, and all other nodes MUST stop + advertising reachability. + + The behavior of default routes (i.e., routes with routing prefix + length 0) is not defined in this specification. Selection of routes + sharing prefix bits should be according to longest match first. + +8. Using AODV with Other Networks + + In some configurations, an ad hoc network may be able to provide + connectivity between external routing domains that do not use AODV. + If the points of contact to the other networks can act as subnet + routers (see Section 7) for any relevant networks within the external + routing domains, then the ad hoc network can maintain connectivity to + the external routing domains. Indeed, the external routing networks + can use the ad hoc network defined by AODV as a transit network. + + In order to provide this feature, a point of contact to an external + network (call it an Infrastructure Router) has to act as the subnet + router for every subnet of interest within the external network for + which the Infrastructure Router can provide reachability. This + includes the need for maintaining a destination sequence number for + that external subnet. + + + + + +Perkins, et. al. Experimental [Page 29] + +RFC 3561 AODV Routing July 2003 + + + If multiple Infrastructure Routers offer reachability to the same + external subnet, those Infrastructure Routers have to cooperate (by + means outside the scope of this specification) to provide consistent + AODV semantics for ad hoc access to those subnets. + +9. Extensions + + In this section, the format of extensions to the RREQ and RREP + messages is specified. All such extensions appear after the message + data, and have the following format: + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Length | type-specific data ... + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + where: + + Type 1-255 + + Length The length of the type-specific data, not including the Type + and Length fields of the extension in bytes. + + Extensions with types between 128 and 255 may NOT be skipped. The + rules for extensions will be spelled out more fully, and conform to + the rules for handling IPv6 options. + +9.1. Hello Interval Extension Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Length | Hello Interval ... | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | ... Hello Interval, continued | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + Type 1 + + Length 4 + + Hello Interval + The number of milliseconds between successive transmissions + of a Hello message. + + + + + + +Perkins, et. al. Experimental [Page 30] + +RFC 3561 AODV Routing July 2003 + + + The Hello Interval extension MAY be appended to a RREP message with + TTL == 1, to be used by a neighboring receiver in determine how long + to wait for subsequent such RREP messages (i.e., Hello messages; see + section 6.9). + +10. Configuration Parameters + + This section gives default values for some important parameters + associated with AODV protocol operations. A particular mobile node + may wish to change certain of the parameters, in particular the + NET_DIAMETER, MY_ROUTE_TIMEOUT, ALLOWED_HELLO_LOSS, RREQ_RETRIES, and + possibly the HELLO_INTERVAL. In the latter case, the node should + advertise the HELLO_INTERVAL in its Hello messages, by appending a + Hello Interval Extension to the RREP message. Choice of these + parameters may affect the performance of the protocol. Changing + NODE_TRAVERSAL_TIME also changes the node's estimate of the + NET_TRAVERSAL_TIME, and so can only be done with suitable knowledge + about the behavior of other nodes in the ad hoc network. The + configured value for MY_ROUTE_TIMEOUT MUST be at least 2 * + PATH_DISCOVERY_TIME. + + Parameter Name Value + ---------------------- ----- + ACTIVE_ROUTE_TIMEOUT 3,000 Milliseconds + ALLOWED_HELLO_LOSS 2 + BLACKLIST_TIMEOUT RREQ_RETRIES * NET_TRAVERSAL_TIME + DELETE_PERIOD see note below + HELLO_INTERVAL 1,000 Milliseconds + LOCAL_ADD_TTL 2 + MAX_REPAIR_TTL 0.3 * NET_DIAMETER + MIN_REPAIR_TTL see note below + MY_ROUTE_TIMEOUT 2 * ACTIVE_ROUTE_TIMEOUT + NET_DIAMETER 35 + NET_TRAVERSAL_TIME 2 * NODE_TRAVERSAL_TIME * NET_DIAMETER + NEXT_HOP_WAIT NODE_TRAVERSAL_TIME + 10 + NODE_TRAVERSAL_TIME 40 milliseconds + PATH_DISCOVERY_TIME 2 * NET_TRAVERSAL_TIME + RERR_RATELIMIT 10 + RING_TRAVERSAL_TIME 2 * NODE_TRAVERSAL_TIME * + (TTL_VALUE + TIMEOUT_BUFFER) + RREQ_RETRIES 2 + RREQ_RATELIMIT 10 + TIMEOUT_BUFFER 2 + TTL_START 1 + TTL_INCREMENT 2 + TTL_THRESHOLD 7 + TTL_VALUE see note below + + + + +Perkins, et. al. Experimental [Page 31] + +RFC 3561 AODV Routing July 2003 + + + The MIN_REPAIR_TTL should be the last known hop count to the + destination. If Hello messages are used, then the + ACTIVE_ROUTE_TIMEOUT parameter value MUST be more than the value + (ALLOWED_HELLO_LOSS * HELLO_INTERVAL). For a given + ACTIVE_ROUTE_TIMEOUT value, this may require some adjustment to the + value of the HELLO_INTERVAL, and consequently use of the Hello + Interval Extension in the Hello messages. + + TTL_VALUE is the value of the TTL field in the IP header while the + expanding ring search is being performed. This is described further + in section 6.4. The TIMEOUT_BUFFER is configurable. Its purpose is + to provide a buffer for the timeout so that if the RREP is delayed + due to congestion, a timeout is less likely to occur while the RREP + is still en route back to the source. To omit this buffer, set + TIMEOUT_BUFFER = 0. + + DELETE_PERIOD is intended to provide an upper bound on the time for + which an upstream node A can have a neighbor B as an active next hop + for destination D, while B has invalidated the route to D. Beyond + this time B can delete the (already invalidated) route to D. The + determination of the upper bound depends somewhat on the + characteristics of the underlying link layer. If Hello messages are + used to determine the continued availability of links to next hop + nodes, DELETE_PERIOD must be at least ALLOWED_HELLO_LOSS * + HELLO_INTERVAL. If the link layer feedback is used to detect loss of + link, DELETE_PERIOD must be at least ACTIVE_ROUTE_TIMEOUT. If hello + messages are received from a neighbor but data packets to that + neighbor are lost (e.g., due to temporary link asymmetry), we have to + make more concrete assumptions about the underlying link layer. We + assume that such asymmetry cannot persist beyond a certain time, say, + a multiple K of HELLO_INTERVAL. In other words, a node will + invariably receive at least one out of K subsequent Hello messages + from a neighbor if the link is working and the neighbor is sending no + other traffic. Covering all possibilities, + + DELETE_PERIOD = K * max (ACTIVE_ROUTE_TIMEOUT, HELLO_INTERVAL) + (K = 5 is recommended). + + NET_DIAMETER measures the maximum possible number of hops between two + nodes in the network. NODE_TRAVERSAL_TIME is a conservative estimate + of the average one hop traversal time for packets and should include + queuing delays, interrupt processing times and transfer times. + ACTIVE_ROUTE_TIMEOUT SHOULD be set to a longer value (at least 10,000 + milliseconds) if link-layer indications are used to detect link + breakages such as in IEEE 802.11 [5] standard. TTL_START should be + set to at least 2 if Hello messages are used for local connectivity + information. Performance of the AODV protocol is sensitive to the + chosen values of these constants, which often depend on the + + + +Perkins, et. al. Experimental [Page 32] + +RFC 3561 AODV Routing July 2003 + + + characteristics of the underlying link layer protocol, radio + technologies etc. BLACKLIST_TIMEOUT should be suitably increased if + an expanding ring search is used. In such cases, it should be + {[(TTL_THRESHOLD - TTL_START)/TTL_INCREMENT] + 1 + RREQ_RETRIES} * + NET_TRAVERSAL_TIME. This is to account for possible additional route + discovery attempts. + +11. Security Considerations + + Currently, AODV does not specify any special security measures. Route + protocols, however, are prime targets for impersonation attacks. In + networks where the node membership is not known, it is difficult to + determine the occurrence of impersonation attacks, and security + prevention techniques are difficult at best. However, when the + network membership is known and there is a danger of such attacks, + AODV control messages must be protected by use of authentication + techniques, such as those involving generation of unforgeable and + cryptographically strong message digests or digital signatures. + While AODV does not place restrictions on the authentication + mechanism used for this purpose, IPsec AH is an appropriate choice + for cases where the nodes share an appropriate security association + that enables the use of AH. + + In particular, RREP messages SHOULD be authenticated to avoid + creation of spurious routes to a desired destination. Otherwise, an + attacker could masquerade as the desired destination, and maliciously + deny service to the destination and/or maliciously inspect and + consume traffic intended for delivery to the destination. RERR + messages, while less dangerous, SHOULD be authenticated in order to + prevent malicious nodes from disrupting valid routes between nodes + that are communication partners. + + AODV does not make any assumption about the method by which addresses + are assigned to the mobile nodes, except that they are presumed to + have unique IP addresses. Therefore, no special consideration, other + than what is natural because of the general protocol specifications, + can be made about the applicability of IPsec authentication headers + or key exchange mechanisms. However, if the mobile nodes in the ad + hoc network have pre-established security associations, it is + presumed that the purposes for which the security associations are + created include that of authorizing the processing of AODV control + messages. Given this understanding, the mobile nodes should be able + to use the same authentication mechanisms based on their IP addresses + as they would have used otherwise. + + + + + + + +Perkins, et. al. Experimental [Page 33] + +RFC 3561 AODV Routing July 2003 + + +12. IANA Considerations + + AODV defines a "Type" field for messages sent to port 654. A new + registry has been created for the values for this Type field, and the + following values have been assigned: + + Message Type Value + --------------------------- ----- + Route Request (RREQ) 1 + Route Reply (RREP) 2 + Route Error (RERR) 3 + Route-Reply Ack (RREP-ACK) 4 + + AODV control messages can have extensions. Currently, only one + extension is defined. A new registry has been created for the Type + field of the extensions: + + Extension Type Value + --------------------------- ----- + Hello Interval 1 + + Future values of the Message Type or Extension Type can be allocated + using standards action [2]. + +13. IPv6 Considerations + + See [6] for detailed operation for IPv6. The only changes to the + protocol are that the address fields are enlarged. + +14. Acknowledgments + + Special thanks to Ian Chakeres, UCSB, for his extensive suggestions + and contributions to recent revisions. + + We acknowledge with gratitude the work done at University of + Pennsylvania within Carl Gunter's group, as well as at Stanford and + CMU, to determine some conditions (especially involving reboots and + lost RERRs) under which previous versions of AODV could suffer from + routing loops. Contributors to those efforts include Karthikeyan + Bhargavan, Joshua Broch, Dave Maltz, Madanlal Musuvathi, and Davor + Obradovic. The idea of a DELETE_PERIOD, for which expired routes + (and, in particular, the sequence numbers) to a particular + destination must be maintained, was also suggested by them. + + We also acknowledge the comments and improvements suggested by Sung- + Ju Lee (especially regarding local repair), Mahesh Marina, Erik + Nordstrom (who provided text for section 6.11), Yves Prelot, Marc + Mosko, Manel Guerrero Zapata, Philippe Jacquet, and Fred Baker. + + + +Perkins, et. al. Experimental [Page 34] + +RFC 3561 AODV Routing July 2003 + + +15. Normative References + + [1] Bradner, S. "Key words for use in RFCs to Indicate Requirement + Levels", BCP 14, RFC 2119, March 1997. + + [2] Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA + Considerations Section in RFCs", BCP 26, RFC 2434, October 1998. + +16. Informative References + + [3] Manner, J., et al., "Mobility Related Terminology", Work in + Progress, July 2001. + + [4] Karthikeyan Bhargavan, Carl A. Gunter, and Davor Obradovic. + Fault Origin Adjudication. In Proceedings of the Workshop on + Formal Methods in Software Practice, Portland, OR, August 2000. + + [5] IEEE 802.11 Committee, AlphaGraphics #35, 10201 N.35th Avenue, + Phoenix AZ 85051. Wireless LAN Medium Access Control MAC and + Physical Layer PHY Specifications, June 1997. IEEE Standard + 802.11-97. + + [6] Perkins, C., Royer, E. and S. Das, "Ad hoc on demand distance + vector (AODV) routing for ip version 6", Work in Progress. + + + + + + + + + + + + + + + + + + + + + + + + + + + +Perkins, et. al. Experimental [Page 35] + +RFC 3561 AODV Routing July 2003 + + +17. Authors' Addresses + + Charles E. Perkins + Communications Systems Laboratory + Nokia Research Center + 313 Fairchild Drive + Mountain View, CA 94303 + USA + + Phone: +1 650 625 2986 + Fax: +1 650 691 2170 (fax) + EMail: Charles.Perkins@nokia.com + + + Elizabeth M. Belding-Royer + Department of Computer Science + University of California, Santa Barbara + Santa Barbara, CA 93106 + + Phone: +1 805 893 3411 + Fax: +1 805 893 8553 + EMail: ebelding@cs.ucsb.edu + + + Samir R. Das + Department of Electrical and Computer Engineering + & Computer Science + University of Cincinnati + Cincinnati, OH 45221-0030 + + Phone: +1 513 556 2594 + Fax: +1 513 556 7326 + EMail: sdas@ececs.uc.edu + + + + + + + + + + + + + + + + + + +Perkins, et. al. Experimental [Page 36] + +RFC 3561 AODV Routing July 2003 + + +18. Full Copyright Statement + + Copyright (C) The Internet Society (2003). All Rights Reserved. + + This document and translations of it may be copied and furnished to + others, and derivative works that comment on or otherwise explain it + or assist in its implementation may be prepared, copied, published + and distributed, in whole or in part, without restriction of any + kind, provided that the above copyright notice and this paragraph are + included on all such copies and derivative works. However, this + document itself may not be modified in any way, such as by removing + the copyright notice or references to the Internet Society or other + Internet organizations, except as needed for the purpose of + developing Internet standards in which case the procedures for + copyrights defined in the Internet Standards process must be + followed, or as required to translate it into languages other than + English. + + The limited permissions granted above are perpetual and will not be + revoked by the Internet Society or its successors or assigns. + + This document and the information contained herein is provided on an + "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING + TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING + BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION + HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + +Acknowledgement + + Funding for the RFC Editor function is currently provided by the + Internet Society. + + + + + + + + + + + + + + + + + + + +Perkins, et. al. Experimental [Page 37] + From 6d411613c3228c56928bbf2697d57b9797c1ce57 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 2 Jul 2009 13:39:00 +0400 Subject: [PATCH 002/191] wscript added --- src/routing/aodv/waf | 1 + src/routing/aodv/wscript | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100755 src/routing/aodv/waf create mode 100644 src/routing/aodv/wscript diff --git a/src/routing/aodv/waf b/src/routing/aodv/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/routing/aodv/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript new file mode 100644 index 000000000..9cdea09f5 --- /dev/null +++ b/src/routing/aodv/wscript @@ -0,0 +1,14 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def build(bld): + module = bld.create_ns3_module('aodv', ['internet-stack', 'contrib']) + module.includes = '.' + module.source = [ + ] + + headers = bld.new_task_gen('ns3header') + headers.module = 'aodv' + headers.source = [ + 'aodv.h', + ] + From 8f7f51dc0be2c59f19379448ae289fd9b34fc969 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 2 Jul 2009 14:44:44 +0400 Subject: [PATCH 003/191] AODV routing table added --- src/routing/aodv/aodv-rtable.cc | 150 ++++++++++++++++++++++++++++ src/routing/aodv/aodv-rtable.h | 167 ++++++++++++++++++++++++++++++++ src/routing/aodv/aodv.h | 33 +++++++ src/routing/aodv/wscript | 3 +- src/wscript | 1 + 5 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 src/routing/aodv/aodv-rtable.cc create mode 100644 src/routing/aodv/aodv-rtable.h create mode 100644 src/routing/aodv/aodv.h diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc new file mode 100644 index 000000000..3704245b3 --- /dev/null +++ b/src/routing/aodv/aodv-rtable.cc @@ -0,0 +1,150 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ + +#include "aodv-rtable.h" +#include + +namespace ns3 { +namespace aodv { + +/* + The Routing Table + */ + +aodv_rt_entry::aodv_rt_entry() +{ + rt_req_timeout = 0.0; + rt_req_cnt = 0; + + rt_dst = 0; + rt_seqno = 0; + rt_hops = rt_last_hop_count = INFINITY2; + rt_nexthop = 0; + rt_expire = 0.0; + rt_flags = RTF_DOWN; + + /* + rt_errors = 0; + rt_error_time = 0.0; + */ + + for (int i=0; i < MAX_HISTORY; i++) + { + rt_disc_latency[i] = 0.0; + } + hist_indx = 0; + rt_req_last_ttl = 0; +} + + +aodv_rt_entry::~aodv_rt_entry() +{ +} + + +void +aodv_rt_entry::nb_insert(Ipv4Address id) +{ + rt_nblist.push_back(AODV_Neighbor(id)); +} + +bool +aodv_rt_entry::nb_lookup(Ipv4Address id, AODV_Neighbor & n) +{ + for(std::vector::const_iterator i = rt_nblist.begin(); i != rt_nblist.end(); ++i) + if (i->nb_addr == id) + { + n = *i; + return true; + } + return false; +} + +void +aodv_rt_entry::pc_insert(Ipv4Address id) +{ + AODV_Precursor p (id); + + if (! pc_lookup(id, p)) rt_pclist.push_back(p); +} + +bool +aodv_rt_entry::pc_lookup(Ipv4Address id, AODV_Precursor & p) +{ + for(std::vector::const_iterator i = rt_pclist.begin(); i != rt_pclist.end(); ++i) + if (i->pc_addr == id) + { + p = *i; + return true; + } + return false; +} + +void +aodv_rt_entry::pc_delete(Ipv4Address id) +{ + AODV_Precursor p(id); + rt_pclist.erase (std::remove(rt_pclist.begin(), rt_pclist.end(), p), rt_pclist.end()); +} + +void +aodv_rt_entry::pc_delete() +{ + rt_pclist.clear(); +} + +bool +aodv_rt_entry::pc_empty() const +{ + return rt_pclist.empty(); +} + +/* + The Routing Table + */ + +bool +aodv_rtable::rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const +{ + std::vector::const_iterator i = std::find (rthead.begin(), rthead.end(), id); + if (i == rthead.end()) return false; + rt = *i; + return true; +} + +void +aodv_rtable::rt_delete(Ipv4Address id) +{ + rthead.erase (std::remove(rthead.begin(), rthead.end(), id), rthead.end()); +} + +void +aodv_rtable::rt_add(aodv_rt_entry const & rt) +{ + aodv_rt_entry dummy; + NS_ASSERT(! rt_lookup(rt.rt_dst, dummy)); + rthead.push_back(rt); +} + +}} diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h new file mode 100644 index 000000000..da05051b5 --- /dev/null +++ b/src/routing/aodv/aodv-rtable.h @@ -0,0 +1,167 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ +#ifndef __aodv_rtable_h__ +#define __aodv_rtable_h__ + +#include +#include +#include +#include "ns3/ipv4.h" +#include "ns3/nstime.h" + +namespace ns3 { +namespace aodv { + +#define INFINITY2 0xff + +/* + AODV Neighbor Cache Entry + */ +class AODV_Neighbor +{ + friend class AODV; + friend class aodv_rt_entry; + +public: + AODV_Neighbor(Ipv4Address const & a) : nb_addr(a), nb_expire(Seconds(0)) {} + +protected: + Ipv4Address nb_addr; + Time nb_expire; +}; + +/* + AODV Precursor list data structure + */ +class AODV_Precursor +{ + friend class AODV; + friend class aodv_rt_entry; +public: + AODV_Precursor(Ipv4Address const & a) : pc_addr(a) {} + + bool operator==(AODV_Precursor const & o) const + { + return (pc_addr == o.pc_addr); + } +protected: + Ipv4Address pc_addr; // precursor address +}; + +/* + Route Table Entry + */ + +class aodv_rt_entry +{ + friend class aodv_rtable; + friend class AODV; + friend class LocalRepairTimer; +public: + /// TODO make functional c-tor + aodv_rt_entry(); + ~aodv_rt_entry(); + + void nb_insert(Ipv4Address id); + /// Lookup neighbor by address, return true on success + bool nb_lookup(Ipv4Address id, AODV_Neighbor & n); + void pc_insert(Ipv4Address id); + /// Lookup precursor by address, return true on success + bool pc_lookup(Ipv4Address id, AODV_Precursor & p); + void pc_delete(Ipv4Address id); + void pc_delete(); + bool pc_empty() const; + + /// Compare destination address + bool operator==(Ipv4Address id) const + { + return rt_dst == id; + } + + double rt_req_timeout; // when I can send another req + u_int8_t rt_req_cnt; // number of route requests + +protected: + Ipv4Address rt_dst; + u_int32_t rt_seqno; + /* u_int8_t rt_interface; */ + u_int16_t rt_hops; // hop count + int rt_last_hop_count; // last valid hop count + Ipv4Address rt_nexthop; // next hop IP address + /* list of precursors */ + std::vector rt_pclist; + double rt_expire; // when entry expires + u_int8_t rt_flags; + +#define RTF_DOWN 0 +#define RTF_UP 1 +#define RTF_IN_REPAIR 2 + + /* + * Must receive 4 errors within 3 seconds in order to mark + * the route down. + u_int8_t rt_errors; // error count + double rt_error_time; +#define MAX_RT_ERROR 4 // errors +#define MAX_RT_ERROR_TIME 3 // seconds + */ + +#define MAX_HISTORY 3 + double rt_disc_latency[MAX_HISTORY]; + char hist_indx; + int rt_req_last_ttl; // last ttl value used + // last few route discovery latencies + // double rt_length [MAX_HISTORY]; + // last few route lengths + + /* + * a list of neighbors that are using this route. + */ + std::vector rt_nblist; +}; + + +/* + The Routing Table + */ + +class aodv_rtable +{ +public: + aodv_rtable() {} + + // aodv_rt_entry * head() {TODO} + + void rt_add(aodv_rt_entry const & r); + void rt_delete(Ipv4Address id); + /// Lookup routing table entry by destination. Return true on success. + bool rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const; + +private: + std::vector rthead; +}; + +}} + +#endif /* _aodv__rtable_h__ */ diff --git a/src/routing/aodv/aodv.h b/src/routing/aodv/aodv.h new file mode 100644 index 000000000..fddf05d33 --- /dev/null +++ b/src/routing/aodv/aodv.h @@ -0,0 +1,33 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 IITP RAS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Pavel Boyko + */ + +#ifndef AODV_H_ +#define AODV_H_ + +/** + * \ingroup routing + * \defgroup aodv AODV + * + * \brief RFC-conformant AODV model ported from ns-2 + * + * TODO more docs + */ + +#endif /* AODV_H_ */ diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript index 9cdea09f5..ab9728c1a 100644 --- a/src/routing/aodv/wscript +++ b/src/routing/aodv/wscript @@ -4,11 +4,12 @@ def build(bld): module = bld.create_ns3_module('aodv', ['internet-stack', 'contrib']) module.includes = '.' module.source = [ + 'aodv-rtable.cc', ] headers = bld.new_task_gen('ns3header') headers.module = 'aodv' headers.source = [ - 'aodv.h', + 'aodv-rtable.h', ] diff --git a/src/wscript b/src/wscript index 3042c2356..ff748b5d6 100644 --- a/src/wscript +++ b/src/wscript @@ -31,6 +31,7 @@ all_modules = ( 'routing/global-routing', 'routing/static-routing', 'routing/list-routing', + 'routing/aodv', 'mobility', 'devices/wifi', 'helper', From 8e3b38b9d7cd7da2607b1f6754a5e5e04574a2b0 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 2 Jul 2009 14:52:34 +0400 Subject: [PATCH 004/191] cosmetics --- src/routing/aodv/aodv-rtable.h | 91 ++++++++++++++++------------------ 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index da05051b5..fe5ccab86 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -35,8 +35,9 @@ namespace aodv { #define INFINITY2 0xff -/* - AODV Neighbor Cache Entry +/** + * \ingroup aodv + * \brief AODV Neighbor Cache Entry */ class AODV_Neighbor { @@ -51,8 +52,10 @@ protected: Time nb_expire; }; -/* - AODV Precursor list data structure +/** + * \ingroup aodv + * + * \brief AODV Precursor list data structure */ class AODV_Precursor { @@ -69,10 +72,10 @@ protected: Ipv4Address pc_addr; // precursor address }; -/* - Route Table Entry +/** + * \ingroup aodv + * \brief Route Table Entry */ - class aodv_rt_entry { friend class aodv_rtable; @@ -83,15 +86,15 @@ public: aodv_rt_entry(); ~aodv_rt_entry(); - void nb_insert(Ipv4Address id); + void nb_insert(Ipv4Address id); /// Lookup neighbor by address, return true on success bool nb_lookup(Ipv4Address id, AODV_Neighbor & n); - void pc_insert(Ipv4Address id); + void pc_insert(Ipv4Address id); /// Lookup precursor by address, return true on success bool pc_lookup(Ipv4Address id, AODV_Precursor & p); - void pc_delete(Ipv4Address id); - void pc_delete(); - bool pc_empty() const; + void pc_delete(Ipv4Address id); + void pc_delete(); + bool pc_empty() const; /// Compare destination address bool operator==(Ipv4Address id) const @@ -99,53 +102,45 @@ public: return rt_dst == id; } - double rt_req_timeout; // when I can send another req - u_int8_t rt_req_cnt; // number of route requests + /// when I can send another req + double rt_req_timeout; + /// number of route requests + u_int8_t rt_req_cnt; protected: - Ipv4Address rt_dst; - u_int32_t rt_seqno; + Ipv4Address rt_dst; + u_int32_t rt_seqno; /* u_int8_t rt_interface; */ - u_int16_t rt_hops; // hop count - int rt_last_hop_count; // last valid hop count - Ipv4Address rt_nexthop; // next hop IP address - /* list of precursors */ + /// hop count + u_int16_t rt_hops; + /// last valid hop count + int rt_last_hop_count; + /// next hop IP address + Ipv4Address rt_nexthop; + /// list of precursors std::vector rt_pclist; - double rt_expire; // when entry expires - u_int8_t rt_flags; + /// when entry expires + double rt_expire; + u_int8_t rt_flags; -#define RTF_DOWN 0 -#define RTF_UP 1 -#define RTF_IN_REPAIR 2 +#define RTF_DOWN 0 +#define RTF_UP 1 +#define RTF_IN_REPAIR 2 +#define MAX_HISTORY 3 - /* - * Must receive 4 errors within 3 seconds in order to mark - * the route down. - u_int8_t rt_errors; // error count - double rt_error_time; -#define MAX_RT_ERROR 4 // errors -#define MAX_RT_ERROR_TIME 3 // seconds - */ - -#define MAX_HISTORY 3 - double rt_disc_latency[MAX_HISTORY]; - char hist_indx; - int rt_req_last_ttl; // last ttl value used - // last few route discovery latencies - // double rt_length [MAX_HISTORY]; - // last few route lengths - - /* - * a list of neighbors that are using this route. - */ + double rt_disc_latency[MAX_HISTORY]; + char hist_indx; + /// last ttl value used + int rt_req_last_ttl; + /// a list of neighbors that are using this route. std::vector rt_nblist; }; -/* - The Routing Table +/** + * \ingroup aodv + * The Routing Table */ - class aodv_rtable { public: From a24a8fef881d23b2d74fd9413f40de176c0af7ee Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 3 Jul 2009 15:09:25 +0400 Subject: [PATCH 005/191] AODV queue added --- src/routing/aodv/aodv-rqueue.cc | 146 ++++++++++++++++++++++++++++++++ src/routing/aodv/aodv-rqueue.h | 83 ++++++++++++++++++ src/routing/aodv/wscript | 2 + 3 files changed, 231 insertions(+) create mode 100644 src/routing/aodv/aodv-rqueue.cc create mode 100644 src/routing/aodv/aodv-rqueue.h diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc new file mode 100644 index 000000000..6e960cb85 --- /dev/null +++ b/src/routing/aodv/aodv-rqueue.cc @@ -0,0 +1,146 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ + +#include +#include "aodv-rqueue.h" +#include "ns3/simulator.h" +#include + + +namespace ns3 { + namespace aodv { + +#define CURRENT_TIME Simulator::Now() + /* + Packet Queue used by AODV. + */ + + aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT) + { + } + + void + aodv_rqueue::enque(QueueEntry entry) { + /* + * Purge any packets that have timed out. + */ + purge(); + entry.enExpire = CURRENT_TIME + timeout_; + + if (queue.size() == limit_) { + // decrements lenght of queue + QueueEntry *p0 = remove_head(); + NS_ASSERT(p0); + if(p0->enExpire > CURRENT_TIME) + { + // drop(p0, DROP_RTR_QFULL); + drop(); + } + else { + // drop(p0, DROP_RTR_QTIMEOUT); + drop(); + } + } + queue.push_back(entry); + + } + + + QueueEntry* + aodv_rqueue::deque() { + QueueEntry * entry; + /* + * Purge any packets that have timed out. + */ + purge(); + entry = remove_head(); + return entry; + + } + + + bool + aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry) + { + /* + * Purge any packets that have timed out. + */ + purge(); + for( std::vector::iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + { + entry = *i; + queue.erase(i); + return true; + } + return false; + } + + bool + aodv_rqueue::find(Ipv4Address dst) + { + for( std::vector::const_iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + return true; + return false; + } + + + + + /* + Private Routines + */ + + QueueEntry* + aodv_rqueue::remove_head() { + QueueEntry * entry = &queue.front(); + queue.erase(queue.begin()); + return entry; + } + + + + + + + + + void + aodv_rqueue::purge() + { + QueueEntry * entry; + for( std::vector::iterator i = queue.begin(); i != queue.end(); ++i) + if(i->enExpire > CURRENT_TIME) + { + entry = &(*i); + queue.erase(i); + // drop(entry, DROP_RTR_QTIMEOUT); + drop(); + } + } + + + + }} diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h new file mode 100644 index 000000000..519f76720 --- /dev/null +++ b/src/routing/aodv/aodv-rqueue.h @@ -0,0 +1,83 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ + + + + + + +#ifndef __aodv_rqueue_h__ +#define __aodv_rqueue_h_ + +//#include +#include "ns3/ipv4-header.h" +#include "ns3/nstime.h" +#include "ns3/packet.h" +#include + +namespace ns3 { +namespace aodv { + + + /// The maximum number of packets that we allow a routing protocol to buffer. +#define AODV_RTQ_MAX_LEN 64 + + + /// The maximum period of time that a routing protocol is allowed to buffer a packet for. +#define AODV_RTQ_TIMEOUT 30 // seconds + +struct QueueEntry +{ + Ptr p; + Ipv4Header header; + Time enExpire; +}; + +inline void drop() {} +class aodv_rqueue { +public: + /// default c-tor + aodv_rqueue(); + /// Push element in queue. + void enque(QueueEntry entry); + /// Returns a element from the head of the queue. + QueueEntry * deque(); + + bool deque(Ipv4Address dst, QueueEntry & entry); + /// Finds whether a packet with destination dst exists in the queue + bool find(Ipv4Address dst); + +private: + std::vector queue; + QueueEntry * remove_head(); + void purge(); +// void findPacketWithDst(Ipv4Address dst, Packet*& p, Packet*& prev); + /// Find packet with destination address dst, return true + bool findPacketWithDst(Ipv4Address dst, QueueEntry & entry); + unsigned int limit_; + Time timeout_; +}; +}} + +#endif /* __aodv_rqueue_h__ */ diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript index ab9728c1a..3fcfcd242 100644 --- a/src/routing/aodv/wscript +++ b/src/routing/aodv/wscript @@ -5,11 +5,13 @@ def build(bld): module.includes = '.' module.source = [ 'aodv-rtable.cc', + 'aodv-rqueue.cc', ] headers = bld.new_task_gen('ns3header') headers.module = 'aodv' headers.source = [ 'aodv-rtable.h', + 'aodv-rqueue.h', ] From 62d10ad15689ced82b12587984217680de391dd4 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Fri, 3 Jul 2009 15:50:19 +0400 Subject: [PATCH 006/191] AODV rqueue fixes --- src/routing/aodv/aodv-rqueue.cc | 176 +++++++++++++------------------- src/routing/aodv/aodv-rqueue.h | 41 +++----- src/routing/aodv/aodv-rtable.h | 1 - 3 files changed, 86 insertions(+), 132 deletions(-) diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index 6e960cb85..660de27c8 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -22,125 +22,87 @@ * Ported to ns-3 by Elena Borovkova */ -#include #include "aodv-rqueue.h" #include "ns3/simulator.h" -#include - +#include namespace ns3 { - namespace aodv { +namespace aodv { -#define CURRENT_TIME Simulator::Now() - /* - Packet Queue used by AODV. - */ +aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT) +{ +} - aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT) - { - } +void +aodv_rqueue::enque(QueueEntry entry) +{ + // Purge any packets that have timed out. + purge(); + entry.enExpire = Simulator::Now() + timeout_; - void - aodv_rqueue::enque(QueueEntry entry) { - /* - * Purge any packets that have timed out. - */ - purge(); - entry.enExpire = CURRENT_TIME + timeout_; + if (queue.size() == limit_) drop(remove_head()); // drop the most aged packet + queue.push_back(entry); +} - if (queue.size() == limit_) { - // decrements lenght of queue - QueueEntry *p0 = remove_head(); - NS_ASSERT(p0); - if(p0->enExpire > CURRENT_TIME) - { - // drop(p0, DROP_RTR_QFULL); - drop(); - } - else { - // drop(p0, DROP_RTR_QTIMEOUT); - drop(); - } +QueueEntry +aodv_rqueue::deque() +{ + purge(); + return remove_head(); +} + +bool +aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry) +{ + purge(); + for(std::vector::iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + { + entry = *i; + queue.erase(i); + return true; } - queue.push_back(entry); + return false; +} - } +bool +aodv_rqueue::find(Ipv4Address dst) +{ + for( std::vector::const_iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + return true; + return false; +} +QueueEntry +aodv_rqueue::remove_head() +{ + QueueEntry entry = queue.front(); + queue.erase(queue.begin()); + return entry; +} - QueueEntry* - aodv_rqueue::deque() { - QueueEntry * entry; - /* - * Purge any packets that have timed out. - */ - purge(); - entry = remove_head(); - return entry; +struct IsExpired +{ + bool operator() (QueueEntry const & e) const + { + return (e.enExpire > Simulator::Now()); + } +}; - } +void +aodv_rqueue::purge() +{ + std::vector::iterator i = std::remove_if(queue.begin(), queue.end(), IsExpired()); + for (std::vector::iterator j = i ; j < queue.end(); ++j) + drop (*j); + queue.erase(i, queue.end()); +} +void +aodv_rqueue::drop(QueueEntry) +{ + // TODO do nothing now. +} - bool - aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry) - { - /* - * Purge any packets that have timed out. - */ - purge(); - for( std::vector::iterator i = queue.begin(); i != queue.end(); ++i) - if(i->header.GetDestination() == dst) - { - entry = *i; - queue.erase(i); - return true; - } - return false; - } - - bool - aodv_rqueue::find(Ipv4Address dst) - { - for( std::vector::const_iterator i = queue.begin(); i != queue.end(); ++i) - if(i->header.GetDestination() == dst) - return true; - return false; - } - - - - - /* - Private Routines - */ - - QueueEntry* - aodv_rqueue::remove_head() { - QueueEntry * entry = &queue.front(); - queue.erase(queue.begin()); - return entry; - } - - - - - - - - - void - aodv_rqueue::purge() - { - QueueEntry * entry; - for( std::vector::iterator i = queue.begin(); i != queue.end(); ++i) - if(i->enExpire > CURRENT_TIME) - { - entry = &(*i); - queue.erase(i); - // drop(entry, DROP_RTR_QTIMEOUT); - drop(); - } - } - - - - }} +}} diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index 519f76720..27faa2779 100644 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -21,16 +21,9 @@ * * Ported to ns-3 by Elena Borovkova */ - - - - - - #ifndef __aodv_rqueue_h__ #define __aodv_rqueue_h_ -//#include #include "ns3/ipv4-header.h" #include "ns3/nstime.h" #include "ns3/packet.h" @@ -39,13 +32,10 @@ namespace ns3 { namespace aodv { - - /// The maximum number of packets that we allow a routing protocol to buffer. -#define AODV_RTQ_MAX_LEN 64 - - - /// The maximum period of time that a routing protocol is allowed to buffer a packet for. -#define AODV_RTQ_TIMEOUT 30 // seconds +/// The maximum number of packets that we allow a routing protocol to buffer. +#define AODV_RTQ_MAX_LEN 64 +/// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds. +#define AODV_RTQ_TIMEOUT 30 struct QueueEntry { @@ -54,29 +44,32 @@ struct QueueEntry Time enExpire; }; -inline void drop() {} -class aodv_rqueue { +class aodv_rqueue +{ public: /// default c-tor aodv_rqueue(); /// Push element in queue. - void enque(QueueEntry entry); + void enque(QueueEntry entry); /// Returns a element from the head of the queue. - QueueEntry * deque(); - + QueueEntry deque(); + /// Return first found (the earliest) entry for given destination bool deque(Ipv4Address dst, QueueEntry & entry); /// Finds whether a packet with destination dst exists in the queue bool find(Ipv4Address dst); private: std::vector queue; - QueueEntry * remove_head(); + /// Remove and return first entry from queue + QueueEntry remove_head(); void purge(); -// void findPacketWithDst(Ipv4Address dst, Packet*& p, Packet*& prev); - /// Find packet with destination address dst, return true + /// Find packet with destination address dst, return true on success bool findPacketWithDst(Ipv4Address dst, QueueEntry & entry); - unsigned int limit_; - Time timeout_; + /// Notify that packet is dropped from queue by timeout + void drop (QueueEntry e); + + uint32_t limit_; + Time timeout_; }; }} diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index fe5ccab86..97793a80d 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -136,7 +136,6 @@ protected: std::vector rt_nblist; }; - /** * \ingroup aodv * The Routing Table From 24522ff8442a5db84800389cef810bb6b8a4cdc1 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Fri, 3 Jul 2009 16:42:51 +0400 Subject: [PATCH 007/191] Unit test for rqueue added --- examples/wscript | 325 ++++++++++++++++---------------- samples/wscript | 103 +++++----- src/routing/aodv/aodv-rqueue.cc | 87 ++++++++- src/routing/aodv/aodv-rqueue.h | 16 +- 4 files changed, 311 insertions(+), 220 deletions(-) diff --git a/examples/wscript b/examples/wscript index 906355a4f..ff9b1b958 100644 --- a/examples/wscript +++ b/examples/wscript @@ -1,165 +1,166 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - obj = bld.create_ns3_program('hello-simulator') - obj.source = 'hello-simulator.cc' - - obj = bld.create_ns3_program('first', - ['core', 'simulator', 'point-to-point', 'internet-stack']) - obj.source = 'first.cc' - - obj = bld.create_ns3_program('second', - ['core', 'simulator', 'point-to-point', 'csma', 'internet-stack']) - obj.source = 'second.cc' - - obj = bld.create_ns3_program('third', - ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack']) - obj.source = 'third.cc' - - obj = bld.create_ns3_program('object-names', - ['core', 'simulator', 'csma', 'internet-stack']) - obj.source = 'object-names.cc' - - obj = bld.create_ns3_program('mixed-wireless', - ['core', 'simulator', 'mobility', 'wifi', 'point-to-point', 'internet-stack']) - obj.source = 'mixed-wireless.cc' - - obj = bld.create_ns3_program('dynamic-global-routing', - ['point-to-point', 'csma', 'internet-stack', 'global-routing']) - obj.source = 'dynamic-global-routing.cc' - - obj = bld.create_ns3_program('static-routing-slash32', - ['point-to-point', 'internet-stack', 'global-routing']) - obj.source = 'static-routing-slash32.cc' - - obj = bld.create_ns3_program('global-routing-slash32', - ['point-to-point', 'internet-stack', 'global-routing']) - obj.source = 'global-routing-slash32.cc' - - obj = bld.create_ns3_program('simple-global-routing', - ['point-to-point', 'internet-stack', 'global-routing']) - obj.source = 'simple-global-routing.cc' - - obj = bld.create_ns3_program('virtual-net-device', - ['point-to-point', 'internet-stack', 'global-routing', 'virtual-net-device']) - obj.source = 'virtual-net-device.cc' - - obj = bld.create_ns3_program('simple-alternate-routing', - ['point-to-point', 'internet-stack', 'global-routing']) - obj.source = 'simple-alternate-routing.cc' - - obj = bld.create_ns3_program('simple-error-model', - ['point-to-point', 'internet-stack']) - obj.source = 'simple-error-model.cc' - - obj = bld.create_ns3_program('csma-one-subnet', - ['csma', 'internet-stack']) - obj.source = 'csma-one-subnet.cc' - - obj = bld.create_ns3_program('csma-bridge', - ['bridge', 'csma', 'internet-stack']) - obj.source = 'csma-bridge.cc' - - obj = bld.create_ns3_program('csma-bridge-one-hop', - ['bridge', 'csma', 'internet-stack']) - obj.source = 'csma-bridge-one-hop.cc' - - obj = bld.create_ns3_program('udp-echo', - ['csma', 'internet-stack']) - obj.source = 'udp-echo.cc' - - obj = bld.create_ns3_program('realtime-udp-echo', - ['csma', 'internet-stack']) - obj.source = 'realtime-udp-echo.cc' - - obj = bld.create_ns3_program('csma-broadcast', - ['csma', 'internet-stack']) - obj.source = 'csma-broadcast.cc' - - obj = bld.create_ns3_program('csma-packet-socket', - ['csma', 'internet-stack']) - obj.source = 'csma-packet-socket.cc' - - obj = bld.create_ns3_program('csma-multicast', - ['csma', 'internet-stack']) - obj.source = 'csma-multicast.cc' - - obj = bld.create_ns3_program( 'mixed-global-routing', - ['point-to-point', 'internet-stack', 'global-routing' , 'csma-cd']) - obj.source = 'mixed-global-routing.cc' - - obj = bld.create_ns3_program('simple-point-to-point-olsr', - ['point-to-point', 'internet-stack', 'olsr']) - obj.source = 'simple-point-to-point-olsr.cc' - - obj = bld.create_ns3_program('tcp-large-transfer', - ['point-to-point', 'internet-stack']) - obj.source = 'tcp-large-transfer.cc' - - obj = bld.create_ns3_program('tcp-nsc-lfn', - ['point-to-point', 'internet-stack']) - obj.source = 'tcp-nsc-lfn.cc' - - obj = bld.create_ns3_program('tcp-nsc-zoo', - ['csma', 'internet-stack']) - obj.source = 'tcp-nsc-zoo.cc' - - obj = bld.create_ns3_program('tcp-star-server', - ['point-to-point', 'internet-stack']) - obj.source = 'tcp-star-server.cc' - - obj = bld.create_ns3_program('star', - ['point-to-point', 'internet-stack']) - obj.source = 'star.cc' - - obj = bld.create_ns3_program('csma-star', - ['csma', 'internet-stack']) - obj.source = 'csma-star.cc' - - obj = bld.create_ns3_program('wifi-adhoc', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'wifi-adhoc.cc' - - obj = bld.create_ns3_program('wifi-clear-channel-cmu', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'wifi-clear-channel-cmu.cc' - - obj = bld.create_ns3_program('wifi-ap', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'wifi-ap.cc' - - bld.add_subdirs('stats') - - obj = bld.create_ns3_program('wifi-wired-bridging', - ['core', 'simulator', 'mobility', 'wifi', - 'csma', 'helper', 'bridge']) - obj.source = 'wifi-wired-bridging.cc' - - obj = bld.create_ns3_program('csma-raw-ip-socket', - ['csma', 'internet-stack']) - obj.source = 'csma-raw-ip-socket.cc' - - obj = bld.create_ns3_program('csma-ping', - ['csma', 'internet-stack', 'v4ping']) - obj.source = 'csma-ping.cc' - - obj = bld.create_ns3_program('test-ipv6', - ['point-to-point', 'internet-stack']) - obj.source = 'test-ipv6.cc' - - env = bld.env_of_name('default') - if env['ENABLE_EMU']: - obj = bld.create_ns3_program('emu-udp-echo', ['emu', 'internet-stack']) - obj.source = 'emu-udp-echo.cc' - - obj = bld.create_ns3_program('emu-ping', ['emu', 'internet-stack']) - obj.source = 'emu-ping.cc' - - if env['ENABLE_TAP']: - obj = bld.create_ns3_program('tap-wifi-dumbbell', - ['wifi', 'csma', 'point-to-point', 'tap-bridge', 'internet-stack']) - obj.source = 'tap-wifi-dumbbell.cc' - - obj = bld.create_ns3_program('simple-wifi-frame-aggregation', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'simple-wifi-frame-aggregation.cc' + print "Don't want to build examples" +# obj = bld.create_ns3_program('hello-simulator') +# obj.source = 'hello-simulator.cc' +# +# obj = bld.create_ns3_program('first', +# ['core', 'simulator', 'point-to-point', 'internet-stack']) +# obj.source = 'first.cc' +# +# obj = bld.create_ns3_program('second', +# ['core', 'simulator', 'point-to-point', 'csma', 'internet-stack']) +# obj.source = 'second.cc' +# +# obj = bld.create_ns3_program('third', +# ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack']) +# obj.source = 'third.cc' +# +# obj = bld.create_ns3_program('object-names', +# ['core', 'simulator', 'csma', 'internet-stack']) +# obj.source = 'object-names.cc' +# +# obj = bld.create_ns3_program('mixed-wireless', +# ['core', 'simulator', 'mobility', 'wifi', 'point-to-point', 'internet-stack']) +# obj.source = 'mixed-wireless.cc' +# +# obj = bld.create_ns3_program('dynamic-global-routing', +# ['point-to-point', 'csma', 'internet-stack', 'global-routing']) +# obj.source = 'dynamic-global-routing.cc' +# +# obj = bld.create_ns3_program('static-routing-slash32', +# ['point-to-point', 'internet-stack', 'global-routing']) +# obj.source = 'static-routing-slash32.cc' +# +# obj = bld.create_ns3_program('global-routing-slash32', +# ['point-to-point', 'internet-stack', 'global-routing']) +# obj.source = 'global-routing-slash32.cc' +# +# obj = bld.create_ns3_program('simple-global-routing', +# ['point-to-point', 'internet-stack', 'global-routing']) +# obj.source = 'simple-global-routing.cc' +# +# obj = bld.create_ns3_program('virtual-net-device', +# ['point-to-point', 'internet-stack', 'global-routing', 'virtual-net-device']) +# obj.source = 'virtual-net-device.cc' +# +# obj = bld.create_ns3_program('simple-alternate-routing', +# ['point-to-point', 'internet-stack', 'global-routing']) +# obj.source = 'simple-alternate-routing.cc' +# +# obj = bld.create_ns3_program('simple-error-model', +# ['point-to-point', 'internet-stack']) +# obj.source = 'simple-error-model.cc' +# +# obj = bld.create_ns3_program('csma-one-subnet', +# ['csma', 'internet-stack']) +# obj.source = 'csma-one-subnet.cc' +# +# obj = bld.create_ns3_program('csma-bridge', +# ['bridge', 'csma', 'internet-stack']) +# obj.source = 'csma-bridge.cc' +# +# obj = bld.create_ns3_program('csma-bridge-one-hop', +# ['bridge', 'csma', 'internet-stack']) +# obj.source = 'csma-bridge-one-hop.cc' +# +# obj = bld.create_ns3_program('udp-echo', +# ['csma', 'internet-stack']) +# obj.source = 'udp-echo.cc' +# +# obj = bld.create_ns3_program('realtime-udp-echo', +# ['csma', 'internet-stack']) +# obj.source = 'realtime-udp-echo.cc' +# +# obj = bld.create_ns3_program('csma-broadcast', +# ['csma', 'internet-stack']) +# obj.source = 'csma-broadcast.cc' +# +# obj = bld.create_ns3_program('csma-packet-socket', +# ['csma', 'internet-stack']) +# obj.source = 'csma-packet-socket.cc' +# +# obj = bld.create_ns3_program('csma-multicast', +# ['csma', 'internet-stack']) +# obj.source = 'csma-multicast.cc' +# +# obj = bld.create_ns3_program( 'mixed-global-routing', +# ['point-to-point', 'internet-stack', 'global-routing' , 'csma-cd']) +# obj.source = 'mixed-global-routing.cc' +# +# obj = bld.create_ns3_program('simple-point-to-point-olsr', +# ['point-to-point', 'internet-stack', 'olsr']) +# obj.source = 'simple-point-to-point-olsr.cc' +# +# obj = bld.create_ns3_program('tcp-large-transfer', +# ['point-to-point', 'internet-stack']) +# obj.source = 'tcp-large-transfer.cc' +# +# obj = bld.create_ns3_program('tcp-nsc-lfn', +# ['point-to-point', 'internet-stack']) +# obj.source = 'tcp-nsc-lfn.cc' +# +# obj = bld.create_ns3_program('tcp-nsc-zoo', +# ['csma', 'internet-stack']) +# obj.source = 'tcp-nsc-zoo.cc' +# +# obj = bld.create_ns3_program('tcp-star-server', +# ['point-to-point', 'internet-stack']) +# obj.source = 'tcp-star-server.cc' +# +# obj = bld.create_ns3_program('star', +# ['point-to-point', 'internet-stack']) +# obj.source = 'star.cc' +# +# obj = bld.create_ns3_program('csma-star', +# ['csma', 'internet-stack']) +# obj.source = 'csma-star.cc' +# +# obj = bld.create_ns3_program('wifi-adhoc', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'wifi-adhoc.cc' +# +# obj = bld.create_ns3_program('wifi-clear-channel-cmu', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'wifi-clear-channel-cmu.cc' +# +# obj = bld.create_ns3_program('wifi-ap', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'wifi-ap.cc' +# +# bld.add_subdirs('stats') +# +# obj = bld.create_ns3_program('wifi-wired-bridging', +# ['core', 'simulator', 'mobility', 'wifi', +# 'csma', 'helper', 'bridge']) +# obj.source = 'wifi-wired-bridging.cc' +# +# obj = bld.create_ns3_program('csma-raw-ip-socket', +# ['csma', 'internet-stack']) +# obj.source = 'csma-raw-ip-socket.cc' +# +# obj = bld.create_ns3_program('csma-ping', +# ['csma', 'internet-stack', 'v4ping']) +# obj.source = 'csma-ping.cc' +# +# obj = bld.create_ns3_program('test-ipv6', +# ['point-to-point', 'internet-stack']) +# obj.source = 'test-ipv6.cc' +# +# env = bld.env_of_name('default') +# if env['ENABLE_EMU']: +# obj = bld.create_ns3_program('emu-udp-echo', ['emu', 'internet-stack']) +# obj.source = 'emu-udp-echo.cc' +# +# obj = bld.create_ns3_program('emu-ping', ['emu', 'internet-stack']) +# obj.source = 'emu-ping.cc' +# +# if env['ENABLE_TAP']: +# obj = bld.create_ns3_program('tap-wifi-dumbbell', +# ['wifi', 'csma', 'point-to-point', 'tap-bridge', 'internet-stack']) +# obj.source = 'tap-wifi-dumbbell.cc' +# +# obj = bld.create_ns3_program('simple-wifi-frame-aggregation', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'simple-wifi-frame-aggregation.cc' diff --git a/samples/wscript b/samples/wscript index c7f9e9a81..d026c1382 100644 --- a/samples/wscript +++ b/samples/wscript @@ -1,56 +1,57 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - obj = bld.create_ns3_program('main-attribute-value') - obj.source = 'main-attribute-value.cc' - - obj = bld.create_ns3_program('main-callback') - obj.source = 'main-callback.cc' - - obj = bld.create_ns3_program('main-simulator') - obj.source = 'main-simulator.cc' - - obj = bld.create_ns3_program('main-ptr') - obj.source = 'main-ptr.cc' - - obj = bld.create_ns3_program('main-random-variable') - obj.source = 'main-random-variable.cc' - - obj = bld.create_ns3_program('main-packet-header', ['common', 'simulator']) - obj.source = 'main-packet-header.cc' - - obj = bld.create_ns3_program('main-packet-tag', ['common', 'simulator']) - obj.source = 'main-packet-tag.cc' - - obj = bld.create_ns3_program('main-test') - obj.source = 'main-test.cc' - - if bld.env['ENABLE_THREADING'] and bld.env["ENABLE_REAL_TIME"]: - obj = bld.create_ns3_program('main-test-sync') - obj.source = 'main-test-sync.cc' - - obj = bld.create_ns3_program('main-simple', - ['node', 'internet-stack', 'onoff']) - obj.source = 'main-simple.cc' - - obj = bld.create_ns3_program('main-grid-topology', - ['core', 'simulator', 'mobility', 'internet-stack']) - obj.source = 'main-grid-topology.cc' - - obj = bld.create_ns3_program('main-random-topology', - ['core', 'simulator', 'mobility']) - obj.source = 'main-random-topology.cc' - - obj = bld.create_ns3_program('main-random-walk', - ['core', 'simulator', 'mobility']) - obj.source = 'main-random-walk.cc' - - obj = bld.create_ns3_program('main-propagation-loss', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'main-propagation-loss.cc' - - obj = bld.create_ns3_program('main-ns2-mob', - ['core', 'simulator', 'mobility', 'wifi']) - obj.source = 'main-ns2-mob.cc' + print "Don't want to build samples" +# obj = bld.create_ns3_program('main-attribute-value') +# obj.source = 'main-attribute-value.cc' +# +# obj = bld.create_ns3_program('main-callback') +# obj.source = 'main-callback.cc' +# +# obj = bld.create_ns3_program('main-simulator') +# obj.source = 'main-simulator.cc' +# +# obj = bld.create_ns3_program('main-ptr') +# obj.source = 'main-ptr.cc' +# +# obj = bld.create_ns3_program('main-random-variable') +# obj.source = 'main-random-variable.cc' +# +# obj = bld.create_ns3_program('main-packet-header', ['common', 'simulator']) +# obj.source = 'main-packet-header.cc' +# +# obj = bld.create_ns3_program('main-packet-tag', ['common', 'simulator']) +# obj.source = 'main-packet-tag.cc' +# +# obj = bld.create_ns3_program('main-test') +# obj.source = 'main-test.cc' +# +# if bld.env['ENABLE_THREADING'] and bld.env["ENABLE_REAL_TIME"]: +# obj = bld.create_ns3_program('main-test-sync') +# obj.source = 'main-test-sync.cc' +# +# obj = bld.create_ns3_program('main-simple', +# ['node', 'internet-stack', 'onoff']) +# obj.source = 'main-simple.cc' +# +# obj = bld.create_ns3_program('main-grid-topology', +# ['core', 'simulator', 'mobility', 'internet-stack']) +# obj.source = 'main-grid-topology.cc' +# +# obj = bld.create_ns3_program('main-random-topology', +# ['core', 'simulator', 'mobility']) +# obj.source = 'main-random-topology.cc' +# +# obj = bld.create_ns3_program('main-random-walk', +# ['core', 'simulator', 'mobility']) +# obj.source = 'main-random-walk.cc' +# +# obj = bld.create_ns3_program('main-propagation-loss', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'main-propagation-loss.cc' +# +# obj = bld.create_ns3_program('main-ns2-mob', +# ['core', 'simulator', 'mobility', 'wifi']) +# obj.source = 'main-ns2-mob.cc' diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index 660de27c8..1bb1b7131 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -24,17 +24,25 @@ #include "aodv-rqueue.h" #include "ns3/simulator.h" +#include "ns3/test.h" #include namespace ns3 { namespace aodv { -aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT) +aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(Seconds(AODV_RTQ_TIMEOUT)) { } +uint32_t +aodv_rqueue::size () +{ + purge(); + return queue.size(); +} + void -aodv_rqueue::enque(QueueEntry entry) +aodv_rqueue::enque(QueueEntry & entry) { // Purge any packets that have timed out. purge(); @@ -78,7 +86,7 @@ QueueEntry aodv_rqueue::remove_head() { QueueEntry entry = queue.front(); - queue.erase(queue.begin()); + queue.erase(queue.begin()); return entry; } @@ -86,7 +94,7 @@ struct IsExpired { bool operator() (QueueEntry const & e) const { - return (e.enExpire > Simulator::Now()); + return (e.enExpire < Simulator::Now()); } }; @@ -105,4 +113,75 @@ aodv_rqueue::drop(QueueEntry) // TODO do nothing now. } +#ifdef RUN_SELF_TESTS +/// Unit test for aodv_rqueue +struct AodvRqueueTest : public Test +{ + AodvRqueueTest () : Test ("AODV/Rqueue"), result(true) {} + virtual bool RunTests(); + + void CheckSizeLimit (); + void CheckTimeout (); + + aodv_rqueue q; + bool result; +}; + +/// Test instance +static AodvRqueueTest g_AodvRqueueTest; + +bool +AodvRqueueTest::RunTests () +{ + Ptr packet = Create(); + Ipv4Header header; + QueueEntry e1 (packet, header); + q.enque (e1); + QueueEntry e2 = q.deque (); + NS_TEST_ASSERT (e1 == e2); + + Ipv4Address dst("1.2.3.4"); + header.SetDestination (dst); + e1 = QueueEntry (packet, header); + q.enque (e1); + + bool ok = q.deque (dst, e2); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT (e1 == e2); + NS_TEST_ASSERT (! q.find(dst)); + q.enque (e1); + NS_TEST_ASSERT (q.find(dst)); + + CheckSizeLimit (); + + Simulator::Schedule (Seconds(AODV_RTQ_TIMEOUT+1), & AodvRqueueTest::CheckTimeout, this); + + Simulator::Run (); + Simulator::Destroy (); + + return result; +} + +void +AodvRqueueTest::CheckSizeLimit () +{ + Ptr packet = Create(); + Ipv4Header header; + QueueEntry e1 (packet, header); + + for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) + q.enque (e1); + NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); + + for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) + q.enque (e1); + NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); +} + +void +AodvRqueueTest::CheckTimeout () +{ + NS_TEST_ASSERT (q.size() == 0); +} +#endif }} diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index 27faa2779..5fce86047 100644 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -33,15 +33,22 @@ namespace ns3 { namespace aodv { /// The maximum number of packets that we allow a routing protocol to buffer. -#define AODV_RTQ_MAX_LEN 64 +#define AODV_RTQ_MAX_LEN 64 /// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds. -#define AODV_RTQ_TIMEOUT 30 +#define AODV_RTQ_TIMEOUT 30 struct QueueEntry { Ptr p; Ipv4Header header; Time enExpire; + + QueueEntry(Ptr pa, Ipv4Header const & h, Time exp = Seconds(0)) : p(pa), header(h), enExpire(exp) {} + + bool operator==(QueueEntry const & o) const + { + return ((p == o.p)/*&& header == o.header*/ && (enExpire == o.enExpire)); + } }; class aodv_rqueue @@ -50,18 +57,21 @@ public: /// default c-tor aodv_rqueue(); /// Push element in queue. - void enque(QueueEntry entry); + void enque(QueueEntry & entry); /// Returns a element from the head of the queue. QueueEntry deque(); /// Return first found (the earliest) entry for given destination bool deque(Ipv4Address dst, QueueEntry & entry); /// Finds whether a packet with destination dst exists in the queue bool find(Ipv4Address dst); + /// Number of entries + uint32_t size(); private: std::vector queue; /// Remove and return first entry from queue QueueEntry remove_head(); + /// Remove all expired entries void purge(); /// Find packet with destination address dst, return true on success bool findPacketWithDst(Ipv4Address dst, QueueEntry & entry); From 9c3edb1309f6e41f866b341770c29c75e6d319f9 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Sun, 5 Jul 2009 16:59:03 +0400 Subject: [PATCH 008/191] aodv_rtable unit test added --- src/routing/aodv/aodv-rqueue.cc | 282 ++++++++++++++++---------------- src/routing/aodv/aodv-rqueue.h | 10 +- src/routing/aodv/aodv-rtable.cc | 160 ++++++++++++------ src/routing/aodv/aodv-rtable.h | 135 ++++++++++----- src/routing/aodv/aodv.h | 0 src/routing/aodv/rfc3561.txt | 2 +- 6 files changed, 359 insertions(+), 230 deletions(-) mode change 100644 => 100755 src/routing/aodv/aodv-rqueue.cc mode change 100644 => 100755 src/routing/aodv/aodv-rqueue.h mode change 100644 => 100755 src/routing/aodv/aodv-rtable.cc mode change 100644 => 100755 src/routing/aodv/aodv-rtable.h mode change 100644 => 100755 src/routing/aodv/aodv.h mode change 100644 => 100755 src/routing/aodv/rfc3561.txt diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc old mode 100644 new mode 100755 index 1bb1b7131..ce82e9e5d --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -28,160 +28,164 @@ #include namespace ns3 { -namespace aodv { + namespace aodv { -aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(Seconds(AODV_RTQ_TIMEOUT)) -{ -} + aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(Seconds(AODV_RTQ_TIMEOUT)) + { + } -uint32_t -aodv_rqueue::size () -{ - purge(); - return queue.size(); -} + uint32_t + aodv_rqueue::size () + { + purge(); + return queue.size(); + } -void -aodv_rqueue::enque(QueueEntry & entry) -{ - // Purge any packets that have timed out. - purge(); - entry.enExpire = Simulator::Now() + timeout_; + void + aodv_rqueue::enque(QueueEntry & entry) + { + // Purge any packets that have timed out. + purge(); + entry.enExpire = Simulator::Now() + timeout_; - if (queue.size() == limit_) drop(remove_head()); // drop the most aged packet - queue.push_back(entry); -} + if (queue.size() == limit_) drop(remove_head()); // drop the most aged packet + queue.push_back(entry); + } -QueueEntry -aodv_rqueue::deque() -{ - purge(); - return remove_head(); -} + QueueEntry + aodv_rqueue::deque() + { + purge(); + return remove_head(); + } -bool -aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry) -{ - purge(); - for(std::vector::iterator i = queue.begin(); i != queue.end(); ++i) - if(i->header.GetDestination() == dst) + bool + aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry) + { + purge(); + for(std::vector::iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + { + entry = *i; + queue.erase(i); + return true; + } + return false; + } + + bool + aodv_rqueue::find(Ipv4Address dst) + { + for( std::vector::const_iterator i = queue.begin(); i != queue.end(); ++i) + if(i->header.GetDestination() == dst) + return true; + return false; + } + + QueueEntry + aodv_rqueue::remove_head() + { + QueueEntry entry = queue.front(); + queue.erase(queue.begin()); + return entry; + } + + struct IsExpired + { + bool operator() (QueueEntry const & e) const { - entry = *i; - queue.erase(i); - return true; + return (e.enExpire < Simulator::Now()); } - return false; -} + }; -bool -aodv_rqueue::find(Ipv4Address dst) -{ - for( std::vector::const_iterator i = queue.begin(); i != queue.end(); ++i) - if(i->header.GetDestination() == dst) - return true; - return false; -} + void + aodv_rqueue::purge() + { + std::vector::iterator i = std::remove_if(queue.begin(), queue.end(), IsExpired()); + for (std::vector::iterator j = i ; j < queue.end(); ++j) + drop (*j); + queue.erase(i, queue.end()); + } -QueueEntry -aodv_rqueue::remove_head() -{ - QueueEntry entry = queue.front(); - queue.erase(queue.begin()); - return entry; -} - -struct IsExpired -{ - bool operator() (QueueEntry const & e) const - { - return (e.enExpire < Simulator::Now()); - } -}; - -void -aodv_rqueue::purge() -{ - std::vector::iterator i = std::remove_if(queue.begin(), queue.end(), IsExpired()); - for (std::vector::iterator j = i ; j < queue.end(); ++j) - drop (*j); - queue.erase(i, queue.end()); -} - -void -aodv_rqueue::drop(QueueEntry) -{ - // TODO do nothing now. -} + void + aodv_rqueue::drop(QueueEntry) + { + // TODO do nothing now. + } #ifdef RUN_SELF_TESTS -/// Unit test for aodv_rqueue -struct AodvRqueueTest : public Test -{ - AodvRqueueTest () : Test ("AODV/Rqueue"), result(true) {} - virtual bool RunTests(); - - void CheckSizeLimit (); - void CheckTimeout (); - - aodv_rqueue q; - bool result; -}; + /// Unit test for aodv_rqueue + struct AodvRqueueTest : public Test + { + AodvRqueueTest () : Test ("AODV/Rqueue"), result(true) {} + virtual bool RunTests(); -/// Test instance -static AodvRqueueTest g_AodvRqueueTest; + void CheckSizeLimit (); + void CheckTimeout (); -bool -AodvRqueueTest::RunTests () -{ - Ptr packet = Create(); - Ipv4Header header; - QueueEntry e1 (packet, header); - q.enque (e1); - QueueEntry e2 = q.deque (); - NS_TEST_ASSERT (e1 == e2); - - Ipv4Address dst("1.2.3.4"); - header.SetDestination (dst); - e1 = QueueEntry (packet, header); - q.enque (e1); - - bool ok = q.deque (dst, e2); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT (e1 == e2); - NS_TEST_ASSERT (! q.find(dst)); - q.enque (e1); - NS_TEST_ASSERT (q.find(dst)); - - CheckSizeLimit (); - - Simulator::Schedule (Seconds(AODV_RTQ_TIMEOUT+1), & AodvRqueueTest::CheckTimeout, this); - - Simulator::Run (); - Simulator::Destroy (); - - return result; -} + aodv_rqueue q; + bool result; + }; -void -AodvRqueueTest::CheckSizeLimit () -{ - Ptr packet = Create(); - Ipv4Header header; - QueueEntry e1 (packet, header); - - for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) - q.enque (e1); - NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); - - for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) + /// Test instance + static AodvRqueueTest g_AodvRqueueTest; + + bool + AodvRqueueTest::RunTests () + { + Ptr packet = Create(); + Ipv4Header header; + QueueEntry e1 (packet, header); q.enque (e1); - NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); -} + QueueEntry e2 = q.deque (); + NS_TEST_ASSERT (e1 == e2); -void -AodvRqueueTest::CheckTimeout () -{ - NS_TEST_ASSERT (q.size() == 0); -} + Ipv4Address dst("1.2.3.4"); + header.SetDestination (dst); + e1 = QueueEntry (packet, header); + q.enque (e1); + + bool ok = q.deque (dst, e2); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT (e1 == e2); + NS_TEST_ASSERT (! q.find(dst)); + q.enque (e1); + NS_TEST_ASSERT (q.find(dst)); + + CheckSizeLimit (); + + Ipv4Header header2; + Ipv4Address dst2("1.2.3.4"); + header2.SetDestination (dst2); + + Simulator::Schedule (Seconds(AODV_RTQ_TIMEOUT+1), & AodvRqueueTest::CheckTimeout, this); + + Simulator::Run (); + Simulator::Destroy (); + + return result; + } + + void + AodvRqueueTest::CheckSizeLimit () + { + Ptr packet = Create(); + Ipv4Header header; + QueueEntry e1 (packet, header); + + for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) + q.enque (e1); + NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); + + for (uint32_t i = 0; i < AODV_RTQ_MAX_LEN; ++i) + q.enque (e1); + NS_TEST_ASSERT (q.size() == AODV_RTQ_MAX_LEN); + } + + void + AodvRqueueTest::CheckTimeout () + { + NS_TEST_ASSERT (q.size() == 0); + } #endif -}} + }} diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h old mode 100644 new mode 100755 index 5fce86047..812f7a82f --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -36,7 +36,10 @@ namespace aodv { #define AODV_RTQ_MAX_LEN 64 /// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds. #define AODV_RTQ_TIMEOUT 30 - +/** + * \ingroup aodv + * \brief AODV Queue Entry + */ struct QueueEntry { Ptr p; @@ -50,7 +53,10 @@ struct QueueEntry return ((p == o.p)/*&& header == o.header*/ && (enExpire == o.enExpire)); } }; - +/** + * \ingroup aodv + * \brief AODV Queue + */ class aodv_rqueue { public: diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc old mode 100644 new mode 100755 index 3704245b3..6259ac1ac --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -15,15 +15,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Authors: The AODV code developed by the CMU/MONARCH group was optimized and - * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. * The work was partially done in Sun Microsystems. - * + * * Ported to ns-3 by Elena Borovkova */ #include "aodv-rtable.h" #include +#include "ns3/test.h" namespace ns3 { namespace aodv { @@ -34,22 +35,17 @@ namespace aodv { aodv_rt_entry::aodv_rt_entry() { - rt_req_timeout = 0.0; + rt_req_timeout = MilliSeconds(0.0); rt_req_cnt = 0; - - rt_dst = 0; + rt_dst = Ipv4Address("127.0.0.1"); + validSeqNo = false; rt_seqno = 0; rt_hops = rt_last_hop_count = INFINITY2; - rt_nexthop = 0; - rt_expire = 0.0; + rt_nexthop = Ipv4Address("127.0.0.1"); + rt_lifetime = MilliSeconds(0.0); rt_flags = RTF_DOWN; - /* - rt_errors = 0; - rt_error_time = 0.0; - */ - - for (int i=0; i < MAX_HISTORY; i++) + for (int i=0; i < MAX_HISTORY; i++) { rt_disc_latency[i] = 0.0; } @@ -57,36 +53,33 @@ aodv_rt_entry::aodv_rt_entry() rt_req_last_ttl = 0; } +aodv_rt_entry::aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, + u_int16_t hops,Ipv4Address nextHop, Time lifetime) +{ + rt_dst = dst; + validSeqNo = vSeqNo; + if(validSeqNo == true) + rt_seqno = seqNo; + rt_hops = hops; + rt_nexthop = nextHop; + rt_lifetime = lifetime; +} aodv_rt_entry::~aodv_rt_entry() { } - -void -aodv_rt_entry::nb_insert(Ipv4Address id) -{ - rt_nblist.push_back(AODV_Neighbor(id)); -} - bool -aodv_rt_entry::nb_lookup(Ipv4Address id, AODV_Neighbor & n) -{ - for(std::vector::const_iterator i = rt_nblist.begin(); i != rt_nblist.end(); ++i) - if (i->nb_addr == id) - { - n = *i; - return true; - } - return false; -} - -void aodv_rt_entry::pc_insert(Ipv4Address id) { AODV_Precursor p (id); - - if (! pc_lookup(id, p)) rt_pclist.push_back(p); + + if (! pc_lookup(id, p)) + { + rt_pclist.push_back(p); + return true; + } + else return false; } bool @@ -101,18 +94,23 @@ aodv_rt_entry::pc_lookup(Ipv4Address id, AODV_Precursor & p) return false; } -void -aodv_rt_entry::pc_delete(Ipv4Address id) +bool +aodv_rt_entry::pc_delete(Ipv4Address id) { AODV_Precursor p(id); - rt_pclist.erase (std::remove(rt_pclist.begin(), rt_pclist.end(), p), rt_pclist.end()); + std::vector::iterator i = std::remove(rt_pclist.begin(), rt_pclist.end(), p); + if(i == rt_pclist.end()) + return false; + else + rt_pclist.erase (i, rt_pclist.end()); + return true; } void -aodv_rt_entry::pc_delete() +aodv_rt_entry::pc_delete() { rt_pclist.clear(); -} +} bool aodv_rt_entry::pc_empty() const @@ -127,24 +125,94 @@ aodv_rt_entry::pc_empty() const bool aodv_rtable::rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const { - std::vector::const_iterator i = std::find (rthead.begin(), rthead.end(), id); + std::vector::const_iterator i = std::find (rthead.begin(), rthead.end(), id); if (i == rthead.end()) return false; rt = *i; return true; } -void -aodv_rtable::rt_delete(Ipv4Address id) +bool +aodv_rtable::rt_delete(Ipv4Address dst) { - rthead.erase (std::remove(rthead.begin(), rthead.end(), id), rthead.end()); + std::vector::iterator i = std::remove(rthead.begin(), rthead.end(), dst); + if(i == rthead.end()) + return false; + rthead.erase (i, rthead.end()); + return true; } -void +bool aodv_rtable::rt_add(aodv_rt_entry const & rt) { aodv_rt_entry dummy; - NS_ASSERT(! rt_lookup(rt.rt_dst, dummy)); + if(rt_lookup(rt.rt_dst, dummy)) + return false; rthead.push_back(rt); + return true; } +#ifdef RUN_SELF_TESTS + /// Unit test for aodv_rqueue + struct AodvRtableTest : public Test + { + AodvRtableTest () : Test ("AODV/Rtable"), result(true) {} + virtual bool RunTests(); + bool result; + }; + + /// Test instance + static AodvRtableTest g_AodvRtableTest; + + bool + AodvRtableTest::RunTests () + { + AODV_Neighbor nb1(Ipv4Address("1.2.3.4")); + AODV_Neighbor nb2(Ipv4Address("4.3.2.1")); + NS_TEST_ASSERT(!(nb1==nb2)); + + AODV_Neighbor nb3(Ipv4Address("3.3.3.3")); + AODV_Neighbor nb4(Ipv4Address("3.3.3.3"), Seconds(1)); + NS_TEST_ASSERT(!(nb1==nb2)); + + AODV_Precursor pc1(Ipv4Address("1.1.1.1")); + AODV_Precursor pc2(Ipv4Address("2.2.2.2")); + NS_TEST_ASSERT(!(pc1==pc2)); + + aodv_rt_entry entry1; + Ipv4Address dst1("3.3.3.3"); + Ipv4Address dst2("1.2.3.4"); + aodv_rt_entry entry2 = aodv_rt_entry(dst2, true, 34, 1, Ipv4Address("5.5.5.5"), Seconds(5)); + NS_TEST_ASSERT( !(entry1 == dst1) ); + NS_TEST_ASSERT(entry2 == dst2); + + entry2.pc_insert(dst1); + AODV_Precursor pc3(dst1); + NS_TEST_ASSERT(entry2.pc_lookup(dst1, pc2)); + NS_TEST_ASSERT(pc3==pc2); + NS_TEST_ASSERT(!entry2.pc_delete(dst2)); + NS_TEST_ASSERT(entry2.pc_delete(dst1)); + NS_TEST_ASSERT(entry2.pc_empty()); + entry2.pc_insert(dst2); + NS_TEST_ASSERT(entry2.pc_insert(dst1)); + NS_TEST_ASSERT(!entry2.pc_insert(dst2)); + entry2.pc_delete(); + NS_TEST_ASSERT(entry2.pc_empty()); + + aodv_rtable rtable; + rtable.rt_add(entry2); + NS_TEST_ASSERT(rtable.rt_lookup(dst2, entry1)); + NS_TEST_ASSERT(entry1 == dst2); + NS_TEST_ASSERT(!rtable.rt_lookup(dst1, entry1)); + NS_TEST_ASSERT(rtable.rt_delete(dst2)); + NS_TEST_ASSERT(!rtable.rt_lookup(dst2, entry1)); + + + + + return result; + } + + +#endif + }} diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h old mode 100644 new mode 100755 index 97793a80d..5ef570ee3 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -15,10 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Authors: The AODV code developed by the CMU/MONARCH group was optimized and - * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. * The work was partially done in Sun Microsystems. - * + * * Ported to ns-3 by Elena Borovkova */ #ifndef __aodv_rtable_h__ @@ -29,6 +29,7 @@ #include #include "ns3/ipv4.h" #include "ns3/nstime.h" +#include "ns3/nstime.h" namespace ns3 { namespace aodv { @@ -39,13 +40,17 @@ namespace aodv { * \ingroup aodv * \brief AODV Neighbor Cache Entry */ -class AODV_Neighbor +class AODV_Neighbor { friend class AODV; friend class aodv_rt_entry; public: - AODV_Neighbor(Ipv4Address const & a) : nb_addr(a), nb_expire(Seconds(0)) {} + AODV_Neighbor(Ipv4Address const & a, Time exp = Seconds(0)) : nb_addr(a), nb_expire(exp) {} + bool operator==(AODV_Neighbor const & n) const + { + return (nb_addr == n.nb_addr)&&(nb_expire == n.nb_expire); + } protected: Ipv4Address nb_addr; @@ -54,73 +59,105 @@ protected: /** * \ingroup aodv - * + * * \brief AODV Precursor list data structure */ -class AODV_Precursor +class AODV_Precursor { friend class AODV; friend class aodv_rt_entry; public: AODV_Precursor(Ipv4Address const & a) : pc_addr(a) {} - bool operator==(AODV_Precursor const & o) const { return (pc_addr == o.pc_addr); } protected: - Ipv4Address pc_addr; // precursor address + /// Precursor address + Ipv4Address pc_addr; }; /** * \ingroup aodv * \brief Route Table Entry */ -class aodv_rt_entry +class aodv_rt_entry { friend class aodv_rtable; friend class AODV; friend class LocalRepairTimer; public: - /// TODO make functional c-tor - aodv_rt_entry(); + aodv_rt_entry(); + aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, + u_int16_t hops,Ipv4Address nextHop, Time lifetime); ~aodv_rt_entry(); - void nb_insert(Ipv4Address id); - /// Lookup neighbor by address, return true on success - bool nb_lookup(Ipv4Address id, AODV_Neighbor & n); - void pc_insert(Ipv4Address id); - /// Lookup precursor by address, return true on success +// void nb_insert(Ipv4Address id); +// /// Lookup neighbor by address, return true on success +// bool nb_lookup(Ipv4Address id, AODV_Neighbor & n); + /** + * Insert precursor in precursor list if it doesn't yet exist in the list + * \param id precursor address + * \return true on success + */ + bool pc_insert(Ipv4Address id); + /** + * Lookup precursor by address + * \param id precursor address + * \param p precursor with address id if exists + * \return true on success + */ bool pc_lookup(Ipv4Address id, AODV_Precursor & p); - void pc_delete(Ipv4Address id); + /** + * \brief Delete precursor + * \param id precursor address + * \return true on success + */ + bool pc_delete(Ipv4Address id); + /// Delete all precursors void pc_delete(); + /** + * \return true if precursor list empty + */ bool pc_empty() const; - - /// Compare destination address - bool operator==(Ipv4Address id) const + /** + * \brief Compare destination address + * \return true if equal + */ + bool operator==(Ipv4Address const dst) const { - return rt_dst == id; + return rt_dst == dst; } - /// when I can send another req - double rt_req_timeout; - /// number of route requests - u_int8_t rt_req_cnt; + /// When I can send another request + Time rt_req_timeout; + /// Number of route requests + u_int8_t rt_req_cnt; protected: + /// Destination address Ipv4Address rt_dst; + /// Valid Destination Sequence Number flag + bool validSeqNo; + /// Destination Sequence Number, if validSeqNo = true u_int32_t rt_seqno; /* u_int8_t rt_interface; */ - /// hop count + /// Hop Count (number of hops needed to reach destination) u_int16_t rt_hops; - /// last valid hop count + /// Last valid hop count int rt_last_hop_count; - /// next hop IP address - Ipv4Address rt_nexthop; - /// list of precursors + /// Next hop IP address + Ipv4Address rt_nexthop; + /// List of precursors std::vector rt_pclist; - /// when entry expires - double rt_expire; + /** + * \brief Expiration or deletion time of the route + * Lifetime field in the routing table plays dual role -- + * for an active route it is the expiry time, and for an invalid route + * it is the deletion time. + */ + Time rt_lifetime; + /// Routing flags: down, up or in repair u_int8_t rt_flags; #define RTF_DOWN 0 @@ -130,27 +167,41 @@ protected: double rt_disc_latency[MAX_HISTORY]; char hist_indx; - /// last ttl value used + /// Last ttl value used int rt_req_last_ttl; - /// a list of neighbors that are using this route. - std::vector rt_nblist; +// /// a list of neighbors that are using this route. +// std::vector rt_nblist; }; /** * \ingroup aodv * The Routing Table */ -class aodv_rtable +class aodv_rtable { public: aodv_rtable() {} // aodv_rt_entry * head() {TODO} - - void rt_add(aodv_rt_entry const & r); - void rt_delete(Ipv4Address id); - /// Lookup routing table entry by destination. Return true on success. - bool rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const; + /** + * Add routing table entry if it doesn't yet exist in routing table + * \param r routing table entry + * \return true in success + */ + bool rt_add(aodv_rt_entry const & r); + /** + * Delete routing table entry + * \param dst destination address + * \return true on success + */ + bool rt_delete(Ipv4Address dst); + /** + * Lookup routing table entry + * \param dst destination address + * \param rt entry with destination address dst, if exists + * \return true on success + */ + bool rt_lookup(Ipv4Address dst, aodv_rt_entry & rt) const; private: std::vector rthead; diff --git a/src/routing/aodv/aodv.h b/src/routing/aodv/aodv.h old mode 100644 new mode 100755 diff --git a/src/routing/aodv/rfc3561.txt b/src/routing/aodv/rfc3561.txt old mode 100644 new mode 100755 index 3b984ddb6..a63fd54b2 --- a/src/routing/aodv/rfc3561.txt +++ b/src/routing/aodv/rfc3561.txt @@ -1518,7 +1518,7 @@ RFC 3561 AODV Routing July 2003 It can be shown [4] that by the time the rebooted node comes out of the waiting phase and becomes an active router again, none of its - neighbors will be using it as an active next hop any more. Its own + iftrs will be using it as an active next hop any more. Its own sequence number gets updated once it receives a RREQ from any other node, as the RREQ always carries the maximum destination sequence number seen en route. If no such RREQ arrives, the node MUST From 150fcb3ac8dd46f88d9d1a64a3770dfb3841151e Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Sun, 5 Jul 2009 17:32:12 +0400 Subject: [PATCH 009/191] comments added --- src/routing/aodv/aodv-rqueue.h | 19 ++++++++++++------- src/routing/aodv/aodv-rtable.h | 6 ------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index 812f7a82f..becbb033f 100755 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -44,10 +44,14 @@ struct QueueEntry { Ptr p; Ipv4Header header; + /// Expire time for queue entry Time enExpire; - + /// c-tor QueueEntry(Ptr pa, Ipv4Header const & h, Time exp = Seconds(0)) : p(pa), header(h), enExpire(exp) {} - + /** + * Compare queue entries + * \return true if equal + */ bool operator==(QueueEntry const & o) const { return ((p == o.p)/*&& header == o.header*/ && (enExpire == o.enExpire)); @@ -60,13 +64,13 @@ struct QueueEntry class aodv_rqueue { public: - /// default c-tor + /// Default c-tor aodv_rqueue(); - /// Push element in queue. + /// Push entry in queue. void enque(QueueEntry & entry); - /// Returns a element from the head of the queue. + /// Returns a entry from the head of the queue. QueueEntry deque(); - /// Return first found (the earliest) entry for given destination + /// Return first found (the earliest) entry for given destination bool deque(Ipv4Address dst, QueueEntry & entry); /// Finds whether a packet with destination dst exists in the queue bool find(Ipv4Address dst); @@ -83,8 +87,9 @@ private: bool findPacketWithDst(Ipv4Address dst, QueueEntry & entry); /// Notify that packet is dropped from queue by timeout void drop (QueueEntry e); - + /// Maximum number of entries in queue uint32_t limit_; + /// Life time of queue entry in queue Time timeout_; }; }} diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 5ef570ee3..65963bbf7 100755 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -91,10 +91,6 @@ public: aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, u_int16_t hops,Ipv4Address nextHop, Time lifetime); ~aodv_rt_entry(); - -// void nb_insert(Ipv4Address id); -// /// Lookup neighbor by address, return true on success -// bool nb_lookup(Ipv4Address id, AODV_Neighbor & n); /** * Insert precursor in precursor list if it doesn't yet exist in the list * \param id precursor address @@ -169,8 +165,6 @@ protected: char hist_indx; /// Last ttl value used int rt_req_last_ttl; -// /// a list of neighbors that are using this route. -// std::vector rt_nblist; }; /** From 522442558818d1a60ed505766971270f8b59aa02 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Mon, 6 Jul 2009 12:44:34 +0400 Subject: [PATCH 010/191] Rtable cosmetics + RREQ header --- src/routing/aodv/aodv-packet.cc | 142 +++++++++++++++++++++++++++++++ src/routing/aodv/aodv-packet.h | 123 +++++++++++++++++++++++++++ src/routing/aodv/aodv-rtable.cc | 143 +++++++++++++++----------------- src/routing/aodv/aodv-rtable.h | 6 +- src/routing/aodv/wscript | 2 + 5 files changed, 338 insertions(+), 78 deletions(-) create mode 100644 src/routing/aodv/aodv-packet.cc create mode 100644 src/routing/aodv/aodv-packet.h diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc new file mode 100644 index 000000000..493029521 --- /dev/null +++ b/src/routing/aodv/aodv-packet.cc @@ -0,0 +1,142 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ +#include "aodv-packet.h" +#include "ns3/address-utils.h" + +namespace ns3 { +namespace aodv { + +//----------------------------------------------------------------------------- +// RREQ +//----------------------------------------------------------------------------- +RreqHeader::RreqHeader () : rq_flags(0), reserved(0), rq_hop_count(0), rq_bcast_id(0), rq_dst_seqno(0), rq_src_seqno(0) +{ + // TODO check defaults in AODV UU + SetGratiousRrep (false); + SetDestinationOnly (false); + SetUnknownSeqno (false); +} + +uint32_t +RreqHeader::GetSerializedSize () +{ + return 24; +} + +void +RreqHeader::Serialize (Buffer::Iterator i) +{ + i.WriteU8 (type()); + i.WriteU8 (rq_flags); + i.WriteU8 (reserved); + i.WriteU8 (rq_hop_count); + i.WriteHtonU32 (rq_bcast_id); + WriteTo (i, rq_dst); + i.WriteHtonU32 (rq_dst_seqno); + WriteTo (i, rq_src); + i.WriteHtonU32 (rq_src_seqno); +} + +uint32_t +RreqHeader::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + uint8_t t = i.ReadU8 (); + NS_ASSERT (t == type()); + + rq_flags = i.ReadU8 (); + reserved = i.ReadU8 (); + rq_hop_count = i.ReadU8 (); + rq_bcast_id = i.ReadNtohU32 (); + ReadFrom (i, rq_dst); + rq_dst_seqno = i.ReadNtohU32 (); + ReadFrom (i, rq_src); + rq_src_seqno = i.ReadNtohU32 (); + + uint32_t dist = i.GetDistanceFrom (start); + NS_ASSERT (dist == GetSerializedSize ()); + return dist; +} + +void +RreqHeader::Print (std::ostream &os) const +{ + // TODO +} + +std::ostream & operator<<(std::ostream & os, RreqHeader const & h) +{ + h.Print (os); + return os; +} + +void +RreqHeader::SetGratiousRrep (bool f) +{ + if (f) rq_flags |= (1 << 2); + else rq_flags &= ~(1 << 2); +} + +bool +RreqHeader::GetGratiousRrep () const +{ + return (rq_flags & (1 << 2)); +} + +void +RreqHeader::SetDestinationOnly (bool f) +{ + if (f) rq_flags |= (1 << 3); + else rq_flags &= ~(1 << 3); +} + +bool +RreqHeader::GetDestinationOnly () const +{ + return (rq_flags & (1 << 3)); +} + +void +RreqHeader::SetUnknownSeqno (bool f) +{ + if (f) rq_flags |= (1 << 4); + else rq_flags &= ~(1 << 4); +} + +bool +RreqHeader::GetUnknownSeqno () const +{ + return (rq_flags & (1 << 4)); +} + +bool +RreqHeader::operator==(RreqHeader const & o) const +{ + return (rq_flags == o.rq_flags && reserved == o.reserved && + rq_hop_count == o.rq_hop_count && rq_bcast_id == o.rq_bcast_id && + rq_dst == o.rq_dst && rq_dst_seqno == o.rq_dst_seqno && + rq_src == o.rq_src && rq_src_seqno == o.rq_src_seqno); +} + +}} diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h new file mode 100644 index 000000000..0b0312421 --- /dev/null +++ b/src/routing/aodv/aodv-packet.h @@ -0,0 +1,123 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ +#ifndef AODVPACKET_H_ +#define AODVPACKET_H_ + +#include +#include +#include "ns3/header.h" +#include "ns3/ipv4-address.h" + +namespace ns3 { +namespace aodv { + +/// AODV message types +enum MessageType +{ + AODVTYPE_HELLO = 0x01, + AODVTYPE_RREQ = 0x02, + AODVTYPE_RREP = 0x04, + AODVTYPE_RERR = 0x08, + AODVTYPE_RREP_ACK = 0x10 +}; + + +/** + * \ingroup aodv + * \brief Route Request (RREQ) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |J|R|G|D|U| Reserved | Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | RREQ ID | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +class RreqHeader : public Header +{ +public: + RreqHeader (); + + ///\name Header serialization/deserialization + //\{ + uint32_t GetSerializedSize (); + void Serialize (Buffer::Iterator start); + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} + + ///\name Fields + //\{ + void SetHopCount (uint8_t count) { rq_hop_count = count; } + uint8_t GetHopCount () const { return rq_hop_count; } + void SetId (uint32_t id) { rq_bcast_id = id; } + uint8_t GetId () const { return rq_bcast_id; } + void SetDst (Ipv4Address a) { rq_dst = a; } + Ipv4Address GetDst () const { return rq_dst; } + void SetDstSeqno (uint32_t s) { rq_dst_seqno = s; } + uint32_t GetDstSeqno () const { return rq_dst_seqno; } + void SetSrc (Ipv4Address a) { rq_src = a; } + Ipv4Address GetSrc () const { return rq_src; } + void SetSrcSeqno (uint32_t s) { rq_src_seqno = s; } + uint32_t GetSrcSeqno () const { return rq_src_seqno; } + //\} + + ///\name Flags + //\{ + void SetGratiousRrep (bool f); + bool GetGratiousRrep () const; + void SetDestinationOnly (bool f); + bool GetDestinationOnly () const; + void SetUnknownSeqno (bool f); + bool GetUnknownSeqno () const; + //\} + + bool operator==(RreqHeader const & o) const; +private: + static MessageType type() { return AODVTYPE_RREQ; } + + uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC + uint8_t reserved; ///< Not used + uint8_t rq_hop_count; ///< Hop Count + uint32_t rq_bcast_id; ///< RREQ ID + Ipv4Address rq_dst; ///< Destination IP Address + uint32_t rq_dst_seqno; ///< Destination Sequence Number + Ipv4Address rq_src; ///< Source IP Address + uint32_t rq_src_seqno; ///< Source Sequence Number +}; + +std::ostream & operator<<(std::ostream & os, RreqHeader const &); + +} +} +#endif /* AODVPACKET_H_ */ diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 6259ac1ac..303930233 100755 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -56,13 +56,12 @@ aodv_rt_entry::aodv_rt_entry() aodv_rt_entry::aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, u_int16_t hops,Ipv4Address nextHop, Time lifetime) { - rt_dst = dst; - validSeqNo = vSeqNo; - if(validSeqNo == true) - rt_seqno = seqNo; - rt_hops = hops; - rt_nexthop = nextHop; - rt_lifetime = lifetime; + rt_dst = dst; + validSeqNo = vSeqNo; + if (validSeqNo) rt_seqno = seqNo; + rt_hops = hops; + rt_nexthop = nextHop; + rt_lifetime = lifetime; } aodv_rt_entry::~aodv_rt_entry() @@ -75,10 +74,10 @@ aodv_rt_entry::pc_insert(Ipv4Address id) AODV_Precursor p (id); if (! pc_lookup(id, p)) - { - rt_pclist.push_back(p); - return true; - } + { + rt_pclist.push_back(p); + return true; + } else return false; } @@ -100,9 +99,9 @@ aodv_rt_entry::pc_delete(Ipv4Address id) AODV_Precursor p(id); std::vector::iterator i = std::remove(rt_pclist.begin(), rt_pclist.end(), p); if(i == rt_pclist.end()) - return false; + return false; else - rt_pclist.erase (i, rt_pclist.end()); + rt_pclist.erase (i, rt_pclist.end()); return true; } @@ -134,9 +133,8 @@ aodv_rtable::rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const bool aodv_rtable::rt_delete(Ipv4Address dst) { - std::vector::iterator i = std::remove(rthead.begin(), rthead.end(), dst); - if(i == rthead.end()) - return false; + std::vector::iterator i = std::remove(rthead.begin(), rthead.end(), dst); + if (i == rthead.end()) return false; rthead.erase (i, rthead.end()); return true; } @@ -152,67 +150,62 @@ aodv_rtable::rt_add(aodv_rt_entry const & rt) } #ifdef RUN_SELF_TESTS - /// Unit test for aodv_rqueue - struct AodvRtableTest : public Test - { - AodvRtableTest () : Test ("AODV/Rtable"), result(true) {} - virtual bool RunTests(); - bool result; - }; - - /// Test instance - static AodvRtableTest g_AodvRtableTest; - - bool - AodvRtableTest::RunTests () - { - AODV_Neighbor nb1(Ipv4Address("1.2.3.4")); - AODV_Neighbor nb2(Ipv4Address("4.3.2.1")); - NS_TEST_ASSERT(!(nb1==nb2)); - - AODV_Neighbor nb3(Ipv4Address("3.3.3.3")); - AODV_Neighbor nb4(Ipv4Address("3.3.3.3"), Seconds(1)); - NS_TEST_ASSERT(!(nb1==nb2)); - - AODV_Precursor pc1(Ipv4Address("1.1.1.1")); - AODV_Precursor pc2(Ipv4Address("2.2.2.2")); - NS_TEST_ASSERT(!(pc1==pc2)); - - aodv_rt_entry entry1; - Ipv4Address dst1("3.3.3.3"); - Ipv4Address dst2("1.2.3.4"); - aodv_rt_entry entry2 = aodv_rt_entry(dst2, true, 34, 1, Ipv4Address("5.5.5.5"), Seconds(5)); - NS_TEST_ASSERT( !(entry1 == dst1) ); - NS_TEST_ASSERT(entry2 == dst2); - - entry2.pc_insert(dst1); - AODV_Precursor pc3(dst1); - NS_TEST_ASSERT(entry2.pc_lookup(dst1, pc2)); - NS_TEST_ASSERT(pc3==pc2); - NS_TEST_ASSERT(!entry2.pc_delete(dst2)); - NS_TEST_ASSERT(entry2.pc_delete(dst1)); - NS_TEST_ASSERT(entry2.pc_empty()); - entry2.pc_insert(dst2); - NS_TEST_ASSERT(entry2.pc_insert(dst1)); - NS_TEST_ASSERT(!entry2.pc_insert(dst2)); - entry2.pc_delete(); - NS_TEST_ASSERT(entry2.pc_empty()); - - aodv_rtable rtable; - rtable.rt_add(entry2); - NS_TEST_ASSERT(rtable.rt_lookup(dst2, entry1)); - NS_TEST_ASSERT(entry1 == dst2); - NS_TEST_ASSERT(!rtable.rt_lookup(dst1, entry1)); - NS_TEST_ASSERT(rtable.rt_delete(dst2)); - NS_TEST_ASSERT(!rtable.rt_lookup(dst2, entry1)); - - - - - return result; - } +/// Unit test for aodv_rqueue +struct AodvRtableTest : public Test +{ + AodvRtableTest () : Test ("AODV/Rtable"), result(true) {} + virtual bool RunTests(); + bool result; +}; +/// Test instance +static AodvRtableTest g_AodvRtableTest; +bool +AodvRtableTest::RunTests () +{ + AODV_Neighbor nb1(Ipv4Address("1.2.3.4")); + AODV_Neighbor nb2(Ipv4Address("4.3.2.1")); + NS_TEST_ASSERT(!(nb1==nb2)); + + AODV_Neighbor nb3(Ipv4Address("3.3.3.3")); + AODV_Neighbor nb4(Ipv4Address("3.3.3.3"), Seconds(1)); + NS_TEST_ASSERT(!(nb1==nb2)); + + AODV_Precursor pc1(Ipv4Address("1.1.1.1")); + AODV_Precursor pc2(Ipv4Address("2.2.2.2")); + NS_TEST_ASSERT(!(pc1==pc2)); + + aodv_rt_entry entry1; + Ipv4Address dst1("3.3.3.3"); + Ipv4Address dst2("1.2.3.4"); + aodv_rt_entry entry2 = aodv_rt_entry(dst2, true, 34, 1, Ipv4Address("5.5.5.5"), Seconds(5)); + NS_TEST_ASSERT( !(entry1 == dst1) ); + NS_TEST_ASSERT(entry2 == dst2); + + entry2.pc_insert(dst1); + AODV_Precursor pc3(dst1); + NS_TEST_ASSERT(entry2.pc_lookup(dst1, pc2)); + NS_TEST_ASSERT(pc3==pc2); + NS_TEST_ASSERT(!entry2.pc_delete(dst2)); + NS_TEST_ASSERT(entry2.pc_delete(dst1)); + NS_TEST_ASSERT(entry2.pc_empty()); + entry2.pc_insert(dst2); + NS_TEST_ASSERT(entry2.pc_insert(dst1)); + NS_TEST_ASSERT(!entry2.pc_insert(dst2)); + entry2.pc_delete(); + NS_TEST_ASSERT(entry2.pc_empty()); + + aodv_rtable rtable; + rtable.rt_add(entry2); + NS_TEST_ASSERT(rtable.rt_lookup(dst2, entry1)); + NS_TEST_ASSERT(entry1 == dst2); + NS_TEST_ASSERT(!rtable.rt_lookup(dst1, entry1)); + NS_TEST_ASSERT(rtable.rt_delete(dst2)); + NS_TEST_ASSERT(!rtable.rt_lookup(dst2, entry1)); + + return result; +} #endif }} diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 65963bbf7..2b641fc05 100755 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -141,7 +141,7 @@ protected: /// Hop Count (number of hops needed to reach destination) u_int16_t rt_hops; /// Last valid hop count - int rt_last_hop_count; + u_int16_t rt_last_hop_count; /// Next hop IP address Ipv4Address rt_nexthop; /// List of precursors @@ -149,7 +149,7 @@ protected: /** * \brief Expiration or deletion time of the route * Lifetime field in the routing table plays dual role -- - * for an active route it is the expiry time, and for an invalid route + * for an active route it is the expiration time, and for an invalid route * it is the deletion time. */ Time rt_lifetime; @@ -164,7 +164,7 @@ protected: double rt_disc_latency[MAX_HISTORY]; char hist_indx; /// Last ttl value used - int rt_req_last_ttl; + uint16_t rt_req_last_ttl; }; /** diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript index 3fcfcd242..ca71cb610 100644 --- a/src/routing/aodv/wscript +++ b/src/routing/aodv/wscript @@ -6,6 +6,7 @@ def build(bld): module.source = [ 'aodv-rtable.cc', 'aodv-rqueue.cc', + 'aodv-packet.cc', ] headers = bld.new_task_gen('ns3header') @@ -13,5 +14,6 @@ def build(bld): headers.source = [ 'aodv-rtable.h', 'aodv-rqueue.h', + 'aodv-packet.h', ] From 5c44d2ec15c5434f82f78dab37e0366a1992a1c0 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Mon, 6 Jul 2009 12:54:22 +0400 Subject: [PATCH 011/191] RREQ unit test --- src/core/test.h | 2 +- src/routing/aodv/aodv-packet.cc | 49 +++++++++++++++++++++++++++++++-- src/routing/aodv/aodv-packet.h | 5 ++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/core/test.h b/src/core/test.h index fa126e1f9..3080ef7e8 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -115,7 +115,7 @@ private: #define NS_TEST_ASSERT_EQUAL_FILELINE(got, expected, file, line) \ do { \ - if ((got) != (expected)) \ + if (! ((got) == (expected))) \ { \ Failure () << file << ":" < */ +#include "ns3/test.h" #include "aodv-packet.h" #include "ns3/address-utils.h" +#include "ns3/packet.h" namespace ns3 { namespace aodv { @@ -38,14 +40,19 @@ RreqHeader::RreqHeader () : rq_flags(0), reserved(0), rq_hop_count(0), rq_bcast_ SetUnknownSeqno (false); } +TypeId RreqHeader::GetInstanceTypeId() const +{ + return TypeId(); +} + uint32_t -RreqHeader::GetSerializedSize () +RreqHeader::GetSerializedSize () const { return 24; } void -RreqHeader::Serialize (Buffer::Iterator i) +RreqHeader::Serialize (Buffer::Iterator i) const { i.WriteU8 (type()); i.WriteU8 (rq_flags); @@ -139,4 +146,42 @@ RreqHeader::operator==(RreqHeader const & o) const rq_src == o.rq_src && rq_src_seqno == o.rq_src_seqno); } +#ifdef RUN_SELF_TESTS +/// Unit test for RREQ +struct RreqHeaderTest : public Test +{ + RreqHeaderTest () : Test ("AODV/RREQ") {} + virtual bool RunTests(); +}; + +/// Test instance +static RreqHeaderTest g_RreqHeaderTest; + +bool RreqHeaderTest::RunTests () +{ + bool result(true); + + RreqHeader h; + h.SetDst (Ipv4Address("1.2.3.4")); + h.SetDstSeqno (123); + h.SetSrc (Ipv4Address("4.3.2.1")); + h.SetSrcSeqno (321); + h.SetId (1); + h.SetGratiousRrep (true); + NS_TEST_ASSERT(h.GetGratiousRrep ()); + h.SetDestinationOnly (true); + NS_TEST_ASSERT(h.GetDestinationOnly ()); + h.SetUnknownSeqno (true); + NS_TEST_ASSERT(h.GetUnknownSeqno ()); + + Ptr p = Create (); + p->AddHeader (h); + RreqHeader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 24); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif + }} diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 0b0312421..67dddcb64 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -70,8 +70,9 @@ public: ///\name Header serialization/deserialization //\{ - uint32_t GetSerializedSize (); - void Serialize (Buffer::Iterator start); + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; uint32_t Deserialize (Buffer::Iterator start); void Print (std::ostream &os) const; //\} From 8b09ce91da83c86d997c10c52ce483b6666ba7ab Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 22:51:52 +0400 Subject: [PATCH 012/191] RREP header --- src/routing/aodv/aodv-packet.cc | 111 ++++++++++++++++++++++++++++++-- src/routing/aodv/aodv-packet.h | 72 ++++++++++++++++++++- 2 files changed, 177 insertions(+), 6 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 769ac87e8..1e40bd251 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -148,10 +148,10 @@ RreqHeader::operator==(RreqHeader const & o) const #ifdef RUN_SELF_TESTS /// Unit test for RREQ -struct RreqHeaderTest : public Test +struct RreqHeaderTest : public Test { RreqHeaderTest () : Test ("AODV/RREQ") {} - virtual bool RunTests(); + virtual bool RunTests(); }; /// Test instance @@ -160,7 +160,7 @@ static RreqHeaderTest g_RreqHeaderTest; bool RreqHeaderTest::RunTests () { bool result(true); - + RreqHeader h; h.SetDst (Ipv4Address("1.2.3.4")); h.SetDstSeqno (123); @@ -173,7 +173,7 @@ bool RreqHeaderTest::RunTests () NS_TEST_ASSERT(h.GetDestinationOnly ()); h.SetUnknownSeqno (true); NS_TEST_ASSERT(h.GetUnknownSeqno ()); - + Ptr p = Create (); p->AddHeader (h); RreqHeader h2; @@ -182,6 +182,107 @@ bool RreqHeaderTest::RunTests () NS_TEST_ASSERT_EQUAL (h, h2); return result; } -#endif +#endif + +//----------------------------------------------------------------------------- +// RREP +//----------------------------------------------------------------------------- + +RrepHeader::RrepHeader() :rp_flags(0), prefixSize(0), rp_hop_count(0), rp_dst_seqno(0) +{ + SetAckRequired(false); +} + +TypeId +RrepHeader::GetInstanceTypeId() const +{ + return TypeId(); +} + +uint32_t +RrepHeader::GetSerializedSize () const +{ + return 20; +} + +void +RrepHeader::Serialize (Buffer::Iterator i) const +{ + i.WriteU8(type()); + i.WriteU8(rp_flags); + i.WriteU8(prefixSize); + i.WriteU8 (rp_hop_count); + WriteTo (i, rp_dst); + i.WriteHtonU32 (rp_dst_seqno); + WriteTo (i, rp_src); + i.WriteHtonU32 (rp_lifetime); +} + +uint32_t +RrepHeader::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + uint8_t t = i.ReadU8 (); + NS_ASSERT (t == type()); + + rp_flags = i.ReadU8 (); + prefixSize = i.ReadU8 (); + rp_hop_count = i.ReadU8 (); + ReadFrom (i, rp_dst); + rp_dst_seqno = i.ReadNtohU32 (); + ReadFrom (i, rp_src); + rp_lifetime = i.ReadNtohU32 (); + + uint32_t dist = i.GetDistanceFrom (start); + NS_ASSERT (dist == GetSerializedSize ()); + return dist; +} + +void +RrepHeader::Print (std::ostream &os) const +{ + // TODO +} + +void +RrepHeader::SetAckRequired (bool f) +{ + if (f) rp_flags |= (1 << 1); + else rp_flags &= ~(1 << 1); +} + +bool +RrepHeader::GetAckRequired () const +{ + return (rp_flags & (1 << 1)); +} + +void +RrepHeader::SetPrefixSize(uint8_t sz) +{ + prefixSize = sz; +} + +uint8_t +RrepHeader::GetPrefixSize() const +{ + return prefixSize; +} + +bool +RrepHeader::operator==(RrepHeader const & o) const +{ + return (rp_flags == o.rp_flags && prefixSize == o.prefixSize && + rp_hop_count == o.rp_hop_count && rp_dst == o.rp_dst && + rp_dst_seqno == o.rp_dst_seqno && rp_src == o.rp_src && + rp_lifetime == o.rp_lifetime); +} + +std::ostream & operator<<(std::ostream & os, RrepHeader const & h) +{ + h.Print (os); + return os; +} + }} diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 67dddcb64..ff787016d 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -28,6 +28,7 @@ #include #include "ns3/header.h" #include "ns3/ipv4-address.h" +#include namespace ns3 { namespace aodv { @@ -42,7 +43,6 @@ enum MessageType AODVTYPE_RREP_ACK = 0x10 }; - /** * \ingroup aodv * \brief Route Request (RREQ) Message Format @@ -119,6 +119,76 @@ private: std::ostream & operator<<(std::ostream & os, RreqHeader const &); +/** + * \ingroup aodv + * \brief Route Reply (RREP) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |R|A| Reserved |Prefix Sz| Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Lifetime | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ +class RrepHeader : public Header +{ +public: + RrepHeader(); + ///\name Header serialization/deserialization + //\{ + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} + + ///\name Fields + //\{ + void SetHopCount (uint8_t count) { rp_hop_count = count; } + uint8_t GetHopCount () const { return rp_hop_count; } + void SetDst (Ipv4Address a) { rp_dst = a; } + Ipv4Address GetDst () const { return rp_dst; } + void SetDstSeqno (uint32_t s) { rp_dst_seqno = s; } + uint32_t GetDstSeqno () const { return rp_dst_seqno; } + void SetSrc (Ipv4Address a) { rp_src = a; } + Ipv4Address GetSrc () const { return rp_src; } + void SetLifeTime (uint32_t t) { rp_lifetime = t; } + uint32_t GetLifeTime () const { return rp_lifetime; } + //\} + + ///\name Flags + //\{ + void SetAckRequired (bool f); + bool GetAckRequired () const; + void SetPrefixSize(uint8_t sz); + uint8_t GetPrefixSize() const; + + //\} + + bool operator==(RrepHeader const & o) const; +private: + static MessageType type() { return AODVTYPE_RREP; } + uint8_t rp_flags; ///< A - acknowledgment required flag + uint8_t prefixSize; ///< Prefix Size + uint8_t rp_hop_count; ///< Hop Count + Ipv4Address rp_dst; ///< Destination IP Address + uint32_t rp_dst_seqno; ///< Destination Sequence Number + Ipv4Address rp_src; ///< Source IP Address + uint32_t rp_lifetime; ///< Lifetime +}; + +std::ostream & operator<<(std::ostream & os, RrepHeader const &); + + } } #endif /* AODVPACKET_H_ */ From 7bee848ad0ac5b4cf0ebe11af20aed7bf0863e95 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 22:54:19 +0400 Subject: [PATCH 013/191] RREP unit test --- src/routing/aodv/aodv-packet.cc | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 1e40bd251..60d209161 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -284,5 +284,43 @@ std::ostream & operator<<(std::ostream & os, RrepHeader const & h) return os; } +#ifdef RUN_SELF_TESTS +/// Unit test for RREP +struct RrepHeaderTest : public Test +{ + RrepHeaderTest () : Test ("AODV/RREP") {} + virtual bool RunTests(); +}; + +/// Test instance +static RrepHeaderTest g_RrepHeaderTest; + +bool RrepHeaderTest::RunTests () +{ + bool result(true); + + RrepHeader h; + h.SetDst (Ipv4Address("1.2.3.4")); + h.SetDstSeqno (123); + h.SetSrc (Ipv4Address("4.3.2.1")); + h.SetLifeTime(12); + h.SetAckRequired(true); + NS_TEST_ASSERT(h.GetAckRequired ()); + h.SetAckRequired(false); + NS_TEST_ASSERT(!h.GetAckRequired ()); + h.SetPrefixSize(2); + uint8_t sz = h.GetPrefixSize(); + NS_TEST_ASSERT_EQUAL(2, sz); + + Ptr p = Create (); + p->AddHeader (h); + RrepHeader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 20); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif + }} From 736fbc07e67efc7e59b50c4b4c525f610902bd35 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 22:57:10 +0400 Subject: [PATCH 014/191] RREP_ACK header --- src/routing/aodv/aodv-packet.cc | 57 +++++++++++++++++++++++++++++++++ src/routing/aodv/aodv-packet.h | 30 +++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 60d209161..f4143e333 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -322,5 +322,62 @@ bool RrepHeaderTest::RunTests () } #endif +//----------------------------------------------------------------------------- +// RREP-ACK +//----------------------------------------------------------------------------- + +RrepAckHader::RrepAckHader () : reserved(0) +{ +} + +TypeId +RrepAckHader::GetInstanceTypeId() const +{ + return TypeId(); +} + +uint32_t +RrepAckHader::GetSerializedSize () const +{ + return 2; +} + +void +RrepAckHader::Serialize (Buffer::Iterator i) const +{ + i.WriteU8(type()); + i.WriteU8(reserved); +} + +uint32_t +RrepAckHader::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + uint8_t t = i.ReadU8 (); + NS_ASSERT (t == type()); + reserved = i.ReadU8 (); + uint32_t dist = i.GetDistanceFrom (start); + NS_ASSERT (dist == GetSerializedSize ()); + return dist; +} + +void +RrepAckHader::Print (std::ostream &os) const +{ + // TODO +} + +bool +RrepAckHader::operator==(RrepAckHader const & o) const +{ + return reserved == o.reserved; +} + +std::ostream & operator<<(std::ostream & os, RrepAckHader const & h) +{ + h.Print(os); + return os; +} + }} diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index ff787016d..e66995f81 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -188,6 +188,36 @@ private: std::ostream & operator<<(std::ostream & os, RrepHeader const &); +/** + * \ingroup aodv + * \brief Route Reply Acknowledgment (RREP-ACK) Message Format + * 0 1 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +class RrepAckHader : public Header +{ +public: + RrepAckHader (); + + ///\name Header serialization/deserialization + //\{ + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} + bool operator==(RrepAckHader const & o) const; +private: + static MessageType type() { return AODVTYPE_RREP_ACK; } + uint8_t reserved; +}; +std::ostream & operator<<(std::ostream & os, RrepAckHader const &); + + } } From 6a32ee22095daae92f9c392a58cb46c92d95793c Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 22:58:31 +0400 Subject: [PATCH 015/191] RREP_ACK unit test --- src/routing/aodv/aodv-packet.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index f4143e333..ae352dc79 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -379,5 +379,30 @@ std::ostream & operator<<(std::ostream & os, RrepAckHader const & h) return os; } +#ifdef RUN_SELF_TESTS +/// Unit test for RREP-ACK +struct RrepAckHeaderTest : public Test +{ + RrepAckHeaderTest () : Test ("AODV/RREP-ACK") {} + virtual bool RunTests(); +}; + +/// Test instance +static RrepAckHeaderTest g_RrepAckHeaderTest; + +bool RrepAckHeaderTest::RunTests () +{ + bool result(true); + + RrepAckHader h; + Ptr p = Create (); + p->AddHeader (h); + RrepAckHader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 2); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif }} From 3cde38f92f1b168acfcf159c65d96fe2087923c3 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 23:01:03 +0400 Subject: [PATCH 016/191] RERR header --- src/routing/aodv/aodv-packet.cc | 115 ++++++++++++++++++++++++++++++++ src/routing/aodv/aodv-packet.h | 54 +++++++++++++++ 2 files changed, 169 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index ae352dc79..e5c28b3a7 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -405,4 +405,119 @@ bool RrepAckHeaderTest::RunTests () } #endif +//----------------------------------------------------------------------------- +// RERR +//----------------------------------------------------------------------------- +RerrHeader::RerrHeader() : er_flag(0), reserved(0) +{ + destCount = unreachable_dst.size(); +} + +TypeId +RerrHeader::GetInstanceTypeId() const +{ + return TypeId(); +} + +uint32_t +RerrHeader::GetSerializedSize () const +{ + return ( 4 + 8*destCount); +} + +void +RerrHeader::Serialize (Buffer::Iterator i) const +{ + i.WriteU8(type()); + i.WriteU8(er_flag); + i.WriteU8(reserved); + i.WriteU8(destCount); + std::map::const_iterator j; + for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) + { + WriteTo (i, (*j).first); + i.WriteHtonU32 ((*j).second); + } +} + +uint32_t +RerrHeader::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + uint8_t t = i.ReadU8 (); + NS_ASSERT (t == type()); + + er_flag = i.ReadU8 (); + reserved = i.ReadU8 (); + destCount = i.ReadU8 (); + unreachable_dst.clear(); + Ipv4Address address; + uint32_t seqNo; + for(uint8_t k = 0; k < destCount; ++k) + { + ReadFrom (i, address); + seqNo = i.ReadNtohU32 (); + unreachable_dst[address] = seqNo; + } + + uint32_t dist = i.GetDistanceFrom (start); + NS_ASSERT (dist == GetSerializedSize ()); + return dist; +} + +void +RerrHeader::Print (std::ostream &os) const +{ + // TODO +} + +void +RerrHeader::SetNoDelete(bool f) +{ + if (f) er_flag |= (1 << 0); + else er_flag &= ~(1 << 0); +} + +bool +RerrHeader::GetNoDelete() +{ + return (er_flag & (1 << 0)); +} + +bool +RerrHeader::AddUnDestination(Ipv4Address dst, uint32_t seqNo) +{ + if(unreachable_dst.find(dst) != unreachable_dst.end()) + return false; + unreachable_dst[dst] = seqNo; + return true; +} + +bool +RerrHeader::operator==(RerrHeader const & o) const +{ + bool result = ( er_flag == o.er_flag && reserved == o.reserved && + destCount == o.destCount ); + if(!result) + return false; + std::map::const_iterator j = unreachable_dst.begin(); + std::map::const_iterator k = o.unreachable_dst.begin(); + for(uint8_t i = 0; i < destCount; ++i) + { + result = result && ( (*j).first == (*k).first ) && ( (*j).second == (*k).second ); + if(!result) + return false; + j++; + k++; + } + return result; +} + +std::ostream & operator<<(std::ostream & os, RerrHeader const & h) +{ + h.Print(os); + return os; +} + + }} diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index e66995f81..ca9dc1eaf 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -218,6 +218,60 @@ private: std::ostream & operator<<(std::ostream & os, RrepAckHader const &); +/** + * \ingroup aodv + * \brief Route Error (RERR) Message Format + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |N| Reserved | DestCount | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination IP Address (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination Sequence Number (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| + | Additional Unreachable Destination IP Addresses (if needed) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |Additional Unreachable Destination Sequence Numbers (if needed)| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ +class RerrHeader : public Header +{ +public: + RerrHeader (); + + ///\name Header serialization/deserialization + //\{ + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator i) const; + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} + + ///\name No delete flag + //\{ + void SetNoDelete(bool f); + bool GetNoDelete(); + //\} + bool AddUnDestination(Ipv4Address dst, uint32_t seqNo); + uint8_t GetDestCount() const { return destCount; } + bool operator==(RerrHeader const & o) const; +private: + static MessageType type() { return AODVTYPE_RERR; } + uint8_t er_flag; ///< No delete flag + uint8_t reserved; ///< Not used + uint8_t destCount; ///< DestCount + /// List of Unreachable destination IP addresses and sequence numbers + std::map unreachable_dst; + +}; +std::ostream & operator<<(std::ostream & os, RerrHeader const &); + + + } } From b0ef7b6fa316e10146a35b7f396a2063ffa20d25 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 09:40:18 +0400 Subject: [PATCH 017/191] doxygen cosmetics --- src/routing/aodv/aodv-packet.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 67dddcb64..d9e9fde60 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -46,7 +46,7 @@ enum MessageType /** * \ingroup aodv * \brief Route Request (RREQ) Message Format - + \verbatim 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -62,6 +62,7 @@ enum MessageType +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Originator Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim */ class RreqHeader : public Header { @@ -107,13 +108,13 @@ public: private: static MessageType type() { return AODVTYPE_RREQ; } - uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC + uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC uint8_t reserved; ///< Not used uint8_t rq_hop_count; ///< Hop Count uint32_t rq_bcast_id; ///< RREQ ID - Ipv4Address rq_dst; ///< Destination IP Address + Ipv4Address rq_dst; ///< Destination IP Address uint32_t rq_dst_seqno; ///< Destination Sequence Number - Ipv4Address rq_src; ///< Source IP Address + Ipv4Address rq_src; ///< Source IP Address uint32_t rq_src_seqno; ///< Source Sequence Number }; From 7d21770a21c6364c735544e7045809941f31a0ac Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 11:03:54 +0400 Subject: [PATCH 018/191] RERR header unit test --- src/routing/aodv/aodv-packet.cc | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index e5c28b3a7..cf5059250 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -490,6 +490,7 @@ RerrHeader::AddUnDestination(Ipv4Address dst, uint32_t seqNo) if(unreachable_dst.find(dst) != unreachable_dst.end()) return false; unreachable_dst[dst] = seqNo; + destCount = unreachable_dst.size(); return true; } @@ -519,5 +520,39 @@ std::ostream & operator<<(std::ostream & os, RerrHeader const & h) return os; } +#ifdef RUN_SELF_TESTS +/// Unit test for RERR +struct RerrHeaderTest : public Test +{ + RerrHeaderTest () : Test ("AODV/RERR") {} + virtual bool RunTests(); +}; +/// Test instance +static RerrHeaderTest g_RerrHeaderTest; + +bool RerrHeaderTest::RunTests () +{ + bool result(true); + + RerrHeader h; + h.SetNoDelete(true); + NS_TEST_ASSERT(h.GetNoDelete()); + Ipv4Address dst = Ipv4Address("1.2.3.4"); + NS_TEST_ASSERT(h.AddUnDestination(dst, 12)); + NS_TEST_ASSERT_EQUAL(h.GetDestCount(),1); + NS_TEST_ASSERT(!h.AddUnDestination(dst, 13)); + Ipv4Address dst2 = Ipv4Address("4.3.2.1"); + NS_TEST_ASSERT(h.AddUnDestination(dst2, 12)); + NS_TEST_ASSERT_EQUAL(h.GetDestCount(), 2); + + Ptr p = Create (); + p->AddHeader (h); + RerrHeader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, h.GetSerializedSize()); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif }} From 14ece96f9d998e6360d1b2a62fcca56c213ae83e Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 12:07:31 +0400 Subject: [PATCH 019/191] hello message header --- src/routing/aodv/aodv-packet.cc | 45 +++++++++++++++++++++++++-------- src/routing/aodv/aodv-packet.h | 17 +++++++++---- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index cf5059250..76f8e7a91 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -278,6 +278,27 @@ RrepHeader::operator==(RrepHeader const & o) const rp_lifetime == o.rp_lifetime); } + +void +RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo) +{ + rp_flags = 0; + prefixSize = 0; + rp_hop_count = 0; + rp_dst = src; + rp_dst_seqno = srcSeqNo; + rp_src = src; + rp_lifetime = HELLO_INTERVAL * ALLOWED_HELLO_LOSS; +} + +bool +RrepHeader::IsHello(Ipv4Address src, uint32_t srcSeqNo) +{ + return (rp_flags == 0 && prefixSize == 0 && rp_hop_count == 0 && + rp_dst == src && rp_dst_seqno == srcSeqNo && rp_src == src && + rp_lifetime == (HELLO_INTERVAL * ALLOWED_HELLO_LOSS)); +} + std::ostream & operator<<(std::ostream & os, RrepHeader const & h) { h.Print (os); @@ -311,6 +332,9 @@ bool RrepHeaderTest::RunTests () h.SetPrefixSize(2); uint8_t sz = h.GetPrefixSize(); NS_TEST_ASSERT_EQUAL(2, sz); + NS_TEST_ASSERT(!h.IsHello(Ipv4Address("1.2.3.4"),10)); + h.SetHello(Ipv4Address("1.2.3.4"),12); + NS_TEST_ASSERT(h.IsHello(Ipv4Address("1.2.3.4"),12)); Ptr p = Create (); p->AddHeader (h); @@ -326,31 +350,31 @@ bool RrepHeaderTest::RunTests () // RREP-ACK //----------------------------------------------------------------------------- -RrepAckHader::RrepAckHader () : reserved(0) +RrepAckHeader::RrepAckHeader () : reserved(0) { } TypeId -RrepAckHader::GetInstanceTypeId() const +RrepAckHeader::GetInstanceTypeId() const { return TypeId(); } uint32_t -RrepAckHader::GetSerializedSize () const +RrepAckHeader::GetSerializedSize () const { return 2; } void -RrepAckHader::Serialize (Buffer::Iterator i) const +RrepAckHeader::Serialize (Buffer::Iterator i) const { i.WriteU8(type()); i.WriteU8(reserved); } uint32_t -RrepAckHader::Deserialize (Buffer::Iterator start) +RrepAckHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; uint8_t t = i.ReadU8 (); @@ -362,18 +386,19 @@ RrepAckHader::Deserialize (Buffer::Iterator start) } void -RrepAckHader::Print (std::ostream &os) const +RrepAckHeader::Print (std::ostream &os) const { // TODO } + bool -RrepAckHader::operator==(RrepAckHader const & o) const +RrepAckHeader::operator==(RrepAckHeader const & o) const { return reserved == o.reserved; } -std::ostream & operator<<(std::ostream & os, RrepAckHader const & h) +std::ostream & operator<<(std::ostream & os, RrepAckHeader const & h) { h.Print(os); return os; @@ -394,10 +419,10 @@ bool RrepAckHeaderTest::RunTests () { bool result(true); - RrepAckHader h; + RrepAckHeader h; Ptr p = Create (); p->AddHeader (h); - RrepAckHader h2; + RrepAckHeader h2; uint32_t bytes = p->RemoveHeader(h2); NS_TEST_ASSERT_EQUAL (bytes, 2); NS_TEST_ASSERT_EQUAL (h, h2); diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 0a8400235..77e92941a 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -36,13 +36,15 @@ namespace aodv { /// AODV message types enum MessageType { - AODVTYPE_HELLO = 0x01, AODVTYPE_RREQ = 0x02, AODVTYPE_RREP = 0x04, AODVTYPE_RERR = 0x08, AODVTYPE_RREP_ACK = 0x10 }; +#define HELLO_INTERVAL 1 // 1000 ms +#define ALLOWED_HELLO_LOSS 3 // packets + /** * \ingroup aodv * \brief Route Request (RREQ) Message Format @@ -172,7 +174,12 @@ public: bool GetAckRequired () const; void SetPrefixSize(uint8_t sz); uint8_t GetPrefixSize() const; + //\} + ///\name Hello massage + //\{ + void SetHello(Ipv4Address src, uint32_t srcSeqNo); + bool IsHello(Ipv4Address src, uint32_t srcSeqNo); //\} bool operator==(RrepHeader const & o) const; @@ -198,10 +205,10 @@ std::ostream & operator<<(std::ostream & os, RrepHeader const &); | Type | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -class RrepAckHader : public Header +class RrepAckHeader : public Header { public: - RrepAckHader (); + RrepAckHeader (); ///\name Header serialization/deserialization //\{ @@ -211,12 +218,12 @@ public: uint32_t Deserialize (Buffer::Iterator start); void Print (std::ostream &os) const; //\} - bool operator==(RrepAckHader const & o) const; + bool operator==(RrepAckHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP_ACK; } uint8_t reserved; }; -std::ostream & operator<<(std::ostream & os, RrepAckHader const &); +std::ostream & operator<<(std::ostream & os, RrepAckHeader const &); /** From e02d95fa41c430663be124375650a7d511d76866 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 12:11:45 +0400 Subject: [PATCH 020/191] cosmetics --- src/routing/aodv/aodv-packet.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 77e92941a..ef4545e68 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -185,13 +185,13 @@ public: bool operator==(RrepHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP; } - uint8_t rp_flags; ///< A - acknowledgment required flag - uint8_t prefixSize; ///< Prefix Size - uint8_t rp_hop_count; ///< Hop Count - Ipv4Address rp_dst; ///< Destination IP Address - uint32_t rp_dst_seqno; ///< Destination Sequence Number - Ipv4Address rp_src; ///< Source IP Address - uint32_t rp_lifetime; ///< Lifetime + uint8_t rp_flags; ///< A - acknowledgment required flag + uint8_t prefixSize; ///< Prefix Size + uint8_t rp_hop_count; ///< Hop Count + Ipv4Address rp_dst; ///< Destination IP Address + uint32_t rp_dst_seqno; ///< Destination Sequence Number + Ipv4Address rp_src; ///< Source IP Address + uint32_t rp_lifetime; ///< Lifetime }; std::ostream & operator<<(std::ostream & os, RrepHeader const &); @@ -218,6 +218,7 @@ public: uint32_t Deserialize (Buffer::Iterator start); void Print (std::ostream &os) const; //\} + bool operator==(RrepAckHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP_ACK; } @@ -264,14 +265,15 @@ public: void SetNoDelete(bool f); bool GetNoDelete(); //\} + bool AddUnDestination(Ipv4Address dst, uint32_t seqNo); uint8_t GetDestCount() const { return destCount; } bool operator==(RerrHeader const & o) const; private: static MessageType type() { return AODVTYPE_RERR; } - uint8_t er_flag; ///< No delete flag - uint8_t reserved; ///< Not used - uint8_t destCount; ///< DestCount + uint8_t er_flag; ///< No delete flag + uint8_t reserved; ///< Not used + uint8_t destCount; ///< DestCount /// List of Unreachable destination IP addresses and sequence numbers std::map unreachable_dst; From 42a15f1229f85f5b72c2fa55a576afd2894bb029 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 12:42:15 +0400 Subject: [PATCH 021/191] cosmetics --- src/routing/aodv/aodv-packet.cc | 184 +++++++++++++++------------- src/routing/aodv/aodv-packet.h | 204 ++++++++++++++++---------------- 2 files changed, 202 insertions(+), 186 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 76f8e7a91..3fa2e816f 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -71,7 +71,7 @@ RreqHeader::Deserialize (Buffer::Iterator start) Buffer::Iterator i = start; uint8_t t = i.ReadU8 (); NS_ASSERT (t == type()); - + rq_flags = i.ReadU8 (); reserved = i.ReadU8 (); rq_hop_count = i.ReadU8 (); @@ -80,7 +80,7 @@ RreqHeader::Deserialize (Buffer::Iterator start) rq_dst_seqno = i.ReadNtohU32 (); ReadFrom (i, rq_src); rq_src_seqno = i.ReadNtohU32 (); - + uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; @@ -89,7 +89,16 @@ RreqHeader::Deserialize (Buffer::Iterator start) void RreqHeader::Print (std::ostream &os) const { - // TODO + + os << "RREO ID " << rq_bcast_id << "\n" + << "destination: ipv4 " << rq_dst << " " + << "sequence number " << rq_dst_seqno << "\n" + << "source: ipv4 " << rq_src << " " + << "sequence number " << rq_src_seqno << "\n" + << "flags:\n" + << "Gratuitous RREP " << (*this).GetGratiousRrep() << "\n" + << "Destination only " << (*this).GetDestinationOnly() << "\n" + << "Unknown sequence number " << (*this).GetUnknownSeqno() << "\n"; } std::ostream & operator<<(std::ostream & os, RreqHeader const & h) @@ -173,7 +182,6 @@ bool RreqHeaderTest::RunTests () NS_TEST_ASSERT(h.GetDestinationOnly ()); h.SetUnknownSeqno (true); NS_TEST_ASSERT(h.GetUnknownSeqno ()); - Ptr p = Create (); p->AddHeader (h); RreqHeader h2; @@ -190,27 +198,27 @@ bool RreqHeaderTest::RunTests () RrepHeader::RrepHeader() :rp_flags(0), prefixSize(0), rp_hop_count(0), rp_dst_seqno(0) { - SetAckRequired(false); + SetAckRequired(false); } TypeId RrepHeader::GetInstanceTypeId() const { - return TypeId(); + return TypeId(); } uint32_t RrepHeader::GetSerializedSize () const { - return 20; + return 20; } void RrepHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); - i.WriteU8(rp_flags); - i.WriteU8(prefixSize); + i.WriteU8(type()); + i.WriteU8(rp_flags); + i.WriteU8(prefixSize); i.WriteU8 (rp_hop_count); WriteTo (i, rp_dst); i.WriteHtonU32 (rp_dst_seqno); @@ -241,62 +249,70 @@ RrepHeader::Deserialize (Buffer::Iterator start) void RrepHeader::Print (std::ostream &os) const { - // TODO + os << "RREP\n" + << "destination: ipv4 " << rp_dst + << "sequence number " << rp_dst_seqno; + if(prefixSize != 0) + os << "prefix size " << prefixSize << "\n"; + else os << "\n"; + os << "source ipv4 " << rp_src + << "life time " << rp_lifetime << "\n" + << "acknowledgment required flag " << (*this).GetAckRequired() << "\n"; } void RrepHeader::SetAckRequired (bool f) { - if (f) rp_flags |= (1 << 1); - else rp_flags &= ~(1 << 1); + if (f) rp_flags |= (1 << 1); + else rp_flags &= ~(1 << 1); } bool RrepHeader::GetAckRequired () const { - return (rp_flags & (1 << 1)); + return (rp_flags & (1 << 1)); } void RrepHeader::SetPrefixSize(uint8_t sz) { - prefixSize = sz; + prefixSize = sz; } uint8_t RrepHeader::GetPrefixSize() const { - return prefixSize; + return prefixSize; } bool RrepHeader::operator==(RrepHeader const & o) const { - return (rp_flags == o.rp_flags && prefixSize == o.prefixSize && - rp_hop_count == o.rp_hop_count && rp_dst == o.rp_dst && - rp_dst_seqno == o.rp_dst_seqno && rp_src == o.rp_src && - rp_lifetime == o.rp_lifetime); + return (rp_flags == o.rp_flags && prefixSize == o.prefixSize && + rp_hop_count == o.rp_hop_count && rp_dst == o.rp_dst && + rp_dst_seqno == o.rp_dst_seqno && rp_src == o.rp_src && + rp_lifetime == o.rp_lifetime); } void RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo) { - rp_flags = 0; - prefixSize = 0; - rp_hop_count = 0; - rp_dst = src; - rp_dst_seqno = srcSeqNo; - rp_src = src; - rp_lifetime = HELLO_INTERVAL * ALLOWED_HELLO_LOSS; + rp_flags = 0; + prefixSize = 0; + rp_hop_count = 0; + rp_dst = src; + rp_dst_seqno = srcSeqNo; + rp_src = src; + rp_lifetime = HELLO_INTERVAL * ALLOWED_HELLO_LOSS; } bool RrepHeader::IsHello(Ipv4Address src, uint32_t srcSeqNo) { - return (rp_flags == 0 && prefixSize == 0 && rp_hop_count == 0 && - rp_dst == src && rp_dst_seqno == srcSeqNo && rp_src == src && - rp_lifetime == (HELLO_INTERVAL * ALLOWED_HELLO_LOSS)); + return (rp_flags == 0 && prefixSize == 0 && rp_hop_count == 0 && + rp_dst == src && rp_dst_seqno == srcSeqNo && rp_src == src && + rp_lifetime == (HELLO_INTERVAL * ALLOWED_HELLO_LOSS)); } std::ostream & operator<<(std::ostream & os, RrepHeader const & h) @@ -357,20 +373,20 @@ RrepAckHeader::RrepAckHeader () : reserved(0) TypeId RrepAckHeader::GetInstanceTypeId() const { - return TypeId(); + return TypeId(); } uint32_t RrepAckHeader::GetSerializedSize () const { - return 2; + return 2; } void RrepAckHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); - i.WriteU8(reserved); + i.WriteU8(type()); + i.WriteU8(reserved); } uint32_t @@ -388,27 +404,27 @@ RrepAckHeader::Deserialize (Buffer::Iterator start) void RrepAckHeader::Print (std::ostream &os) const { - // TODO + // TODO } bool RrepAckHeader::operator==(RrepAckHeader const & o) const { - return reserved == o.reserved; + return reserved == o.reserved; } std::ostream & operator<<(std::ostream & os, RrepAckHeader const & h) { - h.Print(os); - return os; + h.Print(os); + return os; } #ifdef RUN_SELF_TESTS /// Unit test for RREP-ACK struct RrepAckHeaderTest : public Test { - RrepAckHeaderTest () : Test ("AODV/RREP-ACK") {} + RrepAckHeaderTest () : Test ("AODV/RREP-ACK") {} virtual bool RunTests(); }; @@ -435,34 +451,34 @@ bool RrepAckHeaderTest::RunTests () //----------------------------------------------------------------------------- RerrHeader::RerrHeader() : er_flag(0), reserved(0) { - destCount = unreachable_dst.size(); + destCount = unreachable_dst.size(); } TypeId RerrHeader::GetInstanceTypeId() const { - return TypeId(); + return TypeId(); } uint32_t RerrHeader::GetSerializedSize () const { - return ( 4 + 8*destCount); + return ( 4 + 8*destCount); } void RerrHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); - i.WriteU8(er_flag); - i.WriteU8(reserved); - i.WriteU8(destCount); - std::map::const_iterator j; - for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) - { - WriteTo (i, (*j).first); - i.WriteHtonU32 ((*j).second); - } + i.WriteU8(type()); + i.WriteU8(er_flag); + i.WriteU8(reserved); + i.WriteU8(destCount); + std::map::const_iterator j; + for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) + { + WriteTo (i, (*j).first); + i.WriteHtonU32 ((*j).second); + } } uint32_t @@ -478,12 +494,12 @@ RerrHeader::Deserialize (Buffer::Iterator start) unreachable_dst.clear(); Ipv4Address address; uint32_t seqNo; - for(uint8_t k = 0; k < destCount; ++k) - { - ReadFrom (i, address); - seqNo = i.ReadNtohU32 (); - unreachable_dst[address] = seqNo; - } + for(uint8_t k = 0; k < destCount; ++k) + { + ReadFrom (i, address); + seqNo = i.ReadNtohU32 (); + unreachable_dst[address] = seqNo; + } uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); @@ -493,56 +509,56 @@ RerrHeader::Deserialize (Buffer::Iterator start) void RerrHeader::Print (std::ostream &os) const { - // TODO + // TODO } void RerrHeader::SetNoDelete(bool f) { - if (f) er_flag |= (1 << 0); - else er_flag &= ~(1 << 0); + if (f) er_flag |= (1 << 0); + else er_flag &= ~(1 << 0); } bool RerrHeader::GetNoDelete() { - return (er_flag & (1 << 0)); + return (er_flag & (1 << 0)); } bool RerrHeader::AddUnDestination(Ipv4Address dst, uint32_t seqNo) { - if(unreachable_dst.find(dst) != unreachable_dst.end()) - return false; - unreachable_dst[dst] = seqNo; - destCount = unreachable_dst.size(); - return true; + if(unreachable_dst.find(dst) != unreachable_dst.end()) + return false; + unreachable_dst[dst] = seqNo; + destCount = unreachable_dst.size(); + return true; } bool RerrHeader::operator==(RerrHeader const & o) const { - bool result = ( er_flag == o.er_flag && reserved == o.reserved && - destCount == o.destCount ); - if(!result) - return false; - std::map::const_iterator j = unreachable_dst.begin(); - std::map::const_iterator k = o.unreachable_dst.begin(); - for(uint8_t i = 0; i < destCount; ++i) - { - result = result && ( (*j).first == (*k).first ) && ( (*j).second == (*k).second ); - if(!result) - return false; - j++; - k++; - } - return result; + bool result = ( er_flag == o.er_flag && reserved == o.reserved && + destCount == o.destCount ); + if(!result) + return false; + std::map::const_iterator j = unreachable_dst.begin(); + std::map::const_iterator k = o.unreachable_dst.begin(); + for(uint8_t i = 0; i < destCount; ++i) + { + result = result && ( (*j).first == (*k).first ) && ( (*j).second == (*k).second ); + if(!result) + return false; + j++; + k++; + } + return result; } std::ostream & operator<<(std::ostream & os, RerrHeader const & h) { - h.Print(os); - return os; + h.Print(os); + return os; } #ifdef RUN_SELF_TESTS diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index ef4545e68..69a505d57 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -37,40 +37,40 @@ namespace aodv { enum MessageType { AODVTYPE_RREQ = 0x02, - AODVTYPE_RREP = 0x04, - AODVTYPE_RERR = 0x08, - AODVTYPE_RREP_ACK = 0x10 + AODVTYPE_RREP = 0x04, + AODVTYPE_RERR = 0x08, + AODVTYPE_RREP_ACK = 0x10 }; #define HELLO_INTERVAL 1 // 1000 ms #define ALLOWED_HELLO_LOSS 3 // packets /** - * \ingroup aodv - * \brief Route Request (RREQ) Message Format - \verbatim - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type |J|R|G|D|U| Reserved | Hop Count | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | RREQ ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination IP Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Originator IP Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Originator Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - \endverbatim - */ +* \ingroup aodv +* \brief Route Request (RREQ) Message Format +\verbatim +0 1 2 3 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Type |J|R|G|D|U| Reserved | Hop Count | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| RREQ ID | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Destination IP Address | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Destination Sequence Number | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Originator IP Address | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Originator Sequence Number | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +\endverbatim +*/ class RreqHeader : public Header { public: RreqHeader (); - + ///\name Header serialization/deserialization //\{ TypeId GetInstanceTypeId() const; @@ -79,7 +79,7 @@ public: uint32_t Deserialize (Buffer::Iterator start); void Print (std::ostream &os) const; //\} - + ///\name Fields //\{ void SetHopCount (uint8_t count) { rq_hop_count = count; } @@ -95,7 +95,7 @@ public: void SetSrcSeqno (uint32_t s) { rq_src_seqno = s; } uint32_t GetSrcSeqno () const { return rq_src_seqno; } //\} - + ///\name Flags //\{ void SetGratiousRrep (bool f); @@ -105,54 +105,54 @@ public: void SetUnknownSeqno (bool f); bool GetUnknownSeqno () const; //\} - + bool operator==(RreqHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RREQ; } - - uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC - uint8_t reserved; ///< Not used - uint8_t rq_hop_count; ///< Hop Count - uint32_t rq_bcast_id; ///< RREQ ID - Ipv4Address rq_dst; ///< Destination IP Address - uint32_t rq_dst_seqno; ///< Destination Sequence Number - Ipv4Address rq_src; ///< Source IP Address - uint32_t rq_src_seqno; ///< Source Sequence Number + static MessageType type() { return AODVTYPE_RREQ; } + + uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC + uint8_t reserved; ///< Not used + uint8_t rq_hop_count; ///< Hop Count + uint32_t rq_bcast_id; ///< RREQ ID + Ipv4Address rq_dst; ///< Destination IP Address + uint32_t rq_dst_seqno; ///< Destination Sequence Number + Ipv4Address rq_src; ///< Source IP Address + uint32_t rq_src_seqno; ///< Source Sequence Number }; std::ostream & operator<<(std::ostream & os, RreqHeader const &); /** - * \ingroup aodv - * \brief Route Reply (RREP) Message Format +* \ingroup aodv +* \brief Route Reply (RREP) Message Format - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type |R|A| Reserved |Prefix Sz| Hop Count | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination IP address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Originator IP address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Lifetime | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ +0 1 2 3 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Type |R|A| Reserved |Prefix Sz| Hop Count | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Destination IP address | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Destination Sequence Number | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Originator IP address | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Lifetime | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +* +*/ class RrepHeader : public Header { public: - RrepHeader(); - ///\name Header serialization/deserialization - //\{ - TypeId GetInstanceTypeId() const; - uint32_t GetSerializedSize () const; - void Serialize (Buffer::Iterator start) const; - uint32_t Deserialize (Buffer::Iterator start); - void Print (std::ostream &os) const; - //\} + RrepHeader(); + ///\name Header serialization/deserialization + //\{ + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} ///\name Fields //\{ @@ -197,18 +197,18 @@ private: std::ostream & operator<<(std::ostream & os, RrepHeader const &); /** - * \ingroup aodv - * \brief Route Reply Acknowledgment (RREP-ACK) Message Format - * 0 1 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Reserved | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ +* \ingroup aodv +* \brief Route Reply Acknowledgment (RREP-ACK) Message Format +* 0 1 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Type | Reserved | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ class RrepAckHeader : public Header { public: - RrepAckHeader (); + RrepAckHeader (); ///\name Header serialization/deserialization //\{ @@ -221,35 +221,35 @@ public: bool operator==(RrepAckHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RREP_ACK; } - uint8_t reserved; + static MessageType type() { return AODVTYPE_RREP_ACK; } + uint8_t reserved; }; std::ostream & operator<<(std::ostream & os, RrepAckHeader const &); /** - * \ingroup aodv - * \brief Route Error (RERR) Message Format +* \ingroup aodv +* \brief Route Error (RERR) Message Format - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type |N| Reserved | DestCount | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unreachable Destination IP Address (1) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unreachable Destination Sequence Number (1) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| - | Additional Unreachable Destination IP Addresses (if needed) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |Additional Unreachable Destination Sequence Numbers (if needed)| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ +0 1 2 3 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Type |N| Reserved | DestCount | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Unreachable Destination IP Address (1) | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Unreachable Destination Sequence Number (1) | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| +| Additional Unreachable Destination IP Addresses (if needed) | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +|Additional Unreachable Destination Sequence Numbers (if needed)| ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +* +*/ class RerrHeader : public Header { public: - RerrHeader (); + RerrHeader (); ///\name Header serialization/deserialization //\{ @@ -262,20 +262,20 @@ public: ///\name No delete flag //\{ - void SetNoDelete(bool f); - bool GetNoDelete(); + void SetNoDelete(bool f); + bool GetNoDelete(); //\} - bool AddUnDestination(Ipv4Address dst, uint32_t seqNo); - uint8_t GetDestCount() const { return destCount; } + bool AddUnDestination(Ipv4Address dst, uint32_t seqNo); + uint8_t GetDestCount() const { return destCount; } bool operator==(RerrHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RERR; } - uint8_t er_flag; ///< No delete flag - uint8_t reserved; ///< Not used - uint8_t destCount; ///< DestCount - /// List of Unreachable destination IP addresses and sequence numbers - std::map unreachable_dst; + static MessageType type() { return AODVTYPE_RERR; } + uint8_t er_flag; ///< No delete flag + uint8_t reserved; ///< Not used + uint8_t destCount; ///< DestCount + /// List of Unreachable destination IP addresses and sequence numbers + std::map unreachable_dst; }; std::ostream & operator<<(std::ostream & os, RerrHeader const &); From 70205ec81023660ec9b4df3b30875d754b19cb59 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 13:06:17 +0400 Subject: [PATCH 022/191] print header + cosmetics --- src/routing/aodv/aodv-packet.cc | 13 +++++++++---- src/routing/aodv/aodv-packet.h | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 3fa2e816f..a82c417b4 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -255,7 +255,7 @@ RrepHeader::Print (std::ostream &os) const if(prefixSize != 0) os << "prefix size " << prefixSize << "\n"; else os << "\n"; - os << "source ipv4 " << rp_src + os << "source ipv4 " << rp_src << "\n" << "life time " << rp_lifetime << "\n" << "acknowledgment required flag " << (*this).GetAckRequired() << "\n"; } @@ -404,10 +404,9 @@ RrepAckHeader::Deserialize (Buffer::Iterator start) void RrepAckHeader::Print (std::ostream &os) const { - // TODO + os << "RREP-ACK\n"; } - bool RrepAckHeader::operator==(RrepAckHeader const & o) const { @@ -509,7 +508,13 @@ RerrHeader::Deserialize (Buffer::Iterator start) void RerrHeader::Print (std::ostream &os) const { - // TODO + os << "REER\n" + << "Unreachable destination (ipv4 address, seq. number):\n"; + std::map::const_iterator j; + for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) + { + os << (*j).first << ", " << (*j).second << "\n"; + } } void diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 69a505d57..634fdcd96 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -185,13 +185,13 @@ public: bool operator==(RrepHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP; } - uint8_t rp_flags; ///< A - acknowledgment required flag - uint8_t prefixSize; ///< Prefix Size - uint8_t rp_hop_count; ///< Hop Count - Ipv4Address rp_dst; ///< Destination IP Address - uint32_t rp_dst_seqno; ///< Destination Sequence Number - Ipv4Address rp_src; ///< Source IP Address - uint32_t rp_lifetime; ///< Lifetime + uint8_t rp_flags; ///< A - acknowledgment required flag + uint8_t prefixSize; ///< Prefix Size + uint8_t rp_hop_count; ///< Hop Count + Ipv4Address rp_dst; ///< Destination IP Address + uint32_t rp_dst_seqno; ///< Destination Sequence Number + Ipv4Address rp_src; ///< Source IP Address + uint32_t rp_lifetime; ///< Lifetime }; std::ostream & operator<<(std::ostream & os, RrepHeader const &); @@ -271,9 +271,9 @@ public: bool operator==(RerrHeader const & o) const; private: static MessageType type() { return AODVTYPE_RERR; } - uint8_t er_flag; ///< No delete flag - uint8_t reserved; ///< Not used - uint8_t destCount; ///< DestCount + uint8_t er_flag; ///< No delete flag + uint8_t reserved; ///< Not used + uint8_t destCount; ///< DestCount /// List of Unreachable destination IP addresses and sequence numbers std::map unreachable_dst; From f27ae1792b77767f892dd5d81680f79462f2bef9 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 13:41:03 +0400 Subject: [PATCH 023/191] packets cosmetics --- src/routing/aodv/aodv-packet.cc | 45 +++----- src/routing/aodv/aodv-packet.h | 175 ++++++++++++++++---------------- 2 files changed, 103 insertions(+), 117 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 3fa2e816f..3c9b8e13a 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -89,8 +89,7 @@ RreqHeader::Deserialize (Buffer::Iterator start) void RreqHeader::Print (std::ostream &os) const { - - os << "RREO ID " << rq_bcast_id << "\n" + os << "RREQ ID " << rq_bcast_id << "\n" << "destination: ipv4 " << rq_dst << " " << "sequence number " << rq_dst_seqno << "\n" << "source: ipv4 " << rq_src << " " @@ -307,14 +306,6 @@ RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo) rp_lifetime = HELLO_INTERVAL * ALLOWED_HELLO_LOSS; } -bool -RrepHeader::IsHello(Ipv4Address src, uint32_t srcSeqNo) -{ - return (rp_flags == 0 && prefixSize == 0 && rp_hop_count == 0 && - rp_dst == src && rp_dst_seqno == srcSeqNo && rp_src == src && - rp_lifetime == (HELLO_INTERVAL * ALLOWED_HELLO_LOSS)); -} - std::ostream & operator<<(std::ostream & os, RrepHeader const & h) { h.Print (os); @@ -348,9 +339,6 @@ bool RrepHeaderTest::RunTests () h.SetPrefixSize(2); uint8_t sz = h.GetPrefixSize(); NS_TEST_ASSERT_EQUAL(2, sz); - NS_TEST_ASSERT(!h.IsHello(Ipv4Address("1.2.3.4"),10)); - h.SetHello(Ipv4Address("1.2.3.4"),12); - NS_TEST_ASSERT(h.IsHello(Ipv4Address("1.2.3.4"),12)); Ptr p = Create (); p->AddHeader (h); @@ -451,7 +439,6 @@ bool RrepAckHeaderTest::RunTests () //----------------------------------------------------------------------------- RerrHeader::RerrHeader() : er_flag(0), reserved(0) { - destCount = unreachable_dst.size(); } TypeId @@ -463,7 +450,7 @@ RerrHeader::GetInstanceTypeId() const uint32_t RerrHeader::GetSerializedSize () const { - return ( 4 + 8*destCount); + return ( 4 + 8*GetDestCount()); } void @@ -472,7 +459,7 @@ RerrHeader::Serialize (Buffer::Iterator i) const i.WriteU8(type()); i.WriteU8(er_flag); i.WriteU8(reserved); - i.WriteU8(destCount); + i.WriteU8(GetDestCount()); std::map::const_iterator j; for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) { @@ -490,15 +477,15 @@ RerrHeader::Deserialize (Buffer::Iterator start) er_flag = i.ReadU8 (); reserved = i.ReadU8 (); - destCount = i.ReadU8 (); + uint8_t dest = i.ReadU8 (); unreachable_dst.clear(); Ipv4Address address; uint32_t seqNo; - for(uint8_t k = 0; k < destCount; ++k) + for(uint8_t k = 0; k < dest; ++k) { ReadFrom (i, address); seqNo = i.ReadNtohU32 (); - unreachable_dst[address] = seqNo; + unreachable_dst.insert(std::make_pair(address, seqNo)); } uint32_t dist = i.GetDistanceFrom (start); @@ -520,7 +507,7 @@ RerrHeader::SetNoDelete(bool f) } bool -RerrHeader::GetNoDelete() +RerrHeader::GetNoDelete() const { return (er_flag & (1 << 0)); } @@ -530,29 +517,29 @@ RerrHeader::AddUnDestination(Ipv4Address dst, uint32_t seqNo) { if(unreachable_dst.find(dst) != unreachable_dst.end()) return false; - unreachable_dst[dst] = seqNo; - destCount = unreachable_dst.size(); + + NS_ASSERT (GetDestCount() < 255); // can't support more than 255 destinations in single RERR + unreachable_dst.insert(std::make_pair(dst, seqNo)); return true; } bool RerrHeader::operator==(RerrHeader const & o) const { - bool result = ( er_flag == o.er_flag && reserved == o.reserved && - destCount == o.destCount ); - if(!result) + if (er_flag != o.er_flag || reserved != o.reserved || GetDestCount() != o.GetDestCount()) return false; + std::map::const_iterator j = unreachable_dst.begin(); std::map::const_iterator k = o.unreachable_dst.begin(); - for(uint8_t i = 0; i < destCount; ++i) + for(uint8_t i = 0; i < GetDestCount(); ++i) { - result = result && ( (*j).first == (*k).first ) && ( (*j).second == (*k).second ); - if(!result) + if ((j->first != k->first ) || (j->second != k->second)) return false; + j++; k++; } - return result; + return true; } std::ostream & operator<<(std::ostream & os, RerrHeader const & h) diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 69a505d57..4d1e66250 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -30,41 +30,44 @@ #include "ns3/ipv4-address.h" #include -namespace ns3 { -namespace aodv { - -/// AODV message types -enum MessageType -{ - AODVTYPE_RREQ = 0x02, - AODVTYPE_RREP = 0x04, - AODVTYPE_RERR = 0x08, - AODVTYPE_RREP_ACK = 0x10 -}; - +// TODO avoid defines, use protocol attributes #define HELLO_INTERVAL 1 // 1000 ms #define ALLOWED_HELLO_LOSS 3 // packets +namespace ns3 { +namespace aodv { +/** + * \ingroup aodv + * \brief AODV control types + */ +enum MessageType +{ + AODVTYPE_RREQ = 0x02, //!< AODVTYPE_RREQ + AODVTYPE_RREP = 0x04, //!< AODVTYPE_RREP + AODVTYPE_RERR = 0x08, //!< AODVTYPE_RERR + AODVTYPE_RREP_ACK = 0x10//!< AODVTYPE_RREP_ACK +}; + /** * \ingroup aodv * \brief Route Request (RREQ) Message Format -\verbatim -0 1 2 3 -0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Type |J|R|G|D|U| Reserved | Hop Count | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| RREQ ID | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Destination IP Address | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Destination Sequence Number | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Originator IP Address | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Originator Sequence Number | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -\endverbatim + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |J|R|G|D|U| Reserved | Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | RREQ ID | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim */ class RreqHeader : public Header { @@ -124,22 +127,22 @@ std::ostream & operator<<(std::ostream & os, RreqHeader const &); /** * \ingroup aodv -* \brief Route Reply (RREP) Message Format - -0 1 2 3 -0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Type |R|A| Reserved |Prefix Sz| Hop Count | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Destination IP address | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Destination Sequence Number | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Originator IP address | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Lifetime | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -* +* \brief Route Reply (RREP) Message Format + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |R|A| Reserved |Prefix Sz| Hop Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Destination Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator IP address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Lifetime | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim */ class RrepHeader : public Header { @@ -176,22 +179,19 @@ public: uint8_t GetPrefixSize() const; //\} - ///\name Hello massage - //\{ + /// Configure RREP to be a Hello message void SetHello(Ipv4Address src, uint32_t srcSeqNo); - bool IsHello(Ipv4Address src, uint32_t srcSeqNo); - //\} - + bool operator==(RrepHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP; } - uint8_t rp_flags; ///< A - acknowledgment required flag - uint8_t prefixSize; ///< Prefix Size - uint8_t rp_hop_count; ///< Hop Count - Ipv4Address rp_dst; ///< Destination IP Address - uint32_t rp_dst_seqno; ///< Destination Sequence Number - Ipv4Address rp_src; ///< Source IP Address - uint32_t rp_lifetime; ///< Lifetime + uint8_t rp_flags; ///< A - acknowledgment required flag + uint8_t prefixSize; ///< Prefix Size + uint8_t rp_hop_count; ///< Hop Count + Ipv4Address rp_dst; ///< Destination IP Address + uint32_t rp_dst_seqno; ///< Destination Sequence Number + Ipv4Address rp_src; ///< Source IP Address + uint32_t rp_lifetime; ///< Lifetime }; std::ostream & operator<<(std::ostream & os, RrepHeader const &); @@ -199,11 +199,13 @@ std::ostream & operator<<(std::ostream & os, RrepHeader const &); /** * \ingroup aodv * \brief Route Reply Acknowledgment (RREP-ACK) Message Format -* 0 1 -0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Type | Reserved | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \verbatim + 0 1 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim */ class RrepAckHeader : public Header { @@ -222,7 +224,7 @@ public: bool operator==(RrepAckHeader const & o) const; private: static MessageType type() { return AODVTYPE_RREP_ACK; } - uint8_t reserved; + uint8_t reserved; }; std::ostream & operator<<(std::ostream & os, RrepAckHeader const &); @@ -230,21 +232,21 @@ std::ostream & operator<<(std::ostream & os, RrepAckHeader const &); /** * \ingroup aodv * \brief Route Error (RERR) Message Format - -0 1 2 3 -0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Type |N| Reserved | DestCount | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Unreachable Destination IP Address (1) | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Unreachable Destination Sequence Number (1) | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| -| Additional Unreachable Destination IP Addresses (if needed) | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -|Additional Unreachable Destination Sequence Numbers (if needed)| -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -* + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type |N| Reserved | DestCount | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination IP Address (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unreachable Destination Sequence Number (1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| + | Additional Unreachable Destination IP Addresses (if needed) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |Additional Unreachable Destination Sequence Numbers (if needed)| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim */ class RerrHeader : public Header { @@ -263,26 +265,23 @@ public: ///\name No delete flag //\{ void SetNoDelete(bool f); - bool GetNoDelete(); + bool GetNoDelete() const; //\} bool AddUnDestination(Ipv4Address dst, uint32_t seqNo); - uint8_t GetDestCount() const { return destCount; } + uint8_t GetDestCount() const { return (uint8_t)unreachable_dst.size(); } bool operator==(RerrHeader const & o) const; private: static MessageType type() { return AODVTYPE_RERR; } - uint8_t er_flag; ///< No delete flag - uint8_t reserved; ///< Not used - uint8_t destCount; ///< DestCount + + uint8_t er_flag; ///< No delete flag + uint8_t reserved; ///< Not used + /// List of Unreachable destination IP addresses and sequence numbers std::map unreachable_dst; - }; + std::ostream & operator<<(std::ostream & os, RerrHeader const &); - - - - } } #endif /* AODVPACKET_H_ */ From 66ec73863f262cde8428c8b37478e2ae9bf0e16d Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 15:23:12 +0400 Subject: [PATCH 024/191] aodv::RoutingProtocol just added --- src/routing/aodv/aodv-routing-protocol.cc | 194 ++++++++++++++++++++++ src/routing/aodv/aodv-routing-protocol.h | 88 ++++++++++ src/routing/aodv/wscript | 5 +- 3 files changed, 284 insertions(+), 3 deletions(-) create mode 100644 src/routing/aodv/aodv-routing-protocol.cc create mode 100644 src/routing/aodv/aodv-routing-protocol.h diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc new file mode 100644 index 000000000..e08ceb31d --- /dev/null +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -0,0 +1,194 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ +#include "aodv-routing-protocol.h" +#include "ns3/socket-factory.h" +#include "ns3/udp-socket-factory.h" +#include "ns3/simulator.h" +#include "ns3/log.h" +#include "ns3/random-variable.h" +#include "ns3/inet-socket-address.h" +#include "ns3/ipv4-routing-protocol.h" +#include "ns3/ipv4-route.h" +#include "ns3/boolean.h" +#include "ns3/uinteger.h" +#include "ns3/enum.h" +#include "ns3/trace-source-accessor.h" +#include "ns3/ipv4-header.h" + +/// UDP Port for AODV control traffic +#define AODV_PORT 654 + +NS_LOG_COMPONENT_DEFINE ("AodvRoutingProtocol"); + +namespace ns3 +{ +namespace aodv +{ +NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); + +RoutingProtocol::RoutingProtocol() +{ +} + +TypeId +RoutingProtocol::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::aodv::RoutingProtocol") + .SetParent () + .AddConstructor () + ; + return tid; +} + +RoutingProtocol::~RoutingProtocol() +{ +} + +void +RoutingProtocol::DoDispose () +{ + m_ipv4 = 0; + for (std::map< Ptr, Ipv4Address >::iterator iter = m_socketAddresses.begin (); + iter != m_socketAddresses.end (); iter++) + { + iter->first->Close (); + } + m_socketAddresses.clear (); + Ipv4RoutingProtocol::DoDispose (); +} + +Ptr +RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr) +{ + Ptr rtentry; + sockerr = Socket::ERROR_NOROUTETOHOST; + // TODO resolve route + return rtentry; +} + +bool +RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, + UnicastForwardCallback ucb, MulticastForwardCallback mcb, + LocalDeliverCallback lcb, ErrorCallback ecb) +{ + // TODO + return false; +} + +void +RoutingProtocol::SetIpv4 (Ptr ipv4) +{ + NS_ASSERT (ipv4 != 0); + NS_ASSERT (m_ipv4 == 0); + /* + m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); + */ + + m_ipv4 = ipv4; + Simulator::ScheduleNow (&RoutingProtocol::Start, this); +} + +void +RoutingProtocol::Start () +{ + // Open UDP sockets for control traffic on each IP interface + const Ipv4Address loopback ("127.0.0.1"); + for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) + { + Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); + if (addr == loopback) + continue; + + // Create a socket to listen only on this interface + Ptr socket = Socket::CreateSocket (GetObject (), + UdpSocketFactory::GetTypeId()); + socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); + if (socket->Bind (InetSocketAddress (addr, AODV_PORT))) + { + NS_FATAL_ERROR ("Failed to bind() AODV receive socket"); + } + socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), AODV_PORT)); + m_socketAddresses.insert(std::make_pair(socket, addr)); + } +} + +void +RoutingProtocol::NotifyInterfaceUp (uint32_t interface) +{ + // TODO +} + +void +RoutingProtocol::NotifyInterfaceDown (uint32_t interface) +{ + // TODO +} + +void +RoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ +} + +void +RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ +} + +void +RoutingProtocol::RecvAodv (Ptr socket) +{ + Ptr packet; + Address sourceAddress; + packet = socket->RecvFrom (sourceAddress); + + InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress); + Ipv4Address senderIfaceAddr = inetSourceAddr.GetIpv4 (); + Ipv4Address receiverIfaceAddr = m_socketAddresses[socket]; + + NS_ASSERT (receiverIfaceAddr != Ipv4Address ()); + NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << senderIfaceAddr << " to " << receiverIfaceAddr); + NS_ASSERT (inetSourceAddr.GetPort () == AODV_PORT); + + // TODO check packet type and call RecvSmth +} + +void +RoutingProtocol::RecvRequest (Ptr p) +{ + // TODO +} + +void +RoutingProtocol::RecvReply (Ptr p) +{ + // TODO +} + +void +RoutingProtocol::RecvError (Ptr p) +{ + // TODO +} + +}} diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h new file mode 100644 index 000000000..c80933ab3 --- /dev/null +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -0,0 +1,88 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 1997, 1998 Carnegie Mellon University. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: The AODV code developed by the CMU/MONARCH group was optimized and + * tuned by Samir Das and Mahesh Marina, University of Cincinnati. + * The work was partially done in Sun Microsystems. + * + * Ported to ns-3 by Elena Borovkova + */ +#ifndef AODVROUTINGPROTOCOL_H_ +#define AODVROUTINGPROTOCOL_H_ +#include "ns3/object.h" +#include "ns3/packet.h" +#include "ns3/node.h" +#include "ns3/socket.h" +#include "ns3/timer.h" +#include "ns3/ipv4.h" +#include "ns3/ipv4-routing-protocol.h" +#include + +namespace ns3 +{ +namespace aodv +{ + +/** + * \ingroup aodv + * \brief AODV routing protocol + */ +class RoutingProtocol : public Ipv4RoutingProtocol +{ +public: + static TypeId GetTypeId (void); + + RoutingProtocol(); + virtual ~RoutingProtocol(); + virtual void DoDispose (); + + ///\name From Ipv4RoutingProtocol + //\{ + Ptr RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr); + bool RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, + UnicastForwardCallback ucb, MulticastForwardCallback mcb, + LocalDeliverCallback lcb, ErrorCallback ecb); + virtual void NotifyInterfaceUp (uint32_t interface); + virtual void NotifyInterfaceDown (uint32_t interface); + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void SetIpv4 (Ptr ipv4); + //\} + +private: + /// IP protocol + Ptr m_ipv4; + /// UDP socket per each IP interface, map socket -> iface + std::map< Ptr, Ipv4Address > m_socketAddresses; + +private: + /// Start protocol operation + void Start (); + + /// Receive and process control packet + void RecvAodv (Ptr s); + /// Receive RREQ + void RecvRequest (Ptr p); + /// Receive RREP + void RecvReply (Ptr p); + /// Receive RERR + void RecvError (Ptr p); +}; + +} +} +#endif /* AODVROUTINGPROTOCOL_H_ */ diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript index ca71cb610..65d9ff118 100644 --- a/src/routing/aodv/wscript +++ b/src/routing/aodv/wscript @@ -7,13 +7,12 @@ def build(bld): 'aodv-rtable.cc', 'aodv-rqueue.cc', 'aodv-packet.cc', + 'aodv-routing-protocol.cc', ] headers = bld.new_task_gen('ns3header') headers.module = 'aodv' headers.source = [ - 'aodv-rtable.h', - 'aodv-rqueue.h', - 'aodv-packet.h', + 'aodv-routing-protocol.h', ] From 12fcc9d9d95327f1a52feaed30e0d8c8f339fab7 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 16:28:01 +0400 Subject: [PATCH 025/191] AODV protocol copy-paste in progress --- src/routing/aodv/aodv-packet.cc | 4 +- src/routing/aodv/aodv-packet.h | 11 ++-- src/routing/aodv/aodv-routing-protocol.cc | 53 +++++++++++++-- src/routing/aodv/aodv-routing-protocol.h | 80 +++++++++++++++++++++++ src/routing/aodv/aodv-rqueue.h | 2 +- src/routing/aodv/aodv-rtable.cc | 8 --- src/routing/aodv/aodv-rtable.h | 34 ++-------- src/routing/aodv/wscript | 3 + 8 files changed, 145 insertions(+), 50 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 1c738f80c..806b36a8b 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -294,7 +294,7 @@ RrepHeader::operator==(RrepHeader const & o) const void -RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo) +RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime) { rp_flags = 0; prefixSize = 0; @@ -302,7 +302,7 @@ RrepHeader::SetHello(Ipv4Address src, uint32_t srcSeqNo) rp_dst = src; rp_dst_seqno = srcSeqNo; rp_src = src; - rp_lifetime = HELLO_INTERVAL * ALLOWED_HELLO_LOSS; + rp_lifetime = lifetime.GetMilliSeconds (); } std::ostream & operator<<(std::ostream & os, RrepHeader const & h) diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 4d1e66250..8c0dce4ef 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -29,10 +29,7 @@ #include "ns3/header.h" #include "ns3/ipv4-address.h" #include - -// TODO avoid defines, use protocol attributes -#define HELLO_INTERVAL 1 // 1000 ms -#define ALLOWED_HELLO_LOSS 3 // packets +#include "ns3/nstime.h" namespace ns3 { namespace aodv { @@ -167,8 +164,8 @@ public: uint32_t GetDstSeqno () const { return rp_dst_seqno; } void SetSrc (Ipv4Address a) { rp_src = a; } Ipv4Address GetSrc () const { return rp_src; } - void SetLifeTime (uint32_t t) { rp_lifetime = t; } - uint32_t GetLifeTime () const { return rp_lifetime; } + void SetLifeTime (uint32_t t) { rp_lifetime = t; } // TODO use Time + uint32_t GetLifeTime () const { return rp_lifetime; } // TODO use Time //\} ///\name Flags @@ -180,7 +177,7 @@ public: //\} /// Configure RREP to be a Hello message - void SetHello(Ipv4Address src, uint32_t srcSeqNo); + void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime); bool operator==(RrepHeader const & o) const; private: diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index e08ceb31d..21f52ddd8 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -22,6 +22,7 @@ * Ported to ns-3 by Elena Borovkova */ #include "aodv-routing-protocol.h" + #include "ns3/socket-factory.h" #include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" @@ -47,8 +48,21 @@ namespace aodv { NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); -RoutingProtocol::RoutingProtocol() +RoutingProtocol::RoutingProtocol() : + BCAST_ID_SAVE (Seconds (6)), + HELLO_INTERVAL (Seconds (1)), + ALLOWED_HELLO_LOSS (2), + BAD_LINK_LIFETIME (Seconds (3)), + FREQUENCY (Seconds (0.5)), + bid(1), seqno(2/*??*/), + btimer(Timer::REMOVE_ON_DESTROY), + htimer(Timer::REMOVE_ON_DESTROY), + ntimer(Timer::REMOVE_ON_DESTROY), + rtimer(Timer::REMOVE_ON_DESTROY), + lrtimer(Timer::REMOVE_ON_DESTROY) { + MaxHelloInterval = Scalar(1.25) * HELLO_INTERVAL; + MinHelloInterval = Scalar(0.75) * HELLO_INTERVAL; } TypeId @@ -101,10 +115,13 @@ RoutingProtocol::SetIpv4 (Ptr ipv4) { NS_ASSERT (ipv4 != 0); NS_ASSERT (m_ipv4 == 0); - /* - m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); - */ - + + btimer.SetFunction (& RoutingProtocol::BroadcastTimerExpire, this); + ntimer.SetFunction (& RoutingProtocol::NeighborTimerExpire, this); + rtimer.SetFunction (& RoutingProtocol::RouteCacheTimerExpire, this); + lrtimer.SetFunction (& RoutingProtocol::LocalRepairTimerExpire, this); + htimer.SetFunction (& RoutingProtocol::HelloTimerExpire, this); + m_ipv4 = ipv4; Simulator::ScheduleNow (&RoutingProtocol::Start, this); } @@ -191,4 +208,30 @@ RoutingProtocol::RecvError (Ptr p) // TODO } +void +RoutingProtocol::BroadcastTimerExpire () +{ +} + +void +RoutingProtocol::HelloTimerExpire () +{ +} + +void +RoutingProtocol::NeighborTimerExpire () +{ +} + +void +RoutingProtocol::RouteCacheTimerExpire () +{ +} + +void +RoutingProtocol::LocalRepairTimerExpire () +{ +} + + }} diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index c80933ab3..5621556b4 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -23,6 +23,11 @@ */ #ifndef AODVROUTINGPROTOCOL_H_ #define AODVROUTINGPROTOCOL_H_ + +#include "aodv-rtable.h" +#include "aodv-rqueue.h" +#include "aodv-packet.h" + #include "ns3/object.h" #include "ns3/packet.h" #include "ns3/node.h" @@ -36,6 +41,43 @@ namespace ns3 { namespace aodv { +/** + * \ingroup aodv + * \brief AODV Neighbor Cache Entry + * TODO move inside RoutingProtocol + */ +class AODV_Neighbor +{ + friend class AODV; + friend class aodv_rt_entry; + +public: + AODV_Neighbor(Ipv4Address const & a, Time exp = Seconds(0)) : nb_addr(a), nb_expire(exp) {} + bool operator==(AODV_Neighbor const & n) const + { + return (nb_addr == n.nb_addr)&&(nb_expire == n.nb_expire); + } + +protected: + Ipv4Address nb_addr; + Time nb_expire; +}; + +/** + * \ingroup aodv + * + * Broadcast ID Cache entry + * TODO move inside RoutingProtocol + */ +struct BroadcastID +{ + Ipv4Address src; + uint32_t id; + /// now + BCAST_ID_SAVE s + Time expire; + + BroadcastID (Ipv4Address i, uint32_t b, Time t) : src(i), id(b), expire(t) {} +}; /** * \ingroup aodv @@ -64,10 +106,34 @@ public: //\} private: + ///\name Protocol parameters. TODO document + //\{ + Time BCAST_ID_SAVE; + Time HELLO_INTERVAL; + uint32_t ALLOWED_HELLO_LOSS; + Time BAD_LINK_LIFETIME; + Time MaxHelloInterval; // (1.25 * HELLO_INTERVAL) + Time MinHelloInterval; // (0.75 * HELLO_INTERVAL) + Time FREQUENCY; + //\} + /// IP protocol Ptr m_ipv4; /// UDP socket per each IP interface, map socket -> iface std::map< Ptr, Ipv4Address > m_socketAddresses; + /// Routing table + aodv_rtable rtable; + /// A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route. + aodv_rqueue rqueue; + /// List of neighbors (aka neighbors cache). TODO: separate list for each interface??? + std::vector nbhead; + /// Broadcast sequence numbers cache + std::vector bihead; + /// Preq broadcast ID + uint32_t bid; + /// Sequence Number (???) + uint32_t seqno; + private: /// Start protocol operation @@ -81,6 +147,20 @@ private: void RecvReply (Ptr p); /// Receive RERR void RecvError (Ptr p); + + ///\name Timers. TODO comment each one + //\{ + Timer btimer; + void BroadcastTimerExpire (); + Timer htimer; + void HelloTimerExpire (); + Timer ntimer; + void NeighborTimerExpire (); + Timer rtimer; + void RouteCacheTimerExpire (); + Timer lrtimer; + void LocalRepairTimerExpire (); + //\} }; } diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index becbb033f..5f6bbdcfc 100755 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -22,7 +22,7 @@ * Ported to ns-3 by Elena Borovkova */ #ifndef __aodv_rqueue_h__ -#define __aodv_rqueue_h_ +#define __aodv_rqueue_h__ #include "ns3/ipv4-header.h" #include "ns3/nstime.h" diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 303930233..d285ac198 100755 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -164,14 +164,6 @@ static AodvRtableTest g_AodvRtableTest; bool AodvRtableTest::RunTests () { - AODV_Neighbor nb1(Ipv4Address("1.2.3.4")); - AODV_Neighbor nb2(Ipv4Address("4.3.2.1")); - NS_TEST_ASSERT(!(nb1==nb2)); - - AODV_Neighbor nb3(Ipv4Address("3.3.3.3")); - AODV_Neighbor nb4(Ipv4Address("3.3.3.3"), Seconds(1)); - NS_TEST_ASSERT(!(nb1==nb2)); - AODV_Precursor pc1(Ipv4Address("1.1.1.1")); AODV_Precursor pc2(Ipv4Address("2.2.2.2")); NS_TEST_ASSERT(!(pc1==pc2)); diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 2b641fc05..db81ad7e2 100755 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -36,27 +36,6 @@ namespace aodv { #define INFINITY2 0xff -/** - * \ingroup aodv - * \brief AODV Neighbor Cache Entry - */ -class AODV_Neighbor -{ - friend class AODV; - friend class aodv_rt_entry; - -public: - AODV_Neighbor(Ipv4Address const & a, Time exp = Seconds(0)) : nb_addr(a), nb_expire(exp) {} - bool operator==(AODV_Neighbor const & n) const - { - return (nb_addr == n.nb_addr)&&(nb_expire == n.nb_expire); - } - -protected: - Ipv4Address nb_addr; - Time nb_expire; -}; - /** * \ingroup aodv * @@ -128,7 +107,7 @@ public: /// When I can send another request Time rt_req_timeout; /// Number of route requests - u_int8_t rt_req_cnt; + uint8_t rt_req_cnt; protected: /// Destination address @@ -136,12 +115,13 @@ protected: /// Valid Destination Sequence Number flag bool validSeqNo; /// Destination Sequence Number, if validSeqNo = true - u_int32_t rt_seqno; - /* u_int8_t rt_interface; */ + uint32_t rt_seqno; + /// Interface index + uint32_t rt_interface; /// Hop Count (number of hops needed to reach destination) - u_int16_t rt_hops; + uint16_t rt_hops; /// Last valid hop count - u_int16_t rt_last_hop_count; + uint16_t rt_last_hop_count; /// Next hop IP address Ipv4Address rt_nexthop; /// List of precursors @@ -154,7 +134,7 @@ protected: */ Time rt_lifetime; /// Routing flags: down, up or in repair - u_int8_t rt_flags; + uint8_t rt_flags; #define RTF_DOWN 0 #define RTF_UP 1 diff --git a/src/routing/aodv/wscript b/src/routing/aodv/wscript index 65d9ff118..2d455b6af 100644 --- a/src/routing/aodv/wscript +++ b/src/routing/aodv/wscript @@ -13,6 +13,9 @@ def build(bld): headers = bld.new_task_gen('ns3header') headers.module = 'aodv' headers.source = [ + 'aodv-rtable.h', + 'aodv-rqueue.h', + 'aodv-packet.h', 'aodv-routing-protocol.h', ] From aa99830fa63d3cf10f9e4b4d46943d59b44a4911 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 17:31:43 +0400 Subject: [PATCH 026/191] AODV RoutingProtocol stub finished --- src/routing/aodv/aodv-routing-protocol.cc | 55 +++++++++++++- src/routing/aodv/aodv-routing-protocol.h | 87 ++++++++++++++--------- src/routing/aodv/aodv-rtable.cc | 19 +++++ src/routing/aodv/aodv-rtable.h | 24 +++++-- 4 files changed, 145 insertions(+), 40 deletions(-) diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 21f52ddd8..4f8583b4a 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -211,27 +211,80 @@ RoutingProtocol::RecvError (Ptr p) void RoutingProtocol::BroadcastTimerExpire () { + // id_purge(); + btimer.Schedule (BCAST_ID_SAVE); } void RoutingProtocol::HelloTimerExpire () { + SendHello (); + // TODO select random time for the next hello + htimer.Schedule (HELLO_INTERVAL); } void RoutingProtocol::NeighborTimerExpire () -{ +{ + // nb_purge(); + ntimer.Schedule (HELLO_INTERVAL); } void RoutingProtocol::RouteCacheTimerExpire () { + // rt_purge(); + rtimer.Schedule (FREQUENCY); } void RoutingProtocol::LocalRepairTimerExpire () { + // TODO start local repair procedure } +void +RoutingProtocol::SendHello () +{ + // TODO send hello packet from interfaces +} +void +RoutingProtocol::SendRequest (Ipv4Address dst) +{ + // TODO +} + +void +RoutingProtocol::SendReply (Ipv4Address ipdst, uint32_t hop_count, Ipv4Address rpdst, uint32_t rpseq, Time lifetime) +{ + // TODO +} + +void +RoutingProtocol::SendError (Ipv4Address failed) +{ + // TODO +} + +void +RoutingProtocol::LocalRouteRepair (Ipv4Address dst, Ptr p) +{ + // TODO local_rt_repair +} + +void +RoutingProtocol::HandleLinkFailure (Ipv4Address id) +{ + // TODO +} + +void +RoutingProtocol::RtPurge () +{ + // TODO AODV::rt_purge() +} +//----------------------------------------------------------------------------- +// TODO: NeighborList, BroadcastIdCache +//----------------------------------------------------------------------------- }} diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index 5621556b4..316982fb9 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -41,42 +41,42 @@ namespace ns3 { namespace aodv { -/** - * \ingroup aodv - * \brief AODV Neighbor Cache Entry - * TODO move inside RoutingProtocol - */ -class AODV_Neighbor +/// List of neighbors TODO document & move inside protocol +class NeighborList { - friend class AODV; - friend class aodv_rt_entry; - public: - AODV_Neighbor(Ipv4Address const & a, Time exp = Seconds(0)) : nb_addr(a), nb_expire(exp) {} - bool operator==(AODV_Neighbor const & n) const + /// The neighbor + struct Neighbor { - return (nb_addr == n.nb_addr)&&(nb_expire == n.nb_expire); - } + Ipv4Address nb_addr; + Time nb_expire; + }; + + void Insert(Ipv4Address id); + bool Lookup (Ipv4Address id, Neighbor & n); + void Delete (Ipv4Address id); + void Purge (); -protected: - Ipv4Address nb_addr; - Time nb_expire; +private: + std::vector nb; }; -/** - * \ingroup aodv - * - * Broadcast ID Cache entry - * TODO move inside RoutingProtocol - */ -struct BroadcastID +/// Known broadcast ID cache. TODO document & move inside protocol +class BroadcastIdCache { - Ipv4Address src; - uint32_t id; - /// now + BCAST_ID_SAVE s - Time expire; - - BroadcastID (Ipv4Address i, uint32_t b, Time t) : src(i), id(b), expire(t) {} +public: + void Insert (Ipv4Address id, u_int32_t bid); + bool Lookup (Ipv4Address id, u_int32_t bid); + void Purge (); +private: + struct BroadcastId + { + Ipv4Address src; + uint32_t id; + Time expire; + }; + + std::vector bi; }; /** @@ -126,19 +126,26 @@ private: /// A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route. aodv_rqueue rqueue; /// List of neighbors (aka neighbors cache). TODO: separate list for each interface??? - std::vector nbhead; + NeighborList nbhead; /// Broadcast sequence numbers cache - std::vector bihead; + BroadcastIdCache bihead; /// Preq broadcast ID uint32_t bid; /// Sequence Number (???) uint32_t seqno; - private: /// Start protocol operation void Start (); + /// Start local route repair procedure + void LocalRouteRepair (Ipv4Address dst, Ptr p); + /// Process broken link + void HandleLinkFailure (Ipv4Address id); + /// Purge all expired records from rtable + void RtPurge (); + ///\name Recv + //\{ /// Receive and process control packet void RecvAodv (Ptr s); /// Receive RREQ @@ -147,12 +154,26 @@ private: void RecvReply (Ptr p); /// Receive RERR void RecvError (Ptr p); + //\} + + ///\name Send + //\{ + /// Send hello. TODO send independent hello per interface + void SendHello (); + /// Send RREQ + void SendRequest (Ipv4Address dst); + /// Send RREP + void SendReply (Ipv4Address ipdst, uint32_t hop_count, + Ipv4Address rpdst, uint32_t rpseq, Time lifetime); + /// Send RERR + void SendError (Ipv4Address failed); + //\} ///\name Timers. TODO comment each one //\{ Timer btimer; void BroadcastTimerExpire (); - Timer htimer; + Timer htimer; // TODO independent hello timers for all interfaces void HelloTimerExpire (); Timer ntimer; void NeighborTimerExpire (); diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index d285ac198..864e0cbe6 100755 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -117,6 +117,18 @@ aodv_rt_entry::pc_empty() const return rt_pclist.empty(); } +void +aodv_rt_entry::Down () +{ + if(rt_flags == RTF_DOWN) return; + + rt_last_hop_count = rt_hops; + rt_hops = INFINITY2; + rt_flags = RTF_DOWN; + rt_nexthop = 0; + rt_lifetime = Seconds (DELETE_PERIOD); +} + /* The Routing Table */ @@ -149,6 +161,13 @@ aodv_rtable::rt_add(aodv_rt_entry const & rt) return true; } +void +aodv_rtable::SetEntryState (Ipv4Address id, uint8_t state) +{ + std::vector::iterator i = std::find (rthead.begin(), rthead.end(), id); + if (i != rthead.end()) i->rt_flags = state; +} + #ifdef RUN_SELF_TESTS /// Unit test for aodv_rqueue struct AodvRtableTest : public Test diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index db81ad7e2..7c55d29ec 100755 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -34,7 +34,8 @@ namespace ns3 { namespace aodv { -#define INFINITY2 0xff +#define INFINITY2 0xff +#define DELETE_PERIOD 10 // seconds. TODO: remove defines /** * \ingroup aodv @@ -62,14 +63,14 @@ protected: */ class aodv_rt_entry { - friend class aodv_rtable; - friend class AODV; - friend class LocalRepairTimer; public: aodv_rt_entry(); aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, u_int16_t hops,Ipv4Address nextHop, Time lifetime); ~aodv_rt_entry(); + + ///\name Precursors management + //\{ /** * Insert precursor in precursor list if it doesn't yet exist in the list * \param id precursor address @@ -95,6 +96,11 @@ public: * \return true if precursor list empty */ bool pc_empty() const; + //\} + + /// Mark entry as "down" (i.e. disable it) + void Down (); + /** * \brief Compare destination address * \return true if equal @@ -109,7 +115,10 @@ public: /// Number of route requests uint8_t rt_req_cnt; -protected: +private: + friend class aodv_rtable; + friend class RoutingProtocol; + /// Destination address Ipv4Address rt_dst; /// Valid Destination Sequence Number flag @@ -134,13 +143,14 @@ protected: */ Time rt_lifetime; /// Routing flags: down, up or in repair - uint8_t rt_flags; + uint8_t rt_flags; /*TODO use enum*/ #define RTF_DOWN 0 #define RTF_UP 1 #define RTF_IN_REPAIR 2 #define MAX_HISTORY 3 + // TODO review and delete double rt_disc_latency[MAX_HISTORY]; char hist_indx; /// Last ttl value used @@ -176,6 +186,8 @@ public: * \return true on success */ bool rt_lookup(Ipv4Address dst, aodv_rt_entry & rt) const; + /// Set routing table entry flags + void SetEntryState (Ipv4Address dst, uint8_t state /*TODO use enum*/); private: std::vector rthead; From a9da8ac9e783d3fb5bec4d3be6f8317845442370 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Tue, 7 Jul 2009 17:45:08 +0400 Subject: [PATCH 027/191] Permissions corrected --- src/routing/aodv/aodv-rqueue.cc | 0 src/routing/aodv/aodv-rqueue.h | 0 src/routing/aodv/aodv-rtable.cc | 0 src/routing/aodv/aodv-rtable.h | 0 src/routing/aodv/aodv.h | 0 src/routing/aodv/rfc3561.txt | 0 6 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/routing/aodv/aodv-rqueue.cc mode change 100755 => 100644 src/routing/aodv/aodv-rqueue.h mode change 100755 => 100644 src/routing/aodv/aodv-rtable.cc mode change 100755 => 100644 src/routing/aodv/aodv-rtable.h mode change 100755 => 100644 src/routing/aodv/aodv.h mode change 100755 => 100644 src/routing/aodv/rfc3561.txt diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc old mode 100755 new mode 100644 diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h old mode 100755 new mode 100644 diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc old mode 100755 new mode 100644 diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h old mode 100755 new mode 100644 diff --git a/src/routing/aodv/aodv.h b/src/routing/aodv/aodv.h old mode 100755 new mode 100644 diff --git a/src/routing/aodv/rfc3561.txt b/src/routing/aodv/rfc3561.txt old mode 100755 new mode 100644 From 7c5120174860c68b3b481261022de3aced079acb Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 18:27:53 +0400 Subject: [PATCH 028/191] replacement of the vector by a map in rtable --- src/routing/aodv/aodv-packet.cc | 1 + src/routing/aodv/aodv-rtable.cc | 17 ++++++++--------- src/routing/aodv/aodv-rtable.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 806b36a8b..963f1f950 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -501,6 +501,7 @@ RerrHeader::Print (std::ostream &os) const { os << (*j).first << ", " << (*j).second << "\n"; } + os << "No delete flag " << (*this).GetNoDelete() << "\n"; } void diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 864e0cbe6..d8c5f5e25 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -136,19 +136,17 @@ aodv_rt_entry::Down () bool aodv_rtable::rt_lookup(Ipv4Address id, aodv_rt_entry & rt) const { - std::vector::const_iterator i = std::find (rthead.begin(), rthead.end(), id); + std::map::const_iterator i = rthead.find(id); if (i == rthead.end()) return false; - rt = *i; + rt = (*i).second; return true; } bool aodv_rtable::rt_delete(Ipv4Address dst) { - std::vector::iterator i = std::remove(rthead.begin(), rthead.end(), dst); - if (i == rthead.end()) return false; - rthead.erase (i, rthead.end()); - return true; + if(rthead.erase (dst) != 0) return true; + return false; } bool @@ -157,15 +155,15 @@ aodv_rtable::rt_add(aodv_rt_entry const & rt) aodv_rt_entry dummy; if(rt_lookup(rt.rt_dst, dummy)) return false; - rthead.push_back(rt); + rthead.insert(std::make_pair(rt.rt_dst, rt)); return true; } void aodv_rtable::SetEntryState (Ipv4Address id, uint8_t state) { - std::vector::iterator i = std::find (rthead.begin(), rthead.end(), id); - if (i != rthead.end()) i->rt_flags = state; + std::map::iterator i = rthead.find(id); + if (i != rthead.end()) (*i).second.rt_flags = state; } #ifdef RUN_SELF_TESTS @@ -213,6 +211,7 @@ AodvRtableTest::RunTests () NS_TEST_ASSERT(entry1 == dst2); NS_TEST_ASSERT(!rtable.rt_lookup(dst1, entry1)); NS_TEST_ASSERT(rtable.rt_delete(dst2)); + NS_TEST_ASSERT(!rtable.rt_delete(dst2)); NS_TEST_ASSERT(!rtable.rt_lookup(dst2, entry1)); return result; diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 7c55d29ec..5d4eced68 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -25,7 +25,7 @@ #define __aodv_rtable_h__ #include -#include +#include #include #include "ns3/ipv4.h" #include "ns3/nstime.h" @@ -190,7 +190,7 @@ public: void SetEntryState (Ipv4Address dst, uint8_t state /*TODO use enum*/); private: - std::vector rthead; + std::map rthead; }; }} From 051a833eaf907cdee50d46d5218ab97ba44ea7e3 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 7 Jul 2009 18:39:57 +0400 Subject: [PATCH 029/191] AODV_Precursor killed --- src/routing/aodv/aodv-rtable.cc | 27 +++++++-------------------- src/routing/aodv/aodv-rtable.h | 25 +++---------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index d8c5f5e25..5a82f302d 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -71,33 +71,26 @@ aodv_rt_entry::~aodv_rt_entry() bool aodv_rt_entry::pc_insert(Ipv4Address id) { - AODV_Precursor p (id); - - if (! pc_lookup(id, p)) + if (! pc_lookup(id)) { - rt_pclist.push_back(p); + rt_pclist.push_back(id); return true; } else return false; } bool -aodv_rt_entry::pc_lookup(Ipv4Address id, AODV_Precursor & p) +aodv_rt_entry::pc_lookup(Ipv4Address id) { - for(std::vector::const_iterator i = rt_pclist.begin(); i != rt_pclist.end(); ++i) - if (i->pc_addr == id) - { - p = *i; - return true; - } + for(std::vector::const_iterator i = rt_pclist.begin(); i != rt_pclist.end(); ++i) + if (*i == id) return true; return false; } bool aodv_rt_entry::pc_delete(Ipv4Address id) { - AODV_Precursor p(id); - std::vector::iterator i = std::remove(rt_pclist.begin(), rt_pclist.end(), p); + std::vector::iterator i = std::remove(rt_pclist.begin(), rt_pclist.end(), id); if(i == rt_pclist.end()) return false; else @@ -181,10 +174,6 @@ static AodvRtableTest g_AodvRtableTest; bool AodvRtableTest::RunTests () { - AODV_Precursor pc1(Ipv4Address("1.1.1.1")); - AODV_Precursor pc2(Ipv4Address("2.2.2.2")); - NS_TEST_ASSERT(!(pc1==pc2)); - aodv_rt_entry entry1; Ipv4Address dst1("3.3.3.3"); Ipv4Address dst2("1.2.3.4"); @@ -193,9 +182,7 @@ AodvRtableTest::RunTests () NS_TEST_ASSERT(entry2 == dst2); entry2.pc_insert(dst1); - AODV_Precursor pc3(dst1); - NS_TEST_ASSERT(entry2.pc_lookup(dst1, pc2)); - NS_TEST_ASSERT(pc3==pc2); + NS_TEST_ASSERT(entry2.pc_lookup(dst1)); NS_TEST_ASSERT(!entry2.pc_delete(dst2)); NS_TEST_ASSERT(entry2.pc_delete(dst1)); NS_TEST_ASSERT(entry2.pc_empty()); diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 5d4eced68..7cf9b846d 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -37,25 +37,7 @@ namespace aodv { #define INFINITY2 0xff #define DELETE_PERIOD 10 // seconds. TODO: remove defines -/** - * \ingroup aodv - * - * \brief AODV Precursor list data structure - */ -class AODV_Precursor -{ - friend class AODV; - friend class aodv_rt_entry; -public: - AODV_Precursor(Ipv4Address const & a) : pc_addr(a) {} - bool operator==(AODV_Precursor const & o) const - { - return (pc_addr == o.pc_addr); - } -protected: - /// Precursor address - Ipv4Address pc_addr; -}; + /** * \ingroup aodv @@ -80,10 +62,9 @@ public: /** * Lookup precursor by address * \param id precursor address - * \param p precursor with address id if exists * \return true on success */ - bool pc_lookup(Ipv4Address id, AODV_Precursor & p); + bool pc_lookup(Ipv4Address id); /** * \brief Delete precursor * \param id precursor address @@ -134,7 +115,7 @@ private: /// Next hop IP address Ipv4Address rt_nexthop; /// List of precursors - std::vector rt_pclist; + std::vector rt_pclist; /** * \brief Expiration or deletion time of the route * Lifetime field in the routing table plays dual role -- From 1042689880e893feff81ea3e5b125d3d9a253faa Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Thu, 9 Jul 2009 12:26:48 +0400 Subject: [PATCH 030/191] TypeHeader added --- src/routing/aodv/aodv-packet.cc | 174 ++++++++++++++++++++++++++------ src/routing/aodv/aodv-packet.h | 58 ++++++++--- 2 files changed, 186 insertions(+), 46 deletions(-) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 963f1f950..835208cd4 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -29,17 +29,146 @@ namespace ns3 { namespace aodv { +TypeHeader::TypeHeader(uint8_t t) : type(t), valid(true) +{ + switch (type) + { + case AODVTYPE_RREQ: + case AODVTYPE_RREP: + case AODVTYPE_RERR: + case AODVTYPE_RREP_ACK: + break; + default: + valid = false; + } +} + +TypeId +TypeHeader::GetInstanceTypeId() const +{ + return TypeId(); +} + +uint32_t +TypeHeader::GetSerializedSize () const +{ + return 1; +} + +void +TypeHeader::Serialize (Buffer::Iterator i) const +{ + i.WriteU8(type); +} + +uint32_t +TypeHeader::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + type = i.ReadU8 (); + valid = true; + switch (type) + { + case AODVTYPE_RREQ: + case AODVTYPE_RREP: + case AODVTYPE_RERR: + case AODVTYPE_RREP_ACK: + break; + default: + valid = false; + } + uint32_t dist = i.GetDistanceFrom (start); + NS_ASSERT (dist == GetSerializedSize ()); + return dist; +} + +void +TypeHeader::Print (std::ostream &os) const +{ + switch(type) + { + case AODVTYPE_RREQ: + { + os << "RREQ" << "\n"; + break; + } + case AODVTYPE_RREP: + { + os << "RREP" << "\n"; + break; + } + case AODVTYPE_RERR: + { + os << "RERR" << "\n"; + break; + } + case AODVTYPE_RREP_ACK: + { + os << "RREP_ACK" << "\n"; + break; + } + default: + os << ""; + } +} + +bool +TypeHeader::operator==(TypeHeader const & o) const +{ + return ( type == o.type && valid == o.valid ); +} + +std::ostream & operator<<(std::ostream & os, TypeHeader const & h) +{ + h.Print(os); + return os; +} + + +#ifdef RUN_SELF_TESTS +/// Unit test for TypeHeader +struct TypeHeaderTest : public Test +{ + TypeHeaderTest () : Test ("AODV/TypeHeader") {} + virtual bool RunTests(); +}; + +/// Test instance +static TypeHeaderTest g_TypeHeaderTest; + +bool TypeHeaderTest::RunTests () +{ + bool result(true); + + TypeHeader h(AODVTYPE_RREQ); + NS_TEST_ASSERT(h.IsValid()); + TypeHeader h1(13); + NS_TEST_ASSERT(!h1.IsValid()); + + Ptr p = Create (); + p->AddHeader (h); + TypeHeader h2(AODVTYPE_RREP); + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 1); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif + + //----------------------------------------------------------------------------- // RREQ //----------------------------------------------------------------------------- -RreqHeader::RreqHeader () : rq_flags(0), reserved(0), rq_hop_count(0), rq_bcast_id(0), rq_dst_seqno(0), rq_src_seqno(0) +RreqHeader::RreqHeader () : rq_flags(0), reserved(0), rq_hop_count(0), rq_bcast_id(0), +rq_dst_seqno(0), rq_src_seqno(0) { SetGratiousRrep (false); SetDestinationOnly (false); SetUnknownSeqno (false); } -TypeId RreqHeader::GetInstanceTypeId() const +TypeId +RreqHeader::GetInstanceTypeId() const { return TypeId(); } @@ -47,13 +176,12 @@ TypeId RreqHeader::GetInstanceTypeId() const uint32_t RreqHeader::GetSerializedSize () const { - return 24; + return 23; } void RreqHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8 (type()); i.WriteU8 (rq_flags); i.WriteU8 (reserved); i.WriteU8 (rq_hop_count); @@ -68,9 +196,6 @@ uint32_t RreqHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; - uint8_t t = i.ReadU8 (); - NS_ASSERT (t == type()); - rq_flags = i.ReadU8 (); reserved = i.ReadU8 (); rq_hop_count = i.ReadU8 (); @@ -184,7 +309,7 @@ bool RreqHeaderTest::RunTests () p->AddHeader (h); RreqHeader h2; uint32_t bytes = p->RemoveHeader(h2); - NS_TEST_ASSERT_EQUAL (bytes, 24); + NS_TEST_ASSERT_EQUAL (bytes, 23); NS_TEST_ASSERT_EQUAL (h, h2); return result; } @@ -208,13 +333,12 @@ RrepHeader::GetInstanceTypeId() const uint32_t RrepHeader::GetSerializedSize () const { - return 20; + return 19; } void RrepHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); i.WriteU8(rp_flags); i.WriteU8(prefixSize); i.WriteU8 (rp_hop_count); @@ -228,8 +352,6 @@ uint32_t RrepHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; - uint8_t t = i.ReadU8 (); - NS_ASSERT (t == type()); rp_flags = i.ReadU8 (); prefixSize = i.ReadU8 (); @@ -247,8 +369,7 @@ RrepHeader::Deserialize (Buffer::Iterator start) void RrepHeader::Print (std::ostream &os) const { - os << "RREP\n" - << "destination: ipv4 " << rp_dst + os << "destination: ipv4 " << rp_dst << "sequence number " << rp_dst_seqno; if(prefixSize != 0) os << "prefix size " << prefixSize << "\n"; @@ -343,7 +464,7 @@ bool RrepHeaderTest::RunTests () p->AddHeader (h); RrepHeader h2; uint32_t bytes = p->RemoveHeader(h2); - NS_TEST_ASSERT_EQUAL (bytes, 20); + NS_TEST_ASSERT_EQUAL (bytes, 19); NS_TEST_ASSERT_EQUAL (h, h2); return result; } @@ -366,13 +487,12 @@ RrepAckHeader::GetInstanceTypeId() const uint32_t RrepAckHeader::GetSerializedSize () const { - return 2; + return 1; } void RrepAckHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); i.WriteU8(reserved); } @@ -380,8 +500,6 @@ uint32_t RrepAckHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; - uint8_t t = i.ReadU8 (); - NS_ASSERT (t == type()); reserved = i.ReadU8 (); uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); @@ -391,7 +509,6 @@ RrepAckHeader::Deserialize (Buffer::Iterator start) void RrepAckHeader::Print (std::ostream &os) const { - os << "RREP-ACK\n"; } bool @@ -426,7 +543,7 @@ bool RrepAckHeaderTest::RunTests () p->AddHeader (h); RrepAckHeader h2; uint32_t bytes = p->RemoveHeader(h2); - NS_TEST_ASSERT_EQUAL (bytes, 2); + NS_TEST_ASSERT_EQUAL (bytes, 1); NS_TEST_ASSERT_EQUAL (h, h2); return result; } @@ -448,13 +565,12 @@ RerrHeader::GetInstanceTypeId() const uint32_t RerrHeader::GetSerializedSize () const { - return ( 4 + 8*GetDestCount()); + return ( 3 + 8*GetDestCount()); } void RerrHeader::Serialize (Buffer::Iterator i) const { - i.WriteU8(type()); i.WriteU8(er_flag); i.WriteU8(reserved); i.WriteU8(GetDestCount()); @@ -470,9 +586,6 @@ uint32_t RerrHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; - uint8_t t = i.ReadU8 (); - NS_ASSERT (t == type()); - er_flag = i.ReadU8 (); reserved = i.ReadU8 (); uint8_t dest = i.ReadU8 (); @@ -494,8 +607,7 @@ RerrHeader::Deserialize (Buffer::Iterator start) void RerrHeader::Print (std::ostream &os) const { - os << "REER\n" - << "Unreachable destination (ipv4 address, seq. number):\n"; + os << "Unreachable destination (ipv4 address, seq. number):\n"; std::map::const_iterator j; for(j = unreachable_dst.begin(); j != unreachable_dst.end(); ++j) { @@ -522,7 +634,7 @@ RerrHeader::AddUnDestination(Ipv4Address dst, uint32_t seqNo) { if(unreachable_dst.find(dst) != unreachable_dst.end()) return false; - + NS_ASSERT (GetDestCount() < 255); // can't support more than 255 destinations in single RERR unreachable_dst.insert(std::make_pair(dst, seqNo)); return true; @@ -533,14 +645,14 @@ RerrHeader::operator==(RerrHeader const & o) const { if (er_flag != o.er_flag || reserved != o.reserved || GetDestCount() != o.GetDestCount()) return false; - + std::map::const_iterator j = unreachable_dst.begin(); std::map::const_iterator k = o.unreachable_dst.begin(); for(uint8_t i = 0; i < GetDestCount(); ++i) { if ((j->first != k->first ) || (j->second != k->second)) return false; - + j++; k++; } diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 8c0dce4ef..0c6f9f817 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -33,11 +33,8 @@ namespace ns3 { namespace aodv { -/** - * \ingroup aodv - * \brief AODV control types - */ -enum MessageType + +enum MessageType { AODVTYPE_RREQ = 0x02, //!< AODVTYPE_RREQ AODVTYPE_RREP = 0x04, //!< AODVTYPE_RREP @@ -45,6 +42,43 @@ enum MessageType AODVTYPE_RREP_ACK = 0x10//!< AODVTYPE_RREP_ACK }; +/** +* \ingroup aodv +* \brief AODV types +*/ +class TypeHeader : public Header +{ +public: + + enum MessageType + { + AODVTYPE_RREQ = 0x02, //!< AODVTYPE_RREQ + AODVTYPE_RREP = 0x04, //!< AODVTYPE_RREP + AODVTYPE_RERR = 0x08, //!< AODVTYPE_RERR + AODVTYPE_RREP_ACK = 0x10//!< AODVTYPE_RREP_ACK + }; + + TypeHeader(uint8_t t); + + ///\name Header serialization/deserialization + //\{ + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + void Print (std::ostream &os) const; + //\} + + uint8_t Get() const { return type; } + bool IsValid() const { return valid; } + bool operator==(TypeHeader const & o) const; +private: + uint8_t type; + bool valid; +}; + +std::ostream & operator<<(std::ostream & os, TypeHeader const & h); + /** * \ingroup aodv * \brief Route Request (RREQ) Message Format @@ -108,8 +142,6 @@ public: bool operator==(RreqHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RREQ; } - uint8_t rq_flags; ///< |J|R|G|D|U| bit flags, see RFC uint8_t reserved; ///< Not used uint8_t rq_hop_count; ///< Hop Count @@ -164,7 +196,7 @@ public: uint32_t GetDstSeqno () const { return rp_dst_seqno; } void SetSrc (Ipv4Address a) { rp_src = a; } Ipv4Address GetSrc () const { return rp_src; } - void SetLifeTime (uint32_t t) { rp_lifetime = t; } // TODO use Time + void SetLifeTime (uint32_t t) { rp_lifetime = t; } // TODO use Time uint32_t GetLifeTime () const { return rp_lifetime; } // TODO use Time //\} @@ -178,10 +210,9 @@ public: /// Configure RREP to be a Hello message void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime); - + bool operator==(RrepHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RREP; } uint8_t rp_flags; ///< A - acknowledgment required flag uint8_t prefixSize; ///< Prefix Size uint8_t rp_hop_count; ///< Hop Count @@ -196,7 +227,7 @@ std::ostream & operator<<(std::ostream & os, RrepHeader const &); /** * \ingroup aodv * \brief Route Reply Acknowledgment (RREP-ACK) Message Format - \verbatim + \verbatim 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -220,7 +251,6 @@ public: bool operator==(RrepAckHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RREP_ACK; } uint8_t reserved; }; std::ostream & operator<<(std::ostream & os, RrepAckHeader const &); @@ -269,11 +299,9 @@ public: uint8_t GetDestCount() const { return (uint8_t)unreachable_dst.size(); } bool operator==(RerrHeader const & o) const; private: - static MessageType type() { return AODVTYPE_RERR; } - uint8_t er_flag; ///< No delete flag uint8_t reserved; ///< Not used - + /// List of Unreachable destination IP addresses and sequence numbers std::map unreachable_dst; }; From 9c53293f9ef871e7f39895ec35ac76999f336a3c Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 9 Jul 2009 12:54:21 +0400 Subject: [PATCH 031/191] AodvHelper just added --- src/helper/aodv-helper.cc | 48 ++++++++++++++++++++++++++++++ src/helper/aodv-helper.h | 62 +++++++++++++++++++++++++++++++++++++++ src/helper/wscript | 2 ++ 3 files changed, 112 insertions(+) create mode 100644 src/helper/aodv-helper.cc create mode 100644 src/helper/aodv-helper.h diff --git a/src/helper/aodv-helper.cc b/src/helper/aodv-helper.cc new file mode 100644 index 000000000..ddcbe1827 --- /dev/null +++ b/src/helper/aodv-helper.cc @@ -0,0 +1,48 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 IITP RAS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Pavel Boyko , written after OlsrHelper by Mathieu Lacage + */ +#include "aodv-helper.h" +#include "ns3/aodv-routing-protocol.h" +#include "ns3/node-list.h" +#include "ns3/names.h" +#include "ns3/ipv4-list-routing.h" + +namespace ns3 +{ + +AodvHelper::AodvHelper() +{ + m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol"); +} + +Ptr +AodvHelper::Create (Ptr node) const +{ + Ptr agent = m_agentFactory.Create (); + node->AggregateObject (agent); + return agent; +} + +void +AodvHelper::Set (std::string name, const AttributeValue &value) +{ + m_agentFactory.Set (name, value); +} + +} diff --git a/src/helper/aodv-helper.h b/src/helper/aodv-helper.h new file mode 100644 index 000000000..3dd35ca8e --- /dev/null +++ b/src/helper/aodv-helper.h @@ -0,0 +1,62 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 IITP RAS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Pavel Boyko , written after OlsrHelper by Mathieu Lacage + */ +#ifndef AODVHELPER_H_ +#define AODVHELPER_H_ + +#include "ns3/object-factory.h" +#include "ns3/node.h" +#include "node-container.h" +#include "ipv4-routing-helper.h" + +namespace ns3 +{ +/** + * \ingroup aodv + * \brief Helper class that adds AODV routing to nodes. + */ +class AodvHelper +{ +public: + AodvHelper(); + + /** + * \param node the node on which the routing protocol will run + * \return a newly-created routing protocol + * + * This method will be called by ns3::InternetStackHelper::Install + * + * TODO: support installing AODV on the subset of all available IP interfaces + */ + virtual Ptr Create (Ptr node) const; + + /** + * \param name the name of the attribute to set + * \param value the value of the attribute to set. + * + * This method controls the attributes of ns3::olsr::RoutingProtocol + */ + void Set (std::string name, const AttributeValue &value); + +private: + ObjectFactory m_agentFactory; +}; + +} +#endif /* AODVHELPER_H_ */ diff --git a/src/helper/wscript b/src/helper/wscript index 5775fea3a..6afde5bd6 100644 --- a/src/helper/wscript +++ b/src/helper/wscript @@ -28,6 +28,7 @@ def build(bld): 'ipv4-global-routing-helper.cc', 'ipv4-list-routing-helper.cc', 'ipv4-routing-helper.cc', + 'aodv-helper.cc', ] headers = bld.new_task_gen('ns3header') @@ -58,6 +59,7 @@ def build(bld): 'ipv4-global-routing-helper.h', 'ipv4-list-routing-helper.h', 'ipv4-routing-helper.h', + 'aodv-helper.h', ] env = bld.env_of_name('default') From f18d57cae6413a276e6d63f45fb398eff1fe52bf Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 9 Jul 2009 14:44:08 +0400 Subject: [PATCH 032/191] AODV example added. Use ./waf --run aodv --- examples/aodv.cc | 210 ++++++++++++++++++++++++++++++++++++++ examples/wscript | 4 +- src/helper/aodv-helper.cc | 2 +- src/helper/aodv-helper.h | 4 +- 4 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 examples/aodv.cc diff --git a/examples/aodv.cc b/examples/aodv.cc new file mode 100644 index 000000000..ee61ee4a9 --- /dev/null +++ b/examples/aodv.cc @@ -0,0 +1,210 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 IITP RAS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * This is an example script for AODV manet routing protocol. + * + * Authors: Pavel Boyko + */ + +#include "ns3/aodv-module.h" +#include "ns3/core-module.h" +#include "ns3/common-module.h" +#include "ns3/node-module.h" +#include "ns3/helper-module.h" +#include "ns3/mobility-module.h" +#include "ns3/contrib-module.h" +#include "ns3/wifi-module.h" +#include +#include + +using namespace ns3; + +/** + * \brief Test script. + * + * This script creates 1-dimensional grid topology and runs UDP echo from one end to the other one. + */ +class AodvExample +{ +public: + AodvExample (); + /// Configure script parameters, \return true on successful configuration + bool Configure (int argc, char **argv); + /// Run simulation + void Run (); + /// Report results + void Report (std::ostream & os); + +private: + ///\name parameters + //\{ + /// Number of nodes + uint8_t size; + /// Distance between nodes, meters + double step; + /// Simulation time, seconds + double totalTime; + /// Write per-device PCAP traces if true + bool pcap; + //\} + + ///\name network + //\{ + NodeContainer nodes; + NetDeviceContainer devices; + Ipv4InterfaceContainer interfaces; + //\} + +private: + void CreateNodes (); + void CreateDevices (); + void InstallInternetStack (); + void InstallApplications (); +}; + +int main (int argc, char **argv) +{ + AodvExample test; + if (! test.Configure(argc, argv)) + NS_FATAL_ERROR ("Configuration failed. Aborted."); + + test.Run (); + test.Report (std::cout); + return 0; +} + +//----------------------------------------------------------------------------- +AodvExample::AodvExample () : + size (2), + step (150), + totalTime (10), + pcap (true) +{ +} + +bool +AodvExample::Configure (int argc, char **argv) +{ + SeedManager::SetSeed(12345); + CommandLine cmd; + + cmd.AddValue ("pcap", "Write PCAP traces.", pcap); + cmd.AddValue ("size", "Number of nodes.", size); + cmd.AddValue ("time", "Simulation time, s.", totalTime); + cmd.AddValue ("step", "Grid step, m", step); + + cmd.Parse (argc, argv); + return true; +} + +void +AodvExample::Run () +{ + CreateNodes (); + CreateDevices (); + InstallInternetStack (); + InstallApplications (); + + std::cout << "Starting simulation for " << totalTime << " s ...\n"; + + Simulator::Stop (Seconds (totalTime)); + Simulator::Run (); + Simulator::Destroy (); +} + +void +AodvExample::Report (std::ostream &) +{ + std::cout << "Done.\n"; +} + +void +AodvExample::CreateNodes () +{ + nodes.Create (size); + // Name nodes + for (uint32_t i = 0; i < size; ++i) + { + std::ostringstream os; + os << "node-" << i; + Names::Add (os.str (), nodes.Get (i)); + } + // Create static grid + MobilityHelper mobility; + mobility.SetPositionAllocator ("ns3::GridPositionAllocator", + "MinX", DoubleValue (0.0), + "MinY", DoubleValue (0.0), + "DeltaX", DoubleValue (step), + "DeltaY", DoubleValue (0), + "GridWidth", UintegerValue (size), + "LayoutType", StringValue ("RowFirst")); + mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); + mobility.Install (nodes); +} + +void +AodvExample::CreateDevices () +{ + NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); + wifiMac.SetType ("ns3::AdhocWifiMac"); + YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); + YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); + wifiPhy.SetChannel (wifiChannel.Create ()); + WifiHelper wifi = WifiHelper::Default (); + wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("wifia-6mbs")); + devices = wifi.Install (wifiPhy, wifiMac, nodes); + + if (pcap) + { + wifiPhy.EnablePcapAll (std::string ("aodv-")); + } +} + +void +AodvExample::InstallInternetStack () +{ + AodvHelper aodv; + // you can configure AODV attributes here using aodv.Set(name, value) + InternetStackHelper stack; + stack.SetRoutingHelper (aodv); + stack.Install (nodes); + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.0.0.0"); + interfaces = address.Assign (devices); +} + +void +AodvExample::InstallApplications () +{ + LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); + LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); + + UdpEchoServerHelper echoServer (9); + ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); + serverApps.Start (Seconds (0)); + serverApps.Stop (Seconds (totalTime)); + UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); + Time packetInterval (Seconds (0.1)); + uint32_t packetSize (1024); + echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)std::floor(totalTime / packetInterval.GetSeconds()))); + echoClient.SetAttribute ("Interval", TimeValue (packetInterval)); + echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize)); + ApplicationContainer clientApps = echoClient.Install (nodes.Get (size - 1)); + clientApps.Start (Seconds (0)); + clientApps.Stop (Seconds (totalTime)); +} + diff --git a/examples/wscript b/examples/wscript index ff9b1b958..560a92a11 100644 --- a/examples/wscript +++ b/examples/wscript @@ -1,7 +1,9 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - print "Don't want to build examples" + obj = bld.create_ns3_program('aodv') + obj.source = 'aodv.cc' + # obj = bld.create_ns3_program('hello-simulator') # obj.source = 'hello-simulator.cc' # diff --git a/src/helper/aodv-helper.cc b/src/helper/aodv-helper.cc index ddcbe1827..9f5d54fa1 100644 --- a/src/helper/aodv-helper.cc +++ b/src/helper/aodv-helper.cc @@ -26,7 +26,7 @@ namespace ns3 { -AodvHelper::AodvHelper() +AodvHelper::AodvHelper() : Ipv4RoutingHelper () { m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol"); } diff --git a/src/helper/aodv-helper.h b/src/helper/aodv-helper.h index 3dd35ca8e..b58cfe5cd 100644 --- a/src/helper/aodv-helper.h +++ b/src/helper/aodv-helper.h @@ -31,7 +31,7 @@ namespace ns3 * \ingroup aodv * \brief Helper class that adds AODV routing to nodes. */ -class AodvHelper +class AodvHelper : public Ipv4RoutingHelper { public: AodvHelper(); @@ -50,7 +50,7 @@ public: * \param name the name of the attribute to set * \param value the value of the attribute to set. * - * This method controls the attributes of ns3::olsr::RoutingProtocol + * This method controls the attributes of ns3::aodv::RoutingProtocol */ void Set (std::string name, const AttributeValue &value); From 4dac3c28d1e21c5c278a5b7b947cb70c4617d0fc Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Thu, 9 Jul 2009 16:07:04 +0400 Subject: [PATCH 033/191] Use ping in AODV example + multiple V4Ping enhancements to produce pingish output --- examples/aodv.cc | 29 ++++----- examples/wscript | 6 +- src/applications/v4ping/v4ping.cc | 105 ++++++++++++++++++++++++------ src/applications/v4ping/v4ping.h | 21 ++++++ src/contrib/average.h | 79 ++++++++++++++++++++++ src/contrib/wscript | 1 + 6 files changed, 201 insertions(+), 40 deletions(-) create mode 100644 src/contrib/average.h diff --git a/examples/aodv.cc b/examples/aodv.cc index ee61ee4a9..cd245825a 100644 --- a/examples/aodv.cc +++ b/examples/aodv.cc @@ -28,6 +28,7 @@ #include "ns3/mobility-module.h" #include "ns3/contrib-module.h" #include "ns3/wifi-module.h" +#include "ns3/v4ping-helper.h" #include #include @@ -36,7 +37,11 @@ using namespace ns3; /** * \brief Test script. * - * This script creates 1-dimensional grid topology and runs UDP echo from one end to the other one. + * This script creates 1-dimensional grid topology and then ping last node from the first one: + * + * [10.0.0.1] <-- step --> [10.0.0.2] <-- step --> [10.0.0.3] <-- step --> [10.0.04] + * + * ping 10.0.0.4 */ class AodvExample { @@ -129,12 +134,12 @@ AodvExample::Run () void AodvExample::Report (std::ostream &) { - std::cout << "Done.\n"; } void AodvExample::CreateNodes () { + std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n"; nodes.Create (size); // Name nodes for (uint32_t i = 0; i < size; ++i) @@ -190,21 +195,11 @@ AodvExample::InstallInternetStack () void AodvExample::InstallApplications () { - LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); - LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); + V4PingHelper ping (interfaces.GetAddress(size - 1)); + ping.SetAttribute ("Verbose", BooleanValue (true)); - UdpEchoServerHelper echoServer (9); - ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); - serverApps.Start (Seconds (0)); - serverApps.Stop (Seconds (totalTime)); - UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); - Time packetInterval (Seconds (0.1)); - uint32_t packetSize (1024); - echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)std::floor(totalTime / packetInterval.GetSeconds()))); - echoClient.SetAttribute ("Interval", TimeValue (packetInterval)); - echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize)); - ApplicationContainer clientApps = echoClient.Install (nodes.Get (size - 1)); - clientApps.Start (Seconds (0)); - clientApps.Stop (Seconds (totalTime)); + ApplicationContainer p = ping.Install (nodes.Get (0)); + p.Start (Seconds (0)); + p.Stop (Seconds (totalTime)); } diff --git a/examples/wscript b/examples/wscript index 560a92a11..d678ad31d 100644 --- a/examples/wscript +++ b/examples/wscript @@ -142,9 +142,9 @@ def build(bld): # ['csma', 'internet-stack']) # obj.source = 'csma-raw-ip-socket.cc' # -# obj = bld.create_ns3_program('csma-ping', -# ['csma', 'internet-stack', 'v4ping']) -# obj.source = 'csma-ping.cc' + obj = bld.create_ns3_program('csma-ping', + ['csma', 'internet-stack', 'v4ping']) + obj.source = 'csma-ping.cc' # # obj = bld.create_ns3_program('test-ipv6', # ['point-to-point', 'internet-stack']) diff --git a/src/applications/v4ping/v4ping.cc b/src/applications/v4ping/v4ping.cc index 8523439f5..700bbad01 100644 --- a/src/applications/v4ping/v4ping.cc +++ b/src/applications/v4ping/v4ping.cc @@ -20,10 +20,10 @@ #include "ns3/ipv4-address.h" #include "ns3/socket.h" #include "ns3/uinteger.h" +#include "ns3/boolean.h" #include "ns3/inet-socket-address.h" #include "ns3/packet.h" #include "ns3/trace-source-accessor.h" -#include "ns3/simulator.h" namespace ns3 { @@ -41,6 +41,19 @@ V4Ping::GetTypeId (void) Ipv4AddressValue (), MakeIpv4AddressAccessor (&V4Ping::m_remote), MakeIpv4AddressChecker ()) + .AddAttribute ("Verbose", + "Produce usual output.", + BooleanValue (false), + MakeBooleanAccessor (&V4Ping::m_verbose), + MakeBooleanChecker ()) + .AddAttribute ("Interval", "Wait interval seconds between sending each packet.", + TimeValue (Seconds (1)), + MakeTimeAccessor (&V4Ping::m_interval), + MakeTimeChecker ()) + .AddAttribute ("Size", "The number of data bytes to be sent, real packet will be 8 (ICMP) + 20 (IP) bytes longer.", + UintegerValue (56), + MakeUintegerAccessor (&V4Ping::m_size), + MakeUintegerChecker (16)) .AddTraceSource ("Rtt", "The rtt calculated by the ping.", MakeTraceSourceAccessor (&V4Ping::m_traceRtt)); @@ -49,9 +62,14 @@ V4Ping::GetTypeId (void) } V4Ping::V4Ping () - : m_socket (0), - m_seq (0) -{} + : m_interval (Seconds (1)), + m_size (56), + m_socket (0), + m_seq (0), + m_verbose (false), + m_recv (0) +{ +} V4Ping::~V4Ping () {} @@ -92,6 +110,7 @@ V4Ping::Receive (Ptr socket) NS_ASSERT (realFrom.GetPort () == 1); // protocol should be icmp. Ipv4Header ipv4; p->RemoveHeader (ipv4); + uint32_t recvSize = p->GetSize (); NS_ASSERT (ipv4.GetProtocol () == 1); // protocol should be icmp. Icmpv4Header icmp; p->RemoveHeader (icmp); @@ -102,7 +121,7 @@ V4Ping::Receive (Ptr socket) if (echo.GetSequenceNumber () == (m_seq - 1) && echo.GetIdentifier () == 0) { - uint32_t buf[4]; + uint32_t buf[m_size / 4]; uint32_t dataSize = echo.GetDataSize (); if (dataSize == sizeof(buf)) { @@ -117,7 +136,18 @@ V4Ping::Receive (Ptr socket) Time sendTime = TimeStep (ts); NS_ASSERT (Simulator::Now () > sendTime); Time delta = Simulator::Now () - sendTime; + + m_avgRtt.Update (delta.GetMilliSeconds()); + m_recv++; m_traceRtt (delta); + + if (m_verbose) + { + std::cout << recvSize << " bytes from " << realFrom.GetIpv4() << ":" + << " icmp_seq=" << echo.GetSequenceNumber () + << " ttl=" << (unsigned)ipv4.GetTtl () + << " time=" << delta.GetMilliSeconds() << " ms\n"; + } } } } @@ -135,20 +165,8 @@ V4Ping::Write32 (uint8_t *buffer, uint32_t data) } void -V4Ping::StartApplication (void) +V4Ping::Send () { - NS_LOG_FUNCTION (this); - m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory")); - NS_ASSERT (m_socket != 0); - m_socket->SetAttribute ("Protocol", UintegerValue (1)); // icmp - m_socket->SetRecvCallback (MakeCallback (&V4Ping::Receive, this)); - InetSocketAddress src = InetSocketAddress (Ipv4Address::GetAny (), 0); - int status; - status = m_socket->Bind (src); - NS_ASSERT (status != -1); - InetSocketAddress dst = InetSocketAddress (m_remote, 0); - status = m_socket->Connect (dst); - NS_ASSERT (status != -1); Ptr p = Create (); Icmpv4Echo echo; echo.SetSequenceNumber (m_seq); @@ -161,7 +179,10 @@ V4Ping::StartApplication (void) // (where any difference would show up anyway) and borrow that code. Don't // be too surprised when you see that this is a little endian convention. // - uint8_t data[4 * sizeof(uint32_t)]; + uint8_t data[m_size]; + for (uint32_t i = 0; i < m_size; ++i) data[i] = 0; + NS_ASSERT (m_size >= 16); + uint32_t tmp = GetNode ()->GetId (); Write32 (&data[0 * sizeof(uint32_t)], tmp); @@ -176,7 +197,7 @@ V4Ping::StartApplication (void) tmp = now & 0xffffffff; Write32 (&data[3 * sizeof(uint32_t)], tmp); - Ptr dataPacket = Create ((uint8_t *) &data, 16); + Ptr dataPacket = Create ((uint8_t *) &data, m_size); echo.SetData (dataPacket); p->AddHeader (echo); Icmpv4Header header; @@ -185,12 +206,56 @@ V4Ping::StartApplication (void) p->AddHeader (header); m_socket->Send (p, 0); + m_next = Simulator::Schedule (m_interval, & V4Ping::Send, this); +} + +void +V4Ping::StartApplication (void) +{ + NS_LOG_FUNCTION (this); + + m_started = Simulator::Now (); + if (m_verbose) + { + std::cout << "PING " << m_remote << " 56(84) bytes of data.\n"; + } + + m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory")); + NS_ASSERT (m_socket != 0); + m_socket->SetAttribute ("Protocol", UintegerValue (1)); // icmp + m_socket->SetRecvCallback (MakeCallback (&V4Ping::Receive, this)); + InetSocketAddress src = InetSocketAddress (Ipv4Address::GetAny (), 0); + int status; + status = m_socket->Bind (src); + NS_ASSERT (status != -1); + InetSocketAddress dst = InetSocketAddress (m_remote, 0); + status = m_socket->Connect (dst); + NS_ASSERT (status != -1); + + Send (); } void V4Ping::StopApplication (void) { NS_LOG_FUNCTION (this); + m_next.Cancel(); m_socket->Close (); + + if (m_verbose) + { + std::ostringstream os; + os.precision (4); + os << "--- " << m_remote << " ping statistics ---\n" + << m_seq << " packets transmitted, " << m_recv << " received, " + << ((m_seq - m_recv) * 100 / m_seq) << "% packet loss, " + << "time " << (Simulator::Now () - m_started).GetMilliSeconds () << "ms\n"; + + if (m_avgRtt.Count () > 0) + os << "rtt min/avg/max/mdev = " << m_avgRtt.Min() << "/" << m_avgRtt.Avg() << "/" + << m_avgRtt.Max() << "/" << m_avgRtt.Err() + << " ms\n"; + std::cout << os.str(); + } } diff --git a/src/applications/v4ping/v4ping.h b/src/applications/v4ping/v4ping.h index 32815e643..685293d58 100644 --- a/src/applications/v4ping/v4ping.h +++ b/src/applications/v4ping/v4ping.h @@ -4,6 +4,8 @@ #include "ns3/application.h" #include "ns3/traced-callback.h" #include "ns3/nstime.h" +#include "ns3/average.h" +#include "ns3/simulator.h" namespace ns3 { @@ -26,11 +28,30 @@ private: virtual void DoDispose (void); uint32_t GetApplicationId (void) const; void Receive (Ptr socket); + void Send (); + /// Remote address Ipv4Address m_remote; + /// Wait interval seconds between sending each packet + Time m_interval; + /** + * Specifies the number of data bytes to be sent. + * The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. + */ + uint32_t m_size; Ptr m_socket; uint16_t m_seq; TracedCallback