-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdr_sr.h
452 lines (388 loc) · 13.1 KB
/
hdr_sr.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
/*
* hdr_sr.h
* Copyright (C) 2000 by the University of Southern California
* $Id: hdr_sr.h,v 1.8 2005/08/25 18:58:04 johnh Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*
* The copyright of this module includes the following
* linking-with-specific-other-licenses addition:
*
* In addition, as a special exception, the copyright holders of
* this module give you permission to combine (via static or
* dynamic linking) this module with free software programs or
* libraries that are released under the GNU LGPL and with code
* included in the standard release of ns-2 under the Apache 2.0
* license or under otherwise-compatible licenses with advertising
* requirements (or modified versions of such code, with unchanged
* license). You may copy and distribute such a system following the
* terms of the GNU GPL for this module and the licenses of the
* other code concerned, provided that you include the source code of
* that other code when and as the GNU GPL requires distribution of
* source code.
*
* Note that people who make modified versions of this module
* are not obligated to grant this special exception for their
* modified versions; it is their choice whether to do so. The GNU
* General Public License gives permission to release a modified
* version without this exception; this exception also makes it
* possible to release a modified version which carries forward this
* exception.
*
*/
// Other copyrights might apply to parts of this software and are so
// noted when applicable.
//
// Ported from CMU/Monarch's code, appropriate copyright applies.
/* -*- c++ -*-
hdr_sr.h
source route header
*/
#ifndef sr_hdr_h
#define sr_hdr_h
#include <assert.h>
#include <packet.h>
#define SR_HDR_SZ 4 // size of constant part of hdr
#define MAX_SR_LEN 16 // longest source route we can handle
#define MAX_ROUTE_ERRORS 3 // how many route errors can fit in one pkt?
struct sr_addr {
int addr_type; /* same as hdr_cmn in packet.h */
nsaddr_t addr;
/*
* Metrics that I want to collect at each node
*/
double Pt_;
};
struct link_down {
int addr_type; /* same as hdr_cmn in packet.h */
nsaddr_t tell_addr; // tell this host
nsaddr_t from_addr; // that from_addr host can no longer
nsaddr_t to_addr; // get packets to to_addr host
};
//ACU281 Code Section Begin
/* ======================================================================
CBDS K Prime List Implementation
====================================================================== */
class kPrime
{
public:
kPrime()
{
kP_len_=0;
kP_=new sr_addr[MAX_SR_LEN];
}
struct sr_addr* kP_; //[MAX_SR_LEN];
int kP_len_;
struct sr_addr kP_Sender_;
};
// MCBDS
//class kPrimeList
//{
// public:
// kPrimeList()
// {
// kP_List_len_=0;
// kP_List_=new kPrime[MAX_SR_LEN];
// }
// kPrime* kP_List_; //[MAX_SR_LEN];
// int kP_List_len_;
//};
class kPrimeList_New
{
public:
kPrimeList_New()
{
kP_List_New_len_=0;
kP_List_New_=new nsaddr_t[MAX_SR_LEN];
}
nsaddr_t* kP_List_New_; //[MAX_SR_LEN];
int kP_List_New_len_;
};
struct recheck_msg {
int recheck_valid_; /* route checker header is valid? */
int recheck_isRep_; /* */
int recheck_destination_; // Original Destination
int recheck_value_; /* 0: packet is request; 1:suspect node is safe; 2:suspect node is malicious*/
int toMonitor_; /* which node must be monitored */
int maliciousID_; /* ID of suspect node */
int fullPath_;
};
struct inform_msg {
int inform_valid_;
int inform_id_; /* */
int inform_ttl_;
int malicious_ID_; /* ID of suspect node */
};
//ACU281 Code Section End
/* ======================================================================
DSR Packet Types
====================================================================== */
struct route_request {
int req_valid_; /* request header is valid? */
int req_id_; /* unique request identifier */
int req_ttl_; /* max propagation */
};
struct route_reply {
int rep_valid_; /* reply header is valid? */
int rep_rtlen_; /* # hops in route reply */
struct sr_addr rep_addrs_[MAX_SR_LEN];
};
struct route_error {
int err_valid_; /* error header is valid? */
int err_count_; /* number of route errors */
struct link_down err_links_[MAX_ROUTE_ERRORS];
};
/* ======================================================================
DSR Flow State Draft Stuff
====================================================================== */
struct flow_error {
nsaddr_t flow_src;
nsaddr_t flow_dst;
u_int16_t flow_id; /* not valid w/ default flow stuff */
};
struct flow_header {
int flow_valid_;
int hopCount_;
unsigned short flow_id_;
};
struct flow_timeout {
int flow_timeout_valid_;
unsigned long timeout_; // timeout in seconds...
};
struct flow_unknown {
int flow_unknown_valid_;
int err_count_;
struct flow_error err_flows_[MAX_ROUTE_ERRORS];
};
// default flow unknown errors
struct flow_default_err {
int flow_default_valid_;
int err_count_;
struct flow_error err_flows_[MAX_ROUTE_ERRORS];
};
/* ======================================================================
DSR Header
====================================================================== */
class hdr_sr {
private:
int valid_; /* is this header actually in the packet?
and initialized? */
int salvaged_; /* packet has been salvaged? */
int num_addrs_;
int cur_addr_;
struct sr_addr addrs_[MAX_SR_LEN];
int is_testPacket_;
struct route_request sr_request_;
struct route_reply sr_reply_;
struct route_error sr_error_;
// ACU281 Code Section Begin
struct recheck_msg sr_recheck_;
struct inform_msg sr_inform_;
//ACU281 Code Section end
struct flow_header sr_flow_;
struct flow_timeout sr_ftime_;
struct flow_unknown sr_funk_;
struct flow_default_err sr_fdef_unk;
//ACU281 Code Section Begin
// kPrimeList* kPList_; //MCBDS
kPrimeList_New* kPList_New_;
//ACU281 Code Section End
public:
static int offset_; /* offset for this header */
inline int& offset() { return offset_; }
inline static hdr_sr* access(const Packet* p) {
return (hdr_sr*)p->access(offset_);
}
inline int& valid() { return valid_; }
inline int& salvaged() { return salvaged_; }
inline int& num_addrs() { return num_addrs_; }
inline int& cur_addr() { return cur_addr_; }
inline int valid() const { return valid_; }
inline int salvaged() const { return salvaged_; }
inline int num_addrs() const { return num_addrs_; }
inline int cur_addr() const { return cur_addr_; }
inline struct sr_addr* addrs() { return addrs_; }
inline int& route_request() {return sr_request_.req_valid_; }
inline int& rtreq_seq() {return sr_request_.req_id_; }
inline int& max_propagation() {return sr_request_.req_ttl_; }
inline int& inform_msg() {return sr_inform_.inform_valid_; }
inline int& inform_seq() {return sr_inform_.inform_id_; }
inline int& inform_max_ttl() {return sr_inform_.inform_ttl_; }
inline int& inform_malicious_ID() {return sr_inform_.malicious_ID_;}
inline int& route_reply() {return sr_reply_.rep_valid_; }
inline int& route_reply_len() {return sr_reply_.rep_rtlen_; }
inline struct sr_addr* reply_addrs() {return sr_reply_.rep_addrs_; }
// ACU281 Code Section Begin
inline int& test_Packet() {return is_testPacket_;}
inline int& recheck_msg() {return sr_recheck_.recheck_valid_;}
inline int& recheck_msg_isReply() {return sr_recheck_.recheck_isRep_;}
inline int& recheck_msg_dest() {return sr_recheck_.recheck_destination_;}
inline int& recheck_msg_value() {return sr_recheck_.recheck_value_;}
inline int& recheck_msg_toMonitor() {return sr_recheck_.toMonitor_;}
inline int& recheck_msg_maliciousID() {return sr_recheck_.maliciousID_;}
inline int& recheck_msg_fullPath() {return sr_recheck_.fullPath_;}
// ACU281 Code Section End
inline int& route_error() {return sr_error_.err_valid_; }
inline int& num_route_errors() {return sr_error_.err_count_; }
inline struct link_down* down_links() {return sr_error_.err_links_; }
// Flow state stuff, ych 5/2/01
inline int &flow_header() { return sr_flow_.flow_valid_; }
inline u_int16_t &flow_id() { return sr_flow_.flow_id_; }
inline int &hopCount() { return sr_flow_.hopCount_; }
inline int &flow_timeout() { return sr_ftime_.flow_timeout_valid_; }
inline unsigned long &flow_timeout_time() { return sr_ftime_.timeout_; }
inline int &flow_unknown() { return sr_funk_.flow_unknown_valid_; }
inline int &num_flow_unknown() { return sr_funk_.err_count_; }
inline struct flow_error *unknown_flows() { return sr_funk_.err_flows_; }
inline int &flow_default_unknown() { return sr_fdef_unk.flow_default_valid_; }
inline int &num_default_unknown() { return sr_fdef_unk.err_count_; }
inline struct flow_error *unknown_defaults() { return sr_fdef_unk.err_flows_; }
inline int size() {
int sz = 0;
if (
recheck_msg() ||
num_addrs_ || route_request() ||
route_reply() || route_error() ||
flow_timeout() || flow_unknown() || flow_default_unknown())
sz += SR_HDR_SZ;
if (num_addrs_) sz += 4 * (num_addrs_ - 1);
if (route_reply()) sz += 5 + 4 * route_reply_len();
if (route_request()) sz += 8;
if (route_error()) sz += 16 * num_route_errors();
if (flow_timeout()) sz += 4;
if (flow_unknown()) sz += 14 * num_flow_unknown();
if (flow_default_unknown()) sz += 12 * num_default_unknown();
if (flow_header()) sz += 4;
//ACU281 Code Section Begin
if (recheck_msg()) sz+=8+8;
if (inform_msg()) sz+=8+4;
//ACU281 Code Section End
sz = ((sz+3)&(~3)); // align...
assert(sz >= 0);
#if 0
printf("Size: %d (%d %d %d %d %d %d %d %d %d)\n", sz,
(num_addrs_ || route_request() ||
route_reply() || route_error() ||
flow_timeout() || flow_unknown() ||
flow_default_unknown()) ? SR_HDR_SZ : 0,
num_addrs_ ? 4 * (num_addrs_ - 1) : 0,
route_reply() ? 5 + 4 * route_reply_len() : 0,
route_request() ? 8 : 0,
route_error() ? 16 * num_route_errors() : 0,
flow_timeout() ? 4 : 0,
flow_unknown() ? 14 * num_flow_unknown() : 0,
flow_default_unknown() ? 12 * num_default_unknown() : 0,
flow_header() ? 4 : 0);
#endif
return sz;
}
// End Flow State stuff
inline nsaddr_t& get_next_addr() {
assert(cur_addr_ < num_addrs_);
return (addrs_[cur_addr_ + 1].addr);
}
inline int& get_next_type() {
assert(cur_addr_ < num_addrs_);
return (addrs_[cur_addr_ + 1].addr_type);
}
inline void append_addr(nsaddr_t a, int type) {
assert(num_addrs_ < MAX_SR_LEN-1);
addrs_[num_addrs_].addr_type = type;
addrs_[num_addrs_++].addr = a;
}
inline void init() {
valid_ = 1;
salvaged_ = 0;
num_addrs_ = 0;
cur_addr_ = 0;
//ACU281 Code Section Begin
//kPList_=new kPrimeList(); //MCBDS
kPList_New_=new kPrimeList_New();
//kPList_.kP_List_len_=0;
recheck_msg()=0;
recheck_msg_isReply()=0;
recheck_msg_dest()=0;
recheck_msg_value()=0;
is_testPacket_=0; // No=0 Request=1 Response=2
inform_msg()=0;
inform_seq()=0;
//ACU281 Code Section End
route_request() = 0;
route_reply() = 0;
route_reply_len() = 0;
route_error() = 0;
num_route_errors() = 0;
flow_timeout() = 0;
flow_unknown() = 0;
flow_default_unknown() = 0;
flow_header() = 0;
}
#if 0
#ifdef DSR_CONST_HDR_SZ
/* used to estimate the potential benefit of removing the
src route in every packet */
inline int size() {
return SR_HDR_SZ;
}
#else
inline int size() {
int sz = SR_HDR_SZ +
4 * (num_addrs_ - 1) +
4 * (route_reply() ? route_reply_len() : 0) +
8 * (route_error() ? num_route_errors() : 0);
assert(sz >= 0);
return sz;
}
#endif // DSR_CONST_HDR_SZ
#endif // 0
void dump(char *);
char* dump();
//ACU281 Code Section Begin
/*
inline kPrime newKP()
{
return new kPrime();
}
*/
// MCBDS
//inline bool addKPrime(kPrime& kp){
// if(kPList_->kP_List_len_<MAX_SR_LEN)
// {
// kPList_->kP_List_[kPList_->kP_List_len_]=kp;
// kPList_->kP_List_len_=kPList_->kP_List_len_ + 1;
// return true;
// }
// else
// return false;
// }
//
//inline int& kPrimeListSize(){return kPList_->kP_List_len_;}
//inline kPrimeList* getKPrimeList(){return kPList_;}
inline bool addKPrime_New(nsaddr_t id)
{
if(kPList_New_->kP_List_New_len_<MAX_SR_LEN)
{
kPList_New_->kP_List_New_[kPList_New_->kP_List_New_len_]=id;
kPList_New_->kP_List_New_len_=kPList_New_->kP_List_New_len_ + 1;
return true;
}
else
return false;
}
inline int& kPrimeListSize_New(){return kPList_New_->kP_List_New_len_;}
inline kPrimeList_New* getKPrimeList_New(){return kPList_New_;}
//ACU281 Code Section End
};
#endif // sr_hdr_h