-
Notifications
You must be signed in to change notification settings - Fork 82
/
madwifirate.hh
135 lines (101 loc) · 2.59 KB
/
madwifirate.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
#ifndef CLICK_MADWIFIRATE_HH
#define CLICK_MADWIFIRATE_HH
#include <click/element.hh>
#include <click/etheraddress.hh>
#include <click/bighashmap.hh>
#include <click/glue.hh>
#include <click/timer.hh>
#include <elements/wifi/availablerates.hh>
CLICK_DECLS
/*
=c
MadwifiRate([I<KEYWORDS>])
=s Wifi
Madwifi wireless bit-rate selection algorithm
=d
Rate Control present in the Madwifi driver
(http://sourceforge.net/project/madwifi).
=a
SetTXRate, FilterTX, AutoRateFallback
*/
class MadwifiRate : public Element { public:
MadwifiRate() CLICK_COLD;
~MadwifiRate() CLICK_COLD;
const char *class_name() const override { return "MadwifiRate"; }
const char *port_count() const override { return "2/0-2"; }
const char *processing() const override { return "ah/a"; }
const char *flow_code() const override { return "#/#"; }
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
bool can_live_reconfigure() const { return true; }
int initialize(ErrorHandler *) CLICK_COLD;
void run_timer(Timer *);
void adjust_all();
void adjust(EtherAddress);
void push (int, Packet *);
Packet *pull(int);
void add_handlers() CLICK_COLD;
static String static_print_stats(Element *e, void *);
String print_rates();
EtherAddress _bcast;
void assign_rate(Packet *);
void process_feedback(Packet *);
int _stepup;
int _stepdown;
bool _debug;
unsigned _offset;
Timer _timer;
unsigned _packet_size_threshold;
struct DstInfo {
public:
EtherAddress _eth;
Vector<int> _rates;
int _credits;
int _current_index;
int _successes;
int _failures;
int _retries;
DstInfo() {
}
DstInfo(EtherAddress eth) {
_eth = eth;
}
int rate_index(int rate) {
int ndx = 0;
for (int x = 0; x < _rates.size(); x++) {
if (rate == _rates[x]) {
ndx = x;
break;
}
}
return (ndx == _rates.size()) ? -1 : ndx;
}
int pick_rate() {
if (_rates.size() == 0) {
click_chatter("no rates to pick from for %s\n",
_eth.unparse().c_str());
return 2;
}
if (_current_index > 0 && _current_index < _rates.size()) {
return _rates[_current_index];
}
return _rates[0];
}
int pick_alt_rate() {
if (_rates.size() == 0) {
click_chatter("no rates to pick from for %s\n",
_eth.unparse().c_str());
return 2;
}
return _rates[0];
}
};
typedef HashMap<EtherAddress, DstInfo> NeighborTable;
typedef NeighborTable::const_iterator NIter;
NeighborTable _neighbors;
AvailableRates *_rtable;
bool _alt_rate;
bool _active;
int _period;
};
CLICK_ENDDECLS
#endif