-
Notifications
You must be signed in to change notification settings - Fork 82
/
pep.hh
117 lines (102 loc) · 3.44 KB
/
pep.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
#ifndef pep_hh
#define pep_hh
/*
* =c
* PEP(IP, [FIXED, LATITUDE, LONGITUDE])
* =s Grid
* runs the Grid Position Estimation Protocol
* =d
* Run the Grid Position Estimation Protocol. Subtypes GridLocationInfo,
* and can be used in its place.
*
* Produces packets with just the PEP payload. The Grid configuration
* must arrange to encapsulate them appropriately. I expect this
* means UDP/IP/Ether. Expects packets with just PEP payload.
*
* The status handler prints out node id, estimated position,
* and the table of nearby nodes with known locations.
*
* A node that knows its location originates a PEP "fix" every
* second. Each fix update has a new sequence number.
*
* All nodes remember all the fixes they've heard about in the
* last 100 seconds, along with the number of hops to the fix.
*
* A node accepts a new update if the sequence number is
* higher than remembered, or if seq is equal and hop count
* is less. The node remembers the time-stamp of the last
* time it accepted each fix.
*
* Every second, a node broadcasts the nearest fixes it knows about.
* Only fixes heard about in the last 5 seconds are broadcast.
* Also only fixes with hop count < 10.
*
* There's a problem that an update with a new sequence number
* may move quickly along a long path, and supersede an older
* slower update that moved along the minimum length path.
*
* Here's how the PEP protocol handles some interesting cases:
*
* Crash: after about five seconds, nearby nodes will stop propagating
* a crashed fix's updates. But they remember the fix for 100 seconds,
* so won't accept looped updates with high hop counts. The 100
* seconds has to be longer than 5 seconds plus the maximum
* allowed hop count; otherwise updates may loop forever.
*
* Re-start: a fix node is only allowed to re-start if it has stayed
* down for >= 100 seconds, long enough for nodes to flush their entries.
*
* Move closer: if a fix moves closer to you, you'll see (and
* believe) smaller hop counts.
*
* Move farther: if a fix moves farther from you, you'll see
* higher hop counts but you'll believe them because the sequence
* number is larger.
*/
#include <click/element.hh>
#include <click/timer.hh>
#include <click/ipaddress.hh>
#include "pep_proto.hh"
#include "grid.hh"
#include "elements/grid/gridlocationinfo.hh"
CLICK_DECLS
class PEP : public GridLocationInfo {
public:
PEP() CLICK_COLD;
~PEP() CLICK_COLD;
const char *class_name() const override { return "PEP"; }
const char *port_count() const override { return PORTS_1_1; }
const char *processing() const override { return PUSH; }
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
int initialize(ErrorHandler *) CLICK_COLD;
virtual void *cast(const char *);
void run_timer(Timer *);
void add_handlers() CLICK_COLD;
Packet *simple_action(Packet *p);
grid_location get_current_location(void);
String s();
bool _debug;
private:
IPAddress _my_ip;
Timer _timer;
bool _fixed; // We have a static, known location in _lat / _lon.
float _lat;
float _lon;
int _seq;
struct Entry {
Timestamp _when; // When we last updated this entry.
pep_fix _fix;
};
Vector<Entry> _entries;
int findEntry(unsigned id, bool allocate);
void purge_old();
void sort_entries();
bool sendable(Entry);
void externalize(pep_fix *);
void internalize(pep_fix *);
Packet *make_PEP();
grid_location algorithm1();
grid_location algorithm2();
};
CLICK_ENDDECLS
#endif