-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunchctrlresponder.cc
83 lines (67 loc) · 1.84 KB
/
launchctrlresponder.cc
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
#include <click/config.h>
#include <elements/local/launch.hh>
#include <elements/local/launchctrlresponder.hh>
#include <click/args.hh>
#include <clicknet/ether.h>
#include <click/error.hh>
#include <click/glue.hh>
#include <click/confparse.hh>
CLICK_DECLS
LaunchCtrlResponder::LaunchCtrlResponder()
{
}
LaunchCtrlResponder::~LaunchCtrlResponder()
{
}
int
LaunchCtrlResponder::configure(Vector<String> &conf, ErrorHandler * errh)
{
if (Args(conf, this, errh)
.read_mp("ETH", _my_eth)
.read_mp("IP", lch.neighbor_ip)
.read_mp("LONG", lch.my_long)
.read_mp("LAT", lch.my_lat)
.read_mp("TSWTCH", lch.switching_time)
.read_mp("CH0", _pu_behavior0)
.read_mp("CH1", _pu_behavior1)
.read_mp("CH2", _pu_behavior2)
.complete() < 0)
return -1;
lch.type = launch_ctrl_hdr::LAUNCH_RES;
//A node responds with the best channel from three candidates
//in terms of PU behaviour(1/(probability of the presence of PU))
if (_pu_behavior0 >= _pu_behavior1 && _pu_behavior0 >= _pu_behavior2)
{
lch.channel=1;
lch.pu_behavior = _pu_behavior0;
}
else if (_pu_behavior1 >= _pu_behavior0 && _pu_behavior1 >= _pu_behavior2)
{
lch.channel=6;
lch.pu_behavior = _pu_behavior1;
}
else if (_pu_behavior2 >= _pu_behavior0 && _pu_behavior2 >= _pu_behavior1)
{
lch.channel=11;
lch.pu_behavior = _pu_behavior2;
}
return 0;
}
Packet *
LaunchCtrlResponder::simple_action(Packet *p_in)
{
//int extra = sizeof(lch);
//WritablePacket *p = p_in->push(extra);
WritablePacket *p = p_in->uniqueify();
if (!p)
return 0;
click_ether *ethh = p->ether_header();
uint8_t source_address[6];
memcpy(source_address, ethh->ether_shost, 6);
memcpy(ethh->ether_dhost, source_address, 6);
memcpy(ethh->ether_shost, _my_eth.data(), 6);
memcpy(p->data()+14, &lch, sizeof(lch));
return p;
}
CLICK_ENDDECLS
EXPORT_ELEMENT(LaunchCtrlResponder)