-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaodv.h
574 lines (470 loc) · 15.2 KB
/
aodv.h
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/*
Copyright (c) 1997, 1998 Carnegie Mellon University. All Rights
Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.
*/
#ifndef __aodv_h__
#define __aodv_h__
//#include <agent.h>
//#include <packet.h>
//#include <sys/types.h>
//#include <cmu/list.h>
//#include <scheduler.h>
#include "timer-handler.h"
#include <cmu-trace.h>
#include <priqueue.h>
#include <aodv/aodv_rtable.h>
#include <aodv/aodv_rqueue.h>
#include <classifier/classifier-port.h>
#include <mobilenode.h>
#include <god.h>
/*
Allows local repair of routes
*/
#define AODV_LOCAL_REPAIR
/*
Allows AODV to use link-layer (802.11) feedback in determining when
links are up/down.
*/
#define AODV_LINK_LAYER_DETECTION
/*
Causes AODV to apply a "smoothing" function to the link layer feedback
that is generated by 802.11. In essence, it requires that RT_MAX_ERROR
errors occurs within a window of RT_MAX_ERROR_TIME before the link
is considered bad.
*/
#define AODV_USE_LL_METRIC
/*
Only applies if AODV_USE_LL_METRIC is defined.
Causes AODV to apply omniscient knowledge to the feedback received
from 802.11. This may be flawed, because it does not account for
congestion.
*/
//#define AODV_USE_GOD_FEEDBACK
#define R 4 // maximun retransmitions.
#include <mac.h>
class AODV;
class aodv_rpt_entry;
class waitTimer;
class aodv_rptable;
#define MY_ROUTE_TIMEOUT 6 //10 // 100 seconds
#define ACTIVE_ROUTE_TIMEOUT 3 //10 // 50 seconds
#define REV_ROUTE_LIFE 6 // 5 seconds
#define BCAST_ID_SAVE 6 // 3 seconds
// No. of times to do network-wide search before timing out for
// MAX_RREQ_TIMEOUT sec.
#define RREQ_RETRIES 3
// timeout after doing network-wide search RREQ_RETRIES times
#define MAX_RREQ_TIMEOUT 10.0 //sec
/* Various constants used for the expanding ring search */
#define TTL_START 5
#define TTL_THRESHOLD 7
#define TTL_INCREMENT 2
// This should be somewhat related to arp timeout
#define NODE_TRAVERSAL_TIME 0.03 // 30 ms
#define LOCAL_REPAIR_WAIT_TIME 0.15 //sec
// Should be set by the user using best guess (conservative)
#define NETWORK_DIAMETER 30 // 30 hops
// Must be larger than the time difference between a node propagates a route
// request and gets the route reply back.
//#define RREP_WAIT_TIME (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms
//#define RREP_WAIT_TIME (2 * REV_ROUTE_LIFE) // seconds
#define RREP_WAIT_TIME 1.0 // sec
#define ID_NOT_FOUND 0x00
#define ID_FOUND 0x01
//#define INFINITY 0xff
// The followings are used for the forward() function. Controls pacing.
#define DELAY 1.0 // random delay
#define NO_DELAY -1.0 // no delay
// think it should be 30 ms
#define ARP_DELAY 0.01 // fixed delay to keep arp happy
//#define HELLO_INTERVAL 1 // 1000 ms
#define ALLOWED_HELLO_LOSS 2 //3 // packets
#define BAD_LINK_LIFETIME 3 // 3000 ms
//#define MaxHelloInterval (1.25 * HELLO_INTERVAL)
//#define MinHelloInterval (0.75 * HELLO_INTERVAL)
#define urt_interver 50 // 5s
/*
Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
*/
// start
class aodv_rt_entry;
class AODV;
class AODV_Neighbor {
friend class AODV;
friend class aodv_rt_entry;
public:
AODV_Neighbor(u_int32_t a) { nb_addr = a; }
protected:
LIST_ENTRY(AODV_Neighbor) nb_link;
nsaddr_t nb_addr;
double nb_expire; // ALLOWED_HELLO_LOSS * HELLO_INTERVAL
};
LIST_HEAD(aodv_ncache, AODV_Neighbor);
/*
AODV Precursor list data structure
*/
class AODV_Precursor {
friend class AODV;
friend class aodv_rt_entry;
public:
AODV_Precursor(u_int32_t a) { pc_addr = a; }
protected:
LIST_ENTRY(AODV_Precursor) pc_link;
nsaddr_t pc_addr; // precursor address
};
LIST_HEAD(aodv_precursors, AODV_Precursor);
/*
Route Table Entry
*/
class ruTimer : public Handler {
public:
ruTimer(aodv_rt_entry* a) : agent(a) {i = 0;}
void handle(Event*);
private:
aodv_rt_entry *agent;
Event intr;
int i;
};
class aodv_rt_entry {
friend class aodv_rtable;
friend class AODV;
friend class LocalRepairTimer;
friend class ruTimer;
public:
aodv_rt_entry();
~aodv_rt_entry();
void nb_insert(nsaddr_t id);
AODV_Neighbor* nb_lookup(nsaddr_t id);
void pc_insert(nsaddr_t id);
AODV_Precursor* pc_lookup(nsaddr_t id);
void pc_delete(nsaddr_t id);
void pc_delete(void);
bool pc_empty(void);
double rt_req_timeout; // when I can send another req
u_int8_t rt_req_cnt; // number of route requests
AODV *a;
protected:
LIST_ENTRY(aodv_rt_entry) rt_link;
nsaddr_t 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
nsaddr_t rt_nexthop; // next hop IP address
/* list of precursors */
aodv_precursors rt_pclist;
float rt_expire; // when entry expires double before
u_int8_t rt_flags;
float linkDuration;
//double forwardPt;
//double replyPt;
//double pathCost;
//double El_;
ruTimer rutimer;
#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.
*/
aodv_ncache rt_nblist;
};
/*
The Routing Table
*/
class aodv_rtable {
public:
aodv_rtable() { LIST_INIT(&rthead); }
aodv_rt_entry* head() { return rthead.lh_first; }
aodv_rt_entry* rt_add(nsaddr_t id,AODV *a_);
void rt_delete(nsaddr_t id);
aodv_rt_entry* rt_lookup(nsaddr_t id);
void printf_inf_rtable();
private:
LIST_HEAD(aodv_rthead, aodv_rt_entry) rthead;
};
//end
class aodv_rptable{
public:
aodv_rptable(AODV* a) {LIST_INIT(&rpthead);Za = a;}
aodv_rpt_entry* head() { return rpthead.lh_first; }
aodv_rpt_entry* rpt_add(nsaddr_t id,double time_);
aodv_rpt_entry* rt_lookup(nsaddr_t id);
void rt_delete(nsaddr_t id);
protected:
AODV* Za;
LIST_HEAD(aodv_rptable_head,aodv_rpt_entry) rpthead;
};
class BroadcastTimer : public Handler {
public:
BroadcastTimer(AODV* a) : agent(a) {}
void handle(Event*);
private:
AODV *agent;
Event intr;
};
class HelloTimer : public Handler {
public:
HelloTimer(AODV* a) : agent(a) {}
void handle(Event*);
private:
AODV *agent;
Event intr;
};
class NeighborTimer : public Handler {
public:
NeighborTimer(AODV* a) : agent(a) {}
void handle(Event*);
private:
AODV *agent;
Event intr;
};
class RouteCacheTimer : public Handler {
public:
RouteCacheTimer(AODV* a) : agent(a) {}
void handle(Event*);
private:
AODV *agent;
Event intr;
};
class LocalRepairTimer : public Handler {
public:
LocalRepairTimer(AODV* a) : agent(a) {}
void handle(Event*);
private:
AODV *agent;
Event intr;
};
/*
Broadcast ID Cache
*/
class BroadcastID {
friend class AODV;
public:
BroadcastID(nsaddr_t i, u_int32_t b) { src = i; id = b; }
protected:
LIST_ENTRY(BroadcastID) link;
nsaddr_t src;
u_int32_t id;
double expire; // now + BCAST_ID_SAVE s
};
LIST_HEAD(aodv_bcache, BroadcastID);
/*
The Routing Agent
*/
class AODV: public Agent {
/*
* make some friends first
*/
friend class aodv_rt_entry;
friend class BroadcastTimer;
friend class HelloTimer;
friend class NeighborTimer;
friend class RouteCacheTimer;
friend class LocalRepairTimer;
friend class aodv_rpt_entry;
public:
AODV(nsaddr_t id);
void recv(Packet *p, Handler *);
nsaddr_t NodeCal;
protected:
int command(int, const char *const *);
int initialized() { return 1 && target_; }
/*
* Route Table Management
*/
void rt_resolve(Packet *p);
void rt_update(aodv_rt_entry *rt, u_int32_t seqnum,
u_int16_t metric, nsaddr_t nexthop,
double expire_time);
void rt_down(aodv_rt_entry *rt);
void local_rt_repair(aodv_rt_entry *rt, Packet *p);
// Kadd
float xpos;
float ypos;
float zpos;
float iEnergy;
float Velocity;
float Dx,Dy;
MobileNode *iDNode;
MobileNode *iSNode;
float velocity;
float aa1,bb1,aa2,bb2,r,denta,linkduration; //denta1,denta2,
//int l01,l21,l32,l43,l54,l65,l6,l86,l98,l10,l11,l12,lover12,lover15,lover20,lover50;
float a1,b1,a2,b2;
float test;
float minimum;
public:
void rt_ll_failed(Packet *p);
void handle_link_failure(nsaddr_t id);
void sendRequest(nsaddr_t dst);
//int typeroute; // 0 AODV tinh khiet, 1 AODV cua ho, 2 AODV cua ta
//int hesoa;
float getlinkduration(int Snode, int DNode);
protected:
void rt_purge(void);
void enque(aodv_rt_entry *rt, Packet *p);
Packet* deque(aodv_rt_entry *rt);
float interval_wait_request_time;
/*
* Neighbor Management
*/
void nb_insert(nsaddr_t id);
AODV_Neighbor* nb_lookup(nsaddr_t id);
void nb_delete(nsaddr_t id);
void nb_purge(void);
/*
* Broadcast ID Management
*/
void id_insert(nsaddr_t id, u_int32_t bid);
bool id_lookup(nsaddr_t id, u_int32_t bid);
void id_purge(void);
/*
* Packet TX Routines
*/
void forward(aodv_rt_entry *rt, Packet *p, double delay);
void sendHello(void);
void sendReply(nsaddr_t ipdst, u_int32_t hop_count,
nsaddr_t rpdst, u_int32_t rpseq,
double lifetime, double timestamp); //,double optimized
void sendError(Packet *p, bool jitter = true);
/*
* Packet RX Routines
*/
void recvAODV(Packet *p);
void recvHello(Packet *p);
void recvRequest(Packet *p);
void recvReply(Packet *p);
void recvError(Packet *p);
/*
* History management
*/
double PerHopTime(aodv_rt_entry *rt);
nsaddr_t index; // IP Address of this node
u_int32_t seqno; // Sequence Number
int bid; // Broadcast ID
aodv_rtable rthead; // routing table
aodv_ncache nbhead; // Neighbor Cache
aodv_bcache bihead; // Broadcast ID Cache
/*
* Timers
*/
BroadcastTimer btimer;
HelloTimer htimer;
NeighborTimer ntimer;
RouteCacheTimer rtimer;
LocalRepairTimer lrtimer;
/*
* Routing Table
*/
aodv_rtable rtable;
aodv_rptable rptable;
/*
* A "drop-front" queue used by the routing layer to buffer
* packets to which it does not have a route.
*/
aodv_rqueue rqueue;
/*
* A mechanism for logging the contents of the routing
* table.
*/
Trace *logtarget;
/*
* A pointer to the network interface queue that sits
* between the "classifier" and the "link layer".
*/
PriQueue *ifqueue;
/*
* Logging stuff
*/
void log_link_del(nsaddr_t dst);
void log_link_broke(Packet *p);
void log_link_kept(nsaddr_t dst);
/* for passing packets up to agents */
PortClassifier *dmux_;
};
// design for waitTimer
class aodv_rppacket{
friend class AODV;
friend class aodv_rpt_entry;
public:
aodv_rppacket(){}
protected:
LIST_ENTRY(aodv_rppacket) rppacket_link;
nsaddr_t ipdst;
u_int32_t hop_count;
nsaddr_t rpdst;
u_int32_t rpseq;
double lifetime;
double timestamp;
//double optimizedLd;
//double el;
// double pathCost;
};
LIST_HEAD(aodv_rppacket_head, aodv_rppacket);
class waitTimer : public TimerHandler {
public:
waitTimer(aodv_rpt_entry *c):
TimerHandler(){
agent = c;
}
protected:
void expire(Event *e);
private:
aodv_rpt_entry * agent;
};
//anh cuong them
class aodv_rpt_entry{
friend class aodv_rptable;
friend class waitTimer;
public:
aodv_rpt_entry();
~aodv_rpt_entry();
aodv_rppacket* Heap() {rpphead.lh_first;}
aodv_rppacket* rpp_add();
void timeout();
protected:
LIST_ENTRY(aodv_rpt_entry) rptable_link;
nsaddr_t source;
waitTimer *wt_;
double time_;
aodv_rppacket_head rpphead;
AODV *Za;
aodv_rptable *rptable_;
};
#endif /* __aodv_h__ */