-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunchrouter.hh~
189 lines (128 loc) · 4.64 KB
/
launchrouter.hh~
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
#ifndef Launch_Router_HH
#define Launch_Router_HH
#include <click/element.hh>
#include <click/glue.hh>
#include <click/ipaddress.hh>
#include <click/etheraddress.hh>
#include <clicknet/ether.h>
#include <elements/local/launch.hh>
#include <elements/local/launchrequester.hh>
#include <elements/local/launchlockrequester.hh>
#include <click/confparse.hh>
#include <click/timer.hh>
#include <click/hashmap.hh>
CLICK_DECLS
class LaunchRouter : public Element { public:
LaunchRouter();
~LaunchRouter();
const char *class_name() const { return "LaunchRouter"; }
const char *port_count() const { return PORTS_1_1; }
const char *processing() const { return AGNOSTIC; }
int configure(Vector<String> &, ErrorHandler *);
int initialize(ErrorHandler *);
Packet *simple_action(Packet *);
void insert_route( const IPAddress &nip,uint32_t nlat, uint32_t nlong,uint8_t * ne,uint8_t chl, uint32_t pub, uint32_t swt);
void update_route(const IPAddress &nip, uint8_t chl);
void set_channel_loc_positive();
private:
WritablePacket * _holded_packet;
IPAddress _dst_ip;
IPAddress _ip;
EtherAddress _ether_address_eth;
uint8_t _eth [6];
//uint32_t _pu_behavior;
double _pu_behavior;
bool _channel_lock_positive;
bool _routingtable_available;
bool _ready_for_another_packet;
uint32_t my_lat; // this node's Latitude.
uint32_t my_long; // this node's Longitude.
/* destination node's addresses */
IPAddress dst_ip;
EtherAddress dst_eth;
uint32_t dst_lat; // this node's Latitude.
uint32_t dst_long; // this node's Longitude.
/* timers
1. _respone_waiting_timer for waiting on responses to reach this node from its nieghbors
2. _lock_waiting_timer for waiting on channel lock to reach this node from the node it chose as the next hop
3. _routing_table_entry_timer for making route table expire */
Timer _respone_waiting_timer;
Timer _lock_waiting_timer;
Timer _routing_table_entry_timer;
uint32_t _repsonse_waiting_ms;
uint32_t _lock_waiting_ms;
uint32_t _routing_table_entry_ms;
static void static_use_responses(Timer *, void *e) { ((LaunchRouter *) e)->use_responses(); }
void use_responses();
static void static_use_lock(Timer *, void *e) { ((LaunchRouter *) e)->use_lock(); }
void use_lock();
static void static_make_routetable_expire(Timer *, void *e) { ((LaunchRouter *) e)->make_routetable_expire(); }
void make_routetable_expire();
LaunchCtrlRequester *_requester;
LaunchLockRequester * _lock_requester;
//Metric Calculation Function
double distance(double lat1, double lon1, double lat2, double lon2, char unit);
double deg2rad(double deg);
double rad2deg(double deg);
//Routing Table Entry
class RouteEntry {
public:
class IPAddress neighbor_ip; // IP address of this destination
uint32_t neighbor_lat; // Sender's Latitude.
uint32_t neighbor_long; // Sender's Longitude.
uint8_t * neighbor_eth; // hardware address of next hop
uint8_t channel;
uint32_t pu_behavior;
uint32_t switching_time;
RouteEntry(const IPAddress &nip,
uint32_t nlat, uint32_t nlong,
uint8_t * ne, uint8_t chl,
uint32_t pub, uint32_t swt) :
neighbor_ip(nip), neighbor_lat(nlat), neighbor_long(nlong),
neighbor_eth(ne), channel(chl), switching_time(swt)
{}
RouteEntry() {}
~RouteEntry() {}
};
class LocationEntry {
public:
class IPAddress neighbor_ip; // IP address of this destination
uint32_t neighbor_lat; // Sender's Latitude.
uint32_t neighbor_long; // Sender's Longitude.
class EtherAddress neighbor_eth; // hardware address of next hop
LocationEntry(const IPAddress &nip,
uint32_t nlat, uint32_t nlong) :
neighbor_ip(nip), neighbor_lat(nlat), neighbor_long(nlong)
{}
LocationEntry() {}
~LocationEntry() {}
};
typedef HashMap<IPAddress, RouteEntry> RTable;
typedef RTable::const_iterator RTIter;
typedef HashMap<IPAddress, LocationEntry> LocationTable;
typedef LocationTable::const_iterator LTIter;
RTable _rtes;
LocationTable _ltable;
double calculate_metric(RouteEntry r, LocationEntry l);
RouteEntry * choose_bestneighbor(IPAddress _current_dst_addr,HashMap<IPAddress, RouteEntry> _rtes)
{
if(_rtes.findp(_current_dst_addr) != 0)
return _rtes.findp(_current_dst_addr);
double last_metric = 10000;
uint8_t best_ip ;
double current_metric;
for (RTIter iter = _rtes.begin(); iter.live(); iter++) {
RouteEntry rte = iter.value();
LocationEntry lentry = _ltable.find(rte.neighbor_ip);
current_metric = calculate_metric(rte, lentry);
if(current_metric < last_metric)
{
last_metric = current_metric;
best_ip = rte.neighbor_ip;
}
}
return _rtes.findp(best_ip);
};
};
CLICK_ENDDECLS
#endif