-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathns-agent.h
203 lines (167 loc) · 4.4 KB
/
ns-agent.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
/* Copyright (C) Uppsala University
*
* This file is distributed under the terms of the GNU general Public
* License (GPL), see the file LICENSE
*
* Author: Erik Nordström, <[email protected]>
*/
#ifndef _DSR_NS_AGENT
#define _DSR_NS_AGENT
#ifndef NS2
#error "To compile the ns-2 version of DSR-UU, NS2 must be defined!"
#endif /* NS2 */
class DSRUU;
#include <stdarg.h>
#include <object.h>
#include <agent.h>
#include <trace.h>
#include <scheduler.h>
#include <packet.h>
#include <dsr-priqueue.h>
#include <mac.h>
#include <mac-802_11.h>
#include <mobilenode.h>
#define ETH_ALEN 6
#define NSCLASS DSRUU::
#define ConfVal(name) DSRUU::get_confval(name)
#define ConfValToUsecs(cv) DSRUU::confval_to_usecs(cv)
#include "tbl.h"
#include "endian.h"
#include "timer.h"
#define NO_DECLS
#include "debug.h"
#include "dsr.h"
#include "dsr-opt.h"
#include "send-buf.h"
#include "dsr-rreq.h"
#include "dsr-pkt.h"
#include "dsr-rrep.h"
#include "dsr-rerr.h"
#include "dsr-ack.h"
#include "dsr-srt.h"
#include "neigh.h"
#include "link-cache.h"
#undef NO_DECLS
typedef dsr_opt_hdr hdr_dsr;
#define HDR_DSRUU(p) ((hdr_dsr *)hdr_dsr::access(p))
#define init_timer(timer)
#define timer_pending(timer) ((timer)->status() == TIMER_PENDING)
#define del_timer_sync(timer) del_timer(timer)
#define MALLOC(s, p) malloc(s)
#define FREE(p) free(p)
#define XMIT(pkt) ns_xmit(pkt)
#define DELIVER(pkt) ns_deliver(pkt)
#define __init
#define __exit
#define ntohl(x) x
#define htonl(x) x
#define htons(x) x
#define ntohs(x) x
#define IPDEFTTL 64
class DSRUU:public Tap, public Agent {
public:
friend class DSRUUTimer;
DSRUU();
~DSRUU();
DSRUUTimer ack_timer;
int command(int argc, const char *const *argv);
void recv(Packet *, Handler * callback = 0);
void tap(const Packet * p);
Packet *ns_packet_create(struct dsr_pkt *dp);
void ns_xmit(struct dsr_pkt *dp);
void ns_deliver(struct dsr_pkt *dp);
void xmit_failed(Packet *p);
struct hdr_ip *dsr_build_ip(struct dsr_pkt *dp, struct in_addr src,
struct in_addr dst, int ip_len,
int tot_len, int protocol, int ttl);
void add_timer(DSRUUTimer * t) {
/* printf("Setting timer %s to %f\n", t->get_name(), t->expires - Scheduler::instance().clock()); */
if (t->expires - Scheduler::instance().clock() < 0)
t->resched(0);
else
t->resched(t->expires - Scheduler::instance().clock());
}
/* void mod_timer (DSRUUTimer *t, unsinged long expires_) *//* { t->expires = expires_ ; t->resched(t->expires); } */
void del_timer(DSRUUTimer * t) {
//printf("Cancelling timer %s\n", t->get_name());
t->cancel();
}
void set_timer(DSRUUTimer * t, struct timeval *expires) {
//printf("In set_timer\n");
t->expires = expires->tv_usec;
t->expires /= 1000000l;
t->expires += expires->tv_sec;
/* printf("Set timer %s to %f\n", t->get_name(), t->expires - Scheduler::instance().clock()); */
add_timer(t);
}
static const unsigned int get_confval(enum confval cv) {
return confvals[cv];
}
static const unsigned int set_confval(enum confval cv, unsigned int val) {
confvals[cv] = val;
return val;
}
#define NO_GLOBALS
#undef NO_DECLS
#undef _DSR_H
#include "dsr.h"
#undef _DSR_OPT_H
#include "dsr-opt.h"
#undef _DSR_IO_H
#include "dsr-io.h"
#undef _DSR_RREQ_H
#include "dsr-rreq.h"
#undef _DSR_RREP_H
#include "dsr-rrep.h"
#undef _DSR_RERR_H
#include "dsr-rerr.h"
#undef _DSR_ACK_H
#include "dsr-ack.h"
#undef _DSR_SRT_H
#include "dsr-srt.h"
#undef _SEND_BUF_H
#include "send-buf.h"
#undef _NEIGH_H
#include "neigh.h"
#undef _MAINT_BUF_H
#include "maint-buf.h"
#undef _LINK_CACHE_H
#include "link-cache.h"
#undef _DEBUG_H
#include "debug.h"
#undef NO_GLOBALS
struct in_addr my_addr() {
return myaddr_;
}
int arpset(struct in_addr addr, unsigned int mac_addr);
inline void ethtoint(char *eth, int *num) {
memcpy((char *)num, eth, ETH_ALEN);
return;
}
inline void inttoeth(int *num, char *eth) {
memcpy(eth, (char *)num, ETH_ALEN);
return;
}
private:
static int confvals[CONFVAL_MAX];
struct in_addr myaddr_;
unsigned long macaddr_;
Trace *trace_;
Mac *mac_;
LL *ll_;
CMUPriQueue *ifq_;
MobileNode *node_;
struct tbl rreq_tbl;
struct tbl grat_rrep_tbl;
struct tbl send_buf;
struct tbl neigh_tbl;
struct tbl maint_buf;
unsigned int rreq_seqno;
DSRUUTimer grat_rrep_tbl_timer;
DSRUUTimer send_buf_timer;
DSRUUTimer neigh_tbl_timer;
DSRUUTimer lc_timer;
/* The link cache */
struct lc_graph LC;
};
#endif /* _DSR_NS_AGENT_H */