-
Notifications
You must be signed in to change notification settings - Fork 1
/
aodv.h
270 lines (172 loc) · 4.24 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
#ifndef AODV_H
#define AODV_H
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include <netinet/in.h>
#define AODV_CONFIG_PATH_NAME "Aodv"
#define AODV_CONFIG_VALUE_NAME_ADDRESS "Address"
#define AODV_CONFIG_VALUE_DEFAULT_ADDRESS (0x1)
#define AODV_PACKET_HDR_SIZE (20)
#define AODV_PACKET_DATA_SIZE (1000)
#define AODV_PACKET_SIZE (1020)
#define AODV_TX_QUEUE_SIZE (10)
#define AODV_MAX_NETWORK_SIZE (5)
#define AODV_BROADCAST_ADDR (0xFFFF)
#define AODV_RX_INTERVAL_MS (1000)
#define AODV_HELLO_INTERVAL_MS (2000)
#define AODV_TX_QUEUE_POLL_INTERVAL_MS (500)
#define AODV_HELLO_TIMEOUT_MS (4000)
#define AODV_ACTIVE_ROUTE_TIMEOUT_MS (7000)
#define AODV_REVERSE_PATH_TIMEOUT_MS (3000)
#define AODV_QUEUE_POLL_TIMEOUT_MS (3000)
#define AODV_QUEUE_DATA_LIFETIME_MS (6000)
#define AODV_UDP_BUFSIZE (2048)
#define AODV_UDP_PORT (5055)
#define AODV_UDP_TIMEOUT_MS (1000)
/*
*
*
*
*
*
*
*
*
*/
typedef enum AODVPacketType
{
AODV_PACKET_NONE = 0,
AODV_PACKET_RREQ = 120,
AODV_PACKET_RREP = 121,
AODV_PACKET_RERR = 122,
AODV_PACKET_HELLO = 123,
AODV_PACKET_DATA = 124,
} eAODVPacketType;
typedef enum AODVDeviceType
{
AODV_DEVICE_NONE = 0,
AODV_DEVICE_AND = 1, //Android
AODV_DEVICE_XX = 2,
} eAODVDeviceType;
typedef enum AODVNetLinkType
{
AODV_NETLINK_NONE = 0,
AODV_NETLINK_ALL = 1,
AODV_NETLINK_XX = 2,
AODV_NETLINK_UDP = 3,
} eAODVNetLinkType;
typedef struct AODVPacketHdr
{
uint8_t PacketType;
uint8_t NetLinkType;
uint16_t SrcAddr; //origination addr
uint16_t SrcSeqNum;
uint16_t DestAddr; //final destination
uint16_t DestSeqNum;
uint16_t NextAddr; //address of next hop
uint16_t SendAddr; //address of previous hop
uint8_t SendDevType; //device type of sender
uint16_t BcastSeqNum;
uint8_t HopCnt;
uint16_t Length; //length of data
} __attribute__ ((packed)) tAODVPacketHdr;
typedef struct AODVPacket
{
tAODVPacketHdr Hdr; //20 bytes
uint8_t Data[0]; //pointer to data
} __attribute__((packed)) tAODVPacket;
typedef enum AODVThreadState
{
AODV_THREAD_STATE_NONE = 0x00,
AODV_THREAD_STATE_INIT = 0x01,
AODV_THREAD_STATE_RUN = 0x02,
AODV_THREAD_STATE_STOP = 0x04,
AODV_THREAD_STATE_END = 0x08,
} eAODVThreadState;
typedef struct AODVNode
{
uint16_t Addr;
uint16_t SeqNum;
uint16_t BcastSeqNum;
} tAODVNode;
typedef struct AODVRoute
{
bool Valid;
uint16_t DestAddr;
uint16_t DestSeqNum;
uint16_t BcastSeqNum;
uint16_t NextHopAddr;
uint8_t NetLinkType;
uint16_t HopCnt;
uint64_t Timeout;
} tAODVRoute;
typedef struct AODVStats
{
uint16_t HelloTxOkay;
uint16_t HelloTxFail;
uint16_t HelloRxOkay;
uint16_t DATATxOkay;
uint16_t DATATxFail;
uint16_t DATARxOkay;
uint16_t RREQTxOkay;
uint16_t RREQTxFail;
uint16_t RREQRxOkay;
uint16_t RREPTxOkay;
uint16_t RREPTxFail;
uint16_t RREPRxOkay;
uint16_t RERRTxOkay;
uint16_t RERRTxFail;
uint16_t RERRRxOkay;
uint16_t UDPTxOkay;
uint16_t UDPTxFail;
uint16_t UDPRxOkay;
} tAODVStats;
typedef struct AODVTxData
{
uint16_t Address;
uint16_t DataLen;
uint64_t Lifetime;
char *pData;
} tAODVTxData;
typedef struct AODV
{
tAODVNode Self;
tAODVRoute RouteTable[AODV_MAX_NETWORK_SIZE];
/*
*
*
*
*
*/
pthread_t TxCtrlThread;
pthread_attr_t TxCtrlThreadAttr;
uint8_t TxCtrlThreadState;
pthread_t RxCtrlThread;
pthread_attr_t RxCtrlThreadAttr;
uint8_t RxCtrlThreadState;
pthread_t TxDataThread;
pthread_attr_t TxDataThreadAttr;
uint8_t TxDataThreadState;
pthread_t UDPServerThread;
pthread_attr_t UDPServerThreadAttr;
uint8_t UDPServerThreadState;
int SendSockfd; //socket for UDP network transmissions
struct sockaddr_in SendSockAddr;
tAODVTxData *TxQueue[AODV_TX_QUEUE_SIZE]; //"queue" for processing data
pthread_mutex_t RouteTableMutex; //mutex for whenever RouteTable is read/modified
pthread_mutexattr_t RouteTableMutexAttr;
pthread_mutex_t TxMutex; //mutex to synchronize network transmissions
pthread_mutexattr_t TxMutexAttr;
pthread_mutex_t DataMutex;
pthread_mutexattr_t DataMutexAttr;
tAODVStats Stats;
} tAODV;
int AODV_Open(tAODV **ppAodv, pthread_attr_t *pAttr, char *pConfigFileName);
int AODV_Close(tAODV *pAodv);
int AODV_SendMessage(tAODV *pAodv, tAODVTxData *pTxData);
/*
*
*/
void AODV_PrintStats(tAODV *pAodv);
#endif // AODV_H