File: mdart_adp.h

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (163 lines) | stat: -rw-r--r-- 5,921 bytes parent folder | download | duplicates (8)
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
/*******************************************************************************
 *                                                                             *
 *   M-DART Routing Protocol                                                   *
 *                                                                             *
 *   Copyright (C) 2006 by Marcello Caleffi                                    *
 *   marcello.caleffi@unina.it                                                 *
 *                                                                             *
 * 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 M-DART code has been developed by Marcello Caleffi during his Ph.D. at  *
 * the Department of Biomedical, Electronic and Telecommunications Engineering *
 * University of Naples Federico II, Italy.                                    *
 *                                                                             *
 * In order to give credit and recognition to the author, if you use M-DART    *
 * results or results obtained by modificating the M-DART source code, please  *
 * cite one of the following papers:                                           *
 * - M. Caleffi, L. Paura, "M-DART: Multi-Path Dynamic Address RouTing",       *
 *   Wireless Communications and Mobile Computing, 2010                        *
 * - M. Caleffi, G. Ferraiuolo, L. Paura, "Augmented Tree-based Routing        *
 *   Protocol for Scalable Ad Hoc Networks", Proc. of IEEE MASS '07: IEEE      *
 *   Internatonal Conference on Mobile Adhoc and Sensor Systems, Pisa (Italy), *
 *   October 8-11 2007.                                                        *
 *                                                                             *
 ******************************************************************************/



#ifndef __mdart_adp_h__
#define __mdart_adp_h__


#include <mdart/mdart.h>
#include <mdart/mdart_function.h>
#include <mdart/mdart_dht.h>



//------------------------------------------------------------------------------
// Address Discovery Protocol (ADP)
//------------------------------------------------------------------------------
class MDART;
class ADPDaupTimer;
class ADPDarqTimer;

class ADP {
public:
	// ADP
	ADP(MDART* mdart);
	~ADP();
	// ADP network address function
	void					updateAdd();
	// ADP message functions
	void					checkDarq();
	void					sendDarq(nsaddr_t, int);
	void					recvDarq(Packet*);
	void					sendDarp(Packet*);
	void					recvDarp(Packet*);
	void					sendDaup();
	void					recvDaup(Packet*);
	void					sendDabr();
	void					recvDabr(Packet*);
	// ADP DHT functions
	void					addEntry(nsaddr_t id, nsaddr_t address);
	void					addEntry(nsaddr_t id, nsaddr_t address, double);
	inline uint32_t			DHTSize() {
		return dht_->DHTSize();
	}
	inline void				printDHT() {
		return dht_->printDHT();
	}
	inline nsaddr_t			findAdd(nsaddr_t id) {
		return dht_->findAdd(id);
	}
	inline DHT_Entry*		getEntry(u_int32_t pos) {
		return dht_->getEntry(pos);
	}
	inline nsaddr_t			findId(nsaddr_t add) {
		return dht_->findId(add);
	}
private:
	inline u_int32_t	pckSeqNum() {
		return pckSeqNum_++;
	}
	// ADP private members
	MDART*		mdart_;
	DHT*		dht_;
	ADPDaupTimer*	timer_;
	ADPDarqTimer*	timerRx_;
	u_int32_t	pckSeqNum_;
};



//------------------------------------------------------------------------------
// ADP timers
//------------------------------------------------------------------------------
class ADPDaupTimer : public Handler {
public:
	ADPDaupTimer(ADP* adp) {
		adp_ = adp;
		counter = 0;
		handle((Event*) 0);
	}
	inline void	handle(Event*) {
		if (counter > 0) {
			adp_->sendDaup();
		}
		else {
			counter++;
		}
		double interval_ = ADP_DAUP_FREQ * (0.9 + 0.2 * Random::uniform());
		Scheduler::instance().schedule(this, &intr, interval_);
	}
protected:
	ADP*		adp_;
	Event		intr;
	uint32_t	counter;
};

class ADPDarqTimer : public Handler {
public:
	ADPDarqTimer(ADP* adp) {
		adp_ = adp;
		counter = 0;
		handle((Event*) 0);
	}
	void	handle(Event*) {
		if (counter > 0) {
			adp_->checkDarq();
		}
		else {
			counter++;
		}
		Scheduler::instance().schedule(this, &intr, ADP_DARQ_CHECK_FREQ);
	}
protected:
	ADP*		adp_;
	Event		intr;
	uint32_t	counter;
};



#endif /* __mdart_adp_h_ */