Newer
Older
def hcbf(self, packet, state):
if len(self.community) == 0:
return False
c_of = lambda n: community[n]
same_community = lambda a, b: c_of(a) == c_of(b)
cbc_of = lambda n, d: community.get_cbc(c_of(n), c_of(d))
lp_of = lambda n: community.get_lp(n)
ncf_of = lambda n, d: community.get_ncf(n, c_of(d))
ui_of = lambda n: community.get_ui(n)
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
return False
dest = packet.destination
max_cbc = (cbc_of(self, dest), self)
max_lp = (-1, None)
max_ncf= (ncf_of(self, dest), self)
max_ui = (-1, None)
my_lp = lp_of(self)
my_ui = ui_of(self)
for met in self.links:
if met == dest:
# direct transfer
self.send(met, packet)
return True
if same_community(met, dest):
met_ui = ui_of(met)
met_lp = lp_of(met)
if met_ui > my_ui:
max_ui = max((met_ui, met), max_ui)
max_lp = max((met_lp, met), max_lp)
elif same_community(met, self):
met_cbc = cbc_of(met, dest)
max_cbc = max((met_cbc, met), max_cbc)
else:
met_ncf = ncf_of(met, dest)
max_ncf = max((met_ncf, met), max_ncf)
if max_ui[1] is not None and same_community(max_ui[1], dest):
self.send(max_ui[1], packet)
return True
if max_lp[1] is not None and same_community(max_lp[1], dest):
self.send(max_lp[1], packet)
return True
if max_cbc[1] is not self:
self.send(max_cbc[1], packet)
return True
if max_ncf[1] is not self:
self.send(max_ncf[1], packet)
return True
if max_ui[1] is not None and max_ui[0] > my_ui:
self.send(max_ncf[1], packet)
self.send(max_ui[1], packet)
return True
if max_lp[1] is not None and max_lp[0] > my_lp:
self.send(max_lp[1], packet)
return True
return False