author | Pavel Boyko <boyko@iitp.ru> |
Tue, 07 Jul 2009 17:31:43 +0400 | |
changeset 5562 | 2fc3138b5622 |
parent 5561 | f74c7723afd3 |
child 5564 | 95a3e7beb97b |
permissions | -rwxr-xr-x |
5537 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 1997, 1998 Carnegie Mellon University. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
18 |
* Authors: The AODV code developed by the CMU/MONARCH group was optimized and |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
19 |
* tuned by Samir Das and Mahesh Marina, University of Cincinnati. |
5537 | 20 |
* The work was partially done in Sun Microsystems. |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
21 |
* |
5537 | 22 |
* Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru> |
23 |
*/ |
|
24 |
#ifndef __aodv_rtable_h__ |
|
25 |
#define __aodv_rtable_h__ |
|
26 |
||
27 |
#include <cassert> |
|
28 |
#include <vector> |
|
29 |
#include <sys/types.h> |
|
30 |
#include "ns3/ipv4.h" |
|
31 |
#include "ns3/nstime.h" |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
32 |
#include "ns3/nstime.h" |
5537 | 33 |
|
34 |
namespace ns3 { |
|
35 |
namespace aodv { |
|
36 |
||
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
37 |
#define INFINITY2 0xff |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
38 |
#define DELETE_PERIOD 10 // seconds. TODO: remove defines |
5537 | 39 |
|
5538 | 40 |
/** |
41 |
* \ingroup aodv |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
42 |
* |
5538 | 43 |
* \brief AODV Precursor list data structure |
5537 | 44 |
*/ |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
45 |
class AODV_Precursor |
5537 | 46 |
{ |
47 |
friend class AODV; |
|
48 |
friend class aodv_rt_entry; |
|
49 |
public: |
|
50 |
AODV_Precursor(Ipv4Address const & a) : pc_addr(a) {} |
|
51 |
bool operator==(AODV_Precursor const & o) const |
|
52 |
{ |
|
53 |
return (pc_addr == o.pc_addr); |
|
54 |
} |
|
55 |
protected: |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
56 |
/// Precursor address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
57 |
Ipv4Address pc_addr; |
5537 | 58 |
}; |
59 |
||
5538 | 60 |
/** |
61 |
* \ingroup aodv |
|
62 |
* \brief Route Table Entry |
|
5537 | 63 |
*/ |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
64 |
class aodv_rt_entry |
5537 | 65 |
{ |
66 |
public: |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
67 |
aodv_rt_entry(); |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
68 |
aodv_rt_entry(Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
69 |
u_int16_t hops,Ipv4Address nextHop, Time lifetime); |
5537 | 70 |
~aodv_rt_entry(); |
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
71 |
|
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
72 |
///\name Precursors management |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
73 |
//\{ |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
74 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
75 |
* Insert precursor in precursor list if it doesn't yet exist in the list |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
76 |
* \param id precursor address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
77 |
* \return true on success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
78 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
79 |
bool pc_insert(Ipv4Address id); |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
80 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
81 |
* Lookup precursor by address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
82 |
* \param id precursor address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
83 |
* \param p precursor with address id if exists |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
84 |
* \return true on success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
85 |
*/ |
5537 | 86 |
bool pc_lookup(Ipv4Address id, AODV_Precursor & p); |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
87 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
88 |
* \brief Delete precursor |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
89 |
* \param id precursor address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
90 |
* \return true on success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
91 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
92 |
bool pc_delete(Ipv4Address id); |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
93 |
/// Delete all precursors |
5538 | 94 |
void pc_delete(); |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
95 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
96 |
* \return true if precursor list empty |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
97 |
*/ |
5538 | 98 |
bool pc_empty() const; |
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
99 |
//\} |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
100 |
|
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
101 |
/// Mark entry as "down" (i.e. disable it) |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
102 |
void Down (); |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
103 |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
104 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
105 |
* \brief Compare destination address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
106 |
* \return true if equal |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
107 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
108 |
bool operator==(Ipv4Address const dst) const |
5537 | 109 |
{ |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
110 |
return rt_dst == dst; |
5537 | 111 |
} |
112 |
||
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
113 |
/// When I can send another request |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
114 |
Time rt_req_timeout; |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
115 |
/// Number of route requests |
5561
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
116 |
uint8_t rt_req_cnt; |
5537 | 117 |
|
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
118 |
private: |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
119 |
friend class aodv_rtable; |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
120 |
friend class RoutingProtocol; |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
121 |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
122 |
/// Destination address |
5538 | 123 |
Ipv4Address rt_dst; |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
124 |
/// Valid Destination Sequence Number flag |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
125 |
bool validSeqNo; |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
126 |
/// Destination Sequence Number, if validSeqNo = true |
5561
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
127 |
uint32_t rt_seqno; |
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
128 |
/// Interface index |
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
129 |
uint32_t rt_interface; |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
130 |
/// Hop Count (number of hops needed to reach destination) |
5561
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
131 |
uint16_t rt_hops; |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
132 |
/// Last valid hop count |
5561
f74c7723afd3
AODV protocol copy-paste in progress
Pavel Boyko <boyko@iitp.ru>
parents:
5544
diff
changeset
|
133 |
uint16_t rt_last_hop_count; |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
134 |
/// Next hop IP address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
135 |
Ipv4Address rt_nexthop; |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
136 |
/// List of precursors |
5537 | 137 |
std::vector<AODV_Precursor> rt_pclist; |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
138 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
139 |
* \brief Expiration or deletion time of the route |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
140 |
* Lifetime field in the routing table plays dual role -- |
5544
e149190912e4
Rtable cosmetics + RREQ header
Pavel Boyko <boyko@iitp.ru>
parents:
5543
diff
changeset
|
141 |
* for an active route it is the expiration time, and for an invalid route |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
142 |
* it is the deletion time. |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
143 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
144 |
Time rt_lifetime; |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
145 |
/// Routing flags: down, up or in repair |
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
146 |
uint8_t rt_flags; /*TODO use enum*/ |
5537 | 147 |
|
5538 | 148 |
#define RTF_DOWN 0 |
149 |
#define RTF_UP 1 |
|
150 |
#define RTF_IN_REPAIR 2 |
|
151 |
#define MAX_HISTORY 3 |
|
5537 | 152 |
|
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
153 |
// TODO review and delete |
5538 | 154 |
double rt_disc_latency[MAX_HISTORY]; |
155 |
char hist_indx; |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
156 |
/// Last ttl value used |
5544
e149190912e4
Rtable cosmetics + RREQ header
Pavel Boyko <boyko@iitp.ru>
parents:
5543
diff
changeset
|
157 |
uint16_t rt_req_last_ttl; |
5537 | 158 |
}; |
159 |
||
5538 | 160 |
/** |
161 |
* \ingroup aodv |
|
162 |
* The Routing Table |
|
5537 | 163 |
*/ |
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
164 |
class aodv_rtable |
5537 | 165 |
{ |
166 |
public: |
|
167 |
aodv_rtable() {} |
|
168 |
||
169 |
// aodv_rt_entry * head() {TODO} |
|
5542
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
170 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
171 |
* Add routing table entry if it doesn't yet exist in routing table |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
172 |
* \param r routing table entry |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
173 |
* \return true in success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
174 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
175 |
bool rt_add(aodv_rt_entry const & r); |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
176 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
177 |
* Delete routing table entry |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
178 |
* \param dst destination address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
179 |
* \return true on success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
180 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
181 |
bool rt_delete(Ipv4Address dst); |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
182 |
/** |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
183 |
* Lookup routing table entry |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
184 |
* \param dst destination address |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
185 |
* \param rt entry with destination address dst, if exists |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
186 |
* \return true on success |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
187 |
*/ |
1b504e63a1b1
aodv_rtable unit test added
Borovkova Elena <borovkovaes@iitp.ru>
parents:
5540
diff
changeset
|
188 |
bool rt_lookup(Ipv4Address dst, aodv_rt_entry & rt) const; |
5562
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
189 |
/// Set routing table entry flags |
2fc3138b5622
AODV RoutingProtocol stub finished
Pavel Boyko <boyko@iitp.ru>
parents:
5561
diff
changeset
|
190 |
void SetEntryState (Ipv4Address dst, uint8_t state /*TODO use enum*/); |
5537 | 191 |
|
192 |
private: |
|
193 |
std::vector<aodv_rt_entry> rthead; |
|
194 |
}; |
|
195 |
||
196 |
}} |
|
197 |
||
198 |
#endif /* _aodv__rtable_h__ */ |