Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5006c1d6af | ||
|
|
a599d2aac9 | ||
|
|
b98aa3aca6 | ||
|
|
727b61087a | ||
|
|
80111b72f9 | ||
|
|
07da3fec95 | ||
|
|
5e02c04ca7 | ||
|
|
c414ca5895 | ||
|
|
f28a061c22 | ||
|
|
af3ff5a8c6 | ||
|
|
2c61bad944 | ||
|
|
4d030c3896 | ||
|
|
13dae355cb | ||
|
|
8f0028de4e | ||
|
|
412c982a63 | ||
|
|
a103334b1c | ||
|
|
0498ce85b0 | ||
|
|
7647cc7635 | ||
|
|
e08cc4cd7e | ||
|
|
67ad70fbd5 | ||
|
|
d69070ef50 | ||
|
|
d412393379 | ||
|
|
6a699be8cd | ||
|
|
a47cca2634 | ||
|
|
7249fb4d52 | ||
|
|
86644d36ff | ||
|
|
358414d82f | ||
|
|
22085365d2 | ||
|
|
432be57380 | ||
|
|
3db9807200 | ||
|
|
03a75f6c88 | ||
|
|
7922d12449 | ||
|
|
580915891e | ||
|
|
29abf4cda2 | ||
|
|
a6286a9e5a | ||
|
|
40604e3a1f | ||
|
|
4400e428d4 | ||
|
|
05590471e0 | ||
|
|
b21bed88ed | ||
|
|
264af77369 | ||
|
|
6aecc500e5 | ||
|
|
7fb9071230 | ||
|
|
9ab43e67db | ||
|
|
cabd980030 | ||
|
|
2135375d36 | ||
|
|
3dc9fd0b82 | ||
|
|
c0c089314b | ||
|
|
9f6a7d97bc | ||
|
|
0bba81df36 | ||
|
|
2377ada11a | ||
|
|
b7e72c3a0a | ||
|
|
c1d4837b6f | ||
|
|
bc0e617e48 | ||
|
|
5bafd2c7c4 | ||
|
|
13d582abec | ||
|
|
d82134b850 | ||
|
|
ebc20f6000 | ||
|
|
fdc0645d77 | ||
|
|
e1cf4ba46a | ||
|
|
6bead9b6de | ||
|
|
f3bc3ae906 | ||
|
|
a158370ecb | ||
|
|
34b2b57831 | ||
|
|
1f237abbf1 | ||
|
|
3a2339a1b4 | ||
|
|
1752159ae0 | ||
|
|
4995bf960d | ||
|
|
c68b2e8a46 | ||
|
|
c29eb7f50e | ||
|
|
9d283adac4 | ||
|
|
b93fb6c831 | ||
|
|
8f290fc884 | ||
|
|
cb27d91658 | ||
|
|
9cec699867 | ||
|
|
d656aff913 | ||
|
|
22974904d3 | ||
|
|
69857c37c2 | ||
|
|
feeb918ea8 | ||
|
|
13ff259ec8 | ||
|
|
cb6551e96f | ||
|
|
56c68a364a | ||
|
|
51cf75c8f0 | ||
|
|
854866f424 | ||
|
|
32f7eac7cd | ||
|
|
5ab4cf83d9 | ||
|
|
f3ee808927 | ||
|
|
97f26a2618 | ||
|
|
e89118e8be | ||
|
|
fb034219ef | ||
|
|
cf9e1c7789 | ||
|
|
5a897699cf | ||
|
|
18c2b29e41 | ||
|
|
f7d2050f70 | ||
|
|
8e53127d0a | ||
|
|
2feb4596a9 | ||
|
|
6598fb0881 | ||
|
|
a499aa230f | ||
|
|
4bd4f71f60 | ||
|
|
a4abfb010f | ||
|
|
380668b6e2 | ||
|
|
606d5ddc9e | ||
|
|
24be073413 | ||
|
|
759db61b84 | ||
|
|
6c8c2a0b9c | ||
|
|
c88d2d4a61 | ||
|
|
cf1d0c0286 | ||
|
|
f689c7944b | ||
|
|
a6f637a166 | ||
|
|
df1dc6590c | ||
|
|
55d83d449d | ||
|
|
d8315bf75b | ||
|
|
7890a9f26d | ||
|
|
eb7b7abbee | ||
|
|
1402fa153d | ||
|
|
6be9387a4f | ||
|
|
9aafc2a086 | ||
|
|
57113d1369 | ||
|
|
07f2e2f516 | ||
|
|
f190cfa470 | ||
|
|
5153338a18 | ||
|
|
cb425e83e4 | ||
|
|
d214881326 | ||
|
|
5e4a02fe9e | ||
|
|
859a69e349 | ||
|
|
115ea63ecf | ||
|
|
17a7001ae9 | ||
|
|
9d491024ac | ||
|
|
13839ac94a | ||
|
|
602c3aaa56 | ||
|
|
47c343b9f2 | ||
|
|
73b4980eb6 | ||
|
|
25d9728d2f | ||
|
|
9d727857dc | ||
|
|
5f59607a8a | ||
|
|
b3a23ca711 | ||
|
|
075bb7dac4 | ||
|
|
14b391842b | ||
|
|
65c494acf0 | ||
|
|
a6bd7da559 | ||
|
|
b31206e87e | ||
|
|
2cae8cacf0 | ||
|
|
2840dbc868 | ||
|
|
0dc3cb1788 | ||
|
|
9222f3665b | ||
|
|
08b91c8d4e | ||
|
|
a6dec22caa | ||
|
|
03f45d2bb6 | ||
|
|
a809858c53 | ||
|
|
284bd626fd | ||
|
|
16916ae20a | ||
|
|
a681a24c22 | ||
|
|
14e71f0fe8 | ||
|
|
c6a65ad55e | ||
|
|
17c172ba6b | ||
|
|
cf7db2fd83 | ||
|
|
b7703adb88 | ||
|
|
1d12d2fe4e | ||
|
|
3626b59818 | ||
|
|
fa2aa50d8d | ||
|
|
0a71dd3a00 | ||
|
|
3dade00499 | ||
|
|
2d83a86255 | ||
|
|
c707948105 | ||
|
|
78ddcabcd0 | ||
|
|
8a05c7fd2a | ||
|
|
1b077f6028 | ||
|
|
50a6af341d | ||
|
|
77d0bfdaf0 | ||
|
|
2bdf60c4e8 | ||
|
|
6ecc3f8141 | ||
|
|
d3ae85dbad | ||
|
|
97e33024f2 | ||
|
|
19779d861e | ||
|
|
99a7ce1363 | ||
|
|
b8bd5ee965 | ||
|
|
77cddbc978 | ||
|
|
c38219e208 | ||
|
|
48b4587eee | ||
|
|
3ad49db6ea | ||
|
|
feddc3c054 | ||
|
|
9120cee21d | ||
|
|
97ab201be7 | ||
|
|
39465c218d | ||
|
|
00e32fede9 | ||
|
|
f392b8ff44 | ||
|
|
90290c5664 | ||
|
|
2849fd45f0 | ||
|
|
e271260c49 | ||
|
|
edb69c4375 | ||
|
|
dfbeda2f10 | ||
|
|
fbdd5cec13 | ||
|
|
8b663a9528 | ||
|
|
d29a5dab89 | ||
|
|
16cbadb47a | ||
|
|
774071c8d5 | ||
|
|
d27841b7d5 | ||
|
|
bc59dd0075 | ||
|
|
096f86a311 | ||
|
|
9be9980011 | ||
|
|
eef49a922e | ||
|
|
28181320e8 | ||
|
|
a4e6ec3155 | ||
|
|
5e1124ccac | ||
|
|
7570e778e4 | ||
|
|
6eb1ac9b49 | ||
|
|
f48d0809f0 | ||
|
|
e1bdc08302 | ||
|
|
407d569821 | ||
|
|
3c0c035609 | ||
|
|
5ba7dfc10f | ||
|
|
a46d41df0e | ||
|
|
922330b1e0 | ||
|
|
bce3cb528b | ||
|
|
7015694293 | ||
|
|
69692abf50 | ||
|
|
32e7609edf | ||
|
|
d47cd63b1b | ||
|
|
f59e58f202 | ||
|
|
5200904303 | ||
|
|
dda258af14 | ||
|
|
3e7fc83c12 | ||
|
|
f84bac5a7a | ||
|
|
f4cfed1a61 | ||
|
|
9f8b10e350 | ||
|
|
04d5ce685d | ||
|
|
952d6fd3d7 | ||
|
|
b53fe6444b | ||
|
|
a4d7fe0f22 | ||
|
|
457f135980 | ||
|
|
d657d53eea | ||
|
|
359135cfb2 | ||
|
|
4f8dd96fbf | ||
|
|
812d615717 | ||
|
|
e4b2238b33 | ||
|
|
1705744468 | ||
|
|
c0822fa4a5 | ||
|
|
7b8e797c32 | ||
|
|
9c33b90fd3 | ||
|
|
5f35f64d9a | ||
|
|
a3148081ce | ||
|
|
782a1d1621 | ||
|
|
67f797f9a3 | ||
|
|
21e0193e5c | ||
|
|
e34a2825f1 | ||
|
|
45898d2215 | ||
|
|
bd72431945 | ||
|
|
87fc0f8d6f | ||
|
|
981db808cb | ||
|
|
1cb619e63b | ||
|
|
ded17426c6 | ||
|
|
e4d745d41f | ||
|
|
43bb2315ea | ||
|
|
3bdc1decf6 | ||
|
|
30c37ab9bf | ||
|
|
c14a8acf39 | ||
|
|
971d9621ce | ||
|
|
3406dc9742 | ||
|
|
85a36632a7 | ||
|
|
7a36ac7d9d | ||
|
|
057d149fda | ||
|
|
7003e0bc66 | ||
|
|
3cf75dc10b | ||
|
|
068a71d6f0 | ||
|
|
0064c1dd91 | ||
|
|
cdf7845986 | ||
|
|
8dc473a724 | ||
|
|
6f09ab6cde | ||
|
|
cfb1a315ed | ||
|
|
63086448bf | ||
|
|
47456e7d98 | ||
|
|
b922c8891c | ||
|
|
9e5b8af1f5 | ||
|
|
6a88b5f435 | ||
|
|
d9c520bed9 | ||
|
|
d214744ab8 | ||
|
|
2a58815ee3 | ||
|
|
3f94ec31f3 | ||
|
|
e0bae0f64b | ||
|
|
fdcbb4d0ef | ||
|
|
acd00876f9 | ||
|
|
d7b44c817d | ||
|
|
4d82692800 | ||
|
|
56a741f29a | ||
|
|
17d1849dec | ||
|
|
003357899d | ||
|
|
de33245d9f | ||
|
|
26667e16df | ||
|
|
d5e89e8c7d | ||
|
|
c9b5e018ed | ||
|
|
02a0e0fbe3 | ||
|
|
92e4ea53ba | ||
|
|
494a955b56 | ||
|
|
332783b3e5 | ||
|
|
d96744d968 | ||
|
|
85244373f9 | ||
|
|
75306351ff | ||
|
|
3d2049fbc1 | ||
|
|
0c3e57b399 | ||
|
|
15b5505e01 | ||
|
|
97a010178c | ||
|
|
5cc706c8cb | ||
|
|
0e13e1e2e2 | ||
|
|
0c84164fd0 | ||
|
|
a6f2d245d7 | ||
|
|
8ce09032ff | ||
|
|
b49313db62 | ||
|
|
167040a677 | ||
|
|
3160a3f820 | ||
|
|
3257af2823 | ||
|
|
f2bfb44a4a | ||
|
|
8215a3ada6 | ||
|
|
4738f15594 | ||
|
|
00d39fda3c | ||
|
|
78ef901f24 | ||
|
|
3f9234b2cf | ||
|
|
0c63c63ed7 | ||
|
|
69b63dcdd4 | ||
|
|
41aba10d3d | ||
|
|
4253885f23 | ||
|
|
59769b1864 | ||
|
|
52ae3296bd | ||
|
|
bb734df9f6 | ||
|
|
bc79bd63c7 | ||
|
|
6daf2a39f5 | ||
|
|
22fba35327 | ||
|
|
84dd4ca348 | ||
|
|
b8d1fc7562 | ||
|
|
6d1c1c320b | ||
|
|
4b89a6e943 | ||
|
|
afb2059377 | ||
|
|
4e837f8d12 | ||
|
|
b5eee2066b | ||
|
|
0804f5dd1f | ||
|
|
847de408cb | ||
|
|
b5220706c6 | ||
|
|
38fb251c44 | ||
|
|
60b7d51063 | ||
|
|
085b9e3a6f | ||
|
|
cfe81d5098 | ||
|
|
042a331582 | ||
|
|
ac238f29be | ||
|
|
f940ae70f2 | ||
|
|
f54d0301c6 | ||
|
|
88043fcbe8 | ||
|
|
06a1eab063 | ||
|
|
a907980840 | ||
|
|
c25737cd9a | ||
|
|
84d3adcd6c | ||
|
|
a997d29622 | ||
|
|
c8f17e51ed | ||
|
|
c0a5a39a4f | ||
|
|
01bbd09ed8 | ||
|
|
15902efdef | ||
|
|
00a3c9dc86 | ||
|
|
8ca138de13 | ||
|
|
a5765d647b | ||
|
|
2642cd250b | ||
|
|
b15276f90e | ||
|
|
6126547e53 | ||
|
|
b8eebcb4aa | ||
|
|
79a92089e7 | ||
|
|
27b3854eb7 | ||
|
|
bbace1de47 | ||
|
|
4e1b6eee32 | ||
|
|
849e12a068 | ||
|
|
90015991bc | ||
|
|
bb6146ef74 | ||
|
|
6028619f71 | ||
|
|
fc2e13d58d | ||
|
|
944f38bb49 | ||
|
|
b347b7f189 | ||
|
|
6837d4f732 | ||
|
|
0ba6d64e5a | ||
|
|
2d49175d6e | ||
|
|
84d62cbbc6 | ||
|
|
7b0071e6a9 | ||
|
|
a5a3a87ae0 | ||
|
|
cb76686ecc | ||
|
|
0d82d0459c | ||
|
|
2760adcb80 | ||
|
|
f748a4e9e2 | ||
|
|
84c65c0546 | ||
|
|
9ac95d3c1c | ||
|
|
68ab43d8b7 | ||
|
|
0b0a71d801 | ||
|
|
1816d4b190 | ||
|
|
3b0815486e | ||
|
|
dbb6b3e119 | ||
|
|
8a1f170ea6 | ||
|
|
83be1dae4b | ||
|
|
08e96316be | ||
|
|
8eb5f8f3ed | ||
|
|
46afec48ec | ||
|
|
43ff2a9254 | ||
|
|
7744a4a298 | ||
|
|
f32ca897c5 | ||
|
|
221f53bb6f | ||
|
|
9f3973e7b7 | ||
|
|
7d8695d9e7 | ||
|
|
3f21e58a58 | ||
|
|
6eb0271fae | ||
|
|
33a24e8e8f | ||
|
|
16a3adfafc | ||
|
|
f4056d0242 | ||
|
|
9ae8857bce | ||
|
|
a94f3676c3 | ||
|
|
fe0580cb55 | ||
|
|
6f6ef012cb | ||
|
|
5c1bb36ae9 | ||
|
|
8d61c037a7 | ||
|
|
1cce2a3014 | ||
|
|
73bcad33b9 | ||
|
|
22db53973d | ||
|
|
38c7d9e6d7 | ||
|
|
8eda682a18 | ||
|
|
a3c9ddb21c | ||
|
|
acca18ae12 | ||
|
|
77911ccc73 | ||
|
|
c19408ddf2 | ||
|
|
e5eebad6d2 | ||
|
|
8fd15e628a | ||
|
|
b283f52c78 | ||
|
|
f03d4796d7 | ||
|
|
6fc57a69fa | ||
|
|
5d3e481956 | ||
|
|
f995f382ec | ||
|
|
cad76b6242 | ||
|
|
0d97692b40 | ||
|
|
78e32b0ee2 | ||
|
|
6bd6d0b50a | ||
|
|
bfea575095 | ||
|
|
fe4fce3a3f | ||
|
|
185ab29325 | ||
|
|
21f22e692f | ||
|
|
da89fa5a9f | ||
|
|
d2ea2350ad | ||
|
|
4f5cdcf421 | ||
|
|
d396b61ba1 | ||
|
|
1586aff97b | ||
|
|
9fcf123b19 | ||
|
|
635bf20ef5 | ||
|
|
f6af4f8913 | ||
|
|
1d62e62bc0 | ||
|
|
89c0ea0621 | ||
|
|
2fb3e8e3fe | ||
|
|
63b67e2b23 | ||
|
|
1a25a6edd0 | ||
|
|
2fe3af0577 | ||
|
|
ecdbe5f2a6 | ||
|
|
f7bf4093be | ||
|
|
084b79553f | ||
|
|
e38e261ae6 | ||
|
|
918e5d451e | ||
|
|
7a294d49ab | ||
|
|
d695801754 | ||
|
|
26cbdbd904 | ||
|
|
6fd1e7e5ef | ||
|
|
36e5429622 | ||
|
|
58ba3f9429 | ||
|
|
970f648843 | ||
|
|
8f803f292e | ||
|
|
05dd4441b0 | ||
|
|
1fbdb54f85 | ||
|
|
f9858fdd1a | ||
|
|
fab9e0de46 | ||
|
|
1d7fef5810 | ||
|
|
f0dfb33292 | ||
|
|
04262d9c84 | ||
|
|
056815ea8b | ||
|
|
215fd0b6d9 | ||
|
|
9954007722 | ||
|
|
ea47bde02e | ||
|
|
c344304026 | ||
|
|
1f481fa1a3 | ||
|
|
88a062de78 | ||
|
|
19e2e6d858 | ||
|
|
c31080d470 | ||
|
|
b47247dad9 | ||
|
|
8a84773fdb | ||
|
|
55e21b9e17 | ||
|
|
7d30d8556a | ||
|
|
64d99f21eb | ||
|
|
1b65ca1900 | ||
|
|
3409cd399d | ||
|
|
3206565bac | ||
|
|
32dab97321 | ||
|
|
7003c609b8 | ||
|
|
16320cd28b | ||
|
|
406deb5971 | ||
|
|
38b24c7b94 | ||
|
|
530cf00d68 | ||
|
|
465056e9c6 | ||
|
|
91f6ee0c72 | ||
|
|
b859031855 | ||
|
|
81a9a86305 | ||
|
|
7f566dd0e5 | ||
|
|
65800d22e7 | ||
|
|
4cb74319f9 | ||
|
|
3aba7548f4 | ||
|
|
593887c8d0 | ||
|
|
0e4a1f112d | ||
|
|
18739c4ac1 | ||
|
|
947192570d | ||
|
|
2a00194316 | ||
|
|
9137e9e2ae | ||
|
|
890afe9d85 | ||
|
|
d0e276f66a | ||
|
|
5e8755c774 | ||
|
|
037f4ab4b6 | ||
|
|
f15058ab06 | ||
|
|
c34d167b91 | ||
|
|
b4a5acd890 | ||
|
|
a88911105c | ||
|
|
7ee00fb680 | ||
|
|
c29c0b01a7 | ||
|
|
9db735958c | ||
|
|
57cda13f7b | ||
|
|
2a73f35ce6 | ||
|
|
aaa58a6c10 | ||
|
|
52fa45c6ee | ||
|
|
934f5055ab | ||
|
|
26c82ca131 | ||
|
|
52555b06d4 | ||
|
|
e21b3f3dc4 | ||
|
|
ee400b5235 | ||
|
|
e273333fba | ||
|
|
6d932e83d2 | ||
|
|
ae889380da | ||
|
|
a7f9a29e74 | ||
|
|
a6350d9395 | ||
|
|
6c13562d23 | ||
|
|
00dc91423e | ||
|
|
ac767aad0f | ||
|
|
89567d3b31 | ||
|
|
dcdf6212cc | ||
|
|
c5f651f014 | ||
|
|
a274292b93 | ||
|
|
d3ac777f7b | ||
|
|
ecc45cbc7e | ||
|
|
1b4ba050cc | ||
|
|
5f47aa6140 | ||
|
|
89c4cca866 | ||
|
|
27bdd1a325 | ||
|
|
6db5ce1912 | ||
|
|
91e1d7ce48 | ||
|
|
97210d5b15 | ||
|
|
436f3bd9fe | ||
|
|
7de0444d06 | ||
|
|
7c7951391c | ||
|
|
6e21cdb13f | ||
|
|
67019110d7 | ||
|
|
9a00fabed7 | ||
|
|
c05918c860 | ||
|
|
f40551a061 | ||
|
|
d8205106cc | ||
|
|
cffb4e5bce | ||
|
|
3495b8009c | ||
|
|
c143afea10 | ||
|
|
c69f9210d9 | ||
|
|
043c50147c | ||
|
|
e94804bd48 | ||
|
|
e342e8de70 | ||
|
|
c06746182b | ||
|
|
fc6515d2f7 | ||
|
|
3d1eb091c0 | ||
|
|
bf6acd5cc9 | ||
|
|
737c43cdad | ||
|
|
0fc97486ff | ||
|
|
e0edc4c06d | ||
|
|
0a5e5e2fa5 | ||
|
|
8527f86de4 | ||
|
|
6459e64f36 | ||
|
|
25c6ce41d5 | ||
|
|
cbc8e947bf | ||
|
|
0dba01018c | ||
|
|
b5aa7f58e8 | ||
|
|
64567bb12a | ||
|
|
58320f7156 | ||
|
|
5ad19febad | ||
|
|
88f5f7392b | ||
|
|
4260241659 | ||
|
|
231ddd7508 | ||
|
|
cf0f3ce319 | ||
|
|
aaa5dd3a00 | ||
|
|
a269f47bc7 | ||
|
|
9685cc5682 | ||
|
|
2f741327e6 | ||
|
|
8c39bf0b9f | ||
|
|
e0fa33b2a0 | ||
|
|
fc02186460 | ||
|
|
2af9ca368b | ||
|
|
0cc125c365 | ||
|
|
36b22256c1 | ||
|
|
fbe8efea55 | ||
|
|
2e526d70d2 | ||
|
|
06d6ba666d | ||
|
|
37175489ca | ||
|
|
9ddf1b5c26 | ||
|
|
217384025e | ||
|
|
29b4128397 | ||
|
|
331ade75da | ||
|
|
d243d71bf5 | ||
|
|
5b3feb6008 | ||
|
|
d7631279f7 | ||
|
|
f5409d434a | ||
|
|
1c2c6c45e2 | ||
|
|
b30863e0e2 | ||
|
|
13ad4b7a42 | ||
|
|
9f6ca60f74 | ||
|
|
dbef6dc8e2 | ||
|
|
3248205bb7 | ||
|
|
09cf13cd9f | ||
|
|
8ff0a86e18 | ||
|
|
b9420cf0c1 | ||
|
|
340d5533ea | ||
|
|
e7258ffa88 | ||
|
|
dd8f66140b | ||
|
|
15e98b00f5 | ||
|
|
759993b922 | ||
|
|
7f35843d58 | ||
|
|
f2420fc7a3 | ||
|
|
811c010098 | ||
|
|
67f30273dd | ||
|
|
352fc82185 | ||
|
|
9ede5bd312 | ||
|
|
e3cf285ee7 | ||
|
|
f9f7cf35ae | ||
|
|
b660b4c9c0 | ||
|
|
029401f6cc | ||
|
|
9f5b01dfd8 | ||
|
|
38f4ce9f25 | ||
|
|
9cff779038 | ||
|
|
02b73f5705 | ||
|
|
2570f3ec4f | ||
|
|
dcffdaafb5 | ||
|
|
80f9fcdaa1 | ||
|
|
71d12148c8 | ||
|
|
d23de8b9ef | ||
|
|
4a4ccfe7d6 | ||
|
|
5149320e5b | ||
|
|
cb27ea8185 | ||
|
|
ae04d34c17 | ||
|
|
b84e6743be | ||
|
|
5b43f9a74d | ||
|
|
581cf00ee8 | ||
|
|
a49a1abf12 | ||
|
|
3978c92af1 | ||
|
|
221b6fec69 | ||
|
|
ff10da6575 | ||
|
|
af9aa366fd | ||
|
|
a6de4290c8 | ||
|
|
8d843148d2 | ||
|
|
05cc50ae37 | ||
|
|
b260017fec | ||
|
|
8a4c29e8db | ||
|
|
fde3f54d67 | ||
|
|
cf0db02ced | ||
|
|
25a84074ab | ||
|
|
891f47bcfa | ||
|
|
d41d6077ce | ||
|
|
3d1874af59 | ||
|
|
6ca6cf7474 | ||
|
|
67079664ae | ||
|
|
f5aee94f15 | ||
|
|
2879779804 | ||
|
|
b184e5324d | ||
|
|
ff920303df | ||
|
|
e0d71b0bc0 | ||
|
|
ab49745afe | ||
|
|
ace83ac938 | ||
|
|
75142a10be | ||
|
|
b84bd3a8c4 | ||
|
|
cafae24473 | ||
|
|
cc7bee7d80 | ||
|
|
6602b3b179 | ||
|
|
4f1afaca16 | ||
|
|
d72f092052 | ||
|
|
8744c97a4d | ||
|
|
df846e5904 | ||
|
|
eee53aa5d5 | ||
|
|
f3410d8c59 | ||
|
|
4846f37117 | ||
|
|
39a79be5ae | ||
|
|
fef73e4b86 | ||
|
|
2c5a01a67d | ||
|
|
58d479cd4a | ||
|
|
305529410b | ||
|
|
150b80deee | ||
|
|
280d7dde50 | ||
|
|
8509398137 | ||
|
|
42388d6c08 | ||
|
|
ffe8bbb8aa | ||
|
|
330136a89e | ||
|
|
bb9102f7d4 | ||
|
|
4310d505a7 | ||
|
|
d5fe0cf158 | ||
|
|
9360623853 | ||
|
|
e6f0e91590 | ||
|
|
dd7e5da016 | ||
|
|
459cf197b7 | ||
|
|
073da60b19 | ||
|
|
4370fde844 | ||
|
|
965f23dd61 | ||
|
|
72cee94646 | ||
|
|
bc9ed49a55 | ||
|
|
6db75f0bd2 | ||
|
|
4100646192 | ||
|
|
3152abac67 | ||
|
|
9aac873415 | ||
|
|
da3ba96430 | ||
|
|
809462490f | ||
|
|
498373dd01 | ||
|
|
c64d30aeff | ||
|
|
5c47597be9 | ||
|
|
6d8ee7acc9 | ||
|
|
cde37ad608 | ||
|
|
c5401494fe | ||
|
|
65caf20092 | ||
|
|
ca25d72064 | ||
|
|
f22ebaf7f1 | ||
|
|
f35a5a9b08 | ||
|
|
f68f378a23 | ||
|
|
8717e87046 | ||
|
|
0de23a29c5 | ||
|
|
6c4a67af0d | ||
|
|
35120ea2f1 | ||
|
|
eee7b97d7b | ||
|
|
762912d711 | ||
|
|
bd916ad7fc | ||
|
|
4c3e6b89a1 | ||
|
|
8c0500fd97 | ||
|
|
da93f1fd0c | ||
|
|
57df288f5b | ||
|
|
52e8540a86 | ||
|
|
077df8fbb6 | ||
|
|
8728a25f1d | ||
|
|
d5134a7cd4 | ||
|
|
47ab029798 | ||
|
|
ed89ccc521 | ||
|
|
16aabbcc3b | ||
|
|
9c7c79f2eb | ||
|
|
a044be7ed9 | ||
|
|
2d6d5637c0 | ||
|
|
5b8a2b2128 | ||
|
|
abb307c9c5 | ||
|
|
ba81830e81 | ||
|
|
b755e9d5a7 | ||
|
|
c8a66d3530 | ||
|
|
1354611277 | ||
|
|
1d7e7afd38 | ||
|
|
6535f1ed28 | ||
|
|
a1939ba993 | ||
|
|
964d4598ef | ||
|
|
747b67d38f | ||
|
|
d7c9636078 | ||
|
|
94735f99cb | ||
|
|
9c903e063e | ||
|
|
f485d89f16 | ||
|
|
f9572e8439 | ||
|
|
687dba8614 | ||
|
|
d374c406b2 | ||
|
|
259d0d876f | ||
|
|
40cb61c6bd | ||
|
|
643b36b814 | ||
|
|
0a49d34342 | ||
|
|
74c895d316 | ||
|
|
5e5e445182 | ||
|
|
86d3187d9b | ||
|
|
a98bf93a25 | ||
|
|
ec2a698301 | ||
|
|
01f8dba914 | ||
|
|
d2856a41ef | ||
|
|
441ba2175e | ||
|
|
435d705138 | ||
|
|
06a29459dc | ||
|
|
483c43396c | ||
|
|
ecbf584299 | ||
|
|
63ab1bb27a | ||
|
|
6704a4a6e4 | ||
|
|
7cec7eafce | ||
|
|
711c793171 | ||
|
|
73860e3397 | ||
|
|
698f4fea3a | ||
|
|
4ee73d42a4 | ||
|
|
36f3500d21 | ||
|
|
c6184cdb3e | ||
|
|
8149d1077b | ||
|
|
0355e9fd06 | ||
|
|
2fc649bfc6 | ||
|
|
67ba8d28df | ||
|
|
375dcb0bd6 | ||
|
|
0e092aee5c | ||
|
|
faa5c0cd3c | ||
|
|
149e02cf7d | ||
|
|
a714792b03 | ||
|
|
66c569ddcc | ||
|
|
3f41ade02d | ||
|
|
0315269228 | ||
|
|
62b19a6c09 | ||
|
|
7c90e6dfea | ||
|
|
4e274ac915 | ||
|
|
ee7c8441c8 | ||
|
|
c1dfdb44da | ||
|
|
a4527cc837 | ||
|
|
8082993f7f | ||
|
|
b81cff966e | ||
|
|
731f0d70fa | ||
|
|
08f07016a3 | ||
|
|
2666473042 | ||
|
|
5b6deaea18 | ||
|
|
971d3c2b09 | ||
|
|
dbe4f9fefe | ||
|
|
692842d6ad | ||
|
|
cb6e05f2dd | ||
|
|
5620fb2ac9 | ||
|
|
965d3a4e72 | ||
|
|
187ade8566 | ||
|
|
2d1b64066c | ||
|
|
ed808ab2c9 | ||
|
|
7b0f4d1dd8 | ||
|
|
483d652d95 | ||
|
|
1c85221192 | ||
|
|
d397d7773c | ||
|
|
f91ab74da9 | ||
|
|
db9d37edab | ||
|
|
ce81230b09 | ||
|
|
802c092d1a | ||
|
|
e8f4246e13 | ||
|
|
cdb8f364c1 | ||
|
|
e06b627f31 | ||
|
|
d6474640da | ||
|
|
9dcfc40f21 | ||
|
|
2231ab526f | ||
|
|
eab7249b74 | ||
|
|
292e5e1436 | ||
|
|
5ae2877796 | ||
|
|
76c751ce80 | ||
|
|
e4eec13108 | ||
|
|
6ad890a098 | ||
|
|
8896478926 | ||
|
|
58ad5d4dd7 | ||
|
|
ce07470031 | ||
|
|
ebaf7b61fc | ||
|
|
083f778321 | ||
|
|
78926c9083 | ||
|
|
e84044e87d | ||
|
|
9427941781 | ||
|
|
13b76f0937 | ||
|
|
be40fb1e56 | ||
|
|
684fa0f89d | ||
|
|
0e97a97603 | ||
|
|
ff8b39746b | ||
|
|
35b16b1984 | ||
|
|
d0381c05a6 | ||
|
|
60d06d8770 | ||
|
|
0d6d036e4f | ||
|
|
addecff68b | ||
|
|
4d384fcce5 | ||
|
|
faf3eb0823 | ||
|
|
73b909a514 | ||
|
|
a4ff44ce6f | ||
|
|
90c20face8 | ||
|
|
baba2535e1 | ||
|
|
c3ea5a7886 | ||
|
|
2bda6f8d9c | ||
|
|
f08a7376e9 | ||
|
|
63df436e5f | ||
|
|
6b34ab9cec | ||
|
|
5d57f97fa7 | ||
|
|
9cfeecaa2f | ||
|
|
6f570de8d7 | ||
|
|
31367925c6 | ||
|
|
31c781e453 | ||
|
|
8269a05874 | ||
|
|
95ff7112aa | ||
|
|
c0273e3505 | ||
|
|
a788e25e70 | ||
|
|
3056e08c9e | ||
|
|
7c10b3bdc8 | ||
|
|
5af9bd3d6d | ||
|
|
ba3f79ec4f | ||
|
|
66ff0989c5 | ||
|
|
e46279dc83 | ||
|
|
de88b46ac1 | ||
|
|
9a090a0f91 | ||
|
|
8919abe4c4 | ||
|
|
748e9892da | ||
|
|
bda8366ada | ||
|
|
2a655f70a1 | ||
|
|
262203b644 | ||
|
|
49343f6fab | ||
|
|
5d4c977f64 | ||
|
|
76818632e0 | ||
|
|
d7bb88b53a | ||
|
|
0e156df634 | ||
|
|
a37405dbd8 | ||
|
|
80ee7cb931 | ||
|
|
fbf783450c | ||
|
|
04cf5a99d9 | ||
|
|
7c7d33a4b5 | ||
|
|
85d17fcaed | ||
|
|
218be0a884 | ||
|
|
6316220d36 | ||
|
|
5010123d5c | ||
|
|
fc20696c59 | ||
|
|
4381fb6b11 | ||
|
|
319f2c8dbc | ||
|
|
6cdbdfc5ff | ||
|
|
192af1f71c | ||
|
|
5640ec8934 | ||
|
|
b283128b6f | ||
|
|
35353963db | ||
|
|
1e46be30e4 | ||
|
|
767cb33632 | ||
|
|
b30c7b0596 | ||
|
|
c099ddb587 | ||
|
|
a22a217261 | ||
|
|
c91ebfa900 | ||
|
|
8934c4212a | ||
|
|
750fa1cf86 | ||
|
|
09fc3d9df8 | ||
|
|
eae4f80d2c | ||
|
|
39ef261a29 | ||
|
|
158f73fce2 | ||
|
|
3cb4fc6778 | ||
|
|
f8b41eb1b1 | ||
|
|
4147c002ec | ||
|
|
8eb9957db6 | ||
|
|
c5173de511 | ||
|
|
b9d439d202 | ||
|
|
b94af7c82f | ||
|
|
508411efb5 | ||
|
|
e5e1e250cd | ||
|
|
a938818047 | ||
|
|
27533da4f1 | ||
|
|
7e14816e85 | ||
|
|
49e11e797e | ||
|
|
1e064171da | ||
|
|
27be0b0d41 | ||
|
|
1c93cae6c5 | ||
|
|
cd4ee5fcb4 | ||
|
|
ac7b437cdb | ||
|
|
584a569a26 | ||
|
|
70aaf8ad81 | ||
|
|
6077b39ae5 | ||
|
|
66df974ce8 | ||
|
|
e368d999a1 | ||
|
|
2ef995772b | ||
|
|
afbd74d9f1 | ||
|
|
5ccd0c27fd | ||
|
|
4b2e6cb321 | ||
|
|
7726ae5182 | ||
|
|
75ab6b765f | ||
|
|
6db058c4af | ||
|
|
60607c734d | ||
|
|
2bf8d2a703 | ||
|
|
455581daa7 | ||
|
|
759f7060e3 | ||
|
|
2e0db686bd | ||
|
|
c17de8379b | ||
|
|
10783f221d | ||
|
|
b499a601b5 | ||
|
|
2b73ca3216 | ||
|
|
376f73762a | ||
|
|
ab205c20e6 | ||
|
|
ec3e4fc305 | ||
|
|
dbcb1a1192 | ||
|
|
70db992dd1 | ||
|
|
b2bcbcd866 | ||
|
|
a1937bf54c | ||
|
|
913806d047 | ||
|
|
320d23334f | ||
|
|
cd55cde10d | ||
|
|
21303afdf1 | ||
|
|
8e273cac72 | ||
|
|
3651fd75f7 | ||
|
|
689f0e9d52 | ||
|
|
838c4f1a2a | ||
|
|
7c7c136dc4 | ||
|
|
3a8b1b5add | ||
|
|
56a21bf34a | ||
|
|
39cd633013 | ||
|
|
3ffe66d4ef | ||
|
|
6990e4c7b8 | ||
|
|
1f30aac8a2 | ||
|
|
c0640f5e97 | ||
|
|
b4bac92547 | ||
|
|
4e88e07f76 | ||
|
|
cf1e6e7465 | ||
|
|
306df5eeac | ||
|
|
ab1e8f2497 | ||
|
|
35eefdfa1a | ||
|
|
4d4e725233 | ||
|
|
4cf4170b75 | ||
|
|
67f11acf5c | ||
|
|
a110f268c7 | ||
|
|
dae253025c | ||
|
|
9942cea529 | ||
|
|
27d570a089 | ||
|
|
6687aabbc2 | ||
|
|
8bfd56d051 | ||
|
|
15539105df | ||
|
|
f9c2bb19fe | ||
|
|
77c8751576 | ||
|
|
b4336c2e0a | ||
|
|
0e42c574ed | ||
|
|
98733147f5 | ||
|
|
b1c1a83db3 | ||
|
|
60d06387da | ||
|
|
e93d6a3401 | ||
|
|
82e7f58c4f | ||
|
|
3b21fa3258 | ||
|
|
c2642ca20c | ||
|
|
7b0e9cf792 | ||
|
|
3f5655fce5 | ||
|
|
86bc91ae56 | ||
|
|
2075788ffc |
No files matched your search
@@ -0,0 +1,68 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- '*.md'
|
||||
- '.mailmap'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
name: ${{ matrix.compiler }} on ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
compiler: [g++-8, g++-9, g++-10, g++-11,
|
||||
clang++-7, clang++-8, clang++-9, clang++-10, clang++-11, clang++-12]
|
||||
os: [ubuntu-20.04]
|
||||
include:
|
||||
- compiler: g++-7
|
||||
os: ubuntu-18.04
|
||||
- compiler: clang++-5.0
|
||||
os: ubuntu-18.04
|
||||
- compiler: clang++-6.0
|
||||
os: ubuntu-18.04
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
CXX: ${{ matrix.compiler }}
|
||||
NODE_LABELS: Linux Ubuntu
|
||||
WAF_JOBS: 2
|
||||
steps:
|
||||
- name: Install C++ compiler
|
||||
run: |
|
||||
sudo apt-get -qy install ${CXX/clang++/clang}
|
||||
${CXX} --version
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Build and test
|
||||
run: ./.jenkins
|
||||
|
||||
macos:
|
||||
name: Xcode ${{ matrix.xcode }} on ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
xcode: ['11.3', '11.7', '12.4']
|
||||
os: [macos-10.15]
|
||||
include:
|
||||
- xcode: '12.5'
|
||||
os: macos-11
|
||||
- xcode: '13.2'
|
||||
os: macos-11
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
NODE_LABELS: OSX
|
||||
WAF_JOBS: 3
|
||||
steps:
|
||||
- name: Set up Xcode
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: ${{ matrix.xcode }}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Build and test
|
||||
run: ./.jenkins
|
||||
@@ -0,0 +1,40 @@
|
||||
name: Docs
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '*.md'
|
||||
- '.mailmap'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-11, ubuntu-20.04]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
JOB_NAME: Docs
|
||||
WAF_JOBS: 3
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
case ${RUNNER_OS} in
|
||||
Linux) export NODE_LABELS="Linux Ubuntu" ;;
|
||||
macOS) export NODE_LABELS="OSX" ;;
|
||||
esac
|
||||
find .jenkins.d/ -type f -name '[1-9]*.sh' -exec chmod -x '{}' +
|
||||
./.jenkins
|
||||
- name: Build documentation
|
||||
run: |
|
||||
./waf --color=yes configure
|
||||
./waf --color=yes build --targets=version.hpp
|
||||
./waf --color=yes build --targets=manpages
|
||||
./waf --color=yes docs
|
||||
+29
-7
@@ -1,7 +1,29 @@
|
||||
.DS*
|
||||
.waf-1*
|
||||
.waf3-*
|
||||
.lock*
|
||||
**/*.pyc
|
||||
build/
|
||||
VERSION
|
||||
# Emacs
|
||||
*~
|
||||
\#*\#
|
||||
/.emacs.desktop
|
||||
/.emacs.desktop.lock
|
||||
*.elc
|
||||
.\#*
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
._*
|
||||
|
||||
# Waf build system
|
||||
/build/
|
||||
.waf-*-*/
|
||||
.waf3-*-*/
|
||||
.lock-waf*
|
||||
|
||||
# Compiled python code
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# Other
|
||||
/VERSION.info
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[submodule "websocketpp"]
|
||||
path = websocketpp
|
||||
url = https://github.com/zaphoyd/websocketpp.git
|
||||
url = https://github.com/cawka/websocketpp.git
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
source .jenkins.d/util.sh
|
||||
|
||||
if has Linux $NODE_LABELS; then
|
||||
export PATH="${HOME}/.local/bin${PATH:+:}${PATH}"
|
||||
fi
|
||||
export CACHE_DIR=${CACHE_DIR:-/tmp}
|
||||
export WAF_JOBS=${WAF_JOBS:-1}
|
||||
[[ $JOB_NAME == *"code-coverage" ]] && export DISABLE_ASAN=yes
|
||||
|
||||
for file in .jenkins.d/*; do
|
||||
[[ -f $file && -x $file ]] || continue
|
||||
|
||||
if [[ -n $GITHUB_ACTIONS ]]; then
|
||||
label=$(basename "$file" | sed -E 's/[[:digit:]]+-(.*)\..*/\1/')
|
||||
echo "::group::${label}"
|
||||
fi
|
||||
|
||||
echo "\$ $file"
|
||||
"$file"
|
||||
|
||||
if [[ -n $GITHUB_ACTIONS ]]; then
|
||||
echo "::endgroup::"
|
||||
fi
|
||||
done
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
if has OSX $NODE_LABELS; then
|
||||
FORMULAE=(boost openssl pkg-config)
|
||||
if [[ $JOB_NAME == *"Docs" ]]; then
|
||||
FORMULAE+=(doxygen graphviz)
|
||||
fi
|
||||
|
||||
if [[ -n $GITHUB_ACTIONS ]]; then
|
||||
# GitHub Actions runners have a large number of pre-installed
|
||||
# Homebrew packages. Don't waste time upgrading all of them.
|
||||
brew list --versions "${FORMULAE[@]}" || brew update
|
||||
for FORMULA in "${FORMULAE[@]}"; do
|
||||
brew list --versions "$FORMULA" || brew install "$FORMULA"
|
||||
done
|
||||
# Ensure /usr/local/opt/openssl exists
|
||||
brew reinstall openssl
|
||||
else
|
||||
brew update
|
||||
brew upgrade
|
||||
brew install "${FORMULAE[@]}"
|
||||
brew cleanup
|
||||
fi
|
||||
|
||||
if [[ $JOB_NAME == *"Docs" ]]; then
|
||||
pip3 install --upgrade --upgrade-strategy=eager sphinx sphinxcontrib-doxylink
|
||||
fi
|
||||
|
||||
elif has Ubuntu $NODE_LABELS; then
|
||||
sudo apt-get -qq update
|
||||
sudo apt-get -qy install build-essential pkg-config python3-minimal \
|
||||
libboost-all-dev libssl-dev libsqlite3-dev \
|
||||
libpcap-dev libsystemd-dev
|
||||
|
||||
case $JOB_NAME in
|
||||
*code-coverage)
|
||||
sudo apt-get -qy install lcov python3-pip
|
||||
pip3 install --user --upgrade --upgrade-strategy=eager 'gcovr~=5.0'
|
||||
;;
|
||||
*Docs)
|
||||
sudo apt-get -qy install doxygen graphviz python3-pip
|
||||
pip3 install --user --upgrade --upgrade-strategy=eager sphinx sphinxcontrib-doxylink
|
||||
;;
|
||||
esac
|
||||
|
||||
elif has CentOS-8 $NODE_LABELS; then
|
||||
sudo dnf config-manager --enable powertools
|
||||
sudo dnf -y install gcc-c++ libasan pkgconf-pkg-config python3 \
|
||||
boost-devel openssl-devel sqlite-devel \
|
||||
libpcap-devel systemd-devel
|
||||
fi
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
pushd "$CACHE_DIR" >/dev/null
|
||||
|
||||
INSTALLED_VERSION=
|
||||
if has OSX $NODE_LABELS; then
|
||||
BOOST=$(brew ls --versions boost)
|
||||
OLD_BOOST=$(cat boost.txt || :)
|
||||
if [[ $OLD_BOOST != $BOOST ]]; then
|
||||
echo "$BOOST" > boost.txt
|
||||
INSTALLED_VERSION=NONE
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $INSTALLED_VERSION ]]; then
|
||||
INSTALLED_VERSION=$(git -C ndn-cxx rev-parse HEAD 2>/dev/null || echo NONE)
|
||||
fi
|
||||
|
||||
sudo rm -rf ndn-cxx-latest
|
||||
git clone --depth 1 https://github.com/named-data/ndn-cxx.git ndn-cxx-latest
|
||||
LATEST_VERSION=$(git -C ndn-cxx-latest rev-parse HEAD 2>/dev/null || echo UNKNOWN)
|
||||
|
||||
if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
|
||||
sudo rm -rf ndn-cxx
|
||||
mv ndn-cxx-latest ndn-cxx
|
||||
else
|
||||
sudo rm -rf ndn-cxx-latest
|
||||
fi
|
||||
|
||||
sudo rm -f /usr/local/bin/ndnsec*
|
||||
sudo rm -fr /usr/local/include/ndn-cxx
|
||||
sudo rm -f /usr/local/lib{,64}/libndn-cxx*
|
||||
sudo rm -f /usr/local/lib{,64}/pkgconfig/libndn-cxx.pc
|
||||
|
||||
pushd ndn-cxx >/dev/null
|
||||
|
||||
if has CentOS-8 $NODE_LABELS; then
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1721553
|
||||
PCH="--without-pch"
|
||||
fi
|
||||
|
||||
./waf --color=yes configure --disable-static --enable-shared --without-osx-keychain $PCH
|
||||
./waf --color=yes build -j$WAF_JOBS
|
||||
sudo_preserve_env PATH -- ./waf --color=yes install
|
||||
|
||||
popd >/dev/null
|
||||
popd >/dev/null
|
||||
|
||||
if has CentOS-8 $NODE_LABELS; then
|
||||
sudo tee /etc/ld.so.conf.d/ndn.conf >/dev/null <<< /usr/local/lib64
|
||||
fi
|
||||
if has Linux $NODE_LABELS; then
|
||||
sudo ldconfig
|
||||
fi
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
git submodule sync
|
||||
git submodule update --init
|
||||
|
||||
if [[ -z $DISABLE_ASAN ]]; then
|
||||
ASAN="--with-sanitizer=address"
|
||||
fi
|
||||
if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
COVERAGE="--with-coverage"
|
||||
fi
|
||||
if has CentOS-8 $NODE_LABELS; then
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1721553
|
||||
PCH="--without-pch"
|
||||
fi
|
||||
|
||||
if [[ $JOB_NAME != *"code-coverage" && $JOB_NAME != *"limited-build" ]]; then
|
||||
# Build in release mode with tests and without precompiled headers
|
||||
./waf --color=yes configure --with-tests --without-pch
|
||||
./waf --color=yes build -j$WAF_JOBS
|
||||
|
||||
# Cleanup
|
||||
./waf --color=yes distclean
|
||||
|
||||
# Build in release mode without tests, but with "other tests"
|
||||
./waf --color=yes configure --with-other-tests $PCH
|
||||
./waf --color=yes build -j$WAF_JOBS
|
||||
|
||||
# Cleanup
|
||||
./waf --color=yes distclean
|
||||
fi
|
||||
|
||||
# Build in debug mode with tests
|
||||
./waf --color=yes configure --debug --with-tests $ASAN $COVERAGE $PCH
|
||||
./waf --color=yes build -j$WAF_JOBS
|
||||
|
||||
# (tests will be run against the debug version)
|
||||
|
||||
# Install
|
||||
sudo_preserve_env PATH -- ./waf --color=yes install
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
# Prepare environment
|
||||
rm -rf ~/.ndn
|
||||
|
||||
if has OSX $NODE_LABELS; then
|
||||
security unlock-keychain -p named-data
|
||||
fi
|
||||
|
||||
ndnsec key-gen "/tmp/jenkins/$NODE_NAME" | ndnsec cert-install -
|
||||
|
||||
# https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
|
||||
ASAN_OPTIONS="color=always"
|
||||
ASAN_OPTIONS+=":check_initialization_order=1"
|
||||
ASAN_OPTIONS+=":detect_stack_use_after_return=1"
|
||||
ASAN_OPTIONS+=":strict_init_order=1"
|
||||
ASAN_OPTIONS+=":strict_string_checks=1"
|
||||
ASAN_OPTIONS+=":detect_invalid_pointer_pairs=2"
|
||||
ASAN_OPTIONS+=":detect_container_overflow=0"
|
||||
ASAN_OPTIONS+=":detect_leaks=0"
|
||||
ASAN_OPTIONS+=":strip_path_prefix=${PWD}/"
|
||||
export ASAN_OPTIONS
|
||||
|
||||
export BOOST_TEST_BUILD_INFO=1
|
||||
export BOOST_TEST_COLOR_OUTPUT=1
|
||||
export BOOST_TEST_DETECT_MEMORY_LEAK=0
|
||||
|
||||
ut_log_args() {
|
||||
echo --logger=HRF,test_suite,stdout:XML,all,build/xunit-log${1:+-$1}.xml
|
||||
}
|
||||
|
||||
# First run all tests as unprivileged user
|
||||
./build/unit-tests-core $(ut_log_args core)
|
||||
./build/unit-tests-daemon $(ut_log_args daemon)
|
||||
./build/unit-tests-rib $(ut_log_args rib)
|
||||
./build/unit-tests-tools $(ut_log_args tools)
|
||||
|
||||
# Then use sudo to run those tests that need superuser powers
|
||||
sudo_preserve_env ASAN_OPTIONS BOOST_TEST_COLOR_OUTPUT -- \
|
||||
./build/unit-tests-daemon -t TestPrivilegeHelper $(ut_log_args daemon-privilege-helper)
|
||||
sudo_preserve_env ASAN_OPTIONS BOOST_TEST_COLOR_OUTPUT -- \
|
||||
./build/unit-tests-daemon -t Face/*Ethernet* $(ut_log_args daemon-ethernet)
|
||||
sudo_preserve_env ASAN_OPTIONS BOOST_TEST_COLOR_OUTPUT -- \
|
||||
./build/unit-tests-daemon -t Face/TestUdpFactory $(ut_log_args daemon-udp)
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
# Generate an XML report (Cobertura format) and a detailed HTML report using gcovr
|
||||
# Note: trailing slashes are important in the paths below. Do not remove them!
|
||||
gcovr -j$WAF_JOBS \
|
||||
--object-directory build \
|
||||
--exclude tests/ \
|
||||
--exclude websocketpp/ \
|
||||
--exclude-throw-branches \
|
||||
--exclude-unreachable-branches \
|
||||
--print-summary \
|
||||
--html-details build/gcovr/ \
|
||||
--xml build/coverage.xml
|
||||
|
||||
# Generate a detailed HTML report using lcov
|
||||
lcov --quiet \
|
||||
--capture \
|
||||
--directory . \
|
||||
--exclude "$PWD/tests/*" \
|
||||
--exclude "$PWD/websocketpp/*" \
|
||||
--no-external \
|
||||
--rc lcov_branch_coverage=1 \
|
||||
--output-file build/coverage.info
|
||||
|
||||
genhtml --branch-coverage \
|
||||
--demangle-cpp \
|
||||
--legend \
|
||||
--output-directory build/lcov \
|
||||
--title "NFD unit tests" \
|
||||
build/coverage.info
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
# CONTINUOUS INTEGRATION SCRIPTS
|
||||
|
||||
## Environment Variables Used in Build Scripts
|
||||
|
||||
- `NODE_LABELS`: space-separated list of platform properties. The included values are used by
|
||||
the build scripts to select the proper behavior for different operating systems and versions.
|
||||
|
||||
The list should normally contain `[OS_TYPE]`, `[DISTRO_TYPE]`, and `[DISTRO_VERSION]`.
|
||||
|
||||
Example values:
|
||||
|
||||
- `[OS_TYPE]`: `Linux`, `OSX`
|
||||
- `[DISTRO_TYPE]`: `Ubuntu`, `CentOS`
|
||||
- `[DISTRO_VERSION]`: `Ubuntu-16.04`, `Ubuntu-18.04`, `CentOS-8`, `OSX-10.14`, `OSX-10.15`
|
||||
|
||||
- `JOB_NAME`: optional variable that defines the type of build job. Depending on the job type,
|
||||
the build scripts can perform different tasks.
|
||||
|
||||
Possible values:
|
||||
|
||||
- empty: default build task
|
||||
- `code-coverage`: debug build with tests and code coverage analysis (Ubuntu Linux is assumed)
|
||||
- `limited-build`: only a single debug build with tests
|
||||
|
||||
- `CACHE_DIR`: directory containing cached files from previous builds, e.g., a compiled version
|
||||
of ndn-cxx. If not set, `/tmp` is used.
|
||||
|
||||
- `WAF_JOBS`: number of parallel build threads used by waf, defaults to 1.
|
||||
@@ -0,0 +1,39 @@
|
||||
has() {
|
||||
local saved_xtrace
|
||||
[[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
|
||||
set +x
|
||||
|
||||
local p=$1
|
||||
shift
|
||||
local i ret=1
|
||||
for i in "$@"; do
|
||||
if [[ "${i}" == "${p}" ]]; then
|
||||
ret=0
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
set ${saved_xtrace}
|
||||
return ${ret}
|
||||
}
|
||||
export -f has
|
||||
|
||||
sudo_preserve_env() {
|
||||
local saved_xtrace
|
||||
[[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
|
||||
set +x
|
||||
|
||||
local vars=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
local arg=$1
|
||||
shift
|
||||
case ${arg} in
|
||||
--) break ;;
|
||||
*) vars+=("${arg}=${!arg}") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
set ${saved_xtrace}
|
||||
sudo env "${vars[@]}" "$@"
|
||||
}
|
||||
export -f sudo_preserve_env
|
||||
@@ -0,0 +1,14 @@
|
||||
<aa@cs.fiu.edu> <alexander.afanasyev@ucla.edu>
|
||||
<davidepesa@gmail.com> <davide.pesavento@lip6.fr>
|
||||
<enewberry@email.arizona.edu> <enewberry@cs.arizona.edu>
|
||||
Vince Lehman <vslehman@memphis.edu> <vlehman1@gmail.com>
|
||||
<lybmath2009@gmail.com> <lybmath@ucla.edu>
|
||||
Hila Ben Abraham <hilata@gmail.com>
|
||||
<tuyukai1994@gmail.com> <tyk@bupt.edu.cn>
|
||||
Haowei Yuan <hyuan@wustl.edu>
|
||||
Minsheng Zhang <jimmyzms5@gmail.com>
|
||||
Spyridon Mastorakis <spiros.mastorakis@gmail.com>
|
||||
Md Ashiqur Rahman <marahman@email.arizona.edu>
|
||||
Yumin Xia <me@yumin-xia.com>
|
||||
<chghasemi@cs.arizona.edu> <chavoosh.ghasemi@gmail.com>
|
||||
Tai-Lin Chu <tailinchu@gmail.com>
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
# For Ubuntu only
|
||||
language: cpp
|
||||
os:
|
||||
- linux
|
||||
compiler:
|
||||
- gcc
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
||||
on_failure: always
|
||||
before_install:
|
||||
- travis_retry sudo apt-get update
|
||||
- travis_retry sudo apt-get install -qq libssl-dev libpcap-dev libboost1.48-all-dev libcrypto++-dev libsqlite3-dev
|
||||
- travis_retry git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx
|
||||
- cd ndn-cxx
|
||||
- ./waf configure
|
||||
- ./waf -j1
|
||||
- sudo ./waf install
|
||||
- sudo ldconfig
|
||||
- cd ..
|
||||
- ndnsec-keygen /tmp/key | ndnsec-install-cert -
|
||||
script:
|
||||
- ./waf configure --with-tests
|
||||
- ./waf -j1
|
||||
- sudo ./waf install
|
||||
- ./build/unit-tests-core
|
||||
- ./build/unit-tests-daemon
|
||||
- ./build/unit-tests-rib
|
||||
# Tutorial for setting up notifications:
|
||||
# http://docs.travis-ci.com/user/notifications/
|
||||
# Here's a simple example for email notifications:
|
||||
#
|
||||
# notifications:
|
||||
# email:
|
||||
# recipients:
|
||||
# - one@example.com
|
||||
# - other@example.com
|
||||
# on_success: [always|never|change] # default: change
|
||||
# on_failure: [always|never|change] # default: always
|
||||
#
|
||||
# There are also other types of notifications available, including:
|
||||
# IRC, Campfire, Flowdock, HipChat, and Webhook.
|
||||
# For more infomation about notifications, please visit the link above.
|
||||
@@ -1,22 +0,0 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
#
|
||||
# Copyright (c) 2014, Regents of the University of California
|
||||
#
|
||||
# GPL 3.0 license, see the COPYING.md file for more information
|
||||
|
||||
from waflib import Configure
|
||||
|
||||
BOOST_ASIO_HAS_KQUEUE_CHECK = '''
|
||||
#include <boost/asio.hpp>
|
||||
#if defined(BOOST_ASIO_HAS_KQUEUE) and BOOST_VERSION >= 105600
|
||||
#error "Ethernet face support cannot be enabled on this platform"
|
||||
#endif
|
||||
'''
|
||||
|
||||
@Configure.conf
|
||||
def check_asio_pcap_support(conf):
|
||||
if conf.check_cxx(msg='Checking if Ethernet face support can be enabled',
|
||||
fragment=BOOST_ASIO_HAS_KQUEUE_CHECK,
|
||||
features='cxx', use='BOOST', mandatory=False):
|
||||
conf.define('HAVE_ASIO_PCAP_SUPPORT', 1)
|
||||
conf.env['HAVE_ASIO_PCAP_SUPPORT'] = True
|
||||
+252
-97
@@ -30,15 +30,15 @@ When using this tool, the wscript will look like:
|
||||
|
||||
Options are generated, in order to specify the location of boost includes/libraries.
|
||||
The `check_boost` configuration function allows to specify the used boost libraries.
|
||||
It can also provide default arguments to the --boost-static and --boost-mt command-line arguments.
|
||||
It can also provide default arguments to the --boost-mt command-line arguments.
|
||||
Everything will be packaged together in a BOOST component that you can use.
|
||||
|
||||
When using MSVC, a lot of compilation flags need to match your BOOST build configuration:
|
||||
- you may have to add /EHsc to your CXXFLAGS or define boost::throw_exception if BOOST_NO_EXCEPTIONS is defined.
|
||||
Errors: C4530
|
||||
- boost libraries will try to be smart and use the (pretty but often not useful) auto-linking feature of MSVC
|
||||
So before calling `conf.check_boost` you might want to disabling by adding:
|
||||
conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB']
|
||||
So before calling `conf.check_boost` you might want to disabling by adding
|
||||
conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB']
|
||||
Errors:
|
||||
- boost might also be compiled with /MT, which links the runtime statically.
|
||||
If you have problems with redefined symbols,
|
||||
@@ -52,24 +52,60 @@ import sys
|
||||
import re
|
||||
from waflib import Utils, Logs, Errors
|
||||
from waflib.Configure import conf
|
||||
from waflib.TaskGen import feature, after_method
|
||||
|
||||
BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib']
|
||||
BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include']
|
||||
|
||||
BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib', '/usr/lib/x86_64-linux-gnu', '/usr/lib/i386-linux-gnu', '/usr/local/ndn/lib']
|
||||
BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include', '/usr/local/ndn/include']
|
||||
BOOST_VERSION_FILE = 'boost/version.hpp'
|
||||
BOOST_VERSION_CODE = '''
|
||||
#include <iostream>
|
||||
#include <boost/version.hpp>
|
||||
int main() { std::cout << BOOST_LIB_VERSION << ":" << BOOST_VERSION << std::endl; }
|
||||
'''
|
||||
BOOST_SYSTEM_CODE = '''
|
||||
|
||||
BOOST_ERROR_CODE = '''
|
||||
#include <boost/system/error_code.hpp>
|
||||
int main() { boost::system::error_code c; }
|
||||
'''
|
||||
|
||||
PTHREAD_CODE = '''
|
||||
#include <pthread.h>
|
||||
static void* f(void*) { return 0; }
|
||||
int main() {
|
||||
pthread_t th;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&th, &attr, &f, 0);
|
||||
pthread_join(th, 0);
|
||||
pthread_cleanup_push(0, 0);
|
||||
pthread_cleanup_pop(0);
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
'''
|
||||
|
||||
BOOST_THREAD_CODE = '''
|
||||
#include <boost/thread.hpp>
|
||||
int main() { boost::thread t; }
|
||||
'''
|
||||
|
||||
BOOST_LOG_CODE = '''
|
||||
#include <boost/log/trivial.hpp>
|
||||
int main() { BOOST_LOG_TRIVIAL(info) << "boost_log is working"; }
|
||||
'''
|
||||
|
||||
BOOST_LOG_SETUP_CODE = '''
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
int main() {
|
||||
using namespace boost::log;
|
||||
add_common_attributes();
|
||||
add_console_log(std::clog, keywords::format = "%Message%");
|
||||
BOOST_LOG_TRIVIAL(info) << "boost_log_setup is working";
|
||||
}
|
||||
'''
|
||||
|
||||
# toolsets from {boost_dir}/tools/build/v2/tools/common.jam
|
||||
PLATFORM = Utils.unversioned_sys_platform()
|
||||
detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il'
|
||||
@@ -101,34 +137,37 @@ BOOST_TOOLSETS = {
|
||||
|
||||
def options(opt):
|
||||
opt = opt.add_option_group('Boost Options')
|
||||
|
||||
opt.add_option('--boost-includes', type='string',
|
||||
default='', dest='boost_includes',
|
||||
help='''path to the directory where the boost includes are, e.g., /path/to/boost_1_55_0/stage/include''')
|
||||
help='''path to the directory where the boost includes are,
|
||||
e.g., /path/to/boost_1_55_0/stage/include''')
|
||||
opt.add_option('--boost-libs', type='string',
|
||||
default='', dest='boost_libs',
|
||||
help='''path to the directory where the boost libs are, e.g., /path/to/boost_1_55_0/stage/lib''')
|
||||
opt.add_option('--boost-static', action='store_true',
|
||||
default=False, dest='boost_static',
|
||||
help='link with static boost libraries (.lib/.a)')
|
||||
help='''path to the directory where the boost libs are,
|
||||
e.g., path/to/boost_1_55_0/stage/lib''')
|
||||
opt.add_option('--boost-mt', action='store_true',
|
||||
default=False, dest='boost_mt',
|
||||
help='select multi-threaded libraries')
|
||||
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi',
|
||||
help='''select libraries with tags (dgsyp, d for debug), see doc Boost, Getting Started, chapter 6.1''')
|
||||
opt.add_option('--boost-linkage_autodetect', action="store_true", dest='boost_linkage_autodetect',
|
||||
help='''select libraries with tags (gd for debug, static is automatically added),
|
||||
see doc Boost, Getting Started, chapter 6.1''')
|
||||
opt.add_option('--boost-linkage_autodetect', action='store_true', dest='boost_linkage_autodetect',
|
||||
help="auto-detect boost linkage options (don't get used to it / might break other stuff)")
|
||||
opt.add_option('--boost-toolset', type='string',
|
||||
default='', dest='boost_toolset',
|
||||
help='force a toolset e.g. msvc, vc90, gcc, mingw, mgw45 (default: auto)')
|
||||
help='force a toolset e.g. msvc, vc90, \
|
||||
gcc, mingw, mgw45 (default: auto)')
|
||||
py_version = '%d%d' % (sys.version_info[0], sys.version_info[1])
|
||||
opt.add_option('--boost-python', type='string',
|
||||
default=py_version, dest='boost_python',
|
||||
help='select the lib python with this version (default: %s)' % py_version)
|
||||
help='select the lib python with this version \
|
||||
(default: %s)' % py_version)
|
||||
|
||||
|
||||
@conf
|
||||
def __boost_get_version_file(self, d):
|
||||
if not d:
|
||||
return None
|
||||
dnode = self.root.find_dir(d)
|
||||
if dnode:
|
||||
return dnode.find_node(BOOST_VERSION_FILE)
|
||||
@@ -141,33 +180,30 @@ def boost_get_version(self, d):
|
||||
if node:
|
||||
try:
|
||||
txt = node.read()
|
||||
except (OSError, IOError):
|
||||
Logs.error("Could not read the file %r" % node.abspath())
|
||||
except EnvironmentError:
|
||||
Logs.error('Could not read the file %r' % node.abspath())
|
||||
else:
|
||||
re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M)
|
||||
m1 = re_but1.search(txt)
|
||||
|
||||
re_but2 = re.compile('^#define\\s+BOOST_VERSION\\s+(\\d+)', re.M)
|
||||
m2 = re_but2.search(txt)
|
||||
|
||||
if m1 and m2:
|
||||
return (m1.group(1), m2.group(1))
|
||||
|
||||
return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(":")
|
||||
return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(':')
|
||||
|
||||
@conf
|
||||
def boost_get_includes(self, *k, **kw):
|
||||
includes = k and k[0] or kw.get('includes', None)
|
||||
if includes and self.__boost_get_version_file(includes):
|
||||
return includes
|
||||
for d in Utils.to_list(self.environ.get('INCLUDE', '')) + BOOST_INCLUDES:
|
||||
for d in self.environ.get('INCLUDE', '').split(';') + BOOST_INCLUDES:
|
||||
if self.__boost_get_version_file(d):
|
||||
return d
|
||||
if includes:
|
||||
self.end_msg('headers not found in %s' % includes)
|
||||
self.end_msg('headers not found in %s' % includes, 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
else:
|
||||
self.end_msg('headers not found, please provide a --boost-includes argument (see help)')
|
||||
self.end_msg('headers not found, please provide a --boost-includes argument (see help)', 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
|
||||
|
||||
@@ -195,7 +231,9 @@ def __boost_get_libs_path(self, *k, **kw):
|
||||
path = self.root.find_dir(libs)
|
||||
files = path.ant_glob('*boost_*')
|
||||
if not libs or not files:
|
||||
for d in Utils.to_list(self.environ.get('LIB', [])) + BOOST_LIBS:
|
||||
for d in self.environ.get('LIB', '').split(';') + BOOST_LIBS:
|
||||
if not d:
|
||||
continue
|
||||
path = self.root.find_dir(d)
|
||||
if path:
|
||||
files = path.ant_glob('*boost_*')
|
||||
@@ -208,10 +246,10 @@ def __boost_get_libs_path(self, *k, **kw):
|
||||
break
|
||||
if not path:
|
||||
if libs:
|
||||
self.end_msg('libs not found in %s' % libs)
|
||||
self.end_msg('libs not found in %s' % libs, 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
else:
|
||||
self.end_msg('libs not found, please provide a --boost-libs argument (see help)')
|
||||
self.end_msg('libs not found, please provide a --boost-libs argument (see help)', 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
|
||||
self.to_log('Found the boost path in %r with the libraries:' % path)
|
||||
@@ -226,15 +264,10 @@ def boost_get_libs(self, *k, **kw):
|
||||
according to the parameters
|
||||
'''
|
||||
path, files = self.__boost_get_libs_path(**kw)
|
||||
t = []
|
||||
if kw.get('mt', False):
|
||||
t.append('mt')
|
||||
if kw.get('abi', None):
|
||||
t.append(kw['abi'])
|
||||
tags = t and '(-%s)+' % '-'.join(t) or ''
|
||||
files = sorted(files, key=lambda f: (len(f.name), f.name), reverse=True)
|
||||
toolset = self.boost_get_toolset(kw.get('toolset', ''))
|
||||
toolset_pat = '(-%s[0-9]{0,3})+' % toolset
|
||||
version = '(-%s)+' % self.env.BOOST_VERSION
|
||||
toolset_pat = '(-%s[0-9]{0,3})' % toolset
|
||||
version = '-%s' % self.env.BOOST_VERSION
|
||||
|
||||
def find_lib(re_lib, files):
|
||||
for file in files:
|
||||
@@ -248,28 +281,109 @@ def boost_get_libs(self, *k, **kw):
|
||||
name = name[3:]
|
||||
return name[:name.rfind('.')]
|
||||
|
||||
libs = []
|
||||
for lib in Utils.to_list(k and k[0] or kw.get('lib', None)):
|
||||
py = (lib == 'python') and '(-py%s)+' % kw['python'] or ''
|
||||
# Trying libraries, from most strict match to least one
|
||||
for pattern in ['boost_%s%s%s%s%s' % (lib, toolset_pat, tags, py, version),
|
||||
'boost_%s%s%s%s' % (lib, tags, py, version),
|
||||
'boost_%s%s%s' % (lib, tags, version),
|
||||
# Give up trying to find the right version
|
||||
'boost_%s%s%s%s' % (lib, toolset_pat, tags, py),
|
||||
'boost_%s%s%s' % (lib, tags, py),
|
||||
'boost_%s%s' % (lib, tags)]:
|
||||
self.to_log('Trying pattern %s' % pattern)
|
||||
file = find_lib(re.compile(pattern), files)
|
||||
if file:
|
||||
libs.append(format_lib_name(file.name))
|
||||
break
|
||||
else:
|
||||
self.end_msg('lib %s not found in %s' % (lib, path.abspath()))
|
||||
self.fatal('The configuration failed')
|
||||
def match_libs(lib_names, is_static):
|
||||
libs = []
|
||||
lib_names = Utils.to_list(lib_names)
|
||||
if not lib_names:
|
||||
return libs
|
||||
t = []
|
||||
if kw.get('mt', False):
|
||||
t.append('-mt')
|
||||
if kw.get('abi', None):
|
||||
t.append('%s%s' % (is_static and '-s' or '-', kw['abi']))
|
||||
elif is_static:
|
||||
t.append('-s')
|
||||
tags_pat = t and ''.join(t) or ''
|
||||
ext = is_static and self.env.cxxstlib_PATTERN or self.env.cxxshlib_PATTERN
|
||||
ext = ext.partition('%s')[2] # remove '%s' or 'lib%s' from PATTERN
|
||||
|
||||
return path.abspath(), libs
|
||||
for lib in lib_names:
|
||||
if lib == 'python':
|
||||
# for instance, with python='27',
|
||||
# accepts '-py27', '-py2', '27' and '2'
|
||||
# but will reject '-py3', '-py26', '26' and '3'
|
||||
tags = '({0})?((-py{2})|(-py{1}(?=[^0-9]))|({2})|({1}(?=[^0-9]))|(?=[^0-9])(?!-py))'.format(tags_pat, kw['python'][0], kw['python'])
|
||||
else:
|
||||
tags = tags_pat
|
||||
# Trying libraries, from most strict match to least one
|
||||
for pattern in ['boost_%s%s%s%s%s$' % (lib, toolset_pat, tags, version, ext),
|
||||
'boost_%s%s%s%s$' % (lib, tags, version, ext),
|
||||
# Give up trying to find the right version
|
||||
'boost_%s%s%s%s$' % (lib, toolset_pat, tags, ext),
|
||||
'boost_%s%s%s$' % (lib, tags, ext),
|
||||
'boost_%s%s$' % (lib, ext),
|
||||
'boost_%s' % lib]:
|
||||
self.to_log('Trying pattern %s' % pattern)
|
||||
file = find_lib(re.compile(pattern), files)
|
||||
if file:
|
||||
libs.append(format_lib_name(file.name))
|
||||
break
|
||||
else:
|
||||
self.end_msg('lib %s not found in %s' % (lib, path.abspath()), 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
return libs
|
||||
|
||||
return path.abspath(), match_libs(kw.get('lib', None), False), match_libs(kw.get('stlib', None), True)
|
||||
|
||||
@conf
|
||||
def _check_pthread_flag(self, *k, **kw):
|
||||
'''
|
||||
Computes which flags should be added to CXXFLAGS and LINKFLAGS to compile in multi-threading mode
|
||||
|
||||
Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
|
||||
boost/thread.hpp will trigger a #error if -pthread isn't used:
|
||||
boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
|
||||
is not turned on. Please set the correct command line options for
|
||||
threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
|
||||
|
||||
Based on _BOOST_PTHREAD_FLAG(): https://github.com/tsuna/boost.m4/blob/master/build-aux/boost.m4
|
||||
'''
|
||||
|
||||
var = kw.get('uselib_store', 'BOOST')
|
||||
|
||||
self.start_msg('Checking the flags needed to use pthreads')
|
||||
|
||||
# The ordering *is* (sometimes) important. Some notes on the
|
||||
# individual items follow:
|
||||
# (none): in case threads are in libc; should be tried before -Kthread and
|
||||
# other compiler flags to prevent continual compiler warnings
|
||||
# -lpthreads: AIX (must check this before -lpthread)
|
||||
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
|
||||
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
|
||||
# -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
|
||||
# -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
|
||||
# -pthreads: Solaris/GCC
|
||||
# -mthreads: MinGW32/GCC, Lynx/GCC
|
||||
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
|
||||
# doesn't hurt to check since this sometimes defines pthreads too;
|
||||
# also defines -D_REENTRANT)
|
||||
# ... -mt is also the pthreads flag for HP/aCC
|
||||
# -lpthread: GNU Linux, etc.
|
||||
# --thread-safe: KAI C++
|
||||
if Utils.unversioned_sys_platform() == 'sunos':
|
||||
# On Solaris (at least, for some versions), libc contains stubbed
|
||||
# (non-functional) versions of the pthreads routines, so link-based
|
||||
# tests will erroneously succeed. (We need to link with -pthreads/-mt/
|
||||
# -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
|
||||
# a function called by this macro, so we could check for that, but
|
||||
# who knows whether they'll stub that too in a future libc.) So,
|
||||
# we'll just look for -pthreads and -lpthread first:
|
||||
boost_pthread_flags = ['-pthreads', '-lpthread', '-mt', '-pthread']
|
||||
else:
|
||||
boost_pthread_flags = ['', '-lpthreads', '-Kthread', '-kthread', '-llthread', '-pthread',
|
||||
'-pthreads', '-mthreads', '-lpthread', '--thread-safe', '-mt']
|
||||
|
||||
for boost_pthread_flag in boost_pthread_flags:
|
||||
try:
|
||||
self.env.stash()
|
||||
self.env['CXXFLAGS_%s' % var] += [boost_pthread_flag]
|
||||
self.env['LINKFLAGS_%s' % var] += [boost_pthread_flag]
|
||||
self.check_cxx(code=PTHREAD_CODE, msg=None, use=var, execute=False, quiet=True)
|
||||
self.end_msg(boost_pthread_flag)
|
||||
return
|
||||
except self.errors.ConfigurationError:
|
||||
self.env.revert()
|
||||
self.end_msg('none')
|
||||
|
||||
@conf
|
||||
def check_boost(self, *k, **kw):
|
||||
@@ -282,7 +396,10 @@ def check_boost(self, *k, **kw):
|
||||
if not self.env['CXX']:
|
||||
self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
|
||||
|
||||
params = {'lib': k and k[0] or kw.get('lib', None)}
|
||||
params = {
|
||||
'lib': k and k[0] or kw.get('lib', None),
|
||||
'stlib': kw.get('stlib', None)
|
||||
}
|
||||
for key, value in self.options.__dict__.items():
|
||||
if not key.startswith('boost_'):
|
||||
continue
|
||||
@@ -291,48 +408,70 @@ def check_boost(self, *k, **kw):
|
||||
|
||||
var = kw.get('uselib_store', 'BOOST')
|
||||
|
||||
self.start_msg('Checking boost includes')
|
||||
self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params)
|
||||
versions = self.boost_get_version(inc)
|
||||
self.env.BOOST_VERSION = versions[0]
|
||||
self.env.BOOST_VERSION_NUMBER = int(versions[1])
|
||||
self.end_msg("%d.%d.%d" % (int(versions[1]) / 100000,
|
||||
int(versions[1]) / 100 % 1000,
|
||||
int(versions[1]) % 100))
|
||||
if Logs.verbose:
|
||||
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var])
|
||||
if not self.env.DONE_FIND_BOOST_COMMON:
|
||||
self.find_program('dpkg-architecture', var='DPKG_ARCHITECTURE', mandatory=False)
|
||||
if self.env.DPKG_ARCHITECTURE:
|
||||
deb_host_multiarch = self.cmd_and_log([self.env.DPKG_ARCHITECTURE[0], '-qDEB_HOST_MULTIARCH'])
|
||||
BOOST_LIBS.insert(0, '/usr/lib/%s' % deb_host_multiarch.strip())
|
||||
|
||||
if not params['lib']:
|
||||
self.start_msg('Checking boost includes')
|
||||
self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params)
|
||||
versions = self.boost_get_version(inc)
|
||||
self.env.BOOST_VERSION = versions[0]
|
||||
self.env.BOOST_VERSION_NUMBER = int(versions[1])
|
||||
self.end_msg('%d.%d.%d' % (int(versions[1]) / 100000,
|
||||
int(versions[1]) / 100 % 1000,
|
||||
int(versions[1]) % 100))
|
||||
if Logs.verbose:
|
||||
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var])
|
||||
|
||||
self.env.DONE_FIND_BOOST_COMMON = True
|
||||
|
||||
if not params['lib'] and not params['stlib']:
|
||||
return
|
||||
if 'static' in kw or 'static' in params:
|
||||
Logs.warn('boost: static parameter is deprecated, use stlib instead.')
|
||||
self.start_msg('Checking boost libs')
|
||||
suffix = params.get('static', None) and 'ST' or ''
|
||||
path, libs = self.boost_get_libs(**params)
|
||||
self.env['%sLIBPATH_%s' % (suffix, var)] = [path]
|
||||
self.env['%sLIB_%s' % (suffix, var)] = libs
|
||||
self.end_msg('ok')
|
||||
path, libs, stlibs = self.boost_get_libs(**params)
|
||||
self.env['LIBPATH_%s' % var] = [path]
|
||||
self.env['STLIBPATH_%s' % var] = [path]
|
||||
self.env['LIB_%s' % var] = libs
|
||||
self.env['STLIB_%s' % var] = stlibs
|
||||
self.end_msg(' '.join(libs + stlibs))
|
||||
if Logs.verbose:
|
||||
Logs.pprint('CYAN', ' path : %s' % path)
|
||||
Logs.pprint('CYAN', ' libs : %s' % libs)
|
||||
Logs.pprint('CYAN', ' shared libs : %s' % libs)
|
||||
Logs.pprint('CYAN', ' static libs : %s' % stlibs)
|
||||
|
||||
def has_shlib(lib):
|
||||
return params['lib'] and lib in params['lib']
|
||||
def has_stlib(lib):
|
||||
return params['stlib'] and lib in params['stlib']
|
||||
def has_lib(lib):
|
||||
return has_shlib(lib) or has_stlib(lib)
|
||||
if has_lib('thread'):
|
||||
# not inside try_link to make check visible in the output
|
||||
self._check_pthread_flag(k, kw)
|
||||
|
||||
def try_link():
|
||||
if 'system' in params['lib']:
|
||||
self.check_cxx(
|
||||
fragment=BOOST_SYSTEM_CODE,
|
||||
use=var,
|
||||
execute=False,
|
||||
)
|
||||
if 'thread' in params['lib']:
|
||||
self.check_cxx(
|
||||
fragment=BOOST_THREAD_CODE,
|
||||
use=var,
|
||||
execute=False,
|
||||
)
|
||||
if has_lib('system'):
|
||||
self.check_cxx(fragment=BOOST_ERROR_CODE, use=var, execute=False)
|
||||
if has_lib('thread'):
|
||||
self.check_cxx(fragment=BOOST_THREAD_CODE, use=var, execute=False)
|
||||
if has_lib('log') or has_lib('log_setup'):
|
||||
if not has_lib('thread'):
|
||||
self.env['DEFINES_%s' % var] += ['BOOST_LOG_NO_THREADS']
|
||||
if has_shlib('log') or has_shlib('log_setup'):
|
||||
self.env['DEFINES_%s' % var] += ['BOOST_LOG_DYN_LINK']
|
||||
if has_lib('log_setup'):
|
||||
self.check_cxx(fragment=BOOST_LOG_SETUP_CODE, use=var, execute=False)
|
||||
else:
|
||||
self.check_cxx(fragment=BOOST_LOG_CODE, use=var, execute=False)
|
||||
|
||||
if params.get('linkage_autodetect', False):
|
||||
self.start_msg("Attempting to detect boost linkage flags")
|
||||
self.start_msg('Attempting to detect boost linkage flags')
|
||||
toolset = self.boost_get_toolset(kw.get('toolset', ''))
|
||||
if toolset in ['vc']:
|
||||
if toolset in ('vc',):
|
||||
# disable auto-linking feature, causing error LNK1181
|
||||
# because the code wants to be linked against
|
||||
self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB']
|
||||
@@ -352,27 +491,43 @@ def check_boost(self, *k, **kw):
|
||||
# we attempt to play with some known-to-work CXXFLAGS combinations
|
||||
for cxxflags in (['/MD', '/EHsc'], []):
|
||||
self.env.stash()
|
||||
self.env["CXXFLAGS_%s" % var] += cxxflags
|
||||
self.env['CXXFLAGS_%s' % var] += cxxflags
|
||||
try:
|
||||
try_link()
|
||||
self.end_msg("ok: winning cxxflags combination: %s" % (self.env["CXXFLAGS_%s" % var]))
|
||||
e = None
|
||||
self.end_msg('ok: winning cxxflags combination: %s' % (self.env['CXXFLAGS_%s' % var]))
|
||||
exc = None
|
||||
break
|
||||
except Errors.ConfigurationError as exc:
|
||||
except Errors.ConfigurationError as e:
|
||||
self.env.revert()
|
||||
e = exc
|
||||
exc = e
|
||||
|
||||
if e is not None:
|
||||
self.end_msg("Could not auto-detect boost linking flags combination, you may report it to boost.py author", ex=e)
|
||||
if exc is not None:
|
||||
self.end_msg('Could not auto-detect boost linking flags combination, you may report it to boost.py author', ex=exc)
|
||||
self.fatal('The configuration failed')
|
||||
else:
|
||||
self.end_msg("Boost linkage flags auto-detection not implemented (needed ?) for this toolchain")
|
||||
self.end_msg('Boost linkage flags auto-detection not implemented (needed ?) for this toolchain')
|
||||
self.fatal('The configuration failed')
|
||||
else:
|
||||
self.start_msg('Checking for boost linkage')
|
||||
try:
|
||||
try_link()
|
||||
except Errors.ConfigurationError as e:
|
||||
self.end_msg("Could not link against boost libraries using supplied options")
|
||||
self.end_msg('Could not link against boost libraries using supplied options', 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
self.end_msg('ok')
|
||||
|
||||
|
||||
@feature('cxx')
|
||||
@after_method('apply_link')
|
||||
def install_boost(self):
|
||||
if install_boost.done or not Utils.is_win32 or not self.bld.cmd.startswith('install'):
|
||||
return
|
||||
install_boost.done = True
|
||||
inst_to = getattr(self, 'install_path', '${BINDIR}')
|
||||
for lib in self.env.LIB_BOOST:
|
||||
try:
|
||||
file = self.bld.find_file(self.env.cxxshlib_PATTERN % lib, self.env.LIBPATH_BOOST)
|
||||
self.bld.install_files(inst_to, self.bld.root.find_node(file))
|
||||
except:
|
||||
continue
|
||||
install_boost.done = False
|
||||
@@ -1,17 +1,15 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
#
|
||||
# Copyright (c) 2014, Regents of the University of California
|
||||
#
|
||||
# GPL 3.0 license, see the COPYING.md file for more information
|
||||
|
||||
from waflib import TaskGen
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--with-coverage', action='store_true', default=False, dest='with_coverage',
|
||||
help='''Set compiler flags for gcc to enable code coverage information''')
|
||||
opt.add_option('--with-coverage', action='store_true', default=False,
|
||||
help='Add compiler flags to enable code coverage information')
|
||||
|
||||
def configure(conf):
|
||||
if conf.options.with_coverage:
|
||||
if not conf.options.debug:
|
||||
conf.fatal('Code coverage flags require debug mode compilation (add --debug)')
|
||||
conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'],
|
||||
linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True)
|
||||
|
||||
|
||||
@@ -1,62 +1,227 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
#
|
||||
# Copyright (c) 2014, Regents of the University of California
|
||||
#
|
||||
# GPL 3.0 license, see the COPYING.md file for more information
|
||||
|
||||
from waflib import Logs, Configure
|
||||
import platform
|
||||
from waflib import Configure, Logs, Utils
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
|
||||
help='''Compile in debugging mode without all optimizations (-O0)''')
|
||||
opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
|
||||
help='''Enable C++11 mode (experimental, may not work)''')
|
||||
opt.add_option('--debug', '--with-debug', action='store_true', default=False,
|
||||
help='Compile in debugging mode with minimal optimizations (-Og)')
|
||||
|
||||
def configure(conf):
|
||||
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
|
||||
defaultFlags = []
|
||||
conf.start_msg('Checking C++ compiler version')
|
||||
|
||||
if conf.options.use_cxx11:
|
||||
defaultFlags += ['-std=c++0x', '-std=c++11']
|
||||
cxx = conf.env.CXX_NAME # generic name of the compiler
|
||||
ccver = tuple(int(i) for i in conf.env.CC_VERSION)
|
||||
ccverstr = '.'.join(conf.env.CC_VERSION)
|
||||
errmsg = ''
|
||||
warnmsg = ''
|
||||
if cxx == 'gcc':
|
||||
if ccver < (5, 3, 0):
|
||||
errmsg = ('The version of gcc you are using is too old.\n'
|
||||
'The minimum supported gcc version is 7.4.0.')
|
||||
elif ccver < (7, 4, 0):
|
||||
warnmsg = ('Using a version of gcc older than 7.4.0 is not '
|
||||
'officially supported and may result in build failures.')
|
||||
conf.flags = GccFlags()
|
||||
elif cxx == 'clang':
|
||||
if Utils.unversioned_sys_platform() == 'darwin' and ccver < (9, 0, 0):
|
||||
errmsg = ('The version of Xcode you are using is too old.\n'
|
||||
'The minimum supported Xcode version is 9.0.')
|
||||
elif ccver < (4, 0, 0):
|
||||
errmsg = ('The version of clang you are using is too old.\n'
|
||||
'The minimum supported clang version is 4.0.')
|
||||
conf.flags = ClangFlags()
|
||||
else:
|
||||
defaultFlags += ['-std=c++03', '-Wno-variadic-macros', '-Wno-c99-extensions']
|
||||
warnmsg = '%s compiler is unsupported' % cxx
|
||||
conf.flags = CompilerFlags()
|
||||
|
||||
defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long', '-Wno-unneeded-internal-declaration']
|
||||
if errmsg:
|
||||
conf.end_msg(ccverstr, color='RED')
|
||||
conf.fatal(errmsg)
|
||||
elif warnmsg:
|
||||
conf.end_msg(ccverstr, color='YELLOW')
|
||||
Logs.warn('WARNING: ' + warnmsg)
|
||||
else:
|
||||
conf.end_msg(ccverstr)
|
||||
|
||||
conf.areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
|
||||
|
||||
# General flags are always applied (e.g., selecting C++ language standard)
|
||||
generalFlags = conf.flags.getGeneralFlags(conf)
|
||||
conf.add_supported_cxxflags(generalFlags['CXXFLAGS'])
|
||||
conf.add_supported_linkflags(generalFlags['LINKFLAGS'])
|
||||
conf.env.DEFINES += generalFlags['DEFINES']
|
||||
|
||||
@Configure.conf
|
||||
def check_compiler_flags(conf):
|
||||
# Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
|
||||
# corresponding environment variables are not set.
|
||||
# DEFINES are always applied.
|
||||
if conf.options.debug:
|
||||
conf.define('_DEBUG', 1)
|
||||
defaultFlags += ['-O0',
|
||||
'-Og', # gcc >= 4.8
|
||||
'-g3',
|
||||
'-fcolor-diagnostics', # clang
|
||||
'-fdiagnostics-color', # gcc >= 4.9
|
||||
'-Werror',
|
||||
'-Wno-error=maybe-uninitialized', # Bug #1560
|
||||
]
|
||||
if areCustomCxxflagsPresent:
|
||||
missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
|
||||
if len(missingFlags) > 0:
|
||||
Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
|
||||
% " ".join(conf.env.CXXFLAGS))
|
||||
Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
|
||||
else:
|
||||
conf.add_supported_cxxflags(defaultFlags)
|
||||
extraFlags = conf.flags.getDebugFlags(conf)
|
||||
if conf.areCustomCxxflagsPresent:
|
||||
missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS]
|
||||
if missingFlags:
|
||||
Logs.warn('Selected debug mode, but CXXFLAGS is set to a custom value "%s"'
|
||||
% ' '.join(conf.env.CXXFLAGS))
|
||||
Logs.warn('Default flags "%s" will not be used' % ' '.join(missingFlags))
|
||||
else:
|
||||
defaultFlags += ['-O2', '-g']
|
||||
if not areCustomCxxflagsPresent:
|
||||
conf.add_supported_cxxflags(defaultFlags)
|
||||
extraFlags = conf.flags.getOptimizedFlags(conf)
|
||||
|
||||
if not conf.areCustomCxxflagsPresent:
|
||||
conf.add_supported_cxxflags(extraFlags['CXXFLAGS'])
|
||||
conf.add_supported_linkflags(extraFlags['LINKFLAGS'])
|
||||
|
||||
conf.env.DEFINES += extraFlags['DEFINES']
|
||||
|
||||
@Configure.conf
|
||||
def add_supported_cxxflags(self, cxxflags):
|
||||
"""
|
||||
Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
|
||||
"""
|
||||
self.start_msg('Checking allowed flags for c++ compiler')
|
||||
if len(cxxflags) == 0:
|
||||
return
|
||||
|
||||
self.start_msg('Checking supported CXXFLAGS')
|
||||
|
||||
supportedFlags = []
|
||||
for flag in cxxflags:
|
||||
if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
|
||||
supportedFlags += [flag]
|
||||
for flags in cxxflags:
|
||||
flags = Utils.to_list(flags)
|
||||
if self.check_cxx(cxxflags=['-Werror'] + flags, mandatory=False):
|
||||
supportedFlags += flags
|
||||
|
||||
self.end_msg(' '.join(supportedFlags))
|
||||
self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
|
||||
self.env.prepend_value('CXXFLAGS', supportedFlags)
|
||||
|
||||
@Configure.conf
|
||||
def add_supported_linkflags(self, linkflags):
|
||||
"""
|
||||
Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
|
||||
"""
|
||||
if len(linkflags) == 0:
|
||||
return
|
||||
|
||||
self.start_msg('Checking supported LINKFLAGS')
|
||||
|
||||
supportedFlags = []
|
||||
for flags in linkflags:
|
||||
flags = Utils.to_list(flags)
|
||||
if self.check_cxx(linkflags=['-Werror'] + flags, mandatory=False):
|
||||
supportedFlags += flags
|
||||
|
||||
self.end_msg(' '.join(supportedFlags))
|
||||
self.env.prepend_value('LINKFLAGS', supportedFlags)
|
||||
|
||||
|
||||
class CompilerFlags(object):
|
||||
def getCompilerVersion(self, conf):
|
||||
return tuple(int(i) for i in conf.env.CC_VERSION)
|
||||
|
||||
def getGeneralFlags(self, conf):
|
||||
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
|
||||
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
|
||||
|
||||
def getDebugFlags(self, conf):
|
||||
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
|
||||
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['_DEBUG']}
|
||||
|
||||
def getOptimizedFlags(self, conf):
|
||||
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
|
||||
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']}
|
||||
|
||||
class GccBasicFlags(CompilerFlags):
|
||||
"""
|
||||
This class defines basic flags that work for both gcc and clang compilers
|
||||
"""
|
||||
def getGeneralFlags(self, conf):
|
||||
flags = super(GccBasicFlags, self).getGeneralFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-std=c++14']
|
||||
if Utils.unversioned_sys_platform() == 'linux':
|
||||
flags['LINKFLAGS'] += ['-fuse-ld=gold']
|
||||
elif Utils.unversioned_sys_platform() == 'freebsd':
|
||||
flags['LINKFLAGS'] += ['-fuse-ld=lld']
|
||||
return flags
|
||||
|
||||
def getDebugFlags(self, conf):
|
||||
flags = super(GccBasicFlags, self).getDebugFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-Og',
|
||||
'-g3',
|
||||
'-pedantic',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-Werror',
|
||||
'-Wcatch-value=2',
|
||||
'-Wextra-semi',
|
||||
'-Wnon-virtual-dtor',
|
||||
'-Wno-error=deprecated-declarations', # Bug #3795
|
||||
'-Wno-error=maybe-uninitialized', # Bug #1615
|
||||
'-Wno-unused-parameter',
|
||||
]
|
||||
flags['LINKFLAGS'] += ['-Wl,-O1']
|
||||
return flags
|
||||
|
||||
def getOptimizedFlags(self, conf):
|
||||
flags = super(GccBasicFlags, self).getOptimizedFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-O2',
|
||||
'-g',
|
||||
'-pedantic',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-Wcatch-value=2',
|
||||
'-Wextra-semi',
|
||||
'-Wnon-virtual-dtor',
|
||||
'-Wno-unused-parameter',
|
||||
]
|
||||
flags['LINKFLAGS'] += ['-Wl,-O1']
|
||||
return flags
|
||||
|
||||
class GccFlags(GccBasicFlags):
|
||||
def getDebugFlags(self, conf):
|
||||
flags = super(GccFlags, self).getDebugFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-fdiagnostics-color',
|
||||
'-Wredundant-tags',
|
||||
]
|
||||
if platform.machine() == 'armv7l' and self.getCompilerVersion(conf) >= (7, 1, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106
|
||||
return flags
|
||||
|
||||
def getOptimizedFlags(self, conf):
|
||||
flags = super(GccFlags, self).getOptimizedFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-fdiagnostics-color',
|
||||
'-Wredundant-tags',
|
||||
]
|
||||
if platform.machine() == 'armv7l' and self.getCompilerVersion(conf) >= (7, 1, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106
|
||||
return flags
|
||||
|
||||
class ClangFlags(GccBasicFlags):
|
||||
def getGeneralFlags(self, conf):
|
||||
flags = super(ClangFlags, self).getGeneralFlags(conf)
|
||||
if Utils.unversioned_sys_platform() == 'darwin':
|
||||
# Bug #4296
|
||||
flags['CXXFLAGS'] += [['-isystem', '/usr/local/include'], # for Homebrew
|
||||
['-isystem', '/opt/local/include']] # for MacPorts
|
||||
elif Utils.unversioned_sys_platform() == 'freebsd':
|
||||
# Bug #4790
|
||||
flags['CXXFLAGS'] += [['-isystem', '/usr/local/include']]
|
||||
return flags
|
||||
|
||||
def getDebugFlags(self, conf):
|
||||
flags = super(ClangFlags, self).getDebugFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-fcolor-diagnostics',
|
||||
'-Wundefined-func-template',
|
||||
'-Wno-unused-local-typedef', # Bugs #2657 and #3209
|
||||
]
|
||||
if self.getCompilerVersion(conf) < (6, 0, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-missing-braces'] # Bug #4721
|
||||
return flags
|
||||
|
||||
def getOptimizedFlags(self, conf):
|
||||
flags = super(ClangFlags, self).getOptimizedFlags(conf)
|
||||
flags['CXXFLAGS'] += ['-fcolor-diagnostics',
|
||||
'-Wundefined-func-template',
|
||||
'-Wno-unused-local-typedef', # Bugs #2657 and #3209
|
||||
]
|
||||
if self.getCompilerVersion(conf) < (6, 0, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-missing-braces'] # Bug #4721
|
||||
return flags
|
||||
@@ -4,10 +4,10 @@ from waflib import Options, Logs
|
||||
from waflib.Configure import conf
|
||||
|
||||
def addDependencyOptions(self, opt, name, extraHelp=''):
|
||||
opt.add_option('--with-%s' % name, type='string', default=None,
|
||||
dest='with_%s' % name,
|
||||
opt.add_option('--with-%s' % name, metavar='PATH',
|
||||
help='Path to %s, e.g., /usr/local %s' % (name, extraHelp))
|
||||
setattr(Options.OptionsContext, "addDependencyOptions", addDependencyOptions)
|
||||
|
||||
setattr(Options.OptionsContext, 'addDependencyOptions', addDependencyOptions)
|
||||
|
||||
@conf
|
||||
def checkDependency(self, name, **kw):
|
||||
@@ -18,8 +18,8 @@ def checkDependency(self, name, **kw):
|
||||
kw['mandatory'] = kw.get('mandatory', True)
|
||||
|
||||
if root:
|
||||
isOk = self.check_cxx(includes="%s/include" % root,
|
||||
libpath="%s/lib" % root,
|
||||
isOk = self.check_cxx(includes='%s/include' % root,
|
||||
libpath='%s/lib' % root,
|
||||
**kw)
|
||||
else:
|
||||
isOk = self.check_cxx(**kw)
|
||||
|
||||
@@ -85,7 +85,7 @@ class doxygen(Task.Task):
|
||||
|
||||
# Override with any parameters passed to the task generator
|
||||
if getattr(self.generator, 'pars', None):
|
||||
for k, v in self.generator.pars.iteritems():
|
||||
for k, v in self.generator.pars.items():
|
||||
self.pars[k] = v
|
||||
|
||||
self.doxy_inputs = getattr(self, 'doxy_inputs', [])
|
||||
|
||||
+5
-5
@@ -52,7 +52,7 @@ Note that precompiled header must have multiple inclusion guards. If the guards
|
||||
"""
|
||||
|
||||
import os
|
||||
from waflib import Task, TaskGen, Logs, Utils
|
||||
from waflib import Task, TaskGen, Utils
|
||||
from waflib.Tools import c_preproc, cxx
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ def apply_pch(self):
|
||||
|
||||
if getattr(self, 'name', None):
|
||||
try:
|
||||
task = self.bld.pch_tasks[self.name]
|
||||
self.bld.fatal("Duplicated 'pch' task with name %r" % self.name)
|
||||
task = self.bld.pch_tasks["%s.%s" % (self.name, self.idx)]
|
||||
self.bld.fatal("Duplicated 'pch' task with name %r" % "%s.%s" % (self.name, self.idx))
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@@ -104,7 +104,7 @@ def apply_pch(self):
|
||||
|
||||
self.pch_task = task
|
||||
if getattr(self, 'name', None):
|
||||
self.bld.pch_tasks[self.name] = task
|
||||
self.bld.pch_tasks["%s.%s" % (self.name, self.idx)] = task
|
||||
|
||||
@TaskGen.feature('cxx')
|
||||
@TaskGen.after_method('process_source', 'propagate_uselib_vars')
|
||||
@@ -129,7 +129,7 @@ def add_pch(self):
|
||||
x.env.append_value('CXXFLAGS', self.env['CXXPCH_F'] + [pch.target])
|
||||
|
||||
class gchx(Task.Task):
|
||||
run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CPPFLAGS} ${CXXPCH_FLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXXPCH_F:SRC} ${CXX_SRC_F}${SRC[0].abspath()} ${CXX_TGT_F}${TGT[0].abspath()}'
|
||||
run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CXXPCH_FLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXXPCH_F:SRC} ${CXX_SRC_F}${SRC[0].abspath()} ${CXX_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}'
|
||||
scan = c_preproc.scan
|
||||
color = 'BLUE'
|
||||
ext_out=['.h']
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--with-sanitizer', action='store', default='', dest='sanitizers',
|
||||
help='Comma-separated list of compiler sanitizers to enable [default=none]')
|
||||
|
||||
def configure(conf):
|
||||
for san in conf.options.sanitizers.split(','):
|
||||
if not san:
|
||||
continue
|
||||
|
||||
sanflag = '-fsanitize=%s' % san
|
||||
conf.start_msg('Checking if compiler supports %s' % sanflag)
|
||||
|
||||
if conf.check_cxx(cxxflags=['-Werror', sanflag, '-fno-omit-frame-pointer'],
|
||||
linkflags=[sanflag], mandatory=False):
|
||||
conf.end_msg('yes')
|
||||
conf.env.append_unique('CXXFLAGS', [sanflag, '-fno-omit-frame-pointer'])
|
||||
conf.env.append_unique('LINKFLAGS', [sanflag])
|
||||
else:
|
||||
conf.end_msg('no', color='RED')
|
||||
conf.fatal('%s sanitizer is not supported by the current compiler' % san)
|
||||
@@ -44,28 +44,28 @@ def apply_sphinx(self):
|
||||
task.inputs.append(conf)
|
||||
|
||||
confdir = conf.parent.abspath()
|
||||
buildername = getattr(self, "builder", "html")
|
||||
srcdir = getattr(self, "srcdir", confdir)
|
||||
outdir = self.path.find_or_declare(getattr(self, "outdir", buildername)).get_bld()
|
||||
doctreedir = getattr(self, "doctreedir", os.path.join(outdir.abspath(), ".doctrees"))
|
||||
buildername = getattr(self, 'builder', 'html')
|
||||
srcdir = getattr(self, 'srcdir', confdir)
|
||||
outdir = self.path.find_or_declare(getattr(self, 'outdir', buildername)).get_bld()
|
||||
doctreedir = getattr(self, 'doctreedir', os.path.join(outdir.abspath(), '.doctrees'))
|
||||
|
||||
task.env['BUILDERNAME'] = buildername
|
||||
task.env['SRCDIR'] = srcdir
|
||||
task.env['DOCTREEDIR'] = doctreedir
|
||||
task.env['OUTDIR'] = outdir.abspath()
|
||||
task.env['VERSION'] = "version=%s" % self.VERSION
|
||||
task.env['RELEASE'] = "release=%s" % self.VERSION
|
||||
task.env['VERSION'] = 'version=%s' % self.version
|
||||
task.env['RELEASE'] = 'release=%s' % getattr(self, 'release', self.version)
|
||||
|
||||
import imp
|
||||
confData = imp.load_source('sphinx_conf', conf.abspath())
|
||||
|
||||
if buildername == "man":
|
||||
if buildername == 'man':
|
||||
for i in confData.man_pages:
|
||||
target = outdir.find_or_declare('%s.%d' % (i[1], i[4]))
|
||||
task.outputs.append(target)
|
||||
|
||||
if self.install_path:
|
||||
self.bld.install_files("%s/man%d/" % (self.install_path, i[4]), target)
|
||||
self.bld.install_files('%s/man%d/' % (self.install_path, i[4]), target)
|
||||
else:
|
||||
task.outputs.append(outdir)
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
#
|
||||
# Copyright (c) 2014, Regents of the University of California
|
||||
# Copyright (c) 2014-2019, Regents of the University of California
|
||||
#
|
||||
# GPL 3.0 license, see the COPYING.md file for more information
|
||||
|
||||
from waflib import Options
|
||||
|
||||
BOOST_ASIO_HAS_LOCAL_SOCKETS_CHECK = '''
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/local/basic_endpoint.hpp>
|
||||
#ifndef BOOST_ASIO_HAS_LOCAL_SOCKETS
|
||||
#error "Unix sockets are not available on this platform"
|
||||
#endif
|
||||
@@ -15,8 +15,9 @@ BOOST_ASIO_HAS_LOCAL_SOCKETS_CHECK = '''
|
||||
|
||||
def addUnixOptions(self, opt):
|
||||
opt.add_option('--force-unix-socket', action='store_true', default=False,
|
||||
dest='force_unix_socket', help='''Forcefully enable Unix sockets support''')
|
||||
setattr(Options.OptionsContext, "addUnixOptions", addUnixOptions)
|
||||
help='Forcefully enable Unix sockets support')
|
||||
|
||||
setattr(Options.OptionsContext, 'addUnixOptions', addUnixOptions)
|
||||
|
||||
def configure(conf):
|
||||
def boost_asio_has_local_sockets():
|
||||
@@ -24,6 +25,5 @@ def configure(conf):
|
||||
fragment=BOOST_ASIO_HAS_LOCAL_SOCKETS_CHECK,
|
||||
features='cxx', use='BOOST', mandatory=False)
|
||||
|
||||
if conf.options.force_unix_socket or boost_asio_has_local_sockets():
|
||||
conf.define('HAVE_UNIX_SOCKETS', 1)
|
||||
conf.env['HAVE_UNIX_SOCKETS'] = True
|
||||
conf.env.HAVE_UNIX_SOCKETS = conf.options.force_unix_socket or boost_asio_has_local_sockets()
|
||||
conf.define_cond('HAVE_UNIX_SOCKETS', conf.env.HAVE_UNIX_SOCKETS)
|
||||
+26
-32
@@ -1,24 +1,22 @@
|
||||
# encoding: utf-8
|
||||
|
||||
from waflib import Options, Logs, Errors
|
||||
from waflib.Configure import conf
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
from waflib import Options, Logs, Errors, Configure
|
||||
import re
|
||||
|
||||
def addWebsocketOptions(self, opt):
|
||||
opt.add_option('--without-websocket', action='store_false', default=True,
|
||||
dest='with_websocket',
|
||||
help='Disable WebSocket face support')
|
||||
setattr(Options.OptionsContext, "addWebsocketOptions", addWebsocketOptions)
|
||||
dest='with_websocket', help='Disable WebSocket face support')
|
||||
|
||||
@conf
|
||||
setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions)
|
||||
|
||||
@Configure.conf
|
||||
def checkWebsocket(self, **kw):
|
||||
if not self.options.with_websocket:
|
||||
return
|
||||
|
||||
isMandatory = kw.get('mandatory', True)
|
||||
|
||||
self.start_msg('Checking for WebSocket includes')
|
||||
self.start_msg('Checking for WebSocket++ includes')
|
||||
|
||||
try:
|
||||
websocketDir = self.path.find_dir('websocketpp/websocketpp')
|
||||
@@ -27,53 +25,49 @@ def checkWebsocket(self, **kw):
|
||||
|
||||
versionFile = websocketDir.find_node('version.hpp')
|
||||
if not websocketDir:
|
||||
raise Errors.WafError('Corrupted: WebSocket version file not found')
|
||||
raise Errors.WafError('WebSocket++ version file not found')
|
||||
|
||||
try:
|
||||
txt = versionFile.read()
|
||||
except (OSError, IOError):
|
||||
raise Errors.WafError('Corrupted: cannot read WebSocket version file')
|
||||
|
||||
# Looking for the following:
|
||||
# static int const major_version = 0;
|
||||
# static int const minor_version = 3;
|
||||
# static int const patch_version = 0;
|
||||
raise Errors.WafError('Cannot read WebSocket++ version file')
|
||||
|
||||
version = [None, None, None]
|
||||
|
||||
# Looking for the following:
|
||||
# static int const major_version = 0;
|
||||
# static int const minor_version = 7;
|
||||
# static int const patch_version = 0;
|
||||
majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M)
|
||||
version[0] = majorVersion.search(txt)
|
||||
|
||||
minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M)
|
||||
version[1] = minorVersion.search(txt)
|
||||
|
||||
patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M)
|
||||
version[2] = patchVersion.search(txt)
|
||||
|
||||
if not version[0] or not version[1] or not version[2]:
|
||||
raise Errors.WafError('Corrupted: cannot detect websocket version')
|
||||
raise Errors.WafError('Cannot detect WebSocket++ version')
|
||||
|
||||
self.env['WEBSOCKET_VERSION'] = [i.group(1) for i in version]
|
||||
self.env.WEBSOCKET_VERSION = [i.group(1) for i in version]
|
||||
|
||||
# todo: version checking, if necessary
|
||||
|
||||
self.end_msg('.'.join(self.env['WEBSOCKET_VERSION']))
|
||||
self.end_msg('.'.join(self.env.WEBSOCKET_VERSION))
|
||||
|
||||
|
||||
self.env['INCLUDES_WEBSOCKET'] = websocketDir.parent.abspath()
|
||||
self.env['HAVE_WEBSOCKET'] = True
|
||||
self.env.append_unique('DEFINES', ['_WEBSOCKETPP_CPP11_STL_'])
|
||||
self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
|
||||
self.env.HAVE_WEBSOCKET = True
|
||||
self.define('HAVE_WEBSOCKET', 1)
|
||||
|
||||
except Errors.WafError as error:
|
||||
if isMandatory:
|
||||
self.end_msg(str(error), color='RED')
|
||||
Logs.warn('If you are using git NFD repository, checkout websocketpp submodule: ')
|
||||
Logs.warn(' git submodule init && git submodule update')
|
||||
Logs.warn('Otherwise, manually download and extract websocketpp library:')
|
||||
Logs.warn(' mkdir websocketpp')
|
||||
Logs.warn(' curl -L https://github.com/zaphoyd/websocketpp/tarball/65cc3765a892ee5928160ba478178e747233aa6c > websocket.tar.gz')
|
||||
Logs.warn(' tar zxf websocket.tar.gz -C websocketpp/ --strip 1')
|
||||
Logs.warn('If you are using NFD from the git repository, checkout the websocketpp submodule: ')
|
||||
Logs.warn(' git submodule update --init')
|
||||
Logs.warn('Otherwise, manually download and extract the websocketpp library:')
|
||||
Logs.warn(' mkdir -p websocketpp')
|
||||
Logs.warn(' curl -L https://github.com/cawka/websocketpp/archive/0.8.1-hotfix.tar.gz > websocketpp.tar.gz')
|
||||
Logs.warn(' tar xf websocketpp.tar.gz -C websocketpp/ --strip 1')
|
||||
Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket')
|
||||
self.fatal("The configuration failed")
|
||||
self.fatal('WebSocket++ not found')
|
||||
else:
|
||||
self.end_msg(str(error))
|
||||
+58
-61
@@ -1,65 +1,62 @@
|
||||
NFD Authors
|
||||
===========
|
||||
# NFD Authors
|
||||
|
||||
NFD is an open source project started in late 2013, includes contributions
|
||||
from many people around the world, and open for new contributions from new
|
||||
volunteers.
|
||||
The following lists maintainers, primary developers, and all much-appreciated contributors to NFD in alphabetic order.
|
||||
The specific contributions of individual authors can be obtained from the git history of the [official NFD repository](https://github.com/named-data/NFD).
|
||||
If you would like to become a contributor to the official repository, please follow the recommendations in https://github.com/named-data/.github/blob/master/CONTRIBUTING.md.
|
||||
|
||||
* Jerald Paul Abraham <https://cs.arizona.edu/~jeraldabraham>
|
||||
* ***(Maintainer)*** Alexander Afanasyev <https://users.cs.fiu.edu/~afanasyev>
|
||||
* Syed Obai Amin <http://obaidamin.weebly.com>
|
||||
* Hila Ben Abraham <https://sites.wustl.edu/hbabraham>
|
||||
* Muktadir R Chowdhury <https://github.com/alvyC>
|
||||
* Tai-Lin Chu <https://www.linkedin.com/pub/tai-lin-chu/55/5b2/669>
|
||||
* Stephanie DiBenedetto
|
||||
* Saurab Dulal <https://dulalsaurab.github.io>
|
||||
* Chengyu Fan <https://github.com/chengyu>
|
||||
* Ashlesh Gawande <https://www.linkedin.com/in/agawande>
|
||||
* Chavoosh Ghasemi <https://chavoosh.github.io>
|
||||
* Mathias Gibbens <https://calenhad.com>
|
||||
* Nick Gordon <https://github.com/gorgonical>
|
||||
* Giulio Grassi <https://www.lip6.fr/actualite/personnes-fiche.php?ident=D1461>
|
||||
* Yi Huang <https://www.linkedin.com/in/yihuang1991>
|
||||
* Jongseok Lee <https://github.com/imwhiz>
|
||||
* Spencer Lee <https://www.linkedin.com/in/spenlee>
|
||||
* Vince Lehman <http://vslehman.com>
|
||||
* Yanbiao Li <https://www.linkedin.com/pub/yanbiao-li/24/7a1/4ba>
|
||||
* Teng Liang <https://cs.arizona.edu/~philoliang>
|
||||
* Weiwei Liu <https://www.linkedin.com/in/weiweiliu10>
|
||||
* Spyridon Mastorakis <https://sites.google.com/site/spyridonmastorakis>
|
||||
* Ernest McCracken <https://github.com/emccrckn>
|
||||
* Ilya Moiseenko <https://www.linkedin.com/in/ilya-moiseenko-52884317>
|
||||
* Eric Newberry <https://ericnewberry.com>
|
||||
* Ju Pan <https://cs-jupan.com>
|
||||
* João Pereira <http://website.jpereira.co.uk>
|
||||
* Davide Pesavento <https://github.com/Pesa>
|
||||
* Felix Rabe <https://twitter.com/felixrabe>
|
||||
* Md Ashiqur Rahman <https://ashiqrahman.com>
|
||||
* Matteo Sammarco <https://www.linkedin.com/in/matteo-sammarco-9b544530>
|
||||
* Niv Sardi <http://core.evilgiggle.com>
|
||||
* Klaus Schneider <https://cs.arizona.edu/~klaus>
|
||||
* Wentao Shang <https://irl.cs.ucla.edu/~wentao>
|
||||
* Susmit Shannigrahi <https://susm.it>
|
||||
* ***(Former Maintainer)*** Junxiao Shi <https://cs.arizona.edu/~shijunxiao>
|
||||
* Yukai Tu <https://irl.cs.ucla.edu/~yukai>
|
||||
* Sebastian Wölke <https://inet.haw-hamburg.de/members/alumni-1/sebastian-woelke>
|
||||
* Yumin Xia <https://github.com/Stumble>
|
||||
* Yingdi Yu <https://irl.cs.ucla.edu/~yingdi>
|
||||
* Haowei Yuan <http://www.cse.wustl.edu/~yuanh>
|
||||
* Hang Zhang <http://netlab.bit.edu.cn/z_hang>
|
||||
* Minsheng Zhang <https://github.com/mzhang4>
|
||||
* Zhiyi Zhang <https://zhiyi-zhang.com>
|
||||
* Qi Zhao <https://web.cs.ucla.edu/~qi.zhao>
|
||||
* Wenkai Zheng <https://github.com/wenkaizheng>
|
||||
|
||||
## Project technical leads:
|
||||
## Technical Advisors
|
||||
|
||||
* Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
|
||||
* Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/>
|
||||
|
||||
|
||||
## Technical advisors:
|
||||
|
||||
* Beichuan Zhang <http://www.cs.arizona.edu/~bzhang/>
|
||||
* Lixia Zhang <http://www.cs.ucla.edu/~lixia/>
|
||||
|
||||
|
||||
## All project authors and contributors and their affiliations:
|
||||
|
||||
* University of California, Los Angeles
|
||||
|
||||
* Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
|
||||
* Ilya Moiseenko <http://ilyamoiseenko.com/>
|
||||
* Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/web/index.html>
|
||||
* Wentao Shang <http://irl.cs.ucla.edu/~wentao/>
|
||||
* Lixia Zhang <http://www.cs.ucla.edu/~lixia/>
|
||||
|
||||
* The University of Arizona
|
||||
|
||||
* Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/>
|
||||
* Yi Huang <ethanhuang1991@gmail.com>
|
||||
* Jerald Paul Abraham <http://www.cs.arizona.edu/people/jeraldabraham/>
|
||||
* Beichuan Zhang <http://www.cs.arizona.edu/~bzhang/>
|
||||
|
||||
* Colorado State University
|
||||
|
||||
* Steve DiBenedetto <http://www.cs.colostate.edu/~dibenede/>
|
||||
* Chengyu Fan <chengyu@cs.colostate.edu>
|
||||
* Christos Papadopoulos <http://www.cs.colostate.edu/~christos/>
|
||||
|
||||
* University Pierre & Marie Curie, Sorbonne University
|
||||
|
||||
* Davide Pesavento <http://www.lip6.fr/actualite/personnes-fiche.php?ident=D1469>
|
||||
* Giulio Grassi <http://www.lip6.fr/actualite/personnes-fiche.php?ident=D1461>
|
||||
* Giovanni Pau <http://www.cs.ucla.edu/~gpau/Giovanni_Paus_Home_Page/Home.html>
|
||||
|
||||
* Beijing Institute of Technology
|
||||
|
||||
* Hang Zhang <http://netlab.bit.edu.cn/z_hang>
|
||||
* Tian Song <http://cs.bit.edu.cn/songtian>
|
||||
|
||||
* Washington University in St. Louis
|
||||
|
||||
* Haowei Yuan <http://www.cse.wustl.edu/~yuanh/>
|
||||
* Hila Ben Abraham <http://research.engineering.wustl.edu/~abrahamh/>
|
||||
* Patrick Crowley <http://www.arl.wustl.edu/~pcrowley/>
|
||||
|
||||
* The University of Memphis
|
||||
|
||||
* Syed Obaid Amin <http://obaidamin.weebly.com/>
|
||||
* Vince Lehman <vslehman@memphis.edu>
|
||||
* Lan Wang <http://www.cs.memphis.edu/~lanwang/>
|
||||
* Patrick Crowley <https://www.arl.wustl.edu/~pcrowley>
|
||||
* Christos Papadopoulos <https://www.cs.colostate.edu/~christos>
|
||||
* Giovanni Pau <http://www.cs.ucla.edu/~gpau/Giovanni_Paus_Home_Page/Home.html>
|
||||
* Tian Song <http://www.bit-netlab.org/songtian>
|
||||
* Lan Wang <http://www.cs.memphis.edu/~lanwang>
|
||||
* Beichuan Zhang <https://cs.arizona.edu/~bzhang>
|
||||
* Lixia Zhang <https://cs.ucla.edu/~lixia>
|
||||
@@ -0,0 +1,17 @@
|
||||
cff-version: 1.2.0
|
||||
message: If you use NFD in your research, please cite it as below.
|
||||
license: GPL-3.0-or-later
|
||||
repository-code: "https://github.com/named-data/NFD"
|
||||
title: Named Data Networking Forwarding Daemon
|
||||
url: "https://named-data.net/doc/NFD/"
|
||||
preferred-citation:
|
||||
authors:
|
||||
- name: Named Data Networking Project Team
|
||||
date-published: "2021-07-30"
|
||||
journal: NDN Technical Report NDN-0021
|
||||
month: 7
|
||||
title: NFD Developer's Guide
|
||||
type: generic
|
||||
url: "https://named-data.net/publications/techreports/ndn-0021-11-nfd-guide/"
|
||||
version: 11
|
||||
year: 2021
|
||||
+383
-356
File diff suppressed because it is too large.
Load diff
@@ -1,5 +0,0 @@
|
||||
NFD Installation Instructions
|
||||
=============================
|
||||
|
||||
See [`docs/install.rst`](https://github.com/named-data/NFD/blob/master/docs/INSTALL.rst)
|
||||
for detailed NFD installation instructions.
|
||||
+32
-33
@@ -1,20 +1,23 @@
|
||||
Notes for NFD developers
|
||||
========================
|
||||
# Notes for NFD developers
|
||||
|
||||
Requirements
|
||||
------------
|
||||
If you are new to the NDN software community, please read the
|
||||
[Contributor's Guide](https://github.com/named-data/.github/blob/master/CONTRIBUTING.md).
|
||||
|
||||
## Code style
|
||||
|
||||
NFD code is subject to [NFD code style](https://redmine.named-data.net/projects/nfd/wiki/CodeStyle).
|
||||
|
||||
## Licensing
|
||||
|
||||
Contributions to NFD must be licensed under the GPL 3.0 or compatible license. If you
|
||||
are choosing GPL 3.0, please use the following license boilerplate in all `.hpp` and
|
||||
`.cpp` files:
|
||||
|
||||
Include the following license boilerplate into all `.hpp` and `.cpp` files:
|
||||
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) [Year(s)], [Copyright Holder(s)].
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -29,44 +32,41 @@ Include the following license boilerplate into all `.hpp` and `.cpp` files:
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
////// [optional part] //////
|
||||
*
|
||||
* \author Author's Name <email@domain>
|
||||
* \author Other Author's Name <another.email@domain>
|
||||
////// [end of optional part] //////
|
||||
*/
|
||||
|
||||
Recommendations
|
||||
---------------
|
||||
If you are affiliated to an NSF-supported NDN project institution, please use the [NDN Team License
|
||||
Boilerplate](https://redmine.named-data.net/projects/nfd/wiki/NDN_Team_License_Boilerplate_(NFD)).
|
||||
|
||||
NFD code is subject to NFD [code style](http://redmine.named-data.net/projects/nfd/wiki/CodeStyle).
|
||||
## Logging
|
||||
|
||||
Fine-grained per-module logging can be configured via the `NDN_LOG` environment variable.
|
||||
This is especially useful when running unit tests or tools such as `nfdc` that do not
|
||||
have a configuration file. See `ndn-log(7)` manual page for syntax and examples.
|
||||
|
||||
Running unit-tests
|
||||
------------------
|
||||
## Unit tests
|
||||
|
||||
To run unit tests, NFD needs to be configured and build with unit test support:
|
||||
|
||||
./waf configure --with-tests
|
||||
./waf configure --with-tests # --debug is also strongly recommended while developing
|
||||
./waf
|
||||
|
||||
The simplest way to run tests, is just to run the compiled binary without any parameters:
|
||||
The simplest way to run the tests is to launch the compiled binary without any parameters:
|
||||
|
||||
# Run core tests
|
||||
./build/unit-tests-core
|
||||
|
||||
# Run NFD daemon tests
|
||||
# Run NFD daemon tests
|
||||
./build/unit-tests-daemon
|
||||
|
||||
# Run NFD RIB management tests
|
||||
./build/unit-tests-rib
|
||||
|
||||
However, [Boost.Test framework](http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/)
|
||||
The [Boost.Test framework](https://www.boost.org/doc/libs/1_65_1/libs/test/doc/html/index.html)
|
||||
is very flexible and allows a number of run-time customization of what tests should be run.
|
||||
For example, it is possible to choose to run only a specific test suite, only a specific
|
||||
test case within a suite, or specific test cases within specific test suites:
|
||||
|
||||
# Run only TCP Face test suite of NFD daemon tests (see tests/daemon/face/tcp.cpp)
|
||||
# Run only the TCP Face test suite of NFD daemon tests
|
||||
./build/unit-tests-daemon -t FaceTcp
|
||||
|
||||
# Run only test case EndToEnd4 from the same test suite
|
||||
@@ -77,8 +77,8 @@ test case within a suite, or specific test cases within specific test suites:
|
||||
|
||||
By default, Boost.Test framework will produce verbose output only when a test case fails.
|
||||
If it is desired to see verbose output (result of each test assertion), add `-l all`
|
||||
option to `./build/unit-tests` command. To see test progress, you can use `-l test_suite`
|
||||
or `-p` to show progress bar:
|
||||
option to `./build/unit-tests` command. To see test progress, you can use `-l test_suite`,
|
||||
or `-p` to show a progress bar:
|
||||
|
||||
# Show report all log messages including the passed test notification
|
||||
./build/unit-tests-daemon -l all
|
||||
@@ -92,7 +92,6 @@ or `-p` to show progress bar:
|
||||
# Show progress bar
|
||||
./build/unit-tests-core -p
|
||||
|
||||
There are many more command line options available, information about
|
||||
which can be obtained either from the command line using `--help`
|
||||
switch, or online on [Boost.Test library](http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/)
|
||||
website.
|
||||
There are many more command line options available, information about which can be obtained
|
||||
either from the command line using the `--help` switch, or online on the
|
||||
[Boost.Test website](https://www.boost.org/doc/libs/1_65_1/libs/test/doc/html/index.html).
|
||||
@@ -1,33 +1,16 @@
|
||||
NFD - Named Data Networking Forwarding Daemon
|
||||
=============================================
|
||||
# NFD - Named Data Networking Forwarding Daemon
|
||||
|
||||
For complete documentation, including step-by-step installation instructions and
|
||||
tutorials, please visit the [NFD homepage](http://named-data.net/doc/NFD/).
|
||||
[](https://github.com/named-data/NFD/actions/workflows/ci.yml)
|
||||
[](https://github.com/named-data/NFD/actions/workflows/docs.yml)
|
||||

|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
NFD is a network forwarder that implements and evolves together with the Named Data
|
||||
Networking (NDN) [protocol](http://named-data.net/doc/ndn-tlv/). After the initial
|
||||
release, NFD will become a core component of the
|
||||
[NDN Platform](http://named-data.net/codebase/platform/) and will follow the same release
|
||||
cycle.
|
||||
|
||||
NFD is an open and free software package licensed under GPL 3.0 license and is the
|
||||
centerpiece of our committement to making NDN's core technology open and free to all
|
||||
Internet users and developers. For more information about the licensing details and
|
||||
limitation, refer to
|
||||
[`COPYING.md`](https://github.com/named-data/NFD/blob/master/COPYING.md).
|
||||
|
||||
NFD is developed by a community effort. Although the first release was mostly done by the
|
||||
members of [NSF-sponsored NDN project team](http://named-data.net/project/participants/),
|
||||
it already contains significant contributions from people outside the project team (for
|
||||
more details, refer to
|
||||
[`AUTHORS.md`](https://github.com/named-data/NFD/blob/master/AUTHORS.md)). We strongly
|
||||
encourage participation from all interested parties, since broader community support is
|
||||
key for NDN to succeed as a new Internet architecture. Bug reports and feedback are
|
||||
highly appreciated and can be made through
|
||||
[Redmine site](http://redmine.named-data.net/projects/nfd) and the
|
||||
[ndn-interest mailing list](http://www.lists.cs.ucla.edu/mailman/listinfo/ndn-interest).
|
||||
Networking (NDN) [protocol](https://named-data.net/doc/NDN-packet-spec/current/).
|
||||
Since the initial public release in 2014, NFD has been a core component of the
|
||||
[NDN Platform](https://named-data.net/codebase/platform/).
|
||||
|
||||
The main design goal of NFD is to support diverse experimentation of NDN technology. The
|
||||
design emphasizes *modularity* and *extensibility* to allow easy experiments with new
|
||||
@@ -40,3 +23,34 @@ NFD will keep evolving in three aspects: improvement of the modularity framework
|
||||
up with the NDN protocol spec, and addition of other new features. We hope to keep the
|
||||
modular framework stable and lean, allowing researchers to implement and experiment with
|
||||
various features, some of which may eventually work into the protocol spec.
|
||||
|
||||
## Documentation
|
||||
|
||||
See [`docs/INSTALL.rst`](docs/INSTALL.rst) for compilation and installation instructions.
|
||||
|
||||
Extensive documentation is available on NFD's [homepage](https://named-data.net/doc/NFD/).
|
||||
|
||||
## Reporting bugs
|
||||
|
||||
Bug reports and feedback are highly appreciated and can be submitted through the
|
||||
[NFD issue tracker](https://redmine.named-data.net/projects/nfd/issues) or the
|
||||
[ndn-interest mailing list](http://www.lists.cs.ucla.edu/mailman/listinfo/ndn-interest).
|
||||
|
||||
## Contributing
|
||||
|
||||
NFD is developed by a community effort. Although the first release was mostly done by the
|
||||
members of [NSF-sponsored NDN project team](https://named-data.net/project/participants/),
|
||||
it already contains significant contributions from people outside the project team (see
|
||||
[`AUTHORS.md`](AUTHORS.md)). We strongly encourage participation from all interested parties,
|
||||
since broader community support is key for NDN to succeed as a new Internet architecture.
|
||||
|
||||
If you are new to the NDN software community, please read [`README-dev.md`](README-dev.md)
|
||||
and the [Contributor's Guide](https://github.com/named-data/.github/blob/master/CONTRIBUTING.md)
|
||||
to get started.
|
||||
|
||||
## License
|
||||
|
||||
NFD is a free and open-source software package licensed under the GPL version 3 and
|
||||
is the centerpiece of our committement to making NDN's core technology free and open
|
||||
to all Internet users and developers. For more information about licensing, refer to
|
||||
[`COPYING.md`](COPYING.md).
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
docs/release-notes-latest.rst
|
||||
@@ -0,0 +1,3 @@
|
||||
# Enable ndn-autoconfig to run in parallel with NFD. Disabled by default
|
||||
# enabled=true
|
||||
enabled=false
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_COMMON_HPP
|
||||
#define NFD_COMMON_HPP
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#define VIRTUAL_WITH_TESTS virtual
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED public
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE public
|
||||
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE protected
|
||||
#else
|
||||
#define VIRTUAL_WITH_TESTS
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED protected
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE private
|
||||
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE private
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#include <ndn-cxx/common.hpp>
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/data.hpp>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
using std::size_t;
|
||||
|
||||
using boost::noncopyable;
|
||||
using boost::scoped_ptr;
|
||||
|
||||
using ndn::shared_ptr;
|
||||
using ndn::weak_ptr;
|
||||
using ndn::enable_shared_from_this;
|
||||
using ndn::make_shared;
|
||||
using ndn::static_pointer_cast;
|
||||
using ndn::dynamic_pointer_cast;
|
||||
using ndn::const_pointer_cast;
|
||||
using ndn::function;
|
||||
using ndn::bind;
|
||||
using ndn::ref;
|
||||
using ndn::cref;
|
||||
|
||||
using ndn::Interest;
|
||||
using ndn::Data;
|
||||
using ndn::Name;
|
||||
using ndn::Exclude;
|
||||
using ndn::Block;
|
||||
|
||||
namespace tlv {
|
||||
using namespace ndn::Tlv;
|
||||
}
|
||||
|
||||
namespace name = ndn::name;
|
||||
namespace time = ndn::time;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_COMMON_HPP
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
|
||||
<plist version='1.0'>
|
||||
<dict>
|
||||
<key>Label</key><string>net.named-data.nrd</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/bin/nrd</string>
|
||||
<string>--config</string>
|
||||
<string>/usr/local/etc/ndn/nfd.conf</string>
|
||||
</array>
|
||||
<key>UserName</key><string>ndn</string>
|
||||
<key>GroupName</key><string>ndn</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>HOME</key><string>/usr/local/var/lib/ndn/nrd</string>
|
||||
</dict>
|
||||
<key>Debug</key><true/>
|
||||
<key>Disabled</key><true/>
|
||||
<key>KeepAlive</key><true/>
|
||||
<key>StandardErrorPath</key><string>/usr/local/var/log/ndn/nrd.log</string>
|
||||
<key>ProcessType</key><string>Background</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,144 +0,0 @@
|
||||
Starting NFD on Linux with upstart
|
||||
==================================
|
||||
|
||||
Some Linux distributions, such as Ubuntu, use [upstart](http://upstart.ubuntu.com/) as a
|
||||
standard mechanism to start system daemons, monitor their health, and restart
|
||||
when they die.
|
||||
|
||||
Initial setup
|
||||
-------------
|
||||
|
||||
Edit `nfd.conf` and `nrd.conf` correcting paths for `nfd` and `nfd` binaries,
|
||||
configuration file, and log files.
|
||||
|
||||
# Copy upstart config file for nfd (forwarding daemon)
|
||||
sudo cp nfd.conf /etc/init/
|
||||
|
||||
# Copy upstart config file for nrd (RIB management daemon)
|
||||
sudo cp nrd.conf /etc/init/
|
||||
|
||||
# Copy upstart config file for nfd-watcher (will restart NFD when network change detected)
|
||||
sudo cp nfd-watcher.conf /etc/init/
|
||||
|
||||
### Assumptions in the default scripts
|
||||
|
||||
* `nfd` and `nrd` are installed into `/usr/local/bin`
|
||||
* Configuration file is `/usr/local/etc/ndn/nfd.conf`
|
||||
* `nfd` will be run as root
|
||||
* `nrd` will be run as user `ndn` and group `ndn`
|
||||
* Log files will be written to `/usr/local/var/log/ndn` folder, which is owned by user `ndn`
|
||||
* Whenever network connectivity changes, both `nfd` and `nrd` are restarted
|
||||
|
||||
### Creating users
|
||||
|
||||
If `ndn` user and group does not exists, they need to be manually created.
|
||||
|
||||
# Create group `ndn`
|
||||
addgroup --system ndn
|
||||
|
||||
# Create user `ndn`
|
||||
sudo adduser --system \
|
||||
--disabled-login \
|
||||
--ingroup ndn \
|
||||
--home /nonexistent \
|
||||
--gecos "NDN User" \
|
||||
--shell /bin/false \
|
||||
ndn
|
||||
|
||||
|
||||
### Creating folders
|
||||
|
||||
Folder `/usr/local/var/log/ndn` should be created and assigned proper user and group:
|
||||
|
||||
sudo mkdir -p /usr/local/var/log/ndn
|
||||
sudo chown -R ndn:ndn /usr/local/var/log/ndn
|
||||
|
||||
`HOME` directories for `nfd` and `nrd` should be created prior to starting. This is
|
||||
necessary to manage unique security credentials for the deamons.
|
||||
|
||||
# Create HOME and generate self-signed NDN certificate for nfd
|
||||
sudo mkdir -p /usr/local/var/lib/ndn/nfd/.ndn
|
||||
sudo HOME=/usr/local/var/lib/ndn/nfd ndnsec-keygen /localhost/daemons/nfd | \
|
||||
sudo HOME=/usr/local/var/lib/ndn/nfd ndnsec-install-cert -
|
||||
|
||||
# Create HOME and generate self-signed NDN certificate for nrd
|
||||
sudo mkdir -p /usr/local/var/lib/ndn/nrd/.ndn
|
||||
sudo chown -R ndn:ndn /usr/local/var/lib/ndn/nrd
|
||||
sudo -u ndn -g ndn HOME=/usr/local/var/lib/ndn/nrd ndnsec-keygen /localhost/daemons/nrd | \
|
||||
sudo -u ndn -g ndn HOME=/usr/local/var/lib/ndn/nrd ndnsec-install-cert -
|
||||
|
||||
### Configuring NFD's security
|
||||
|
||||
NFD sample configuration allows anybody to create faces, add nexthops to FIB, and set
|
||||
strategy choice for namespaces. While such settings could be a good start, it is
|
||||
generally not a good idea to run NFD in this mode.
|
||||
|
||||
While thorough discussion about security configuration of NFD is outside the scope of this
|
||||
document, at least the following change should be done to ``nfd.conf`` in authorize
|
||||
section:
|
||||
|
||||
authorizations
|
||||
{
|
||||
authorize
|
||||
{
|
||||
certfile certs/localhost_daemons_nrd.ndncert
|
||||
privileges
|
||||
{
|
||||
faces
|
||||
fib
|
||||
strategy-choice
|
||||
}
|
||||
}
|
||||
|
||||
authorize
|
||||
{
|
||||
certfile any
|
||||
privileges
|
||||
{
|
||||
faces
|
||||
strategy-choice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
While this configuration still allows management of faces and updating strategy choice by
|
||||
anybody, only NFD's RIB Manager Daemon (`nrd`) is allowed to manage FIB.
|
||||
|
||||
As the final step to make this configuration work, nrd's self-signed certificate needs to
|
||||
be exported into `localhost_daemons_nrd.ndncert` file:
|
||||
|
||||
sudo mkdir /usr/local/etc/ndn/certs
|
||||
sudo sh -c 'sudo -u ndn -g ndn HOME=/usr/local/var/lib/ndn/nrd \
|
||||
ndnsec-dump-certificate -i /localhost/daemons/nrd \
|
||||
> /usr/local/etc/ndn/certs/localhost_daemons_nrd.ndncert'
|
||||
|
||||
|
||||
Enable auto-start
|
||||
-----------------
|
||||
|
||||
After copying the provided upstart scripts, `nfd` and `nrd` daemons will automatically run
|
||||
after the reboot. To manually start them, use the following commands:
|
||||
|
||||
sudo start nfd
|
||||
# nrd will be automatically started by upstart
|
||||
|
||||
Note that an additional upstart job, ``nfd-watcher``, will automatically monitor for
|
||||
network connectivity changes, such as when network interface gets connected, disconnected,
|
||||
or IP addresses of the network interface get updated. When ``nfd-watcher`` detects the
|
||||
event, it will restart `nfd` and `nrd`.
|
||||
|
||||
Disable auto-start
|
||||
------------------
|
||||
|
||||
To stop `nrd` and `nfd` daemon, use the following commands:
|
||||
|
||||
sudo stop nfd
|
||||
# nrd will be automatically stopped by upstart
|
||||
|
||||
Note that as long as upstart files are present in `/etc/init/`, the daemons will
|
||||
automatically start after the reboot. To permanently stop `nfd` and `nrd` daemons, delete
|
||||
the upstart files:
|
||||
|
||||
sudo rm /etc/init/nfd.conf
|
||||
sudo rm /etc/init/nrd.conf
|
||||
sudo rm /etc/init/nfd-watcher.conf
|
||||
@@ -1,13 +0,0 @@
|
||||
# nfd-watcher.conf
|
||||
#
|
||||
# Restarting NDN Forwarding Daemon on network connectivity changes
|
||||
|
||||
start on (net-device-up or
|
||||
net-device-removed or
|
||||
net-device-changed)
|
||||
task
|
||||
|
||||
script
|
||||
status nfd | grep -q start/ || stop
|
||||
restart nfd
|
||||
end script
|
||||
@@ -1,17 +0,0 @@
|
||||
# nfd.conf
|
||||
#
|
||||
# NDN Forwarding Daemon
|
||||
|
||||
description "NDN forwarding daemon"
|
||||
|
||||
start on (local-filesystems and net-device-up IFACE!=lo)
|
||||
stop on runlevel [!2345]
|
||||
|
||||
respawn
|
||||
respawn limit unlimited
|
||||
|
||||
env HOME=/usr/local/var/lib/ndn/nfd
|
||||
export HOME
|
||||
|
||||
exec /usr/local/bin/nfd --config /usr/local/etc/ndn/nfd.conf 2>> /usr/local/var/log/ndn/nfd.log
|
||||
post-stop exec sleep 2
|
||||
@@ -1,22 +0,0 @@
|
||||
# nrd.conf
|
||||
#
|
||||
# NDN RIB Manager Daemon
|
||||
|
||||
description "NDN RIB Manager Daemon"
|
||||
|
||||
start on started nfd
|
||||
stop on stopping nfd
|
||||
|
||||
respawn
|
||||
respawn limit unlimited
|
||||
|
||||
setuid ndn
|
||||
setgid ndn
|
||||
|
||||
pre-start exec sleep 2
|
||||
script
|
||||
export HOME=/usr/local/var/lib/ndn/nrd
|
||||
/usr/local/bin/nrd --config /usr/local/etc/ndn/nfd.conf 2>> /usr/local/var/log/ndn/nrd.log
|
||||
end script
|
||||
|
||||
post-stop exec sleep 2
|
||||
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_ALGORITHM_HPP
|
||||
#define NFD_CORE_ALGORITHM_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include <boost/concept/requires.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief finds the last element satisfying a predicate
|
||||
* \tparam It BidirectionalIterator
|
||||
* \tparam Pred UnaryPredicate
|
||||
*
|
||||
* \return Iterator to the last element satisfying the condition,
|
||||
* or \p last if no such element is found.
|
||||
*
|
||||
* Complexity: at most \p last-first invocations of \p p
|
||||
*/
|
||||
template<typename It, typename Pred>
|
||||
BOOST_CONCEPT_REQUIRES(
|
||||
((boost::BidirectionalIterator<It>))
|
||||
((boost::UnaryPredicate<Pred, typename std::iterator_traits<It>::value_type>)),
|
||||
(It)
|
||||
)
|
||||
find_last_if(It first, It last, Pred p)
|
||||
{
|
||||
std::reverse_iterator<It> firstR(first), lastR(last);
|
||||
auto found = std::find_if(lastR, firstR, p);
|
||||
return found == firstR ? last : std::prev(found.base());
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_ALGORITHM_HPP
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_COMMON_HPP
|
||||
#define NFD_CORE_COMMON_HPP
|
||||
|
||||
#include "core/config.hpp"
|
||||
|
||||
#ifdef NFD_WITH_TESTS
|
||||
#define NFD_VIRTUAL_WITH_TESTS virtual
|
||||
#define NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED public
|
||||
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE public
|
||||
#define NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE protected
|
||||
#define NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL override
|
||||
#define NFD_FINAL_UNLESS_WITH_TESTS
|
||||
#else
|
||||
#define NFD_VIRTUAL_WITH_TESTS
|
||||
#define NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED protected
|
||||
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE private
|
||||
#define NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE private
|
||||
#define NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL final
|
||||
#define NFD_FINAL_UNLESS_WITH_TESTS final
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <ndn-cxx/data.hpp>
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/name.hpp>
|
||||
#include <ndn-cxx/encoding/block.hpp>
|
||||
#include <ndn-cxx/lp/nack.hpp>
|
||||
#include <ndn-cxx/net/face-uri.hpp>
|
||||
#include <ndn-cxx/util/backports.hpp>
|
||||
#include <ndn-cxx/util/exception.hpp>
|
||||
#include <ndn-cxx/util/optional.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
#include <ndn-cxx/util/signal.hpp>
|
||||
#include <ndn-cxx/util/span.hpp>
|
||||
#include <ndn-cxx/util/time.hpp>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
using std::size_t;
|
||||
|
||||
using boost::noncopyable;
|
||||
|
||||
using std::shared_ptr;
|
||||
using std::unique_ptr;
|
||||
using std::weak_ptr;
|
||||
using std::make_shared;
|
||||
using std::make_unique;
|
||||
|
||||
using std::static_pointer_cast;
|
||||
using std::dynamic_pointer_cast;
|
||||
using std::const_pointer_cast;
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
using ndn::optional;
|
||||
using ndn::nullopt;
|
||||
using ndn::span;
|
||||
using ndn::to_string;
|
||||
|
||||
using ndn::Block;
|
||||
using ndn::Data;
|
||||
using ndn::FaceUri;
|
||||
using ndn::Interest;
|
||||
using ndn::Name;
|
||||
using ndn::PartialName;
|
||||
using ndn::Scheduler;
|
||||
|
||||
// Not using a namespace alias (namespace tlv = ndn::tlv), because
|
||||
// it doesn't allow NFD to add other members to the namespace
|
||||
namespace tlv {
|
||||
using namespace ndn::tlv;
|
||||
} // namespace tlv
|
||||
|
||||
namespace lp = ndn::lp;
|
||||
namespace name = ndn::name;
|
||||
namespace scheduler = ndn::scheduler;
|
||||
namespace signal = ndn::util::signal;
|
||||
namespace time = ndn::time;
|
||||
using namespace ndn::time_literals;
|
||||
using ndn::operator""_block;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_COMMON_HPP
|
||||
@@ -1,128 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_CONFIG_FILE_HPP
|
||||
#define NFD_CORE_CONFIG_FILE_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
typedef boost::property_tree::ptree ConfigSection;
|
||||
|
||||
/// \brief callback for config file sections
|
||||
typedef function<void(const ConfigSection& /*section*/,
|
||||
bool /*isDryRun*/,
|
||||
const std::string& /*filename*/)> ConfigSectionHandler;
|
||||
|
||||
/// \brief callback for config file sections without a subscribed handler
|
||||
typedef function<void(const std::string& /*filename*/,
|
||||
const std::string& /*sectionName*/,
|
||||
const ConfigSection& /*section*/,
|
||||
bool /*isDryRun*/)> UnknownConfigSectionHandler;
|
||||
|
||||
class ConfigFile : noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
ConfigFile(UnknownConfigSectionHandler unknownSectionCallback = throwErrorOnUnknownSection);
|
||||
|
||||
static void
|
||||
throwErrorOnUnknownSection(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun);
|
||||
|
||||
static void
|
||||
ignoreUnknownSection(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun);
|
||||
|
||||
/// \brief setup notification of configuration file sections
|
||||
void
|
||||
addSectionHandler(const std::string& sectionName,
|
||||
ConfigSectionHandler subscriber);
|
||||
|
||||
|
||||
/**
|
||||
* \param filename file to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \throws ConfigFile::Error if file not found
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(const std::string& filename, bool isDryRun);
|
||||
|
||||
/**
|
||||
* \param input configuration (as a string) to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \param filename optional convenience argument to provide more detailed error messages
|
||||
* \throws ConfigFile::Error if file not found
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(const std::string& input, bool isDryRun, const std::string& filename);
|
||||
|
||||
/**
|
||||
* \param input stream to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \param filename optional convenience argument to provide more detailed error messages
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(std::istream& input, bool isDryRun, const std::string& filename);
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
process(bool isDryRun, const std::string& filename);
|
||||
|
||||
private:
|
||||
UnknownConfigSectionHandler m_unknownSectionCallback;
|
||||
|
||||
typedef std::map<std::string, ConfigSectionHandler> SubscriptionTable;
|
||||
|
||||
SubscriptionTable m_subscriptions;
|
||||
|
||||
ConfigSection m_global;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
|
||||
#endif // NFD_CORE_CONFIG_FILE_HPP
|
||||
@@ -1,82 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "ethernet.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
std::string
|
||||
Address::toString(char sep) const
|
||||
{
|
||||
char s[18]; // 12 digits + 5 separators + null terminator
|
||||
::snprintf(s, sizeof(s), "%02x%c%02x%c%02x%c%02x%c%02x%c%02x",
|
||||
elems[0], sep, elems[1], sep, elems[2], sep,
|
||||
elems[3], sep, elems[4], sep, elems[5]);
|
||||
return std::string(s);
|
||||
}
|
||||
|
||||
Address
|
||||
Address::fromString(const std::string& str)
|
||||
{
|
||||
unsigned short temp[ADDR_LEN];
|
||||
char sep[5][2]; // 5 * (1 separator char + 1 null terminator)
|
||||
int n = 0; // num of chars read from the input string
|
||||
|
||||
// ISO C++98 does not support the 'hh' type modifier
|
||||
/// \todo use SCNx8 (cinttypes) when we enable C++11
|
||||
int ret = ::sscanf(str.c_str(), "%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%n",
|
||||
&temp[0], &sep[0][0], &temp[1], &sep[1][0], &temp[2], &sep[2][0],
|
||||
&temp[3], &sep[3][0], &temp[4], &sep[4][0], &temp[5], &n);
|
||||
|
||||
if (ret < 11 || static_cast<size_t>(n) != str.length())
|
||||
return Address();
|
||||
|
||||
Address a;
|
||||
for (size_t i = 0; i < ADDR_LEN; ++i)
|
||||
{
|
||||
// check that all separators are actually the same char (: or -)
|
||||
if (i < 5 && sep[i][0] != sep[0][0])
|
||||
return Address();
|
||||
|
||||
// check that each value fits into a uint8_t
|
||||
if (temp[i] > 0xFF)
|
||||
return Address();
|
||||
|
||||
a[i] = static_cast<uint8_t>(temp[i]);
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& o, const Address& a)
|
||||
{
|
||||
return o << a.toString();
|
||||
}
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
@@ -1,167 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_ETHERNET_HPP
|
||||
#define NFD_CORE_ETHERNET_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <boost/array.hpp>
|
||||
|
||||
#define ETHERTYPE_NDN 0x8624
|
||||
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
const size_t ADDR_LEN = 6; ///< Octets in one Ethernet address
|
||||
const size_t TYPE_LEN = 2; ///< Octets in Ethertype field
|
||||
const size_t HDR_LEN = 14; ///< Total octets in Ethernet header (without 802.1Q tag)
|
||||
const size_t TAG_LEN = 4; ///< Octets in 802.1Q tag (TPID + priority + VLAN)
|
||||
const size_t MIN_DATA_LEN = 46; ///< Min octets in Ethernet payload (assuming no 802.1Q tag)
|
||||
const size_t MAX_DATA_LEN = 1500; ///< Max octets in Ethernet payload
|
||||
const size_t CRC_LEN = 4; ///< Octets in Ethernet frame check sequence
|
||||
|
||||
|
||||
class Address : public boost::array<uint8_t, ADDR_LEN>
|
||||
{
|
||||
public:
|
||||
/// Constructs a null Ethernet address (00:00:00:00:00:00)
|
||||
Address();
|
||||
|
||||
/// Constructs a new Ethernet address with the given octets
|
||||
Address(uint8_t a1, uint8_t a2, uint8_t a3,
|
||||
uint8_t a4, uint8_t a5, uint8_t a6);
|
||||
|
||||
/// Constructs a new Ethernet address with the given octets
|
||||
explicit
|
||||
Address(const uint8_t octets[ADDR_LEN]);
|
||||
|
||||
/// Copy constructor
|
||||
Address(const Address& address);
|
||||
|
||||
/// True if this is a broadcast address (ff:ff:ff:ff:ff:ff)
|
||||
bool
|
||||
isBroadcast() const;
|
||||
|
||||
/// True if this is a multicast address
|
||||
bool
|
||||
isMulticast() const;
|
||||
|
||||
/// True if this is a null address (00:00:00:00:00:00)
|
||||
bool
|
||||
isNull() const;
|
||||
|
||||
/**
|
||||
* @brief Converts the address to a human-readable string
|
||||
*
|
||||
* @param sep A character used to visually separate the octets,
|
||||
* usually ':' (the default value) or '-'
|
||||
*/
|
||||
std::string
|
||||
toString(char sep = ':') const;
|
||||
|
||||
/**
|
||||
* @brief Creates an Address from a string containing an Ethernet address
|
||||
* in hexadecimal notation, with colons or hyphens as separators
|
||||
*
|
||||
* @param str The string to be parsed
|
||||
* @return Always an instance of Address, which will be null
|
||||
* if the parsing fails
|
||||
*/
|
||||
static Address
|
||||
fromString(const std::string& str);
|
||||
};
|
||||
|
||||
/// Returns the Ethernet broadcast address (ff:ff:ff:ff:ff:ff)
|
||||
inline Address
|
||||
getBroadcastAddress()
|
||||
{
|
||||
static Address bcast(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
return bcast;
|
||||
}
|
||||
|
||||
/// Returns the default Ethernet multicast address for NDN
|
||||
inline Address
|
||||
getDefaultMulticastAddress()
|
||||
{
|
||||
static Address mcast(0x01, 0x00, 0x5E, 0x00, 0x17, 0xAA);
|
||||
return mcast;
|
||||
}
|
||||
|
||||
inline
|
||||
Address::Address()
|
||||
{
|
||||
assign(0);
|
||||
}
|
||||
|
||||
inline
|
||||
Address::Address(uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4, uint8_t a5, uint8_t a6)
|
||||
{
|
||||
elems[0] = a1;
|
||||
elems[1] = a2;
|
||||
elems[2] = a3;
|
||||
elems[3] = a4;
|
||||
elems[4] = a5;
|
||||
elems[5] = a6;
|
||||
}
|
||||
|
||||
inline
|
||||
Address::Address(const uint8_t octets[])
|
||||
{
|
||||
std::copy(octets, octets + size(), begin());
|
||||
}
|
||||
|
||||
inline
|
||||
Address::Address(const Address& address)
|
||||
{
|
||||
std::copy(address.begin(), address.end(), begin());
|
||||
}
|
||||
|
||||
inline bool
|
||||
Address::isBroadcast() const
|
||||
{
|
||||
return elems[0] == 0xFF && elems[1] == 0xFF && elems[2] == 0xFF &&
|
||||
elems[3] == 0xFF && elems[4] == 0xFF && elems[5] == 0xFF;
|
||||
}
|
||||
|
||||
inline bool
|
||||
Address::isMulticast() const
|
||||
{
|
||||
return (elems[0] & 1) != 0;
|
||||
}
|
||||
|
||||
inline bool
|
||||
Address::isNull() const
|
||||
{
|
||||
return elems[0] == 0x0 && elems[1] == 0x0 && elems[2] == 0x0 &&
|
||||
elems[3] == 0x0 && elems[4] == 0x0 && elems[5] == 0x0;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& o, const Address& a);
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_FACE_ETHERNET_HPP
|
||||
@@ -1,356 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_EVENT_EMITTER_HPP
|
||||
#define NFD_CORE_EVENT_EMITTER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
struct empty
|
||||
{
|
||||
};
|
||||
|
||||
/** \class EventEmitter
|
||||
* \brief provides a lightweight event system
|
||||
*
|
||||
* To declare an event:
|
||||
* EventEmitter<TArgs> onEventName;
|
||||
* To subscribe to an event:
|
||||
* eventSource->onEventName += eventHandler;
|
||||
* Multiple functions can subscribe to the same event.
|
||||
* To trigger an event:
|
||||
* onEventName(args);
|
||||
* To clear event subscriptions:
|
||||
* onEventName.clear();
|
||||
*/
|
||||
|
||||
// four arguments
|
||||
template<typename T1 = empty, typename T2 = empty,
|
||||
typename T3 = empty, typename T4 = empty>
|
||||
class EventEmitter : noncopyable
|
||||
{
|
||||
public:
|
||||
/// represents a handler that can subscribe to the event
|
||||
typedef function<void(const T1&, const T2&,
|
||||
const T3&, const T4&)> Handler;
|
||||
|
||||
/// adds an subscription
|
||||
void
|
||||
operator+=(Handler handler);
|
||||
|
||||
/// returns true if there is no subscription,
|
||||
/// otherwise returns false
|
||||
bool
|
||||
isEmpty();
|
||||
|
||||
/// clears all subscriptions
|
||||
void
|
||||
clear();
|
||||
|
||||
/// triggers the event
|
||||
void
|
||||
operator()(const T1& a1, const T2& a2, const T3& a3, const T4& a4);
|
||||
|
||||
private:
|
||||
/// stores all subscribed handlers
|
||||
std::vector<Handler> m_handlers;
|
||||
};
|
||||
|
||||
// zero argument
|
||||
template<>
|
||||
class EventEmitter<empty, empty, empty, empty> : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef function<void()> Handler;
|
||||
|
||||
void
|
||||
operator+=(Handler handler);
|
||||
|
||||
bool
|
||||
isEmpty();
|
||||
|
||||
void
|
||||
clear();
|
||||
|
||||
void
|
||||
operator()();
|
||||
|
||||
private:
|
||||
std::vector<Handler> m_handlers;
|
||||
};
|
||||
|
||||
|
||||
// one argument
|
||||
template<typename T1>
|
||||
class EventEmitter<T1, empty, empty, empty> : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef function<void(const T1&)> Handler;
|
||||
|
||||
void
|
||||
operator+=(Handler handler);
|
||||
|
||||
bool
|
||||
isEmpty();
|
||||
|
||||
void
|
||||
clear();
|
||||
|
||||
void
|
||||
operator()(const T1& a1);
|
||||
|
||||
private:
|
||||
std::vector<Handler> m_handlers;
|
||||
};
|
||||
|
||||
|
||||
// two arguments
|
||||
template<typename T1, typename T2>
|
||||
class EventEmitter<T1, T2, empty, empty> : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef function<void(const T1&, const T2&)> Handler;
|
||||
|
||||
void
|
||||
operator+=(Handler handler);
|
||||
|
||||
bool
|
||||
isEmpty();
|
||||
|
||||
void
|
||||
clear();
|
||||
|
||||
void
|
||||
operator()(const T1& a1, const T2& a2);
|
||||
|
||||
private:
|
||||
std::vector<Handler> m_handlers;
|
||||
};
|
||||
|
||||
|
||||
// three arguments
|
||||
template<typename T1, typename T2, typename T3>
|
||||
class EventEmitter<T1, T2, T3, empty> : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef function<void(const T1&, const T2&, const T3&)> Handler;
|
||||
|
||||
void
|
||||
operator+=(Handler handler);
|
||||
|
||||
bool
|
||||
isEmpty();
|
||||
|
||||
void
|
||||
clear();
|
||||
|
||||
void
|
||||
operator()(const T1& a1, const T2& a2, const T3& a3);
|
||||
|
||||
private:
|
||||
std::vector<Handler> m_handlers;
|
||||
};
|
||||
|
||||
|
||||
// zero argument
|
||||
|
||||
inline void
|
||||
EventEmitter<empty, empty, empty, empty>::operator+=(Handler handler)
|
||||
{
|
||||
m_handlers.push_back(handler);
|
||||
}
|
||||
|
||||
inline bool
|
||||
EventEmitter<empty, empty, empty, empty>::isEmpty()
|
||||
{
|
||||
return m_handlers.empty();
|
||||
}
|
||||
|
||||
inline void
|
||||
EventEmitter<empty, empty, empty, empty>::clear()
|
||||
{
|
||||
return m_handlers.clear();
|
||||
}
|
||||
|
||||
inline void
|
||||
EventEmitter<empty, empty, empty, empty>::operator()()
|
||||
{
|
||||
std::vector<Handler>::iterator it;
|
||||
for (it = m_handlers.begin(); it != m_handlers.end(); ++it) {
|
||||
(*it)();
|
||||
if (m_handlers.empty()) // .clear has been called
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// one argument
|
||||
|
||||
template<typename T1>
|
||||
inline void
|
||||
EventEmitter<T1, empty, empty, empty>::operator+=(Handler handler)
|
||||
{
|
||||
m_handlers.push_back(handler);
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
inline bool
|
||||
EventEmitter<T1, empty, empty, empty>::isEmpty()
|
||||
{
|
||||
return m_handlers.empty();
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
inline void
|
||||
EventEmitter<T1, empty, empty, empty>::clear()
|
||||
{
|
||||
return m_handlers.clear();
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
inline void
|
||||
EventEmitter<T1, empty, empty, empty>::operator()(const T1& a1)
|
||||
{
|
||||
typename std::vector<Handler>::iterator it;
|
||||
for (it = m_handlers.begin(); it != m_handlers.end(); ++it) {
|
||||
(*it)(a1);
|
||||
if (m_handlers.empty()) // .clear has been called
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// two arguments
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
EventEmitter<T1, T2, empty, empty>::operator+=(Handler handler)
|
||||
{
|
||||
m_handlers.push_back(handler);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline bool
|
||||
EventEmitter<T1, T2, empty, empty>::isEmpty()
|
||||
{
|
||||
return m_handlers.empty();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
EventEmitter<T1, T2, empty, empty>::clear()
|
||||
{
|
||||
return m_handlers.clear();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
EventEmitter<T1, T2, empty, empty>::operator()
|
||||
(const T1& a1, const T2& a2)
|
||||
{
|
||||
typename std::vector<Handler>::iterator it;
|
||||
for (it = m_handlers.begin(); it != m_handlers.end(); ++it) {
|
||||
(*it)(a1, a2);
|
||||
if (m_handlers.empty()) // .clear has been called
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// three arguments
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, empty>::operator+=(Handler handler)
|
||||
{
|
||||
m_handlers.push_back(handler);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline bool
|
||||
EventEmitter<T1, T2, T3, empty>::isEmpty()
|
||||
{
|
||||
return m_handlers.empty();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, empty>::clear()
|
||||
{
|
||||
return m_handlers.clear();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, empty>::operator()
|
||||
(const T1& a1, const T2& a2, const T3& a3)
|
||||
{
|
||||
typename std::vector<Handler>::iterator it;
|
||||
for (it = m_handlers.begin(); it != m_handlers.end(); ++it) {
|
||||
(*it)(a1, a2, a3);
|
||||
if (m_handlers.empty()) // .clear has been called
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// four arguments
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, T4>::operator+=(Handler handler)
|
||||
{
|
||||
m_handlers.push_back(handler);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
inline bool
|
||||
EventEmitter<T1, T2, T3, T4>::isEmpty()
|
||||
{
|
||||
return m_handlers.empty();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, T4>::clear()
|
||||
{
|
||||
return m_handlers.clear();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
inline void
|
||||
EventEmitter<T1, T2, T3, T4>::operator()
|
||||
(const T1& a1, const T2& a2, const T3& a3, const T4& a4)
|
||||
{
|
||||
typename std::vector<Handler>::iterator it;
|
||||
for (it = m_handlers.begin(); it != m_handlers.end(); ++it) {
|
||||
(*it)(a1, a2, a3, a4);
|
||||
if (m_handlers.empty()) // .clear has been called
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_EVENT_EMITTER_HPP
|
||||
@@ -1,163 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "face-uri.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
#include "ethernet.hpp"
|
||||
#endif // HAVE_LIBPCAP
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
NFD_LOG_INIT("FaceUri");
|
||||
|
||||
namespace nfd {
|
||||
|
||||
FaceUri::FaceUri(const std::string& uri)
|
||||
{
|
||||
if (!parse(uri)) {
|
||||
throw Error("Malformed URI: " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
FaceUri::FaceUri(const char* uri)
|
||||
{
|
||||
if (!parse(uri)) {
|
||||
throw Error("Malformed URI: " + std::string(uri));
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
FaceUri::parse(const std::string& uri)
|
||||
{
|
||||
m_scheme.clear();
|
||||
m_host.clear();
|
||||
m_isV6 = false;
|
||||
m_port.clear();
|
||||
m_path.clear();
|
||||
|
||||
static const boost::regex protocolExp("(\\w+\\d?)://([^/]*)(\\/[^?]*)?");
|
||||
boost::smatch protocolMatch;
|
||||
if (!boost::regex_match(uri, protocolMatch, protocolExp)) {
|
||||
return false;
|
||||
}
|
||||
m_scheme = protocolMatch[1];
|
||||
const std::string& authority = protocolMatch[2];
|
||||
m_path = protocolMatch[3];
|
||||
|
||||
// pattern for IPv6 address enclosed in [ ], with optional port number
|
||||
static const boost::regex v6Exp("^\\[([a-fA-F0-9:]+)\\](?:\\:(\\d+))?$");
|
||||
// pattern for Ethernet address in standard hex-digits-and-colons notation
|
||||
static const boost::regex etherExp("^\\[((?:[a-fA-F0-9]{1,2}\\:){5}(?:[a-fA-F0-9]{1,2}))\\]$");
|
||||
// pattern for IPv4-mapped IPv6 address, with optional port number
|
||||
static const boost::regex v4MappedV6Exp("^\\[::ffff:(\\d+(?:\\.\\d+){3})\\](?:\\:(\\d+))?$");
|
||||
// pattern for IPv4/hostname/fd/ifname, with optional port number
|
||||
static const boost::regex v4HostExp("^([^:]+)(?:\\:(\\d+))?$");
|
||||
|
||||
if (authority.empty()) {
|
||||
// UNIX, internal
|
||||
}
|
||||
else {
|
||||
boost::smatch match;
|
||||
m_isV6 = boost::regex_match(authority, match, v6Exp);
|
||||
if (m_isV6 ||
|
||||
boost::regex_match(authority, match, etherExp) ||
|
||||
boost::regex_match(authority, match, v4MappedV6Exp) ||
|
||||
boost::regex_match(authority, match, v4HostExp)) {
|
||||
m_host = match[1];
|
||||
m_port = match[2];
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
NFD_LOG_DEBUG("URI [" << uri << "] parsed into: " <<
|
||||
m_scheme << ", " << m_host << ", " << m_port << ", " << m_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
FaceUri::FaceUri(const boost::asio::ip::tcp::endpoint& endpoint)
|
||||
{
|
||||
m_isV6 = endpoint.address().is_v6();
|
||||
m_scheme = m_isV6 ? "tcp6" : "tcp4";
|
||||
m_host = endpoint.address().to_string();
|
||||
m_port = boost::lexical_cast<std::string>(endpoint.port());
|
||||
}
|
||||
|
||||
FaceUri::FaceUri(const boost::asio::ip::udp::endpoint& endpoint)
|
||||
{
|
||||
m_isV6 = endpoint.address().is_v6();
|
||||
m_scheme = m_isV6 ? "udp6" : "udp4";
|
||||
m_host = endpoint.address().to_string();
|
||||
m_port = boost::lexical_cast<std::string>(endpoint.port());
|
||||
}
|
||||
|
||||
FaceUri::FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme)
|
||||
: m_scheme(scheme)
|
||||
{
|
||||
m_isV6 = endpoint.address().is_v6();
|
||||
m_host = endpoint.address().to_string();
|
||||
m_port = boost::lexical_cast<std::string>(endpoint.port());
|
||||
}
|
||||
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
FaceUri::FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint)
|
||||
: m_isV6(false)
|
||||
{
|
||||
m_scheme = "unix";
|
||||
m_path = endpoint.path();
|
||||
}
|
||||
#endif // HAVE_UNIX_SOCKETS
|
||||
|
||||
FaceUri
|
||||
FaceUri::fromFd(int fd)
|
||||
{
|
||||
FaceUri uri;
|
||||
uri.m_scheme = "fd";
|
||||
uri.m_host = boost::lexical_cast<std::string>(fd);
|
||||
return uri;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
FaceUri::FaceUri(const ethernet::Address& address)
|
||||
: m_isV6(true)
|
||||
{
|
||||
m_scheme = "ether";
|
||||
m_host = address.toString();
|
||||
}
|
||||
#endif // HAVE_LIBPCAP
|
||||
|
||||
FaceUri
|
||||
FaceUri::fromDev(const std::string& ifname)
|
||||
{
|
||||
FaceUri uri;
|
||||
uri.m_scheme = "dev";
|
||||
uri.m_host = ifname;
|
||||
return uri;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,219 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_FACE_URI_H
|
||||
#define NFD_CORE_FACE_URI_H
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
namespace ethernet {
|
||||
class Address;
|
||||
} // namespace ethernet
|
||||
#endif // HAVE_LIBPCAP
|
||||
|
||||
/** \brief represents the underlying protocol and address used by a Face
|
||||
* \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#FaceUri
|
||||
*/
|
||||
class FaceUri
|
||||
{
|
||||
public:
|
||||
class Error : public std::invalid_argument
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::invalid_argument(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
FaceUri();
|
||||
|
||||
/** \brief construct by parsing
|
||||
*
|
||||
* \param uri scheme://host[:port]/path
|
||||
* \throw FaceUri::Error if URI cannot be parsed
|
||||
*/
|
||||
explicit
|
||||
FaceUri(const std::string& uri);
|
||||
|
||||
// This overload is needed so that calls with string literal won't be
|
||||
// resolved to boost::asio::local::stream_protocol::endpoint overload.
|
||||
explicit
|
||||
FaceUri(const char* uri);
|
||||
|
||||
/// exception-safe parsing
|
||||
bool
|
||||
parse(const std::string& uri);
|
||||
|
||||
public: // scheme-specific construction
|
||||
/// construct tcp4 or tcp6 canonical FaceUri
|
||||
explicit
|
||||
FaceUri(const boost::asio::ip::tcp::endpoint& endpoint);
|
||||
|
||||
/// construct udp4 or udp6 canonical FaceUri
|
||||
explicit
|
||||
FaceUri(const boost::asio::ip::udp::endpoint& endpoint);
|
||||
|
||||
/// construct tcp canonical FaceUri with customized scheme
|
||||
FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme);
|
||||
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
/// construct unix canonical FaceUri
|
||||
explicit
|
||||
FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint);
|
||||
#endif // HAVE_UNIX_SOCKETS
|
||||
|
||||
/// create fd FaceUri from file descriptor
|
||||
static FaceUri
|
||||
fromFd(int fd);
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
/// construct ether canonical FaceUri
|
||||
explicit
|
||||
FaceUri(const ethernet::Address& address);
|
||||
#endif // HAVE_LIBPCAP
|
||||
|
||||
/// create dev FaceUri from network device name
|
||||
static FaceUri
|
||||
fromDev(const std::string& ifname);
|
||||
|
||||
public: // getters
|
||||
/// get scheme (protocol)
|
||||
const std::string&
|
||||
getScheme() const;
|
||||
|
||||
/// get host (domain)
|
||||
const std::string&
|
||||
getHost() const;
|
||||
|
||||
/// get port
|
||||
const std::string&
|
||||
getPort() const;
|
||||
|
||||
/// get path
|
||||
const std::string&
|
||||
getPath() const;
|
||||
|
||||
/// write as a string
|
||||
std::string
|
||||
toString() const;
|
||||
|
||||
public: // EqualityComparable concept
|
||||
/// equality operator
|
||||
bool
|
||||
operator==(const FaceUri& rhs) const;
|
||||
|
||||
/// inequality operator
|
||||
bool
|
||||
operator!=(const FaceUri& rhs) const;
|
||||
|
||||
private:
|
||||
std::string m_scheme;
|
||||
std::string m_host;
|
||||
/// whether to add [] around host when writing string
|
||||
bool m_isV6;
|
||||
std::string m_port;
|
||||
std::string m_path;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
|
||||
};
|
||||
|
||||
inline
|
||||
FaceUri::FaceUri()
|
||||
: m_isV6(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline const std::string&
|
||||
FaceUri::getScheme() const
|
||||
{
|
||||
return m_scheme;
|
||||
}
|
||||
|
||||
inline const std::string&
|
||||
FaceUri::getHost() const
|
||||
{
|
||||
return m_host;
|
||||
}
|
||||
|
||||
inline const std::string&
|
||||
FaceUri::getPort() const
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
|
||||
inline const std::string&
|
||||
FaceUri::getPath() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
inline std::string
|
||||
FaceUri::toString() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *this;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
inline bool
|
||||
FaceUri::operator==(const FaceUri& rhs) const
|
||||
{
|
||||
return (m_scheme == rhs.m_scheme &&
|
||||
m_host == rhs.m_host &&
|
||||
m_isV6 == rhs.m_isV6 &&
|
||||
m_port == rhs.m_port &&
|
||||
m_path == rhs.m_path);
|
||||
}
|
||||
|
||||
inline bool
|
||||
FaceUri::operator!=(const FaceUri& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, const FaceUri& uri)
|
||||
{
|
||||
os << uri.m_scheme << "://";
|
||||
if (uri.m_isV6) {
|
||||
os << "[" << uri.m_host << "]";
|
||||
}
|
||||
else {
|
||||
os << uri.m_host;
|
||||
}
|
||||
if (!uri.m_port.empty()) {
|
||||
os << ":" << uri.m_port;
|
||||
}
|
||||
os << uri.m_path;
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_FACE_URI_H
|
||||
@@ -1,53 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "global-io.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
namespace scheduler {
|
||||
// defined in scheduler.cpp
|
||||
void
|
||||
resetGlobalScheduler();
|
||||
} // namespace scheduler
|
||||
|
||||
static shared_ptr<boost::asio::io_service> g_ioService;
|
||||
|
||||
boost::asio::io_service&
|
||||
getGlobalIoService()
|
||||
{
|
||||
if (!static_cast<bool>(g_ioService)) {
|
||||
g_ioService = make_shared<boost::asio::io_service>();
|
||||
}
|
||||
return *g_ioService;
|
||||
}
|
||||
|
||||
void
|
||||
resetGlobalIoService()
|
||||
{
|
||||
scheduler::resetGlobalScheduler();
|
||||
g_ioService.reset();
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,213 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "logger-factory.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT("LoggerFactory");
|
||||
|
||||
LoggerFactory&
|
||||
LoggerFactory::getInstance()
|
||||
{
|
||||
static LoggerFactory globalLoggerFactory;
|
||||
|
||||
return globalLoggerFactory;
|
||||
}
|
||||
|
||||
LoggerFactory::LoggerFactory()
|
||||
: m_defaultLevel(LOG_INFO)
|
||||
{
|
||||
m_levelNames["NONE"] = LOG_NONE;
|
||||
m_levelNames["ERROR"] = LOG_ERROR;
|
||||
m_levelNames["WARN"] = LOG_WARN;
|
||||
m_levelNames["INFO"] = LOG_INFO;
|
||||
m_levelNames["DEBUG"] = LOG_DEBUG;
|
||||
m_levelNames["TRACE"] = LOG_TRACE;
|
||||
m_levelNames["ALL"] = LOG_ALL;
|
||||
}
|
||||
|
||||
void
|
||||
LoggerFactory::setConfigFile(ConfigFile& config)
|
||||
{
|
||||
config.addSectionHandler("log", bind(&LoggerFactory::onConfig, this, _1, _2, _3));
|
||||
}
|
||||
|
||||
LogLevel
|
||||
LoggerFactory::parseLevel(const std::string& level)
|
||||
{
|
||||
std::string upperLevel = level;
|
||||
boost::to_upper(upperLevel);
|
||||
|
||||
// std::cerr << "parsing level: " << upperLevel << std::endl;;
|
||||
// std::cerr << "# levels: " << m_levelNames.size() << std::endl;
|
||||
// std::cerr << m_levelNames.begin()->first << std::endl;
|
||||
|
||||
LevelMap::const_iterator levelIt = m_levelNames.find(upperLevel);
|
||||
if (levelIt != m_levelNames.end())
|
||||
{
|
||||
return levelIt->second;
|
||||
}
|
||||
try
|
||||
{
|
||||
uint32_t levelNo = boost::lexical_cast<uint32_t>(level);
|
||||
|
||||
if ((boost::lexical_cast<uint32_t>(LOG_NONE) <= levelNo &&
|
||||
levelNo <= boost::lexical_cast<uint32_t>(LOG_TRACE)) ||
|
||||
levelNo == LOG_ALL)
|
||||
{
|
||||
return static_cast<LogLevel>(levelNo);
|
||||
}
|
||||
}
|
||||
catch (const boost::bad_lexical_cast& error)
|
||||
{
|
||||
}
|
||||
throw LoggerFactory::Error("Unsupported logging level \"" +
|
||||
level + "\"");
|
||||
}
|
||||
|
||||
LogLevel
|
||||
LoggerFactory::extractLevel(const ConfigSection& item, const std::string& key)
|
||||
{
|
||||
std::string levelString;
|
||||
try
|
||||
{
|
||||
levelString = item.get_value<std::string>();
|
||||
}
|
||||
catch (const boost::property_tree::ptree_error& error)
|
||||
{
|
||||
}
|
||||
|
||||
if (levelString.empty())
|
||||
{
|
||||
throw LoggerFactory::Error("No logging level found for option \"" + key + "\"");
|
||||
}
|
||||
|
||||
return parseLevel(levelString);
|
||||
}
|
||||
|
||||
void
|
||||
LoggerFactory::onConfig(const ConfigSection& section,
|
||||
bool isDryRun,
|
||||
const std::string& filename)
|
||||
{
|
||||
// log
|
||||
// {
|
||||
// ; default_level specifies the logging level for modules
|
||||
// ; that are not explicitly named. All debugging levels
|
||||
// ; listed above the selected value are enabled.
|
||||
//
|
||||
// default_level INFO
|
||||
//
|
||||
// ; You may also override the default for specific modules:
|
||||
//
|
||||
// FibManager DEBUG
|
||||
// Forwarder WARN
|
||||
// }
|
||||
|
||||
if (!isDryRun)
|
||||
{
|
||||
ConfigSection::const_assoc_iterator item = section.find("default_level");
|
||||
if (item != section.not_found())
|
||||
{
|
||||
LogLevel level = extractLevel(item->second, "default_level");
|
||||
setDefaultLevel(level);
|
||||
}
|
||||
else
|
||||
{
|
||||
setDefaultLevel(LOG_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
for (ConfigSection::const_iterator item = section.begin();
|
||||
item != section.end();
|
||||
++item)
|
||||
{
|
||||
LogLevel level = extractLevel(item->second, item->first);
|
||||
|
||||
if (item->first == "default_level")
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
LoggerMap::iterator loggerIt = m_loggers.find(item->first);
|
||||
if (loggerIt == m_loggers.end())
|
||||
{
|
||||
NFD_LOG_DEBUG("Failed to configure logging level for module \"" <<
|
||||
item->first << "\" (module not found)");
|
||||
}
|
||||
else if (!isDryRun)
|
||||
{
|
||||
// std::cerr << "changing level for module " << item->first << " to " << level << std::endl;
|
||||
loggerIt->second.setLogLevel(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LoggerFactory::setDefaultLevel(LogLevel level)
|
||||
{
|
||||
// std::cerr << "changing to default_level " << level << std::endl;
|
||||
|
||||
m_defaultLevel = level;
|
||||
for (LoggerMap::iterator i = m_loggers.begin(); i != m_loggers.end(); ++i)
|
||||
{
|
||||
// std::cerr << "changing " << i->first << " to default " << m_defaultLevel << std::endl;
|
||||
i->second.setLogLevel(m_defaultLevel);
|
||||
}
|
||||
}
|
||||
|
||||
Logger&
|
||||
LoggerFactory::create(const std::string& moduleName)
|
||||
{
|
||||
return LoggerFactory::getInstance().createLogger(moduleName);
|
||||
}
|
||||
|
||||
Logger&
|
||||
LoggerFactory::createLogger(const std::string& moduleName)
|
||||
{
|
||||
// std::cerr << "creating logger for " << moduleName
|
||||
// << " with level " << m_defaultLevel << std::endl;
|
||||
|
||||
std::pair<LoggerMap::iterator, bool> loggerIt =
|
||||
m_loggers.insert(NameAndLogger(moduleName, Logger(moduleName, m_defaultLevel)));
|
||||
|
||||
return loggerIt.first->second;
|
||||
}
|
||||
|
||||
std::list<std::string>
|
||||
LoggerFactory::getModules() const
|
||||
{
|
||||
std::list<std::string> modules;
|
||||
for (LoggerMap::const_iterator i = m_loggers.begin(); i != m_loggers.end(); ++i)
|
||||
{
|
||||
modules.push_back(i->first);
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,110 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_LOGGER_FACTORY_HPP
|
||||
#define NFD_CORE_LOGGER_FACTORY_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config-file.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class LoggerFactory : noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& error)
|
||||
: std::runtime_error(error)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static LoggerFactory&
|
||||
getInstance();
|
||||
|
||||
void
|
||||
setConfigFile(ConfigFile& config);
|
||||
|
||||
void
|
||||
onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
|
||||
|
||||
std::list<std::string>
|
||||
getModules() const;
|
||||
|
||||
static Logger&
|
||||
create(const std::string& moduleName);
|
||||
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
|
||||
// these methods are used during unit-testing
|
||||
|
||||
LogLevel
|
||||
getDefaultLevel() const;
|
||||
|
||||
void
|
||||
setDefaultLevel(LogLevel level);
|
||||
|
||||
private:
|
||||
|
||||
LoggerFactory();
|
||||
|
||||
Logger&
|
||||
createLogger(const std::string& moduleName);
|
||||
|
||||
LogLevel
|
||||
parseLevel(const std::string& level);
|
||||
|
||||
LogLevel
|
||||
extractLevel(const ConfigSection& item, const std::string& key);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<std::string, LogLevel> LevelMap;
|
||||
typedef std::pair<std::string, LogLevel> NameAndLevel;
|
||||
|
||||
LevelMap m_levelNames;
|
||||
|
||||
typedef std::map<std::string, Logger> LoggerMap;
|
||||
typedef std::pair<std::string, Logger> NameAndLogger;
|
||||
|
||||
LoggerMap m_loggers;
|
||||
|
||||
LogLevel m_defaultLevel;
|
||||
};
|
||||
|
||||
inline LogLevel
|
||||
LoggerFactory::getDefaultLevel() const
|
||||
{
|
||||
return m_defaultLevel;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_LOGGER_FACTORY_HPP
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_LOGGER_HPP
|
||||
#define NFD_CORE_LOGGER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include <ndn-cxx/util/time.hpp>
|
||||
|
||||
/// \todo use when we enable C++11 (see todo in now())
|
||||
// #include <cinttypes>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
enum LogLevel {
|
||||
LOG_NONE = 0, // no messages
|
||||
LOG_ERROR = 1, // serious error messages
|
||||
LOG_WARN = 2, // warning messages
|
||||
LOG_INFO = 3, // informational messages
|
||||
LOG_DEBUG = 4, // debug messages
|
||||
LOG_TRACE = 5, // trace messages (most verbose)
|
||||
// LOG_FATAL is not a level and is logged unconditionally
|
||||
LOG_ALL = 255 // all messages
|
||||
};
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
|
||||
Logger(const std::string& name, LogLevel level)
|
||||
: m_moduleName(name)
|
||||
, m_enabledLogLevel(level)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
isEnabled(LogLevel level) const
|
||||
{
|
||||
// std::cerr << m_moduleName <<
|
||||
// " enabled = " << m_enabledLogLevel
|
||||
// << " level = " << level << std::endl;
|
||||
return (m_enabledLogLevel >= level);
|
||||
}
|
||||
|
||||
void
|
||||
setLogLevel(LogLevel level)
|
||||
{
|
||||
m_enabledLogLevel = level;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
getName() const
|
||||
{
|
||||
return m_moduleName;
|
||||
}
|
||||
|
||||
void
|
||||
setName(const std::string& name)
|
||||
{
|
||||
m_moduleName = name;
|
||||
}
|
||||
|
||||
/// \brief return a string representation of time since epoch: seconds.microseconds
|
||||
static std::string
|
||||
now()
|
||||
{
|
||||
using namespace ndn::time;
|
||||
|
||||
static const microseconds::rep ONE_SECOND = 1000000;
|
||||
microseconds::rep microseconds_since_epoch =
|
||||
duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
|
||||
|
||||
// 10 (whole seconds) + '.' + 6 (fraction) + 1 (\0)
|
||||
char buffer[10 + 1 + 6 + 1];
|
||||
::snprintf(buffer, sizeof(buffer), "%lld.%06lld",
|
||||
static_cast<long long int>(microseconds_since_epoch / ONE_SECOND),
|
||||
static_cast<long long int>(microseconds_since_epoch % ONE_SECOND));
|
||||
|
||||
/// \todo use this version when we enable C++11 to avoid casting
|
||||
// ::snprintf(buffer, sizeof(buffer), "%" PRIdLEAST64 ".%06" PRIdLEAST64,
|
||||
// microseconds_since_epoch / ONE_SECOND,
|
||||
// microseconds_since_epoch % ONE_SECOND);
|
||||
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_moduleName;
|
||||
LogLevel m_enabledLogLevel;
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& output, const Logger& logger)
|
||||
{
|
||||
output << logger.getName();
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#include "core/logger-factory.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
#define NFD_LOG_INIT(name) \
|
||||
static nfd::Logger& g_logger = nfd::LoggerFactory::create(name)
|
||||
|
||||
#define NFD_LOG_INCLASS_DECLARE() \
|
||||
static nfd::Logger& g_logger
|
||||
|
||||
#define NFD_LOG_INCLASS_DEFINE(cls, name) \
|
||||
nfd::Logger& cls::g_logger = nfd::LoggerFactory::create(name)
|
||||
|
||||
#define NFD_LOG_INCLASS_TEMPLATE_DEFINE(cls, name) \
|
||||
template<class T> \
|
||||
nfd::Logger& cls<T>::g_logger = nfd::LoggerFactory::create(name)
|
||||
|
||||
#define NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(cls, specialization, name) \
|
||||
template<> \
|
||||
nfd::Logger& cls<specialization>::g_logger = nfd::LoggerFactory::create(name)
|
||||
|
||||
#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name) \
|
||||
template<> \
|
||||
nfd::Logger& cls<s1, s2>::g_logger = nfd::LoggerFactory::create(name)
|
||||
|
||||
|
||||
#define NFD_LOG(level, expression) \
|
||||
do { \
|
||||
if (g_logger.isEnabled(::nfd::LOG_##level)) \
|
||||
std::clog << ::nfd::Logger::now() << " "#level": " \
|
||||
<< "[" << g_logger << "] " << expression << "\n"; \
|
||||
} while (false)
|
||||
|
||||
#define NFD_LOG_TRACE(expression) NFD_LOG(TRACE, expression)
|
||||
#define NFD_LOG_DEBUG(expression) NFD_LOG(DEBUG, expression)
|
||||
#define NFD_LOG_INFO(expression) NFD_LOG(INFO, expression)
|
||||
#define NFD_LOG_ERROR(expression) NFD_LOG(ERROR, expression)
|
||||
|
||||
// specialize WARN because the message is "WARNING" instead of "WARN"
|
||||
#define NFD_LOG_WARN(expression) \
|
||||
do { \
|
||||
if (g_logger.isEnabled(::nfd::LOG_WARN)) \
|
||||
std::clog << ::nfd::Logger::now() << " WARNING: " \
|
||||
<< "[" << g_logger << "] " << expression << "\n"; \
|
||||
} while (false)
|
||||
|
||||
#define NFD_LOG_FATAL(expression) \
|
||||
do { \
|
||||
std::clog << ::nfd::Logger::now() << " FATAL: " \
|
||||
<< "[" << g_logger << "] " << expression << "\n"; \
|
||||
} while (false)
|
||||
|
||||
} //namespace nfd
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_MAP_VALUE_ITERATOR_H
|
||||
#define NFD_CORE_MAP_VALUE_ITERATOR_H
|
||||
|
||||
#include "common.hpp"
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \class MapValueIterator
|
||||
* \brief ForwardIterator to iterator over map values
|
||||
*/
|
||||
template<typename Map>
|
||||
class MapValueIterator
|
||||
: public boost::transform_iterator<
|
||||
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
||||
typename Map::const_iterator>
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
MapValueIterator(typename Map::const_iterator it)
|
||||
: boost::transform_iterator<
|
||||
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
||||
typename Map::const_iterator>(it, &takeSecond)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
static const typename Map::mapped_type&
|
||||
takeSecond(const typename Map::value_type& pair)
|
||||
{
|
||||
return pair.second;
|
||||
}
|
||||
};
|
||||
|
||||
/** \class MapValueReverseIterator
|
||||
* \brief ReverseIterator to iterator over map values
|
||||
*/
|
||||
template<typename Map>
|
||||
class MapValueReverseIterator
|
||||
: public boost::transform_iterator<
|
||||
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
||||
typename Map::const_reverse_iterator>
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
MapValueReverseIterator(typename Map::const_reverse_iterator it)
|
||||
: boost::transform_iterator<
|
||||
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
||||
typename Map::const_reverse_iterator>(it, &takeSecond)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
static const typename Map::mapped_type&
|
||||
takeSecond(const typename Map::value_type& pair)
|
||||
{
|
||||
return pair.second;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_MAP_VALUE_ITERATOR_H
|
||||
@@ -1,139 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "network-interface.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <arpa/inet.h> // for inet_ntop()
|
||||
#include <netinet/in.h> // for struct sockaddr_in{,6}
|
||||
#include <ifaddrs.h> // for getifaddrs()
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <net/if_arp.h> // for ARPHRD_* constants
|
||||
#include <netpacket/packet.h> // for struct sockaddr_ll
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <net/if_dl.h> // for struct sockaddr_dl
|
||||
#else
|
||||
#error Platform not supported
|
||||
#endif
|
||||
|
||||
NFD_LOG_INIT("NetworkInterfaceInfo");
|
||||
|
||||
namespace nfd {
|
||||
|
||||
std::list< shared_ptr<NetworkInterfaceInfo> >
|
||||
listNetworkInterfaces()
|
||||
{
|
||||
typedef std::map< std::string, shared_ptr<NetworkInterfaceInfo> > InterfacesMap;
|
||||
InterfacesMap ifmap;
|
||||
|
||||
ifaddrs* ifa_list;
|
||||
if (::getifaddrs(&ifa_list) < 0)
|
||||
throw std::runtime_error("getifaddrs() failed");
|
||||
|
||||
for (ifaddrs* ifa = ifa_list; ifa != 0; ifa = ifa->ifa_next)
|
||||
{
|
||||
shared_ptr<NetworkInterfaceInfo> netif;
|
||||
std::string ifname(ifa->ifa_name);
|
||||
InterfacesMap::iterator i = ifmap.find(ifname);
|
||||
if (i == ifmap.end())
|
||||
{
|
||||
netif = make_shared<NetworkInterfaceInfo>();
|
||||
netif->name = ifname;
|
||||
netif->flags = ifa->ifa_flags;
|
||||
ifmap[ifname] = netif;
|
||||
}
|
||||
else
|
||||
{
|
||||
netif = i->second;
|
||||
}
|
||||
|
||||
if (!ifa->ifa_addr)
|
||||
continue;
|
||||
|
||||
switch (ifa->ifa_addr->sa_family)
|
||||
{
|
||||
case AF_INET: {
|
||||
const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
|
||||
char address[INET_ADDRSTRLEN];
|
||||
if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address)))
|
||||
netif->ipv4Addresses.push_back(boost::asio::ip::address_v4::from_string(address));
|
||||
else
|
||||
NFD_LOG_WARN("inet_ntop() failed on " << ifname);
|
||||
}
|
||||
break;
|
||||
case AF_INET6: {
|
||||
const sockaddr_in6* sin6 = reinterpret_cast<sockaddr_in6*>(ifa->ifa_addr);
|
||||
char address[INET6_ADDRSTRLEN];
|
||||
if (::inet_ntop(AF_INET6, &sin6->sin6_addr, address, sizeof(address)))
|
||||
netif->ipv6Addresses.push_back(boost::asio::ip::address_v6::from_string(address));
|
||||
else
|
||||
NFD_LOG_WARN("inet_ntop() failed on " << ifname);
|
||||
}
|
||||
break;
|
||||
#if defined(__linux__)
|
||||
case AF_PACKET: {
|
||||
const sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ifa->ifa_addr);
|
||||
netif->index = sll->sll_ifindex;
|
||||
if (sll->sll_hatype == ARPHRD_ETHER && sll->sll_halen == ethernet::ADDR_LEN)
|
||||
netif->etherAddress = ethernet::Address(sll->sll_addr);
|
||||
else if (sll->sll_hatype != ARPHRD_LOOPBACK)
|
||||
NFD_LOG_WARN("Unrecognized hardware address on " << ifname);
|
||||
}
|
||||
break;
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
case AF_LINK: {
|
||||
const sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(ifa->ifa_addr);
|
||||
netif->index = sdl->sdl_index;
|
||||
netif->etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (netif->isBroadcastCapable() && ifa->ifa_broadaddr != 0)
|
||||
{
|
||||
const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_broadaddr);
|
||||
|
||||
char address[INET_ADDRSTRLEN];
|
||||
if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address)))
|
||||
netif->broadcastAddress = boost::asio::ip::address_v4::from_string(address);
|
||||
else
|
||||
NFD_LOG_WARN("inet_ntop() failed on " << ifname);
|
||||
}
|
||||
}
|
||||
|
||||
::freeifaddrs(ifa_list);
|
||||
|
||||
std::list< shared_ptr<NetworkInterfaceInfo> > list;
|
||||
BOOST_FOREACH(InterfacesMap::value_type elem, ifmap) {
|
||||
list.push_back(elem.second);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,90 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_NETWORK_INTERFACE_HPP
|
||||
#define NFD_CORE_NETWORK_INTERFACE_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "ethernet.hpp"
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class NetworkInterfaceInfo
|
||||
{
|
||||
public:
|
||||
|
||||
int index;
|
||||
std::string name;
|
||||
ethernet::Address etherAddress;
|
||||
std::vector<boost::asio::ip::address_v4> ipv4Addresses;
|
||||
std::vector<boost::asio::ip::address_v6> ipv6Addresses;
|
||||
boost::asio::ip::address_v4 broadcastAddress;
|
||||
unsigned int flags;
|
||||
|
||||
bool
|
||||
isLoopback() const;
|
||||
|
||||
bool
|
||||
isMulticastCapable() const;
|
||||
|
||||
bool
|
||||
isBroadcastCapable() const;
|
||||
|
||||
bool
|
||||
isUp() const;
|
||||
|
||||
};
|
||||
|
||||
inline bool
|
||||
NetworkInterfaceInfo::isLoopback() const
|
||||
{
|
||||
return (flags & IFF_LOOPBACK) != 0;
|
||||
}
|
||||
|
||||
inline bool
|
||||
NetworkInterfaceInfo::isMulticastCapable() const
|
||||
{
|
||||
return (flags & IFF_MULTICAST) != 0;
|
||||
}
|
||||
|
||||
inline bool
|
||||
NetworkInterfaceInfo::isBroadcastCapable() const
|
||||
{
|
||||
return (flags & IFF_BROADCAST) != 0;
|
||||
}
|
||||
|
||||
inline bool
|
||||
NetworkInterfaceInfo::isUp() const
|
||||
{
|
||||
return (flags & IFF_UP) != 0;
|
||||
}
|
||||
|
||||
std::list< shared_ptr<NetworkInterfaceInfo> >
|
||||
listNetworkInterfaces();
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_NETWORK_INTERFACE_HPP
|
||||
@@ -0,0 +1,181 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2018, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "network.hpp"
|
||||
|
||||
#include <boost/utility/value_init.hpp>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
Network::Network() = default;
|
||||
|
||||
Network::Network(const boost::asio::ip::address& minAddress,
|
||||
const boost::asio::ip::address& maxAddress)
|
||||
: m_minAddress(minAddress)
|
||||
, m_maxAddress(maxAddress)
|
||||
{
|
||||
}
|
||||
|
||||
const Network&
|
||||
Network::getMaxRangeV4()
|
||||
{
|
||||
using boost::asio::ip::address_v4;
|
||||
static Network range{address_v4{}, address_v4{0xffffffff}};
|
||||
return range;
|
||||
}
|
||||
|
||||
const Network&
|
||||
Network::getMaxRangeV6()
|
||||
{
|
||||
using boost::asio::ip::address_v6;
|
||||
static address_v6::bytes_type maxV6 = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
|
||||
static Network range{address_v6{}, address_v6{maxV6}};
|
||||
return range;
|
||||
}
|
||||
|
||||
bool
|
||||
Network::isValidCidr(const std::string& cidr)
|
||||
{
|
||||
auto pos = cidr.find('/');
|
||||
if (pos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
boost::lexical_cast<Network>(cidr);
|
||||
return true;
|
||||
}
|
||||
catch (const boost::bad_lexical_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const Network& network)
|
||||
{
|
||||
return os << network.m_minAddress << " <-> " << network.m_maxAddress;
|
||||
}
|
||||
|
||||
std::istream&
|
||||
operator>>(std::istream& is, Network& network)
|
||||
{
|
||||
namespace ip = boost::asio::ip;
|
||||
|
||||
std::string networkStr;
|
||||
is >> networkStr;
|
||||
|
||||
size_t position = networkStr.find('/');
|
||||
if (position == std::string::npos) {
|
||||
try {
|
||||
network.m_minAddress = ip::address::from_string(networkStr);
|
||||
network.m_maxAddress = ip::address::from_string(networkStr);
|
||||
}
|
||||
catch (const boost::system::system_error&) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boost::system::error_code ec;
|
||||
auto address = ip::address::from_string(networkStr.substr(0, position), ec);
|
||||
if (ec) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
|
||||
auto prefixLenStr = networkStr.substr(position + 1);
|
||||
if (!std::all_of(prefixLenStr.begin(), prefixLenStr.end(),
|
||||
[] (unsigned char c) { return std::isdigit(c); })) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
size_t mask;
|
||||
try {
|
||||
mask = boost::lexical_cast<size_t>(prefixLenStr);
|
||||
}
|
||||
catch (const boost::bad_lexical_cast&) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
|
||||
if (address.is_v4()) {
|
||||
if (mask > 32) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
|
||||
ip::address_v4::bytes_type maskBytes = boost::initialized_value;
|
||||
for (size_t i = 0; i < mask; i++) {
|
||||
size_t byteId = i / 8;
|
||||
size_t bitIndex = 7 - i % 8;
|
||||
maskBytes[byteId] |= (1 << bitIndex);
|
||||
}
|
||||
|
||||
ip::address_v4::bytes_type addressBytes = address.to_v4().to_bytes();
|
||||
ip::address_v4::bytes_type min;
|
||||
ip::address_v4::bytes_type max;
|
||||
|
||||
for (size_t i = 0; i < addressBytes.size(); i++) {
|
||||
min[i] = addressBytes[i] & maskBytes[i];
|
||||
max[i] = addressBytes[i] | ~(maskBytes[i]);
|
||||
}
|
||||
|
||||
network.m_minAddress = ip::address_v4(min);
|
||||
network.m_maxAddress = ip::address_v4(max);
|
||||
}
|
||||
else {
|
||||
if (mask > 128) {
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
|
||||
ip::address_v6::bytes_type maskBytes = boost::initialized_value;
|
||||
for (size_t i = 0; i < mask; i++) {
|
||||
size_t byteId = i / 8;
|
||||
size_t bitIndex = 7 - i % 8;
|
||||
maskBytes[byteId] |= (1 << bitIndex);
|
||||
}
|
||||
|
||||
ip::address_v6::bytes_type addressBytes = address.to_v6().to_bytes();
|
||||
ip::address_v6::bytes_type min;
|
||||
ip::address_v6::bytes_type max;
|
||||
|
||||
for (size_t i = 0; i < addressBytes.size(); i++) {
|
||||
min[i] = addressBytes[i] & maskBytes[i];
|
||||
max[i] = addressBytes[i] | ~(maskBytes[i]);
|
||||
}
|
||||
|
||||
network.m_minAddress = ip::address_v6(min);
|
||||
network.m_maxAddress = ip::address_v6(max);
|
||||
}
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_NETWORK_HPP
|
||||
#define NFD_CORE_NETWORK_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
Network();
|
||||
|
||||
Network(const boost::asio::ip::address& minAddress,
|
||||
const boost::asio::ip::address& maxAddress);
|
||||
|
||||
bool
|
||||
doesContain(const boost::asio::ip::address& address) const
|
||||
{
|
||||
return m_minAddress <= address && address <= m_maxAddress;
|
||||
}
|
||||
|
||||
static const Network&
|
||||
getMaxRangeV4();
|
||||
|
||||
static const Network&
|
||||
getMaxRangeV6();
|
||||
|
||||
static bool
|
||||
isValidCidr(const std::string& cidr);
|
||||
|
||||
bool
|
||||
operator==(const Network& rhs) const
|
||||
{
|
||||
return m_minAddress == rhs.m_minAddress && m_maxAddress == rhs.m_maxAddress;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(const Network& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
boost::asio::ip::address m_minAddress;
|
||||
boost::asio::ip::address m_maxAddress;
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const Network& network);
|
||||
|
||||
friend std::istream&
|
||||
operator>>(std::istream& is, Network& network);
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const Network& network);
|
||||
|
||||
std::istream&
|
||||
operator>>(std::istream& is, Network& network);
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_NETWORK_HPP
|
||||
@@ -1,81 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_NOTIFICATION_STREAM_HPP
|
||||
#define NFD_CORE_NOTIFICATION_STREAM_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/encoding-buffer.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief provides a publisher of Notification Stream
|
||||
* \sa http://redmine.named-data.net/projects/nfd/wiki/Notification
|
||||
*/
|
||||
template <class FaceBase>
|
||||
class NotificationStream : noncopyable
|
||||
{
|
||||
public:
|
||||
NotificationStream(FaceBase& face, const Name& prefix, ndn::KeyChain& keyChain)
|
||||
: m_face(face)
|
||||
, m_prefix(prefix)
|
||||
, m_keyChain(keyChain)
|
||||
, m_sequenceNo(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~NotificationStream()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T> void
|
||||
postNotification(const T& notification)
|
||||
{
|
||||
Name dataName = m_prefix;
|
||||
dataName.appendSequenceNumber(m_sequenceNo);
|
||||
|
||||
shared_ptr<Data> data = make_shared<Data>(dataName);
|
||||
data->setContent(notification.wireEncode());
|
||||
data->setFreshnessPeriod(time::seconds(1));
|
||||
|
||||
m_keyChain.sign(*data);
|
||||
m_face.put(*data);
|
||||
|
||||
++m_sequenceNo;
|
||||
}
|
||||
|
||||
private:
|
||||
FaceBase& m_face;
|
||||
const Name m_prefix;
|
||||
ndn::KeyChain& m_keyChain;
|
||||
uint64_t m_sequenceNo;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_NOTIFICATION_STREAM_HPP
|
||||
@@ -1,195 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "privilege-helper.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT("PrivilegeHelper");
|
||||
|
||||
uid_t PrivilegeHelper::s_normalUid = ::geteuid();
|
||||
gid_t PrivilegeHelper::s_normalGid = ::getegid();
|
||||
|
||||
uid_t PrivilegeHelper::s_privilegedUid = ::geteuid();
|
||||
gid_t PrivilegeHelper::s_privilegedGid = ::getegid();
|
||||
|
||||
void
|
||||
PrivilegeHelper::initialize(const std::string& userName, const std::string& groupName)
|
||||
{
|
||||
static const size_t MAX_GROUP_BUFFER_SIZE = 16384; // 16kB
|
||||
static const size_t MAX_PASSWD_BUFFER_SIZE = 16384;
|
||||
|
||||
static const size_t FALLBACK_GROUP_BUFFER_SIZE = 1024;
|
||||
static const size_t FALLBACK_PASSWD_BUFFER_SIZE = 1024;
|
||||
|
||||
NFD_LOG_TRACE("initializing privilege helper with user \"" << userName << "\""
|
||||
<< " group \"" << groupName << "\"");
|
||||
|
||||
// workflow from man getpwnam_r
|
||||
|
||||
if (!groupName.empty())
|
||||
{
|
||||
static int groupSize = ::sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
|
||||
if (groupSize == -1)
|
||||
{
|
||||
groupSize = FALLBACK_GROUP_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
std::vector<char> groupBuffer(groupSize);
|
||||
struct group group;
|
||||
struct group* groupResult = 0;
|
||||
|
||||
int errorCode = getgrnam_r(groupName.c_str(), &group,
|
||||
&groupBuffer[0], groupSize, &groupResult);
|
||||
|
||||
while (errorCode == ERANGE)
|
||||
{
|
||||
if (groupBuffer.size() * 2 > MAX_GROUP_BUFFER_SIZE)
|
||||
{
|
||||
throw PrivilegeHelper::Error("Cannot allocate large enough buffer for struct group");
|
||||
}
|
||||
|
||||
groupBuffer.resize(groupBuffer.size() * 2);
|
||||
|
||||
errorCode = getgrnam_r(groupName.c_str(), &group,
|
||||
&groupBuffer[0], groupBuffer.size(), &groupResult);
|
||||
}
|
||||
|
||||
if (errorCode != 0 || !groupResult)
|
||||
{
|
||||
throw PrivilegeHelper::Error("Failed to get gid for \"" + groupName + "\"");
|
||||
}
|
||||
|
||||
s_normalGid = group.gr_gid;
|
||||
}
|
||||
|
||||
if (!userName.empty())
|
||||
{
|
||||
static int passwdSize = ::sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
|
||||
if (passwdSize == -1)
|
||||
{
|
||||
passwdSize = FALLBACK_PASSWD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
std::vector<char> passwdBuffer(passwdSize);
|
||||
struct passwd passwd;
|
||||
struct passwd* passwdResult = 0;
|
||||
|
||||
int errorCode =
|
||||
getpwnam_r(userName.c_str(), &passwd,
|
||||
&passwdBuffer[0], passwdBuffer.size(), &passwdResult);
|
||||
|
||||
while (errorCode == ERANGE)
|
||||
{
|
||||
if (passwdBuffer.size() * 2 > MAX_PASSWD_BUFFER_SIZE)
|
||||
{
|
||||
throw PrivilegeHelper::Error("Cannot allocate large enough buffer for struct passwd");
|
||||
}
|
||||
|
||||
passwdBuffer.resize(passwdBuffer.size() * 2);
|
||||
|
||||
errorCode = getpwnam_r(userName.c_str(), &passwd,
|
||||
&passwdBuffer[0], passwdBuffer.size(), &passwdResult);
|
||||
}
|
||||
|
||||
if (errorCode != 0 || !passwdResult)
|
||||
{
|
||||
throw PrivilegeHelper::Error("Failed to get uid for \"" + userName + "\"");
|
||||
}
|
||||
|
||||
s_normalUid = passwd.pw_uid;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::drop()
|
||||
{
|
||||
NFD_LOG_TRACE("dropping to effective gid=" << s_normalGid);
|
||||
if (::setegid(s_normalGid) != 0)
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Failed to drop to effective gid=" << s_normalGid;
|
||||
|
||||
throw PrivilegeHelper::Error(error.str());
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("dropping to effective uid=" << s_normalUid);
|
||||
if (::seteuid(s_normalUid) != 0)
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Failed to drop to effective uid=" << s_normalUid;
|
||||
|
||||
throw PrivilegeHelper::Error(error.str());
|
||||
}
|
||||
|
||||
NFD_LOG_INFO("dropped to effective uid=" << ::geteuid() << " gid=" << ::getegid());
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::raise()
|
||||
{
|
||||
NFD_LOG_TRACE("elevating to effective uid=" << s_privilegedUid);
|
||||
if (::seteuid(s_privilegedUid) != 0)
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Failed to elevate to effective uid=" << s_privilegedUid;
|
||||
|
||||
throw PrivilegeHelper::Error(error.str());
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("elevating to effective gid=" << s_privilegedGid);
|
||||
if (::setegid(s_privilegedGid) != 0)
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Failed to elevate to effective gid=" << s_privilegedGid;
|
||||
|
||||
throw PrivilegeHelper::Error(error.str());
|
||||
}
|
||||
NFD_LOG_INFO("elevated to effective uid=" << ::geteuid() << " gid=" << ::getegid());
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::runElevated(function<void()> f)
|
||||
{
|
||||
raise();
|
||||
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
drop();
|
||||
throw;
|
||||
}
|
||||
drop();
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,49 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file declares the global random number generator
|
||||
* All random numbers in NFD should use this global random number generator,
|
||||
* so that the generator can be properly seeded when necessary.
|
||||
*
|
||||
* This random number generator is not suitable for security purposes;
|
||||
* security-critical code should use CryptoPP random number generator instead.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_RANDOM_HPP
|
||||
#define NFD_CORE_RANDOM_HPP
|
||||
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \return the global random number generator instance
|
||||
*/
|
||||
boost::random::mt19937&
|
||||
getGlobalRng();
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_RANDOM_HPP
|
||||
@@ -1,214 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_RESOLVER_H
|
||||
#define NFD_CORE_RESOLVER_H
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "core/scheduler.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace resolver {
|
||||
|
||||
typedef function<bool (const boost::asio::ip::address& address)> AddressSelector;
|
||||
|
||||
struct AnyAddress {
|
||||
bool
|
||||
operator()(const boost::asio::ip::address& address)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Ipv4Address {
|
||||
bool
|
||||
operator()(const boost::asio::ip::address& address)
|
||||
{
|
||||
return address.is_v4();
|
||||
}
|
||||
};
|
||||
|
||||
struct Ipv6Address {
|
||||
bool
|
||||
operator()(const boost::asio::ip::address& address)
|
||||
{
|
||||
return address.is_v6();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace resolver
|
||||
|
||||
template<class Protocol>
|
||||
class Resolver
|
||||
{
|
||||
public:
|
||||
struct Error : public std::runtime_error
|
||||
{
|
||||
Error(const std::string& what) : std::runtime_error(what) {}
|
||||
};
|
||||
|
||||
typedef function<void (const typename Protocol::endpoint& endpoint)> SuccessCallback;
|
||||
typedef function<void (const std::string& reason)> ErrorCallback;
|
||||
|
||||
typedef boost::asio::ip::basic_resolver< Protocol > resolver;
|
||||
|
||||
/** \brief Asynchronously resolve host and port
|
||||
*
|
||||
* If an address selector predicate is specified, then each resolved IP address
|
||||
* is checked against the predicate.
|
||||
*
|
||||
* Available address selector predicates:
|
||||
*
|
||||
* - resolver::AnyAddress()
|
||||
* - resolver::Ipv4Address()
|
||||
* - resolver::Ipv6Address()
|
||||
*/
|
||||
static void
|
||||
asyncResolve(const std::string& host, const std::string& port,
|
||||
const SuccessCallback& onSuccess,
|
||||
const ErrorCallback& onError,
|
||||
const nfd::resolver::AddressSelector& addressSelector = nfd::resolver::AnyAddress(),
|
||||
const time::seconds& timeout = time::seconds(4))
|
||||
{
|
||||
shared_ptr<Resolver> resolver =
|
||||
shared_ptr<Resolver>(new Resolver(onSuccess, onError,
|
||||
addressSelector));
|
||||
|
||||
resolver->asyncResolve(host, port, timeout, resolver);
|
||||
// resolver will be destroyed when async operation finishes or global IO service stops
|
||||
}
|
||||
|
||||
/** \brief Synchronously resolve host and port
|
||||
*
|
||||
* If an address selector predicate is specified, then each resolved IP address
|
||||
* is checked against the predicate.
|
||||
*
|
||||
* Available address selector predicates:
|
||||
*
|
||||
* - resolver::AnyAddress()
|
||||
* - resolver::Ipv4Address()
|
||||
* - resolver::Ipv6Address()
|
||||
*/
|
||||
static typename Protocol::endpoint
|
||||
syncResolve(const std::string& host, const std::string& port,
|
||||
const nfd::resolver::AddressSelector& addressSelector = nfd::resolver::AnyAddress())
|
||||
{
|
||||
Resolver resolver(SuccessCallback(), ErrorCallback(), addressSelector);
|
||||
|
||||
typename resolver::query query(host, port
|
||||
#if not defined(__FreeBSD__)
|
||||
, resolver::query::all_matching
|
||||
#endif
|
||||
);
|
||||
|
||||
typename resolver::iterator remoteEndpoint = resolver.m_resolver.resolve(query);
|
||||
typename resolver::iterator end;
|
||||
for (; remoteEndpoint != end; ++remoteEndpoint)
|
||||
{
|
||||
if (addressSelector(typename Protocol::endpoint(*remoteEndpoint).address()))
|
||||
return *remoteEndpoint;
|
||||
}
|
||||
throw Error("No endpoint matching the specified address selector found");
|
||||
}
|
||||
|
||||
private:
|
||||
Resolver(const SuccessCallback& onSuccess,
|
||||
const ErrorCallback& onError,
|
||||
const nfd::resolver::AddressSelector& addressSelector)
|
||||
: m_resolver(getGlobalIoService())
|
||||
, m_addressSelector(addressSelector)
|
||||
, m_onSuccess(onSuccess)
|
||||
, m_onError(onError)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
asyncResolve(const std::string& host, const std::string& port,
|
||||
const time::seconds& timeout,
|
||||
const shared_ptr<Resolver>& self)
|
||||
{
|
||||
typename resolver::query query(host, port
|
||||
#if not defined(__FreeBSD__)
|
||||
, resolver::query::all_matching
|
||||
#endif
|
||||
);
|
||||
|
||||
m_resolver.async_resolve(query,
|
||||
bind(&Resolver::onResolveSuccess, this, _1, _2, self));
|
||||
|
||||
m_resolveTimeout = scheduler::schedule(timeout,
|
||||
bind(&Resolver::onResolveError, this,
|
||||
"Timeout", self));
|
||||
}
|
||||
|
||||
void
|
||||
onResolveSuccess(const boost::system::error_code& error,
|
||||
typename resolver::iterator remoteEndpoint,
|
||||
const shared_ptr<Resolver>& self)
|
||||
{
|
||||
scheduler::cancel(m_resolveTimeout);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error == boost::system::errc::operation_canceled)
|
||||
return;
|
||||
|
||||
return m_onError("Remote endpoint hostname or port cannot be resolved: " +
|
||||
error.category().message(error.value()));
|
||||
}
|
||||
|
||||
typename resolver::iterator end;
|
||||
for (; remoteEndpoint != end; ++remoteEndpoint)
|
||||
{
|
||||
if (m_addressSelector(typename Protocol::endpoint(*remoteEndpoint).address()))
|
||||
return m_onSuccess(*remoteEndpoint);
|
||||
}
|
||||
|
||||
m_onError("No endpoint matching the specified address selector found");
|
||||
}
|
||||
|
||||
void
|
||||
onResolveError(const std::string& errorInfo,
|
||||
const shared_ptr<Resolver>& self)
|
||||
{
|
||||
m_resolver.cancel();
|
||||
m_onError(errorInfo);
|
||||
}
|
||||
|
||||
private:
|
||||
resolver m_resolver;
|
||||
EventId m_resolveTimeout;
|
||||
|
||||
nfd::resolver::AddressSelector m_addressSelector;
|
||||
SuccessCallback m_onSuccess;
|
||||
ErrorCallback m_onError;
|
||||
};
|
||||
|
||||
typedef Resolver<boost::asio::ip::tcp> TcpResolver;
|
||||
typedef Resolver<boost::asio::ip::udp> UdpResolver;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_RESOLVER_H
|
||||
@@ -1,61 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "global-io.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace scheduler {
|
||||
|
||||
static shared_ptr<Scheduler> g_scheduler;
|
||||
|
||||
inline Scheduler&
|
||||
getGlobalScheduler()
|
||||
{
|
||||
if (!static_cast<bool>(g_scheduler)) {
|
||||
g_scheduler = make_shared<Scheduler>(ref(getGlobalIoService()));
|
||||
}
|
||||
return *g_scheduler;
|
||||
}
|
||||
|
||||
EventId
|
||||
schedule(const time::nanoseconds& after, const Scheduler::Event& event)
|
||||
{
|
||||
return getGlobalScheduler().scheduleEvent(after, event);
|
||||
}
|
||||
|
||||
void
|
||||
cancel(const EventId& eventId)
|
||||
{
|
||||
getGlobalScheduler().cancelEvent(eventId);
|
||||
}
|
||||
|
||||
void
|
||||
resetGlobalScheduler()
|
||||
{
|
||||
g_scheduler.reset();
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace nfd
|
||||
@@ -1,57 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_CORE_SCHEDULER_HPP
|
||||
#define NFD_CORE_SCHEDULER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace scheduler {
|
||||
|
||||
using ndn::Scheduler;
|
||||
|
||||
/** \class EventId
|
||||
* \brief Opaque type (shared_ptr) representing ID of a scheduled event
|
||||
*/
|
||||
using ndn::EventId;
|
||||
|
||||
/** \brief schedule an event
|
||||
*/
|
||||
EventId
|
||||
schedule(const time::nanoseconds& after, const Scheduler::Event& event);
|
||||
|
||||
/** \brief cancel a scheduled event
|
||||
*/
|
||||
void
|
||||
cancel(const EventId& eventId);
|
||||
|
||||
} // namespace scheduler
|
||||
|
||||
using scheduler::EventId;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_SCHEDULER_HPP
|
||||
@@ -1,120 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_SEGMENT_PUBLISHER_HPP
|
||||
#define NFD_CORE_SEGMENT_PUBLISHER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/encoding-buffer.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief provides a publisher of Status Dataset or other segmented octet stream
|
||||
* \sa http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
|
||||
*/
|
||||
template <class FaceBase>
|
||||
class SegmentPublisher : noncopyable
|
||||
{
|
||||
public:
|
||||
SegmentPublisher(FaceBase& face, const Name& prefix, ndn::KeyChain& keyChain)
|
||||
: m_face(face)
|
||||
, m_prefix(prefix)
|
||||
, m_keyChain(keyChain)
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~SegmentPublisher()
|
||||
{
|
||||
}
|
||||
|
||||
static size_t
|
||||
getMaxSegmentSize()
|
||||
{
|
||||
static const size_t MAX_SEGMENT_SIZE = ndn::MAX_NDN_PACKET_SIZE >> 1;
|
||||
return MAX_SEGMENT_SIZE;
|
||||
}
|
||||
|
||||
void
|
||||
publish()
|
||||
{
|
||||
ndn::EncodingBuffer buffer;
|
||||
generate(buffer);
|
||||
|
||||
const uint8_t* rawBuffer = buffer.buf();
|
||||
const uint8_t* segmentBegin = rawBuffer;
|
||||
const uint8_t* end = rawBuffer + buffer.size();
|
||||
|
||||
Name segmentPrefix(m_prefix);
|
||||
segmentPrefix.appendVersion();
|
||||
|
||||
uint64_t segmentNo = 0;
|
||||
do {
|
||||
const uint8_t* segmentEnd = segmentBegin + getMaxSegmentSize();
|
||||
if (segmentEnd > end) {
|
||||
segmentEnd = end;
|
||||
}
|
||||
|
||||
Name segmentName(segmentPrefix);
|
||||
segmentName.appendSegment(segmentNo);
|
||||
|
||||
shared_ptr<Data> data = make_shared<Data>(segmentName);
|
||||
data->setContent(segmentBegin, segmentEnd - segmentBegin);
|
||||
|
||||
segmentBegin = segmentEnd;
|
||||
if (segmentBegin >= end) {
|
||||
data->setFinalBlockId(segmentName[-1]);
|
||||
}
|
||||
|
||||
publishSegment(data);
|
||||
++segmentNo;
|
||||
} while (segmentBegin < end);
|
||||
}
|
||||
|
||||
protected:
|
||||
/** \brief In a derived class, write the octets into outBuffer.
|
||||
*/
|
||||
virtual size_t
|
||||
generate(ndn::EncodingBuffer& outBuffer) = 0;
|
||||
|
||||
private:
|
||||
void
|
||||
publishSegment(shared_ptr<Data>& data)
|
||||
{
|
||||
m_keyChain.sign(*data);
|
||||
m_face.put(*data);
|
||||
}
|
||||
|
||||
private:
|
||||
FaceBase& m_face;
|
||||
const Name m_prefix;
|
||||
ndn::KeyChain& m_keyChain;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_SEGMENT_PUBLISHER_HPP
|
||||
@@ -1,11 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -20,16 +21,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#include "strategy-info-host.hpp"
|
||||
#include "core/version.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
void
|
||||
StrategyInfoHost::clearStrategyInfo()
|
||||
{
|
||||
m_strategyInfo.reset();
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
const char NFD_VERSION_STRING[] = "@VERSION_STRING@";
|
||||
const char NFD_VERSION_BUILD_STRING[] = "@VERSION_BUILD@";
|
||||
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_VERSION_HPP
|
||||
#define NFD_CORE_VERSION_HPP
|
||||
|
||||
// NFD version follows Semantic Versioning 2.0.0 based on year and month of the release
|
||||
// https://semver.org/spec/v2.0.0.html
|
||||
//
|
||||
// To change version number, modify the VERSION variable in the top-level wscript.
|
||||
|
||||
/**
|
||||
* \brief NFD version represented as an integer.
|
||||
*
|
||||
* Equivalent to: #NFD_VERSION_MAJOR*1000000 + #NFD_VERSION_MINOR*1000 + #NFD_VERSION_PATCH
|
||||
*/
|
||||
#define NFD_VERSION @VERSION@
|
||||
|
||||
/// The major version of NFD
|
||||
#define NFD_VERSION_MAJOR @VERSION_MAJOR@
|
||||
/// The minor version of NFD
|
||||
#define NFD_VERSION_MINOR @VERSION_MINOR@
|
||||
/// The patch version of NFD
|
||||
#define NFD_VERSION_PATCH @VERSION_PATCH@
|
||||
|
||||
/**
|
||||
* \brief NFD version represented as a string.
|
||||
*
|
||||
* Format:
|
||||
* @code
|
||||
* MAJOR.MINOR.PATCH
|
||||
* @endcode
|
||||
*/
|
||||
extern const char NFD_VERSION_STRING[];
|
||||
|
||||
/**
|
||||
* \brief NFD version string, including git commit information if NFD is build from a
|
||||
* specific git commit.
|
||||
*
|
||||
* #NFD_VERSION_BUILD_STRING is obtained using the following command (`NFD-` prefix is
|
||||
* afterwards removed): ``git describe --match 'NFD-*'``
|
||||
*
|
||||
* When NFD is not built from git, #NFD_VERSION_BUILD_STRING equals #NFD_VERSION_STRING.
|
||||
*
|
||||
* Format:
|
||||
* @code
|
||||
* MAJOR.MINOR(.PATCH)(-release-candidate-tag)(-(number-of-commits-since-tag)-COMMIT-HASH)
|
||||
* @endcode
|
||||
*
|
||||
* Example: 2022.02-1-g5c86570
|
||||
*/
|
||||
extern const char NFD_VERSION_BUILD_STRING[];
|
||||
|
||||
#endif // NFD_CORE_VERSION_HPP
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,11 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -20,17 +21,21 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#include "config-file.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "common/config-file.hpp"
|
||||
|
||||
#include <boost/property_tree/info_parser.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT("ConfigFile");
|
||||
ConfigFile::ConfigFile(UnknownConfigSectionHandler unknownSectionCallback)
|
||||
: m_unknownSectionCallback(unknownSectionCallback)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ConfigFile::throwErrorOnUnknownSection(const std::string& filename,
|
||||
@@ -38,11 +43,8 @@ ConfigFile::throwErrorOnUnknownSection(const std::string& filename,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun)
|
||||
{
|
||||
std::string msg = "Error processing configuration file ";
|
||||
msg += filename;
|
||||
msg += ": no module subscribed for section \"" + sectionName + "\"";
|
||||
|
||||
throw ConfigFile::Error(msg);
|
||||
NDN_THROW(Error("Error processing configuration file " + filename +
|
||||
": no module subscribed for section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -54,9 +56,21 @@ ConfigFile::ignoreUnknownSection(const std::string& filename,
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(UnknownConfigSectionHandler unknownSectionCallback)
|
||||
: m_unknownSectionCallback(unknownSectionCallback)
|
||||
bool
|
||||
ConfigFile::parseYesNo(const ConfigSection& node, const std::string& key,
|
||||
const std::string& sectionName)
|
||||
{
|
||||
auto value = node.get_value<std::string>();
|
||||
|
||||
if (value == "yes") {
|
||||
return true;
|
||||
}
|
||||
else if (value == "no") {
|
||||
return false;
|
||||
}
|
||||
|
||||
NDN_THROW(Error("Invalid value '" + value + "' for option '" +
|
||||
key + "' in section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -69,14 +83,10 @@ ConfigFile::addSectionHandler(const std::string& sectionName,
|
||||
void
|
||||
ConfigFile::parse(const std::string& filename, bool isDryRun)
|
||||
{
|
||||
std::ifstream inputFile;
|
||||
inputFile.open(filename.c_str());
|
||||
if (!inputFile.good() || !inputFile.is_open())
|
||||
{
|
||||
std::string msg = "Failed to read configuration file: ";
|
||||
msg += filename;
|
||||
throw Error(msg);
|
||||
}
|
||||
std::ifstream inputFile(filename);
|
||||
if (!inputFile.good() || !inputFile.is_open()) {
|
||||
NDN_THROW(Error("Failed to read configuration file " + filename));
|
||||
}
|
||||
parse(inputFile, isDryRun, filename);
|
||||
inputFile.close();
|
||||
}
|
||||
@@ -88,56 +98,41 @@ ConfigFile::parse(const std::string& input, bool isDryRun, const std::string& fi
|
||||
parse(inputStream, isDryRun, filename);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConfigFile::parse(std::istream& input, bool isDryRun, const std::string& filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::property_tree::read_info(input, m_global);
|
||||
}
|
||||
catch (const boost::property_tree::info_parser_error& error)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "Failed to parse configuration file";
|
||||
msg << " " << filename;
|
||||
msg << " " << error.message() << " line " << error.line();
|
||||
throw Error(msg.str());
|
||||
}
|
||||
try {
|
||||
boost::property_tree::read_info(input, m_global);
|
||||
}
|
||||
catch (const boost::property_tree::info_parser_error& error) {
|
||||
NDN_THROW(Error("Failed to parse configuration file " + filename +
|
||||
": " + error.message() + " on line " + to_string(error.line())));
|
||||
}
|
||||
|
||||
process(isDryRun, filename);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigFile::process(bool isDryRun, const std::string& filename)
|
||||
ConfigFile::parse(const ConfigSection& config, bool isDryRun, const std::string& filename)
|
||||
{
|
||||
m_global = config;
|
||||
process(isDryRun, filename);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigFile::process(bool isDryRun, const std::string& filename) const
|
||||
{
|
||||
BOOST_ASSERT(!filename.empty());
|
||||
// NFD_LOG_DEBUG("processing..." << ((isDryRun)?("dry run"):("")));
|
||||
|
||||
if (m_global.begin() == m_global.end())
|
||||
{
|
||||
std::string msg = "Error processing configuration file: ";
|
||||
msg += filename;
|
||||
msg += " no data";
|
||||
throw Error(msg);
|
||||
for (const auto& i : m_global) {
|
||||
try {
|
||||
const ConfigSectionHandler& subscriber = m_subscriptions.at(i.first);
|
||||
subscriber(i.second, isDryRun, filename);
|
||||
}
|
||||
|
||||
for (ConfigSection::const_iterator i = m_global.begin(); i != m_global.end(); ++i)
|
||||
{
|
||||
const std::string& sectionName = i->first;
|
||||
const ConfigSection& section = i->second;
|
||||
|
||||
SubscriptionTable::iterator subscriberIt = m_subscriptions.find(sectionName);
|
||||
if (subscriberIt != m_subscriptions.end())
|
||||
{
|
||||
ConfigSectionHandler subscriber = subscriberIt->second;
|
||||
subscriber(section, isDryRun, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_unknownSectionCallback(filename, sectionName, section, isDryRun);
|
||||
}
|
||||
catch (const std::out_of_range&) {
|
||||
m_unknownSectionCallback(filename, i.first, i.second, isDryRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,199 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
#define NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief a config file section
|
||||
*/
|
||||
using ConfigSection = boost::property_tree::ptree;
|
||||
|
||||
/** \brief an optional config file section
|
||||
*/
|
||||
using OptionalConfigSection = boost::optional<const ConfigSection&>;
|
||||
|
||||
/** \brief callback to process a config file section
|
||||
*/
|
||||
using ConfigSectionHandler = std::function<void(const ConfigSection& section, bool isDryRun,
|
||||
const std::string& filename)>;
|
||||
|
||||
/** \brief callback to process a config file section without a \p ConfigSectionHandler
|
||||
*/
|
||||
using UnknownConfigSectionHandler = std::function<void(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun)>;
|
||||
|
||||
/** \brief configuration file parsing utility
|
||||
*/
|
||||
class ConfigFile : noncopyable
|
||||
{
|
||||
public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
explicit
|
||||
ConfigFile(UnknownConfigSectionHandler unknownSectionCallback = throwErrorOnUnknownSection);
|
||||
|
||||
public: // unknown section handlers
|
||||
static void
|
||||
throwErrorOnUnknownSection(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun);
|
||||
|
||||
static void
|
||||
ignoreUnknownSection(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun);
|
||||
|
||||
public: // parse helpers
|
||||
/** \brief parse a config option that can be either "yes" or "no"
|
||||
* \retval true "yes"
|
||||
* \retval false "no"
|
||||
* \throw Error the value is neither "yes" nor "no"
|
||||
*/
|
||||
static bool
|
||||
parseYesNo(const ConfigSection& node, const std::string& key, const std::string& sectionName);
|
||||
|
||||
static bool
|
||||
parseYesNo(const ConfigSection::value_type& option, const std::string& sectionName)
|
||||
{
|
||||
return parseYesNo(option.second, option.first, sectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief parse a numeric (integral or floating point) config option
|
||||
* \tparam T an arithmetic type
|
||||
*
|
||||
* \return the numeric value of the parsed option
|
||||
* \throw Error the value cannot be converted to the specified type
|
||||
*/
|
||||
template<typename T>
|
||||
static T
|
||||
parseNumber(const ConfigSection& node, const std::string& key, const std::string& sectionName)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "T must be an arithmetic type");
|
||||
|
||||
boost::optional<T> value = node.get_value_optional<T>();
|
||||
// Unsigned logic is workaround for https://redmine.named-data.net/issues/4489
|
||||
if (value &&
|
||||
(std::is_signed<T>() || node.get_value<std::string>().find("-") == std::string::npos)) {
|
||||
return *value;
|
||||
}
|
||||
NDN_THROW(Error("Invalid value '" + node.get_value<std::string>() +
|
||||
"' for option '" + key + "' in section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T
|
||||
parseNumber(const ConfigSection::value_type& option, const std::string& sectionName)
|
||||
{
|
||||
return parseNumber<T>(option.second, option.first, sectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief check that a value is within the inclusive range [min, max]
|
||||
* \throw Error the value is out of the acceptable range
|
||||
*/
|
||||
template<typename T>
|
||||
static void
|
||||
checkRange(T value, T min, T max, const std::string& key, const std::string& sectionName)
|
||||
{
|
||||
static_assert(std::is_integral<T>::value, "T must be an integral type");
|
||||
|
||||
if (value < min || value > max) {
|
||||
NDN_THROW(Error("Invalid value '" + to_string(value) + "' for option '" + key +
|
||||
"' in section '" + sectionName + "': out of acceptable range [" +
|
||||
to_string(min) + ", " + to_string(max) + "]"));
|
||||
}
|
||||
}
|
||||
|
||||
public: // setup and parsing
|
||||
/// \brief setup notification of configuration file sections
|
||||
void
|
||||
addSectionHandler(const std::string& sectionName,
|
||||
ConfigSectionHandler subscriber);
|
||||
|
||||
/**
|
||||
* \param filename file to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \throws ConfigFile::Error if file not found
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(const std::string& filename, bool isDryRun);
|
||||
|
||||
/**
|
||||
* \param input configuration (as a string) to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \param filename logical filename of the config file, can appear in error messages
|
||||
* \throws ConfigFile::Error if file not found
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(const std::string& input, bool isDryRun, const std::string& filename);
|
||||
|
||||
/**
|
||||
* \param input stream to parse
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \param filename logical filename of the config file, can appear in error messages
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(std::istream& input, bool isDryRun, const std::string& filename);
|
||||
|
||||
/**
|
||||
* \param config ConfigSection that needs to be processed
|
||||
* \param isDryRun true if performing a dry run of configuration, false otherwise
|
||||
* \param filename logical filename of the config file, can appear in error messages
|
||||
* \throws ConfigFile::Error if parse error
|
||||
*/
|
||||
void
|
||||
parse(const ConfigSection& config, bool isDryRun, const std::string& filename);
|
||||
|
||||
private:
|
||||
void
|
||||
process(bool isDryRun, const std::string& filename) const;
|
||||
|
||||
private:
|
||||
UnknownConfigSectionHandler m_unknownSectionCallback;
|
||||
std::map<std::string, ConfigSectionHandler> m_subscriptions;
|
||||
ConfigSection m_global;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
#define NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief represents a counter that encloses an integer value
|
||||
*
|
||||
* SimpleCounter is noncopyable, because increment should be called on the counter,
|
||||
* not a copy of it; it's implicitly convertible to an integral type to be observed
|
||||
*/
|
||||
class SimpleCounter : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef uint64_t rep;
|
||||
|
||||
/** \brief observe the counter
|
||||
*/
|
||||
operator rep() const noexcept
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/** \brief replace the counter value
|
||||
*/
|
||||
void
|
||||
set(rep value) noexcept
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
rep m_value = 0;
|
||||
};
|
||||
|
||||
/** \brief represents a counter of number of packets
|
||||
*
|
||||
* \warning The counter value may wrap after exceeding the range of underlying integer type.
|
||||
*/
|
||||
class PacketCounter : public SimpleCounter
|
||||
{
|
||||
public:
|
||||
/** \brief increment the counter by one
|
||||
*/
|
||||
PacketCounter&
|
||||
operator++() noexcept
|
||||
{
|
||||
++m_value;
|
||||
return *this;
|
||||
}
|
||||
// postfix ++ operator is not provided because it's not needed
|
||||
};
|
||||
|
||||
/** \brief represents a counter of number of bytes
|
||||
*
|
||||
* \warning The counter value may wrap after exceeding the range of underlying integer type.
|
||||
*/
|
||||
class ByteCounter : public SimpleCounter
|
||||
{
|
||||
public:
|
||||
/** \brief increase the counter
|
||||
*/
|
||||
ByteCounter&
|
||||
operator+=(rep n) noexcept
|
||||
{
|
||||
m_value += n;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/** \brief provides a counter that observes the size of a table
|
||||
* \tparam T a type that provides a size() const member function
|
||||
*
|
||||
* if table not specified in constructor, it can be added later by invoking observe()
|
||||
*/
|
||||
template<typename T>
|
||||
class SizeCounter : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef size_t Rep;
|
||||
|
||||
explicit constexpr
|
||||
SizeCounter(const T* table = nullptr) noexcept
|
||||
: m_table(table)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
observe(const T* table) noexcept
|
||||
{
|
||||
m_table = table;
|
||||
}
|
||||
|
||||
/** \brief observe the counter
|
||||
*/
|
||||
operator Rep() const
|
||||
{
|
||||
BOOST_ASSERT(m_table != nullptr);
|
||||
return m_table->size();
|
||||
}
|
||||
|
||||
private:
|
||||
const T* m_table;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
@@ -0,0 +1,100 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common/global.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
static thread_local unique_ptr<boost::asio::io_service> g_ioService;
|
||||
static thread_local unique_ptr<Scheduler> g_scheduler;
|
||||
static boost::asio::io_service* g_mainIoService = nullptr;
|
||||
static boost::asio::io_service* g_ribIoService = nullptr;
|
||||
|
||||
boost::asio::io_service&
|
||||
getGlobalIoService()
|
||||
{
|
||||
if (g_ioService == nullptr) {
|
||||
g_ioService = make_unique<boost::asio::io_service>();
|
||||
}
|
||||
return *g_ioService;
|
||||
}
|
||||
|
||||
Scheduler&
|
||||
getScheduler()
|
||||
{
|
||||
if (g_scheduler == nullptr) {
|
||||
g_scheduler = make_unique<Scheduler>(getGlobalIoService());
|
||||
}
|
||||
return *g_scheduler;
|
||||
}
|
||||
|
||||
#ifdef NFD_WITH_TESTS
|
||||
void
|
||||
resetGlobalIoService()
|
||||
{
|
||||
g_scheduler.reset();
|
||||
g_ioService.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::asio::io_service&
|
||||
getMainIoService()
|
||||
{
|
||||
BOOST_ASSERT(g_mainIoService != nullptr);
|
||||
return *g_mainIoService;
|
||||
}
|
||||
|
||||
boost::asio::io_service&
|
||||
getRibIoService()
|
||||
{
|
||||
BOOST_ASSERT(g_ribIoService != nullptr);
|
||||
return *g_ribIoService;
|
||||
}
|
||||
|
||||
void
|
||||
setMainIoService(boost::asio::io_service* mainIo)
|
||||
{
|
||||
g_mainIoService = mainIo;
|
||||
}
|
||||
|
||||
void
|
||||
setRibIoService(boost::asio::io_service* ribIo)
|
||||
{
|
||||
g_ribIoService = ribIo;
|
||||
}
|
||||
|
||||
void
|
||||
runOnMainIoService(const std::function<void()>& f)
|
||||
{
|
||||
getMainIoService().post(f);
|
||||
}
|
||||
|
||||
void
|
||||
runOnRibIoService(const std::function<void()>& f)
|
||||
{
|
||||
getRibIoService().post(f);
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,75 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_DAEMON_COMMON_GLOBAL_HPP
|
||||
#define NFD_DAEMON_COMMON_GLOBAL_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief Returns the global io_service instance for the calling thread.
|
||||
*/
|
||||
boost::asio::io_service&
|
||||
getGlobalIoService();
|
||||
|
||||
/** \brief Returns the global Scheduler instance for the calling thread.
|
||||
*/
|
||||
Scheduler&
|
||||
getScheduler();
|
||||
|
||||
boost::asio::io_service&
|
||||
getMainIoService();
|
||||
|
||||
boost::asio::io_service&
|
||||
getRibIoService();
|
||||
|
||||
void
|
||||
setMainIoService(boost::asio::io_service* mainIo);
|
||||
|
||||
void
|
||||
setRibIoService(boost::asio::io_service* ribIo);
|
||||
|
||||
/** \brief Run a function on the main io_service instance.
|
||||
*/
|
||||
void
|
||||
runOnMainIoService(const std::function<void()>& f);
|
||||
|
||||
/** \brief Run a function on the RIB io_service instance.
|
||||
*/
|
||||
void
|
||||
runOnRibIoService(const std::function<void()>& f);
|
||||
|
||||
#ifdef NFD_WITH_TESTS
|
||||
/** \brief Destroy the global io_service instance.
|
||||
*
|
||||
* It will be recreated at the next invocation of getGlobalIoService().
|
||||
*/
|
||||
void
|
||||
resetGlobalIoService();
|
||||
#endif
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_COMMON_GLOBAL_HPP
|
||||
@@ -0,0 +1,44 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_COMMON_LOGGER_HPP
|
||||
#define NFD_DAEMON_COMMON_LOGGER_HPP
|
||||
|
||||
#include <ndn-cxx/util/logger.hpp>
|
||||
|
||||
#define NFD_LOG_INIT(name) NDN_LOG_INIT(nfd.name)
|
||||
#define NFD_LOG_MEMBER_DECL() NDN_LOG_MEMBER_DECL()
|
||||
#define NFD_LOG_MEMBER_DECL_SPECIALIZED(cls) NDN_LOG_MEMBER_DECL_SPECIALIZED(cls)
|
||||
#define NFD_LOG_MEMBER_INIT(cls, name) NDN_LOG_MEMBER_INIT(cls, nfd.name)
|
||||
#define NFD_LOG_MEMBER_INIT_SPECIALIZED(cls, name) NDN_LOG_MEMBER_INIT_SPECIALIZED(cls, nfd.name)
|
||||
|
||||
#define NFD_LOG_TRACE NDN_LOG_TRACE
|
||||
#define NFD_LOG_DEBUG NDN_LOG_DEBUG
|
||||
#define NFD_LOG_INFO NDN_LOG_INFO
|
||||
#define NFD_LOG_WARN NDN_LOG_WARN
|
||||
#define NFD_LOG_ERROR NDN_LOG_ERROR
|
||||
#define NFD_LOG_FATAL NDN_LOG_FATAL
|
||||
|
||||
#endif // NFD_DAEMON_COMMON_LOGGER_HPP
|
||||
@@ -0,0 +1,159 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common/privilege-helper.hpp"
|
||||
#include "common/logger.hpp"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT(PrivilegeHelper);
|
||||
|
||||
#ifdef NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
uid_t PrivilegeHelper::s_normalUid = ::geteuid();
|
||||
gid_t PrivilegeHelper::s_normalGid = ::getegid();
|
||||
|
||||
uid_t PrivilegeHelper::s_privilegedUid = ::geteuid();
|
||||
gid_t PrivilegeHelper::s_privilegedGid = ::getegid();
|
||||
#endif // NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
|
||||
void
|
||||
PrivilegeHelper::initialize(const std::string& userName, const std::string& groupName)
|
||||
{
|
||||
#ifdef NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
static const size_t MAX_GROUP_BUFFER_SIZE = 16384; // 16 KiB
|
||||
static const size_t MAX_PASSWD_BUFFER_SIZE = 16384;
|
||||
|
||||
static const size_t FALLBACK_GROUP_BUFFER_SIZE = 1024;
|
||||
static const size_t FALLBACK_PASSWD_BUFFER_SIZE = 1024;
|
||||
|
||||
NFD_LOG_TRACE("initializing with user \"" << userName << "\""
|
||||
<< " group \"" << groupName << "\"");
|
||||
|
||||
// workflow from man getpwnam_r
|
||||
|
||||
if (!groupName.empty()) {
|
||||
static long groupSize = ::sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
|
||||
if (groupSize == -1)
|
||||
groupSize = FALLBACK_GROUP_BUFFER_SIZE;
|
||||
|
||||
std::vector<char> groupBuffer(static_cast<size_t>(groupSize));
|
||||
group gr;
|
||||
group* grResult = nullptr;
|
||||
|
||||
int errorCode = getgrnam_r(groupName.data(), &gr, groupBuffer.data(), groupBuffer.size(), &grResult);
|
||||
|
||||
while (errorCode == ERANGE) {
|
||||
if (groupBuffer.size() * 2 > MAX_GROUP_BUFFER_SIZE)
|
||||
throw Error("Cannot allocate large enough buffer for struct group");
|
||||
|
||||
groupBuffer.resize(groupBuffer.size() * 2);
|
||||
errorCode = getgrnam_r(groupName.data(), &gr, groupBuffer.data(), groupBuffer.size(), &grResult);
|
||||
}
|
||||
|
||||
if (errorCode != 0 || !grResult)
|
||||
throw Error("Failed to get gid for \"" + groupName + "\"");
|
||||
|
||||
s_normalGid = gr.gr_gid;
|
||||
}
|
||||
|
||||
if (!userName.empty()) {
|
||||
static long passwdSize = ::sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
|
||||
if (passwdSize == -1)
|
||||
passwdSize = FALLBACK_PASSWD_BUFFER_SIZE;
|
||||
|
||||
std::vector<char> passwdBuffer(static_cast<size_t>(passwdSize));
|
||||
passwd pw;
|
||||
passwd* pwResult = nullptr;
|
||||
|
||||
int errorCode = getpwnam_r(userName.data(), &pw, passwdBuffer.data(), passwdBuffer.size(), &pwResult);
|
||||
|
||||
while (errorCode == ERANGE) {
|
||||
if (passwdBuffer.size() * 2 > MAX_PASSWD_BUFFER_SIZE)
|
||||
throw Error("Cannot allocate large enough buffer for struct passwd");
|
||||
|
||||
passwdBuffer.resize(passwdBuffer.size() * 2);
|
||||
errorCode = getpwnam_r(userName.data(), &pw, passwdBuffer.data(), passwdBuffer.size(), &pwResult);
|
||||
}
|
||||
|
||||
if (errorCode != 0 || !pwResult)
|
||||
throw Error("Failed to get uid for \"" + userName + "\"");
|
||||
|
||||
s_normalUid = pw.pw_uid;
|
||||
}
|
||||
#else
|
||||
if (!userName.empty() || !groupName.empty()) {
|
||||
throw Error("Dropping and raising privileges is not supported on this platform");
|
||||
}
|
||||
#endif // NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::drop()
|
||||
{
|
||||
#ifdef NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
if (::geteuid() == s_normalUid && ::getegid() == s_normalGid)
|
||||
return;
|
||||
|
||||
NFD_LOG_TRACE("dropping to effective gid=" << s_normalGid);
|
||||
if (::setegid(s_normalGid) != 0)
|
||||
throw Error("Failed to drop to effective gid=" + to_string(s_normalGid));
|
||||
|
||||
NFD_LOG_TRACE("dropping to effective uid=" << s_normalUid);
|
||||
if (::seteuid(s_normalUid) != 0)
|
||||
throw Error("Failed to drop to effective uid=" + to_string(s_normalUid));
|
||||
|
||||
NFD_LOG_INFO("dropped to effective uid=" << ::geteuid() << " gid=" << ::getegid());
|
||||
#else
|
||||
NFD_LOG_WARN("Dropping privileges is not supported on this platform");
|
||||
#endif // NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::raise()
|
||||
{
|
||||
#ifdef NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
if (::geteuid() == s_privilegedUid && ::getegid() == s_privilegedGid)
|
||||
return;
|
||||
|
||||
NFD_LOG_TRACE("elevating to effective uid=" << s_privilegedUid);
|
||||
if (::seteuid(s_privilegedUid) != 0)
|
||||
throw Error("Failed to elevate to effective uid=" + to_string(s_privilegedUid));
|
||||
|
||||
NFD_LOG_TRACE("elevating to effective gid=" << s_privilegedGid);
|
||||
if (::setegid(s_privilegedGid) != 0)
|
||||
throw Error("Failed to elevate to effective gid=" + to_string(s_privilegedGid));
|
||||
|
||||
NFD_LOG_INFO("elevated to effective uid=" << ::geteuid() << " gid=" << ::getegid());
|
||||
#else
|
||||
NFD_LOG_WARN("Elevating privileges is not supported on this platform");
|
||||
#endif // NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,11 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -20,12 +21,12 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_PRIVILEGE_HELPER_HPP
|
||||
#define NFD_CORE_PRIVILEGE_HELPER_HPP
|
||||
#ifndef NFD_DAEMON_COMMON_PRIVILEGE_HELPER_HPP
|
||||
#define NFD_DAEMON_COMMON_PRIVILEGE_HELPER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/common.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -34,9 +35,11 @@ namespace nfd {
|
||||
class PrivilegeHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/// \brief PrivilegeHelper::Error represents a serious seteuid/gid failure and
|
||||
/// should only be caught by main in as part of a graceful program termination.
|
||||
/** \brief represents a serious seteuid/gid failure
|
||||
*
|
||||
* This should only be caught by main as part of a graceful program termination.
|
||||
* \note This is not an std::exception and NDN_THROW should not be used.
|
||||
*/
|
||||
class Error
|
||||
{
|
||||
public:
|
||||
@@ -49,7 +52,7 @@ public:
|
||||
const char*
|
||||
what() const
|
||||
{
|
||||
return m_whatMessage.c_str();
|
||||
return m_whatMessage.data();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -62,23 +65,35 @@ public:
|
||||
static void
|
||||
drop();
|
||||
|
||||
template<class F>
|
||||
static void
|
||||
runElevated(function<void()> f);
|
||||
|
||||
private:
|
||||
runElevated(F&& f)
|
||||
{
|
||||
raise();
|
||||
try {
|
||||
std::forward<F>(f)();
|
||||
}
|
||||
catch (...) {
|
||||
drop();
|
||||
throw;
|
||||
}
|
||||
drop();
|
||||
}
|
||||
|
||||
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
static void
|
||||
raise();
|
||||
|
||||
private:
|
||||
|
||||
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
#ifdef NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
static uid_t s_normalUid;
|
||||
static gid_t s_normalGid;
|
||||
|
||||
static uid_t s_privilegedUid;
|
||||
static gid_t s_privilegedGid;
|
||||
#endif // NFD_HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_PRIVILEGE_HELPER_HPP
|
||||
#endif // NFD_DAEMON_COMMON_PRIVILEGE_HELPER_HPP
|
||||
@@ -0,0 +1,62 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_CHANNEL_LOG_HPP
|
||||
#define NFD_DAEMON_FACE_CHANNEL_LOG_HPP
|
||||
|
||||
#include "common/logger.hpp"
|
||||
|
||||
/** \defgroup ChannelLogging Channel logging macros
|
||||
*
|
||||
* These macros augment the log message with some channel-specific information,
|
||||
* such as the local URI, that are useful to distinguish which channel produced
|
||||
* the message. It is strongly recommended to use these macros instead of the
|
||||
* generic ones for all logging inside Channel subclasses.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \cond */
|
||||
#define NFD_LOG_CHAN(level, msg) NFD_LOG_##level( \
|
||||
"[" << this->getUri() << "] " << msg)
|
||||
/** \endcond */
|
||||
|
||||
/** \brief Log a message at TRACE level */
|
||||
#define NFD_LOG_CHAN_TRACE(msg) NFD_LOG_CHAN(TRACE, msg)
|
||||
|
||||
/** \brief Log a message at DEBUG level */
|
||||
#define NFD_LOG_CHAN_DEBUG(msg) NFD_LOG_CHAN(DEBUG, msg)
|
||||
|
||||
/** \brief Log a message at INFO level */
|
||||
#define NFD_LOG_CHAN_INFO(msg) NFD_LOG_CHAN(INFO, msg)
|
||||
|
||||
/** \brief Log a message at WARN level */
|
||||
#define NFD_LOG_CHAN_WARN(msg) NFD_LOG_CHAN(WARN, msg)
|
||||
|
||||
/** \brief Log a message at ERROR level */
|
||||
#define NFD_LOG_CHAN_ERROR(msg) NFD_LOG_CHAN(ERROR, msg)
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // NFD_DAEMON_FACE_CHANNEL_LOG_HPP
|
||||
+29
-11
@@ -1,11 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -20,15 +21,15 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "face.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
Channel::~Channel()
|
||||
{
|
||||
}
|
||||
Channel::~Channel() = default;
|
||||
|
||||
void
|
||||
Channel::setUri(const FaceUri& uri)
|
||||
@@ -36,4 +37,21 @@ Channel::setUri(const FaceUri& uri)
|
||||
m_uri = uri;
|
||||
}
|
||||
|
||||
void
|
||||
Channel::setDefaultMtu(size_t mtu)
|
||||
{
|
||||
m_defaultMtu = mtu;
|
||||
}
|
||||
|
||||
void
|
||||
connectFaceClosedSignal(Face& face, std::function<void()> f)
|
||||
{
|
||||
face.afterStateChange.connect([f = std::move(f)] (auto, FaceState newState) {
|
||||
if (newState == FaceState::CLOSED) {
|
||||
f();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
+64
-27
@@ -1,11 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -20,49 +21,85 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_CHANNEL_HPP
|
||||
#define NFD_DAEMON_FACE_CHANNEL_HPP
|
||||
|
||||
#include "face.hpp"
|
||||
#include "channel-log.hpp"
|
||||
#include "face-common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class Channel : noncopyable
|
||||
/** \brief Represents a channel that listens on a local endpoint.
|
||||
* \sa FaceSystem
|
||||
*
|
||||
* A channel can listen on a local endpoint and initiate outgoing connection from a local endpoint.
|
||||
* A channel creates Face objects and retains shared ownership of them.
|
||||
*/
|
||||
class Channel : public std::enable_shared_from_this<Channel>, noncopyable
|
||||
{
|
||||
public:
|
||||
/** \brief Prototype for the callback called when face is created
|
||||
* (as a response to incoming connection or after connection
|
||||
* is established)
|
||||
*/
|
||||
typedef function<void(const shared_ptr<Face>& newFace)> FaceCreatedCallback;
|
||||
|
||||
/** \brief Prototype for the callback that is called when face is failed to
|
||||
* get created
|
||||
*/
|
||||
typedef function<void(const std::string& reason)> ConnectFailedCallback;
|
||||
|
||||
virtual
|
||||
~Channel();
|
||||
|
||||
const FaceUri&
|
||||
getUri() const;
|
||||
getUri() const
|
||||
{
|
||||
return m_uri;
|
||||
}
|
||||
|
||||
/** \brief Returns the default MTU for all faces created by this channel
|
||||
*/
|
||||
size_t
|
||||
getDefaultMtu() const
|
||||
{
|
||||
return m_defaultMtu;
|
||||
}
|
||||
|
||||
/** \brief Returns whether the channel is listening
|
||||
*/
|
||||
virtual bool
|
||||
isListening() const = 0;
|
||||
|
||||
/** \brief Returns the number of faces in the channel
|
||||
*/
|
||||
virtual size_t
|
||||
size() const = 0;
|
||||
|
||||
protected:
|
||||
void
|
||||
setUri(const FaceUri& uri);
|
||||
|
||||
void
|
||||
setDefaultMtu(size_t mtu);
|
||||
|
||||
private:
|
||||
FaceUri m_uri;
|
||||
size_t m_defaultMtu = ndn::MAX_NDN_PACKET_SIZE;
|
||||
};
|
||||
|
||||
inline const FaceUri&
|
||||
Channel::getUri() const
|
||||
{
|
||||
return m_uri;
|
||||
}
|
||||
/** \brief Prototype for the callback that is invoked when a face is created
|
||||
* (in response to an incoming connection or after a connection is established).
|
||||
*/
|
||||
using FaceCreatedCallback = std::function<void(const shared_ptr<Face>&)>;
|
||||
|
||||
/** \brief Prototype for the callback that is invoked when a face fails to be created.
|
||||
*/
|
||||
using FaceCreationFailedCallback = std::function<void(uint32_t status, const std::string& reason)>;
|
||||
|
||||
/** \brief Invokes a callback when a face is closed.
|
||||
* \param face the face
|
||||
* \param f the callback to be invoked when the face enters CLOSED state
|
||||
*
|
||||
* This function connects a callback to the afterStateChange signal of \p face,
|
||||
* and invokes \p f when the state becomes CLOSED.
|
||||
*/
|
||||
void
|
||||
connectFaceClosedSignal(Face& face, std::function<void()> f);
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_CHANNEL_HPP
|
||||
@@ -1,342 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
|
||||
#define NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
|
||||
|
||||
#include "face.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class Unicast {};
|
||||
class Multicast {};
|
||||
|
||||
template<class Protocol, class Type = Unicast>
|
||||
class DatagramFace : public Face
|
||||
{
|
||||
public:
|
||||
typedef Protocol protocol;
|
||||
|
||||
/** \brief Construct datagram face
|
||||
*
|
||||
* \param socket Protocol-specific socket for the created face
|
||||
* \param isOnDemand If true, the face can be closed after it remains
|
||||
* unused for a certain amount of time
|
||||
*/
|
||||
DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
|
||||
const shared_ptr<typename protocol::socket>& socket,
|
||||
bool isOnDemand);
|
||||
|
||||
virtual
|
||||
~DatagramFace();
|
||||
|
||||
// from Face
|
||||
virtual void
|
||||
sendInterest(const Interest& interest);
|
||||
|
||||
virtual void
|
||||
sendData(const Data& data);
|
||||
|
||||
virtual void
|
||||
close();
|
||||
|
||||
void
|
||||
receiveDatagram(const uint8_t* buffer,
|
||||
size_t nBytesReceived,
|
||||
const boost::system::error_code& error);
|
||||
|
||||
/**
|
||||
* \brief Set m_hasBeenUsedRecently to false
|
||||
*/
|
||||
void
|
||||
resetRecentUsage();
|
||||
|
||||
bool
|
||||
hasBeenUsedRecently() const;
|
||||
|
||||
void
|
||||
setOnDemand(bool isOnDemand);
|
||||
|
||||
protected:
|
||||
void
|
||||
handleSend(const boost::system::error_code& error,
|
||||
size_t nBytesSent,
|
||||
const Block& payload);
|
||||
|
||||
void
|
||||
handleReceive(const boost::system::error_code& error,
|
||||
size_t nBytesReceived);
|
||||
|
||||
void
|
||||
keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face);
|
||||
|
||||
void
|
||||
closeSocket();
|
||||
|
||||
protected:
|
||||
shared_ptr<typename protocol::socket> m_socket;
|
||||
uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE];
|
||||
bool m_hasBeenUsedRecently;
|
||||
|
||||
NFD_LOG_INCLASS_DECLARE();
|
||||
};
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
inline
|
||||
DatagramFace<T, U>::DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
|
||||
const shared_ptr<typename DatagramFace::protocol::socket>& socket,
|
||||
bool isOnDemand)
|
||||
: Face(remoteUri, localUri)
|
||||
, m_socket(socket)
|
||||
{
|
||||
setOnDemand(isOnDemand);
|
||||
|
||||
m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
|
||||
bind(&DatagramFace<T, U>::handleReceive, this, _1, _2));
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline
|
||||
DatagramFace<T, U>::~DatagramFace()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::sendInterest(const Interest& interest)
|
||||
{
|
||||
this->onSendInterest(interest);
|
||||
const Block& payload = interest.wireEncode();
|
||||
m_socket->async_send(boost::asio::buffer(payload.wire(), payload.size()),
|
||||
bind(&DatagramFace<T, U>::handleSend, this, _1, _2, payload));
|
||||
|
||||
// anything else should be done here?
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::sendData(const Data& data)
|
||||
{
|
||||
this->onSendData(data);
|
||||
const Block& payload = data.wireEncode();
|
||||
m_socket->async_send(boost::asio::buffer(payload.wire(), payload.size()),
|
||||
bind(&DatagramFace<T, U>::handleSend, this, _1, _2, payload));
|
||||
|
||||
// anything else should be done here?
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::handleSend(const boost::system::error_code& error,
|
||||
size_t nBytesSent,
|
||||
const Block& payload)
|
||||
// 'payload' is unused; it's needed to retain the underlying Buffer
|
||||
{
|
||||
if (error != 0) {
|
||||
if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
|
||||
return;
|
||||
|
||||
if (!m_socket->is_open()) {
|
||||
fail("Tunnel closed");
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_WARN("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Send operation failed, closing socket: "
|
||||
<< error.category().message(error.value()));
|
||||
|
||||
closeSocket();
|
||||
|
||||
if (error == boost::asio::error::eof) {
|
||||
fail("Tunnel closed");
|
||||
}
|
||||
else {
|
||||
fail("Send operation failed, closing socket: " +
|
||||
error.category().message(error.value()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Successfully sent: " << nBytesSent << " bytes");
|
||||
this->getMutableCounters().getNOutBytes() += nBytesSent;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::close()
|
||||
{
|
||||
if (!m_socket->is_open())
|
||||
return;
|
||||
|
||||
NFD_LOG_INFO("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Close tunnel");
|
||||
|
||||
closeSocket();
|
||||
fail("Close tunnel");
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::handleReceive(const boost::system::error_code& error,
|
||||
size_t nBytesReceived)
|
||||
{
|
||||
NFD_LOG_DEBUG("handleReceive: " << nBytesReceived);
|
||||
receiveDatagram(m_inputBuffer, nBytesReceived, error);
|
||||
if (m_socket->is_open())
|
||||
m_socket->async_receive(boost::asio::buffer(m_inputBuffer, MAX_NDN_PACKET_SIZE), 0,
|
||||
bind(&DatagramFace<T, U>::handleReceive, this, _1, _2));
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::receiveDatagram(const uint8_t* buffer,
|
||||
size_t nBytesReceived,
|
||||
const boost::system::error_code& error)
|
||||
{
|
||||
if (error != 0 || nBytesReceived == 0) {
|
||||
if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
|
||||
return;
|
||||
|
||||
// this should be unnecessary, but just in case
|
||||
if (!m_socket->is_open()) {
|
||||
fail("Tunnel closed");
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_WARN("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Receive operation failed: "
|
||||
<< error.category().message(error.value()));
|
||||
|
||||
closeSocket();
|
||||
|
||||
if (error == boost::asio::error::eof) {
|
||||
fail("Tunnel closed");
|
||||
}
|
||||
else {
|
||||
fail("Receive operation failed, closing socket: " +
|
||||
error.category().message(error.value()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Received: " << nBytesReceived << " bytes");
|
||||
this->getMutableCounters().getNInBytes() += nBytesReceived;
|
||||
|
||||
Block element;
|
||||
bool isOk = Block::fromBuffer(buffer, nBytesReceived, element);
|
||||
if (!isOk)
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Failed to parse incoming packet");
|
||||
// This message won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
|
||||
if (element.size() != nBytesReceived)
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Received datagram size and decoded "
|
||||
<< "element size don't match");
|
||||
// This message won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->decodeAndDispatchInput(element))
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] Received unrecognized block of type ["
|
||||
<< element.type() << "]");
|
||||
// This message won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
|
||||
m_hasBeenUsedRecently = true;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::closeSocket()
|
||||
{
|
||||
NFD_LOG_DEBUG("[id:" << this->getId()
|
||||
<< ",uri:" << this->getRemoteUri()
|
||||
<< "] closeSocket");
|
||||
|
||||
boost::asio::io_service& io = m_socket->get_io_service();
|
||||
|
||||
// use the non-throwing variants and ignore errors, if any
|
||||
boost::system::error_code error;
|
||||
m_socket->shutdown(protocol::socket::shutdown_both, error);
|
||||
m_socket->close(error);
|
||||
// after this, handlers will be called with an error code
|
||||
|
||||
// ensure that the Face object is alive at least until all pending
|
||||
// handlers are dispatched
|
||||
io.post(bind(&DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted,
|
||||
this, this->shared_from_this()));
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::setOnDemand(bool isOnDemand)
|
||||
{
|
||||
Face::setOnDemand(isOnDemand);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramFace<T, U>::resetRecentUsage()
|
||||
{
|
||||
m_hasBeenUsedRecently = false;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
DatagramFace<T, U>::hasBeenUsedRecently() const
|
||||
{
|
||||
return m_hasBeenUsedRecently;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
|
||||
@@ -0,0 +1,270 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
|
||||
#define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
|
||||
|
||||
#include "transport.hpp"
|
||||
#include "socket-utils.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
struct Unicast {};
|
||||
struct Multicast {};
|
||||
|
||||
/** \brief Implements Transport for datagram-based protocols.
|
||||
*
|
||||
* \tparam Protocol a datagram-based protocol in Boost.Asio
|
||||
*/
|
||||
template<class Protocol, class Addressing = Unicast>
|
||||
class DatagramTransport : public Transport
|
||||
{
|
||||
public:
|
||||
using protocol = Protocol;
|
||||
|
||||
/** \brief Construct datagram transport.
|
||||
*
|
||||
* \param socket Protocol-specific socket for the created transport
|
||||
*/
|
||||
explicit
|
||||
DatagramTransport(typename protocol::socket&& socket);
|
||||
|
||||
ssize_t
|
||||
getSendQueueLength() override;
|
||||
|
||||
/**
|
||||
* \brief Receive datagram, translate buffer into packet, deliver to parent class.
|
||||
*/
|
||||
void
|
||||
receiveDatagram(span<const uint8_t> buffer, const boost::system::error_code& error);
|
||||
|
||||
protected:
|
||||
void
|
||||
doClose() override;
|
||||
|
||||
void
|
||||
doSend(const Block& packet) override;
|
||||
|
||||
void
|
||||
handleSend(const boost::system::error_code& error, size_t nBytesSent);
|
||||
|
||||
void
|
||||
handleReceive(const boost::system::error_code& error, size_t nBytesReceived);
|
||||
|
||||
void
|
||||
processErrorCode(const boost::system::error_code& error);
|
||||
|
||||
bool
|
||||
hasRecentlyReceived() const;
|
||||
|
||||
void
|
||||
resetRecentlyReceived();
|
||||
|
||||
static EndpointId
|
||||
makeEndpointId(const typename protocol::endpoint& ep);
|
||||
|
||||
protected:
|
||||
typename protocol::socket m_socket;
|
||||
typename protocol::endpoint m_sender;
|
||||
|
||||
NFD_LOG_MEMBER_DECL();
|
||||
|
||||
private:
|
||||
std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
|
||||
bool m_hasRecentlyReceived;
|
||||
};
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
DatagramTransport<T, U>::DatagramTransport(typename DatagramTransport::protocol::socket&& socket)
|
||||
: m_socket(std::move(socket))
|
||||
, m_hasRecentlyReceived(false)
|
||||
{
|
||||
boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
|
||||
boost::system::error_code error;
|
||||
m_socket.get_option(sendBufferSizeOption, error);
|
||||
if (error) {
|
||||
NFD_LOG_FACE_WARN("Failed to obtain send queue capacity from socket: " << error.message());
|
||||
this->setSendQueueCapacity(QUEUE_ERROR);
|
||||
}
|
||||
else {
|
||||
this->setSendQueueCapacity(sendBufferSizeOption.value());
|
||||
}
|
||||
|
||||
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
|
||||
[this] (auto&&... args) {
|
||||
this->handleReceive(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
ssize_t
|
||||
DatagramTransport<T, U>::getSendQueueLength()
|
||||
{
|
||||
ssize_t queueLength = getTxQueueLength(m_socket.native_handle());
|
||||
if (queueLength == QUEUE_ERROR) {
|
||||
NFD_LOG_FACE_WARN("Failed to obtain send queue length from socket: " << std::strerror(errno));
|
||||
}
|
||||
return queueLength;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::doClose()
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
if (m_socket.is_open()) {
|
||||
// Cancel all outstanding operations and close the socket.
|
||||
// Use the non-throwing variants and ignore errors, if any.
|
||||
boost::system::error_code error;
|
||||
m_socket.cancel(error);
|
||||
m_socket.close(error);
|
||||
}
|
||||
|
||||
// Ensure that the Transport stays alive at least until
|
||||
// all pending handlers are dispatched
|
||||
getGlobalIoService().post([this] {
|
||||
this->setState(TransportState::CLOSED);
|
||||
});
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::doSend(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
m_socket.async_send(boost::asio::buffer(packet),
|
||||
// 'packet' is copied into the lambda to retain the underlying Buffer
|
||||
[this, packet] (auto&&... args) {
|
||||
this->handleSend(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::receiveDatagram(span<const uint8_t> buffer,
|
||||
const boost::system::error_code& error)
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
NFD_LOG_FACE_TRACE("Received: " << buffer.size() << " bytes from " << m_sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(buffer);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << m_sender);
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
if (element.size() != buffer.size()) {
|
||||
NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
m_hasRecentlyReceived = true;
|
||||
|
||||
this->receive(element, makeEndpointId(m_sender));
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error, size_t nBytesReceived)
|
||||
{
|
||||
receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
|
||||
|
||||
if (m_socket.is_open())
|
||||
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
|
||||
[this] (auto&&... args) {
|
||||
this->handleReceive(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::handleSend(const boost::system::error_code& error, size_t nBytesSent)
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::processErrorCode(const boost::system::error_code& error)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
if (getState() == TransportState::CLOSING ||
|
||||
getState() == TransportState::FAILED ||
|
||||
getState() == TransportState::CLOSED ||
|
||||
error == boost::asio::error::operation_aborted) {
|
||||
// transport is shutting down, ignore any errors
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
|
||||
NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << error.message());
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_ERROR("Send or receive operation failed: " << error.message());
|
||||
this->setState(TransportState::FAILED);
|
||||
doClose();
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
bool
|
||||
DatagramTransport<T, U>::hasRecentlyReceived() const
|
||||
{
|
||||
return m_hasRecentlyReceived;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::resetRecentlyReceived()
|
||||
{
|
||||
m_hasRecentlyReceived = false;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
EndpointId
|
||||
DatagramTransport<T, U>::makeEndpointId(const typename protocol::endpoint&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
|
||||
@@ -0,0 +1,242 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ethernet-channel.hpp"
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "face.hpp"
|
||||
#include "generic-link-service.hpp"
|
||||
#include "unicast-ethernet-transport.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(EthernetChannel);
|
||||
|
||||
EthernetChannel::EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
|
||||
time::nanoseconds idleTimeout)
|
||||
: m_localEndpoint(std::move(localEndpoint))
|
||||
, m_isListening(false)
|
||||
, m_socket(getGlobalIoService())
|
||||
, m_pcap(m_localEndpoint->getName())
|
||||
, m_idleFaceTimeout(idleTimeout)
|
||||
#ifdef _DEBUG
|
||||
, m_nDropped(0)
|
||||
#endif
|
||||
{
|
||||
setUri(FaceUri::fromDev(m_localEndpoint->getName()));
|
||||
NFD_LOG_CHAN_INFO("Creating channel");
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::connect(const ethernet::Address& remoteEndpoint,
|
||||
const FaceParams& params,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onConnectFailed)
|
||||
{
|
||||
shared_ptr<Face> face;
|
||||
try {
|
||||
face = createFace(remoteEndpoint, params).second;
|
||||
}
|
||||
catch (const boost::system::system_error& e) {
|
||||
NFD_LOG_CHAN_DEBUG("Face creation for " << remoteEndpoint << " failed: " << e.what());
|
||||
if (onConnectFailed)
|
||||
onConnectFailed(504, "Face creation failed: "s + e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to invoke the callback regardless of whether or not we had already
|
||||
// created the face so that control responses and such can be sent
|
||||
onFaceCreated(face);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::listen(const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onFaceCreationFailed)
|
||||
{
|
||||
if (isListening()) {
|
||||
NFD_LOG_CHAN_WARN("Already listening");
|
||||
return;
|
||||
}
|
||||
m_isListening = true;
|
||||
|
||||
try {
|
||||
m_pcap.activate(DLT_EN10MB);
|
||||
m_socket.assign(m_pcap.getFd());
|
||||
}
|
||||
catch (const PcapHelper::Error& e) {
|
||||
NDN_THROW_NESTED(Error(e.what()));
|
||||
}
|
||||
updateFilter();
|
||||
|
||||
asyncRead(onFaceCreated, onFaceCreationFailed);
|
||||
NFD_LOG_CHAN_DEBUG("Started listening");
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::asyncRead(const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed)
|
||||
{
|
||||
m_socket.async_read_some(boost::asio::null_buffers(),
|
||||
[=] (const auto& e, auto) { this->handleRead(e, onFaceCreated, onReceiveFailed); });
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::handleRead(const boost::system::error_code& error,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed)
|
||||
{
|
||||
if (error) {
|
||||
if (error != boost::asio::error::operation_aborted) {
|
||||
NFD_LOG_CHAN_DEBUG("Receive failed: " << error.message());
|
||||
if (onReceiveFailed)
|
||||
onReceiveFailed(500, "Receive failed: " + error.message());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
span<const uint8_t> pkt;
|
||||
std::string err;
|
||||
std::tie(pkt, err) = m_pcap.readNextPacket();
|
||||
|
||||
if (pkt.empty()) {
|
||||
NFD_LOG_CHAN_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_localEndpoint->getEthernetAddress(),
|
||||
m_localEndpoint->getEthernetAddress());
|
||||
if (eh == nullptr) {
|
||||
NFD_LOG_CHAN_DEBUG(err);
|
||||
}
|
||||
else {
|
||||
ethernet::Address sender(eh->ether_shost);
|
||||
pkt = pkt.subspan(ethernet::HDR_LEN);
|
||||
processIncomingPacket(pkt, sender, onFaceCreated, onReceiveFailed);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
size_t nDropped = m_pcap.getNDropped();
|
||||
if (nDropped - m_nDropped > 0)
|
||||
NFD_LOG_CHAN_DEBUG("Detected " << nDropped - m_nDropped << " dropped frame(s)");
|
||||
m_nDropped = nDropped;
|
||||
#endif
|
||||
|
||||
asyncRead(onFaceCreated, onReceiveFailed);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::processIncomingPacket(span<const uint8_t> packet,
|
||||
const ethernet::Address& sender,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed)
|
||||
{
|
||||
NFD_LOG_CHAN_TRACE("New peer " << sender);
|
||||
|
||||
bool isCreated = false;
|
||||
shared_ptr<Face> face;
|
||||
try {
|
||||
FaceParams params;
|
||||
params.persistency = ndn::nfd::FACE_PERSISTENCY_ON_DEMAND;
|
||||
std::tie(isCreated, face) = createFace(sender, params);
|
||||
}
|
||||
catch (const EthernetTransport::Error& e) {
|
||||
NFD_LOG_CHAN_DEBUG("Face creation for " << sender << " failed: " << e.what());
|
||||
if (onReceiveFailed)
|
||||
onReceiveFailed(504, "Face creation failed: "s + e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCreated)
|
||||
onFaceCreated(face);
|
||||
else
|
||||
NFD_LOG_CHAN_DEBUG("Received frame for existing face");
|
||||
|
||||
// dispatch the packet to the face for processing
|
||||
auto* transport = static_cast<UnicastEthernetTransport*>(face->getTransport());
|
||||
transport->receivePayload(packet, sender);
|
||||
}
|
||||
|
||||
std::pair<bool, shared_ptr<Face>>
|
||||
EthernetChannel::createFace(const ethernet::Address& remoteEndpoint,
|
||||
const FaceParams& params)
|
||||
{
|
||||
auto it = m_channelFaces.find(remoteEndpoint);
|
||||
if (it != m_channelFaces.end()) {
|
||||
// we already have a face for this endpoint, so reuse it
|
||||
NFD_LOG_CHAN_TRACE("Reusing existing face for " << remoteEndpoint);
|
||||
return {false, it->second};
|
||||
}
|
||||
|
||||
// else, create a new face
|
||||
GenericLinkService::Options options;
|
||||
options.allowFragmentation = true;
|
||||
options.allowReassembly = true;
|
||||
options.reliabilityOptions.isEnabled = params.wantLpReliability;
|
||||
if (params.mtu) {
|
||||
options.overrideMtu = *params.mtu;
|
||||
}
|
||||
|
||||
auto linkService = make_unique<GenericLinkService>(options);
|
||||
auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
|
||||
params.persistency, m_idleFaceTimeout);
|
||||
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
|
||||
face->setChannel(shared_from_this()); // use weak_from_this() in C++17
|
||||
|
||||
m_channelFaces[remoteEndpoint] = face;
|
||||
connectFaceClosedSignal(*face, [this, remoteEndpoint] {
|
||||
m_channelFaces.erase(remoteEndpoint);
|
||||
updateFilter();
|
||||
});
|
||||
updateFilter();
|
||||
|
||||
return {true, face};
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::updateFilter()
|
||||
{
|
||||
if (!isListening())
|
||||
return;
|
||||
|
||||
std::string filter = "(ether proto " + to_string(ethernet::ETHERTYPE_NDN) +
|
||||
") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() + ")";
|
||||
for (const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
|
||||
filter += " && (not ether src " + addr.toString() + ")";
|
||||
}
|
||||
// "not vlan" must appear last in the filter expression, or the
|
||||
// rest of the filter won't work as intended, see pcap-filter(7)
|
||||
filter += " && (not vlan)";
|
||||
|
||||
NFD_LOG_CHAN_TRACE("Updating filter: " << filter);
|
||||
m_pcap.setPacketFilter(filter.data());
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,143 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "pcap-helper.hpp"
|
||||
|
||||
#include <ndn-cxx/net/network-interface.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/**
|
||||
* \brief Class implementing Ethernet-based channel to create faces
|
||||
*/
|
||||
class EthernetChannel final : public Channel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief EthernetChannel-related error
|
||||
*/
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Create an Ethernet channel on the given \p localEndpoint (network interface)
|
||||
*
|
||||
* To enable creation of faces upon incoming connections,
|
||||
* one needs to explicitly call EthernetChannel::listen method.
|
||||
*/
|
||||
EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
|
||||
time::nanoseconds idleTimeout);
|
||||
|
||||
bool
|
||||
isListening() const final
|
||||
{
|
||||
return m_isListening;
|
||||
}
|
||||
|
||||
size_t
|
||||
size() const final
|
||||
{
|
||||
return m_channelFaces.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a unicast Ethernet face toward \p remoteEndpoint
|
||||
*/
|
||||
void
|
||||
connect(const ethernet::Address& remoteEndpoint,
|
||||
const FaceParams& params,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onConnectFailed);
|
||||
|
||||
/**
|
||||
* \brief Start listening
|
||||
*
|
||||
* Enable listening on the local endpoint, waiting for incoming frames,
|
||||
* and creating a face when a frame is received from a new remote host.
|
||||
*
|
||||
* Faces created in this way will have on-demand persistency.
|
||||
*
|
||||
* \param onFaceCreated Callback to notify successful creation of a face
|
||||
* \param onFaceCreationFailed Callback to notify errors
|
||||
* \throw Error
|
||||
*/
|
||||
void
|
||||
listen(const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onFaceCreationFailed);
|
||||
|
||||
private:
|
||||
void
|
||||
asyncRead(const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed);
|
||||
|
||||
void
|
||||
handleRead(const boost::system::error_code& error,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed);
|
||||
|
||||
void
|
||||
processIncomingPacket(span<const uint8_t> packet,
|
||||
const ethernet::Address& sender,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed);
|
||||
|
||||
std::pair<bool, shared_ptr<Face>>
|
||||
createFace(const ethernet::Address& remoteEndpoint,
|
||||
const FaceParams& params);
|
||||
|
||||
void
|
||||
updateFilter();
|
||||
|
||||
private:
|
||||
shared_ptr<const ndn::net::NetworkInterface> m_localEndpoint;
|
||||
bool m_isListening;
|
||||
boost::asio::posix::stream_descriptor m_socket;
|
||||
PcapHelper m_pcap;
|
||||
std::map<ethernet::Address, shared_ptr<Face>> m_channelFaces;
|
||||
const time::nanoseconds m_idleFaceTimeout; ///< Timeout for automatic closure of idle on-demand faces
|
||||
|
||||
#ifdef _DEBUG
|
||||
/// number of frames dropped by the kernel, as reported by libpcap
|
||||
size_t m_nDropped;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
|
||||
@@ -1,336 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "ethernet-face.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "core/network-interface.hpp"
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
#include <cstring> // for std::strncpy()
|
||||
#include <arpa/inet.h> // for htons() and ntohs()
|
||||
#include <net/ethernet.h> // for struct ether_header
|
||||
#include <net/if.h> // for struct ifreq
|
||||
#include <stdio.h> // for snprintf()
|
||||
#include <sys/ioctl.h> // for ioctl()
|
||||
#include <unistd.h> // for dup()
|
||||
|
||||
#if !defined(PCAP_NETMASK_UNKNOWN)
|
||||
/*
|
||||
* Value to pass to pcap_compile() as the netmask if you don't know what
|
||||
* the netmask is.
|
||||
*/
|
||||
#define PCAP_NETMASK_UNKNOWN 0xffffffff
|
||||
#endif
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT("EthernetFace");
|
||||
|
||||
EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
|
||||
const shared_ptr<NetworkInterfaceInfo>& interface,
|
||||
const ethernet::Address& address)
|
||||
: Face(FaceUri(address), FaceUri::fromDev(interface->name))
|
||||
, m_socket(socket)
|
||||
, m_interfaceName(interface->name)
|
||||
, m_srcAddress(interface->etherAddress)
|
||||
, m_destAddress(address)
|
||||
{
|
||||
NFD_LOG_INFO("Creating ethernet face on " << m_interfaceName << ": "
|
||||
<< m_srcAddress << " <--> " << m_destAddress);
|
||||
pcapInit();
|
||||
|
||||
int fd = pcap_get_selectable_fd(m_pcap);
|
||||
if (fd < 0)
|
||||
throw Error("pcap_get_selectable_fd() failed");
|
||||
|
||||
// need to duplicate the fd, otherwise both pcap_close()
|
||||
// and stream_descriptor::close() will try to close the
|
||||
// same fd and one of them will fail
|
||||
m_socket->assign(::dup(fd));
|
||||
|
||||
m_interfaceMtu = getInterfaceMtu();
|
||||
NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Interface MTU is: " << m_interfaceMtu);
|
||||
|
||||
char filter[100];
|
||||
::snprintf(filter, sizeof(filter),
|
||||
"(ether proto 0x%x) && (ether dst %s) && (not ether src %s)",
|
||||
ETHERTYPE_NDN,
|
||||
m_destAddress.toString().c_str(),
|
||||
m_srcAddress.toString().c_str());
|
||||
setPacketFilter(filter);
|
||||
|
||||
m_socket->async_read_some(boost::asio::null_buffers(),
|
||||
bind(&EthernetFace::handleRead, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
||||
EthernetFace::~EthernetFace()
|
||||
{
|
||||
onFail.clear(); // no reason to call onFail anymore
|
||||
close();
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::sendInterest(const Interest& interest)
|
||||
{
|
||||
onSendInterest(interest);
|
||||
sendPacket(interest.wireEncode());
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::sendData(const Data& data)
|
||||
{
|
||||
onSendData(data);
|
||||
sendPacket(data.wireEncode());
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::close()
|
||||
{
|
||||
if (m_pcap)
|
||||
{
|
||||
boost::system::error_code error;
|
||||
m_socket->close(error); // ignore errors
|
||||
pcap_close(m_pcap);
|
||||
m_pcap = 0;
|
||||
|
||||
fail("Face closed");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::pcapInit()
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
errbuf[0] = '\0';
|
||||
m_pcap = pcap_create(m_interfaceName.c_str(), errbuf);
|
||||
if (!m_pcap)
|
||||
throw Error("pcap_create(): " + std::string(errbuf));
|
||||
|
||||
#ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
|
||||
// Enable "immediate mode", effectively disabling any read buffering in the kernel.
|
||||
// This corresponds to the BIOCIMMEDIATE ioctl on BSD-like systems (including OS X)
|
||||
// where libpcap uses a BPF device. On Linux this forces libpcap not to use TPACKET_V3,
|
||||
// even if the kernel supports it, thus preventing bug #1511.
|
||||
pcap_set_immediate_mode(m_pcap, 1);
|
||||
#endif
|
||||
|
||||
/// \todo Do not rely on promisc mode, see task #1278
|
||||
if (!m_destAddress.isBroadcast())
|
||||
pcap_set_promisc(m_pcap, 1);
|
||||
|
||||
if (pcap_activate(m_pcap) < 0)
|
||||
throw Error("pcap_activate() failed");
|
||||
|
||||
if (pcap_set_datalink(m_pcap, DLT_EN10MB) < 0)
|
||||
throw Error("pcap_set_datalink(): " + std::string(pcap_geterr(m_pcap)));
|
||||
|
||||
if (pcap_setdirection(m_pcap, PCAP_D_IN) < 0)
|
||||
// no need to throw on failure, BPF will filter unwanted packets anyway
|
||||
NFD_LOG_WARN("pcap_setdirection(): " << pcap_geterr(m_pcap));
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::setPacketFilter(const char* filterString)
|
||||
{
|
||||
bpf_program filter;
|
||||
if (pcap_compile(m_pcap, &filter, filterString, 1, PCAP_NETMASK_UNKNOWN) < 0)
|
||||
throw Error("pcap_compile(): " + std::string(pcap_geterr(m_pcap)));
|
||||
|
||||
int ret = pcap_setfilter(m_pcap, &filter);
|
||||
pcap_freecode(&filter);
|
||||
if (ret < 0)
|
||||
throw Error("pcap_setfilter(): " + std::string(pcap_geterr(m_pcap)));
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::sendPacket(const ndn::Block& block)
|
||||
{
|
||||
if (!m_pcap)
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Trying to send on closed face");
|
||||
fail("Face closed");
|
||||
return;
|
||||
}
|
||||
|
||||
/// \todo Fragmentation
|
||||
if (block.size() > m_interfaceMtu)
|
||||
{
|
||||
NFD_LOG_ERROR("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Fragmentation not implemented: dropping packet larger than MTU");
|
||||
return;
|
||||
}
|
||||
|
||||
/// \todo Right now there is no reserve when packet is received, but
|
||||
/// we should reserve some space at the beginning and at the end
|
||||
ndn::EncodingBuffer buffer(block);
|
||||
|
||||
// pad with zeroes if the payload is too short
|
||||
if (block.size() < ethernet::MIN_DATA_LEN)
|
||||
{
|
||||
static const uint8_t padding[ethernet::MIN_DATA_LEN] = {0};
|
||||
buffer.appendByteArray(padding, ethernet::MIN_DATA_LEN - block.size());
|
||||
}
|
||||
|
||||
// construct and prepend the ethernet header
|
||||
static uint16_t ethertype = htons(ETHERTYPE_NDN);
|
||||
buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ðertype), ethernet::TYPE_LEN);
|
||||
buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
|
||||
buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
// send the packet
|
||||
int sent = pcap_inject(m_pcap, buffer.buf(), buffer.size());
|
||||
if (sent < 0)
|
||||
{
|
||||
throw Error("pcap_inject(): " + std::string(pcap_geterr(m_pcap)));
|
||||
}
|
||||
else if (static_cast<size_t>(sent) < buffer.size())
|
||||
{
|
||||
throw Error("Failed to send packet");
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Successfully sent: " << block.size() << " bytes");
|
||||
this->getMutableCounters().getNOutBytes() += block.size();
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::handleRead(const boost::system::error_code& error, size_t)
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
pcap_pkthdr* pktHeader;
|
||||
const uint8_t* packet;
|
||||
int ret = pcap_next_ex(m_pcap, &pktHeader, &packet);
|
||||
if (ret < 0)
|
||||
{
|
||||
throw Error("pcap_next_ex(): " + std::string(pcap_geterr(m_pcap)));
|
||||
}
|
||||
else if (ret == 0)
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] pcap_next_ex() timed out");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t length = pktHeader->caplen;
|
||||
if (length < ethernet::HDR_LEN + ethernet::MIN_DATA_LEN)
|
||||
throw Error("Received packet is too short");
|
||||
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
|
||||
if (ntohs(eh->ether_type) != ETHERTYPE_NDN)
|
||||
throw Error("Unrecognized ethertype");
|
||||
|
||||
packet += ethernet::HDR_LEN;
|
||||
length -= ethernet::HDR_LEN;
|
||||
|
||||
/// \todo Reserve space in front and at the back
|
||||
/// of the underlying buffer
|
||||
Block element;
|
||||
bool isOk = Block::fromBuffer(packet, length, element);
|
||||
if (isOk)
|
||||
{
|
||||
NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Received: " << element.size() << " bytes");
|
||||
this->getMutableCounters().getNInBytes() += element.size();
|
||||
|
||||
if (!decodeAndDispatchInput(element))
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Received unrecognized block of type " << element.type());
|
||||
// ignore unknown packet
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Received block is invalid or too large to process");
|
||||
}
|
||||
}
|
||||
|
||||
m_socket->async_read_some(boost::asio::null_buffers(),
|
||||
bind(&EthernetFace::handleRead, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFace::processErrorCode(const boost::system::error_code& error)
|
||||
{
|
||||
if (error == boost::system::errc::operation_canceled)
|
||||
// when socket is closed by someone
|
||||
return;
|
||||
|
||||
if (!m_pcap)
|
||||
{
|
||||
fail("Face closed");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string msg;
|
||||
if (error == boost::asio::error::eof)
|
||||
{
|
||||
msg = "Face closed";
|
||||
NFD_LOG_INFO("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "Receive operation failed, closing face: " + error.message();
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
|
||||
}
|
||||
|
||||
close();
|
||||
fail(msg);
|
||||
}
|
||||
|
||||
size_t
|
||||
EthernetFace::getInterfaceMtu() const
|
||||
{
|
||||
size_t mtu = ethernet::MAX_DATA_LEN;
|
||||
|
||||
#ifdef SIOCGIFMTU
|
||||
ifreq ifr = boost::initialized_value;
|
||||
std::strncpy(ifr.ifr_name, m_interfaceName.c_str(), sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
if (::ioctl(m_socket->native_handle(), SIOCGIFMTU, &ifr) < 0)
|
||||
{
|
||||
NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
|
||||
<< "] Failed to get interface MTU, assuming " << mtu);
|
||||
}
|
||||
else
|
||||
{
|
||||
mtu = std::min(mtu, static_cast<size_t>(ifr.ifr_mtu));
|
||||
}
|
||||
#endif
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,115 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_FACE_HPP
|
||||
|
||||
#include "config.hpp"
|
||||
#include "ethernet.hpp"
|
||||
#include "face.hpp"
|
||||
|
||||
#ifndef HAVE_LIBPCAP
|
||||
#error "Cannot include this file when libpcap is not available"
|
||||
#endif
|
||||
|
||||
// forward declarations
|
||||
struct pcap;
|
||||
typedef pcap pcap_t;
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class NetworkInterfaceInfo;
|
||||
|
||||
/**
|
||||
* \brief Implementation of Face abstraction that uses raw
|
||||
* Ethernet frames as underlying transport mechanism
|
||||
*/
|
||||
class EthernetFace : public Face
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief EthernetFace-related error
|
||||
*/
|
||||
struct Error : public Face::Error
|
||||
{
|
||||
Error(const std::string& what) : Face::Error(what) {}
|
||||
};
|
||||
|
||||
EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
|
||||
const shared_ptr<NetworkInterfaceInfo>& interface,
|
||||
const ethernet::Address& address);
|
||||
|
||||
virtual
|
||||
~EthernetFace();
|
||||
|
||||
/// send an Interest
|
||||
virtual void
|
||||
sendInterest(const Interest& interest);
|
||||
|
||||
/// send a Data
|
||||
virtual void
|
||||
sendData(const Data& data);
|
||||
|
||||
/**
|
||||
* \brief Close the face
|
||||
*
|
||||
* This terminates all communication on the face and cause
|
||||
* onFail() method event to be invoked
|
||||
*/
|
||||
virtual void
|
||||
close();
|
||||
|
||||
private:
|
||||
void
|
||||
pcapInit();
|
||||
|
||||
void
|
||||
setPacketFilter(const char* filterString);
|
||||
|
||||
void
|
||||
sendPacket(const ndn::Block& block);
|
||||
|
||||
void
|
||||
handleRead(const boost::system::error_code& error,
|
||||
size_t nBytesRead);
|
||||
|
||||
void
|
||||
processErrorCode(const boost::system::error_code& error);
|
||||
|
||||
size_t
|
||||
getInterfaceMtu() const;
|
||||
|
||||
private:
|
||||
shared_ptr<boost::asio::posix::stream_descriptor> m_socket;
|
||||
std::string m_interfaceName;
|
||||
ethernet::Address m_srcAddress;
|
||||
ethernet::Address m_destAddress;
|
||||
size_t m_interfaceMtu;
|
||||
pcap_t* m_pcap;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -24,72 +24,358 @@
|
||||
*/
|
||||
|
||||
#include "ethernet-factory.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "core/network-interface.hpp"
|
||||
#include "generic-link-service.hpp"
|
||||
#include "multicast-ethernet-transport.hpp"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <pcap/pcap.h>
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("EthernetFactory");
|
||||
NFD_LOG_INIT(EthernetFactory);
|
||||
NFD_REGISTER_PROTOCOL_FACTORY(EthernetFactory);
|
||||
|
||||
shared_ptr<EthernetFace>
|
||||
EthernetFactory::createMulticastFace(const shared_ptr<NetworkInterfaceInfo> &interface,
|
||||
const ethernet::Address &address)
|
||||
const std::string&
|
||||
EthernetFactory::getId() noexcept
|
||||
{
|
||||
if (!address.isMulticast())
|
||||
throw Error(address.toString() + " is not a multicast address");
|
||||
static std::string id("ether");
|
||||
return id;
|
||||
}
|
||||
|
||||
const std::string& name = interface->name;
|
||||
shared_ptr<EthernetFace> face = findMulticastFace(name, address);
|
||||
if (face)
|
||||
return face;
|
||||
EthernetFactory::EthernetFactory(const CtorParams& params)
|
||||
: ProtocolFactory(params)
|
||||
{
|
||||
m_netifAddConn = netmon->onInterfaceAdded.connect([this] (const auto& netif) {
|
||||
this->applyUnicastConfigToNetif(netif);
|
||||
this->applyMcastConfigToNetif(*netif);
|
||||
});
|
||||
}
|
||||
|
||||
shared_ptr<boost::asio::posix::stream_descriptor> socket =
|
||||
make_shared<boost::asio::posix::stream_descriptor>(ref(getGlobalIoService()));
|
||||
void
|
||||
EthernetFactory::doProcessConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context)
|
||||
{
|
||||
// ether
|
||||
// {
|
||||
// listen yes
|
||||
// idle_timeout 600
|
||||
// mcast yes
|
||||
// mcast_group 01:00:5E:00:17:AA
|
||||
// mcast_ad_hoc no
|
||||
// whitelist
|
||||
// {
|
||||
// *
|
||||
// }
|
||||
// blacklist
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
face = make_shared<EthernetFace>(socket, interface, address);
|
||||
face->onFail += bind(&EthernetFactory::afterFaceFailed,
|
||||
this, name, address);
|
||||
m_multicastFaces[std::make_pair(name, address)] = face;
|
||||
UnicastConfig unicastConfig;
|
||||
MulticastConfig mcastConfig;
|
||||
|
||||
if (configSection) {
|
||||
// listen and mcast default to 'yes' but only if face_system.ether section is present
|
||||
unicastConfig.isEnabled = unicastConfig.wantListen = mcastConfig.isEnabled = true;
|
||||
|
||||
for (const auto& pair : *configSection) {
|
||||
const std::string& key = pair.first;
|
||||
const ConfigSection& value = pair.second;
|
||||
|
||||
if (key == "listen") {
|
||||
unicastConfig.wantListen = ConfigFile::parseYesNo(pair, "face_system.ether");
|
||||
}
|
||||
else if (key == "idle_timeout") {
|
||||
unicastConfig.idleTimeout = time::seconds(ConfigFile::parseNumber<uint32_t>(pair, "face_system.ether"));
|
||||
}
|
||||
else if (key == "mcast") {
|
||||
mcastConfig.isEnabled = ConfigFile::parseYesNo(pair, "face_system.ether");
|
||||
}
|
||||
else if (key == "mcast_group") {
|
||||
const std::string& valueStr = value.get_value<std::string>();
|
||||
mcastConfig.group = ethernet::Address::fromString(valueStr);
|
||||
if (mcastConfig.group.isNull()) {
|
||||
NDN_THROW(ConfigFile::Error("face_system.ether.mcast_group: '" +
|
||||
valueStr + "' cannot be parsed as an Ethernet address"));
|
||||
}
|
||||
else if (!mcastConfig.group.isMulticast()) {
|
||||
NDN_THROW(ConfigFile::Error("face_system.ether.mcast_group: '" +
|
||||
valueStr + "' is not a multicast address"));
|
||||
}
|
||||
}
|
||||
else if (key == "mcast_ad_hoc") {
|
||||
bool wantAdHoc = ConfigFile::parseYesNo(pair, "face_system.ether");
|
||||
mcastConfig.linkType = wantAdHoc ? ndn::nfd::LINK_TYPE_AD_HOC : ndn::nfd::LINK_TYPE_MULTI_ACCESS;
|
||||
}
|
||||
else if (key == "whitelist") {
|
||||
mcastConfig.netifPredicate.parseWhitelist(value);
|
||||
}
|
||||
else if (key == "blacklist") {
|
||||
mcastConfig.netifPredicate.parseBlacklist(value);
|
||||
}
|
||||
else {
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option face_system.ether." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context.isDryRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (unicastConfig.isEnabled) {
|
||||
if (m_unicastConfig.wantListen && !unicastConfig.wantListen && !m_channels.empty()) {
|
||||
NFD_LOG_WARN("Cannot stop listening on Ethernet channels");
|
||||
}
|
||||
if (m_unicastConfig.idleTimeout != unicastConfig.idleTimeout && !m_channels.empty()) {
|
||||
NFD_LOG_WARN("Idle timeout setting applies to new Ethernet channels only");
|
||||
}
|
||||
}
|
||||
else if (m_unicastConfig.isEnabled && !m_channels.empty()) {
|
||||
NFD_LOG_WARN("Cannot disable Ethernet channels after initialization");
|
||||
}
|
||||
|
||||
if (m_mcastConfig.isEnabled != mcastConfig.isEnabled) {
|
||||
if (mcastConfig.isEnabled) {
|
||||
NFD_LOG_INFO("enabling multicast on " << mcastConfig.group);
|
||||
}
|
||||
else {
|
||||
NFD_LOG_INFO("disabling multicast");
|
||||
}
|
||||
}
|
||||
else if (mcastConfig.isEnabled) {
|
||||
if (m_mcastConfig.linkType != mcastConfig.linkType && !m_mcastFaces.empty()) {
|
||||
NFD_LOG_WARN("Cannot change ad hoc setting on existing faces");
|
||||
}
|
||||
if (m_mcastConfig.group != mcastConfig.group) {
|
||||
NFD_LOG_INFO("changing multicast group from " << m_mcastConfig.group <<
|
||||
" to " << mcastConfig.group);
|
||||
}
|
||||
if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
|
||||
NFD_LOG_INFO("changing whitelist/blacklist");
|
||||
}
|
||||
}
|
||||
|
||||
// Even if there's no configuration change, we still need to re-apply configuration because
|
||||
// netifs may have changed.
|
||||
m_unicastConfig = unicastConfig;
|
||||
m_mcastConfig = mcastConfig;
|
||||
this->applyConfig(context);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFactory::doCreateFace(const CreateFaceRequest& req,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure)
|
||||
{
|
||||
if (!req.localUri || req.localUri->getScheme() != "dev") {
|
||||
NFD_LOG_TRACE("Cannot create unicast Ethernet face without dev:// LocalUri");
|
||||
onFailure(406, "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme");
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.params.persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
|
||||
NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND");
|
||||
onFailure(406, "Outgoing Ethernet faces do not support on-demand persistency");
|
||||
return;
|
||||
}
|
||||
|
||||
ethernet::Address remoteEndpoint(ethernet::Address::fromString(req.remoteUri.getHost()));
|
||||
std::string localEndpoint(req.localUri->getHost());
|
||||
|
||||
if (remoteEndpoint.isMulticast()) {
|
||||
NFD_LOG_TRACE("createFace does not support multicast faces");
|
||||
onFailure(406, "Cannot create multicast Ethernet faces");
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.params.wantLocalFields) {
|
||||
// Ethernet faces are never local
|
||||
NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
|
||||
onFailure(406, "Local fields can only be enabled on faces with local scope");
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.params.mtu && *req.params.mtu < MIN_MTU) {
|
||||
// The specified MTU must be greater than the minimum possible
|
||||
NFD_LOG_TRACE("createFace: override MTU cannot be less than " << MIN_MTU);
|
||||
onFailure(406, "Override MTU cannot be less than " + to_string(MIN_MTU));
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& i : m_channels) {
|
||||
if (i.first == localEndpoint) {
|
||||
i.second->connect(remoteEndpoint, req.params, onCreated, onFailure);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("No channels available to connect to " << remoteEndpoint);
|
||||
onFailure(504, "No channels available to connect");
|
||||
}
|
||||
|
||||
shared_ptr<EthernetChannel>
|
||||
EthernetFactory::createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
|
||||
time::nanoseconds idleTimeout)
|
||||
{
|
||||
auto it = m_channels.find(localEndpoint->getName());
|
||||
if (it != m_channels.end())
|
||||
return it->second;
|
||||
|
||||
auto channel = std::make_shared<EthernetChannel>(localEndpoint, idleTimeout);
|
||||
m_channels[localEndpoint->getName()] = channel;
|
||||
return channel;
|
||||
}
|
||||
|
||||
std::vector<shared_ptr<const Channel>>
|
||||
EthernetFactory::doGetChannels() const
|
||||
{
|
||||
return getChannelsFromMap(m_channels);
|
||||
}
|
||||
|
||||
shared_ptr<Face>
|
||||
EthernetFactory::createMulticastFace(const ndn::net::NetworkInterface& netif,
|
||||
const ethernet::Address& address)
|
||||
{
|
||||
BOOST_ASSERT(address.isMulticast());
|
||||
|
||||
auto key = std::make_pair(netif.getName(), address);
|
||||
auto found = m_mcastFaces.find(key);
|
||||
if (found != m_mcastFaces.end()) {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
GenericLinkService::Options opts;
|
||||
opts.allowFragmentation = true;
|
||||
opts.allowReassembly = true;
|
||||
|
||||
auto linkService = make_unique<GenericLinkService>(opts);
|
||||
auto transport = make_unique<MulticastEthernetTransport>(netif, address, m_mcastConfig.linkType);
|
||||
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
|
||||
|
||||
m_mcastFaces[key] = face;
|
||||
connectFaceClosedSignal(*face, [this, key] { m_mcastFaces.erase(key); });
|
||||
|
||||
auto channelIt = m_channels.find(netif.getName());
|
||||
face->setChannel(channelIt != m_channels.end() ? channelIt->second : nullptr);
|
||||
|
||||
return face;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFactory::afterFaceFailed(const std::string& interfaceName,
|
||||
const ethernet::Address& address)
|
||||
shared_ptr<EthernetChannel>
|
||||
EthernetFactory::applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif)
|
||||
{
|
||||
NFD_LOG_DEBUG("afterFaceFailed: " << interfaceName << "/" << address);
|
||||
m_multicastFaces.erase(std::make_pair(interfaceName, address));
|
||||
if (!m_unicastConfig.isEnabled) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (netif->getType() != ndn::net::InterfaceType::ETHERNET) {
|
||||
NFD_LOG_DEBUG("Not creating channel on " << netif->getName() << ": incompatible netif type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!netif->isUp()) {
|
||||
NFD_LOG_DEBUG("Not creating channel on " << netif->getName() << ": netif is down");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (netif->getEthernetAddress().isNull()) {
|
||||
NFD_LOG_DEBUG("Not creating channel on " << netif->getName() << ": invalid Ethernet address");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto channel = this->createChannel(netif, m_unicastConfig.idleTimeout);
|
||||
if (m_unicastConfig.wantListen && !channel->isListening()) {
|
||||
try {
|
||||
channel->listen(this->addFace, nullptr);
|
||||
}
|
||||
catch (const EthernetChannel::Error& e) {
|
||||
NFD_LOG_WARN("Cannot listen on " << netif->getName() << ": " << e.what());
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
shared_ptr<EthernetFace>
|
||||
EthernetFactory::findMulticastFace(const std::string& interfaceName,
|
||||
const ethernet::Address& address) const
|
||||
shared_ptr<Face>
|
||||
EthernetFactory::applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif)
|
||||
{
|
||||
MulticastFaceMap::const_iterator i =
|
||||
m_multicastFaces.find(std::make_pair(interfaceName, address));
|
||||
if (i != m_multicastFaces.end())
|
||||
return i->second;
|
||||
else
|
||||
return shared_ptr<EthernetFace>();
|
||||
if (!m_mcastConfig.isEnabled) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (netif.getType() != ndn::net::InterfaceType::ETHERNET) {
|
||||
NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": incompatible netif type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!netif.isUp()) {
|
||||
NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": netif is down");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!netif.canMulticast()) {
|
||||
NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": netif cannot multicast");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (netif.getEthernetAddress().isNull()) {
|
||||
NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": invalid Ethernet address");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!m_mcastConfig.netifPredicate(netif)) {
|
||||
NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": rejected by whitelist/blacklist");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NFD_LOG_DEBUG("Creating multicast face on " << netif.getName());
|
||||
shared_ptr<Face> face;
|
||||
try {
|
||||
face = this->createMulticastFace(netif, m_mcastConfig.group);
|
||||
}
|
||||
catch (const EthernetTransport::Error& e) {
|
||||
NFD_LOG_WARN("Cannot create multicast face on " << netif.getName() << ": " << e.what());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (face->getId() == face::INVALID_FACEID) {
|
||||
// new face: register with forwarding
|
||||
this->addFace(face);
|
||||
}
|
||||
return face;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFactory::createFace(const FaceUri& uri,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceConnectFailedCallback& onConnectFailed)
|
||||
EthernetFactory::applyConfig(const FaceSystem::ConfigContext&)
|
||||
{
|
||||
throw Error("EthernetFactory does not support 'createFace' operation");
|
||||
}
|
||||
if (m_unicastConfig.isEnabled) {
|
||||
providedSchemes.insert("ether");
|
||||
}
|
||||
else {
|
||||
providedSchemes.erase("ether");
|
||||
}
|
||||
|
||||
std::list<shared_ptr<const Channel> >
|
||||
EthernetFactory::getChannels() const
|
||||
{
|
||||
return std::list<shared_ptr<const Channel> >();
|
||||
// collect old multicast faces
|
||||
std::set<shared_ptr<Face>> oldFaces;
|
||||
boost::copy(m_mcastFaces | boost::adaptors::map_values, std::inserter(oldFaces, oldFaces.end()));
|
||||
|
||||
// create channels and multicast faces if requested by config
|
||||
for (const auto& netif : netmon->listNetworkInterfaces()) {
|
||||
this->applyUnicastConfigToNetif(netif);
|
||||
|
||||
auto face = this->applyMcastConfigToNetif(*netif);
|
||||
if (face != nullptr) {
|
||||
// don't destroy face
|
||||
oldFaces.erase(face);
|
||||
}
|
||||
}
|
||||
|
||||
// destroy old multicast faces that are not needed in new configuration
|
||||
for (const auto& face : oldFaces) {
|
||||
face->close();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -21,100 +21,114 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
|
||||
|
||||
#include "ethernet-face.hpp"
|
||||
#include "protocol-factory.hpp"
|
||||
#include "ethernet-channel.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class NetworkInterfaceInfo;
|
||||
|
||||
class EthernetFactory : public ProtocolFactory
|
||||
/** \brief Protocol factory for Ethernet
|
||||
*/
|
||||
class EthernetFactory final : public ProtocolFactory
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Exception of EthernetFactory
|
||||
*/
|
||||
class Error : public ProtocolFactory::Error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: ProtocolFactory::Error(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
static const std::string&
|
||||
getId() noexcept;
|
||||
|
||||
typedef std::map< std::pair<std::string, ethernet::Address>,
|
||||
shared_ptr<EthernetFace> > MulticastFaceMap;
|
||||
|
||||
// from ProtocolFactory
|
||||
virtual void
|
||||
createFace(const FaceUri& uri,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceConnectFailedCallback& onConnectFailed);
|
||||
explicit
|
||||
EthernetFactory(const CtorParams& params);
|
||||
|
||||
/**
|
||||
* \brief Create an EthernetFace to communicate with the given multicast group
|
||||
* \brief Create Ethernet-based channel on the specified network interface
|
||||
*
|
||||
* If this method is called twice with the same interface and group, only
|
||||
* one face will be created. Instead, the second call will just retrieve
|
||||
* the existing face.
|
||||
* If this method is called twice with the same endpoint, only one channel
|
||||
* will be created. The second call will just return the existing channel.
|
||||
*
|
||||
* \param interface Local network interface
|
||||
* \param address Ethernet broadcast/multicast destination address
|
||||
*
|
||||
* \returns always a valid shared pointer to an EthernetFace object,
|
||||
* an exception will be thrown if the creation fails
|
||||
*
|
||||
* \throws EthernetFactory::Error or EthernetFace::Error
|
||||
* \return always a valid pointer to a EthernetChannel object, an exception
|
||||
* is thrown if it cannot be created.
|
||||
* \throw PcapHelper::Error channel creation failed
|
||||
*/
|
||||
shared_ptr<EthernetFace>
|
||||
createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface,
|
||||
const ethernet::Address& address);
|
||||
shared_ptr<EthernetChannel>
|
||||
createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
|
||||
time::nanoseconds idleTimeout);
|
||||
|
||||
/**
|
||||
* \brief Get map of configured multicast faces
|
||||
* \brief Create a face to communicate on the given Ethernet multicast group
|
||||
*
|
||||
* If this method is called twice with the same arguments, only one face
|
||||
* will be created. The second call will just return the existing face.
|
||||
*
|
||||
* \param localEndpoint local network interface
|
||||
* \param group multicast group address
|
||||
*
|
||||
* \throw EthernetTransport::Error transport creation fails
|
||||
*/
|
||||
const MulticastFaceMap&
|
||||
getMulticastFaces() const;
|
||||
|
||||
virtual std::list<shared_ptr<const Channel> >
|
||||
getChannels() const;
|
||||
shared_ptr<Face>
|
||||
createMulticastFace(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& group);
|
||||
|
||||
private:
|
||||
/** \brief process face_system.ether config section
|
||||
*/
|
||||
void
|
||||
afterFaceFailed(const std::string& interfaceName,
|
||||
const ethernet::Address& address);
|
||||
doProcessConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context) final;
|
||||
|
||||
/**
|
||||
* \brief Look up EthernetFace using specified interface and address
|
||||
*
|
||||
* \returns shared pointer to the existing EthernetFace object or
|
||||
* empty shared pointer when such face does not exist
|
||||
*
|
||||
* \throws never
|
||||
void
|
||||
doCreateFace(const CreateFaceRequest& req,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure) final;
|
||||
|
||||
std::vector<shared_ptr<const Channel>>
|
||||
doGetChannels() const final;
|
||||
|
||||
/** \brief Create EthernetChannel on \p netif if requested by \p m_unicastConfig.
|
||||
* \return new or existing channel, or nullptr if no channel should be created
|
||||
*/
|
||||
shared_ptr<EthernetFace>
|
||||
findMulticastFace(const std::string& interfaceName,
|
||||
const ethernet::Address& address) const;
|
||||
shared_ptr<EthernetChannel>
|
||||
applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif);
|
||||
|
||||
/** \brief Create Ethernet multicast face on \p netif if requested by \p m_mcastConfig.
|
||||
* \return new or existing face, or nullptr if no face should be created
|
||||
*/
|
||||
shared_ptr<Face>
|
||||
applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif);
|
||||
|
||||
void
|
||||
applyConfig(const FaceSystem::ConfigContext& context);
|
||||
|
||||
private:
|
||||
MulticastFaceMap m_multicastFaces;
|
||||
std::map<std::string, shared_ptr<EthernetChannel>> m_channels; ///< ifname => channel
|
||||
|
||||
struct UnicastConfig
|
||||
{
|
||||
bool isEnabled = false;
|
||||
bool wantListen = false;
|
||||
time::nanoseconds idleTimeout = 10_min;
|
||||
};
|
||||
UnicastConfig m_unicastConfig;
|
||||
|
||||
struct MulticastConfig
|
||||
{
|
||||
bool isEnabled = false;
|
||||
ethernet::Address group = ethernet::getDefaultMulticastAddress();
|
||||
ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS;
|
||||
NetworkInterfacePredicate netifPredicate;
|
||||
};
|
||||
MulticastConfig m_mcastConfig;
|
||||
|
||||
/// (ifname, group) => face
|
||||
std::map<std::pair<std::string, ethernet::Address>, shared_ptr<Face>> m_mcastFaces;
|
||||
|
||||
signal::ScopedConnection m_netifAddConn;
|
||||
};
|
||||
|
||||
|
||||
inline const EthernetFactory::MulticastFaceMap&
|
||||
EthernetFactory::getMulticastFaces() const
|
||||
{
|
||||
return m_multicastFaces;
|
||||
}
|
||||
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
|
||||
@@ -0,0 +1,61 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ethernet-protocol.hpp"
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
std::tuple<const ether_header*, std::string>
|
||||
checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr)
|
||||
{
|
||||
if (packet.size() < HDR_LEN + MIN_DATA_LEN)
|
||||
return {nullptr, "Received frame too short: " + to_string(packet.size()) + " bytes"};
|
||||
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet.data());
|
||||
|
||||
// in some cases VLAN-tagged frames may survive the BPF filter,
|
||||
// make sure we do not process those frames (see #3348)
|
||||
uint16_t ethertype = boost::endian::big_to_native(eh->ether_type);
|
||||
if (ethertype != ETHERTYPE_NDN)
|
||||
return {nullptr, "Received frame with wrong ethertype: " + to_string(ethertype)};
|
||||
|
||||
#ifdef _DEBUG
|
||||
Address shost(eh->ether_shost);
|
||||
if (shost == localAddr)
|
||||
return {nullptr, "Received frame sent by this host"};
|
||||
|
||||
Address dhost(eh->ether_dhost);
|
||||
if (dhost != destAddr)
|
||||
return {nullptr, "Received frame addressed to another host or multicast group: " + dhost.toString()};
|
||||
#endif
|
||||
|
||||
return {eh, ""};
|
||||
}
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -23,31 +23,23 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_MGMT_APP_FACE_HPP
|
||||
#define NFD_DAEMON_MGMT_APP_FACE_HPP
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/common.hpp"
|
||||
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/net/ethernet.hpp>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
typedef function<void(const Name&, const Interest&)> OnInterest;
|
||||
using namespace ndn::ethernet;
|
||||
|
||||
class AppFace
|
||||
{
|
||||
public:
|
||||
virtual void
|
||||
setInterestFilter(const Name& filter,
|
||||
OnInterest onInterest) = 0;
|
||||
|
||||
virtual void
|
||||
put(const Data& data) = 0;
|
||||
|
||||
virtual
|
||||
~AppFace() { }
|
||||
};
|
||||
std::tuple<const ether_header*, std::string>
|
||||
checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr);
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_MGMT_APP_FACE_HPP
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
@@ -0,0 +1,240 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ethernet-transport.hpp"
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
#include <cstring> // for memcpy()
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(EthernetTransport);
|
||||
|
||||
EthernetTransport::EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& remoteEndpoint)
|
||||
: m_socket(getGlobalIoService())
|
||||
, m_pcap(localEndpoint.getName())
|
||||
, m_srcAddress(localEndpoint.getEthernetAddress())
|
||||
, m_destAddress(remoteEndpoint)
|
||||
, m_interfaceName(localEndpoint.getName())
|
||||
, m_hasRecentlyReceived(false)
|
||||
#ifdef _DEBUG
|
||||
, m_nDropped(0)
|
||||
#endif
|
||||
{
|
||||
try {
|
||||
m_pcap.activate(DLT_EN10MB);
|
||||
m_socket.assign(m_pcap.getFd());
|
||||
}
|
||||
catch (const PcapHelper::Error& e) {
|
||||
NDN_THROW_NESTED(Error(e.what()));
|
||||
}
|
||||
|
||||
// Set initial transport state based upon the state of the underlying NetworkInterface
|
||||
handleNetifStateChange(localEndpoint.getState());
|
||||
|
||||
m_netifStateChangedConn = localEndpoint.onStateChanged.connect(
|
||||
[this] (ndn::net::InterfaceState, ndn::net::InterfaceState newState) {
|
||||
handleNetifStateChange(newState);
|
||||
});
|
||||
|
||||
m_netifMtuChangedConn = localEndpoint.onMtuChanged.connect(
|
||||
[this] (uint32_t, uint32_t mtu) {
|
||||
setMtu(mtu);
|
||||
});
|
||||
|
||||
asyncRead();
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::doClose()
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
if (m_socket.is_open()) {
|
||||
// Cancel all outstanding operations and close the socket.
|
||||
// Use the non-throwing variants and ignore errors, if any.
|
||||
boost::system::error_code error;
|
||||
m_socket.cancel(error);
|
||||
m_socket.close(error);
|
||||
}
|
||||
m_pcap.close();
|
||||
|
||||
// Ensure that the Transport stays alive at least
|
||||
// until all pending handlers are dispatched
|
||||
getGlobalIoService().post([this] {
|
||||
this->setState(TransportState::CLOSED);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::handleNetifStateChange(ndn::net::InterfaceState netifState)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE("netif is " << netifState);
|
||||
if (netifState == ndn::net::InterfaceState::RUNNING) {
|
||||
if (getState() == TransportState::DOWN) {
|
||||
this->setState(TransportState::UP);
|
||||
}
|
||||
}
|
||||
else if (getState() == TransportState::UP) {
|
||||
this->setState(TransportState::DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::doSend(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::sendPacket(const ndn::Block& block)
|
||||
{
|
||||
ndn::EncodingBuffer buffer(block);
|
||||
|
||||
// pad with zeroes if the payload is too short
|
||||
if (block.size() < ethernet::MIN_DATA_LEN) {
|
||||
static const uint8_t padding[ethernet::MIN_DATA_LEN] = {};
|
||||
buffer.appendBytes(ndn::make_span(padding).subspan(block.size()));
|
||||
}
|
||||
|
||||
// construct and prepend the ethernet header
|
||||
uint16_t ethertype = boost::endian::native_to_big(ethernet::ETHERTYPE_NDN);
|
||||
buffer.prependBytes({reinterpret_cast<const uint8_t*>(ðertype), ethernet::TYPE_LEN});
|
||||
buffer.prependBytes(m_srcAddress);
|
||||
buffer.prependBytes(m_destAddress);
|
||||
|
||||
// send the frame
|
||||
int sent = pcap_inject(m_pcap, buffer.data(), buffer.size());
|
||||
if (sent < 0)
|
||||
handleError("Send operation failed: " + m_pcap.getLastError());
|
||||
else if (static_cast<size_t>(sent) < buffer.size())
|
||||
handleError("Failed to send the full frame: size=" + to_string(buffer.size()) +
|
||||
" sent=" + to_string(sent));
|
||||
else
|
||||
// print block size because we don't want to count the padding in buffer
|
||||
NFD_LOG_FACE_TRACE("Successfully sent: " << block.size() << " bytes");
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::asyncRead()
|
||||
{
|
||||
m_socket.async_read_some(boost::asio::null_buffers(),
|
||||
[this] (const auto& e, auto) { this->handleRead(e); });
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::handleRead(const boost::system::error_code& error)
|
||||
{
|
||||
if (error) {
|
||||
// boost::asio::error::operation_aborted must be checked first: in that case, the Transport
|
||||
// may already have been destructed, therefore it's unsafe to call getState() or do logging.
|
||||
if (error != boost::asio::error::operation_aborted &&
|
||||
getState() != TransportState::CLOSING &&
|
||||
getState() != TransportState::FAILED &&
|
||||
getState() != TransportState::CLOSED) {
|
||||
handleError("Receive operation failed: " + error.message());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
span<const uint8_t> pkt;
|
||||
std::string err;
|
||||
std::tie(pkt, err) = m_pcap.readNextPacket();
|
||||
|
||||
if (pkt.empty()) {
|
||||
NFD_LOG_FACE_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_srcAddress,
|
||||
m_destAddress.isMulticast() ? m_destAddress : m_srcAddress);
|
||||
if (eh == nullptr) {
|
||||
NFD_LOG_FACE_WARN(err);
|
||||
}
|
||||
else {
|
||||
ethernet::Address sender(eh->ether_shost);
|
||||
pkt = pkt.subspan(ethernet::HDR_LEN);
|
||||
receivePayload(pkt, sender);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
size_t nDropped = m_pcap.getNDropped();
|
||||
if (nDropped - m_nDropped > 0)
|
||||
NFD_LOG_FACE_DEBUG("Detected " << nDropped - m_nDropped << " dropped frame(s)");
|
||||
m_nDropped = nDropped;
|
||||
#endif
|
||||
|
||||
asyncRead();
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::receivePayload(span<const uint8_t> payload, const ethernet::Address& sender)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE("Received: " << payload.size() << " bytes from " << sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(payload);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << sender);
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
m_hasRecentlyReceived = true;
|
||||
|
||||
static_assert(sizeof(EndpointId) >= ethernet::ADDR_LEN, "EndpointId is too small");
|
||||
EndpointId endpoint = 0;
|
||||
if (m_destAddress.isMulticast()) {
|
||||
std::memcpy(&endpoint, sender.data(), sender.size());
|
||||
}
|
||||
|
||||
this->receive(element, endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::handleError(const std::string& errorMessage)
|
||||
{
|
||||
if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
|
||||
NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_ERROR(errorMessage);
|
||||
this->setState(TransportState::FAILED);
|
||||
doClose();
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,119 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
|
||||
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "pcap-helper.hpp"
|
||||
#include "transport.hpp"
|
||||
|
||||
#include <ndn-cxx/net/network-interface.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/**
|
||||
* @brief Base class for Ethernet-based Transports
|
||||
*/
|
||||
class EthernetTransport : public Transport
|
||||
{
|
||||
public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Processes the payload of an incoming frame
|
||||
* @param payload Payload bytes, starting from the first byte after the Ethernet header
|
||||
* @param sender Sender address
|
||||
*/
|
||||
void
|
||||
receivePayload(span<const uint8_t> payload, const ethernet::Address& sender);
|
||||
|
||||
protected:
|
||||
EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& remoteEndpoint);
|
||||
|
||||
void
|
||||
doClose() final;
|
||||
|
||||
bool
|
||||
hasRecentlyReceived() const
|
||||
{
|
||||
return m_hasRecentlyReceived;
|
||||
}
|
||||
|
||||
void
|
||||
resetRecentlyReceived()
|
||||
{
|
||||
m_hasRecentlyReceived = false;
|
||||
}
|
||||
|
||||
private:
|
||||
void
|
||||
handleNetifStateChange(ndn::net::InterfaceState netifState);
|
||||
|
||||
void
|
||||
doSend(const Block& packet) final;
|
||||
|
||||
/**
|
||||
* @brief Sends the specified TLV block on the network wrapped in an Ethernet frame
|
||||
*/
|
||||
void
|
||||
sendPacket(const ndn::Block& block);
|
||||
|
||||
void
|
||||
asyncRead();
|
||||
|
||||
void
|
||||
handleRead(const boost::system::error_code& error);
|
||||
|
||||
void
|
||||
handleError(const std::string& errorMessage);
|
||||
|
||||
protected:
|
||||
boost::asio::posix::stream_descriptor m_socket;
|
||||
PcapHelper m_pcap;
|
||||
ethernet::Address m_srcAddress;
|
||||
ethernet::Address m_destAddress;
|
||||
std::string m_interfaceName;
|
||||
|
||||
private:
|
||||
signal::ScopedConnection m_netifStateChangedConn;
|
||||
signal::ScopedConnection m_netifMtuChangedConn;
|
||||
bool m_hasRecentlyReceived;
|
||||
#ifdef _DEBUG
|
||||
/// number of frames dropped by the kernel, as reported by libpcap
|
||||
size_t m_nDropped;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
|
||||
@@ -0,0 +1,155 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
#include "common/logger.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/nfd-constants.hpp>
|
||||
|
||||
#include <boost/logic/tribool.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class Face;
|
||||
class LinkService;
|
||||
|
||||
/** \brief Identifies a face.
|
||||
*/
|
||||
using FaceId = uint64_t;
|
||||
|
||||
/// indicates an invalid FaceId
|
||||
const FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
|
||||
/// identifies the InternalFace used in management
|
||||
const FaceId FACEID_INTERNAL_FACE = 1;
|
||||
/// identifies a packet comes from the ContentStore
|
||||
const FaceId FACEID_CONTENT_STORE = 254;
|
||||
/// identifies the NullFace that drops every packet
|
||||
const FaceId FACEID_NULL = 255;
|
||||
/// upper bound of reserved FaceIds
|
||||
const FaceId FACEID_RESERVED_MAX = 255;
|
||||
|
||||
/** \brief Minimum MTU that may be set
|
||||
*
|
||||
* This is done to ensure the NDNLPv2 fragmentation feature functions properly.
|
||||
*/
|
||||
const ssize_t MIN_MTU = 64;
|
||||
|
||||
/** \brief Identifies a remote endpoint on the link.
|
||||
*
|
||||
* This ID is only meaningful in the context of the same Transport.
|
||||
* Incoming packets from the same remote endpoint have the same EndpointId,
|
||||
* and incoming packets from different remote endpoints have different EndpointIds.
|
||||
*
|
||||
* Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0).
|
||||
*/
|
||||
using EndpointId = uint64_t;
|
||||
|
||||
/** \brief Parameters used to set Transport properties or LinkService options on a newly created face.
|
||||
*
|
||||
* Parameters are passed as a struct rather than individually, so that a future change in the list
|
||||
* of parameters does not require an update to the method signature in all subclasses.
|
||||
*/
|
||||
struct FaceParams
|
||||
{
|
||||
ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
|
||||
optional<time::nanoseconds> baseCongestionMarkingInterval;
|
||||
optional<uint64_t> defaultCongestionThreshold;
|
||||
optional<ssize_t> mtu;
|
||||
bool wantLocalFields = false;
|
||||
bool wantLpReliability = false;
|
||||
boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
|
||||
};
|
||||
|
||||
/** \brief For internal use by FaceLogging macros.
|
||||
*
|
||||
* FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
|
||||
*
|
||||
* `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
|
||||
* should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
|
||||
* which will appear as part of the log message.
|
||||
*/
|
||||
template<typename T>
|
||||
class FaceLogHelper
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
FaceLogHelper(const T& obj1) noexcept
|
||||
: obj(obj1)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
const T& obj;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
|
||||
using face::EndpointId;
|
||||
using face::FaceId;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
/** \defgroup FaceLogging Face logging macros
|
||||
*
|
||||
* These macros augment the log message with some face-specific information,
|
||||
* such as the face ID, that are useful to distinguish which face produced the
|
||||
* message. It is strongly recommended to use these macros instead of the
|
||||
* generic ones for all logging inside Face, LinkService, Transport subclasses.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \cond */
|
||||
// implementation detail
|
||||
#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
|
||||
::nfd::face::FaceLogHelper< \
|
||||
typename std::remove_cv< \
|
||||
typename std::remove_reference<decltype(*this)>::type \
|
||||
>::type \
|
||||
>(*this) \
|
||||
<< msg)
|
||||
/** \endcond */
|
||||
|
||||
/** \brief Log a message at TRACE level */
|
||||
#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
|
||||
|
||||
/** \brief Log a message at DEBUG level */
|
||||
#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
|
||||
|
||||
/** \brief Log a message at INFO level */
|
||||
#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
|
||||
|
||||
/** \brief Log a message at WARN level */
|
||||
#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
|
||||
|
||||
/** \brief Log a message at ERROR level */
|
||||
#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "face-counters.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
FaceCounters::FaceCounters(const LinkService::Counters& linkServiceCounters,
|
||||
const Transport::Counters& transportCounters)
|
||||
: nInInterests(linkServiceCounters.nInInterests)
|
||||
, nOutInterests(linkServiceCounters.nOutInterests)
|
||||
, nInterestsExceededRetx(linkServiceCounters.nInterestsExceededRetx)
|
||||
, nInData(linkServiceCounters.nInData)
|
||||
, nOutData(linkServiceCounters.nOutData)
|
||||
, nInNacks(linkServiceCounters.nInNacks)
|
||||
, nOutNacks(linkServiceCounters.nOutNacks)
|
||||
, nInPackets(transportCounters.nInPackets)
|
||||
, nOutPackets(transportCounters.nOutPackets)
|
||||
, nInBytes(transportCounters.nInBytes)
|
||||
, nOutBytes(transportCounters.nOutBytes)
|
||||
, m_linkServiceCounters(linkServiceCounters)
|
||||
, m_transportCounters(transportCounters)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
+63
-214
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -26,226 +26,75 @@
|
||||
#ifndef NFD_DAEMON_FACE_FACE_COUNTERS_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_COUNTERS_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "link-service.hpp"
|
||||
#include "transport.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \brief represents a counter of number of packets
|
||||
/** \brief gives access to counters provided by Face
|
||||
*
|
||||
* This type is a facade that exposes common counters of a Face.
|
||||
*
|
||||
* get<T>() can be used to access extended counters provided by
|
||||
* LinkService or Transport of the Face.
|
||||
*/
|
||||
// PacketCounter is noncopyable, because increment should be called on the counter,
|
||||
// not a copy of it; it's implicitly convertible to uint64_t to be observed
|
||||
class PacketCounter : noncopyable
|
||||
class FaceCounters
|
||||
{
|
||||
public:
|
||||
typedef uint64_t rep;
|
||||
FaceCounters(const LinkService::Counters& linkServiceCounters,
|
||||
const Transport::Counters& transportCounters);
|
||||
|
||||
PacketCounter()
|
||||
: m_value(0)
|
||||
{
|
||||
}
|
||||
|
||||
operator rep() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
PacketCounter&
|
||||
operator++()
|
||||
{
|
||||
++m_value;
|
||||
return *this;
|
||||
}
|
||||
// postfix ++ operator is not provided because it's not needed
|
||||
|
||||
void
|
||||
set(rep value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
private:
|
||||
rep m_value;
|
||||
};
|
||||
|
||||
/** \brief represents a counter of number of bytes
|
||||
*/
|
||||
// ByteCounter is noncopyable, because increment should be called on the counter,
|
||||
// not a copy of it; it's implicitly convertible to uint64_t to be observed
|
||||
class ByteCounter : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef uint64_t rep;
|
||||
|
||||
ByteCounter()
|
||||
: m_value(0)
|
||||
{
|
||||
}
|
||||
|
||||
operator rep() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
ByteCounter&
|
||||
operator+=(rep n)
|
||||
{
|
||||
m_value += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
set(rep value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
private:
|
||||
rep m_value;
|
||||
};
|
||||
|
||||
/** \brief contains network layer packet counters
|
||||
*/
|
||||
class NetworkLayerCounters : noncopyable
|
||||
{
|
||||
public:
|
||||
/// incoming Interest
|
||||
const PacketCounter&
|
||||
getNInInterests() const
|
||||
{
|
||||
return m_nInInterests;
|
||||
}
|
||||
|
||||
PacketCounter&
|
||||
getNInInterests()
|
||||
{
|
||||
return m_nInInterests;
|
||||
}
|
||||
|
||||
/// incoming Data
|
||||
const PacketCounter&
|
||||
getNInDatas() const
|
||||
{
|
||||
return m_nInDatas;
|
||||
}
|
||||
|
||||
PacketCounter&
|
||||
getNInDatas()
|
||||
{
|
||||
return m_nInDatas;
|
||||
}
|
||||
|
||||
/// outgoing Interest
|
||||
const PacketCounter&
|
||||
getNOutInterests() const
|
||||
{
|
||||
return m_nOutInterests;
|
||||
}
|
||||
|
||||
PacketCounter&
|
||||
getNOutInterests()
|
||||
{
|
||||
return m_nOutInterests;
|
||||
}
|
||||
|
||||
/// outgoing Data
|
||||
const PacketCounter&
|
||||
getNOutDatas() const
|
||||
{
|
||||
return m_nOutDatas;
|
||||
}
|
||||
|
||||
PacketCounter&
|
||||
getNOutDatas()
|
||||
{
|
||||
return m_nOutDatas;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** \brief copy current obseverations to a struct
|
||||
* \param recipient an object with set methods for counters
|
||||
/** \return counters provided by LinkService
|
||||
* \tparam T LinkService counters type
|
||||
* \throw std::bad_cast counters type mismatch
|
||||
*/
|
||||
template<typename R>
|
||||
void
|
||||
copyTo(R& recipient) const
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_base_of<LinkService::Counters, T>::value, const T&>::type
|
||||
get() const
|
||||
{
|
||||
recipient.setNInInterests(this->getNInInterests());
|
||||
recipient.setNInDatas(this->getNInDatas());
|
||||
recipient.setNOutInterests(this->getNOutInterests());
|
||||
recipient.setNOutDatas(this->getNOutDatas());
|
||||
return dynamic_cast<const T&>(m_linkServiceCounters);
|
||||
}
|
||||
|
||||
/** \return counters provided by Transport
|
||||
* \tparam T Transport counters type
|
||||
* \throw std::bad_cast counters type mismatch
|
||||
*/
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_base_of<Transport::Counters, T>::value, const T&>::type
|
||||
get() const
|
||||
{
|
||||
return dynamic_cast<const T&>(m_transportCounters);
|
||||
}
|
||||
|
||||
public:
|
||||
const PacketCounter& nInInterests;
|
||||
const PacketCounter& nOutInterests;
|
||||
const PacketCounter& nInterestsExceededRetx;
|
||||
const PacketCounter& nInData;
|
||||
const PacketCounter& nOutData;
|
||||
const PacketCounter& nInNacks;
|
||||
const PacketCounter& nOutNacks;
|
||||
|
||||
const PacketCounter& nInPackets;
|
||||
const PacketCounter& nOutPackets;
|
||||
const ByteCounter& nInBytes;
|
||||
const ByteCounter& nOutBytes;
|
||||
|
||||
/** \brief count of incoming Interests dropped due to HopLimit == 0
|
||||
*/
|
||||
PacketCounter nInHopLimitZero;
|
||||
|
||||
/** \brief count of outgoing Interests dropped due to HopLimit == 0 on non-local faces
|
||||
*/
|
||||
PacketCounter nOutHopLimitZero;
|
||||
|
||||
private:
|
||||
PacketCounter m_nInInterests;
|
||||
PacketCounter m_nInDatas;
|
||||
PacketCounter m_nOutInterests;
|
||||
PacketCounter m_nOutDatas;
|
||||
};
|
||||
|
||||
/** \brief contains link layer byte counters
|
||||
*/
|
||||
class LinkLayerCounters : noncopyable
|
||||
{
|
||||
public:
|
||||
/// received bytes
|
||||
const ByteCounter&
|
||||
getNInBytes() const
|
||||
{
|
||||
return m_nInBytes;
|
||||
}
|
||||
|
||||
ByteCounter&
|
||||
getNInBytes()
|
||||
{
|
||||
return m_nInBytes;
|
||||
}
|
||||
|
||||
/// sent bytes
|
||||
const ByteCounter&
|
||||
getNOutBytes() const
|
||||
{
|
||||
return m_nOutBytes;
|
||||
}
|
||||
|
||||
ByteCounter&
|
||||
getNOutBytes()
|
||||
{
|
||||
return m_nOutBytes;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** \brief copy current obseverations to a struct
|
||||
* \param recipient an object with set methods for counters
|
||||
*/
|
||||
template<typename R>
|
||||
void
|
||||
copyTo(R& recipient) const
|
||||
{
|
||||
recipient.setNInBytes(this->getNInBytes());
|
||||
recipient.setNOutBytes(this->getNOutBytes());
|
||||
}
|
||||
|
||||
private:
|
||||
ByteCounter m_nInBytes;
|
||||
ByteCounter m_nOutBytes;
|
||||
};
|
||||
|
||||
/** \brief contains counters on face
|
||||
*/
|
||||
class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
|
||||
{
|
||||
public:
|
||||
/** \brief copy current obseverations to a struct
|
||||
* \param recipient an object with set methods for counters
|
||||
*/
|
||||
template<typename R>
|
||||
void
|
||||
copyTo(R& recipient) const
|
||||
{
|
||||
this->NetworkLayerCounters::copyTo(recipient);
|
||||
this->LinkLayerCounters::copyTo(recipient);
|
||||
}
|
||||
const LinkService::Counters& m_linkServiceCounters;
|
||||
const Transport::Counters& m_transportCounters;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP
|
||||
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
|
||||
#include "face.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief Represents a face-endpoint pair in the forwarder.
|
||||
* \sa face::Face, face::EndpointId
|
||||
*/
|
||||
class FaceEndpoint
|
||||
{
|
||||
public:
|
||||
FaceEndpoint(Face& face, EndpointId endpoint)
|
||||
: face(face)
|
||||
, endpoint(endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
Face& face;
|
||||
const EndpointId endpoint;
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, const FaceEndpoint& fe)
|
||||
{
|
||||
return os << '(' << fe.face.getId() << ',' << fe.endpoint << ')';
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
@@ -0,0 +1,170 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "face-system.hpp"
|
||||
#include "protocol-factory.hpp"
|
||||
#include "netdev-bound.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "fw/face-table.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(FaceSystem);
|
||||
|
||||
const std::string CFGSEC_FACESYSTEM = "face_system";
|
||||
const std::string CFGSEC_GENERAL = "general";
|
||||
const std::string CFGSEC_GENERAL_FQ = CFGSEC_FACESYSTEM + ".general";
|
||||
const std::string CFGSEC_NETDEVBOUND = "netdev_bound";
|
||||
|
||||
FaceSystem::FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon)
|
||||
: m_faceTable(faceTable)
|
||||
, m_netmon(std::move(netmon))
|
||||
{
|
||||
auto pfCtorParams = this->makePFCtorParams();
|
||||
for (const auto& id : ProtocolFactory::listRegistered()) {
|
||||
NFD_LOG_TRACE("creating factory " << id);
|
||||
m_factories[id] = ProtocolFactory::create(id, pfCtorParams);
|
||||
}
|
||||
|
||||
m_netdevBound = make_unique<NetdevBound>(pfCtorParams, *this);
|
||||
}
|
||||
|
||||
ProtocolFactoryCtorParams
|
||||
FaceSystem::makePFCtorParams()
|
||||
{
|
||||
auto addFace = [this] (auto face) { m_faceTable.add(std::move(face)); };
|
||||
return {addFace, m_netmon};
|
||||
}
|
||||
|
||||
FaceSystem::~FaceSystem() = default;
|
||||
|
||||
std::set<const ProtocolFactory*>
|
||||
FaceSystem::listProtocolFactories() const
|
||||
{
|
||||
std::set<const ProtocolFactory*> factories;
|
||||
for (const auto& p : m_factories) {
|
||||
factories.insert(p.second.get());
|
||||
}
|
||||
return factories;
|
||||
}
|
||||
|
||||
ProtocolFactory*
|
||||
FaceSystem::getFactoryById(const std::string& id)
|
||||
{
|
||||
auto found = m_factories.find(id);
|
||||
return found == m_factories.end() ? nullptr : found->second.get();
|
||||
}
|
||||
|
||||
ProtocolFactory*
|
||||
FaceSystem::getFactoryByScheme(const std::string& scheme)
|
||||
{
|
||||
auto found = m_factoryByScheme.find(scheme);
|
||||
return found == m_factoryByScheme.end() ? nullptr : found->second;
|
||||
}
|
||||
|
||||
bool
|
||||
FaceSystem::hasFactoryForScheme(const std::string& scheme) const
|
||||
{
|
||||
return m_factoryByScheme.count(scheme) > 0;
|
||||
}
|
||||
|
||||
void
|
||||
FaceSystem::setConfigFile(ConfigFile& configFile)
|
||||
{
|
||||
configFile.addSectionHandler(CFGSEC_FACESYSTEM, [this] (auto&&... args) {
|
||||
processConfig(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
FaceSystem::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
|
||||
{
|
||||
ConfigContext context;
|
||||
context.isDryRun = isDryRun;
|
||||
|
||||
// process general protocol factory config section
|
||||
auto generalSection = configSection.get_child_optional(CFGSEC_GENERAL);
|
||||
if (generalSection) {
|
||||
for (const auto& pair : *generalSection) {
|
||||
const std::string& key = pair.first;
|
||||
if (key == "enable_congestion_marking") {
|
||||
context.generalConfig.wantCongestionMarking = ConfigFile::parseYesNo(pair, CFGSEC_GENERAL_FQ);
|
||||
}
|
||||
else {
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option " + CFGSEC_GENERAL_FQ + "." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process in protocol factories
|
||||
for (const auto& pair : m_factories) {
|
||||
const std::string& sectionName = pair.first;
|
||||
ProtocolFactory* factory = pair.second.get();
|
||||
|
||||
std::set<std::string> oldProvidedSchemes = factory->getProvidedSchemes();
|
||||
factory->processConfig(configSection.get_child_optional(sectionName), context);
|
||||
|
||||
if (!isDryRun) {
|
||||
for (const std::string& scheme : factory->getProvidedSchemes()) {
|
||||
m_factoryByScheme[scheme] = factory;
|
||||
if (oldProvidedSchemes.erase(scheme) == 0) {
|
||||
NFD_LOG_TRACE("factory " << sectionName <<
|
||||
" provides " << scheme << " FaceUri scheme");
|
||||
}
|
||||
}
|
||||
for (const std::string& scheme : oldProvidedSchemes) {
|
||||
m_factoryByScheme.erase(scheme);
|
||||
NFD_LOG_TRACE("factory " << sectionName <<
|
||||
" no longer provides " << scheme << " FaceUri scheme");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process netdev_bound section, after factories start providing *+dev schemes
|
||||
auto netdevBoundSection = configSection.get_child_optional(CFGSEC_NETDEVBOUND);
|
||||
m_netdevBound->processConfig(netdevBoundSection, context);
|
||||
|
||||
// process other sections
|
||||
std::set<std::string> seenSections;
|
||||
for (const auto& pair : configSection) {
|
||||
const std::string& sectionName = pair.first;
|
||||
// const ConfigSection& subSection = pair.second;
|
||||
|
||||
if (!seenSections.insert(sectionName).second) {
|
||||
NDN_THROW(ConfigFile::Error("Duplicate section " + CFGSEC_FACESYSTEM + "." + sectionName));
|
||||
}
|
||||
|
||||
if (sectionName == CFGSEC_GENERAL || sectionName == CFGSEC_NETDEVBOUND ||
|
||||
m_factories.count(sectionName) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option " + CFGSEC_FACESYSTEM + "." + sectionName));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,135 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_FACE_SYSTEM_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_SYSTEM_HPP
|
||||
|
||||
#include "network-predicate.hpp"
|
||||
#include "common/config-file.hpp"
|
||||
|
||||
#include <ndn-cxx/net/network-address.hpp>
|
||||
#include <ndn-cxx/net/network-interface.hpp>
|
||||
#include <ndn-cxx/net/network-monitor.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class FaceTable;
|
||||
|
||||
namespace face {
|
||||
|
||||
class NetdevBound;
|
||||
class ProtocolFactory;
|
||||
struct ProtocolFactoryCtorParams;
|
||||
|
||||
/** \brief entry point of the face system
|
||||
*
|
||||
* NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy.
|
||||
* FaceSystem class is the entry point of NFD's face system and owns ProtocolFactory objects.
|
||||
*/
|
||||
class FaceSystem : noncopyable
|
||||
{
|
||||
public:
|
||||
FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon);
|
||||
|
||||
~FaceSystem();
|
||||
|
||||
/** \return ProtocolFactory objects owned by the FaceSystem
|
||||
*/
|
||||
std::set<const ProtocolFactory*>
|
||||
listProtocolFactories() const;
|
||||
|
||||
/** \return ProtocolFactory for the specified registered factory id or nullptr if not found
|
||||
*/
|
||||
ProtocolFactory*
|
||||
getFactoryById(const std::string& id);
|
||||
|
||||
/** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found
|
||||
*/
|
||||
ProtocolFactory*
|
||||
getFactoryByScheme(const std::string& scheme);
|
||||
|
||||
bool
|
||||
hasFactoryForScheme(const std::string& scheme) const;
|
||||
|
||||
FaceTable&
|
||||
getFaceTable()
|
||||
{
|
||||
return m_faceTable;
|
||||
}
|
||||
|
||||
/** \brief register handler for face_system section of NFD configuration file
|
||||
*/
|
||||
void
|
||||
setConfigFile(ConfigFile& configFile);
|
||||
|
||||
/** \brief configuration options from "general" section
|
||||
*/
|
||||
struct GeneralConfig
|
||||
{
|
||||
bool wantCongestionMarking = true;
|
||||
};
|
||||
|
||||
/** \brief context for processing a config section in ProtocolFactory
|
||||
*/
|
||||
class ConfigContext : noncopyable
|
||||
{
|
||||
public:
|
||||
GeneralConfig generalConfig;
|
||||
bool isDryRun;
|
||||
};
|
||||
|
||||
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
ProtocolFactoryCtorParams
|
||||
makePFCtorParams();
|
||||
|
||||
private:
|
||||
void
|
||||
processConfig(const ConfigSection& configSection, bool isDryRun,
|
||||
const std::string& filename);
|
||||
|
||||
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
/** \brief config section name => protocol factory
|
||||
*/
|
||||
std::map<std::string, unique_ptr<ProtocolFactory>> m_factories;
|
||||
unique_ptr<NetdevBound> m_netdevBound;
|
||||
|
||||
private:
|
||||
/** \brief scheme => protocol factory
|
||||
*
|
||||
* The same protocol factory may be available under multiple schemes.
|
||||
*/
|
||||
std::map<std::string, ProtocolFactory*> m_factoryByScheme;
|
||||
|
||||
FaceTable& m_faceTable;
|
||||
shared_ptr<ndn::net::NetworkMonitor> m_netmon;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
|
||||
using face::FaceSystem;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP
|
||||
+29
-116
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -24,120 +24,33 @@
|
||||
*/
|
||||
|
||||
#include "face.hpp"
|
||||
#include "face-flags.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
|
||||
: m_id(INVALID_FACEID)
|
||||
, m_isLocal(isLocal)
|
||||
, m_remoteUri(remoteUri)
|
||||
, m_localUri(localUri)
|
||||
, m_isOnDemand(false)
|
||||
, m_isFailed(false)
|
||||
Face::Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport)
|
||||
: afterReceiveInterest(service->afterReceiveInterest)
|
||||
, afterReceiveData(service->afterReceiveData)
|
||||
, afterReceiveNack(service->afterReceiveNack)
|
||||
, onDroppedInterest(service->onDroppedInterest)
|
||||
, afterStateChange(transport->afterStateChange)
|
||||
, m_id(INVALID_FACEID)
|
||||
, m_service(std::move(service))
|
||||
, m_transport(std::move(transport))
|
||||
, m_counters(m_service->getCounters(), m_transport->getCounters())
|
||||
{
|
||||
onReceiveInterest += bind(&PacketCounter::operator++, &m_counters.getNInInterests());
|
||||
onReceiveData += bind(&PacketCounter::operator++, &m_counters.getNInDatas());
|
||||
onSendInterest += bind(&PacketCounter::operator++, &m_counters.getNOutInterests());
|
||||
onSendData += bind(&PacketCounter::operator++, &m_counters.getNOutDatas());
|
||||
m_service->setFaceAndTransport(*this, *m_transport);
|
||||
m_transport->setFaceAndLinkService(*this, *m_service);
|
||||
}
|
||||
|
||||
Face::~Face()
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceLogHelper<Face>& flh)
|
||||
{
|
||||
const Face& face = flh.obj;
|
||||
os << "[id=" << face.getId() << ",local=" << face.getLocalUri() <<
|
||||
",remote=" << face.getRemoteUri() << "] ";
|
||||
return os;
|
||||
}
|
||||
|
||||
FaceId
|
||||
Face::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
// this method is private and should be used only by the FaceTable
|
||||
void
|
||||
Face::setId(FaceId faceId)
|
||||
{
|
||||
m_id = faceId;
|
||||
}
|
||||
|
||||
void
|
||||
Face::setDescription(const std::string& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
Face::getDescription() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
bool
|
||||
Face::isMultiAccess() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Face::isUp() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Face::decodeAndDispatchInput(const Block& element)
|
||||
{
|
||||
try {
|
||||
/// \todo Ensure lazy field decoding process
|
||||
|
||||
if (element.type() == tlv::Interest)
|
||||
{
|
||||
shared_ptr<Interest> i = make_shared<Interest>();
|
||||
i->wireDecode(element);
|
||||
this->onReceiveInterest(*i);
|
||||
}
|
||||
else if (element.type() == tlv::Data)
|
||||
{
|
||||
shared_ptr<Data> d = make_shared<Data>();
|
||||
d->wireDecode(element);
|
||||
this->onReceiveData(*d);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (tlv::Error&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Face::fail(const std::string& reason)
|
||||
{
|
||||
if (m_isFailed) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_isFailed = true;
|
||||
this->onFail(reason);
|
||||
|
||||
this->onFail.clear();
|
||||
}
|
||||
|
||||
ndn::nfd::FaceStatus
|
||||
Face::getFaceStatus() const
|
||||
{
|
||||
ndn::nfd::FaceStatus status;
|
||||
status.setFaceId(getId())
|
||||
.setRemoteUri(getRemoteUri().toString())
|
||||
.setLocalUri(getLocalUri().toString())
|
||||
.setFlags(getFaceFlags(*this));
|
||||
|
||||
this->getCounters().copyTo(status);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
} //namespace nfd
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
+249
-177
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -26,225 +26,297 @@
|
||||
#ifndef NFD_DAEMON_FACE_FACE_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/event-emitter.hpp"
|
||||
#include "core/face-uri.hpp"
|
||||
#include "face-common.hpp"
|
||||
#include "face-counters.hpp"
|
||||
|
||||
#include <ndn-cxx/management/nfd-face-status.hpp>
|
||||
#include "link-service.hpp"
|
||||
#include "transport.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \class FaceId
|
||||
* \brief identifies a face
|
||||
class Channel;
|
||||
|
||||
/** \brief indicates the state of a face
|
||||
*/
|
||||
typedef int FaceId;
|
||||
typedef TransportState FaceState;
|
||||
|
||||
/// indicates an invalid FaceId
|
||||
const FaceId INVALID_FACEID = -1;
|
||||
|
||||
/// identifies the InternalFace used in management
|
||||
const FaceId FACEID_INTERNAL_FACE = 1;
|
||||
/// identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId
|
||||
const FaceId FACEID_CONTENT_STORE = 254;
|
||||
/// identifies the NullFace that drops every packet
|
||||
const FaceId FACEID_NULL = 255;
|
||||
/// upper bound of reserved FaceIds
|
||||
const FaceId FACEID_RESERVED_MAX = 255;
|
||||
|
||||
|
||||
/// pratical limit of packet size in octets
|
||||
const size_t MAX_NDN_PACKET_SIZE = 8800;
|
||||
|
||||
|
||||
/** \brief represents a face
|
||||
/** \brief generalization of a network interface
|
||||
*
|
||||
* A face generalizes a network interface.
|
||||
* It provides best-effort network-layer packet delivery services
|
||||
* on a physical interface, an overlay tunnel, or a link to a local application.
|
||||
*
|
||||
* A face combines two parts: LinkService and Transport.
|
||||
* Transport is the lower part, which provides best-effort TLV block deliveries.
|
||||
* LinkService is the upper part, which translates between network-layer packets
|
||||
* and TLV blocks, and may provide additional services such as fragmentation and reassembly.
|
||||
*/
|
||||
class Face : noncopyable, public enable_shared_from_this<Face>
|
||||
class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Face-related error
|
||||
*/
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
|
||||
|
||||
Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal = false);
|
||||
LinkService*
|
||||
getLinkService() const;
|
||||
|
||||
virtual
|
||||
~Face();
|
||||
Transport*
|
||||
getTransport() const;
|
||||
|
||||
/// fires when an Interest is received
|
||||
EventEmitter<Interest> onReceiveInterest;
|
||||
|
||||
/// fires when a Data is received
|
||||
EventEmitter<Data> onReceiveData;
|
||||
|
||||
/// fires when an Interest is sent out
|
||||
EventEmitter<Interest> onSendInterest;
|
||||
|
||||
/// fires when a Data is sent out
|
||||
EventEmitter<Data> onSendData;
|
||||
|
||||
/// fires when face disconnects or fails to perform properly
|
||||
EventEmitter<std::string/*reason*/> onFail;
|
||||
|
||||
/// send an Interest
|
||||
virtual void
|
||||
sendInterest(const Interest& interest) = 0;
|
||||
|
||||
/// send a Data
|
||||
virtual void
|
||||
sendData(const Data& data) = 0;
|
||||
|
||||
/** \brief Close the face
|
||||
/** \brief Request that the face be closed
|
||||
*
|
||||
* This terminates all communication on the face and cause
|
||||
* onFail() method event to be invoked
|
||||
* This operation is effective only if face is in the UP or DOWN state; otherwise, it has no effect.
|
||||
* The face will change state to CLOSING, and then perform a cleanup procedure.
|
||||
* When the cleanup is complete, the state will be changed to CLOSED, which may happen
|
||||
* synchronously or asynchronously.
|
||||
*
|
||||
* \warning The face must not be deallocated until its state changes to CLOSED.
|
||||
*/
|
||||
virtual void
|
||||
close() = 0;
|
||||
void
|
||||
close();
|
||||
|
||||
public: // attributes
|
||||
public: // upper interface connected to forwarding
|
||||
/** \brief send Interest
|
||||
*/
|
||||
void
|
||||
sendInterest(const Interest& interest);
|
||||
|
||||
/** \brief send Data
|
||||
*/
|
||||
void
|
||||
sendData(const Data& data);
|
||||
|
||||
/** \brief send Nack
|
||||
*/
|
||||
void
|
||||
sendNack(const lp::Nack& nack);
|
||||
|
||||
/** \brief signals on Interest received
|
||||
*/
|
||||
signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
|
||||
|
||||
/** \brief signals on Data received
|
||||
*/
|
||||
signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
|
||||
|
||||
/** \brief signals on Nack received
|
||||
*/
|
||||
signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
|
||||
|
||||
/** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
|
||||
*/
|
||||
signal::Signal<LinkService, Interest>& onDroppedInterest;
|
||||
|
||||
public: // properties
|
||||
/** \return face ID
|
||||
*/
|
||||
FaceId
|
||||
getId() const;
|
||||
|
||||
/** \brief Set the description
|
||||
*
|
||||
* This is typically invoked by mgmt on set description command
|
||||
/** \brief sets face ID
|
||||
* \note Normally, this should only be invoked by FaceTable.
|
||||
*/
|
||||
virtual void
|
||||
setDescription(const std::string& description);
|
||||
void
|
||||
setId(FaceId id);
|
||||
|
||||
/// Get the description
|
||||
virtual const std::string&
|
||||
getDescription() const;
|
||||
|
||||
/** \brief Get whether face is connected to a local app
|
||||
/** \return a FaceUri representing local endpoint
|
||||
*/
|
||||
bool
|
||||
isLocal() const;
|
||||
|
||||
/** \brief Get whether packets sent this Face may reach multiple peers
|
||||
*
|
||||
* In this base class this property is always false.
|
||||
*/
|
||||
virtual bool
|
||||
isMultiAccess() const;
|
||||
|
||||
/** \brief Get whether underlying communication is up
|
||||
*
|
||||
* In this base class this property is always true.
|
||||
*/
|
||||
virtual bool
|
||||
isUp() const;
|
||||
|
||||
/** \brief Get whether face is created on demand or explicitly via FaceManagement protocol
|
||||
*/
|
||||
bool
|
||||
isOnDemand() const;
|
||||
|
||||
const FaceCounters&
|
||||
getCounters() const;
|
||||
|
||||
/** \return a FaceUri that represents the remote endpoint
|
||||
*/
|
||||
const FaceUri&
|
||||
getRemoteUri() const;
|
||||
|
||||
/** \return a FaceUri that represents the local endpoint (NFD side)
|
||||
*/
|
||||
const FaceUri&
|
||||
FaceUri
|
||||
getLocalUri() const;
|
||||
|
||||
/** \return FaceStatus data structure filled with the current Face status
|
||||
/** \return a FaceUri representing remote endpoint
|
||||
*/
|
||||
virtual ndn::nfd::FaceStatus
|
||||
getFaceStatus() const;
|
||||
FaceUri
|
||||
getRemoteUri() const;
|
||||
|
||||
protected:
|
||||
// this is a non-virtual method
|
||||
bool
|
||||
decodeAndDispatchInput(const Block& element);
|
||||
/** \return whether face is local or non-local for scope control purpose
|
||||
*/
|
||||
ndn::nfd::FaceScope
|
||||
getScope() const;
|
||||
|
||||
/** \return face persistency setting
|
||||
*/
|
||||
ndn::nfd::FacePersistency
|
||||
getPersistency() const;
|
||||
|
||||
/** \brief changes face persistency setting
|
||||
*/
|
||||
void
|
||||
setPersistency(ndn::nfd::FacePersistency persistency);
|
||||
|
||||
/** \return whether face is point-to-point or multi-access
|
||||
*/
|
||||
ndn::nfd::LinkType
|
||||
getLinkType() const;
|
||||
|
||||
/** \brief Returns face effective MTU
|
||||
*
|
||||
* This function is a wrapper. The effective MTU of a face is determined by the link service.
|
||||
*/
|
||||
ssize_t
|
||||
getMtu() const;
|
||||
|
||||
/** \return face state
|
||||
*/
|
||||
FaceState
|
||||
getState() const;
|
||||
|
||||
/** \brief signals after face state changed
|
||||
*/
|
||||
signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
|
||||
|
||||
/** \return expiration time of the face
|
||||
* \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
|
||||
*/
|
||||
time::steady_clock::TimePoint
|
||||
getExpirationTime() const;
|
||||
|
||||
const FaceCounters&
|
||||
getCounters() const
|
||||
{
|
||||
return m_counters;
|
||||
}
|
||||
|
||||
FaceCounters&
|
||||
getMutableCounters();
|
||||
getCounters()
|
||||
{
|
||||
return m_counters;
|
||||
}
|
||||
|
||||
void
|
||||
setOnDemand(bool isOnDemand);
|
||||
/**
|
||||
* \brief Get channel on which face was created (unicast) or the associated channel (multicast)
|
||||
*/
|
||||
weak_ptr<Channel>
|
||||
getChannel() const
|
||||
{
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/** \brief fail the face and raise onFail event if it's UP; otherwise do nothing
|
||||
/**
|
||||
* \brief Set channel on which face was created (unicast) or the associated channel (multicast)
|
||||
*/
|
||||
void
|
||||
fail(const std::string& reason);
|
||||
|
||||
private:
|
||||
void
|
||||
setId(FaceId faceId);
|
||||
setChannel(weak_ptr<Channel> channel)
|
||||
{
|
||||
m_channel = std::move(channel);
|
||||
}
|
||||
|
||||
private:
|
||||
FaceId m_id;
|
||||
std::string m_description;
|
||||
bool m_isLocal; // for scoping purposes
|
||||
unique_ptr<LinkService> m_service;
|
||||
unique_ptr<Transport> m_transport;
|
||||
FaceCounters m_counters;
|
||||
FaceUri m_remoteUri;
|
||||
FaceUri m_localUri;
|
||||
bool m_isOnDemand;
|
||||
bool m_isFailed;
|
||||
|
||||
// allow setting FaceId
|
||||
friend class FaceTable;
|
||||
weak_ptr<Channel> m_channel;
|
||||
};
|
||||
|
||||
|
||||
inline bool
|
||||
Face::isLocal() const
|
||||
inline LinkService*
|
||||
Face::getLinkService() const
|
||||
{
|
||||
return m_isLocal;
|
||||
return m_service.get();
|
||||
}
|
||||
|
||||
inline const FaceCounters&
|
||||
Face::getCounters() const
|
||||
inline Transport*
|
||||
Face::getTransport() const
|
||||
{
|
||||
return m_counters;
|
||||
}
|
||||
|
||||
inline FaceCounters&
|
||||
Face::getMutableCounters()
|
||||
{
|
||||
return m_counters;
|
||||
}
|
||||
|
||||
inline const FaceUri&
|
||||
Face::getRemoteUri() const
|
||||
{
|
||||
return m_remoteUri;
|
||||
}
|
||||
|
||||
inline const FaceUri&
|
||||
Face::getLocalUri() const
|
||||
{
|
||||
return m_localUri;
|
||||
return m_transport.get();
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::setOnDemand(bool isOnDemand)
|
||||
Face::close()
|
||||
{
|
||||
m_isOnDemand = isOnDemand;
|
||||
m_transport->close();
|
||||
}
|
||||
|
||||
inline bool
|
||||
Face::isOnDemand() const
|
||||
inline void
|
||||
Face::sendInterest(const Interest& interest)
|
||||
{
|
||||
return m_isOnDemand;
|
||||
m_service->sendInterest(interest);
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::sendData(const Data& data)
|
||||
{
|
||||
m_service->sendData(data);
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::sendNack(const lp::Nack& nack)
|
||||
{
|
||||
m_service->sendNack(nack);
|
||||
}
|
||||
|
||||
inline FaceId
|
||||
Face::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::setId(FaceId id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
inline FaceUri
|
||||
Face::getLocalUri() const
|
||||
{
|
||||
return m_transport->getLocalUri();
|
||||
}
|
||||
|
||||
inline FaceUri
|
||||
Face::getRemoteUri() const
|
||||
{
|
||||
return m_transport->getRemoteUri();
|
||||
}
|
||||
|
||||
inline ndn::nfd::FaceScope
|
||||
Face::getScope() const
|
||||
{
|
||||
return m_transport->getScope();
|
||||
}
|
||||
|
||||
inline ndn::nfd::FacePersistency
|
||||
Face::getPersistency() const
|
||||
{
|
||||
return m_transport->getPersistency();
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::setPersistency(ndn::nfd::FacePersistency persistency)
|
||||
{
|
||||
return m_transport->setPersistency(persistency);
|
||||
}
|
||||
|
||||
inline ndn::nfd::LinkType
|
||||
Face::getLinkType() const
|
||||
{
|
||||
return m_transport->getLinkType();
|
||||
}
|
||||
|
||||
inline ssize_t
|
||||
Face::getMtu() const
|
||||
{
|
||||
return m_service->getEffectiveMtu();
|
||||
}
|
||||
|
||||
inline FaceState
|
||||
Face::getState() const
|
||||
{
|
||||
return m_transport->getState();
|
||||
}
|
||||
|
||||
inline time::steady_clock::TimePoint
|
||||
Face::getExpirationTime() const
|
||||
{
|
||||
return m_transport->getExpirationTime();
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
|
||||
|
||||
} // namespace face
|
||||
|
||||
using face::Face;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_HPP
|
||||
@@ -0,0 +1,514 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "generic-link-service.hpp"
|
||||
|
||||
#include <ndn-cxx/lp/pit-token.hpp>
|
||||
#include <ndn-cxx/lp/tags.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(GenericLinkService);
|
||||
|
||||
constexpr size_t CONGESTION_MARK_SIZE = tlv::sizeOfVarNumber(lp::tlv::CongestionMark) + // type
|
||||
tlv::sizeOfVarNumber(sizeof(uint64_t)) + // length
|
||||
tlv::sizeOfNonNegativeInteger(UINT64_MAX); // value
|
||||
|
||||
GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
|
||||
: m_options(options)
|
||||
, m_fragmenter(m_options.fragmenterOptions, this)
|
||||
, m_reassembler(m_options.reassemblerOptions, this)
|
||||
, m_reliability(m_options.reliabilityOptions, this)
|
||||
, m_lastSeqNo(-2)
|
||||
, m_nextMarkTime(time::steady_clock::time_point::max())
|
||||
, m_nMarkedSinceInMarkingState(0)
|
||||
{
|
||||
m_reassembler.beforeTimeout.connect([this] (auto&&...) { ++nReassemblyTimeouts; });
|
||||
m_reliability.onDroppedInterest.connect([this] (const auto& i) { notifyDroppedInterest(i); });
|
||||
nReassembling.observe(&m_reassembler);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::setOptions(const GenericLinkService::Options& options)
|
||||
{
|
||||
m_options = options;
|
||||
m_fragmenter.setOptions(m_options.fragmenterOptions);
|
||||
m_reassembler.setOptions(m_options.reassemblerOptions);
|
||||
m_reliability.setOptions(m_options.reliabilityOptions);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
GenericLinkService::getEffectiveMtu() const
|
||||
{
|
||||
// Since MTU_UNLIMITED is negative, it will implicitly override any finite override MTU
|
||||
return std::min(m_options.overrideMtu, getTransport()->getMtu());
|
||||
}
|
||||
|
||||
bool
|
||||
GenericLinkService::canOverrideMtuTo(ssize_t mtu) const
|
||||
{
|
||||
// Not allowed to override unlimited transport MTU
|
||||
if (getTransport()->getMtu() == MTU_UNLIMITED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Override MTU must be at least MIN_MTU (also implicitly forbids MTU_UNLIMITED and MTU_INVALID)
|
||||
return mtu >= MIN_MTU;
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::requestIdlePacket()
|
||||
{
|
||||
// No need to request Acks to attach to this packet from LpReliability, as they are already
|
||||
// attached in sendLpPacket
|
||||
NFD_LOG_FACE_TRACE("IDLE packet requested");
|
||||
this->sendLpPacket({});
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::sendLpPacket(lp::Packet&& pkt)
|
||||
{
|
||||
const ssize_t mtu = getEffectiveMtu();
|
||||
|
||||
if (m_options.reliabilityOptions.isEnabled) {
|
||||
m_reliability.piggyback(pkt, mtu);
|
||||
}
|
||||
|
||||
if (m_options.allowCongestionMarking) {
|
||||
checkCongestionLevel(pkt);
|
||||
}
|
||||
|
||||
auto block = pkt.wireEncode();
|
||||
if (mtu != MTU_UNLIMITED && block.size() > static_cast<size_t>(mtu)) {
|
||||
++nOutOverMtu;
|
||||
NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
|
||||
return;
|
||||
}
|
||||
this->sendPacket(block);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::doSendInterest(const Interest& interest)
|
||||
{
|
||||
lp::Packet lpPacket(interest.wireEncode());
|
||||
|
||||
encodeLpFields(interest, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket), true);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::doSendData(const Data& data)
|
||||
{
|
||||
lp::Packet lpPacket(data.wireEncode());
|
||||
|
||||
encodeLpFields(data, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket), false);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::doSendNack(const lp::Nack& nack)
|
||||
{
|
||||
lp::Packet lpPacket(nack.getInterest().wireEncode());
|
||||
lpPacket.add<lp::NackField>(nack.getHeader());
|
||||
|
||||
encodeLpFields(nack, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket), false);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
|
||||
{
|
||||
std::for_each(pkts.begin(), pkts.end(), [this] (lp::Packet& pkt) {
|
||||
pkt.set<lp::SequenceField>(++m_lastSeqNo);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket)
|
||||
{
|
||||
if (m_options.allowLocalFields) {
|
||||
auto incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
|
||||
if (incomingFaceIdTag != nullptr) {
|
||||
lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
|
||||
}
|
||||
}
|
||||
|
||||
auto congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
|
||||
if (congestionMarkTag != nullptr) {
|
||||
lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
|
||||
}
|
||||
|
||||
if (m_options.allowSelfLearning) {
|
||||
auto nonDiscoveryTag = netPkt.getTag<lp::NonDiscoveryTag>();
|
||||
if (nonDiscoveryTag != nullptr) {
|
||||
lpPacket.add<lp::NonDiscoveryField>(*nonDiscoveryTag);
|
||||
}
|
||||
|
||||
auto prefixAnnouncementTag = netPkt.getTag<lp::PrefixAnnouncementTag>();
|
||||
if (prefixAnnouncementTag != nullptr) {
|
||||
lpPacket.add<lp::PrefixAnnouncementField>(*prefixAnnouncementTag);
|
||||
}
|
||||
}
|
||||
|
||||
auto pitToken = netPkt.getTag<lp::PitToken>();
|
||||
if (pitToken != nullptr) {
|
||||
lpPacket.add<lp::PitTokenField>(*pitToken);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::sendNetPacket(lp::Packet&& pkt, bool isInterest)
|
||||
{
|
||||
std::vector<lp::Packet> frags;
|
||||
ssize_t mtu = getEffectiveMtu();
|
||||
|
||||
// Make space for feature fields in fragments
|
||||
if (m_options.reliabilityOptions.isEnabled && mtu != MTU_UNLIMITED) {
|
||||
mtu -= LpReliability::RESERVED_HEADER_SPACE;
|
||||
}
|
||||
|
||||
if (m_options.allowCongestionMarking && mtu != MTU_UNLIMITED) {
|
||||
mtu -= CONGESTION_MARK_SIZE;
|
||||
}
|
||||
|
||||
// An MTU of 0 is allowed but will cause all packets to be dropped before transmission
|
||||
BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu >= 0);
|
||||
|
||||
if (m_options.allowFragmentation && mtu != MTU_UNLIMITED) {
|
||||
bool isOk = false;
|
||||
std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
|
||||
if (!isOk) {
|
||||
// fragmentation failed (warning is logged by LpFragmenter)
|
||||
++nFragmentationErrors;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_options.reliabilityOptions.isEnabled) {
|
||||
frags.push_back(pkt);
|
||||
}
|
||||
else {
|
||||
frags.push_back(std::move(pkt));
|
||||
}
|
||||
}
|
||||
|
||||
if (frags.size() == 1) {
|
||||
// even if indexed fragmentation is enabled, the fragmenter should not
|
||||
// fragment the packet if it can fit in MTU
|
||||
BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
|
||||
BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
|
||||
}
|
||||
|
||||
// Only assign sequences to fragments if reliability enabled or if packet contains >1 fragment
|
||||
if (m_options.reliabilityOptions.isEnabled || frags.size() > 1) {
|
||||
// Assign sequences to all fragments
|
||||
this->assignSequences(frags);
|
||||
}
|
||||
|
||||
if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) {
|
||||
m_reliability.handleOutgoing(frags, std::move(pkt), isInterest);
|
||||
}
|
||||
|
||||
for (lp::Packet& frag : frags) {
|
||||
this->sendLpPacket(std::move(frag));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::checkCongestionLevel(lp::Packet& pkt)
|
||||
{
|
||||
ssize_t sendQueueLength = getTransport()->getSendQueueLength();
|
||||
// The transport must support retrieving the current send queue length
|
||||
if (sendQueueLength < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sendQueueLength > 0) {
|
||||
NFD_LOG_FACE_TRACE("txqlen=" << sendQueueLength << " threshold=" <<
|
||||
m_options.defaultCongestionThreshold << " capacity=" <<
|
||||
getTransport()->getSendQueueCapacity());
|
||||
}
|
||||
|
||||
// sendQueue is above target
|
||||
if (static_cast<size_t>(sendQueueLength) > m_options.defaultCongestionThreshold) {
|
||||
const auto now = time::steady_clock::now();
|
||||
|
||||
if (m_nextMarkTime == time::steady_clock::time_point::max()) {
|
||||
m_nextMarkTime = now + m_options.baseCongestionMarkingInterval;
|
||||
}
|
||||
// Mark packet if sendQueue stays above target for one interval
|
||||
else if (now >= m_nextMarkTime) {
|
||||
pkt.set<lp::CongestionMarkField>(1);
|
||||
++nCongestionMarked;
|
||||
NFD_LOG_FACE_DEBUG("LpPacket was marked as congested");
|
||||
|
||||
++m_nMarkedSinceInMarkingState;
|
||||
// Decrease the marking interval by the inverse of the square root of the number of packets
|
||||
// marked in this incident of congestion
|
||||
time::nanoseconds interval(static_cast<time::nanoseconds::rep>(
|
||||
m_options.baseCongestionMarkingInterval.count() /
|
||||
std::sqrt(m_nMarkedSinceInMarkingState + 1)));
|
||||
m_nextMarkTime += interval;
|
||||
}
|
||||
}
|
||||
else if (m_nextMarkTime != time::steady_clock::time_point::max()) {
|
||||
// Congestion incident has ended, so reset
|
||||
NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
|
||||
m_nextMarkTime = time::steady_clock::time_point::max();
|
||||
m_nMarkedSinceInMarkingState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::doReceivePacket(const Block& packet, const EndpointId& endpoint)
|
||||
{
|
||||
try {
|
||||
lp::Packet pkt(packet);
|
||||
|
||||
if (m_options.reliabilityOptions.isEnabled) {
|
||||
if (!m_reliability.processIncomingPacket(pkt)) {
|
||||
NFD_LOG_FACE_TRACE("received duplicate fragment: DROP");
|
||||
++nDuplicateSequence;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pkt.has<lp::FragmentField>()) {
|
||||
NFD_LOG_FACE_TRACE("received IDLE packet: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) &&
|
||||
!m_options.allowReassembly) {
|
||||
NFD_LOG_FACE_WARN("received fragment, but reassembly disabled: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isReassembled = false;
|
||||
Block netPkt;
|
||||
lp::Packet firstPkt;
|
||||
std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(endpoint, pkt);
|
||||
if (isReassembled) {
|
||||
this->decodeNetPacket(netPkt, firstPkt, endpoint);
|
||||
}
|
||||
}
|
||||
catch (const tlv::Error& e) {
|
||||
++nInLpInvalid;
|
||||
NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
try {
|
||||
switch (netPkt.type()) {
|
||||
case tlv::Interest:
|
||||
if (firstPkt.has<lp::NackField>()) {
|
||||
this->decodeNack(netPkt, firstPkt, endpointId);
|
||||
}
|
||||
else {
|
||||
this->decodeInterest(netPkt, firstPkt, endpointId);
|
||||
}
|
||||
break;
|
||||
case tlv::Data:
|
||||
this->decodeData(netPkt, firstPkt, endpointId);
|
||||
break;
|
||||
default:
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (const tlv::Error& e) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Interest);
|
||||
BOOST_ASSERT(!firstPkt.has<lp::NackField>());
|
||||
|
||||
// forwarding expects Interest to be created with make_shared
|
||||
auto interest = make_shared<Interest>(netPkt);
|
||||
|
||||
if (firstPkt.has<lp::NextHopFaceIdField>()) {
|
||||
if (m_options.allowLocalFields) {
|
||||
interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
|
||||
}
|
||||
else {
|
||||
NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CachePolicyField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::IncomingFaceIdField>()) {
|
||||
NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CongestionMarkField>()) {
|
||||
interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::NonDiscoveryField>()) {
|
||||
if (m_options.allowSelfLearning) {
|
||||
interest->setTag(make_shared<lp::NonDiscoveryTag>(firstPkt.get<lp::NonDiscoveryField>()));
|
||||
}
|
||||
else {
|
||||
NFD_LOG_FACE_WARN("received NonDiscovery, but self-learning disabled: IGNORE");
|
||||
}
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received PrefixAnnouncement with Interest: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::PitTokenField>()) {
|
||||
interest->setTag(make_shared<lp::PitToken>(firstPkt.get<lp::PitTokenField>()));
|
||||
}
|
||||
|
||||
this->receiveInterest(*interest, endpointId);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Data);
|
||||
|
||||
// forwarding expects Data to be created with make_shared
|
||||
auto data = make_shared<Data>(netPkt);
|
||||
|
||||
if (firstPkt.has<lp::NackField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received Nack with Data: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::NextHopFaceIdField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CachePolicyField>()) {
|
||||
// CachePolicy is unprivileged and does not require allowLocalFields option.
|
||||
// In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
|
||||
// so it's unnecessary to check here.
|
||||
data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::IncomingFaceIdField>()) {
|
||||
NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CongestionMarkField>()) {
|
||||
data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::NonDiscoveryField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received NonDiscovery with Data: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
|
||||
if (m_options.allowSelfLearning) {
|
||||
data->setTag(make_shared<lp::PrefixAnnouncementTag>(firstPkt.get<lp::PrefixAnnouncementField>()));
|
||||
}
|
||||
else {
|
||||
NFD_LOG_FACE_WARN("received PrefixAnnouncement, but self-learning disabled: IGNORE");
|
||||
}
|
||||
}
|
||||
|
||||
this->receiveData(*data, endpointId);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Interest);
|
||||
BOOST_ASSERT(firstPkt.has<lp::NackField>());
|
||||
|
||||
lp::Nack nack((Interest(netPkt)));
|
||||
nack.setHeader(firstPkt.get<lp::NackField>());
|
||||
|
||||
if (firstPkt.has<lp::NextHopFaceIdField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CachePolicyField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::IncomingFaceIdField>()) {
|
||||
NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CongestionMarkField>()) {
|
||||
nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::NonDiscoveryField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
|
||||
++nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
this->receiveNack(nack, endpointId);
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,331 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
*
|
||||
* NFD is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
|
||||
#define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
|
||||
|
||||
#include "link-service.hpp"
|
||||
#include "lp-fragmenter.hpp"
|
||||
#include "lp-reassembler.hpp"
|
||||
#include "lp-reliability.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \brief counters provided by GenericLinkService
|
||||
* \note The type name 'GenericLinkServiceCounters' is implementation detail.
|
||||
* Use 'GenericLinkService::Counters' in public API.
|
||||
*/
|
||||
class GenericLinkServiceCounters : public virtual LinkService::Counters
|
||||
{
|
||||
public:
|
||||
/** \brief count of failed fragmentations
|
||||
*/
|
||||
PacketCounter nFragmentationErrors;
|
||||
|
||||
/** \brief count of outgoing LpPackets dropped due to exceeding MTU limit
|
||||
*
|
||||
* If this counter is non-zero, the operator should enable fragmentation.
|
||||
*/
|
||||
PacketCounter nOutOverMtu;
|
||||
|
||||
/** \brief count of invalid LpPackets dropped before reassembly
|
||||
*/
|
||||
PacketCounter nInLpInvalid;
|
||||
|
||||
/** \brief count of network-layer packets currently being reassembled
|
||||
*/
|
||||
SizeCounter<LpReassembler> nReassembling;
|
||||
|
||||
/** \brief count of dropped partial network-layer packets due to reassembly timeout
|
||||
*/
|
||||
PacketCounter nReassemblyTimeouts;
|
||||
|
||||
/** \brief count of invalid reassembled network-layer packets dropped
|
||||
*/
|
||||
PacketCounter nInNetInvalid;
|
||||
|
||||
/** \brief count of network-layer packets that did not require retransmission of a fragment
|
||||
*/
|
||||
PacketCounter nAcknowledged;
|
||||
|
||||
/** \brief count of network-layer packets that had at least one fragment retransmitted, but were
|
||||
* eventually received in full
|
||||
*/
|
||||
PacketCounter nRetransmitted;
|
||||
|
||||
/** \brief count of network-layer packets dropped because a fragment reached the maximum number
|
||||
* of retransmissions
|
||||
*/
|
||||
PacketCounter nRetxExhausted;
|
||||
|
||||
/** \brief count of LpPackets dropped due to duplicate Sequence numbers
|
||||
*/
|
||||
PacketCounter nDuplicateSequence;
|
||||
|
||||
/** \brief count of outgoing LpPackets that were marked with congestion marks
|
||||
*/
|
||||
PacketCounter nCongestionMarked;
|
||||
};
|
||||
|
||||
/** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
*/
|
||||
class GenericLinkService NFD_FINAL_UNLESS_WITH_TESTS : public LinkService
|
||||
, protected virtual GenericLinkServiceCounters
|
||||
{
|
||||
public:
|
||||
/** \brief Options that control the behavior of GenericLinkService
|
||||
*/
|
||||
class Options
|
||||
{
|
||||
public:
|
||||
Options() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
/** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
|
||||
*/
|
||||
bool allowLocalFields = false;
|
||||
|
||||
/** \brief enables fragmentation
|
||||
*/
|
||||
bool allowFragmentation = false;
|
||||
|
||||
/** \brief options for fragmentation
|
||||
*/
|
||||
LpFragmenter::Options fragmenterOptions;
|
||||
|
||||
/** \brief enables reassembly
|
||||
*/
|
||||
bool allowReassembly = false;
|
||||
|
||||
/** \brief options for reassembly
|
||||
*/
|
||||
LpReassembler::Options reassemblerOptions;
|
||||
|
||||
/** \brief options for reliability
|
||||
*/
|
||||
LpReliability::Options reliabilityOptions;
|
||||
|
||||
/** \brief enables send queue congestion detection and marking
|
||||
*/
|
||||
bool allowCongestionMarking = false;
|
||||
|
||||
/** \brief starting value for congestion marking interval
|
||||
*
|
||||
* Packets are marked if the queue size stays above THRESHOLD for at least one INTERVAL.
|
||||
*
|
||||
* The default value (100 ms) is taken from RFC 8289 (CoDel).
|
||||
*/
|
||||
time::nanoseconds baseCongestionMarkingInterval = 100_ms;
|
||||
|
||||
/** \brief default congestion threshold in bytes
|
||||
*
|
||||
* Packets are marked if the queue size stays above THRESHOLD for at least one INTERVAL.
|
||||
*
|
||||
* The default value (64 KiB) works well for a queue capacity of 200 KiB.
|
||||
*/
|
||||
size_t defaultCongestionThreshold = 65536;
|
||||
|
||||
/** \brief enables self-learning forwarding support
|
||||
*/
|
||||
bool allowSelfLearning = true;
|
||||
|
||||
/** \brief overrides MTU provided by Transport
|
||||
*
|
||||
* This MTU value will be used instead of the MTU provided by the transport if it is less than
|
||||
* the transport MTU. However, it will not be utilized when the transport MTU is unlimited.
|
||||
*
|
||||
* Acceptable values for the override MTU are values >= MIN_MTU, which can be validated before
|
||||
* being set with canOverrideMtuTo().
|
||||
*/
|
||||
ssize_t overrideMtu = std::numeric_limits<ssize_t>::max();
|
||||
};
|
||||
|
||||
/** \brief counters provided by GenericLinkService
|
||||
*/
|
||||
using Counters = GenericLinkServiceCounters;
|
||||
|
||||
explicit
|
||||
GenericLinkService(const Options& options = {});
|
||||
|
||||
/** \brief get Options used by GenericLinkService
|
||||
*/
|
||||
const Options&
|
||||
getOptions() const;
|
||||
|
||||
/** \brief sets Options used by GenericLinkService
|
||||
*/
|
||||
void
|
||||
setOptions(const Options& options);
|
||||
|
||||
const Counters&
|
||||
getCounters() const NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
ssize_t
|
||||
getEffectiveMtu() const NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \brief Whether MTU can be overridden to the specified value
|
||||
*
|
||||
* If the transport MTU is unlimited, then this will always return false.
|
||||
*/
|
||||
bool
|
||||
canOverrideMtuTo(ssize_t mtu) const;
|
||||
|
||||
NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path
|
||||
/** \brief request an IDLE packet to transmit pending service fields
|
||||
*/
|
||||
void
|
||||
requestIdlePacket();
|
||||
|
||||
/** \brief send an LpPacket
|
||||
*/
|
||||
void
|
||||
sendLpPacket(lp::Packet&& pkt);
|
||||
|
||||
void
|
||||
doSendInterest(const Interest& interest) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
void
|
||||
doSendData(const Data& data) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
void
|
||||
doSendNack(const ndn::lp::Nack& nack) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \brief assign consecutive sequence numbers to LpPackets
|
||||
*/
|
||||
void
|
||||
assignSequences(std::vector<lp::Packet>& pkts);
|
||||
|
||||
private: // send path
|
||||
/** \brief encode link protocol fields from tags onto an outgoing LpPacket
|
||||
* \param netPkt network-layer packet to extract tags from
|
||||
* \param lpPacket LpPacket to add link protocol fields to
|
||||
*/
|
||||
void
|
||||
encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket);
|
||||
|
||||
/** \brief send a complete network layer packet
|
||||
* \param pkt LpPacket containing a complete network layer packet
|
||||
* \param isInterest whether the network layer packet is an Interest
|
||||
*/
|
||||
void
|
||||
sendNetPacket(lp::Packet&& pkt, bool isInterest);
|
||||
|
||||
/** \brief if the send queue is found to be congested, add a congestion mark to the packet
|
||||
* according to CoDel
|
||||
* \sa https://tools.ietf.org/html/rfc8289
|
||||
*/
|
||||
void
|
||||
checkCongestionLevel(lp::Packet& pkt);
|
||||
|
||||
private: // receive path
|
||||
void
|
||||
doReceivePacket(const Block& packet, const EndpointId& endpoint) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \brief decode incoming network-layer packet
|
||||
* \param netPkt reassembled network-layer packet
|
||||
* \param firstPkt LpPacket of first fragment
|
||||
* \param endpointId endpoint of peer who sent the packet
|
||||
*
|
||||
* If decoding is successful, a receive signal is emitted;
|
||||
* otherwise, a warning is logged.
|
||||
*/
|
||||
void
|
||||
decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
|
||||
|
||||
/** \brief decode incoming Interest
|
||||
* \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
|
||||
* \param firstPkt LpPacket of first fragment; must not have Nack field
|
||||
* \param endpointId endpoint of peer who sent the Interest
|
||||
*
|
||||
* If decoding is successful, receiveInterest signal is emitted;
|
||||
* otherwise, a warning is logged.
|
||||
*
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
|
||||
|
||||
/** \brief decode incoming Interest
|
||||
* \param netPkt reassembled network-layer packet; TLV-TYPE must be Data
|
||||
* \param firstPkt LpPacket of first fragment
|
||||
* \param endpointId endpoint of peer who sent the Data
|
||||
*
|
||||
* If decoding is successful, receiveData signal is emitted;
|
||||
* otherwise, a warning is logged.
|
||||
*
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
|
||||
|
||||
/** \brief decode incoming Interest
|
||||
* \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
|
||||
* \param firstPkt LpPacket of first fragment; must have Nack field
|
||||
* \param endpointId endpoint of peer who sent the Nack
|
||||
*
|
||||
* If decoding is successful, receiveNack signal is emitted;
|
||||
* otherwise, a warning is logged.
|
||||
*
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
|
||||
|
||||
NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE:
|
||||
Options m_options;
|
||||
LpFragmenter m_fragmenter;
|
||||
LpReassembler m_reassembler;
|
||||
LpReliability m_reliability;
|
||||
lp::Sequence m_lastSeqNo;
|
||||
|
||||
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
/// Time to mark next packet due to send queue congestion
|
||||
time::steady_clock::TimePoint m_nextMarkTime;
|
||||
/// number of marked packets in the current incident of congestion
|
||||
size_t m_nMarkedSinceInMarkingState;
|
||||
|
||||
friend class LpReliability;
|
||||
};
|
||||
|
||||
inline const GenericLinkService::Options&
|
||||
GenericLinkService::getOptions() const
|
||||
{
|
||||
return m_options;
|
||||
}
|
||||
|
||||
inline const GenericLinkService::Counters&
|
||||
GenericLinkService::getCounters() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
|
||||
Loaded 100 of 769 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user