-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleach-routing-table.h
More file actions
291 lines (254 loc) · 6.64 KB
/
leach-routing-table.h
File metadata and controls
291 lines (254 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#ifndef LEACH_ROUTING_TABLE
#define LEACH_ROUTING_TABLE
#include <bits/stdint-uintn.h>
#include <cassert>
#include <map>
#include <sys/types.h>
#include "ns3/event-id.h"
#include "ns3/ipv4-address.h"
#include "ns3/ipv4-interface-address.h"
#include "ns3/ipv4.h"
#include "ns3/ipv4-route.h"
#include "ns3/ptr.h"
#include "ns3/timer.h"
#include "ns3/net-device.h"
#include "ns3/output-stream-wrapper.h"
namespace ns3 {
namespace leach {
enum RouteFlags
{
VALID = 0,
INVALID = 1,
};
/**
* \ingroup leach
* \brief Routing table entry
*/
class RoutingTableEntry
{
public:
RoutingTableEntry (Ptr<NetDevice> dev = 0, Ipv4Address dstAddr = Ipv4Address (),
Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), Ipv4Address nextHopAddr = Ipv4Address ());
~RoutingTableEntry ();
void
Reset ()
{
m_iface = Ipv4InterfaceAddress ();
m_ipv4Route -> SetDestination (Ipv4Address ());
m_ipv4Route -> SetGateway (Ipv4Address ());
m_ipv4Route -> SetSource(m_iface.GetLocal());
m_flag = VALID;
}
void
Copy (RoutingTableEntry from)
{
;
}
Ipv4Address
GetDestination() const
{
return m_ipv4Route->GetDestination();
}
Ptr<Ipv4Route>
GetRoute () const
{
return m_ipv4Route;
}
void
SetRoute (Ptr<Ipv4Route> route)
{
m_ipv4Route = route;
}
void
SetNextHop (Ipv4Address nextHop)
{
m_ipv4Route -> SetGateway (nextHop);
}
Ipv4Address
GetNextHop () const
{
return m_ipv4Route->GetGateway();
}
void
SetOutputDevice (Ptr<NetDevice> outputDevice)
{
m_ipv4Route->SetOutputDevice(outputDevice);
}
Ptr<NetDevice>
GetOutputDevice () const
{
return m_ipv4Route->GetOutputDevice ();
}
Ipv4InterfaceAddress
GetInterface () const
{
return m_iface;
}
void
SetInterface (Ipv4InterfaceAddress iface)
{
m_iface = iface;
}
void
SetFlag (RouteFlags flag)
{
m_flag = flag;
}
RouteFlags
GetFlag () const
{
return m_flag;
}
/**
* \brief Compare destination address
* \return true if equal
*/
bool
operator== (Ipv4Address const destination) const
{
return (m_ipv4Route->GetDestination () == destination);
}
void
Print (Ptr<OutputStreamWrapper> stream) const;
private:
// Fields
/**
* Ip route, include
* - destination address
* - source address
* - next hop address (gateway)
* - output device
*/
Ptr<Ipv4Route> m_ipv4Route;
// Output interface address
Ipv4InterfaceAddress m_iface;
// Routing Flags: valid, invalid or searching
RouteFlags m_flag;
};
class RoutingTable
{
public:
RoutingTable ();
/**
* Add Routing table entry if it doesn't exist in routing table
* \param routingTableEntry
* \return true in success
*/
bool
AddRoute (RoutingTableEntry &routingTableEntry);
/**
* Delete existing routing table entry for destination address
* \param dstAddr destination address
* \return true on success
*/
bool
DeleteRoute (Ipv4Address dstAddr);
/**
* Lookup routing table entry with destination address dstAddr
* \param dstAddr destination address
* \param rtEntry routing table entry
* \return true on success
*/
bool
LookupRoute (Ipv4Address dstAddr, RoutingTableEntry &rtEntry);
bool
LookupRoute (Ipv4Address id, RoutingTableEntry &rtEntry, bool forRouteInput);
/**
* Update route table entry with route table entry rtEntry
* \param rtEntry routing table entry
* \return true on success
*/
bool
Update (RoutingTableEntry &rtEntry);
/**
* Lookup list of address for which nextHop is next hop address
* \param nextHop is address for which we want list of destination
* \param dstList is list holding all destination addresses
*/
void
GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, RoutingTableEntry> &dstList);
/**
* Lookup list of address in routing table
* \param allRoutes is the list holding addresses present in nodes routing table
*/
void
GetListOfAllRoutes (std::map<Ipv4Address, RoutingTableEntry> &allRoutes);
/**
* Delete all routes for interface
* \param iface interface to delete routing table
*/
void
DeleteAllRouteFromInterface (Ipv4InterfaceAddress iface);
// Delete all entries from routing table
void
Clear ()
{
m_ipv4AddressEntry.clear();
}
/// Print Routing Table
void
Print (Ptr<OutputStreamWrapper> stream) const;
/// Provide number of routes in that nodes routing table
uint32_t
RoutingTableSize ();
/**
* Add an event for a destination address so update that the update to for that destination is sent
* after the event is completed
* \param address destination address for which this event is running
* \param id unique eventid that was generated
* \return true on success
*/
bool
AddIpv4Event (Ipv4Address address, EventId id);
/**
* Clear up entry from map after event is complete
* \param address destination for which event is running
* \return true on success
*/
bool
DeleteIpv4Event (Ipv4Address address);
/**
* Check if event is running
* \param address destination address for which event is running
* \return true on success
*/
bool
AnyRunningEvent (Ipv4Address address);
/**
* Force Delete an update waiting for settling time to complete as better update to
* same address was recieved
* \param address destination address for which event is running
* \return true on success
*/
bool
ForceDeleteIpv4Event (Ipv4Address address);
/**
* Get eventid associated with that address
* \param address destination address for which event is running
* \return EventId on finding out an event associated
* else return NULL
*/
EventId
GetEventId (Ipv4Address address);
// Handle life time of invalid route
Time
GetHoldDownTime () const
{
return m_holdDownTime;
}
void
SetHoldDownTime (Time t)
{
m_holdDownTime = t;
}
private:
// Fields
/// an entry in routing table
std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
///an entry in event table
std::map<Ipv4Address, EventId> m_ipv4Events;
Time m_holdDownTime;
};
} /* namespace leach */
} /* namespace ns3 */
#endif /* LEACH_ROUTING_TABLE */