Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bb9a2772a | ||
|
|
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 |
No files matched your search
+29
-9
@@ -1,9 +1,29 @@
|
||||
.DS*
|
||||
.waf-1*
|
||||
.waf3-*
|
||||
.lock*
|
||||
*.pyc
|
||||
*.pyo
|
||||
build/
|
||||
VERSION
|
||||
unit-tests.conf
|
||||
# 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
|
||||
@@ -1,10 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
source .jenkins.d/util.sh
|
||||
|
||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
export CACHE_DIR=${CACHE_DIR:-/tmp}
|
||||
export WAF_JOBS=${WAF_JOBS:-1}
|
||||
[[ $JOB_NAME == *"code-coverage" ]] && export DISABLE_ASAN=yes
|
||||
|
||||
for file in "$DIR"/.jenkins.d/*; do
|
||||
nanos() {
|
||||
# Cannot use date(1) because macOS does not support %N format specifier
|
||||
python3 -c 'import time; print(int(time.time() * 1e9))'
|
||||
}
|
||||
|
||||
for file in .jenkins.d/*; do
|
||||
[[ -f $file && -x $file ]] || continue
|
||||
echo "Run: $file"
|
||||
|
||||
if [[ -n $TRAVIS ]]; then
|
||||
label=$(basename "$file" | sed -E 's/[[:digit:]]+-(.*)\..*/\1/')
|
||||
echo -ne "travis_fold:start:${label}\r"
|
||||
echo -ne "travis_time:start:${label}\r"
|
||||
start=$(nanos)
|
||||
fi
|
||||
|
||||
echo "\$ $file"
|
||||
"$file"
|
||||
|
||||
if [[ -n $TRAVIS ]]; then
|
||||
finish=$(nanos)
|
||||
echo -ne "travis_time:end:${label}:start=${start},finish=${finish},duration=$((finish-start)),event=${label}\r"
|
||||
echo -ne "travis_fold:end:${label}\r"
|
||||
fi
|
||||
done
|
||||
+35
-15
@@ -1,21 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
source "$JDIR"/util.sh
|
||||
|
||||
set -x
|
||||
set -ex
|
||||
|
||||
if has OSX $NODE_LABELS; then
|
||||
brew update
|
||||
brew upgrade
|
||||
brew install boost pkg-config cryptopp openssl
|
||||
brew cleanup
|
||||
fi
|
||||
FORMULAE=(boost openssl pkg-config)
|
||||
if has OSX-10.13 $NODE_LABELS || has OSX-10.14 $NODE_LABELS; then
|
||||
FORMULAE+=(python)
|
||||
fi
|
||||
|
||||
if has Ubuntu $NODE_LABELS; then
|
||||
if [[ -n $TRAVIS ]]; then
|
||||
# Travis images come with a large number of pre-installed
|
||||
# brew 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
|
||||
|
||||
elif has Ubuntu $NODE_LABELS; then
|
||||
sudo apt-get -qq update
|
||||
sudo apt-get -qq install build-essential pkg-config libboost-all-dev \
|
||||
libcrypto++-dev libsqlite3-dev libssl-dev \
|
||||
libpcap-dev
|
||||
sudo apt-get -qy install build-essential pkg-config python3-minimal \
|
||||
libboost-all-dev libssl-dev libsqlite3-dev \
|
||||
libpcap-dev libsystemd-dev
|
||||
|
||||
if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
sudo apt-get -qy install gcovr lcov
|
||||
fi
|
||||
|
||||
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
|
||||
+40
-28
@@ -1,43 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -ex
|
||||
|
||||
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
source "$JDIR"/util.sh
|
||||
pushd "$CACHE_DIR" >/dev/null
|
||||
|
||||
set -x
|
||||
|
||||
pushd "${CACHE_DIR:-/tmp}" >/dev/null
|
||||
|
||||
INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
|
||||
|
||||
sudo rm -Rf ndn-cxx-latest
|
||||
|
||||
git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
|
||||
|
||||
LATEST_VERSION=$((cd ndn-cxx-latest && git 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
|
||||
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
|
||||
|
||||
sudo rm -Rf /usr/local/include/ndn-cxx
|
||||
sudo rm -f /usr/local/lib/libndn-cxx*
|
||||
sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
|
||||
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
|
||||
|
||||
./waf -j1 --color=yes configure --enable-shared --disable-static --without-osx-keychain
|
||||
./waf -j1 --color=yes build
|
||||
sudo ./waf -j1 --color=yes install
|
||||
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
|
||||
elif has FreeBSD $NODE_LABELS; then
|
||||
sudo ldconfig -a
|
||||
fi
|
||||
+32
-35
@@ -1,44 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -ex
|
||||
|
||||
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
source "$JDIR"/util.sh
|
||||
|
||||
set -x
|
||||
|
||||
git submodule init
|
||||
git submodule sync
|
||||
git submodule update
|
||||
git submodule update --init
|
||||
|
||||
# Cleanup
|
||||
sudo ./waf -j1 --color=yes distclean
|
||||
|
||||
if [[ $JOB_NAME != *"code-coverage" && $JOB_NAME != *"limited-build" ]]; then
|
||||
# Configure/build in optimized mode with tests
|
||||
./waf -j1 --color=yes configure --with-tests
|
||||
./waf -j1 --color=yes build
|
||||
|
||||
# Cleanup
|
||||
sudo ./waf -j1 --color=yes distclean
|
||||
|
||||
# Configure/build in optimized mode without tests
|
||||
./waf -j1 --color=yes configure
|
||||
./waf -j1 --color=yes build
|
||||
|
||||
# Cleanup
|
||||
sudo ./waf -j1 --color=yes distclean
|
||||
fi
|
||||
|
||||
# Configure/build in debug mode with tests and without precompiled headers
|
||||
if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
COVERAGE="--with-coverage"
|
||||
elif ! has OSX-10.9 $NODE_LABELS && ! has OSX-10.11 $NODE_LABELS; then
|
||||
if [[ -z $DISABLE_ASAN ]]; then
|
||||
ASAN="--with-sanitizer=address"
|
||||
fi
|
||||
./waf -j1 --color=yes configure --debug --with-tests --without-pch $COVERAGE $ASAN
|
||||
./waf -j1 --color=yes build
|
||||
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
|
||||
|
||||
# (tests will be run against debug version)
|
||||
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 ./waf -j1 --color=yes install
|
||||
sudo_preserve_env PATH -- ./waf --color=yes install
|
||||
+24
-33
@@ -1,13 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
source "$JDIR"/util.sh
|
||||
|
||||
set -x
|
||||
set -ex
|
||||
|
||||
# Prepare environment
|
||||
rm -Rf ~/.ndn
|
||||
rm -rf ~/.ndn
|
||||
|
||||
if has OSX $NODE_LABELS; then
|
||||
security unlock-keychain -p named-data
|
||||
@@ -15,32 +10,26 @@ fi
|
||||
|
||||
ndnsec-keygen "/tmp/jenkins/$NODE_NAME" | ndnsec-install-cert -
|
||||
|
||||
BOOST_VERSION=$(python -c "import sys; sys.path.append('build/c4che'); import _cache; print(_cache.BOOST_VERSION_NUMBER);")
|
||||
|
||||
ut_log_args() {
|
||||
if (( BOOST_VERSION >= 106200 )); then
|
||||
echo --logger=HRF,test_suite,stdout:XML,all,build/xunit-${1:-report}.xml
|
||||
else
|
||||
if [[ -n $XUNIT ]]; then
|
||||
echo --log_level=all $( (( BOOST_VERSION >= 106000 )) && echo -- ) \
|
||||
--log_format2=XML --log_sink2=build/xunit-${1:-report}.xml
|
||||
else
|
||||
echo --log_level=test_suite
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
|
||||
ASAN_OPTIONS="color=always"
|
||||
ASAN_OPTIONS+=":detect_leaks=false"
|
||||
ASAN_OPTIONS+=":detect_stack_use_after_return=true"
|
||||
ASAN_OPTIONS+=":check_initialization_order=true"
|
||||
ASAN_OPTIONS+=":strict_init_order=true"
|
||||
ASAN_OPTIONS+=":detect_invalid_pointer_pairs=1"
|
||||
ASAN_OPTIONS+=":detect_container_overflow=false"
|
||||
ASAN_OPTIONS+=":strict_string_checks=true"
|
||||
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)
|
||||
@@ -48,7 +37,9 @@ export ASAN_OPTIONS
|
||||
./build/unit-tests-tools $(ut_log_args tools)
|
||||
|
||||
# Then use sudo to run those tests that need superuser powers
|
||||
sudo -E ./build/unit-tests-core -t TestPrivilegeHelper $(ut_log_args core-privilege)
|
||||
sudo -E ./build/unit-tests-daemon -t Face/TestEthernetTransport $(ut_log_args daemon-ethernet)
|
||||
sudo -E ./build/unit-tests-daemon -t Face/*Factory/ProcessConfig $(ut_log_args daemon-face-config)
|
||||
sudo -E ./build/unit-tests-daemon -t Mgmt/TestGeneralConfigSection/UserAndGroupConfig,NoUserConfig $(ut_log_args daemon-user-config)
|
||||
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)
|
||||
@@ -1,10 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
source "$JDIR"/util.sh
|
||||
|
||||
set -x
|
||||
set -ex
|
||||
|
||||
if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
gcovr --object-directory=build \
|
||||
@@ -12,4 +7,29 @@ if [[ $JOB_NAME == *"code-coverage" ]]; then
|
||||
--exclude="$PWD/(tests|websocketpp)" \
|
||||
--root=. \
|
||||
--xml
|
||||
|
||||
# Generate also a detailed HTML output, but using lcov (better results)
|
||||
lcov --quiet \
|
||||
--capture \
|
||||
--directory . \
|
||||
--no-external \
|
||||
--rc lcov_branch_coverage=1 \
|
||||
--output-file build/coverage-with-tests-and-websocketpp.info
|
||||
|
||||
lcov --quiet \
|
||||
--remove build/coverage-with-tests-and-websocketpp.info "$PWD/websocketpp/*" \
|
||||
--rc lcov_branch_coverage=1 \
|
||||
--output-file build/coverage-with-tests.info
|
||||
|
||||
lcov --quiet \
|
||||
--remove build/coverage-with-tests.info "$PWD/tests/*" \
|
||||
--rc lcov_branch_coverage=1 \
|
||||
--output-file build/coverage.info
|
||||
|
||||
genhtml --branch-coverage \
|
||||
--demangle-cpp \
|
||||
--legend \
|
||||
--output-directory build/coverage \
|
||||
--title "NFD unit tests" \
|
||||
build/coverage.info
|
||||
fi
|
||||
+17
-23
@@ -1,34 +1,28 @@
|
||||
CONTINUOUS INTEGRATION SCRIPTS
|
||||
==============================
|
||||
# CONTINUOUS INTEGRATION SCRIPTS
|
||||
|
||||
Environment Variables Used in Build Scripts
|
||||
-------------------------------------------
|
||||
## Environment Variables Used in Build Scripts
|
||||
|
||||
- `NODE_LABELS`: the variable defines a list of OS properties. The set values are used by the
|
||||
build scripts to select proper behavior for different OS.
|
||||
- `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 include at least `[OS_TYPE]`, `[DISTRO_TYPE]`, and `[DISTRO_VERSION]`.
|
||||
The list should normally contain `[OS_TYPE]`, `[DISTRO_TYPE]`, and `[DISTRO_VERSION]`.
|
||||
|
||||
Possible values for Linux:
|
||||
Example values:
|
||||
|
||||
* `[OS_TYPE]`: `Linux`
|
||||
* `[DISTRO_TYPE]`: `Ubuntu`
|
||||
* `[DISTRO_VERSION]`: `Ubuntu-14.04`, `Ubuntu-16.04`
|
||||
- `[OS_TYPE]`: `Linux`, `OSX`
|
||||
- `[DISTRO_TYPE]`: `Ubuntu`, `CentOS`
|
||||
- `[DISTRO_VERSION]`: `Ubuntu-16.04`, `Ubuntu-18.04`, `CentOS-8`, `OSX-10.14`, `OSX-10.15`
|
||||
|
||||
Possible values for OS X / macOS:
|
||||
|
||||
* `[OS_TYPE]`: `OSX`
|
||||
* `[DISTRO_TYPE]`: `OSX` (can be absent)
|
||||
* `[DISTRO_VERSION]`: `OSX-10.10`, `OSX-10.11`, `OSX-10.12`
|
||||
|
||||
- `JOB_NAME`: optional variable to define type of the job. Depending on the defined job type,
|
||||
- `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 process
|
||||
* `code-coverage` (Linux OS is assumed): debug build with tests and code coverage analysis
|
||||
* `limited-build`: only a single debug build with tests
|
||||
- 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`: the variable defines a path to folder containing cached files from previous builds,
|
||||
e.g., a compiled version of ndn-cxx library. If not set, `/tmp` is used.
|
||||
- `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.
|
||||
@@ -16,3 +16,24 @@ has() {
|
||||
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>
|
||||
+110
-23
@@ -1,28 +1,115 @@
|
||||
sudo: required
|
||||
language: generic
|
||||
version: ~> 1.0
|
||||
language: cpp
|
||||
os: linux
|
||||
dist: bionic
|
||||
|
||||
arch:
|
||||
- amd64
|
||||
#- arm64 # Too slow, exceeds time limit
|
||||
#- ppc64le # Fails transport tests
|
||||
#- s390x # Fails transport tests
|
||||
|
||||
env:
|
||||
global:
|
||||
- JOB_NAME=limited-build
|
||||
matrix:
|
||||
- COMPILER=g++-7
|
||||
- COMPILER=g++-9
|
||||
- COMPILER=clang++-6.0
|
||||
- COMPILER=clang++-9
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- os: linux
|
||||
dist: trusty
|
||||
env:
|
||||
- CXX=g++
|
||||
- NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
|
||||
- os: linux
|
||||
dist: trusty
|
||||
env:
|
||||
- CXX=clang++
|
||||
- NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
|
||||
# Linux
|
||||
- env: COMPILER=g++-5
|
||||
- env: COMPILER=g++-6
|
||||
- env: COMPILER=g++-8
|
||||
- env: COMPILER=clang++-4.0
|
||||
- env: COMPILER=clang++-5.0
|
||||
- env: COMPILER=clang++-7
|
||||
- env: COMPILER=clang++-8
|
||||
- env: COMPILER=clang++-10
|
||||
- env: COMPILER=clang++-11
|
||||
- env: COMPILER=clang++-12
|
||||
|
||||
# macOS
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
env:
|
||||
- CXX=clang++
|
||||
- NODE_LABELS="OSX OSX-10.12"
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
||||
on_failure: always
|
||||
osx_image: xcode9.4
|
||||
env: # default compiler
|
||||
- os: osx
|
||||
osx_image: xcode10.1
|
||||
env: # default compiler
|
||||
- os: osx
|
||||
osx_image: xcode10.3
|
||||
env: # default compiler
|
||||
- os: osx
|
||||
osx_image: xcode11.3
|
||||
env: # default compiler
|
||||
- os: osx
|
||||
osx_image: xcode11.6
|
||||
env: # default compiler
|
||||
- os: osx
|
||||
osx_image: xcode12
|
||||
env: # default compiler
|
||||
|
||||
allow_failures:
|
||||
- env: COMPILER=g++-5
|
||||
- env: COMPILER=g++-6
|
||||
- env: COMPILER=clang++-4.0
|
||||
- env: COMPILER=clang++-12
|
||||
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- |
|
||||
: Adding apt repositories
|
||||
case ${COMPILER} in
|
||||
g++-9)
|
||||
# https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test/+packages
|
||||
travis_retry sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
travis_retry sudo apt-get -qq update
|
||||
;;
|
||||
clang++-1?)
|
||||
# https://apt.llvm.org/
|
||||
LLVM_REPO=${COMPILER/clang++/llvm-toolchain-${TRAVIS_DIST}}
|
||||
travis_retry wget -nv -O - "https://apt.llvm.org/llvm-snapshot.gpg.key" | sudo apt-key add -
|
||||
travis_retry sudo add-apt-repository -y "deb http://apt.llvm.org/${TRAVIS_DIST}/ ${LLVM_REPO%-12} main"
|
||||
travis_retry sudo apt-get -qq update
|
||||
;;
|
||||
esac
|
||||
|
||||
install:
|
||||
- |
|
||||
: Installing C++ compiler
|
||||
if [[ -n ${COMPILER} ]]; then
|
||||
travis_retry sudo apt-get -qy install ${COMPILER/clang++/clang}
|
||||
fi
|
||||
|
||||
before_script:
|
||||
- |
|
||||
: Setting environment variables
|
||||
if [[ -n ${COMPILER} ]]; then
|
||||
export CXX=${COMPILER}
|
||||
fi
|
||||
case ${TRAVIS_OS_NAME} in
|
||||
linux) export NODE_LABELS="Linux Ubuntu Ubuntu-18.04" ;;
|
||||
osx) export NODE_LABELS="OSX OSX-$(sw_vers -productVersion | cut -d . -f -2)" ;;
|
||||
esac
|
||||
export JOB_NAME=limited-build
|
||||
export WAF_JOBS=2
|
||||
- |
|
||||
: Enabling workarounds
|
||||
case "${TRAVIS_CPU_ARCH},${COMPILER}" in
|
||||
ppc64le,g++-7)
|
||||
# AddressSanitizer does not seem to be working
|
||||
export DISABLE_ASAN=yes
|
||||
;;
|
||||
*,clang++-8)
|
||||
# https://bugs.llvm.org/show_bug.cgi?id=40808
|
||||
export DISABLE_ASAN=yes
|
||||
;;
|
||||
esac
|
||||
if [[ ${TRAVIS_OS_NAME} == linux ]]; then
|
||||
sudo sysctl -e -w net.ipv6.conf.all.disable_ipv6=0
|
||||
fi
|
||||
- ${CXX:-c++} --version
|
||||
|
||||
script:
|
||||
- ./.jenkins
|
||||
@@ -1,23 +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 with boost 1.56"
|
||||
#endif
|
||||
'''
|
||||
|
||||
@Configure.conf
|
||||
def check_asio_pcap_support(conf):
|
||||
# https://svn.boost.org/trac/boost/ticket/10367
|
||||
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
|
||||
+53
-38
@@ -54,9 +54,9 @@ from waflib import Utils, Logs, Errors
|
||||
from waflib.Configure import conf
|
||||
from waflib.TaskGen import feature, after_method
|
||||
|
||||
BOOST_LIBS = ['/usr/lib/x86_64-linux-gnu', '/usr/lib/i386-linux-gnu',
|
||||
'/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib']
|
||||
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_VERSION_FILE = 'boost/version.hpp'
|
||||
BOOST_VERSION_CODE = '''
|
||||
#include <iostream>
|
||||
@@ -91,13 +91,18 @@ 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(debug) << "log is working" << std::endl;
|
||||
BOOST_LOG_TRIVIAL(info) << "boost_log_setup is working";
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -146,7 +151,7 @@ def options(opt):
|
||||
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi',
|
||||
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',
|
||||
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',
|
||||
@@ -176,7 +181,7 @@ def boost_get_version(self, d):
|
||||
try:
|
||||
txt = node.read()
|
||||
except EnvironmentError:
|
||||
Logs.error("Could not read the file %r" % node.abspath())
|
||||
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)
|
||||
@@ -184,7 +189,7 @@ def boost_get_version(self, d):
|
||||
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):
|
||||
@@ -195,10 +200,10 @@ def boost_get_includes(self, *k, **kw):
|
||||
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')
|
||||
|
||||
|
||||
@@ -241,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)
|
||||
@@ -314,7 +319,7 @@ def boost_get_libs(self, *k, **kw):
|
||||
libs.append(format_lib_name(file.name))
|
||||
break
|
||||
else:
|
||||
self.end_msg('lib %s not found in %s' % (lib, path.abspath()))
|
||||
self.end_msg('lib %s not found in %s' % (lib, path.abspath()), 'YELLOW')
|
||||
self.fatal('The configuration failed')
|
||||
return libs
|
||||
|
||||
@@ -355,7 +360,7 @@ def _check_pthread_flag(self, *k, **kw):
|
||||
# ... -mt is also the pthreads flag for HP/aCC
|
||||
# -lpthread: GNU Linux, etc.
|
||||
# --thread-safe: KAI C++
|
||||
if Utils.unversioned_sys_platform() == "sunos":
|
||||
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/
|
||||
@@ -363,23 +368,22 @@ def _check_pthread_flag(self, *k, **kw):
|
||||
# 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"]
|
||||
boost_pthread_flags = ['-pthreads', '-lpthread', '-mt', '-pthread']
|
||||
else:
|
||||
boost_pthread_flags = ["", "-lpthreads", "-Kthread", "-kthread", "-llthread", "-pthread",
|
||||
"-pthreads", "-mthreads", "-lpthread", "--thread-safe", "-mt"]
|
||||
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)
|
||||
|
||||
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')
|
||||
self.end_msg('none')
|
||||
|
||||
@conf
|
||||
def check_boost(self, *k, **kw):
|
||||
@@ -404,16 +408,24 @@ 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())
|
||||
|
||||
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
|
||||
@@ -425,7 +437,7 @@ def check_boost(self, *k, **kw):
|
||||
self.env['STLIBPATH_%s' % var] = [path]
|
||||
self.env['LIB_%s' % var] = libs
|
||||
self.env['STLIB_%s' % var] = stlibs
|
||||
self.end_msg('ok')
|
||||
self.end_msg(' '.join(libs + stlibs))
|
||||
if Logs.verbose:
|
||||
Logs.pprint('CYAN', ' path : %s' % path)
|
||||
Logs.pprint('CYAN', ' shared libs : %s' % libs)
|
||||
@@ -446,15 +458,18 @@ def check_boost(self, *k, **kw):
|
||||
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'):
|
||||
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'):
|
||||
if has_shlib('log') or has_shlib('log_setup'):
|
||||
self.env['DEFINES_%s' % var] += ['BOOST_LOG_DYN_LINK']
|
||||
self.check_cxx(fragment=BOOST_LOG_CODE, use=var, execute=False)
|
||||
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',):
|
||||
# disable auto-linking feature, causing error LNK1181
|
||||
@@ -476,10 +491,10 @@ 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]))
|
||||
self.end_msg('ok: winning cxxflags combination: %s' % (self.env['CXXFLAGS_%s' % var]))
|
||||
exc = None
|
||||
break
|
||||
except Errors.ConfigurationError as e:
|
||||
@@ -487,17 +502,17 @@ def check_boost(self, *k, **kw):
|
||||
exc = 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.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')
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
from waflib.Configure import conf
|
||||
|
||||
def configure(conf):
|
||||
pass
|
||||
@@ -1,15 +1,15 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
from waflib import TaskGen, Logs
|
||||
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.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,44 +1,74 @@
|
||||
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
from waflib import Logs, Configure, Utils
|
||||
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 optimizations (-O0 or -Og)''')
|
||||
opt.add_option('--debug', '--with-debug', action='store_true', default=False,
|
||||
help='Compile in debugging mode with minimal optimizations (-Og)')
|
||||
|
||||
def configure(conf):
|
||||
cxx = conf.env['CXX_NAME'] # CXX_NAME represents generic name of the compiler
|
||||
conf.start_msg('Checking C++ compiler version')
|
||||
|
||||
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':
|
||||
flags = GccFlags()
|
||||
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':
|
||||
flags = ClangFlags()
|
||||
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:
|
||||
flags = CompilerFlags()
|
||||
Logs.warn('The code has not yet been tested with %s compiler' % cxx)
|
||||
warnmsg = '%s compiler is unsupported' % cxx
|
||||
conf.flags = CompilerFlags()
|
||||
|
||||
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
|
||||
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)
|
||||
|
||||
# General flags are always applied (e.g., selecting C++11 mode)
|
||||
generalFlags = flags.getGeneralFlags(conf)
|
||||
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:
|
||||
extraFlags = flags.getDebugFlags(conf)
|
||||
if areCustomCxxflagsPresent:
|
||||
extraFlags = conf.flags.getDebugFlags(conf)
|
||||
if conf.areCustomCxxflagsPresent:
|
||||
missingFlags = [x for x in extraFlags['CXXFLAGS'] 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))
|
||||
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:
|
||||
extraFlags = flags.getOptimizedFlags(conf)
|
||||
extraFlags = conf.flags.getOptimizedFlags(conf)
|
||||
|
||||
if not areCustomCxxflagsPresent:
|
||||
if not conf.areCustomCxxflagsPresent:
|
||||
conf.add_supported_cxxflags(extraFlags['CXXFLAGS'])
|
||||
conf.add_supported_linkflags(extraFlags['LINKFLAGS'])
|
||||
|
||||
@@ -55,9 +85,10 @@ def add_supported_cxxflags(self, cxxflags):
|
||||
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.prepend_value('CXXFLAGS', supportedFlags)
|
||||
@@ -73,15 +104,19 @@ def add_supported_linkflags(self, linkflags):
|
||||
self.start_msg('Checking supported LINKFLAGS')
|
||||
|
||||
supportedFlags = []
|
||||
for flag in linkflags:
|
||||
if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
|
||||
supportedFlags += [flag]
|
||||
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': []}
|
||||
@@ -98,18 +133,31 @@ 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'] += ['-O0',
|
||||
flags['CXXFLAGS'] += ['-Og',
|
||||
'-g3',
|
||||
'-pedantic',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-Werror',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-error=maybe-uninitialized', # Bug #1615
|
||||
'-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):
|
||||
@@ -119,63 +167,61 @@ class GccBasicFlags(CompilerFlags):
|
||||
'-pedantic',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-Wcatch-value=2',
|
||||
'-Wextra-semi',
|
||||
'-Wnon-virtual-dtor',
|
||||
'-Wno-unused-parameter',
|
||||
]
|
||||
flags['LINKFLAGS'] += ['-Wl,-O1']
|
||||
return flags
|
||||
|
||||
class GccFlags(GccBasicFlags):
|
||||
def getGeneralFlags(self, conf):
|
||||
flags = super(GccFlags, self).getGeneralFlags(conf)
|
||||
version = tuple(int(i) for i in conf.env['CC_VERSION'])
|
||||
if version < (4, 8, 2):
|
||||
conf.fatal('The version of gcc you are using (%s) is too old.\n' %
|
||||
'.'.join(conf.env['CC_VERSION']) +
|
||||
'The minimum supported gcc version is 4.8.2.')
|
||||
else:
|
||||
flags['CXXFLAGS'] += ['-std=c++11']
|
||||
return flags
|
||||
|
||||
def getDebugFlags(self, conf):
|
||||
flags = super(GccFlags, self).getDebugFlags(conf)
|
||||
version = tuple(int(i) for i in conf.env['CC_VERSION'])
|
||||
if version < (5, 1, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
|
||||
flags['CXXFLAGS'] += ['-Og', # gcc >= 4.8
|
||||
'-fdiagnostics-color', # gcc >= 4.9
|
||||
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)
|
||||
version = tuple(int(i) for i in conf.env['CC_VERSION'])
|
||||
if version < (5, 1, 0):
|
||||
flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
|
||||
flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
|
||||
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)
|
||||
flags['CXXFLAGS'] += ['-std=c++11']
|
||||
if Utils.unversioned_sys_platform() == 'darwin':
|
||||
flags['CXXFLAGS'] += ['-stdlib=libc++']
|
||||
flags['LINKFLAGS'] += ['-stdlib=libc++']
|
||||
# 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
|
||||
'-Wno-error=unneeded-internal-declaration', # Bug #1588
|
||||
'-Wno-error=deprecated-register',
|
||||
'-Wno-error=keyword-macro', # Bug #3235
|
||||
'-Wno-error=infinite-recursion', # Bug #3358
|
||||
]
|
||||
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)
|
||||
|
||||
+5
-10
@@ -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
|
||||
|
||||
|
||||
@@ -67,11 +67,6 @@ def options(opt):
|
||||
|
||||
def configure(conf):
|
||||
if (conf.options.with_pch and conf.env['COMPILER_CXX'] in PCH_COMPILER_OPTIONS.keys()):
|
||||
if Utils.unversioned_sys_platform() == "darwin" and conf.env['CXX_NAME'] == 'clang':
|
||||
version = tuple(int(i) for i in conf.env['CC_VERSION'])
|
||||
if version < (6, 1, 0):
|
||||
# Issue #2804
|
||||
return
|
||||
conf.env.WITH_PCH = True
|
||||
flags = PCH_COMPILER_OPTIONS[conf.env['COMPILER_CXX']]
|
||||
conf.env.CXXPCH_F = flags[0]
|
||||
@@ -95,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
|
||||
|
||||
@@ -109,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')
|
||||
@@ -134,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']
|
||||
|
||||
@@ -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,19 +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
|
||||
|
||||
IS_MOVE_CONSTRUCTIBLE_CHECK = '''
|
||||
#include <type_traits>
|
||||
static_assert(std::is_move_constructible<int>::value, "");
|
||||
'''
|
||||
|
||||
def configure(conf):
|
||||
if conf.check_cxx(msg='Checking for std::is_move_constructible',
|
||||
fragment=IS_MOVE_CONSTRUCTIBLE_CHECK,
|
||||
features='cxx', mandatory=False):
|
||||
conf.define('HAVE_IS_MOVE_CONSTRUCTIBLE', 1)
|
||||
conf.env['HAVE_IS_MOVE_CONSTRUCTIBLE'] = True
|
||||
@@ -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)
|
||||
+18
-21
@@ -6,7 +6,8 @@ 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)
|
||||
|
||||
setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions)
|
||||
|
||||
@Configure.conf
|
||||
def checkWebsocket(self, **kw):
|
||||
@@ -15,7 +16,7 @@ def checkWebsocket(self, **kw):
|
||||
|
||||
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')
|
||||
@@ -24,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')
|
||||
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;
|
||||
|
||||
version = [None, None, None]
|
||||
|
||||
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.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
|
||||
self.env.HAVE_WEBSOCKET = True
|
||||
self.define('HAVE_WEBSOCKET', 1)
|
||||
self.define('_WEBSOCKETPP_CPP11_STL_', 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/archive/0.7.0.tar.gz > 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
-78
@@ -1,82 +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/>
|
||||
|
||||
|
||||
## Main project authors 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 <https://www.linkedin.com/in/davidepesavento>
|
||||
* 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>
|
||||
* Minsheng Zhang <mzhang4@memphis.edu>
|
||||
* Lan Wang <http://www.cs.memphis.edu/~lanwang/>
|
||||
|
||||
## Project contributors
|
||||
|
||||
The following is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS,
|
||||
people who have reported bugs, submitted patches, and implemented new features
|
||||
in the library:
|
||||
|
||||
* Tai-Lin Chu <https://www.linkedin.com/pub/tai-lin-chu/55/5b2/669>
|
||||
* Spyridon Mastorakis <http://cs.ucla.edu/~mastorakis/>
|
||||
* Eric Newberry <http://cs.arizona.edu/~enewberry/>
|
||||
* Yukai Tu <tuyukai1994@gmail.com>
|
||||
* João Pereira <http://website.jpereira.co.uk>
|
||||
* Mathias Gibbens <gibmat@cs.arizona.edu>
|
||||
* Yanbiao Li <https://www.linkedin.com/pub/yanbiao-li/24/7a1/4ba>
|
||||
* Weiwei Liu <https://www.linkedin.com/in/weiweiliu10>
|
||||
* Spencer Lee <https://www.linkedin.com/in/spenlee>
|
||||
* 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,81 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our
|
||||
project and our community a harassment-free experience for everyone,
|
||||
regardless of age, body size, disability, ethnicity, gender identity
|
||||
and expression, level of experience, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive
|
||||
environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual
|
||||
attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political
|
||||
attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or
|
||||
electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in
|
||||
a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of
|
||||
acceptable behavior and are expected to take appropriate and fair
|
||||
corrective action in response to any instances of unacceptable
|
||||
behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit,
|
||||
or reject comments, commits, code, wiki edits, issues, and other
|
||||
contributions that are not aligned to this Code of Conduct, or to ban
|
||||
temporarily or permanently any contributor for other behaviors that
|
||||
they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public
|
||||
spaces when an individual is representing the project or its
|
||||
community. Examples of representing a project or community include
|
||||
using an official project e-mail address, posting via an official
|
||||
social media account, or acting as an appointed representative at an
|
||||
online or offline event. Representation of a project may be further
|
||||
defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior
|
||||
may be reported by contacting the project leaders Lixia Zhang,
|
||||
Beichuan Zhang, or Alex Afanasyev
|
||||
at
|
||||
[lixia@cs.ucla.edu](mailto:lixia@cs.ucla.edu),
|
||||
[bzhang@cs.arizona.edu](mailto:bzhang@cs.arizona.edu),
|
||||
and [aa@cs.ucla.edu](mailto:aa@cs.ucla.edu). All complaints will be
|
||||
reviewed and investigated and will result in a response that is deemed
|
||||
necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of
|
||||
an incident. Further details of specific enforcement policies may be
|
||||
posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct
|
||||
in good faith may face temporary or permanent repercussions as
|
||||
determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from
|
||||
the [Contributor Covenant](http://contributor-covenant.org), version 1.4, available
|
||||
at [http://contributor-covenant.org/version/1/4](http://contributor-covenant.org/version/1/4/)
|
||||
+489
@@ -0,0 +1,489 @@
|
||||
# Contributing to the NDN Codebase
|
||||
## Getting Started
|
||||
|
||||
The NDN team is very glad you are interested in contributing! The NDN
|
||||
(Named Data Networking) codebase is composed of many projects, with
|
||||
multiple universities across the world contributing. This
|
||||
documentation will help you understand how we work and what we expect
|
||||
from contributors.
|
||||
|
||||
### Code of Conduct
|
||||
|
||||
NDN codebase development adheres to the Contributor Covenant, located
|
||||
in `CODE_OF_CONDUCT.md`. By contributing, you are expected to also
|
||||
adhere to this code. If you feel someone has breached this code of
|
||||
conduct,
|
||||
please
|
||||
[email us](mailto:lixia@cs.ucla.edu,bzhang@cs.arizona.edu,aa@cs.ucla.edu).
|
||||
|
||||
### What can I do?
|
||||
|
||||
The NDN codebase continually needs help with, among other
|
||||
things:
|
||||
|
||||
1. Implementing new features
|
||||
2. Writing fixes for bugs
|
||||
3. Writing documentation for features that have recently changed or
|
||||
that change quickly. Sometimes people forget to update
|
||||
documentation!
|
||||
4. Code review
|
||||
|
||||
## Finding Documentation
|
||||
|
||||
The NDN team maintains a community
|
||||
([Redmine site](https://redmine.named-data.net/projects/nfd)) for
|
||||
issue tracking and documentation hosting. Redmine is the hub for
|
||||
design activity. In particular, all design discussion and decisions
|
||||
will either occur or be copied there.
|
||||
|
||||
**Why did they do it *this* way?** When writing code, if you ever have
|
||||
questions about why some design decision was made, the best approach
|
||||
is to use `git blame` on a file to inspect the last commit for some
|
||||
line of code. In this view there will be a commit hash in hex
|
||||
(e.g. `0ab12e3a`) in the first column. Using our example, `git show
|
||||
0ab12e3a` would show the commit made for that line. In the commit view
|
||||
there should be a reference number (e.g. `refs: #1234`). Using this
|
||||
number, you can find a pertaining issue on the Redmine
|
||||
(e.g., `https://redmine.named-data.net/issues/1234`).
|
||||
|
||||
Additionally, in some cases there are published papers you can read in
|
||||
order to gain a better understanding of the project. Searching for
|
||||
these papers is not difficult; in many cases you can find a pertaining
|
||||
paper or technical report listed on
|
||||
[the main NDN website](https://named-data.net/publications).
|
||||
Usually the title of a project will be a good keyword.
|
||||
|
||||
If you cannot find an answer to your question, the best place to go is
|
||||
the
|
||||
[mailing lists](https://named-data.net/codebase/platform/support/mailing-lists/).
|
||||
There are multiple different lists for different interests, so be sure you
|
||||
are mailing the right list for a quick response.
|
||||
|
||||
## Tracking work on Redmine ##
|
||||
|
||||
As mentioned above, Redmine is the organizational hub of the NDN
|
||||
projects. As such, extensive use of it is made, and learning how it
|
||||
works will help you. In particular, there is a workflow associated
|
||||
with Redmine. Generally it is:
|
||||
|
||||
1. An issue is reported by someone. At this point they should
|
||||
describe the issue, including relationships to other
|
||||
issues. Unless they know what they're doing, they should leave
|
||||
particulars blank. Such particulars are priority, target version,
|
||||
assignees, and categories.
|
||||
2. Design discussion about the issue occurs, and the issue is either
|
||||
accepted or rejected.
|
||||
3. Someone either is assigned to, or assigns themselves to work on the
|
||||
issue, setting the status to "In progress."
|
||||
**Note:** You must be a "Developer" of the project before you are
|
||||
able to toggle the Status field. A user should contact a project
|
||||
manager to be granted Developer privilege. Project managers can be
|
||||
found on "Overview" page of the project.
|
||||
4. After every useful chunk of progress, notes are made on the issue
|
||||
and the progress percentage is updated to reflect this. Remember
|
||||
that notes are actually Markdown, so it is advised to use the
|
||||
'preview' button to ensure your note looks right.
|
||||
5. The changes are uploaded to Gerrit for review. Once all changes
|
||||
pertaining to an issue are on Gerrit, an issues status should
|
||||
change to "Code review."
|
||||
6. Once all changes are cleared for merging, they either can be
|
||||
merged, or held for feedback, at which point the issue status
|
||||
should become "Feedback."
|
||||
7. After all changes have been merged, the issue should be set to
|
||||
"Closed."
|
||||
|
||||
Redmine provides other facilities for managing your work on NDN
|
||||
projects, too, such as time logging and time estimation.
|
||||
|
||||
## Contributing Guidelines
|
||||
|
||||
### Repositories ###
|
||||
|
||||
All NDN projects are hosted on GitHub, at various organizations, using git
|
||||
for version control:
|
||||
|
||||
- [Main NDN codebase](https://github.com/named-data)
|
||||
- [NDN codebase for mobile platforms](https://github.com/named-data-mobile)
|
||||
- [NDN codebase for IoT](https://github.com/named-data-iot)
|
||||
- [ndnSIM codebase](https://github.com/named-data-ndnSIM)
|
||||
- [Other NDN codebase (REMAP)](https://github.com/remap)
|
||||
|
||||
If you are unfamiliar with git, some kind
|
||||
of [tutorial on git](https://git-scm.com/book/en/v1/Getting-Started)
|
||||
should be your first step.
|
||||
|
||||
There is also a [Git game](http://learngitbranching.js.org/index.html)
|
||||
you can play. Finally, there is a
|
||||
[wiki page](https://redmine.named-data.net/projects/nfd/wiki#Development-process)
|
||||
on NFD's Redmine that has more useful links.
|
||||
|
||||
There are a lot of different projects, so take some time to look
|
||||
through them for ones that pertain to your interests. NDN projects
|
||||
use [Gerrit](https://gerrit.named-data.net/) for code review purposes.
|
||||
|
||||
Occasionally there will be other repositories used privately to test
|
||||
changes, but this is uncommon. In general, you will not need to refer
|
||||
to these repositories.
|
||||
|
||||
### Style ###
|
||||
|
||||
Most NDN projects are written in C++, and there is a
|
||||
[style guide](https://named-data.net/doc/ndn-cxx/current/code-style.html).
|
||||
In general the NDN style is similar to the GNU style, but there are
|
||||
some significant changes. This style guide is not exhaustive, and in
|
||||
all cases not covered by the guide you should emulate the current
|
||||
style of the project.
|
||||
|
||||
There is a
|
||||
[partial styleguide](https://redmine.named-data.net/projects/nfd/wiki/CodeStyle)
|
||||
for Python. It applies many of the provisions from the C++ guide, in
|
||||
addition to some other Python-specific things.
|
||||
|
||||
Some NDN projects are written in JavaScript, and there is a [style guide](https://named-data.net/codebase/platform/documentation/ndn-platform-development-guidelines/cpp-code-guidelines/) for that language, too.
|
||||
|
||||
#### Commit Messages ####
|
||||
|
||||
Commit messages are very important, as they are usually the first
|
||||
thing (besides the changelog file) a developer looks at when trying to
|
||||
understand the timeline of a project. Commit messages should:
|
||||
|
||||
- Have a short, descriptive first line, starting with the module
|
||||
they change. A good rule of thumb is a maximum length of 65
|
||||
characters.
|
||||
- If including a body, leave a blank line between the first line and
|
||||
the rest, and ensure that each line is no longer than 72 characters.
|
||||
- Include Redmine issue numbers. The exact syntax is given below.
|
||||
- Be written in an imperative mood. E.g. `"Make foo a bar"` and not
|
||||
`"Foo is now a bar"`
|
||||
- Use the present tense. E.g. `"Make foo a bar"` and not `"Made foo a
|
||||
bar"`
|
||||
|
||||
To explain, the anatomy of a typical commit message is like this:
|
||||
|
||||
docs: write contributing guide and code of conduct
|
||||
|
||||
This commit adds a guide that may be useful for new-comers to NDN in
|
||||
becoming productive contributors. This commit also adds a code of
|
||||
conduct.
|
||||
|
||||
refs: #3898
|
||||
Change-Id: Ife89360305027dba9020f0b298793c1121ae1fd6c
|
||||
|
||||
Explaining this:
|
||||
|
||||
- `docs` is the module that the commit affects. We want this because
|
||||
it lets someone know at a glance what part of the project it
|
||||
changes. For some projects, there will be only one module or only
|
||||
very small other modules. This practice should be observed in
|
||||
those cases, too.
|
||||
- `#3898` is the Redmine issue number. Gerrit transforms these into
|
||||
clickable links, and it is useful to reviewers to gain background
|
||||
understanding of the issue. You can have multiple by separating
|
||||
them with commas.
|
||||
- `Change-Id` should be filled automatically. It is used by Gerrit
|
||||
to track changes.
|
||||
|
||||
### Unit Tests ###
|
||||
With a few exceptions, every patch needs to have unit tests that
|
||||
accompany them. For C++, we use
|
||||
the [Boost unit test framework](http://www.boost.org/libs/test) to
|
||||
help us out. Note that this link points to the newest version of the
|
||||
Boost Test library documentation, and you may need to refer to older
|
||||
documentation if you are using an older version of Boost. More
|
||||
information on this is available in
|
||||
the
|
||||
[NFD Dev Guide](https://named-data.net/publications/techreports/ndn-0021-7-nfd-developer-guide/)
|
||||
|
||||
When designing and writing tests, a few things need to be kept in mind:
|
||||
|
||||
1. Unit tests are **design** tools, *not* debug tools. Just because
|
||||
your code passes some unit tests does not mean it is
|
||||
bug-free. Unit tests are tools to convince you that your code does
|
||||
what you think it does.
|
||||
2. It can be difficult to know when you should test something. If
|
||||
you find that you are having a hard time designing a test for
|
||||
something, ask yourself whether it is because it doesn't make
|
||||
sense to test what you've just written, or if it's because the way
|
||||
you designed it makes it difficult to test. Consider a second look
|
||||
at your design if you think it's the second one.
|
||||
3. The method that gave the world unit tests says that unit tests
|
||||
should be written *before* the code they test. This is
|
||||
a contentious issue, so writing them either before or after is
|
||||
acceptable. If writing them later, keep the tests in mind when
|
||||
writing the code, and it will help design good interfaces.
|
||||
4. At the very least, write the test for a completed module/unit of
|
||||
code before moving on. Doing this will ensure that the test gets
|
||||
written, and will help you think about the interface that you need
|
||||
to examine. If you don't, you may forget exactly what each piece
|
||||
is responsible for when you're looking at the whole system
|
||||
afterward.
|
||||
5. Separate your I/O, as it is very hard to test, so I/O should be
|
||||
isolated if possible. Consider something like separating a
|
||||
function that invokes I/O into two functions: one that does the
|
||||
I/O and calls the other one, which takes that I/O result. This
|
||||
will make it easier to test that second function than if they were
|
||||
combined.
|
||||
|
||||
Writing unit tests using the Boost framework is quite simple, and you
|
||||
can refer to existing unit tests for examples.
|
||||
([This is a good example.](https://github.com/named-data/NFD/blob/master/tests/rib/rib.t.cpp))
|
||||
|
||||
#### Building and running unit tests ####
|
||||
This is mentioned in greater depth in
|
||||
the [developer's readme](README-dev.md), but the basic procedure is:
|
||||
|
||||
1. In the base directory of the project, run `./waf distclean`. This
|
||||
removes all prior build files.
|
||||
2. Run `./waf configure --with-tests`. This configures the next build
|
||||
to also build the tests.
|
||||
3. Run `./waf`. This will build the tests.
|
||||
4. Then, the unit tests will be in the `build` directory, and will be
|
||||
named `unit-tests-<module name`, e.g. `unit-tests-nlsr` or
|
||||
`unit-tests-rib`. To run just one test suite, run
|
||||
`./unit-tests-exampleModule -t ExampleTestSuite`. To run a
|
||||
specific test in a suite, use `./unit-tests-exampleModule -t
|
||||
ExampleTestSuite/ExampleTestCase`.
|
||||
|
||||
## Gerrit: Uploading Patches and Code Review ##
|
||||
|
||||
As mentioned above, NDN projects
|
||||
use [Gerrit](https://gerrit.named-data.net/) for code review. This is
|
||||
a web-hosted, open code review platform that allows for interactive
|
||||
code review, rebasing, and cross-linking with the Redmine, and a
|
||||
developer interacts with it using the familiar git. For issues that
|
||||
require a tracker reference, a particularly useful feature is that
|
||||
the `refs: #...` becomes a clickable link to the issue for design
|
||||
discussion.
|
||||
|
||||
### First-time Setup ###
|
||||
|
||||
The first-time Gerrit setup goes like this:
|
||||
|
||||
1. Log in to Gerrit. You can authenticate using many different
|
||||
methods, including GitHub OAuth. You need to ensure that you have a Gerrit username:
|
||||
1. Log in.
|
||||
2. Click on your name in the top right corner and click "Settings" in the pop-up box.
|
||||
3. In the `Username` box, check for a name. If there's already one there, great.
|
||||
4. If not, type one in, and this will be used in later steps.
|
||||
|
||||
2. Set up your Gerrit credentials. This will depend on how you
|
||||
configured your Gerrit remote in step 1. Among other things, you
|
||||
need to set up identities so that the email on your Gerrit profile
|
||||
matches whatever email you will be committing with on your git
|
||||
repo.
|
||||
**Note:** We only support using
|
||||
[SSH access to Gerrit](https://gerrit.named-data.net/Documentation/user-upload.html#ssh).
|
||||
|
||||
This shows what the identities panel looks like. If you do
|
||||
not see the email here that you have configured git to use, you
|
||||
cannot upload to Gerrit.
|
||||

|
||||
|
||||
In that case, add it under contact information panel.
|
||||
.
|
||||
|
||||
Gerrit itself has
|
||||
[extensive documentation](https://gerrit.named-data.net/Documentation/error-messages.html)
|
||||
regarding error messages, and this identity-based one is by far the most
|
||||
common. This is the
|
||||
[documentation for an identity error.](https://gerrit.named-data.net/Documentation/error-invalid-author.html)
|
||||
|
||||
3. Clone the source for a project from Gerrit.
|
||||
1. While logged in to Gerrit, there will be a link in the top-left
|
||||
area, `Projects`.
|
||||
2. From this project view, click on the `Clone with commit-msg
|
||||
hook` tab.
|
||||
3. Click on the `ssh` tab to select cloning over SSH. **Note:**
|
||||
This will require setting up SSH access to Gerrit first.
|
||||
4. Copy-and-paste the `git clone ...` command into your terminal
|
||||
to fetch the project source.
|
||||
|
||||
After this, your remotes will be set up correctly, and pushing to
|
||||
Gerrit will only require `git push origin HEAD:refs/for/master` after
|
||||
committing work. This section has some
|
||||
[git tips and tricks to type less][type-less].
|
||||
|
||||
### Uploading patches ###
|
||||
|
||||
Most patches should have a corresponding Redmine issue that they can
|
||||
reference. If you search the Redmine and notice there is no relevant
|
||||
issue for a patch you are writing, please create an issue first. You
|
||||
will need a Redmine account, which can be created there.
|
||||
|
||||
After writing some changes, commit them locally as normal. After
|
||||
saving and exiting your editor, the commit hook will insert a unique
|
||||
`Change-Id` to the message.
|
||||
|
||||
|
||||
Once you have a commit message you are happy with, simply run `git
|
||||
push HEAD:refs/for/master`.
|
||||
|
||||
**Note:** Gerrit separates commits into patch sets by the unique
|
||||
`Change-Id`s. As a result, you must either:
|
||||
|
||||
* Squash your various commits into one with `git rebase -i
|
||||
<initial commit>`, ensuring that the ultimate `Change-Id` in the
|
||||
commit is the one on the patch set on Gerrit. This workflow is
|
||||
generally preferred.
|
||||
* Amend your commit with any new changes using `git commit --amend`.
|
||||
|
||||
If you do not do this, what will happen is that each commit will be
|
||||
interpreted by Gerrit as a separate patch set. This is probably not
|
||||
what you want.
|
||||
|
||||
### Code Review ###
|
||||
#### Dealing with Code Review ####
|
||||
|
||||
It is important to remember that code review is about improving
|
||||
the quality of code contributed, and nothing else. Further, code
|
||||
review is highly important, as every line of code that's
|
||||
committed comes with a burden of maintenance. Code review helps
|
||||
minimize the burden of that maintenance. Consider that when you
|
||||
are receiving comments, those comments are influenced by two
|
||||
things:
|
||||
|
||||
- How the reviewer personally feels about the change ("Would I
|
||||
be happy to see this code in a year?" or "Would I be happy if
|
||||
I wrote this?") and
|
||||
- How the reviewer feels the change abides by style and usage
|
||||
requirements ("I may not personally mind, but we have to do it
|
||||
this way.")
|
||||
|
||||
Remembering these things when reading comments helps to separate
|
||||
what can feel like needless negativity.
|
||||
|
||||
#### Doing Code Review and Writing Comments ####
|
||||
|
||||
**Code review is *extremely* important!** We need every bit of code
|
||||
review you can give. In many cases this is the bottleneck for
|
||||
new contributors who do not fully understand how certain
|
||||
language constructs should be used, what best practices are,
|
||||
etc. In these cases it is important to give constructive
|
||||
feedback.
|
||||
|
||||
Writing comments is somewhat counter-intuitive on Gerrit. If you are
|
||||
signed in through a modern browser, you can leave a comment in a file
|
||||
either by clicking on the line number, by selecting some text you want
|
||||
to comment and pressing 'c', or by clicking on someone else's
|
||||
comment. After typing, click the `Save` button there. After navigating
|
||||
through the patch set with the arrows at the top-right of the Gerrit
|
||||
UI, you then must click the up-arrow to get back to the Change
|
||||
screen. **At this point your comments have *not* been made yet!** You
|
||||
must then click the `Reply...` button, and assign a score. If you
|
||||
correctly saved your comments, they will be shown at the bottom of
|
||||
that box. Once you click post, the comments will be made public to
|
||||
others.
|
||||
|
||||
Minimally, a review *must* include:
|
||||
|
||||
- A score (usually -1, 0, or +1)
|
||||
- An "itemized" commentary on each objection you have, or a
|
||||
justification for a whole-change objection.
|
||||
|
||||
Optimally, a review should include:
|
||||
|
||||
- A useful explanation of *why* you object to some item. This is
|
||||
more important than it first appears. Consider that although
|
||||
you may have been writing code since before you could count,
|
||||
not everyone has. Some things may not be obvious to others,
|
||||
and sharing your knowledge is key to making an open-source
|
||||
project work.
|
||||
- Comments about good design decisions. These help motivate
|
||||
developers when otherwise a review is entirely negative
|
||||
comments.
|
||||
|
||||
#### Expediting the Code Review Process ####
|
||||
|
||||
If you observe that code review takes a long time, there are a
|
||||
few things that you can do to to expedite the process:
|
||||
|
||||
1. **Think about language best practices.**
|
||||
2. **Ask yourself how you would feel about this code, if you saw it "in the wild."**
|
||||
3. **When making code decisions, ask yourself "why *shouldn't* I do it this way?"**
|
||||
|
||||
#### Responding to Code Review ####
|
||||
|
||||
There are a few things to remember when responding to code review, including:
|
||||
|
||||
- **Don't** click "Done" on a comment if you agree with a comment and
|
||||
are updating the code accordingly. These comments are essentially
|
||||
useless and only clutter the discussion. Gerrit has a convenient
|
||||
mechanism to check the differences between two patch sets, so
|
||||
reviewers are expected to check that their comments have been
|
||||
addressed.
|
||||
- **Don't** blindly follow what is suggested. Review is just that: a
|
||||
review. Sometimes what is suggested is functionally equivalent to
|
||||
what you have implemented. Other times, the reviewer has not
|
||||
considered something when writing their review, and their
|
||||
suggestion will not work. Lastly, if you disagree with a suggestion
|
||||
for some other reason, feel free to object, but you may be asked to
|
||||
provide an explanation.
|
||||
- **How** to reply. To reply to a comment, click on the comment in
|
||||
the Gerrit interface, type your reply, and then press save. After
|
||||
replying, you **must remember** to go to the main patch set change
|
||||
screen, and press `Reply...`. Your comments will be shown as
|
||||
drafts, and you must click `Post` to make them visible to others.
|
||||
|
||||
### Jenkins ###
|
||||
|
||||
As a supplement to the code review process, every patch set is automatically
|
||||
compiled and tested on multiple platforms
|
||||
using [our instance of Jenkins](http://jenkins.named-data.net/), the
|
||||
continuous integration system. Interacting with Jenkins is not usually
|
||||
necessary, as Jenkins automatically picks up new patch sets and posts
|
||||
the results. Typically the only interaction needed with Jenkins is
|
||||
when some kind of glitch occurs and a build needs to be retriggered.
|
||||
|
||||
It is expected that code is checked locally. Reviewers may wait until
|
||||
Jenkins checks the code before doing a more functional review of the
|
||||
code. Since Jenkins checks can take a while, you can save some time by
|
||||
checking yourself first.
|
||||
|
||||
### Gerrit Change-Id Commit Hook ###
|
||||
|
||||
If you encounter an error like this when trying to push work:
|
||||
|
||||
remote: ERROR: [4311462] missing Change-Id in commit message footer
|
||||
remote:
|
||||
remote: Hint: To automatically insert Change-Id, install the hook:
|
||||
remote: gitdir=$(git rev-parse --git-dir); scp -p -P 29418 someuser@gerrit.named-data.net:hooks/commit-msg ${gitdir}/hooks/
|
||||
remote: And then amend the commit:
|
||||
remote: git commit --amend
|
||||
|
||||
Then your commit hook has not been set up correctly, somehow. Follow
|
||||
the instructions in the terminal to resolve this.
|
||||
|
||||
### Code Style Robot ###
|
||||
|
||||
As part of CI, there is a script that checks every patch uploaded to
|
||||
Gerrit for code style consistency. Checking these kinds of things is
|
||||
notoriously difficult, and while the robot is very good in general, it
|
||||
will occasionally report false positives and miss things. So all
|
||||
issues it raises should be inspected manually to ensure they really
|
||||
are style problems. Further, since this automated check is not
|
||||
perfect, you should take steps (e.g., configure your editor or run a
|
||||
linter before you commit) to ensure you adhere to code style rules.
|
||||
|
||||
### <a name="type-less"></a> Typing Less to Upload Patches to Gerrit ###
|
||||
|
||||
If typing `HEAD:refs/for/master` feels
|
||||
repetitive, you have a few options:
|
||||
|
||||
* You can configure git to do the work for you, as described
|
||||
in [this blog post](https://yoursunny.com/t/2017/NFD-devbox/#Uploading-to-Gerrit)
|
||||
|
||||
* Git has an alias system that you can use to specify certain
|
||||
commands. For example, you can use `git config --global alias.pg
|
||||
"push origin HEAD:refs/for/master"` to make `git pg` push to
|
||||
Gerrit. [Learn about git aliases here.](https://githowto.com/aliases)
|
||||
|
||||
* If using Linux or macOS, it is relatively simple to create a shell
|
||||
alias: `alias gs="git status"` for example, or `alias gitpush="git
|
||||
push origin HEAD:refs/for/master`. The alias itself must be one
|
||||
word, but it can represent multiple words. To persist your
|
||||
aliases, they need to go in your environment file, which is
|
||||
generally at `~/.bashrc` or `~/.zshrc` or `~/.profile`. The exact
|
||||
syntax of aliases and the environment variables file will vary by
|
||||
shell. You should be careful not to overuse aliases, however.
|
||||
|
||||
[type-less]: #type-less
|
||||
+371
-374
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.
|
||||
+29
-26
@@ -1,18 +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).
|
||||
|
||||
Contributions to NFD must be licensed under 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:
|
||||
## 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) [Year(s)], [Copyright Holder(s)].
|
||||
/*
|
||||
* 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.
|
||||
@@ -32,37 +37,36 @@ Include the following license boilerplate into all `.hpp` and `.cpp` files:
|
||||
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)).
|
||||
|
||||
Recommendations
|
||||
---------------
|
||||
## Logging
|
||||
|
||||
NFD code is subject to NFD [code style](https://redmine.named-data.net/projects/nfd/wiki/CodeStyle).
|
||||
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_54_0/libs/test/doc/html/index.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
|
||||
@@ -73,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
|
||||
@@ -88,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_54_0/libs/test/doc/html/index.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,35 +1,15 @@
|
||||
NFD - Named Data Networking Forwarding Daemon
|
||||
=============================================
|
||||
# NFD - Named Data Networking Forwarding Daemon
|
||||
|
||||

|
||||
[](https://travis-ci.org/named-data/NFD)
|
||||
|
||||
For complete documentation, including step-by-step installation instructions and
|
||||
tutorials, please visit the [NFD homepage](https://named-data.net/doc/NFD/).
|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
NFD is a network forwarder that implements and evolves together with the Named Data
|
||||
Networking (NDN) [protocol](https://named-data.net/doc/ndn-tlv/). After the initial
|
||||
release, NFD will become a core component of the
|
||||
[NDN Platform](https://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](https://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](https://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
|
||||
@@ -42,3 +22,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).
|
||||
@@ -1,130 +0,0 @@
|
||||
Starting NFD on Linux with systemd
|
||||
==================================
|
||||
|
||||
Newer versions of Ubuntu (starting with 15.04) and some other Linux distributions, including Debian
|
||||
use systemd to start system daemons, monitor their health, and restart them when they die.
|
||||
|
||||
Initial setup
|
||||
-------------
|
||||
|
||||
* Edit `nfd.service`, correcting the paths to the `nfd` executable, configuration, and
|
||||
``HOME`` directories.
|
||||
|
||||
* Copy the systemd config file for NFD to the proper directory
|
||||
|
||||
sudo cp nfd.service /etc/systemd/system
|
||||
|
||||
* Reload the systemd manager configuration
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
### Assumptions in the default scripts
|
||||
|
||||
* `nfd` is installed into `/usr/local/bin`
|
||||
* Configuraton file is `/usr/local/etc/ndn/nfd.conf`
|
||||
* `nfd` will be run as root
|
||||
* Log files will be written to `/usr/local/var/log/ndn` folder, which is owned by user `ndn`
|
||||
|
||||
### Creating users
|
||||
|
||||
If the `ndn` user and group do not exist, they need to be manually created.
|
||||
|
||||
# Create group `ndn`
|
||||
sudo 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` directory for `nfd` should be created prior to starting. This is necessary to manage
|
||||
unique security credentials for the daemon.
|
||||
|
||||
# Create HOME and generate self-signed NDN certificate for nfd
|
||||
sudo sh -c ' \
|
||||
mkdir -p /usr/local/var/lib/ndn/nfd/.ndn; \
|
||||
export HOME=/usr/local/var/lib/ndn/nfd; \
|
||||
ndnsec-keygen /localhost/daemons/nfd | 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 the security configuration of NFD is outside the scope of
|
||||
this document, at least the following change should be done in ``nfd.conf`` in the
|
||||
authorize section:
|
||||
|
||||
authorizations
|
||||
{
|
||||
authorize
|
||||
{
|
||||
certfile certs/localhost_daemons_nfd.ndncert
|
||||
privileges
|
||||
{
|
||||
faces
|
||||
fib
|
||||
strategy-choice
|
||||
}
|
||||
}
|
||||
|
||||
authorize
|
||||
{
|
||||
certfile any
|
||||
privileges
|
||||
{
|
||||
faces
|
||||
strategy-choice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
While this configuration still allows the management of faces and updating strategy choice by
|
||||
anyone, only NFD's RIB Manager (i.e., NFD itself) is allowed to manage FIB.
|
||||
|
||||
As the final step to make this configuration work, nfd's self-signed certificate needs to
|
||||
be exported into the `localhost_daemons_nfd.ndncert` file:
|
||||
|
||||
sudo sh -c '\
|
||||
mkdir -p /usr/local/etc/ndn/certs || true; \
|
||||
export HOME=/usr/local/var/lib/ndn/nfd; \
|
||||
ndnsec-dump-certificate -i /localhost/daemons/nfd > \
|
||||
/usr/local/etc/ndn/certs/localhost_daemons_nfd.ndncert; \
|
||||
'
|
||||
|
||||
Enable auto-start
|
||||
-----------------
|
||||
|
||||
After copying the provided upstart script, auto-start of the `nfd` daemon can be enabled with:
|
||||
|
||||
sudo systemctl enable nfd
|
||||
|
||||
To manually start it, use the following command:
|
||||
|
||||
sudo systemctl start nfd
|
||||
|
||||
Disable auto-start
|
||||
------------------
|
||||
|
||||
To stop the `nfd` daemon, use the following command:
|
||||
|
||||
sudo systemctl stop nfd
|
||||
|
||||
To permanently stop the `nfd` daemon and disable it from being automatically started on reboot,
|
||||
disable the service:
|
||||
|
||||
sudo systemctl disable nfd
|
||||
@@ -1,42 +0,0 @@
|
||||
# Copyright (c) 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/>.
|
||||
#
|
||||
# Author: Eric Newberry <enewberry@email.arizona.edu>
|
||||
|
||||
[Unit]
|
||||
Description=NDN Forwarding Daemon
|
||||
Documentation=man:nfd man:nfdc man:nfd-status
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Environment=HOME=/usr/local/var/lib/ndn/nfd
|
||||
ExecStart=/usr/local/bin/nfd --config /usr/local/etc/ndn/nfd.conf
|
||||
ExecStartPost=/bin/sh -ec 'sleep 2; if [ -f /usr/local/etc/ndn/nfd-init.sh ]; then . /usr/local/etc/ndn/nfd-init.sh; fi'
|
||||
Restart=on-failure
|
||||
ProtectSystem=full
|
||||
PrivateTmp=yes
|
||||
PrivateDevices=yes
|
||||
ProtectHome=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,125 +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` correcting paths for `nfd` binary, configuration and log files.
|
||||
|
||||
* Copy upstart config file for NFD
|
||||
|
||||
sudo cp nfd.conf /etc/init/
|
||||
|
||||
### Assumptions in the default scripts
|
||||
|
||||
* `nfd` is installed into `/usr/local/bin`
|
||||
* Configuration file is `/usr/local/etc/ndn/nfd.conf`
|
||||
* `nfd` will be run as root
|
||||
* Log files will be written to `/usr/local/var/log/ndn` folder, which is owned by user `ndn`
|
||||
|
||||
### 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` directory for `nfd` should be created prior to starting. This is necessary to manage
|
||||
unique security credentials for the deamon.
|
||||
|
||||
# Create HOME and generate self-signed NDN certificate for nfd
|
||||
sudo -s -- ' \
|
||||
mkdir -p /usr/local/var/lib/ndn/nfd/.ndn; \
|
||||
export HOME=/usr/local/var/lib/ndn/nfd; \
|
||||
ndnsec-keygen /localhost/daemons/nfd | 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_nfd.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 (i.e., NFD itself) is allowed to manage FIB.
|
||||
|
||||
As the final step to make this configuration work, nfd's self-signed certificate needs to
|
||||
be exported into `localhost_daemons_nfd.ndncert` file:
|
||||
|
||||
sudo -s -- '\
|
||||
mkdir -p /usr/local/etc/ndn/certs || true; \
|
||||
export HOME=/usr/local/var/lib/ndn/nfd; \
|
||||
ndnsec-dump-certificate -i /localhost/daemons/nfd > \
|
||||
/usr/local/etc/ndn/certs/localhost_daemons_nfd.ndncert; \
|
||||
'
|
||||
|
||||
|
||||
Enable auto-start
|
||||
-----------------
|
||||
|
||||
After copying the provided upstart script, `nfd` daemon will automatically run after the reboot.
|
||||
To manually start them, use the following commands:
|
||||
|
||||
sudo start nfd
|
||||
|
||||
Disable auto-start
|
||||
------------------
|
||||
|
||||
To stop `nfd` daemon, use the following commands:
|
||||
|
||||
sudo stop nfd
|
||||
|
||||
Note that as long as upstart files are present in `/etc/init/`, the daemon will
|
||||
automatically start after the reboot. To permanently stop `nfd` daemon, delete
|
||||
the upstart files:
|
||||
|
||||
sudo rm /etc/init/nfd.conf
|
||||
@@ -1,26 +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-start script
|
||||
if [ -f /usr/local/etc/ndn/nfd-init.sh ]; then
|
||||
sleep 2 # post-start is executed just after nfd process starts, but there is no guarantee
|
||||
# that all initialization has been finished
|
||||
. /usr/local/etc/ndn/nfd-init.sh
|
||||
fi
|
||||
end script
|
||||
|
||||
post-stop exec sleep 2
|
||||
@@ -1,67 +0,0 @@
|
||||
/* -*- 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_ASSERTS_HPP
|
||||
#define NFD_CORE_ASSERTS_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include <boost/concept/assert.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace nfd {
|
||||
namespace detail {
|
||||
|
||||
// As of Boost 1.54.0, the internal implementation of BOOST_CONCEPT_ASSERT does not allow
|
||||
// multiple assertions on the same line, so we have to combine multiple concepts together.
|
||||
|
||||
template<typename T>
|
||||
class StlForwardIteratorConcept : public boost::ForwardIterator<T>
|
||||
, public boost::DefaultConstructible<T>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace nfd
|
||||
|
||||
/** \brief assert T is default constructible
|
||||
* \sa http://en.cppreference.com/w/cpp/concept/DefaultConstructible
|
||||
*/
|
||||
#define NFD_ASSERT_DEFAULT_CONSTRUCTIBLE(T) \
|
||||
static_assert(std::is_default_constructible<T>::value, \
|
||||
#T " must be default-constructible"); \
|
||||
BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>))
|
||||
|
||||
/** \brief assert T is a forward iterator
|
||||
* \sa http://en.cppreference.com/w/cpp/concept/ForwardIterator
|
||||
* \note A forward iterator should be default constructible, but boost::ForwardIterator follows
|
||||
* SGI standard which doesn't require DefaultConstructible, so a separate check is needed.
|
||||
*/
|
||||
#define NFD_ASSERT_FORWARD_ITERATOR(T) \
|
||||
BOOST_CONCEPT_ASSERT((::nfd::detail::StlForwardIteratorConcept<T>)); \
|
||||
static_assert(std::is_default_constructible<T>::value, \
|
||||
#T " must be default-constructible")
|
||||
|
||||
#endif // NFD_CORE_ASSERTS_HPP
|
||||
+30
-19
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -33,12 +33,14 @@
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED public
|
||||
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE public
|
||||
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE protected
|
||||
#define OVERRIDE_WITH_TESTS_ELSE_FINAL override
|
||||
#define FINAL_UNLESS_WITH_TESTS
|
||||
#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
|
||||
#define OVERRIDE_WITH_TESTS_ELSE_FINAL final
|
||||
#define FINAL_UNLESS_WITH_TESTS final
|
||||
#endif
|
||||
|
||||
@@ -46,31 +48,35 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/data.hpp>
|
||||
#include <ndn-cxx/delegation.hpp>
|
||||
#include <ndn-cxx/delegation-list.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/face-uri.hpp>
|
||||
#include <ndn-cxx/util/exception.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
#include <ndn-cxx/util/signal.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/noncopyable.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
@@ -82,38 +88,43 @@ using std::shared_ptr;
|
||||
using std::unique_ptr;
|
||||
using std::weak_ptr;
|
||||
using std::make_shared;
|
||||
using ndn::make_unique;
|
||||
using std::enable_shared_from_this;
|
||||
using std::make_unique;
|
||||
|
||||
using std::static_pointer_cast;
|
||||
using std::dynamic_pointer_cast;
|
||||
using std::const_pointer_cast;
|
||||
|
||||
using std::function;
|
||||
using std::bind;
|
||||
using std::ref;
|
||||
using std::cref;
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
using ndn::optional;
|
||||
using ndn::nullopt;
|
||||
using ndn::to_string;
|
||||
|
||||
using ndn::Interest;
|
||||
using ndn::Block;
|
||||
using ndn::Data;
|
||||
using ndn::Delegation;
|
||||
using ndn::DelegationList;
|
||||
using ndn::FaceUri;
|
||||
using ndn::Interest;
|
||||
using ndn::Name;
|
||||
using ndn::PartialName;
|
||||
using ndn::Exclude;
|
||||
using ndn::Link;
|
||||
using ndn::Block;
|
||||
using ndn::util::FaceUri;
|
||||
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 {
|
||||
// Don't write "namespace tlv = ndn::tlv", because NFD can add other members into this namespace.
|
||||
using namespace ndn::tlv;
|
||||
} // namespace tlv
|
||||
|
||||
namespace lp = ndn::lp;
|
||||
namespace name = ndn::name;
|
||||
namespace time = ndn::time;
|
||||
namespace scheduler = ndn::scheduler;
|
||||
namespace signal = ndn::util::signal;
|
||||
namespace time = ndn::time;
|
||||
using namespace ndn::time_literals;
|
||||
using ndn::operator""_block;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/* -*- 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_EXTENDED_ERROR_MESSAGE_HPP
|
||||
#define NFD_CORE_EXTENDED_ERROR_MESSAGE_HPP
|
||||
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
template<typename E>
|
||||
std::string
|
||||
getExtendedErrorMessage(const E& exception)
|
||||
{
|
||||
std::ostringstream errorMessage;
|
||||
errorMessage << exception.what();
|
||||
|
||||
const char* const* file = boost::get_error_info<boost::throw_file>(exception);
|
||||
const int* line = boost::get_error_info<boost::throw_line>(exception);
|
||||
const char* const* func = boost::get_error_info<boost::throw_function>(exception);
|
||||
if (file && line) {
|
||||
errorMessage << " [from " << *file << ":" << *line;
|
||||
if (func) {
|
||||
errorMessage << " in " << *func;
|
||||
}
|
||||
errorMessage << "]";
|
||||
}
|
||||
|
||||
return errorMessage.str();
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_EXTENDED_ERROR_MESSAGE_HPP
|
||||
@@ -1,48 +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_GLOBAL_IO_HPP
|
||||
#define NFD_CORE_GLOBAL_IO_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \return the global io_service instance
|
||||
*/
|
||||
boost::asio::io_service&
|
||||
getGlobalIoService();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
/** \brief delete the global io_service instance
|
||||
*
|
||||
* It will be recreated at the next invocation of getGlobalIoService.
|
||||
*/
|
||||
void
|
||||
resetGlobalIoService();
|
||||
#endif
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_GLOBAL_IO_HPP
|
||||
@@ -1,226 +0,0 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "logger-factory.hpp"
|
||||
|
||||
#include <ndn-cxx/util/logging.hpp>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
|
||||
#ifdef HAVE_CUSTOM_LOGGER
|
||||
#error "This file should not be compiled when custom logger is used"
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
// Let ndn-cxx logging facility initialize Boost.Log backend,
|
||||
// so that only one sink is attached to Boost.Log core.
|
||||
ndn::util::Logging::setDestination(std::clog);
|
||||
}
|
||||
|
||||
LoggerFactory::~LoggerFactory()
|
||||
{
|
||||
ndn::util::Logging::flush();
|
||||
}
|
||||
|
||||
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 = boost::to_upper_copy(level);
|
||||
|
||||
// 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) {
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(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()) {
|
||||
BOOST_THROW_EXCEPTION(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 (const auto& i : section) {
|
||||
LogLevel level = extractLevel(i.second, i.first);
|
||||
|
||||
if (i.first == "default_level") {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
std::unique_lock<std::mutex> lock(m_loggersGuard);
|
||||
LoggerMap::iterator loggerIt = m_loggers.find(i.first);
|
||||
if (loggerIt == m_loggers.end()) {
|
||||
lock.unlock();
|
||||
NFD_LOG_DEBUG("Failed to configure logging level for module \"" <<
|
||||
i.first << "\" (module not found)");
|
||||
}
|
||||
else if (!isDryRun) {
|
||||
loggerIt->second.setLogLevel(level);
|
||||
lock.unlock();
|
||||
NFD_LOG_DEBUG("Changing level for module " << i.first << " to " << level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LoggerFactory::setDefaultLevel(LogLevel level)
|
||||
{
|
||||
// std::cerr << "changing to default_level " << level << std::endl;
|
||||
std::lock_guard<std::mutex> lock(m_loggersGuard);
|
||||
|
||||
m_defaultLevel = level;
|
||||
for (auto&& logger : m_loggers) {
|
||||
// std::cerr << "changing " << i->first << " to default " << m_defaultLevel << std::endl;
|
||||
logger.second.setLogLevel(m_defaultLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LoggerFactory::flushBackend()
|
||||
{
|
||||
ndn::util::Logging::flush();
|
||||
}
|
||||
|
||||
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::lock_guard<std::mutex> lock(m_loggersGuard);
|
||||
|
||||
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::lock_guard<std::mutex> lock(m_loggersGuard);
|
||||
|
||||
std::list<std::string> modules;
|
||||
for (const auto& loggerName : m_loggers | boost::adaptors::map_keys) {
|
||||
modules.push_back(loggerName);
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,126 +0,0 @@
|
||||
/* -*- 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_LOGGER_FACTORY_HPP
|
||||
#define NFD_CORE_LOGGER_FACTORY_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#ifdef HAVE_CUSTOM_LOGGER
|
||||
#include "custom-logger-factory.hpp"
|
||||
#else
|
||||
|
||||
#include "config-file.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
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);
|
||||
|
||||
void
|
||||
flushBackend();
|
||||
|
||||
private:
|
||||
|
||||
LoggerFactory();
|
||||
|
||||
~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;
|
||||
mutable std::mutex m_loggersGuard;
|
||||
|
||||
LogLevel m_defaultLevel;
|
||||
};
|
||||
|
||||
inline LogLevel
|
||||
LoggerFactory::getDefaultLevel() const
|
||||
{
|
||||
return m_defaultLevel;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // HAVE_CUSTOM_LOGGER
|
||||
|
||||
#endif // NFD_CORE_LOGGER_FACTORY_HPP
|
||||
@@ -1,70 +0,0 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "logger.hpp"
|
||||
|
||||
#ifdef HAVE_CUSTOM_LOGGER
|
||||
#error "This file should not be compiled when custom logger is used"
|
||||
#endif
|
||||
|
||||
#include <ndn-cxx/util/time.hpp>
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
Logger::Logger(const std::string& name, LogLevel level)
|
||||
: m_moduleName(name)
|
||||
, m_enabledLogLevel(level)
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const LoggerTimestamp&)
|
||||
{
|
||||
using namespace ndn::time;
|
||||
|
||||
static const microseconds::rep ONE_SECOND = 1000000;
|
||||
microseconds::rep microsecondsSinceEpoch = duration_cast<microseconds>(
|
||||
system_clock::now().time_since_epoch()).count();
|
||||
|
||||
// 10 (whole seconds) + '.' + 6 (fraction) + '\0'
|
||||
char buffer[10 + 1 + 6 + 1];
|
||||
BOOST_ASSERT_MSG(microsecondsSinceEpoch / ONE_SECOND <= 9999999999L,
|
||||
"whole seconds cannot fit in 10 characters");
|
||||
|
||||
static_assert(std::is_same<microseconds::rep, int_least64_t>::value,
|
||||
"PRIdLEAST64 is incompatible with microseconds::rep");
|
||||
// - std::snprintf not found in some environments
|
||||
// http://redmine.named-data.net/issues/2299 for more information
|
||||
snprintf(buffer, sizeof(buffer), "%" PRIdLEAST64 ".%06" PRIdLEAST64,
|
||||
microsecondsSinceEpoch / ONE_SECOND,
|
||||
microsecondsSinceEpoch % ONE_SECOND);
|
||||
|
||||
return os << buffer;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
-171
@@ -1,171 +0,0 @@
|
||||
/* -*- 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_LOGGER_HPP
|
||||
#define NFD_CORE_LOGGER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#ifdef HAVE_CUSTOM_LOGGER
|
||||
#include "custom-logger.hpp"
|
||||
#else
|
||||
#include <boost/log/common.hpp>
|
||||
#include <boost/log/sources/logger.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** \brief indicates a log level
|
||||
* \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
|
||||
*/
|
||||
enum LogLevel {
|
||||
LOG_FATAL = -1, // fatal (will be logged unconditionally)
|
||||
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_ALL = 255 // all messages
|
||||
};
|
||||
|
||||
/** \brief provides logging for a module
|
||||
* \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
|
||||
* \note This type is copyable because logger can be declared as a field of
|
||||
* (usually template) classes, and shouldn't prevent those classes to be copyable.
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger(const std::string& name, LogLevel level);
|
||||
|
||||
bool
|
||||
isEnabled(LogLevel level) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public:
|
||||
boost::log::sources::logger boostLogger;
|
||||
|
||||
private:
|
||||
std::string m_moduleName;
|
||||
LogLevel m_enabledLogLevel;
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& output, const Logger& logger)
|
||||
{
|
||||
output << logger.getName();
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief a tag that writes a timestamp upon stream output
|
||||
*/
|
||||
struct LoggerTimestamp
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief write a timestamp to \p os
|
||||
* \note This function is thread-safe.
|
||||
*/
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const LoggerTimestamp&);
|
||||
|
||||
} // 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)
|
||||
|
||||
#if (BOOST_VERSION >= 105900) && (BOOST_VERSION < 106000)
|
||||
// workaround Boost bug 11549
|
||||
#define NFD_BOOST_LOG(x) BOOST_LOG(x) << ""
|
||||
#else
|
||||
#define NFD_BOOST_LOG(x) BOOST_LOG(x)
|
||||
#endif
|
||||
|
||||
#define NFD_LOG_LINE(msg, expression) \
|
||||
::nfd::LoggerTimestamp{} << " "#msg": " << "[" << g_logger << "] " << expression
|
||||
|
||||
#define NFD_LOG(level, msg, expression) \
|
||||
do { \
|
||||
if (g_logger.isEnabled(::nfd::LOG_##level)) { \
|
||||
NFD_BOOST_LOG(g_logger.boostLogger) << NFD_LOG_LINE(msg, expression); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define NFD_LOG_TRACE(expression) NFD_LOG(TRACE, TRACE, expression)
|
||||
#define NFD_LOG_DEBUG(expression) NFD_LOG(DEBUG, DEBUG, expression)
|
||||
#define NFD_LOG_INFO(expression) NFD_LOG(INFO, INFO, expression)
|
||||
#define NFD_LOG_WARN(expression) NFD_LOG(WARN, WARNING, expression)
|
||||
#define NFD_LOG_ERROR(expression) NFD_LOG(ERROR, ERROR, expression)
|
||||
#define NFD_LOG_FATAL(expression) NFD_LOG(FATAL, FATAL, expression)
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // HAVE_CUSTOM_LOGGER
|
||||
|
||||
#endif // NFD_CORE_LOGGER_HPP
|
||||
@@ -1,129 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* 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-predicate.hpp"
|
||||
|
||||
#include "config-file.hpp"
|
||||
#include "network-interface.hpp"
|
||||
#include "network.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NetworkInterfacePredicate::NetworkInterfacePredicate()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void
|
||||
NetworkInterfacePredicate::clear()
|
||||
{
|
||||
m_whitelist = std::set<std::string>{"*"};
|
||||
m_blacklist.clear();
|
||||
}
|
||||
|
||||
static void
|
||||
parseList(std::set<std::string>& set, const boost::property_tree::ptree& list, const std::string& section)
|
||||
{
|
||||
set.clear();
|
||||
|
||||
for (const auto& item : list) {
|
||||
if (item.first == "*") {
|
||||
// insert wildcard
|
||||
set.insert(item.first);
|
||||
}
|
||||
else if (item.first == "ifname") {
|
||||
// very basic sanity check for interface names
|
||||
auto name = item.second.get_value<std::string>();
|
||||
if (name.empty()) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Empty interface name in \"" + section + "\" section"));
|
||||
}
|
||||
set.insert(name);
|
||||
}
|
||||
else if (item.first == "ether") {
|
||||
// validate ethernet address
|
||||
auto addr = item.second.get_value<std::string>();
|
||||
if (ethernet::Address::fromString(addr).isNull()) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Malformed ether address \"" + addr +
|
||||
"\" in \"" + section + "\" section"));
|
||||
}
|
||||
set.insert(addr);
|
||||
}
|
||||
else if (item.first == "subnet") {
|
||||
// example subnet: 10.0.0.0/8
|
||||
auto cidr = item.second.get_value<std::string>();
|
||||
if (!Network::isValidCidr(cidr)) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Malformed subnet declaration \"" + cidr +
|
||||
"\" in \"" + section + "\" section"));
|
||||
}
|
||||
set.insert(cidr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkInterfacePredicate::parseWhitelist(const boost::property_tree::ptree& list)
|
||||
{
|
||||
parseList(m_whitelist, list, "whitelist");
|
||||
}
|
||||
|
||||
void
|
||||
NetworkInterfacePredicate::parseBlacklist(const boost::property_tree::ptree& list)
|
||||
{
|
||||
parseList(m_blacklist, list, "blacklist");
|
||||
}
|
||||
|
||||
static bool
|
||||
doesMatchRule(const NetworkInterfaceInfo& netif, const std::string& rule)
|
||||
{
|
||||
// if '/' is in rule, this is a subnet, check if IP in subnet
|
||||
if (rule.find('/') != std::string::npos) {
|
||||
Network n = boost::lexical_cast<Network>(rule);
|
||||
for (const auto& addr : netif.ipv4Addresses) {
|
||||
if (n.doesContain(addr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rule == "*" ||
|
||||
netif.name == rule ||
|
||||
netif.etherAddress.toString() == rule;
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkInterfacePredicate::operator()(const NetworkInterfaceInfo& netif) const
|
||||
{
|
||||
return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesMatchRule, netif, _1)) &&
|
||||
std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesMatchRule, netif, _1));
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkInterfacePredicate::operator==(const NetworkInterfacePredicate& other) const
|
||||
{
|
||||
return this->m_whitelist == other.m_whitelist &&
|
||||
this->m_blacklist == other.m_blacklist;
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,185 +0,0 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "network-interface.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
#include <ifaddrs.h> // for getifaddrs()
|
||||
|
||||
#include <arpa/inet.h> // for inet_ntop()
|
||||
#include <netinet/in.h> // for struct sockaddr_in{,6}
|
||||
|
||||
#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
|
||||
#include <net/if_types.h> // for IFT_* constants
|
||||
#endif
|
||||
|
||||
#endif // HAVE_IFADDRS_H
|
||||
|
||||
|
||||
NFD_LOG_INIT("NetworkInterfaceInfo");
|
||||
|
||||
namespace nfd {
|
||||
|
||||
static_assert(std::is_standard_layout<NetworkInterfaceInfo>::value,
|
||||
"NetworkInterfaceInfo must be a standard layout type");
|
||||
#ifdef HAVE_IS_DEFAULT_CONSTRUCTIBLE
|
||||
static_assert(std::is_default_constructible<NetworkInterfaceInfo>::value,
|
||||
"NetworkInterfaceInfo must provide a default constructor");
|
||||
#endif
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
static shared_ptr<std::vector<NetworkInterfaceInfo>> s_debugNetworkInterfaces = nullptr;
|
||||
|
||||
void
|
||||
setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces)
|
||||
{
|
||||
s_debugNetworkInterfaces = interfaces;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<NetworkInterfaceInfo>
|
||||
listNetworkInterfaces()
|
||||
{
|
||||
#ifdef WITH_TESTS
|
||||
if (s_debugNetworkInterfaces != nullptr) {
|
||||
return *s_debugNetworkInterfaces;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
using namespace boost::asio::ip;
|
||||
using std::strerror;
|
||||
|
||||
std::unordered_map<std::string, NetworkInterfaceInfo> ifmap;
|
||||
ifaddrs* ifa_list = nullptr;
|
||||
|
||||
if (::getifaddrs(&ifa_list) < 0)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getifaddrs() failed: ") +
|
||||
strerror(errno)));
|
||||
|
||||
for (ifaddrs* ifa = ifa_list; ifa != nullptr; ifa = ifa->ifa_next) {
|
||||
std::string ifname(ifa->ifa_name);
|
||||
NetworkInterfaceInfo& netif = ifmap[ifname];
|
||||
netif.name = ifa->ifa_name;
|
||||
netif.flags = ifa->ifa_flags;
|
||||
|
||||
if (ifa->ifa_addr == nullptr)
|
||||
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(address_v4::from_string(address));
|
||||
NFD_LOG_TRACE(ifname << ": added IPv4 address " << address);
|
||||
}
|
||||
else
|
||||
NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) failed: " << strerror(errno));
|
||||
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(address_v6::from_string(address));
|
||||
NFD_LOG_TRACE(ifname << ": added IPv6 address " << address);
|
||||
}
|
||||
else
|
||||
NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET6) failed: " << strerror(errno));
|
||||
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);
|
||||
NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
|
||||
}
|
||||
else if (sll->sll_hatype != ARPHRD_LOOPBACK) {
|
||||
NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled hardware type "
|
||||
<< sll->sll_hatype);
|
||||
}
|
||||
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;
|
||||
if (sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == ethernet::ADDR_LEN) {
|
||||
netif.etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
|
||||
NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
|
||||
}
|
||||
else if (sdl->sdl_type != IFT_LOOP) {
|
||||
NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled interface type "
|
||||
<< sdl->sdl_type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (netif.isBroadcastCapable() && ifa->ifa_broadaddr != nullptr) {
|
||||
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 = address_v4::from_string(address);
|
||||
NFD_LOG_TRACE(ifname << ": added IPv4 broadcast address " << address);
|
||||
}
|
||||
else
|
||||
NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) for broadaddr failed: " << strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
::freeifaddrs(ifa_list);
|
||||
|
||||
std::vector<NetworkInterfaceInfo> v;
|
||||
v.reserve(ifmap.size());
|
||||
for (auto&& element : ifmap) {
|
||||
v.push_back(element.second);
|
||||
}
|
||||
|
||||
return v;
|
||||
#else
|
||||
return {};
|
||||
#endif // HAVE_IFADDRS_H
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,107 +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_NETWORK_INTERFACE_HPP
|
||||
#define NFD_CORE_NETWORK_INTERFACE_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <ndn-cxx/util/ethernet.hpp>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
namespace ethernet = ndn::util::ethernet;
|
||||
|
||||
/** \brief contains information about a network interface
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/** \brief List configured network interfaces on the system and their info
|
||||
* \warning invalid IP addresses (e.g., 0.0.0.0) may be returned in some environments
|
||||
*/
|
||||
std::vector<NetworkInterfaceInfo>
|
||||
listNetworkInterfaces();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
/** \brief Set a list of network interfaces to be returned by subsequent listNetworkInterfaces call
|
||||
* \note To reset to normal behavior, use `setDebugNetworkInterfaces(nullptr);`
|
||||
*/
|
||||
void
|
||||
setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces);
|
||||
#endif
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_NETWORK_INTERFACE_HPP
|
||||
+46
-25
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* 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
|
||||
* 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,12 +21,13 @@
|
||||
*
|
||||
* 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 {
|
||||
|
||||
@@ -65,28 +66,13 @@ Network::isValidCidr(const std::string& cidr)
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::system::error_code invalidIp;
|
||||
boost::asio::ip::address_v4::from_string(cidr.substr(0, pos), invalidIp);
|
||||
if (invalidIp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto prefixLenStr = cidr.substr(pos + 1);
|
||||
if (!std::all_of(prefixLenStr.begin(), prefixLenStr.end(), ::isdigit)) {
|
||||
return false;
|
||||
}
|
||||
int prefixLen = -1;
|
||||
try {
|
||||
prefixLen = boost::lexical_cast<int>(prefixLenStr);
|
||||
boost::lexical_cast<Network>(cidr);
|
||||
return true;
|
||||
}
|
||||
catch (const boost::bad_lexical_cast&) {
|
||||
return false;
|
||||
}
|
||||
if (prefixLen < 0 || prefixLen > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
@@ -105,14 +91,44 @@ operator>>(std::istream& is, Network& network)
|
||||
|
||||
size_t position = networkStr.find('/');
|
||||
if (position == std::string::npos) {
|
||||
network.m_minAddress = ip::address::from_string(networkStr);
|
||||
network.m_maxAddress = ip::address::from_string(networkStr);
|
||||
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 {
|
||||
ip::address address = ip::address::from_string(networkStr.substr(0, position));
|
||||
size_t mask = boost::lexical_cast<size_t>(networkStr.substr(position+1));
|
||||
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;
|
||||
@@ -133,6 +149,11 @@ operator>>(std::istream& is, Network& network)
|
||||
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;
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "privilege-helper.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT("PrivilegeHelper");
|
||||
|
||||
#ifdef 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 // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
|
||||
void
|
||||
PrivilegeHelper::initialize(const std::string& userName, const std::string& groupName)
|
||||
{
|
||||
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
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;
|
||||
}
|
||||
#else
|
||||
if (!userName.empty() || !groupName.empty()) {
|
||||
throw Error("Dropping and raising privileges is not supported on this platform");
|
||||
}
|
||||
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::drop()
|
||||
{
|
||||
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
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());
|
||||
#else
|
||||
NFD_LOG_WARN("Dropping privileges is not supported on this platform");
|
||||
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::raise()
|
||||
{
|
||||
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
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());
|
||||
#else
|
||||
NFD_LOG_WARN("Elevating privileges is not supported on this platform");
|
||||
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::runElevated(function<void()> f)
|
||||
{
|
||||
raise();
|
||||
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
drop();
|
||||
throw;
|
||||
}
|
||||
drop();
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,99 +0,0 @@
|
||||
/* -*- 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_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);
|
||||
|
||||
/** \brief cancels an event automatically upon destruction
|
||||
*/
|
||||
class ScopedEventId : noncopyable
|
||||
{
|
||||
public:
|
||||
ScopedEventId();
|
||||
|
||||
/** \brief implicit constructor from EventId
|
||||
* \param event the event to be cancelled upon destruction
|
||||
*/
|
||||
ScopedEventId(const EventId& event);
|
||||
|
||||
/** \brief move constructor
|
||||
*/
|
||||
ScopedEventId(ScopedEventId&& other);
|
||||
|
||||
/** \brief assigns an event
|
||||
*
|
||||
* If a different event has been assigned to this instance previously,
|
||||
* that event will be cancelled immediately.
|
||||
*/
|
||||
ScopedEventId&
|
||||
operator=(const EventId& event);
|
||||
|
||||
/** \brief cancels the event
|
||||
*/
|
||||
~ScopedEventId();
|
||||
|
||||
/** \brief cancels the event manually
|
||||
*/
|
||||
void
|
||||
cancel();
|
||||
|
||||
/** \brief releases the event so that it won't be disconnected
|
||||
* when this ScopedEventId is destructed
|
||||
*/
|
||||
void
|
||||
release();
|
||||
|
||||
private:
|
||||
EventId m_event;
|
||||
};
|
||||
|
||||
} // namespace scheduler
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_SCHEDULER_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,24 +23,7 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rib/route.hpp"
|
||||
#include "core/version.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace rib {
|
||||
namespace tests {
|
||||
|
||||
inline Route
|
||||
createRoute(uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
|
||||
{
|
||||
Route temp;
|
||||
temp.faceId = faceId;
|
||||
temp.origin = origin;
|
||||
temp.cost = cost;
|
||||
temp.flags = flags;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
} // namespace tests
|
||||
} // namespace rib
|
||||
} // namespace nfd
|
||||
const char NFD_VERSION_STRING[] = "@VERSION_STRING@";
|
||||
const char NFD_VERSION_BUILD_STRING[] = "@VERSION_BUILD@";
|
||||
+35
-36
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,49 +26,48 @@
|
||||
#ifndef NFD_CORE_VERSION_HPP
|
||||
#define NFD_CORE_VERSION_HPP
|
||||
|
||||
namespace nfd {
|
||||
|
||||
/** NFD version follows Semantic Versioning 2.0.0 specification
|
||||
* http://semver.org/
|
||||
*/
|
||||
|
||||
// NFD version follows Semantic Versioning 2.0.0
|
||||
// https://semver.org/spec/v2.0.0.html
|
||||
//
|
||||
// To change version number, modify VERSION variable in top-level wscript.
|
||||
|
||||
/** \brief NFD version represented as an integer
|
||||
/** \brief NFD version represented as an integer.
|
||||
*
|
||||
* MAJOR*1000000 + MINOR*1000 + PATCH
|
||||
* Equivalent to: `#NFD_VERSION_MAJOR*1000000 + #NFD_VERSION_MINOR*1000 + #NFD_VERSION_PATCH`
|
||||
*/
|
||||
#define NFD_VERSION @VERSION@
|
||||
|
||||
/** \brief NFD version represented as a string
|
||||
*
|
||||
* MAJOR.MINOR.PATCH
|
||||
*/
|
||||
#define NFD_VERSION_STRING "@VERSION_STRING@"
|
||||
|
||||
/** \brief NFD version string, including git commit information, if NFD is build from
|
||||
* 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 built not from git, NFD_VERSION_BUILD_STRING equals NFD_VERSION_STRING
|
||||
*
|
||||
* MAJOR.MINOR.PATCH(-release-candidate-tag)(-(number-of-commits-since-tag)-COMMIT-HASH)
|
||||
*
|
||||
* Example, 0.1.0-rc1-1-g5c86570
|
||||
*/
|
||||
#define NFD_VERSION_BUILD_STRING "@VERSION_BUILD@"
|
||||
|
||||
/// MAJOR version
|
||||
/// The major version of NFD
|
||||
#define NFD_VERSION_MAJOR @VERSION_MAJOR@
|
||||
/// MINOR version
|
||||
/// The minor version of NFD
|
||||
#define NFD_VERSION_MINOR @VERSION_MINOR@
|
||||
/// PATCH version
|
||||
/// The patch version of NFD
|
||||
#define NFD_VERSION_PATCH @VERSION_PATCH@
|
||||
|
||||
} // namespace nfd
|
||||
/** \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
|
||||
* 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: 0.1.0-rc1-1-g5c86570
|
||||
*/
|
||||
extern const char NFD_VERSION_BUILD_STRING[];
|
||||
|
||||
#endif // NFD_CORE_VERSION_HPP
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,11 +23,12 @@
|
||||
* 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 {
|
||||
|
||||
@@ -42,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 + "\"";
|
||||
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
|
||||
NDN_THROW(Error("Error processing configuration file " + filename +
|
||||
": no module subscribed for section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -71,8 +69,8 @@ ConfigFile::parseYesNo(const ConfigSection& node, const std::string& key,
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(Error("Invalid value \"" + value + "\" for option \"" +
|
||||
key + "\" in \"" + sectionName + "\" section"));
|
||||
NDN_THROW(Error("Invalid value '" + value + "' for option '" +
|
||||
key + "' in section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -87,7 +85,7 @@ ConfigFile::parse(const std::string& filename, bool isDryRun)
|
||||
{
|
||||
std::ifstream inputFile(filename);
|
||||
if (!inputFile.good() || !inputFile.is_open()) {
|
||||
BOOST_THROW_EXCEPTION(Error("Failed to read configuration file: " + filename));
|
||||
NDN_THROW(Error("Failed to read configuration file " + filename));
|
||||
}
|
||||
parse(inputFile, isDryRun, filename);
|
||||
inputFile.close();
|
||||
@@ -107,11 +105,8 @@ ConfigFile::parse(std::istream& input, bool isDryRun, const std::string& filenam
|
||||
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();
|
||||
BOOST_THROW_EXCEPTION(Error(msg.str()));
|
||||
NDN_THROW(Error("Failed to parse configuration file " + filename +
|
||||
": " + error.message() + " on line " + to_string(error.line())));
|
||||
}
|
||||
|
||||
process(isDryRun, filename);
|
||||
@@ -129,13 +124,6 @@ ConfigFile::process(bool isDryRun, const std::string& filename) const
|
||||
{
|
||||
BOOST_ASSERT(!filename.empty());
|
||||
|
||||
if (m_global.begin() == m_global.end()) {
|
||||
std::string msg = "Error processing configuration file: ";
|
||||
msg += filename;
|
||||
msg += " no data";
|
||||
BOOST_THROW_EXCEPTION(Error(msg));
|
||||
}
|
||||
|
||||
for (const auto& i : m_global) {
|
||||
try {
|
||||
const ConfigSectionHandler& subscriber = m_subscriptions.at(i.first);
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,10 +23,10 @@
|
||||
* 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
|
||||
#ifndef NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
#define NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/common.hpp"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
@@ -34,24 +34,23 @@ namespace nfd {
|
||||
|
||||
/** \brief a config file section
|
||||
*/
|
||||
typedef boost::property_tree::ptree ConfigSection;
|
||||
using ConfigSection = boost::property_tree::ptree;
|
||||
|
||||
/** \brief an optional config file section
|
||||
*/
|
||||
typedef boost::optional<const ConfigSection&> OptionalConfigSection;
|
||||
using OptionalConfigSection = boost::optional<const ConfigSection&>;
|
||||
|
||||
/** \brief callback to process a config file section
|
||||
*/
|
||||
typedef function<void(const ConfigSection& section,
|
||||
bool isDryRun,
|
||||
const std::string& filename)> ConfigSectionHandler;
|
||||
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
|
||||
*/
|
||||
typedef function<void(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun)> UnknownConfigSectionHandler;
|
||||
using UnknownConfigSectionHandler = std::function<void(const std::string& filename,
|
||||
const std::string& sectionName,
|
||||
const ConfigSection& section,
|
||||
bool isDryRun)>;
|
||||
|
||||
/** \brief configuration file parsing utility
|
||||
*/
|
||||
@@ -61,11 +60,7 @@ public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
explicit
|
||||
@@ -113,11 +108,13 @@ public: // parse helpers
|
||||
static_assert(std::is_arithmetic<T>::value, "T must be an arithmetic type");
|
||||
|
||||
boost::optional<T> value = node.get_value_optional<T>();
|
||||
if (value) {
|
||||
// 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;
|
||||
}
|
||||
BOOST_THROW_EXCEPTION(Error("Invalid value \"" + node.get_value<std::string>() +
|
||||
"\" for option \"" + key + "\" in \"" + sectionName + "\" section"));
|
||||
NDN_THROW(Error("Invalid value '" + node.get_value<std::string>() +
|
||||
"' for option '" + key + "' in section '" + sectionName + "'"));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -182,4 +179,4 @@ private:
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_CONFIG_FILE_HPP
|
||||
#endif // NFD_DAEMON_COMMON_CONFIG_FILE_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,10 +23,10 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_CORE_COUNTER_HPP
|
||||
#define NFD_CORE_COUNTER_HPP
|
||||
#ifndef NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
#define NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
#include "core/common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
@@ -35,25 +35,14 @@ namespace nfd {
|
||||
* 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
|
||||
class SimpleCounter : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef uint64_t rep;
|
||||
|
||||
constexpr
|
||||
SimpleCounter()
|
||||
: m_value(0)
|
||||
{
|
||||
}
|
||||
|
||||
SimpleCounter(const SimpleCounter&) = delete;
|
||||
|
||||
SimpleCounter&
|
||||
operator=(const SimpleCounter&) = delete;
|
||||
|
||||
/** \brief observe the counter
|
||||
*/
|
||||
operator rep() const
|
||||
operator rep() const noexcept
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
@@ -61,13 +50,13 @@ public:
|
||||
/** \brief replace the counter value
|
||||
*/
|
||||
void
|
||||
set(rep value)
|
||||
set(rep value) noexcept
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
rep m_value;
|
||||
rep m_value = 0;
|
||||
};
|
||||
|
||||
/** \brief represents a counter of number of packets
|
||||
@@ -80,7 +69,7 @@ public:
|
||||
/** \brief increment the counter by one
|
||||
*/
|
||||
PacketCounter&
|
||||
operator++()
|
||||
operator++() noexcept
|
||||
{
|
||||
++m_value;
|
||||
return *this;
|
||||
@@ -98,7 +87,7 @@ public:
|
||||
/** \brief increase the counter
|
||||
*/
|
||||
ByteCounter&
|
||||
operator+=(rep n)
|
||||
operator+=(rep n) noexcept
|
||||
{
|
||||
m_value += n;
|
||||
return *this;
|
||||
@@ -107,35 +96,39 @@ public:
|
||||
|
||||
/** \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
|
||||
class SizeCounter : noncopyable
|
||||
{
|
||||
public:
|
||||
typedef size_t rep;
|
||||
typedef size_t Rep;
|
||||
|
||||
constexpr
|
||||
SizeCounter(const T& table)
|
||||
explicit constexpr
|
||||
SizeCounter(const T* table = nullptr) noexcept
|
||||
: m_table(table)
|
||||
{
|
||||
}
|
||||
|
||||
SizeCounter(const SizeCounter&) = delete;
|
||||
|
||||
SizeCounter&
|
||||
operator=(const SizeCounter&) = delete;
|
||||
void
|
||||
observe(const T* table) noexcept
|
||||
{
|
||||
m_table = table;
|
||||
}
|
||||
|
||||
/** \brief observe the counter
|
||||
*/
|
||||
operator rep() const
|
||||
operator Rep() const
|
||||
{
|
||||
return m_table.size();
|
||||
BOOST_ASSERT(m_table != nullptr);
|
||||
return m_table->size();
|
||||
}
|
||||
|
||||
private:
|
||||
const T& m_table;
|
||||
const T* m_table;
|
||||
};
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_CORE_COUNTER_HPP
|
||||
#endif // NFD_DAEMON_COMMON_COUNTER_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,85 +23,78 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "global-io.hpp"
|
||||
|
||||
#include <boost/thread/tss.hpp>
|
||||
#include "common/global.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace scheduler {
|
||||
|
||||
static boost::thread_specific_ptr<Scheduler> g_scheduler;
|
||||
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&
|
||||
getGlobalScheduler()
|
||||
getScheduler()
|
||||
{
|
||||
if (g_scheduler.get() == nullptr) {
|
||||
g_scheduler.reset(new Scheduler(getGlobalIoService()));
|
||||
if (g_scheduler == nullptr) {
|
||||
g_scheduler = make_unique<Scheduler>(getGlobalIoService());
|
||||
}
|
||||
|
||||
return *g_scheduler;
|
||||
}
|
||||
|
||||
EventId
|
||||
schedule(const time::nanoseconds& after, const Scheduler::Event& event)
|
||||
{
|
||||
return getGlobalScheduler().scheduleEvent(after, event);
|
||||
}
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void
|
||||
cancel(const EventId& eventId)
|
||||
{
|
||||
getGlobalScheduler().cancelEvent(eventId);
|
||||
}
|
||||
|
||||
void
|
||||
resetGlobalScheduler()
|
||||
resetGlobalIoService()
|
||||
{
|
||||
g_scheduler.reset();
|
||||
g_ioService.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::asio::io_service&
|
||||
getMainIoService()
|
||||
{
|
||||
BOOST_ASSERT(g_mainIoService != nullptr);
|
||||
return *g_mainIoService;
|
||||
}
|
||||
|
||||
ScopedEventId::ScopedEventId()
|
||||
boost::asio::io_service&
|
||||
getRibIoService()
|
||||
{
|
||||
}
|
||||
|
||||
ScopedEventId::ScopedEventId(const EventId& event)
|
||||
: m_event(event)
|
||||
{
|
||||
}
|
||||
|
||||
ScopedEventId::ScopedEventId(ScopedEventId&& other)
|
||||
: m_event(other.m_event)
|
||||
{
|
||||
other.release();
|
||||
}
|
||||
|
||||
ScopedEventId&
|
||||
ScopedEventId::operator=(const EventId& event)
|
||||
{
|
||||
if (m_event != event) {
|
||||
scheduler::cancel(m_event);
|
||||
m_event = event;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ScopedEventId::~ScopedEventId()
|
||||
{
|
||||
scheduler::cancel(m_event);
|
||||
BOOST_ASSERT(g_ribIoService != nullptr);
|
||||
return *g_ribIoService;
|
||||
}
|
||||
|
||||
void
|
||||
ScopedEventId::cancel()
|
||||
setMainIoService(boost::asio::io_service* mainIo)
|
||||
{
|
||||
scheduler::cancel(m_event);
|
||||
g_mainIoService = mainIo;
|
||||
}
|
||||
|
||||
void
|
||||
ScopedEventId::release()
|
||||
setRibIoService(boost::asio::io_service* ribIo)
|
||||
{
|
||||
m_event.reset();
|
||||
g_ribIoService = ribIo;
|
||||
}
|
||||
|
||||
void
|
||||
runOnMainIoService(const std::function<void()>& f)
|
||||
{
|
||||
getMainIoService().post(f);
|
||||
}
|
||||
|
||||
void
|
||||
runOnRibIoService(const std::function<void()>& f)
|
||||
{
|
||||
getRibIoService().post(f);
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,75 @@
|
||||
/* -*- 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
|
||||
*
|
||||
* 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 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-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 "common/privilege-helper.hpp"
|
||||
#include "common/logger.hpp"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
NFD_LOG_INIT(PrivilegeHelper);
|
||||
|
||||
#ifdef 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 // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
|
||||
void
|
||||
PrivilegeHelper::initialize(const std::string& userName, const std::string& groupName)
|
||||
{
|
||||
#ifdef 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 // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::drop()
|
||||
{
|
||||
#ifdef 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 // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
void
|
||||
PrivilegeHelper::raise()
|
||||
{
|
||||
#ifdef 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 // HAVE_PRIVILEGE_DROP_AND_ELEVATE
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,10 +23,10 @@
|
||||
* 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>
|
||||
|
||||
@@ -35,11 +35,10 @@ namespace nfd {
|
||||
class PrivilegeHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/** \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 BOOST_THROW_EXCEPTION should not be used.
|
||||
* \note This is not an std::exception and NDN_THROW should not be used.
|
||||
*/
|
||||
class Error
|
||||
{
|
||||
@@ -53,7 +52,7 @@ public:
|
||||
const char*
|
||||
what() const
|
||||
{
|
||||
return m_whatMessage.c_str();
|
||||
return m_whatMessage.data();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -66,11 +65,22 @@ public:
|
||||
static void
|
||||
drop();
|
||||
|
||||
template<class F>
|
||||
static void
|
||||
runElevated(function<void()> f);
|
||||
runElevated(F&& f)
|
||||
{
|
||||
raise();
|
||||
try {
|
||||
f();
|
||||
}
|
||||
catch (...) {
|
||||
drop();
|
||||
throw;
|
||||
}
|
||||
drop();
|
||||
}
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
|
||||
static void
|
||||
raise();
|
||||
|
||||
@@ -86,4 +96,4 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
|
||||
} // 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
|
||||
+12
-14
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "face.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
Channel::~Channel()
|
||||
{
|
||||
}
|
||||
Channel::~Channel() = default;
|
||||
|
||||
void
|
||||
Channel::setUri(const FaceUri& uri)
|
||||
@@ -38,16 +38,14 @@ Channel::setUri(const FaceUri& uri)
|
||||
}
|
||||
|
||||
void
|
||||
connectFaceClosedSignal(Face& face, const std::function<void()>& f)
|
||||
connectFaceClosedSignal(Face& face, std::function<void()> f)
|
||||
{
|
||||
using face::FaceState;
|
||||
|
||||
face.afterStateChange.connect(
|
||||
[f] (FaceState oldState, FaceState newState) {
|
||||
if (newState == FaceState::CLOSED) {
|
||||
f();
|
||||
}
|
||||
});
|
||||
face.afterStateChange.connect([f = std::move(f)] (auto, FaceState newState) {
|
||||
if (newState == FaceState::CLOSED) {
|
||||
f();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
+33
-27
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,37 +26,39 @@
|
||||
#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 {
|
||||
|
||||
/**
|
||||
* \brief Prototype for the callback that is invoked when the 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 invoked when the face
|
||||
* fails to be created
|
||||
*/
|
||||
typedef function<void(uint32_t status, const std::string& reason)> FaceCreationFailedCallback;
|
||||
|
||||
/** \brief represent a channel that communicates on a local endpoint
|
||||
/** \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 : noncopyable
|
||||
class Channel : public std::enable_shared_from_this<Channel>, noncopyable
|
||||
{
|
||||
public:
|
||||
virtual
|
||||
~Channel();
|
||||
|
||||
const FaceUri&
|
||||
getUri() const;
|
||||
getUri() const
|
||||
{
|
||||
return m_uri;
|
||||
}
|
||||
|
||||
/** \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
|
||||
@@ -66,22 +68,26 @@ private:
|
||||
FaceUri m_uri;
|
||||
};
|
||||
|
||||
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 invokes a callback when the face is closed
|
||||
/** \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 on the \p face,
|
||||
* 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, const std::function<void()>& f);
|
||||
connectFaceClosedSignal(Face& face, std::function<void()> f);
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_CHANNEL_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -27,7 +27,8 @@
|
||||
#define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
|
||||
|
||||
#include "transport.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "socket-utils.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -54,6 +55,9 @@ public:
|
||||
explicit
|
||||
DatagramTransport(typename protocol::socket&& socket);
|
||||
|
||||
ssize_t
|
||||
getSendQueueLength() override;
|
||||
|
||||
/** \brief Receive datagram, translate buffer into packet, deliver to parent class.
|
||||
*/
|
||||
void
|
||||
@@ -61,28 +65,26 @@ public:
|
||||
const boost::system::error_code& error);
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
void
|
||||
doClose() override;
|
||||
|
||||
virtual void
|
||||
doSend(Transport::Packet&& packet) override;
|
||||
void
|
||||
doSend(const Block& packet) override;
|
||||
|
||||
void
|
||||
handleSend(const boost::system::error_code& error,
|
||||
size_t nBytesSent, const Block& payload);
|
||||
handleSend(const boost::system::error_code& error, size_t nBytesSent);
|
||||
|
||||
void
|
||||
handleReceive(const boost::system::error_code& error,
|
||||
size_t nBytesReceived);
|
||||
handleReceive(const boost::system::error_code& error, size_t nBytesReceived);
|
||||
|
||||
void
|
||||
processErrorCode(const boost::system::error_code& error);
|
||||
|
||||
bool
|
||||
hasBeenUsedRecently() const;
|
||||
hasRecentlyReceived() const;
|
||||
|
||||
void
|
||||
resetRecentUsage();
|
||||
resetRecentlyReceived();
|
||||
|
||||
static EndpointId
|
||||
makeEndpointId(const typename protocol::endpoint& ep);
|
||||
@@ -91,23 +93,45 @@ protected:
|
||||
typename protocol::socket m_socket;
|
||||
typename protocol::endpoint m_sender;
|
||||
|
||||
NFD_LOG_INCLASS_DECLARE();
|
||||
NFD_LOG_MEMBER_DECL();
|
||||
|
||||
private:
|
||||
std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
|
||||
bool m_hasBeenUsedRecently;
|
||||
bool m_hasRecentlyReceived;
|
||||
};
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
DatagramTransport<T, U>::DatagramTransport(typename DatagramTransport::protocol::socket&& socket)
|
||||
: m_socket(std::move(socket))
|
||||
, m_hasBeenUsedRecently(false)
|
||||
, 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,
|
||||
bind(&DatagramTransport<T, U>::handleReceive, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
[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>
|
||||
@@ -133,15 +157,15 @@ DatagramTransport<T, U>::doClose()
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::doSend(Transport::Packet&& packet)
|
||||
DatagramTransport<T, U>::doSend(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
m_socket.async_send(boost::asio::buffer(packet.packet),
|
||||
bind(&DatagramTransport<T, U>::handleSend, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred,
|
||||
packet.packet));
|
||||
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>
|
||||
@@ -152,13 +176,13 @@ DatagramTransport<T, U>::receiveDatagram(const uint8_t* buffer, size_t nBytesRec
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
|
||||
NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes from " << m_sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet");
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << m_sender);
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
@@ -167,32 +191,27 @@ DatagramTransport<T, U>::receiveDatagram(const uint8_t* buffer, size_t nBytesRec
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
m_hasBeenUsedRecently = true;
|
||||
m_hasRecentlyReceived = true;
|
||||
|
||||
Transport::Packet tp(std::move(element));
|
||||
tp.remoteEndpoint = makeEndpointId(m_sender);
|
||||
this->receive(std::move(tp));
|
||||
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)
|
||||
DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error, size_t nBytesReceived)
|
||||
{
|
||||
receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
|
||||
|
||||
if (m_socket.is_open())
|
||||
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
|
||||
bind(&DatagramTransport<T, U>::handleReceive, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
[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, const Block& payload)
|
||||
// 'payload' is unused; it's needed to retain the underlying Buffer
|
||||
DatagramTransport<T, U>::handleSend(const boost::system::error_code& error, size_t nBytesSent)
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
@@ -209,39 +228,38 @@ DatagramTransport<T, U>::processErrorCode(const boost::system::error_code& error
|
||||
if (getState() == TransportState::CLOSING ||
|
||||
getState() == TransportState::FAILED ||
|
||||
getState() == TransportState::CLOSED ||
|
||||
error == boost::asio::error::operation_aborted)
|
||||
error == boost::asio::error::operation_aborted) {
|
||||
// transport is shutting down, ignore any errors
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPersistency() == ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERMANENT) {
|
||||
if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
|
||||
NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << error.message());
|
||||
return;
|
||||
}
|
||||
|
||||
if (error != boost::asio::error::eof)
|
||||
NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
|
||||
|
||||
NFD_LOG_FACE_ERROR("Send or receive operation failed: " << error.message());
|
||||
this->setState(TransportState::FAILED);
|
||||
doClose();
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
DatagramTransport<T, U>::hasBeenUsedRecently() const
|
||||
bool
|
||||
DatagramTransport<T, U>::hasRecentlyReceived() const
|
||||
{
|
||||
return m_hasBeenUsedRecently;
|
||||
return m_hasRecentlyReceived;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline void
|
||||
DatagramTransport<T, U>::resetRecentUsage()
|
||||
void
|
||||
DatagramTransport<T, U>::resetRecentlyReceived()
|
||||
{
|
||||
m_hasBeenUsedRecently = false;
|
||||
m_hasRecentlyReceived = false;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline Transport::EndpointId
|
||||
DatagramTransport<T, U>::makeEndpointId(const typename protocol::endpoint& ep)
|
||||
EndpointId
|
||||
DatagramTransport<T, U>::makeEndpointId(const typename protocol::endpoint&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
/* -*- 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 "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;
|
||||
}
|
||||
|
||||
const uint8_t* pkt;
|
||||
size_t len;
|
||||
std::string err;
|
||||
std::tie(pkt, len, err) = m_pcap.readNextPacket();
|
||||
|
||||
if (pkt == nullptr) {
|
||||
NFD_LOG_CHAN_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_localEndpoint->getEthernetAddress(),
|
||||
m_localEndpoint->getEthernetAddress());
|
||||
if (eh == nullptr) {
|
||||
NFD_LOG_CHAN_DEBUG(err);
|
||||
}
|
||||
else {
|
||||
ethernet::Address sender(eh->ether_shost);
|
||||
pkt += ethernet::HDR_LEN;
|
||||
len -= ethernet::HDR_LEN;
|
||||
processIncomingPacket(pkt, len, 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(const uint8_t* packet, size_t length,
|
||||
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, length, 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,142 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#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 : 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 override
|
||||
{
|
||||
return m_isListening;
|
||||
}
|
||||
|
||||
size_t
|
||||
size() const override
|
||||
{
|
||||
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(const uint8_t* packet, size_t length,
|
||||
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,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,34 +24,45 @@
|
||||
*/
|
||||
|
||||
#include "ethernet-factory.hpp"
|
||||
#include "ethernet-transport.hpp"
|
||||
#include "generic-link-service.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "multicast-ethernet-transport.hpp"
|
||||
|
||||
#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);
|
||||
|
||||
const std::string&
|
||||
EthernetFactory::getId()
|
||||
EthernetFactory::getId() noexcept
|
||||
{
|
||||
static std::string id("ether");
|
||||
return id;
|
||||
}
|
||||
|
||||
EthernetFactory::EthernetFactory(const CtorParams& params)
|
||||
: ProtocolFactory(params)
|
||||
{
|
||||
m_netifAddConn = netmon->onInterfaceAdded.connect([this] (const auto& netif) {
|
||||
this->applyUnicastConfigToNetif(netif);
|
||||
this->applyMcastConfigToNetif(*netif);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
EthernetFactory::processConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context)
|
||||
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
|
||||
// {
|
||||
// *
|
||||
@@ -61,31 +72,42 @@ EthernetFactory::processConfig(OptionalConfigSection configSection,
|
||||
// }
|
||||
// }
|
||||
|
||||
UnicastConfig unicastConfig;
|
||||
MulticastConfig mcastConfig;
|
||||
|
||||
if (configSection) {
|
||||
// face_system.ether.mcast defaults to 'yes' but only if face_system.ether section is present
|
||||
mcastConfig.isEnabled = true;
|
||||
// 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 == "mcast") {
|
||||
mcastConfig.isEnabled = ConfigFile::parseYesNo(pair, "ether");
|
||||
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()) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.ether.mcast_group: '" +
|
||||
valueStr + "' cannot be parsed as an Ethernet address"));
|
||||
NDN_THROW(ConfigFile::Error("face_system.ether.mcast_group: '" +
|
||||
valueStr + "' cannot be parsed as an Ethernet address"));
|
||||
}
|
||||
else if (!mcastConfig.group.isMulticast()) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.ether.mcast_group: '" +
|
||||
valueStr + "' is not a multicast address"));
|
||||
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);
|
||||
}
|
||||
@@ -93,119 +115,263 @@ EthernetFactory::processConfig(OptionalConfigSection configSection,
|
||||
mcastConfig.netifPredicate.parseBlacklist(value);
|
||||
}
|
||||
else {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option face_system.ether." + key));
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option face_system.ether." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!context.isDryRun) {
|
||||
if (m_mcastConfig.isEnabled != mcastConfig.isEnabled) {
|
||||
if (mcastConfig.isEnabled) {
|
||||
NFD_LOG_INFO("enabling multicast on " << mcastConfig.group);
|
||||
}
|
||||
else {
|
||||
NFD_LOG_INFO("disabling multicast");
|
||||
}
|
||||
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");
|
||||
}
|
||||
else if (m_mcastConfig.group != mcastConfig.group) {
|
||||
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);
|
||||
}
|
||||
else if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
|
||||
if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
|
||||
NFD_LOG_INFO("changing whitelist/blacklist");
|
||||
}
|
||||
else {
|
||||
// There's no configuration change, but we still need to re-apply configuration because
|
||||
// netifs may have changed.
|
||||
}
|
||||
|
||||
m_mcastConfig = mcastConfig;
|
||||
this->applyConfig(context);
|
||||
}
|
||||
|
||||
// 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::createFace(const FaceUri& uri,
|
||||
ndn::nfd::FacePersistency persistency,
|
||||
bool wantLocalFieldsEnabled,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure)
|
||||
EthernetFactory::doCreateFace(const CreateFaceRequest& req,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure)
|
||||
{
|
||||
onFailure(406, "Unsupported protocol");
|
||||
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::getChannels() const
|
||||
EthernetFactory::doGetChannels() const
|
||||
{
|
||||
return {};
|
||||
return getChannelsFromMap(m_channels);
|
||||
}
|
||||
|
||||
shared_ptr<Face>
|
||||
EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& netif,
|
||||
EthernetFactory::createMulticastFace(const ndn::net::NetworkInterface& netif,
|
||||
const ethernet::Address& address)
|
||||
{
|
||||
BOOST_ASSERT(address.isMulticast());
|
||||
|
||||
auto key = std::make_pair(netif.name, address);
|
||||
auto key = std::make_pair(netif.getName(), address);
|
||||
auto found = m_mcastFaces.find(key);
|
||||
if (found != m_mcastFaces.end()) {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
face::GenericLinkService::Options opts;
|
||||
GenericLinkService::Options opts;
|
||||
opts.allowFragmentation = true;
|
||||
opts.allowReassembly = true;
|
||||
|
||||
auto linkService = make_unique<face::GenericLinkService>(opts);
|
||||
auto transport = make_unique<face::EthernetTransport>(netif, address);
|
||||
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;
|
||||
}
|
||||
|
||||
shared_ptr<EthernetChannel>
|
||||
EthernetFactory::applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif)
|
||||
{
|
||||
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<Face>
|
||||
EthernetFactory::applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif)
|
||||
{
|
||||
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::applyConfig(const FaceSystem::ConfigContext& context)
|
||||
EthernetFactory::applyConfig(const FaceSystem::ConfigContext&)
|
||||
{
|
||||
// collect old faces
|
||||
if (m_unicastConfig.isEnabled) {
|
||||
providedSchemes.insert("ether");
|
||||
}
|
||||
else {
|
||||
providedSchemes.erase("ether");
|
||||
}
|
||||
|
||||
// collect old multicast faces
|
||||
std::set<shared_ptr<Face>> oldFaces;
|
||||
boost::copy(m_mcastFaces | boost::adaptors::map_values,
|
||||
std::inserter(oldFaces, oldFaces.end()));
|
||||
boost::copy(m_mcastFaces | boost::adaptors::map_values, std::inserter(oldFaces, oldFaces.end()));
|
||||
|
||||
if (m_mcastConfig.isEnabled) {
|
||||
// determine interfaces on which faces should be created or retained
|
||||
auto capableNetifs = context.listNetifs() |
|
||||
boost::adaptors::filtered([this] (const NetworkInterfaceInfo& netif) {
|
||||
return netif.isUp() && netif.isMulticastCapable() &&
|
||||
m_mcastConfig.netifPredicate(netif);
|
||||
});
|
||||
// create channels and multicast faces if requested by config
|
||||
for (const auto& netif : netmon->listNetworkInterfaces()) {
|
||||
this->applyUnicastConfigToNetif(netif);
|
||||
|
||||
// create faces
|
||||
for (const auto& netif : capableNetifs) {
|
||||
shared_ptr<Face> face;
|
||||
try {
|
||||
face = this->createMulticastFace(netif, m_mcastConfig.group);
|
||||
}
|
||||
catch (const EthernetTransport::Error& e) {
|
||||
NFD_LOG_ERROR("Cannot create Ethernet multicast face on " << netif.name << ": " <<
|
||||
e.what() << ", continuing");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (face->getId() == face::INVALID_FACEID) {
|
||||
// new face: register with forwarding
|
||||
context.addFace(face);
|
||||
}
|
||||
else {
|
||||
// existing face: don't destroy
|
||||
oldFaces.erase(face);
|
||||
}
|
||||
auto face = this->applyMcastConfigToNetif(*netif);
|
||||
if (face != nullptr) {
|
||||
// don't destroy face
|
||||
oldFaces.erase(face);
|
||||
}
|
||||
}
|
||||
|
||||
// destroy old faces that are not needed in new configuration
|
||||
// destroy old multicast faces that are not needed in new configuration
|
||||
for (const auto& face : oldFaces) {
|
||||
face->close();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2018, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -27,66 +27,105 @@
|
||||
#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
|
||||
|
||||
#include "protocol-factory.hpp"
|
||||
#include "ethernet-channel.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \brief protocol factory for Ethernet
|
||||
*
|
||||
* Currently, only Ethernet multicast is supported.
|
||||
/** \brief Protocol factory for Ethernet
|
||||
*/
|
||||
class EthernetFactory : public ProtocolFactory
|
||||
{
|
||||
public:
|
||||
static const std::string&
|
||||
getId();
|
||||
getId() noexcept;
|
||||
|
||||
explicit
|
||||
EthernetFactory(const CtorParams& params);
|
||||
|
||||
/**
|
||||
* \brief Create Ethernet-based channel on the specified network interface
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \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<EthernetChannel>
|
||||
createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
|
||||
time::nanoseconds idleTimeout);
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
shared_ptr<Face>
|
||||
createMulticastFace(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& group);
|
||||
|
||||
private:
|
||||
/** \brief process face_system.ether config section
|
||||
*/
|
||||
void
|
||||
processConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context) override;
|
||||
doProcessConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context) override;
|
||||
|
||||
/** \brief unicast face creation is not supported and will always fail
|
||||
*/
|
||||
void
|
||||
createFace(const FaceUri& uri,
|
||||
ndn::nfd::FacePersistency persistency,
|
||||
bool wantLocalFieldsEnabled,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure) override;
|
||||
doCreateFace(const CreateFaceRequest& req,
|
||||
const FaceCreatedCallback& onCreated,
|
||||
const FaceCreationFailedCallback& onFailure) override;
|
||||
|
||||
/** \return empty container, because Ethernet unicast is not supported
|
||||
*/
|
||||
std::vector<shared_ptr<const Channel>>
|
||||
getChannels() const override;
|
||||
doGetChannels() const override;
|
||||
|
||||
private:
|
||||
/** \brief Create a face to communicate on the given Ethernet multicast group
|
||||
* \param netif local network interface
|
||||
* \param group multicast group address
|
||||
* \note Calling this method again with same arguments returns the existing face on the given
|
||||
* interface and multicast group rather than creating a new one.
|
||||
* \throw EthernetTransport::Error transport creation fails
|
||||
/** \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<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>
|
||||
createMulticastFace(const NetworkInterfaceInfo& netif, const ethernet::Address& group);
|
||||
applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif);
|
||||
|
||||
void
|
||||
applyConfig(const FaceSystem::ConfigContext& context);
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* -*- 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 "ethernet-protocol.hpp"
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
std::pair<const ether_header*, std::string>
|
||||
checkFrameHeader(const uint8_t* packet, size_t length,
|
||||
const Address& localAddr, const Address& destAddr)
|
||||
{
|
||||
if (length < HDR_LEN + MIN_DATA_LEN)
|
||||
return {nullptr, "Received frame too short: " + to_string(length) + " bytes"};
|
||||
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
|
||||
|
||||
// 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,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,24 +23,23 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief declares ContentStore internal types
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_TABLE_CS_INTERNAL_HPP
|
||||
#define NFD_DAEMON_TABLE_CS_INTERNAL_HPP
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
#include <ndn-cxx/net/ethernet.hpp>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
namespace nfd {
|
||||
namespace cs {
|
||||
namespace ethernet {
|
||||
|
||||
class EntryImpl;
|
||||
using namespace ndn::ethernet;
|
||||
|
||||
typedef std::set<EntryImpl> Table;
|
||||
typedef Table::const_iterator iterator;
|
||||
std::pair<const ether_header*, std::string>
|
||||
checkFrameHeader(const uint8_t* packet, size_t length,
|
||||
const Address& localAddr, const Address& destAddr);
|
||||
|
||||
} // namespace cs
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_TABLE_CS_INTERNAL_HPP
|
||||
#endif // NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
+120
-288
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,110 +24,58 @@
|
||||
*/
|
||||
|
||||
#include "ethernet-transport.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
#include <cerrno> // for errno
|
||||
#include <cstring> // for memcpy(), strerror(), 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()
|
||||
#include <cstring> // for memcpy()
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <netpacket/packet.h> // for struct packet_mreq
|
||||
#include <sys/socket.h> // for setsockopt()
|
||||
#endif
|
||||
|
||||
#ifdef SIOCADDMULTI
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <net/if_dl.h> // for struct sockaddr_dl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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
|
||||
#include <boost/endian/conversion.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("EthernetTransport");
|
||||
NFD_LOG_INIT(EthernetTransport);
|
||||
|
||||
EthernetTransport::EthernetTransport(const NetworkInterfaceInfo& interface,
|
||||
const ethernet::Address& mcastAddress)
|
||||
: m_pcap(nullptr, pcap_close)
|
||||
, m_socket(getGlobalIoService())
|
||||
, m_srcAddress(interface.etherAddress)
|
||||
, m_destAddress(mcastAddress)
|
||||
, m_interfaceName(interface.name)
|
||||
#if defined(__linux__)
|
||||
, m_interfaceIndex(interface.index)
|
||||
#endif
|
||||
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
|
||||
{
|
||||
this->setLocalUri(FaceUri::fromDev(interface.name));
|
||||
this->setRemoteUri(FaceUri(mcastAddress));
|
||||
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
|
||||
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
|
||||
this->setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
|
||||
|
||||
NFD_LOG_FACE_INFO("Creating transport");
|
||||
|
||||
pcapInit();
|
||||
|
||||
int fd = pcap_get_selectable_fd(m_pcap.get());
|
||||
if (fd < 0)
|
||||
BOOST_THROW_EXCEPTION(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));
|
||||
|
||||
// do this after assigning m_socket because getInterfaceMtu uses it
|
||||
this->setMtu(getInterfaceMtu());
|
||||
|
||||
char filter[110];
|
||||
// note #1: we cannot use std::snprintf because it's not available
|
||||
// on some platforms (see #2299)
|
||||
// note #2: "not vlan" must appear last in the filter expression, or the
|
||||
// rest of the filter won't work as intended (see pcap-filter(7))
|
||||
snprintf(filter, sizeof(filter),
|
||||
"(ether proto 0x%x) && (ether dst %s) && (not ether src %s) && (not vlan)",
|
||||
ethernet::ETHERTYPE_NDN,
|
||||
m_destAddress.toString().c_str(),
|
||||
m_srcAddress.toString().c_str());
|
||||
setPacketFilter(filter);
|
||||
|
||||
if (!m_destAddress.isBroadcast() && !joinMulticastGroup()) {
|
||||
NFD_LOG_FACE_WARN("Falling back to promiscuous mode");
|
||||
pcap_set_promisc(m_pcap.get(), 1);
|
||||
try {
|
||||
m_pcap.activate(DLT_EN10MB);
|
||||
m_socket.assign(m_pcap.getFd());
|
||||
}
|
||||
catch (const PcapHelper::Error& e) {
|
||||
NDN_THROW_NESTED(Error(e.what()));
|
||||
}
|
||||
|
||||
m_socket.async_read_some(boost::asio::null_buffers(),
|
||||
bind(&EthernetTransport::handleRead, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
// 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::doSend(Transport::Packet&& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
sendPacket(packet.packet);
|
||||
}
|
||||
|
||||
void EthernetTransport::doClose()
|
||||
void
|
||||
EthernetTransport::doClose()
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
@@ -138,7 +86,7 @@ void EthernetTransport::doClose()
|
||||
m_socket.cancel(error);
|
||||
m_socket.close(error);
|
||||
}
|
||||
m_pcap.reset();
|
||||
m_pcap.close();
|
||||
|
||||
// Ensure that the Transport stays alive at least
|
||||
// until all pending handlers are dispatched
|
||||
@@ -148,116 +96,30 @@ void EthernetTransport::doClose()
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::pcapInit()
|
||||
EthernetTransport::handleNetifStateChange(ndn::net::InterfaceState netifState)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE] = {};
|
||||
m_pcap.reset(pcap_create(m_interfaceName.c_str(), errbuf));
|
||||
if (!m_pcap)
|
||||
BOOST_THROW_EXCEPTION(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.get(), 1);
|
||||
#endif
|
||||
|
||||
if (pcap_activate(m_pcap.get()) < 0)
|
||||
BOOST_THROW_EXCEPTION(Error("pcap_activate failed"));
|
||||
|
||||
if (pcap_set_datalink(m_pcap.get(), DLT_EN10MB) < 0)
|
||||
BOOST_THROW_EXCEPTION(Error("pcap_set_datalink: " + std::string(pcap_geterr(m_pcap.get()))));
|
||||
|
||||
if (pcap_setdirection(m_pcap.get(), PCAP_D_IN) < 0)
|
||||
// no need to throw on failure, BPF will filter unwanted packets anyway
|
||||
NFD_LOG_FACE_WARN("pcap_setdirection failed: " << pcap_geterr(m_pcap.get()));
|
||||
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::setPacketFilter(const char* filterString)
|
||||
EthernetTransport::doSend(const Block& packet)
|
||||
{
|
||||
bpf_program filter;
|
||||
if (pcap_compile(m_pcap.get(), &filter, filterString, 1, PCAP_NETMASK_UNKNOWN) < 0)
|
||||
BOOST_THROW_EXCEPTION(Error("pcap_compile: " + std::string(pcap_geterr(m_pcap.get()))));
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
int ret = pcap_setfilter(m_pcap.get(), &filter);
|
||||
pcap_freecode(&filter);
|
||||
if (ret < 0)
|
||||
BOOST_THROW_EXCEPTION(Error("pcap_setfilter: " + std::string(pcap_geterr(m_pcap.get()))));
|
||||
}
|
||||
|
||||
bool
|
||||
EthernetTransport::joinMulticastGroup()
|
||||
{
|
||||
#if defined(__linux__)
|
||||
packet_mreq mr{};
|
||||
mr.mr_ifindex = m_interfaceIndex;
|
||||
mr.mr_type = PACKET_MR_MULTICAST;
|
||||
mr.mr_alen = m_destAddress.size();
|
||||
std::memcpy(mr.mr_address, m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
if (::setsockopt(m_socket.native_handle(), SOL_PACKET,
|
||||
PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == 0)
|
||||
return true; // success
|
||||
|
||||
NFD_LOG_FACE_WARN("setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
|
||||
#endif
|
||||
|
||||
#if defined(SIOCADDMULTI)
|
||||
ifreq ifr{};
|
||||
std::strncpy(ifr.ifr_name, m_interfaceName.c_str(), sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
// see bug #2327
|
||||
using boost::asio::ip::udp;
|
||||
udp::socket sock(getGlobalIoService(), udp::v4());
|
||||
int fd = sock.native_handle();
|
||||
|
||||
/*
|
||||
* Differences between Linux and the BSDs (including OS X):
|
||||
* o BSD does not have ifr_hwaddr; use ifr_addr instead.
|
||||
* o While OS X seems to accept both AF_LINK and AF_UNSPEC as the address
|
||||
* family, FreeBSD explicitly requires AF_LINK, so we have to use AF_LINK
|
||||
* and sockaddr_dl instead of the generic sockaddr structure.
|
||||
* o BSD's sockaddr (and sockaddr_dl in particular) contains an additional
|
||||
* field, sa_len (sdl_len), which must be set to the total length of the
|
||||
* structure, including the length field itself.
|
||||
* o We do not specify the interface name, thus sdl_nlen is left at 0 and
|
||||
* LLADDR is effectively the same as sdl_data.
|
||||
*/
|
||||
sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(&ifr.ifr_addr);
|
||||
sdl->sdl_len = sizeof(ifr.ifr_addr);
|
||||
sdl->sdl_family = AF_LINK;
|
||||
sdl->sdl_alen = m_destAddress.size();
|
||||
std::memcpy(LLADDR(sdl), m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
static_assert(sizeof(ifr.ifr_addr) >= offsetof(sockaddr_dl, sdl_data) + ethernet::ADDR_LEN,
|
||||
"ifr_addr in struct ifreq is too small on this platform");
|
||||
#else
|
||||
int fd = m_socket.native_handle();
|
||||
|
||||
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
|
||||
std::memcpy(ifr.ifr_hwaddr.sa_data, m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
static_assert(sizeof(ifr.ifr_hwaddr.sa_data) >= ethernet::ADDR_LEN,
|
||||
"ifr_hwaddr in struct ifreq is too small on this platform");
|
||||
#endif
|
||||
|
||||
if (::ioctl(fd, SIOCADDMULTI, &ifr) == 0)
|
||||
return true; // success
|
||||
|
||||
NFD_LOG_FACE_WARN("ioctl(SIOCADDMULTI) failed: " << std::strerror(errno));
|
||||
#endif
|
||||
|
||||
return false;
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::sendPacket(const ndn::Block& block)
|
||||
{
|
||||
/// \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
|
||||
@@ -267,144 +129,114 @@ EthernetTransport::sendPacket(const ndn::Block& block)
|
||||
}
|
||||
|
||||
// construct and prepend the ethernet header
|
||||
static uint16_t ethertype = htons(ethernet::ETHERTYPE_NDN);
|
||||
uint16_t ethertype = boost::endian::native_to_big(ethernet::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.get(), buffer.buf(), buffer.size());
|
||||
// send the frame
|
||||
int sent = pcap_inject(m_pcap, buffer.buf(), buffer.size());
|
||||
if (sent < 0)
|
||||
NFD_LOG_FACE_ERROR("pcap_inject failed: " << pcap_geterr(m_pcap.get()));
|
||||
handleError("Send operation failed: " + m_pcap.getLastError());
|
||||
else if (static_cast<size_t>(sent) < buffer.size())
|
||||
NFD_LOG_FACE_ERROR("Failed to send the full frame: bufsize=" << buffer.size() << " sent=" << sent);
|
||||
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::handleRead(const boost::system::error_code& error, size_t)
|
||||
EthernetTransport::asyncRead()
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
pcap_pkthdr* header;
|
||||
const uint8_t* packet;
|
||||
|
||||
// read the pcap header and packet data
|
||||
int ret = pcap_next_ex(m_pcap.get(), &header, &packet);
|
||||
if (ret < 0)
|
||||
NFD_LOG_FACE_ERROR("pcap_next_ex failed: " << pcap_geterr(m_pcap.get()));
|
||||
else if (ret == 0)
|
||||
NFD_LOG_FACE_WARN("Read timeout");
|
||||
else
|
||||
processIncomingPacket(header, packet);
|
||||
|
||||
#ifdef _DEBUG
|
||||
pcap_stat ps{};
|
||||
ret = pcap_stats(m_pcap.get(), &ps);
|
||||
if (ret < 0) {
|
||||
NFD_LOG_FACE_DEBUG("pcap_stats failed: " << pcap_geterr(m_pcap.get()));
|
||||
}
|
||||
else if (ret == 0) {
|
||||
if (ps.ps_drop - m_nDropped > 0)
|
||||
NFD_LOG_FACE_DEBUG("Detected " << ps.ps_drop - m_nDropped << " dropped packet(s)");
|
||||
m_nDropped = ps.ps_drop;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_socket.async_read_some(boost::asio::null_buffers(),
|
||||
bind(&EthernetTransport::handleRead, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
[this] (const auto& e, auto) { this->handleRead(e); });
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet)
|
||||
EthernetTransport::handleRead(const boost::system::error_code& error)
|
||||
{
|
||||
size_t length = header->caplen;
|
||||
if (length < ethernet::HDR_LEN + ethernet::MIN_DATA_LEN) {
|
||||
NFD_LOG_FACE_WARN("Received frame is too short (" << length << " bytes)");
|
||||
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;
|
||||
}
|
||||
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
|
||||
const ethernet::Address sourceAddress(eh->ether_shost);
|
||||
const uint8_t* pkt;
|
||||
size_t len;
|
||||
std::string err;
|
||||
std::tie(pkt, len, err) = m_pcap.readNextPacket();
|
||||
|
||||
// in some cases VLAN-tagged frames may survive the BPF filter,
|
||||
// make sure we do not process those frames (see #3348)
|
||||
if (ntohs(eh->ether_type) != ethernet::ETHERTYPE_NDN)
|
||||
return;
|
||||
if (pkt == nullptr) {
|
||||
NFD_LOG_FACE_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, 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 += ethernet::HDR_LEN;
|
||||
len -= ethernet::HDR_LEN;
|
||||
receivePayload(pkt, len, sender);
|
||||
}
|
||||
}
|
||||
|
||||
// check that our BPF filter is working correctly
|
||||
BOOST_ASSERT_MSG(ethernet::Address(eh->ether_dhost) == m_destAddress,
|
||||
"Received frame addressed to a different multicast group");
|
||||
BOOST_ASSERT_MSG(sourceAddress != m_srcAddress,
|
||||
"Received frame sent by this host");
|
||||
#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
|
||||
|
||||
packet += ethernet::HDR_LEN;
|
||||
length -= ethernet::HDR_LEN;
|
||||
asyncRead();
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::receivePayload(const uint8_t* payload, size_t length,
|
||||
const ethernet::Address& sender)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE("Received: " << length << " bytes from " << sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(packet, length);
|
||||
std::tie(isOk, element) = Block::fromBuffer(payload, length);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Received invalid packet from " << sourceAddress.toString());
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << sender);
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
m_hasRecentlyReceived = true;
|
||||
|
||||
NFD_LOG_FACE_TRACE("Received: " << element.size() << " bytes from " << sourceAddress.toString());
|
||||
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());
|
||||
}
|
||||
|
||||
Transport::Packet tp(std::move(element));
|
||||
static_assert(sizeof(tp.remoteEndpoint) >= ethernet::ADDR_LEN,
|
||||
"Transport::Packet::remoteEndpoint is too small");
|
||||
std::memcpy(&tp.remoteEndpoint, sourceAddress.data(), sourceAddress.size());
|
||||
this->receive(std::move(tp));
|
||||
this->receive(element, endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::processErrorCode(const boost::system::error_code& error)
|
||||
EthernetTransport::handleError(const std::string& errorMessage)
|
||||
{
|
||||
// boost::asio::error::operation_aborted must be checked first. In that situation, the Transport
|
||||
// may already have been destructed, and 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) {
|
||||
// transport is shutting down, ignore any errors
|
||||
if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
|
||||
NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_WARN("Receive operation failed: " << error.message());
|
||||
}
|
||||
|
||||
size_t
|
||||
EthernetTransport::getInterfaceMtu()
|
||||
{
|
||||
#ifdef SIOCGIFMTU
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
// see bug #2328
|
||||
using boost::asio::ip::udp;
|
||||
udp::socket sock(getGlobalIoService(), udp::v4());
|
||||
int fd = sock.native_handle();
|
||||
#else
|
||||
int fd = m_socket.native_handle();
|
||||
#endif
|
||||
|
||||
ifreq ifr{};
|
||||
std::strncpy(ifr.ifr_name, m_interfaceName.c_str(), sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
if (::ioctl(fd, SIOCGIFMTU, &ifr) == 0) {
|
||||
NFD_LOG_FACE_DEBUG("Interface MTU is " << ifr.ifr_mtu);
|
||||
return static_cast<size_t>(ifr.ifr_mtu);
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_WARN("Failed to get interface MTU: " << std::strerror(errno));
|
||||
#endif
|
||||
|
||||
NFD_LOG_FACE_DEBUG("Assuming default MTU of " << ethernet::MAX_DATA_LEN);
|
||||
return ethernet::MAX_DATA_LEN;
|
||||
NFD_LOG_FACE_ERROR(errorMessage);
|
||||
this->setState(TransportState::FAILED);
|
||||
doClose();
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,73 +26,62 @@
|
||||
#ifndef NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
|
||||
#define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
#include "ethernet-protocol.hpp"
|
||||
#include "pcap-helper.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "core/network-interface.hpp"
|
||||
|
||||
#ifndef HAVE_LIBPCAP
|
||||
#error "Cannot include this file when libpcap is not available"
|
||||
#endif
|
||||
|
||||
// forward declarations
|
||||
struct pcap;
|
||||
typedef pcap pcap_t;
|
||||
struct pcap_pkthdr;
|
||||
#include <ndn-cxx/net/network-interface.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/**
|
||||
* \brief A multicast Transport that uses raw Ethernet II frames
|
||||
* @brief Base class for Ethernet-based Transports
|
||||
*/
|
||||
class EthernetTransport final : public Transport
|
||||
class EthernetTransport : public Transport
|
||||
{
|
||||
public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an Ethernet-based transport for multicast communication
|
||||
* @brief Processes the payload of an incoming frame
|
||||
* @param payload Pointer to the first byte of data after the Ethernet header
|
||||
* @param length Payload length
|
||||
* @param sender Sender address
|
||||
*/
|
||||
EthernetTransport(const NetworkInterfaceInfo& interface,
|
||||
const ethernet::Address& mcastAddress);
|
||||
void
|
||||
receivePayload(const uint8_t* payload, size_t length,
|
||||
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
|
||||
doSend(Transport::Packet&& packet) final;
|
||||
handleNetifStateChange(ndn::net::InterfaceState netifState);
|
||||
|
||||
/**
|
||||
* @brief Allocates and initializes a libpcap context for live capture
|
||||
*/
|
||||
void
|
||||
pcapInit();
|
||||
|
||||
/**
|
||||
* @brief Installs a BPF filter on the receiving socket
|
||||
*
|
||||
* @param filterString string containing the source BPF program
|
||||
*/
|
||||
void
|
||||
setPacketFilter(const char* filterString);
|
||||
|
||||
/**
|
||||
* @brief Enables receiving frames addressed to our MAC multicast group
|
||||
*
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
bool
|
||||
joinMulticastGroup();
|
||||
doSend(const Block& packet) final;
|
||||
|
||||
/**
|
||||
* @brief Sends the specified TLV block on the network wrapped in an Ethernet frame
|
||||
@@ -100,49 +89,29 @@ private:
|
||||
void
|
||||
sendPacket(const ndn::Block& block);
|
||||
|
||||
/**
|
||||
* @brief Receive callback
|
||||
*/
|
||||
void
|
||||
handleRead(const boost::system::error_code& error, size_t nBytesRead);
|
||||
asyncRead();
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
/**
|
||||
* @brief Processes an incoming frame as captured by libpcap
|
||||
*
|
||||
* @param header pointer to capture metadata
|
||||
* @param packet pointer to the received frame, including the link-layer header
|
||||
*/
|
||||
void
|
||||
processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet);
|
||||
handleRead(const boost::system::error_code& error);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Handles errors encountered by Boost.Asio on the receive path
|
||||
*/
|
||||
void
|
||||
processErrorCode(const boost::system::error_code& error);
|
||||
handleError(const std::string& errorMessage);
|
||||
|
||||
/**
|
||||
* @brief Returns the MTU of the underlying network interface
|
||||
*/
|
||||
size_t
|
||||
getInterfaceMtu();
|
||||
|
||||
private:
|
||||
unique_ptr<pcap_t, void(*)(pcap_t*)> m_pcap;
|
||||
protected:
|
||||
boost::asio::posix::stream_descriptor m_socket;
|
||||
|
||||
PcapHelper m_pcap;
|
||||
ethernet::Address m_srcAddress;
|
||||
ethernet::Address m_destAddress;
|
||||
std::string m_interfaceName;
|
||||
#if defined(__linux__)
|
||||
int m_interfaceIndex;
|
||||
#endif
|
||||
|
||||
private:
|
||||
signal::ScopedConnection m_netifStateChangedConn;
|
||||
signal::ScopedConnection m_netifMtuChangedConn;
|
||||
bool m_hasRecentlyReceived;
|
||||
#ifdef _DEBUG
|
||||
/// number of packets dropped by the kernel, as reported by libpcap
|
||||
unsigned int m_nDropped;
|
||||
/// number of frames dropped by the kernel, as reported by libpcap
|
||||
size_t m_nDropped;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,28 +23,83 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_FACE_LOG_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_LOG_HPP
|
||||
#ifndef NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
|
||||
#include "core/logger.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 {
|
||||
|
||||
/** \brief for internal use by FaceLogging macros
|
||||
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
|
||||
*
|
||||
* FaceLogHelper wraps a Face, LinkService, or Transport object.
|
||||
* 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.
|
||||
*
|
||||
* std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
|
||||
* 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 appears as part of the log message.
|
||||
* which will appear as part of the log message.
|
||||
*/
|
||||
template<typename T>
|
||||
class FaceLogHelper
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
FaceLogHelper(const T& obj1)
|
||||
FaceLogHelper(const T& obj1) noexcept
|
||||
: obj(obj1)
|
||||
{
|
||||
}
|
||||
@@ -53,6 +108,13 @@ 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,
|
||||
@@ -62,6 +124,8 @@ public:
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \cond */
|
||||
// implementation detail
|
||||
#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
|
||||
::nfd::face::FaceLogHelper< \
|
||||
typename std::remove_cv< \
|
||||
@@ -69,6 +133,7 @@ public:
|
||||
>::type \
|
||||
>(*this) \
|
||||
<< msg)
|
||||
/** \endcond */
|
||||
|
||||
/** \brief Log a message at TRACE level */
|
||||
#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
|
||||
@@ -87,7 +152,4 @@ public:
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_FACE_LOG_HPP
|
||||
#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -32,6 +32,7 @@ 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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
public:
|
||||
const PacketCounter& nInInterests;
|
||||
const PacketCounter& nOutInterests;
|
||||
const PacketCounter& nInterestsExceededRetx;
|
||||
const PacketCounter& nInData;
|
||||
const PacketCounter& nOutData;
|
||||
const PacketCounter& nInNacks;
|
||||
@@ -80,6 +81,14 @@ public:
|
||||
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:
|
||||
const LinkService::Counters& m_linkServiceCounters;
|
||||
const Transport::Counters& m_transportCounters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,28 +23,36 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FW_CLIENT_CONTROL_STRATEGY_HPP
|
||||
#define NFD_DAEMON_FW_CLIENT_CONTROL_STRATEGY_HPP
|
||||
#ifndef NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
|
||||
#include "best-route-strategy.hpp"
|
||||
#include "face.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace fw {
|
||||
|
||||
/** \brief identical to BestRouteStrategy v1, for backwards compatibility
|
||||
* \deprecated NextHopFaceId field is honored universally and it's unnecessary to set this strategy
|
||||
/** \brief Represents a face-endpoint pair in the forwarder.
|
||||
* \sa face::Face, face::EndpointId
|
||||
*/
|
||||
class ClientControlStrategy : public BestRouteStrategyBase
|
||||
class FaceEndpoint
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
ClientControlStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
|
||||
FaceEndpoint(const Face& face, EndpointId endpoint)
|
||||
: face(const_cast<Face&>(face))
|
||||
, endpoint(endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
static const Name&
|
||||
getStrategyName();
|
||||
public:
|
||||
Face& face;
|
||||
const EndpointId endpoint;
|
||||
};
|
||||
|
||||
} // namespace fw
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, const FaceEndpoint& fe)
|
||||
{
|
||||
return os << '(' << fe.face.getId() << ',' << fe.endpoint << ')';
|
||||
}
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FW_CLIENT_CONTROL_STRATEGY_HPP
|
||||
#endif // NFD_DAEMON_FACE_FACE_ENDPOINT_HPP
|
||||
+57
-19
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -25,21 +25,38 @@
|
||||
|
||||
#include "face-system.hpp"
|
||||
#include "protocol-factory.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "netdev-bound.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "fw/face-table.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("FaceSystem");
|
||||
NFD_LOG_INIT(FaceSystem);
|
||||
|
||||
FaceSystem::FaceSystem(FaceTable& faceTable)
|
||||
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))
|
||||
{
|
||||
for (const std::string& id : ProtocolFactory::listRegistered()) {
|
||||
auto pfCtorParams = this->makePFCtorParams();
|
||||
for (const auto& id : ProtocolFactory::listRegistered()) {
|
||||
NFD_LOG_TRACE("creating factory " << id);
|
||||
m_factories[id] = ProtocolFactory::create(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;
|
||||
@@ -68,21 +85,39 @@ FaceSystem::getFactoryByScheme(const std::string& scheme)
|
||||
return found == m_factoryByScheme.end() ? nullptr : found->second;
|
||||
}
|
||||
|
||||
void
|
||||
FaceSystem::setConfigFile(ConfigFile& configFile)
|
||||
bool
|
||||
FaceSystem::hasFactoryForScheme(const std::string& scheme) const
|
||||
{
|
||||
configFile.addSectionHandler("face_system", bind(&FaceSystem::processConfig, this, _1, _2, _3));
|
||||
return m_factoryByScheme.count(scheme) > 0;
|
||||
}
|
||||
|
||||
void
|
||||
FaceSystem::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename)
|
||||
FaceSystem::setConfigFile(ConfigFile& configFile)
|
||||
{
|
||||
configFile.addSectionHandler(CFGSEC_FACESYSTEM, bind(&FaceSystem::processConfig, this, _1, _2, _3));
|
||||
}
|
||||
|
||||
void
|
||||
FaceSystem::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
|
||||
{
|
||||
ConfigContext context;
|
||||
context.isDryRun = isDryRun;
|
||||
context.addFace = bind(&FaceTable::add, &m_faceTable, _1);
|
||||
context.m_netifs = listNetworkInterfaces();
|
||||
|
||||
// process sections in protocol factories
|
||||
// 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();
|
||||
@@ -106,6 +141,10 @@ FaceSystem::processConfig(const ConfigSection& configSection, bool isDryRun, con
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -113,16 +152,15 @@ FaceSystem::processConfig(const ConfigSection& configSection, bool isDryRun, con
|
||||
// const ConfigSection& subSection = pair.second;
|
||||
|
||||
if (!seenSections.insert(sectionName).second) {
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Duplicate section face_system." + sectionName));
|
||||
NDN_THROW(ConfigFile::Error("Duplicate section " + CFGSEC_FACESYSTEM + "." + sectionName));
|
||||
}
|
||||
|
||||
if (m_factories.count(sectionName) > 0) {
|
||||
if (sectionName == CFGSEC_GENERAL || sectionName == CFGSEC_NETDEVBOUND ||
|
||||
m_factories.count(sectionName) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
///\todo #3521 nicfaces
|
||||
|
||||
BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option face_system." + sectionName));
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option " + CFGSEC_FACESYSTEM + "." + sectionName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
-23
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,10 +26,12 @@
|
||||
#ifndef NFD_DAEMON_FACE_FACE_SYSTEM_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_SYSTEM_HPP
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "core/config-file.hpp"
|
||||
#include "core/network-interface.hpp"
|
||||
#include "core/network-interface-predicate.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 {
|
||||
|
||||
@@ -37,7 +39,9 @@ class FaceTable;
|
||||
|
||||
namespace face {
|
||||
|
||||
class NetdevBound;
|
||||
class ProtocolFactory;
|
||||
struct ProtocolFactoryCtorParams;
|
||||
|
||||
/** \brief entry point of the face system
|
||||
*
|
||||
@@ -47,8 +51,7 @@ class ProtocolFactory;
|
||||
class FaceSystem : noncopyable
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
FaceSystem(FaceTable& faceTable);
|
||||
FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon);
|
||||
|
||||
~FaceSystem();
|
||||
|
||||
@@ -67,34 +70,40 @@ public:
|
||||
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:
|
||||
const std::vector<NetworkInterfaceInfo>&
|
||||
listNetifs() const
|
||||
{
|
||||
///\todo get netifs from NetworkMonitor
|
||||
return m_netifs;
|
||||
}
|
||||
|
||||
public:
|
||||
GeneralConfig generalConfig;
|
||||
bool isDryRun;
|
||||
FaceCreatedCallback addFace;
|
||||
///\todo add NetworkMonitor
|
||||
|
||||
private:
|
||||
std::vector<NetworkInterfaceInfo> m_netifs;
|
||||
|
||||
friend class FaceSystem;
|
||||
};
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
ProtocolFactoryCtorParams
|
||||
makePFCtorParams();
|
||||
|
||||
private:
|
||||
void
|
||||
processConfig(const ConfigSection& configSection, bool isDryRun,
|
||||
@@ -104,6 +113,7 @@ 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
|
||||
@@ -113,6 +123,7 @@ private:
|
||||
std::map<std::string, ProtocolFactory*> m_factoryByScheme;
|
||||
|
||||
FaceTable& m_faceTable;
|
||||
shared_ptr<ndn::net::NetworkMonitor> m_netmon;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -32,6 +32,7 @@ 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))
|
||||
|
||||
+71
-62
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -23,31 +23,18 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FACE_HPP
|
||||
#define NFD_DAEMON_FACE_HPP
|
||||
#ifndef NFD_DAEMON_FACE_FACE_HPP
|
||||
#define NFD_DAEMON_FACE_FACE_HPP
|
||||
|
||||
#include "transport.hpp"
|
||||
#include "link-service.hpp"
|
||||
#include "face-common.hpp"
|
||||
#include "face-counters.hpp"
|
||||
#include "face-log.hpp"
|
||||
#include "link-service.hpp"
|
||||
#include "transport.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \brief identifies a face
|
||||
*/
|
||||
typedef uint64_t FaceId;
|
||||
|
||||
/// indicates an invalid FaceId
|
||||
const FaceId INVALID_FACEID = 0;
|
||||
/// 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;
|
||||
class Channel;
|
||||
|
||||
/** \brief indicates the state of a face
|
||||
*/
|
||||
@@ -64,11 +51,7 @@ typedef TransportState FaceState;
|
||||
* 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
|
||||
#ifndef WITH_TESTS
|
||||
final
|
||||
#endif
|
||||
: public enable_shared_from_this<Face>, noncopyable
|
||||
class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
|
||||
{
|
||||
public:
|
||||
Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
|
||||
@@ -79,35 +62,51 @@ public:
|
||||
Transport*
|
||||
getTransport() const;
|
||||
|
||||
/** \brief Request that the face be closed
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
close();
|
||||
|
||||
public: // upper interface connected to forwarding
|
||||
/** \brief sends Interest on Face
|
||||
/** \brief send Interest
|
||||
*/
|
||||
void
|
||||
sendInterest(const Interest& interest);
|
||||
|
||||
/** \brief sends Data on Face
|
||||
/** \brief send Data
|
||||
*/
|
||||
void
|
||||
sendData(const Data& data);
|
||||
|
||||
/** \brief sends Nack on Face
|
||||
/** \brief send Nack
|
||||
*/
|
||||
void
|
||||
sendNack(const lp::Nack& nack);
|
||||
|
||||
/** \brief signals on Interest received
|
||||
*/
|
||||
signal::Signal<LinkService, Interest>& afterReceiveInterest;
|
||||
signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
|
||||
|
||||
/** \brief signals on Data received
|
||||
*/
|
||||
signal::Signal<LinkService, Data>& afterReceiveData;
|
||||
signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
|
||||
|
||||
/** \brief signals on Nack received
|
||||
*/
|
||||
signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
|
||||
signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
|
||||
|
||||
public: // static properties
|
||||
/** \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
|
||||
@@ -149,7 +148,13 @@ public: // static properties
|
||||
ndn::nfd::LinkType
|
||||
getLinkType() const;
|
||||
|
||||
public: // dynamic properties
|
||||
/** \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
|
||||
@@ -165,27 +170,33 @@ public: // dynamic properties
|
||||
time::steady_clock::TimePoint
|
||||
getExpirationTime() const;
|
||||
|
||||
/** \brief request the face to be closed
|
||||
*
|
||||
* This operation is effective only if face is in UP or DOWN state,
|
||||
* otherwise it has no effect.
|
||||
* The face changes state to CLOSING, and performs cleanup procedure.
|
||||
* The state will be changed to CLOSED when cleanup is complete, which may
|
||||
* happen synchronously or asynchronously.
|
||||
*
|
||||
* \warning the face must not be deallocated until its state changes to CLOSED
|
||||
*/
|
||||
void
|
||||
close();
|
||||
|
||||
const FaceCounters&
|
||||
getCounters() const;
|
||||
|
||||
/**
|
||||
* \brief Get channel on which face was created (unicast) or the associated channel (multicast)
|
||||
*/
|
||||
weak_ptr<Channel>
|
||||
getChannel() const
|
||||
{
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set channel on which face was created (unicast) or the associated channel (multicast)
|
||||
*/
|
||||
void
|
||||
setChannel(weak_ptr<Channel> channel)
|
||||
{
|
||||
m_channel = std::move(channel);
|
||||
}
|
||||
|
||||
private:
|
||||
FaceId m_id;
|
||||
unique_ptr<LinkService> m_service;
|
||||
unique_ptr<Transport> m_transport;
|
||||
FaceCounters m_counters;
|
||||
weak_ptr<Channel> m_channel;
|
||||
};
|
||||
|
||||
inline LinkService*
|
||||
@@ -200,6 +211,12 @@ Face::getTransport() const
|
||||
return m_transport.get();
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::close()
|
||||
{
|
||||
m_transport->close();
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::sendInterest(const Interest& interest)
|
||||
{
|
||||
@@ -266,6 +283,12 @@ Face::getLinkType() const
|
||||
return m_transport->getLinkType();
|
||||
}
|
||||
|
||||
inline ssize_t
|
||||
Face::getMtu() const
|
||||
{
|
||||
return m_service->getEffectiveMtu();
|
||||
}
|
||||
|
||||
inline FaceState
|
||||
Face::getState() const
|
||||
{
|
||||
@@ -278,12 +301,6 @@ Face::getExpirationTime() const
|
||||
return m_transport->getExpirationTime();
|
||||
}
|
||||
|
||||
inline void
|
||||
Face::close()
|
||||
{
|
||||
m_transport->close();
|
||||
}
|
||||
|
||||
inline const FaceCounters&
|
||||
Face::getCounters() const
|
||||
{
|
||||
@@ -293,18 +310,10 @@ Face::getCounters() const
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_base_of<Face, T>::value, std::ostream&>::type
|
||||
operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
|
||||
{
|
||||
return os << FaceLogHelper<Face>(flh.obj);
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
using face::FaceId;
|
||||
using face::Face;
|
||||
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_HPP
|
||||
#endif // NFD_DAEMON_FACE_FACE_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,33 +24,92 @@
|
||||
*/
|
||||
|
||||
#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");
|
||||
NFD_LOG_INIT(GenericLinkService);
|
||||
|
||||
GenericLinkServiceCounters::GenericLinkServiceCounters(const LpReassembler& reassembler)
|
||||
: nReassembling(reassembler)
|
||||
{
|
||||
}
|
||||
|
||||
GenericLinkService::Options::Options()
|
||||
: allowLocalFields(false)
|
||||
, allowFragmentation(false)
|
||||
, allowReassembly(false)
|
||||
{
|
||||
}
|
||||
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)
|
||||
: GenericLinkServiceCounters(m_reassembler)
|
||||
, m_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::TimePoint::max())
|
||||
, m_nMarkedSinceInMarkingState(0)
|
||||
{
|
||||
m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; }));
|
||||
m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; });
|
||||
m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->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)) {
|
||||
++this->nOutOverMtu;
|
||||
NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
|
||||
return;
|
||||
}
|
||||
this->sendPacket(block);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -60,7 +119,7 @@ GenericLinkService::doSendInterest(const Interest& interest)
|
||||
|
||||
encodeLpFields(interest, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket));
|
||||
this->sendNetPacket(std::move(lpPacket), true);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -70,7 +129,7 @@ GenericLinkService::doSendData(const Data& data)
|
||||
|
||||
encodeLpFields(data, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket));
|
||||
this->sendNetPacket(std::move(lpPacket), false);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -81,30 +140,68 @@ GenericLinkService::doSendNack(const lp::Nack& nack)
|
||||
|
||||
encodeLpFields(nack, lpPacket);
|
||||
|
||||
this->sendNetPacket(std::move(lpPacket));
|
||||
this->sendNetPacket(std::move(lpPacket), false);
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket)
|
||||
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) {
|
||||
shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
|
||||
auto incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
|
||||
if (incomingFaceIdTag != nullptr) {
|
||||
lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
|
||||
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)
|
||||
GenericLinkService::sendNetPacket(lp::Packet&& pkt, bool isInterest)
|
||||
{
|
||||
std::vector<lp::Packet> frags;
|
||||
const ssize_t mtu = this->getTransport()->getMtu();
|
||||
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);
|
||||
@@ -115,49 +212,94 @@ GenericLinkService::sendNetPacket(lp::Packet&& pkt)
|
||||
}
|
||||
}
|
||||
else {
|
||||
frags.push_back(pkt);
|
||||
if (m_options.reliabilityOptions.isEnabled) {
|
||||
frags.push_back(pkt);
|
||||
}
|
||||
else {
|
||||
frags.push_back(std::move(pkt));
|
||||
}
|
||||
}
|
||||
|
||||
if (frags.size() > 1) {
|
||||
// sequence is needed only if packet is fragmented
|
||||
this->assignSequences(frags);
|
||||
}
|
||||
else {
|
||||
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.size() > 0);
|
||||
BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
|
||||
BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
|
||||
}
|
||||
|
||||
for (const lp::Packet& frag : frags) {
|
||||
Transport::Packet tp(frag.wireEncode());
|
||||
if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
|
||||
++this->nOutOverMtu;
|
||||
NFD_LOG_FACE_WARN("attempt to send packet over MTU limit");
|
||||
continue;
|
||||
}
|
||||
this->sendPacket(std::move(tp));
|
||||
// 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::assignSequence(lp::Packet& pkt)
|
||||
GenericLinkService::checkCongestionLevel(lp::Packet& pkt)
|
||||
{
|
||||
pkt.set<lp::SequenceField>(++m_lastSeqNo);
|
||||
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::TimePoint::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::TimePoint::max()) {
|
||||
// Congestion incident has ended, so reset
|
||||
NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
|
||||
m_nextMarkTime = time::steady_clock::TimePoint::max();
|
||||
m_nMarkedSinceInMarkingState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
|
||||
{
|
||||
std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence, this, _1));
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::doReceivePacket(Transport::Packet&& packet)
|
||||
GenericLinkService::doReceivePacket(const Block& packet, const EndpointId& endpoint)
|
||||
{
|
||||
try {
|
||||
lp::Packet pkt(packet.packet);
|
||||
lp::Packet pkt(packet);
|
||||
|
||||
if (m_options.reliabilityOptions.isEnabled) {
|
||||
if (!m_reliability.processIncomingPacket(pkt)) {
|
||||
NFD_LOG_FACE_TRACE("received duplicate fragment: DROP");
|
||||
++this->nDuplicateSequence;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pkt.has<lp::FragmentField>()) {
|
||||
NFD_LOG_FACE_TRACE("received IDLE packet: DROP");
|
||||
@@ -173,10 +315,9 @@ GenericLinkService::doReceivePacket(Transport::Packet&& packet)
|
||||
bool isReassembled = false;
|
||||
Block netPkt;
|
||||
lp::Packet firstPkt;
|
||||
std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(packet.remoteEndpoint,
|
||||
pkt);
|
||||
std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(endpoint, pkt);
|
||||
if (isReassembled) {
|
||||
this->decodeNetPacket(netPkt, firstPkt);
|
||||
this->decodeNetPacket(netPkt, firstPkt, endpoint);
|
||||
}
|
||||
}
|
||||
catch (const tlv::Error& e) {
|
||||
@@ -186,20 +327,21 @@ GenericLinkService::doReceivePacket(Transport::Packet&& packet)
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt)
|
||||
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);
|
||||
this->decodeNack(netPkt, firstPkt, endpointId);
|
||||
}
|
||||
else {
|
||||
this->decodeInterest(netPkt, firstPkt);
|
||||
this->decodeInterest(netPkt, firstPkt, endpointId);
|
||||
}
|
||||
break;
|
||||
case tlv::Data:
|
||||
this->decodeData(netPkt, firstPkt);
|
||||
this->decodeData(netPkt, firstPkt, endpointId);
|
||||
break;
|
||||
default:
|
||||
++this->nInNetInvalid;
|
||||
@@ -214,7 +356,8 @@ GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& first
|
||||
}
|
||||
|
||||
void
|
||||
GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt)
|
||||
GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Interest);
|
||||
BOOST_ASSERT(!firstPkt.has<lp::NackField>());
|
||||
@@ -246,11 +389,31 @@ GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstP
|
||||
interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
this->receiveInterest(*interest);
|
||||
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>()) {
|
||||
++this->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)
|
||||
GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Data);
|
||||
|
||||
@@ -270,14 +433,10 @@ GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt)
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::CachePolicyField>()) {
|
||||
if (m_options.allowLocalFields) {
|
||||
// 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>()));
|
||||
}
|
||||
else {
|
||||
NFD_LOG_FACE_WARN("received CachePolicy, but local fields disabled: IGNORE");
|
||||
}
|
||||
// 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>()) {
|
||||
@@ -288,11 +447,27 @@ GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt)
|
||||
data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
this->receiveData(*data);
|
||||
if (firstPkt.has<lp::NonDiscoveryField>()) {
|
||||
++this->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)
|
||||
GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt,
|
||||
const EndpointId& endpointId)
|
||||
{
|
||||
BOOST_ASSERT(netPkt.type() == tlv::Interest);
|
||||
BOOST_ASSERT(firstPkt.has<lp::NackField>());
|
||||
@@ -320,7 +495,19 @@ GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt)
|
||||
nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
|
||||
}
|
||||
|
||||
this->receiveNack(nack);
|
||||
if (firstPkt.has<lp::NonDiscoveryField>()) {
|
||||
++this->nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
|
||||
++this->nInNetInvalid;
|
||||
NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
|
||||
return;
|
||||
}
|
||||
|
||||
this->receiveNack(nack, endpointId);
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,12 +26,10 @@
|
||||
#ifndef NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
|
||||
#define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
#include "link-service.hpp"
|
||||
#include "lp-fragmenter.hpp"
|
||||
#include "lp-reassembler.hpp"
|
||||
#include "lp-reliability.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
@@ -43,9 +41,6 @@ namespace face {
|
||||
class GenericLinkServiceCounters : public virtual LinkService::Counters
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
GenericLinkServiceCounters(const LpReassembler& reassembler);
|
||||
|
||||
/** \brief count of failed fragmentations
|
||||
*/
|
||||
PacketCounter nFragmentationErrors;
|
||||
@@ -71,13 +66,35 @@ public:
|
||||
/** \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 http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
*/
|
||||
class GenericLinkService : public LinkService
|
||||
, protected virtual GenericLinkServiceCounters
|
||||
class GenericLinkService FINAL_UNLESS_WITH_TESTS : public LinkService
|
||||
, protected virtual GenericLinkServiceCounters
|
||||
{
|
||||
public:
|
||||
/** \brief Options that control the behavior of GenericLinkService
|
||||
@@ -85,16 +102,18 @@ public:
|
||||
class Options
|
||||
{
|
||||
public:
|
||||
Options();
|
||||
Options() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
/** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
|
||||
*/
|
||||
bool allowLocalFields;
|
||||
bool allowLocalFields = false;
|
||||
|
||||
/** \brief enables fragmentation
|
||||
*/
|
||||
bool allowFragmentation;
|
||||
bool allowFragmentation = false;
|
||||
|
||||
/** \brief options for fragmentation
|
||||
*/
|
||||
@@ -102,19 +121,57 @@ public:
|
||||
|
||||
/** \brief enables reassembly
|
||||
*/
|
||||
bool allowReassembly;
|
||||
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
|
||||
*/
|
||||
typedef GenericLinkServiceCounters Counters;
|
||||
using Counters = GenericLinkServiceCounters;
|
||||
|
||||
explicit
|
||||
GenericLinkService(const Options& options = Options());
|
||||
GenericLinkService(const Options& options = {});
|
||||
|
||||
/** \brief get Options used by GenericLinkService
|
||||
*/
|
||||
@@ -126,67 +183,85 @@ public:
|
||||
void
|
||||
setOptions(const Options& options);
|
||||
|
||||
virtual const Counters&
|
||||
getCounters() const override;
|
||||
const Counters&
|
||||
getCounters() const OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
private: // send path
|
||||
/** \brief send Interest
|
||||
ssize_t
|
||||
getEffectiveMtu() const 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;
|
||||
|
||||
PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path
|
||||
/** \brief request an IDLE packet to transmit pending service fields
|
||||
*/
|
||||
void
|
||||
doSendInterest(const Interest& interest) override;
|
||||
requestIdlePacket();
|
||||
|
||||
/** \brief send Data
|
||||
/** \brief send an LpPacket
|
||||
*/
|
||||
void
|
||||
doSendData(const Data& data) override;
|
||||
sendLpPacket(lp::Packet&& pkt);
|
||||
|
||||
/** \brief send Nack
|
||||
*/
|
||||
void
|
||||
doSendNack(const ndn::lp::Nack& nack) override;
|
||||
doSendInterest(const Interest& interest) OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \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::TagHost& netPkt, lp::Packet& lpPacket);
|
||||
doSendData(const Data& data) OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \brief send a complete network layer packet
|
||||
* \param pkt LpPacket containing a complete network layer packet
|
||||
*/
|
||||
void
|
||||
sendNetPacket(lp::Packet&& pkt);
|
||||
|
||||
/** \brief assign a sequence number to an LpPacket
|
||||
*/
|
||||
void
|
||||
assignSequence(lp::Packet& pkt);
|
||||
doSendNack(const ndn::lp::Nack& nack) OVERRIDE_WITH_TESTS_ELSE_FINAL;
|
||||
|
||||
/** \brief assign consecutive sequence numbers to LpPackets
|
||||
*/
|
||||
void
|
||||
assignSequences(std::vector<lp::Packet>& pkts);
|
||||
|
||||
private: // receive path
|
||||
/** \brief receive Packet from Transport
|
||||
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
|
||||
doReceivePacket(Transport::Packet&& packet) override;
|
||||
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) 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);
|
||||
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.
|
||||
@@ -194,11 +269,12 @@ private: // receive path
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeInterest(const Block& netPkt, const lp::Packet& firstPkt);
|
||||
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.
|
||||
@@ -206,11 +282,12 @@ private: // receive path
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeData(const Block& netPkt, const lp::Packet& firstPkt);
|
||||
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.
|
||||
@@ -218,13 +295,22 @@ private: // receive path
|
||||
* \throw tlv::Error parse error in an LpHeader field
|
||||
*/
|
||||
void
|
||||
decodeNack(const Block& netPkt, const lp::Packet& firstPkt);
|
||||
decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId);
|
||||
|
||||
private:
|
||||
PROTECTED_WITH_TESTS_ELSE_PRIVATE:
|
||||
Options m_options;
|
||||
LpFragmenter m_fragmenter;
|
||||
LpReassembler m_reassembler;
|
||||
LpReliability m_reliability;
|
||||
lp::Sequence m_lastSeqNo;
|
||||
|
||||
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&
|
||||
@@ -233,12 +319,6 @@ GenericLinkService::getOptions() const
|
||||
return m_options;
|
||||
}
|
||||
|
||||
inline void
|
||||
GenericLinkService::setOptions(const GenericLinkService::Options& options)
|
||||
{
|
||||
m_options = options;
|
||||
}
|
||||
|
||||
inline const GenericLinkService::Counters&
|
||||
GenericLinkService::getCounters() const
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "internal-face.hpp"
|
||||
#include "generic-link-service.hpp"
|
||||
#include "internal-transport.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,16 +24,16 @@
|
||||
*/
|
||||
|
||||
#include "internal-transport.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INCLASS_DEFINE(InternalForwarderTransport, "InternalForwarderTransport");
|
||||
NFD_LOG_MEMBER_INIT(InternalForwarderTransport, InternalForwarderTransport);
|
||||
NFD_LOG_MEMBER_INIT(InternalClientTransport, InternalClientTransport);
|
||||
|
||||
InternalForwarderTransport::InternalForwarderTransport(
|
||||
const FaceUri& localUri, const FaceUri& remoteUri,
|
||||
ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType)
|
||||
InternalForwarderTransport::InternalForwarderTransport(const FaceUri& localUri, const FaceUri& remoteUri,
|
||||
ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType)
|
||||
{
|
||||
this->setLocalUri(localUri);
|
||||
this->setRemoteUri(remoteUri);
|
||||
@@ -42,25 +42,25 @@ InternalForwarderTransport::InternalForwarderTransport(
|
||||
this->setLinkType(linkType);
|
||||
this->setMtu(MTU_UNLIMITED);
|
||||
|
||||
NFD_LOG_FACE_INFO("Creating transport");
|
||||
NFD_LOG_FACE_DEBUG("Creating transport");
|
||||
}
|
||||
|
||||
void
|
||||
InternalForwarderTransport::receiveFromLink(const Block& packet)
|
||||
InternalForwarderTransport::receivePacket(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
Packet p;
|
||||
p.packet = packet;
|
||||
this->receive(std::move(p));
|
||||
getGlobalIoService().post([this, packet] {
|
||||
NFD_LOG_FACE_TRACE("Received: " << packet.size() << " bytes");
|
||||
receive(packet);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
InternalForwarderTransport::doSend(Packet&& packet)
|
||||
InternalForwarderTransport::doSend(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
NFD_LOG_FACE_TRACE("Sending to " << m_peer);
|
||||
|
||||
this->emitSignal(afterSend, packet.packet);
|
||||
if (m_peer)
|
||||
m_peer->receivePacket(packet);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -68,52 +68,59 @@ InternalForwarderTransport::doClose()
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
this->setState(TransportState::CLOSED);
|
||||
setState(TransportState::CLOSED);
|
||||
}
|
||||
|
||||
NFD_LOG_INCLASS_DEFINE(InternalClientTransport, "InternalClientTransport");
|
||||
|
||||
static void
|
||||
asyncReceive(InternalTransportBase* recipient, const Block& packet)
|
||||
InternalClientTransport::~InternalClientTransport()
|
||||
{
|
||||
getGlobalIoService().post([packet, recipient] {
|
||||
recipient->receiveFromLink(packet);
|
||||
});
|
||||
if (m_forwarder != nullptr) {
|
||||
m_forwarder->setPeer(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InternalClientTransport::connectToForwarder(InternalForwarderTransport* forwarderTransport)
|
||||
InternalClientTransport::connectToForwarder(InternalForwarderTransport* forwarder)
|
||||
{
|
||||
NFD_LOG_DEBUG(__func__ << " " << forwarderTransport);
|
||||
NFD_LOG_DEBUG(__func__ << " " << forwarder);
|
||||
|
||||
m_fwToClientTransmitConn.disconnect();
|
||||
m_clientToFwTransmitConn.disconnect();
|
||||
m_fwTransportStateConn.disconnect();
|
||||
if (m_forwarder != nullptr) {
|
||||
// disconnect from the old forwarder transport
|
||||
m_forwarder->setPeer(nullptr);
|
||||
m_fwTransportStateConn.disconnect();
|
||||
}
|
||||
|
||||
if (forwarderTransport != nullptr) {
|
||||
m_fwToClientTransmitConn = forwarderTransport->afterSend.connect(bind(&asyncReceive, this, _1));
|
||||
m_clientToFwTransmitConn = this->afterSend.connect(bind(&asyncReceive, forwarderTransport, _1));
|
||||
m_fwTransportStateConn = forwarderTransport->afterStateChange.connect(
|
||||
m_forwarder = forwarder;
|
||||
|
||||
if (m_forwarder != nullptr) {
|
||||
// connect to the new forwarder transport
|
||||
m_forwarder->setPeer(this);
|
||||
m_fwTransportStateConn = m_forwarder->afterStateChange.connect(
|
||||
[this] (TransportState oldState, TransportState newState) {
|
||||
if (newState == TransportState::CLOSED) {
|
||||
this->connectToForwarder(nullptr);
|
||||
connectToForwarder(nullptr);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InternalClientTransport::receiveFromLink(const Block& packet)
|
||||
InternalClientTransport::receivePacket(const Block& packet)
|
||||
{
|
||||
if (m_receiveCallback) {
|
||||
m_receiveCallback(packet);
|
||||
}
|
||||
getGlobalIoService().post([this, packet] {
|
||||
NFD_LOG_TRACE("Received: " << packet.size() << " bytes");
|
||||
if (m_receiveCallback) {
|
||||
m_receiveCallback(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
InternalClientTransport::send(const Block& wire)
|
||||
{
|
||||
this->emitSignal(afterSend, wire);
|
||||
NFD_LOG_TRACE("Sending to " << m_forwarder);
|
||||
|
||||
if (m_forwarder)
|
||||
m_forwarder->receivePacket(wire);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -123,7 +130,7 @@ InternalClientTransport::send(const Block& header, const Block& payload)
|
||||
encoder.appendByteArray(header.wire(), header.size());
|
||||
encoder.appendByteArray(payload.wire(), payload.size());
|
||||
|
||||
this->send(encoder.block());
|
||||
send(encoder.block());
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -27,59 +27,67 @@
|
||||
#define NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
|
||||
|
||||
#include "transport.hpp"
|
||||
|
||||
#include <ndn-cxx/transport/transport.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/** \brief abstracts a transport that can be paired with another
|
||||
/** \brief Abstracts a transport that can be paired with another.
|
||||
*/
|
||||
class InternalTransportBase
|
||||
{
|
||||
public:
|
||||
/** \brief causes the transport to receive a link-layer packet
|
||||
*/
|
||||
virtual
|
||||
~InternalTransportBase() = default;
|
||||
|
||||
virtual void
|
||||
receiveFromLink(const Block& packet) = 0;
|
||||
|
||||
signal::Signal<InternalTransportBase, Block> afterSend;
|
||||
|
||||
protected:
|
||||
DECLARE_SIGNAL_EMIT(afterSend)
|
||||
receivePacket(const Block& packet) = 0;
|
||||
};
|
||||
|
||||
/** \brief implements a forwarder-side transport that can be paired with another
|
||||
/** \brief Implements a forwarder-side transport that can be paired with another transport.
|
||||
*/
|
||||
class InternalForwarderTransport : public face::Transport, public InternalTransportBase
|
||||
class InternalForwarderTransport final : public Transport, public InternalTransportBase
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
InternalForwarderTransport(const FaceUri& localUri = FaceUri("internal://"),
|
||||
const FaceUri& remoteUri = FaceUri("internal://"),
|
||||
ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_LOCAL,
|
||||
ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
|
||||
|
||||
void
|
||||
receiveFromLink(const Block& packet) override;
|
||||
setPeer(InternalTransportBase* peer)
|
||||
{
|
||||
m_peer = peer;
|
||||
}
|
||||
|
||||
void
|
||||
receivePacket(const Block& packet) final;
|
||||
|
||||
protected:
|
||||
void
|
||||
doClose() override;
|
||||
doClose() final;
|
||||
|
||||
private:
|
||||
void
|
||||
doSend(Packet&& packet) override;
|
||||
doSend(const Block& packet) final;
|
||||
|
||||
private:
|
||||
NFD_LOG_INCLASS_DECLARE();
|
||||
NFD_LOG_MEMBER_DECL();
|
||||
|
||||
InternalTransportBase* m_peer = nullptr;
|
||||
};
|
||||
|
||||
/** \brief implements a client-side transport that can be paired with another
|
||||
/** \brief Implements a client-side transport that can be paired with an InternalForwarderTransport.
|
||||
*/
|
||||
class InternalClientTransport : public ndn::Transport, public InternalTransportBase
|
||||
class InternalClientTransport final : public ndn::Transport, public InternalTransportBase
|
||||
{
|
||||
public:
|
||||
/** \brief connect to a forwarder-side transport
|
||||
* \param forwarderTransport the forwarder-side transport to connect to; may be nullptr
|
||||
~InternalClientTransport() final;
|
||||
|
||||
/** \brief Connect to a forwarder-side transport.
|
||||
* \param forwarder the forwarder-side transport to connect to; may be nullptr
|
||||
*
|
||||
* The connected forwarder-side transport will be disconnected automatically if this method
|
||||
* is called again, or if that transport is closed.
|
||||
@@ -87,37 +95,36 @@ public:
|
||||
* all sent packets would be lost, and nothing would be received.
|
||||
*/
|
||||
void
|
||||
connectToForwarder(InternalForwarderTransport* forwarderTransport);
|
||||
connectToForwarder(InternalForwarderTransport* forwarder);
|
||||
|
||||
void
|
||||
receiveFromLink(const Block& packet) override;
|
||||
receivePacket(const Block& packet) final;
|
||||
|
||||
void
|
||||
close() override
|
||||
send(const Block& wire) final;
|
||||
|
||||
void
|
||||
send(const Block& header, const Block& payload) final;
|
||||
|
||||
void
|
||||
close() final
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
pause() override
|
||||
pause() final
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
resume() override
|
||||
resume() final
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
send(const Block& wire) override;
|
||||
|
||||
void
|
||||
send(const Block& header, const Block& payload) override;
|
||||
|
||||
private:
|
||||
NFD_LOG_INCLASS_DECLARE();
|
||||
NFD_LOG_MEMBER_DECL();
|
||||
|
||||
signal::ScopedConnection m_fwToClientTransmitConn;
|
||||
signal::ScopedConnection m_clientToFwTransmitConn;
|
||||
InternalForwarderTransport* m_forwarder = nullptr;
|
||||
signal::ScopedConnection m_fwTransportStateConn;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -29,7 +29,7 @@
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("LinkService");
|
||||
NFD_LOG_INIT(LinkService);
|
||||
|
||||
LinkService::LinkService()
|
||||
: m_face(nullptr)
|
||||
@@ -85,33 +85,40 @@ LinkService::sendNack(const ndn::lp::Nack& nack)
|
||||
}
|
||||
|
||||
void
|
||||
LinkService::receiveInterest(const Interest& interest)
|
||||
LinkService::receiveInterest(const Interest& interest, const EndpointId& endpoint)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
++this->nInInterests;
|
||||
|
||||
afterReceiveInterest(interest);
|
||||
afterReceiveInterest(interest, endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
LinkService::receiveData(const Data& data)
|
||||
LinkService::receiveData(const Data& data, const EndpointId& endpoint)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
++this->nInData;
|
||||
|
||||
afterReceiveData(data);
|
||||
afterReceiveData(data, endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
LinkService::receiveNack(const ndn::lp::Nack& nack)
|
||||
LinkService::receiveNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
++this->nInNacks;
|
||||
|
||||
afterReceiveNack(nack);
|
||||
afterReceiveNack(nack, endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
LinkService::notifyDroppedInterest(const Interest& interest)
|
||||
{
|
||||
++this->nInterestsExceededRetx;
|
||||
onDroppedInterest(interest);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,15 +26,13 @@
|
||||
#ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP
|
||||
#define NFD_DAEMON_FACE_LINK_SERVICE_HPP
|
||||
|
||||
#include "core/counter.hpp"
|
||||
#include "face-common.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "face-log.hpp"
|
||||
#include "common/counter.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class Face;
|
||||
|
||||
/** \brief counters provided by LinkService
|
||||
* \note The type name 'LinkServiceCounters' is implementation detail.
|
||||
* Use 'LinkService::Counters' in public API.
|
||||
@@ -50,11 +48,15 @@ public:
|
||||
*/
|
||||
PacketCounter nOutInterests;
|
||||
|
||||
/** \brief count of incoming Data
|
||||
/** \brief count of Interests dropped by reliability system for exceeding allowed number of retx
|
||||
*/
|
||||
PacketCounter nInterestsExceededRetx;
|
||||
|
||||
/** \brief count of incoming Data packets
|
||||
*/
|
||||
PacketCounter nInData;
|
||||
|
||||
/** \brief count of outgoing Data
|
||||
/** \brief count of outgoing Data packets
|
||||
*/
|
||||
PacketCounter nOutData;
|
||||
|
||||
@@ -107,20 +109,23 @@ public:
|
||||
virtual const Counters&
|
||||
getCounters() const;
|
||||
|
||||
virtual ssize_t
|
||||
getEffectiveMtu() const;
|
||||
|
||||
public: // upper interface to be used by forwarding
|
||||
/** \brief send Interest
|
||||
/** \brief Send Interest
|
||||
* \pre setTransport has been called
|
||||
*/
|
||||
void
|
||||
sendInterest(const Interest& interest);
|
||||
|
||||
/** \brief send Data
|
||||
/** \brief Send Data
|
||||
* \pre setTransport has been called
|
||||
*/
|
||||
void
|
||||
sendData(const Data& data);
|
||||
|
||||
/** \brief send Nack
|
||||
/** \brief Send Nack
|
||||
* \pre setTransport has been called
|
||||
*/
|
||||
void
|
||||
@@ -128,43 +133,51 @@ public: // upper interface to be used by forwarding
|
||||
|
||||
/** \brief signals on Interest received
|
||||
*/
|
||||
signal::Signal<LinkService, Interest> afterReceiveInterest;
|
||||
signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
|
||||
|
||||
/** \brief signals on Data received
|
||||
*/
|
||||
signal::Signal<LinkService, Data> afterReceiveData;
|
||||
signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
|
||||
|
||||
/** \brief signals on Nack received
|
||||
*/
|
||||
signal::Signal<LinkService, lp::Nack> afterReceiveNack;
|
||||
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: // lower interface to be invoked by Transport
|
||||
/** \brief performs LinkService specific operations to receive a lower-layer packet
|
||||
*/
|
||||
void
|
||||
receivePacket(Transport::Packet&& packet);
|
||||
receivePacket(const Block& packet, const EndpointId& endpoint);
|
||||
|
||||
protected: // upper interface to be invoked in subclass (receive path termination)
|
||||
/** \brief delivers received Interest to forwarding
|
||||
*/
|
||||
void
|
||||
receiveInterest(const Interest& interest);
|
||||
receiveInterest(const Interest& interest, const EndpointId& endpoint);
|
||||
|
||||
/** \brief delivers received Data to forwarding
|
||||
*/
|
||||
void
|
||||
receiveData(const Data& data);
|
||||
receiveData(const Data& data, const EndpointId& endpoint);
|
||||
|
||||
/** \brief delivers received Nack to forwarding
|
||||
*/
|
||||
void
|
||||
receiveNack(const lp::Nack& nack);
|
||||
receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
|
||||
|
||||
protected: // lower interface to be invoked in subclass (send path termination)
|
||||
/** \brief sends a lower-layer packet via Transport
|
||||
/** \brief send a lower-layer packet via Transport
|
||||
*/
|
||||
void
|
||||
sendPacket(Transport::Packet&& packet);
|
||||
sendPacket(const Block& packet);
|
||||
|
||||
protected:
|
||||
void
|
||||
notifyDroppedInterest(const Interest& packet);
|
||||
|
||||
private: // upper interface to be overridden in subclass (send path entrypoint)
|
||||
/** \brief performs LinkService specific operations to send an Interest
|
||||
@@ -184,7 +197,7 @@ private: // upper interface to be overridden in subclass (send path entrypoint)
|
||||
|
||||
private: // lower interface to be overridden in subclass
|
||||
virtual void
|
||||
doReceivePacket(Transport::Packet&& packet) = 0;
|
||||
doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
|
||||
|
||||
private:
|
||||
Face* m_face;
|
||||
@@ -215,16 +228,22 @@ LinkService::getCounters() const
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void
|
||||
LinkService::receivePacket(Transport::Packet&& packet)
|
||||
inline ssize_t
|
||||
LinkService::getEffectiveMtu() const
|
||||
{
|
||||
doReceivePacket(std::move(packet));
|
||||
return m_transport->getMtu();
|
||||
}
|
||||
|
||||
inline void
|
||||
LinkService::sendPacket(Transport::Packet&& packet)
|
||||
LinkService::receivePacket(const Block& packet, const EndpointId& endpoint)
|
||||
{
|
||||
m_transport->send(std::move(packet));
|
||||
doReceivePacket(packet, endpoint);
|
||||
}
|
||||
|
||||
inline void
|
||||
LinkService::sendPacket(const Block& packet)
|
||||
{
|
||||
m_transport->send(packet);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2018, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -25,12 +25,13 @@
|
||||
|
||||
#include "lp-fragmenter.hpp"
|
||||
#include "link-service.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/tlv.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("LpFragmenter");
|
||||
NFD_LOG_INIT(LpFragmenter);
|
||||
|
||||
static_assert(lp::tlv::LpPacket < 253, "LpPacket TLV-TYPE must fit in 1 octet");
|
||||
static_assert(lp::tlv::Sequence < 253, "Sequence TLV-TYPE must fit in 1 octet");
|
||||
@@ -56,11 +57,6 @@ static const size_t MAX_FRAG_OVERHEAD =
|
||||
1 + 1 + 8 + // FragCount TLV
|
||||
1 + 9; // Fragment TLV-TYPE and TLV-LENGTH
|
||||
|
||||
LpFragmenter::Options::Options()
|
||||
: nMaxFragments(400)
|
||||
{
|
||||
}
|
||||
|
||||
LpFragmenter::LpFragmenter(const LpFragmenter::Options& options, const LinkService* linkService)
|
||||
: m_options(options)
|
||||
, m_linkService(linkService)
|
||||
@@ -121,7 +117,7 @@ LpFragmenter::fragmentPacket(const lp::Packet& packet, size_t mtu)
|
||||
// compute FragCount
|
||||
if (fragCount > m_options.nMaxFragments) {
|
||||
NFD_LOG_FACE_WARN("fragmentation error, FragCount over limit: DROP");
|
||||
return std::make_pair(false, std::vector<lp::Packet>{});
|
||||
return std::make_tuple(false, std::vector<lp::Packet>{});
|
||||
}
|
||||
|
||||
// populate fragments
|
||||
@@ -134,7 +130,7 @@ LpFragmenter::fragmentPacket(const lp::Packet& packet, size_t mtu)
|
||||
lp::Packet& frag = frags[fragIndex];
|
||||
frag.add<lp::FragIndexField>(fragIndex);
|
||||
frag.add<lp::FragCountField>(fragCount);
|
||||
frag.set<lp::FragmentField>(std::make_pair(fragBegin, fragEnd));
|
||||
frag.set<lp::FragmentField>({fragBegin, fragEnd});
|
||||
BOOST_ASSERT(frag.wireEncode().size() <= mtu);
|
||||
|
||||
++fragIndex;
|
||||
@@ -143,7 +139,7 @@ LpFragmenter::fragmentPacket(const lp::Packet& packet, size_t mtu)
|
||||
}
|
||||
BOOST_ASSERT(fragIndex == fragCount);
|
||||
|
||||
return std::make_pair(true, frags);
|
||||
return std::make_tuple(true, frags);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,36 +26,30 @@
|
||||
#ifndef NFD_DAEMON_FACE_LP_FRAGMENTER_HPP
|
||||
#define NFD_DAEMON_FACE_LP_FRAGMENTER_HPP
|
||||
|
||||
#include "face-log.hpp"
|
||||
#include "face-common.hpp"
|
||||
|
||||
#include <ndn-cxx/lp/packet.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class LinkService;
|
||||
|
||||
/** \brief fragments network-layer packets into NDNLPv2 link-layer packets
|
||||
* \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
*/
|
||||
class LpFragmenter
|
||||
{
|
||||
public:
|
||||
/** \brief Options that control the behavior of LpFragmenter
|
||||
*/
|
||||
class Options
|
||||
struct Options
|
||||
{
|
||||
public:
|
||||
Options();
|
||||
|
||||
public:
|
||||
/** \brief maximum number of fragments in a packet
|
||||
*/
|
||||
size_t nMaxFragments;
|
||||
size_t nMaxFragments = 400;
|
||||
};
|
||||
|
||||
explicit
|
||||
LpFragmenter(const Options& options = Options(), const LinkService* linkService = nullptr);
|
||||
LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
|
||||
|
||||
/** \brief set options for fragmenter
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -25,18 +25,14 @@
|
||||
|
||||
#include "lp-reassembler.hpp"
|
||||
#include "link-service.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT("LpReassembler");
|
||||
|
||||
LpReassembler::Options::Options()
|
||||
: nMaxFragments(400)
|
||||
, reassemblyTimeout(time::milliseconds(500))
|
||||
{
|
||||
}
|
||||
NFD_LOG_INIT(LpReassembler);
|
||||
|
||||
LpReassembler::LpReassembler(const LpReassembler::Options& options, const LinkService* linkService)
|
||||
: m_options(options)
|
||||
@@ -45,7 +41,7 @@ LpReassembler::LpReassembler(const LpReassembler::Options& options, const LinkSe
|
||||
}
|
||||
|
||||
std::tuple<bool, Block, lp::Packet>
|
||||
LpReassembler::receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet& packet)
|
||||
LpReassembler::receiveFragment(EndpointId remoteEndpoint, const lp::Packet& packet)
|
||||
{
|
||||
BOOST_ASSERT(packet.has<lp::FragmentField>());
|
||||
|
||||
@@ -118,8 +114,7 @@ LpReassembler::receiveFragment(Transport::EndpointId remoteEndpoint, const lp::P
|
||||
}
|
||||
|
||||
// set drop timer
|
||||
pp.dropTimer = scheduler::schedule(m_options.reassemblyTimeout,
|
||||
bind(&LpReassembler::timeoutPartialPacket, this, key));
|
||||
pp.dropTimer = getScheduler().schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
|
||||
|
||||
return FALSE_RETURN;
|
||||
}
|
||||
@@ -129,7 +124,7 @@ LpReassembler::doReassembly(const Key& key)
|
||||
{
|
||||
PartialPacket& pp = m_partialPackets[key];
|
||||
|
||||
size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0,
|
||||
size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0U,
|
||||
[&] (size_t sum, const lp::Packet& pkt) -> size_t {
|
||||
ndn::Buffer::const_iterator fragBegin, fragEnd;
|
||||
std::tie(fragBegin, fragEnd) = pkt.get<lp::FragmentField>();
|
||||
@@ -137,7 +132,7 @@ LpReassembler::doReassembly(const Key& key)
|
||||
});
|
||||
|
||||
ndn::Buffer fragBuffer(payloadSize);
|
||||
ndn::Buffer::iterator it = fragBuffer.begin();
|
||||
auto it = fragBuffer.begin();
|
||||
|
||||
for (const lp::Packet& frag : pp.fragments) {
|
||||
ndn::Buffer::const_iterator fragBegin, fragEnd;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -26,44 +26,36 @@
|
||||
#ifndef NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
|
||||
#define NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
|
||||
|
||||
#include "core/scheduler.hpp"
|
||||
#include "face-log.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "face-common.hpp"
|
||||
|
||||
#include <ndn-cxx/lp/packet.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class LinkService;
|
||||
|
||||
/** \brief reassembles fragmented network-layer packets
|
||||
* \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
*/
|
||||
class LpReassembler : noncopyable
|
||||
{
|
||||
public:
|
||||
/** \brief Options that control the behavior of LpReassembler
|
||||
*/
|
||||
class Options
|
||||
struct Options
|
||||
{
|
||||
public:
|
||||
Options();
|
||||
|
||||
public:
|
||||
/** \brief maximum number of fragments in a packet
|
||||
*
|
||||
* LpPackets with FragCount over this limit are dropped.
|
||||
*/
|
||||
size_t nMaxFragments;
|
||||
size_t nMaxFragments = 400;
|
||||
|
||||
/** \brief timeout before a partially reassembled packet is dropped
|
||||
*/
|
||||
time::nanoseconds reassemblyTimeout;
|
||||
time::nanoseconds reassemblyTimeout = 500_ms;
|
||||
};
|
||||
|
||||
explicit
|
||||
LpReassembler(const Options& options = Options(), const LinkService* linkService = nullptr);
|
||||
LpReassembler(const Options& options, const LinkService* linkService = nullptr);
|
||||
|
||||
/** \brief set options for reassembler
|
||||
*/
|
||||
@@ -77,17 +69,17 @@ public:
|
||||
const LinkService*
|
||||
getLinkService() const;
|
||||
|
||||
/** \brief adds received fragment to buffer
|
||||
* \param remoteEndpoint endpoint whose sends the packet
|
||||
* \param packet received fragment;
|
||||
* must have Fragment field
|
||||
* \return whether network-layer packet has been completely received,
|
||||
/** \brief adds received fragment to the buffer
|
||||
* \param remoteEndpoint endpoint that sent the packet
|
||||
* \param packet received fragment; must have Fragment field
|
||||
* \return a tuple containing:
|
||||
* whether a network-layer packet has been completely received,
|
||||
* the reassembled network-layer packet,
|
||||
* and the first fragment for inspecting other NDNLPv2 headers
|
||||
* the first fragment for inspecting other NDNLPv2 headers
|
||||
* \throw tlv::Error packet is malformed
|
||||
*/
|
||||
std::tuple<bool, Block, lp::Packet>
|
||||
receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet& packet);
|
||||
receiveFragment(EndpointId remoteEndpoint, const lp::Packet& packet);
|
||||
|
||||
/** \brief count of partial packets
|
||||
*/
|
||||
@@ -101,7 +93,7 @@ public:
|
||||
* Before it's erased, this signal is emitted with the remote endpoint,
|
||||
* and the number of fragments being dropped.
|
||||
*/
|
||||
signal::Signal<LpReassembler, Transport::EndpointId, size_t> beforeTimeout;
|
||||
signal::Signal<LpReassembler, EndpointId, size_t> beforeTimeout;
|
||||
|
||||
private:
|
||||
/** \brief holds all fragments of packet until reassembled
|
||||
@@ -117,7 +109,7 @@ private:
|
||||
/** \brief index key for PartialPackets
|
||||
*/
|
||||
typedef std::tuple<
|
||||
Transport::EndpointId, // remoteEndpoint
|
||||
EndpointId, // remoteEndpoint
|
||||
lp::Sequence // message identifier (sequence of the first fragment)
|
||||
> Key;
|
||||
|
||||
@@ -129,8 +121,8 @@ private:
|
||||
|
||||
private:
|
||||
Options m_options;
|
||||
std::map<Key, PartialPacket> m_partialPackets;
|
||||
const LinkService* m_linkService;
|
||||
std::map<Key, PartialPacket> m_partialPackets;
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
/* -*- 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 "lp-reliability.hpp"
|
||||
#include "generic-link-service.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(LpReliability);
|
||||
|
||||
LpReliability::LpReliability(const LpReliability::Options& options, GenericLinkService* linkService)
|
||||
: m_options(options)
|
||||
, m_linkService(linkService)
|
||||
, m_firstUnackedFrag(m_unackedFrags.begin())
|
||||
, m_lastTxSeqNo(-1) // set to "-1" to start TxSequence numbers at 0
|
||||
{
|
||||
BOOST_ASSERT(m_linkService != nullptr);
|
||||
BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns);
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::setOptions(const Options& options)
|
||||
{
|
||||
BOOST_ASSERT(options.idleAckTimerPeriod > 0_ns);
|
||||
|
||||
if (m_options.isEnabled && !options.isEnabled) {
|
||||
m_idleAckTimer.cancel();
|
||||
}
|
||||
|
||||
m_options = options;
|
||||
}
|
||||
|
||||
const GenericLinkService*
|
||||
LpReliability::getLinkService() const
|
||||
{
|
||||
return m_linkService;
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest)
|
||||
{
|
||||
BOOST_ASSERT(m_options.isEnabled);
|
||||
|
||||
auto unackedFragsIt = m_unackedFrags.begin();
|
||||
auto sendTime = time::steady_clock::now();
|
||||
|
||||
auto netPkt = make_shared<NetPkt>(std::move(pkt), isInterest);
|
||||
netPkt->unackedFrags.reserve(frags.size());
|
||||
|
||||
for (lp::Packet& frag : frags) {
|
||||
// Non-IDLE packets are required to have assigned Sequence numbers with LpReliability enabled
|
||||
BOOST_ASSERT(frag.has<lp::SequenceField>());
|
||||
|
||||
// Assign TxSequence number
|
||||
lp::Sequence txSeq = assignTxSequence(frag);
|
||||
|
||||
// Store LpPacket for future retransmissions
|
||||
unackedFragsIt = m_unackedFrags.emplace_hint(unackedFragsIt,
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(txSeq),
|
||||
std::forward_as_tuple(frag));
|
||||
unackedFragsIt->second.sendTime = sendTime;
|
||||
auto rto = m_rttEst.getEstimatedRto();
|
||||
lp::Sequence seq = frag.get<lp::SequenceField>();
|
||||
NFD_LOG_FACE_TRACE("transmitting seq=" << seq << ", txseq=" << txSeq << ", rto=" <<
|
||||
time::duration_cast<time::milliseconds>(rto).count() << "ms");
|
||||
unackedFragsIt->second.rtoTimer = getScheduler().schedule(rto, [=] {
|
||||
onLpPacketLost(txSeq, true);
|
||||
});
|
||||
unackedFragsIt->second.netPkt = netPkt;
|
||||
|
||||
if (m_unackedFrags.size() == 1) {
|
||||
m_firstUnackedFrag = m_unackedFrags.begin();
|
||||
}
|
||||
|
||||
// Add to associated NetPkt
|
||||
netPkt->unackedFrags.push_back(unackedFragsIt);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
LpReliability::processIncomingPacket(const lp::Packet& pkt)
|
||||
{
|
||||
BOOST_ASSERT(m_options.isEnabled);
|
||||
|
||||
bool isDuplicate = false;
|
||||
auto now = time::steady_clock::now();
|
||||
|
||||
// Extract and parse Acks
|
||||
for (lp::Sequence ackTxSeq : pkt.list<lp::AckField>()) {
|
||||
auto fragIt = m_unackedFrags.find(ackTxSeq);
|
||||
if (fragIt == m_unackedFrags.end()) {
|
||||
// Ignore an Ack for an unknown TxSequence number
|
||||
NFD_LOG_FACE_DEBUG("received ack for unknown txseq=" << ackTxSeq);
|
||||
continue;
|
||||
}
|
||||
auto& frag = fragIt->second;
|
||||
|
||||
// Cancel the RTO timer for the acknowledged fragment
|
||||
frag.rtoTimer.cancel();
|
||||
|
||||
if (frag.retxCount == 0) {
|
||||
NFD_LOG_FACE_TRACE("received ack for seq=" << frag.pkt.get<lp::SequenceField>() << ", txseq=" <<
|
||||
ackTxSeq << ", retx=0, rtt=" <<
|
||||
time::duration_cast<time::milliseconds>(now - frag.sendTime).count() << "ms");
|
||||
// This sequence had no retransmissions, so use it to estimate the RTO
|
||||
m_rttEst.addMeasurement(now - frag.sendTime);
|
||||
}
|
||||
else {
|
||||
NFD_LOG_FACE_TRACE("received ack for seq=" << frag.pkt.get<lp::SequenceField>() << ", txseq=" <<
|
||||
ackTxSeq << ", retx=" << frag.retxCount);
|
||||
}
|
||||
|
||||
// Look for frags with TxSequence numbers < ackTxSeq (allowing for wraparound) and consider
|
||||
// them lost if a configurable number of Acks containing greater TxSequence numbers have been
|
||||
// received.
|
||||
auto lostLpPackets = findLostLpPackets(fragIt);
|
||||
|
||||
// Remove the fragment from the map of unacknowledged fragments and from its associated network
|
||||
// packet. Potentially increment the start of the window.
|
||||
onLpPacketAcknowledged(fragIt);
|
||||
|
||||
// This set contains TxSequences that have been removed by onLpPacketLost below because they
|
||||
// were part of a network packet that was removed due to a fragment exceeding retx, as well as
|
||||
// any other TxSequences removed by onLpPacketLost. This prevents onLpPacketLost from being
|
||||
// called later for an invalid iterator.
|
||||
std::set<lp::Sequence> removedLpPackets;
|
||||
|
||||
// Resend or fail fragments considered lost. Potentially increment the start of the window.
|
||||
for (lp::Sequence txSeq : lostLpPackets) {
|
||||
if (removedLpPackets.find(txSeq) == removedLpPackets.end()) {
|
||||
auto removedTxSeqs = onLpPacketLost(txSeq, false);
|
||||
for (auto removedTxSeq : removedTxSeqs) {
|
||||
removedLpPackets.insert(removedTxSeq);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If packet has Fragment and TxSequence fields, extract TxSequence and add to AckQueue
|
||||
if (pkt.has<lp::FragmentField>() && pkt.has<lp::TxSequenceField>()) {
|
||||
NFD_LOG_FACE_TRACE("queueing ack for remote txseq=" << pkt.get<lp::TxSequenceField>());
|
||||
m_ackQueue.push(pkt.get<lp::TxSequenceField>());
|
||||
|
||||
// Check for received frames with duplicate Sequences
|
||||
if (pkt.has<lp::SequenceField>()) {
|
||||
lp::Sequence pktSequence = pkt.get<lp::SequenceField>();
|
||||
isDuplicate = m_recentRecvSeqs.count(pktSequence) > 0;
|
||||
// Check for recent received Sequences to remove
|
||||
auto now = time::steady_clock::now();
|
||||
auto rto = m_rttEst.getEstimatedRto();
|
||||
while (m_recentRecvSeqsQueue.size() > 0 &&
|
||||
now > m_recentRecvSeqs[m_recentRecvSeqsQueue.front()] + rto) {
|
||||
m_recentRecvSeqs.erase(m_recentRecvSeqsQueue.front());
|
||||
m_recentRecvSeqsQueue.pop();
|
||||
}
|
||||
m_recentRecvSeqs.emplace(pktSequence, now);
|
||||
m_recentRecvSeqsQueue.push(pktSequence);
|
||||
}
|
||||
|
||||
startIdleAckTimer();
|
||||
}
|
||||
|
||||
return !isDuplicate;
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::piggyback(lp::Packet& pkt, ssize_t mtu)
|
||||
{
|
||||
BOOST_ASSERT(m_options.isEnabled);
|
||||
BOOST_ASSERT(pkt.wireEncode().type() == lp::tlv::LpPacket);
|
||||
|
||||
// up to 2 extra octets reserved for potential TLV-LENGTH size increases
|
||||
ssize_t pktSize = pkt.wireEncode().size();
|
||||
ssize_t reservedSpace = tlv::sizeOfVarNumber(ndn::MAX_NDN_PACKET_SIZE) -
|
||||
tlv::sizeOfVarNumber(pktSize);
|
||||
ssize_t remainingSpace = (mtu == MTU_UNLIMITED ? ndn::MAX_NDN_PACKET_SIZE : mtu) - reservedSpace;
|
||||
remainingSpace -= pktSize;
|
||||
|
||||
while (!m_ackQueue.empty()) {
|
||||
lp::Sequence ackTxSeq = m_ackQueue.front();
|
||||
// Ack size = Ack TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
|
||||
const ssize_t ackSize = tlv::sizeOfVarNumber(lp::tlv::Ack) +
|
||||
tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
|
||||
sizeof(lp::Sequence);
|
||||
|
||||
if (ackSize > remainingSpace) {
|
||||
break;
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_TRACE("piggybacking ack for remote txseq=" << ackTxSeq);
|
||||
|
||||
pkt.add<lp::AckField>(ackTxSeq);
|
||||
m_ackQueue.pop();
|
||||
remainingSpace -= ackSize;
|
||||
}
|
||||
}
|
||||
|
||||
lp::Sequence
|
||||
LpReliability::assignTxSequence(lp::Packet& frag)
|
||||
{
|
||||
lp::Sequence txSeq = ++m_lastTxSeqNo;
|
||||
frag.set<lp::TxSequenceField>(txSeq);
|
||||
if (m_unackedFrags.size() > 0 && m_lastTxSeqNo == m_firstUnackedFrag->first) {
|
||||
NDN_THROW(std::length_error("TxSequence range exceeded"));
|
||||
}
|
||||
return m_lastTxSeqNo;
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::startIdleAckTimer()
|
||||
{
|
||||
if (m_idleAckTimer) {
|
||||
// timer is already running, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
m_idleAckTimer = getScheduler().schedule(m_options.idleAckTimerPeriod, [this] {
|
||||
while (!m_ackQueue.empty()) {
|
||||
m_linkService->requestIdlePacket();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<lp::Sequence>
|
||||
LpReliability::findLostLpPackets(LpReliability::UnackedFrags::iterator ackIt)
|
||||
{
|
||||
std::vector<lp::Sequence> lostLpPackets;
|
||||
|
||||
for (auto it = m_firstUnackedFrag; ; ++it) {
|
||||
if (it == m_unackedFrags.end()) {
|
||||
it = m_unackedFrags.begin();
|
||||
}
|
||||
|
||||
if (it->first == ackIt->first) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto& unackedFrag = it->second;
|
||||
unackedFrag.nGreaterSeqAcks++;
|
||||
NFD_LOG_FACE_TRACE("received ack=" << ackIt->first << " before=" << it->first <<
|
||||
", before count=" << unackedFrag.nGreaterSeqAcks);
|
||||
|
||||
if (unackedFrag.nGreaterSeqAcks >= m_options.seqNumLossThreshold) {
|
||||
lostLpPackets.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
return lostLpPackets;
|
||||
}
|
||||
|
||||
std::vector<lp::Sequence>
|
||||
LpReliability::onLpPacketLost(lp::Sequence txSeq, bool isTimeout)
|
||||
{
|
||||
BOOST_ASSERT(m_unackedFrags.count(txSeq) > 0);
|
||||
auto txSeqIt = m_unackedFrags.find(txSeq);
|
||||
|
||||
auto& txFrag = txSeqIt->second;
|
||||
txFrag.rtoTimer.cancel();
|
||||
auto netPkt = txFrag.netPkt;
|
||||
std::vector<lp::Sequence> removedThisTxSeq;
|
||||
lp::Sequence seq = txFrag.pkt.get<lp::SequenceField>();
|
||||
|
||||
if (isTimeout) {
|
||||
NFD_LOG_FACE_TRACE("rto timer expired for seq=" << seq << ", txseq=" << txSeq);
|
||||
}
|
||||
else { // lost due to out-of-order TxSeqs
|
||||
NFD_LOG_FACE_TRACE("seq=" << seq << ", txseq=" << txSeq <<
|
||||
" considered lost from acks for more recent txseqs");
|
||||
}
|
||||
|
||||
// Check if maximum number of retransmissions exceeded
|
||||
if (txFrag.retxCount >= m_options.maxRetx) {
|
||||
NFD_LOG_FACE_DEBUG("seq=" << seq << " exceeded allowed retransmissions: DROP");
|
||||
// Delete all LpPackets of NetPkt from m_unackedFrags (except this one)
|
||||
for (size_t i = 0; i < netPkt->unackedFrags.size(); i++) {
|
||||
if (netPkt->unackedFrags[i] != txSeqIt) {
|
||||
removedThisTxSeq.push_back(netPkt->unackedFrags[i]->first);
|
||||
deleteUnackedFrag(netPkt->unackedFrags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
++m_linkService->nRetxExhausted;
|
||||
|
||||
// Notify strategy of dropped Interest (if any)
|
||||
if (netPkt->isInterest) {
|
||||
BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>());
|
||||
ndn::Buffer::const_iterator fragBegin, fragEnd;
|
||||
std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>();
|
||||
Block frag(&*fragBegin, std::distance(fragBegin, fragEnd));
|
||||
onDroppedInterest(Interest(frag));
|
||||
}
|
||||
|
||||
// Delete this LpPacket from m_unackedFrags
|
||||
removedThisTxSeq.push_back(txSeqIt->first);
|
||||
deleteUnackedFrag(txSeqIt);
|
||||
}
|
||||
else {
|
||||
// Assign new TxSequence
|
||||
lp::Sequence newTxSeq = assignTxSequence(txFrag.pkt);
|
||||
netPkt->didRetx = true;
|
||||
|
||||
// Move fragment to new TxSequence mapping
|
||||
auto newTxFragIt = m_unackedFrags.emplace_hint(
|
||||
m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq
|
||||
? m_firstUnackedFrag
|
||||
: m_unackedFrags.end(),
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(newTxSeq),
|
||||
std::forward_as_tuple(txFrag.pkt));
|
||||
auto& newTxFrag = newTxFragIt->second;
|
||||
newTxFrag.retxCount = txFrag.retxCount + 1;
|
||||
newTxFrag.netPkt = netPkt;
|
||||
|
||||
// Update associated NetPkt
|
||||
auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), txSeqIt);
|
||||
BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end());
|
||||
*fragInNetPkt = newTxFragIt;
|
||||
|
||||
removedThisTxSeq.push_back(txSeqIt->first);
|
||||
deleteUnackedFrag(txSeqIt);
|
||||
|
||||
// Retransmit fragment
|
||||
m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt));
|
||||
|
||||
auto rto = m_rttEst.getEstimatedRto();
|
||||
NFD_LOG_FACE_TRACE("retransmitting seq=" << seq << ", txseq=" << newTxSeq << ", retx=" <<
|
||||
txFrag.retxCount << ", rto=" <<
|
||||
time::duration_cast<time::milliseconds>(rto).count() << "ms");
|
||||
|
||||
// Start RTO timer for this sequence
|
||||
newTxFrag.rtoTimer = getScheduler().schedule(rto, [=] {
|
||||
onLpPacketLost(newTxSeq, true);
|
||||
});
|
||||
}
|
||||
|
||||
return removedThisTxSeq;
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::onLpPacketAcknowledged(UnackedFrags::iterator fragIt)
|
||||
{
|
||||
auto netPkt = fragIt->second.netPkt;
|
||||
|
||||
// Remove from NetPkt unacked fragment list
|
||||
auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), fragIt);
|
||||
BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end());
|
||||
*fragInNetPkt = netPkt->unackedFrags.back();
|
||||
netPkt->unackedFrags.pop_back();
|
||||
|
||||
// Check if network-layer packet completely received. If so, increment counters
|
||||
if (netPkt->unackedFrags.empty()) {
|
||||
if (netPkt->didRetx) {
|
||||
++m_linkService->nRetransmitted;
|
||||
}
|
||||
else {
|
||||
++m_linkService->nAcknowledged;
|
||||
}
|
||||
}
|
||||
|
||||
deleteUnackedFrag(fragIt);
|
||||
}
|
||||
|
||||
void
|
||||
LpReliability::deleteUnackedFrag(UnackedFrags::iterator fragIt)
|
||||
{
|
||||
lp::Sequence firstUnackedTxSeq = m_firstUnackedFrag->first;
|
||||
lp::Sequence currentTxSeq = fragIt->first;
|
||||
auto nextFragIt = m_unackedFrags.erase(fragIt);
|
||||
|
||||
if (!m_unackedFrags.empty() && firstUnackedTxSeq == currentTxSeq) {
|
||||
// If "first" fragment in send window (allowing for wraparound), increment window begin
|
||||
if (nextFragIt == m_unackedFrags.end()) {
|
||||
m_firstUnackedFrag = m_unackedFrags.begin();
|
||||
}
|
||||
else {
|
||||
m_firstUnackedFrag = nextFragIt;
|
||||
}
|
||||
}
|
||||
else if (m_unackedFrags.empty()) {
|
||||
m_firstUnackedFrag = m_unackedFrags.end();
|
||||
}
|
||||
}
|
||||
|
||||
LpReliability::UnackedFrag::UnackedFrag(lp::Packet pkt)
|
||||
: pkt(std::move(pkt))
|
||||
, sendTime(time::steady_clock::now())
|
||||
, retxCount(0)
|
||||
, nGreaterSeqAcks(0)
|
||||
{
|
||||
}
|
||||
|
||||
LpReliability::NetPkt::NetPkt(lp::Packet&& pkt, bool isInterest)
|
||||
: pkt(std::move(pkt))
|
||||
, isInterest(isInterest)
|
||||
, didRetx(false)
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceLogHelper<LpReliability>& flh)
|
||||
{
|
||||
if (flh.obj.getLinkService() == nullptr) {
|
||||
os << "[id=0,local=unknown,remote=unknown] ";
|
||||
}
|
||||
else {
|
||||
os << FaceLogHelper<LinkService>(*flh.obj.getLinkService());
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,227 @@
|
||||
/* -*- 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_LP_RELIABILITY_HPP
|
||||
#define NFD_DAEMON_FACE_LP_RELIABILITY_HPP
|
||||
|
||||
#include "face-common.hpp"
|
||||
|
||||
#include <ndn-cxx/lp/packet.hpp>
|
||||
#include <ndn-cxx/lp/sequence.hpp>
|
||||
#include <ndn-cxx/util/rtt-estimator.hpp>
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class GenericLinkService;
|
||||
|
||||
/** \brief provides for reliable sending and receiving of link-layer packets
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
|
||||
*/
|
||||
class LpReliability : noncopyable
|
||||
{
|
||||
public:
|
||||
struct Options
|
||||
{
|
||||
/** \brief enables link-layer reliability
|
||||
*/
|
||||
bool isEnabled = false;
|
||||
|
||||
/** \brief maximum number of retransmissions for an LpPacket
|
||||
*/
|
||||
size_t maxRetx = 3;
|
||||
|
||||
/** \brief period between sending pending Acks in an IDLE packet
|
||||
*/
|
||||
time::nanoseconds idleAckTimerPeriod = 5_ms;
|
||||
|
||||
/** \brief a fragment is considered lost if this number of fragments with greater sequence
|
||||
* numbers are acknowledged
|
||||
*/
|
||||
size_t seqNumLossThreshold = 3;
|
||||
};
|
||||
|
||||
LpReliability(const Options& options, GenericLinkService* linkService);
|
||||
|
||||
/** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
|
||||
*/
|
||||
signal::Signal<LpReliability, Interest> onDroppedInterest;
|
||||
|
||||
/** \brief set options for reliability
|
||||
*/
|
||||
void
|
||||
setOptions(const Options& options);
|
||||
|
||||
/** \return GenericLinkService that owns this instance
|
||||
*
|
||||
* This is only used for logging, and may be nullptr.
|
||||
*/
|
||||
const GenericLinkService*
|
||||
getLinkService() const;
|
||||
|
||||
/** \brief observe outgoing fragment(s) of a network packet and store for potential retransmission
|
||||
* \param frags fragments of network packet
|
||||
* \param pkt encapsulated network packet
|
||||
* \param isInterest whether the network packet is an Interest
|
||||
*/
|
||||
void
|
||||
handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest);
|
||||
|
||||
/** \brief extract and parse all Acks and add Ack for contained Fragment (if any) to AckQueue
|
||||
* \param pkt incoming LpPacket
|
||||
* \return whether incoming LpPacket is new and not a duplicate
|
||||
*/
|
||||
bool
|
||||
processIncomingPacket(const lp::Packet& pkt);
|
||||
|
||||
/** \brief called by GenericLinkService to attach Acks onto an outgoing LpPacket
|
||||
* \param pkt outgoing LpPacket to attach Acks to
|
||||
* \param mtu MTU of the Transport
|
||||
*/
|
||||
void
|
||||
piggyback(lp::Packet& pkt, ssize_t mtu);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
class UnackedFrag;
|
||||
class NetPkt;
|
||||
using UnackedFrags = std::map<lp::Sequence, UnackedFrag>;
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
/** \brief assign TxSequence number to a fragment
|
||||
* \param frag fragment to assign TxSequence to
|
||||
* \return assigned TxSequence number
|
||||
* \throw std::length_error assigned TxSequence is equal to the start of the existing window
|
||||
*/
|
||||
lp::Sequence
|
||||
assignTxSequence(lp::Packet& frag);
|
||||
|
||||
/** \brief start the idle Ack timer
|
||||
*
|
||||
* This timer requests an IDLE packet to acknowledge pending fragments not already piggybacked.
|
||||
* It is called regularly on a period configured in Options::idleAckTimerPeriod. This allows Acks
|
||||
* to be returned to the sender, even if the link goes idle.
|
||||
*/
|
||||
void
|
||||
startIdleAckTimer();
|
||||
|
||||
/** \brief find and mark as lost fragments where a configurable number of Acks
|
||||
* (\p m_options.seqNumLossThreshold) have been received for greater TxSequence numbers
|
||||
* \param ackIt iterator pointing to acknowledged fragment
|
||||
* \return vector containing TxSequences of fragments marked lost by this mechanism
|
||||
*/
|
||||
std::vector<lp::Sequence>
|
||||
findLostLpPackets(UnackedFrags::iterator ackIt);
|
||||
|
||||
/** \brief resend (or give up on) a lost fragment
|
||||
* \return vector of the TxSequences of fragments removed due to a network packet being removed
|
||||
*/
|
||||
std::vector<lp::Sequence>
|
||||
onLpPacketLost(lp::Sequence txSeq, bool isTimeout);
|
||||
|
||||
/** \brief remove the fragment with the given sequence number from the map of unacknowledged
|
||||
* fragments, as well as its associated network packet (if any)
|
||||
* \param fragIt iterator to acknowledged fragment
|
||||
*
|
||||
* If the given TxSequence marks the beginning of the send window, the window will be incremented.
|
||||
* If the associated network packet has been fully transmitted, it will be removed.
|
||||
*/
|
||||
void
|
||||
onLpPacketAcknowledged(UnackedFrags::iterator fragIt);
|
||||
|
||||
/** \brief delete a fragment from UnackedFrags and advance acknowledge window if necessary
|
||||
* \param fragIt iterator to an UnackedFrag, must be dereferencable
|
||||
* \post fragIt is not in m_unackedFrags
|
||||
* \post if was equal to m_firstUnackedFrag,
|
||||
* m_firstUnackedFrag is set to the UnackedFrag after fragIt with consideration of
|
||||
* TxSequence number wraparound, or set to m_unackedFrags.end() if m_unackedFrags is empty
|
||||
*/
|
||||
void
|
||||
deleteUnackedFrag(UnackedFrags::iterator fragIt);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
/** \brief contains a sent fragment that has not been acknowledged and associated data
|
||||
*/
|
||||
class UnackedFrag
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
UnackedFrag(lp::Packet pkt);
|
||||
|
||||
public:
|
||||
lp::Packet pkt;
|
||||
scheduler::ScopedEventId rtoTimer;
|
||||
time::steady_clock::TimePoint sendTime;
|
||||
size_t retxCount;
|
||||
size_t nGreaterSeqAcks; //!< number of Acks received for sequences greater than this fragment
|
||||
shared_ptr<NetPkt> netPkt;
|
||||
};
|
||||
|
||||
/** \brief contains a network-layer packet with unacknowledged fragments
|
||||
*/
|
||||
class NetPkt
|
||||
{
|
||||
public:
|
||||
NetPkt(lp::Packet&& pkt, bool isInterest);
|
||||
|
||||
public:
|
||||
std::vector<UnackedFrags::iterator> unackedFrags;
|
||||
lp::Packet pkt;
|
||||
bool isInterest;
|
||||
bool didRetx;
|
||||
};
|
||||
|
||||
public:
|
||||
/// TxSequence TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
|
||||
static constexpr size_t RESERVED_HEADER_SPACE = tlv::sizeOfVarNumber(lp::tlv::TxSequence) +
|
||||
tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
|
||||
sizeof(lp::Sequence);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
Options m_options;
|
||||
GenericLinkService* m_linkService;
|
||||
UnackedFrags m_unackedFrags;
|
||||
/** An iterator that points to the first unacknowledged fragment in the current window. The window
|
||||
* can wrap around so that the beginning of the window is at a TxSequence greater than other
|
||||
* fragments in the window. When the window is moved past the last item in the iterator, the
|
||||
* first fragment in the map will become the start of the window.
|
||||
*/
|
||||
UnackedFrags::iterator m_firstUnackedFrag;
|
||||
std::queue<lp::Sequence> m_ackQueue;
|
||||
std::map<lp::Sequence, time::steady_clock::TimePoint> m_recentRecvSeqs;
|
||||
std::queue<lp::Sequence> m_recentRecvSeqsQueue;
|
||||
lp::Sequence m_lastTxSeqNo;
|
||||
scheduler::ScopedEventId m_idleAckTimer;
|
||||
ndn::util::RttEstimator m_rttEst;
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceLogHelper<LpReliability>& flh);
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_LP_RELIABILITY_HPP
|
||||
@@ -0,0 +1,151 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "multicast-ethernet-transport.hpp"
|
||||
#include "common/global.hpp"
|
||||
|
||||
#include <cerrno> // for errno
|
||||
#include <cstring> // for memcpy(), strerror(), strncpy()
|
||||
#include <net/if.h> // for struct ifreq
|
||||
#include <stdio.h> // for snprintf()
|
||||
#include <sys/ioctl.h> // for ioctl()
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <netpacket/packet.h> // for struct packet_mreq
|
||||
#include <sys/socket.h> // for setsockopt()
|
||||
#endif
|
||||
|
||||
#ifdef SIOCADDMULTI
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <net/if_dl.h> // for struct sockaddr_dl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(MulticastEthernetTransport);
|
||||
|
||||
MulticastEthernetTransport::MulticastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& mcastAddress,
|
||||
ndn::nfd::LinkType linkType)
|
||||
: EthernetTransport(localEndpoint, mcastAddress)
|
||||
#if defined(__linux__)
|
||||
, m_interfaceIndex(localEndpoint.getIndex())
|
||||
#endif
|
||||
{
|
||||
this->setLocalUri(FaceUri::fromDev(m_interfaceName));
|
||||
this->setRemoteUri(FaceUri(m_destAddress));
|
||||
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
|
||||
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
|
||||
this->setLinkType(linkType);
|
||||
this->setMtu(localEndpoint.getMtu());
|
||||
|
||||
NFD_LOG_FACE_DEBUG("Creating transport");
|
||||
|
||||
char filter[110];
|
||||
// note #1: we cannot use std::snprintf because it's not available
|
||||
// on some platforms (see #2299)
|
||||
// note #2: "not vlan" must appear last in the filter expression, or the
|
||||
// rest of the filter won't work as intended (see pcap-filter(7))
|
||||
snprintf(filter, sizeof(filter),
|
||||
"(ether proto 0x%x) && (ether dst %s) && (not ether src %s) && (not vlan)",
|
||||
ethernet::ETHERTYPE_NDN,
|
||||
m_destAddress.toString().data(),
|
||||
m_srcAddress.toString().data());
|
||||
m_pcap.setPacketFilter(filter);
|
||||
|
||||
BOOST_ASSERT(m_destAddress.isMulticast());
|
||||
if (!m_destAddress.isBroadcast())
|
||||
joinMulticastGroup();
|
||||
}
|
||||
|
||||
void
|
||||
MulticastEthernetTransport::joinMulticastGroup()
|
||||
{
|
||||
#if defined(__linux__)
|
||||
packet_mreq mr{};
|
||||
mr.mr_ifindex = m_interfaceIndex;
|
||||
mr.mr_type = PACKET_MR_MULTICAST;
|
||||
mr.mr_alen = m_destAddress.size();
|
||||
std::memcpy(mr.mr_address, m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
if (::setsockopt(m_socket.native_handle(), SOL_PACKET,
|
||||
PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == 0)
|
||||
return; // success
|
||||
|
||||
NFD_LOG_FACE_WARN("setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
|
||||
#endif
|
||||
|
||||
#if defined(SIOCADDMULTI)
|
||||
ifreq ifr{};
|
||||
std::strncpy(ifr.ifr_name, m_interfaceName.data(), sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
// see bug #2327
|
||||
using boost::asio::ip::udp;
|
||||
udp::socket sock(getGlobalIoService(), udp::v4());
|
||||
int fd = sock.native_handle();
|
||||
|
||||
// Differences between Linux and the BSDs (including macOS):
|
||||
// o BSD does not have ifr_hwaddr; use ifr_addr instead.
|
||||
// o While macOS seems to accept both AF_LINK and AF_UNSPEC as the address
|
||||
// family, FreeBSD explicitly requires AF_LINK, so we have to use AF_LINK
|
||||
// and sockaddr_dl instead of the generic sockaddr structure.
|
||||
// o BSD's sockaddr (and sockaddr_dl in particular) contains an additional
|
||||
// field, sa_len (sdl_len), which must be set to the total length of the
|
||||
// structure, including the length field itself.
|
||||
// o We do not specify the interface name, thus sdl_nlen is left at 0 and
|
||||
// LLADDR is effectively the same as sdl_data.
|
||||
|
||||
sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(&ifr.ifr_addr);
|
||||
sdl->sdl_len = sizeof(ifr.ifr_addr);
|
||||
sdl->sdl_family = AF_LINK;
|
||||
sdl->sdl_alen = m_destAddress.size();
|
||||
std::memcpy(LLADDR(sdl), m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
static_assert(sizeof(ifr.ifr_addr) >= offsetof(sockaddr_dl, sdl_data) + ethernet::ADDR_LEN,
|
||||
"ifr_addr in struct ifreq is too small on this platform");
|
||||
#else
|
||||
int fd = m_socket.native_handle();
|
||||
|
||||
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
|
||||
std::memcpy(ifr.ifr_hwaddr.sa_data, m_destAddress.data(), m_destAddress.size());
|
||||
|
||||
static_assert(sizeof(ifr.ifr_hwaddr.sa_data) >= ethernet::ADDR_LEN,
|
||||
"ifr_hwaddr in struct ifreq is too small on this platform");
|
||||
#endif
|
||||
|
||||
if (::ioctl(fd, SIOCADDMULTI, &ifr) == 0)
|
||||
return; // success
|
||||
|
||||
NFD_LOG_FACE_WARN("ioctl(SIOCADDMULTI) failed: " << std::strerror(errno));
|
||||
#endif
|
||||
|
||||
NDN_THROW(Error("Failed to join multicast group"));
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* 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_MULTICAST_ETHERNET_TRANSPORT_HPP
|
||||
#define NFD_DAEMON_FACE_MULTICAST_ETHERNET_TRANSPORT_HPP
|
||||
|
||||
#include "ethernet-transport.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
/**
|
||||
* @brief A multicast Transport that uses raw Ethernet II frames
|
||||
*/
|
||||
class MulticastEthernetTransport final : public EthernetTransport
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates an Ethernet-based transport for multicast communication
|
||||
*/
|
||||
MulticastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
|
||||
const ethernet::Address& mcastAddress,
|
||||
ndn::nfd::LinkType linkType);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Enables receiving frames addressed to our MAC multicast group
|
||||
*/
|
||||
void
|
||||
joinMulticastGroup();
|
||||
|
||||
private:
|
||||
#if defined(__linux__)
|
||||
int m_interfaceIndex;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_MULTICAST_ETHERNET_TRANSPORT_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -24,42 +24,73 @@
|
||||
*/
|
||||
|
||||
#include "multicast-udp-transport.hpp"
|
||||
#include "socket-utils.hpp"
|
||||
#include "udp-protocol.hpp"
|
||||
|
||||
#include "common/privilege-helper.hpp"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <cerrno> // for errno
|
||||
#include <cstring> // for std::strerror()
|
||||
#include <sys/socket.h> // for setsockopt()
|
||||
#endif // __linux__
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(DatagramTransport, MulticastUdpTransport::protocol,
|
||||
Multicast, "MulticastUdpTransport");
|
||||
NFD_LOG_MEMBER_INIT_SPECIALIZED((DatagramTransport<boost::asio::ip::udp, Multicast>), MulticastUdpTransport);
|
||||
|
||||
MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& localEndpoint,
|
||||
const protocol::endpoint& multicastGroup,
|
||||
MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& multicastGroup,
|
||||
protocol::socket&& recvSocket,
|
||||
protocol::socket&& sendSocket)
|
||||
protocol::socket&& sendSocket,
|
||||
ndn::nfd::LinkType linkType)
|
||||
: DatagramTransport(std::move(recvSocket))
|
||||
, m_multicastGroup(multicastGroup)
|
||||
, m_sendSocket(std::move(sendSocket))
|
||||
{
|
||||
this->setLocalUri(FaceUri(localEndpoint));
|
||||
this->setLocalUri(FaceUri(m_sendSocket.local_endpoint()));
|
||||
this->setRemoteUri(FaceUri(multicastGroup));
|
||||
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
|
||||
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
|
||||
this->setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
|
||||
this->setMtu(udp::computeMtu(localEndpoint));
|
||||
this->setLinkType(linkType);
|
||||
this->setMtu(udp::computeMtu(m_sendSocket.local_endpoint()));
|
||||
|
||||
NFD_LOG_FACE_INFO("Creating transport");
|
||||
protocol::socket::send_buffer_size sendBufferSizeOption;
|
||||
boost::system::error_code error;
|
||||
m_sendSocket.get_option(sendBufferSizeOption);
|
||||
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());
|
||||
}
|
||||
|
||||
NFD_LOG_FACE_DEBUG("Creating transport");
|
||||
}
|
||||
|
||||
ssize_t
|
||||
MulticastUdpTransport::getSendQueueLength()
|
||||
{
|
||||
ssize_t queueLength = getTxQueueLength(m_sendSocket.native_handle());
|
||||
if (queueLength == QUEUE_ERROR) {
|
||||
NFD_LOG_FACE_WARN("Failed to obtain send queue length from socket: " << std::strerror(errno));
|
||||
}
|
||||
return queueLength;
|
||||
}
|
||||
|
||||
void
|
||||
MulticastUdpTransport::doSend(Transport::Packet&& packet)
|
||||
MulticastUdpTransport::doSend(const Block& packet)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE(__func__);
|
||||
|
||||
m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
|
||||
bind(&MulticastUdpTransport::handleSend, this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred,
|
||||
packet.packet));
|
||||
m_sendSocket.async_send_to(boost::asio::buffer(packet), m_multicastGroup,
|
||||
// 'packet' is copied into the lambda to retain the underlying Buffer
|
||||
[this, packet] (auto&&... args) {
|
||||
this->handleSend(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -78,15 +109,102 @@ MulticastUdpTransport::doClose()
|
||||
DatagramTransport::doClose();
|
||||
}
|
||||
|
||||
static void
|
||||
bindToDevice(int fd, const std::string& ifname)
|
||||
{
|
||||
// On Linux, if there is more than one MulticastUdpTransport for the same multicast
|
||||
// group but they are on different network interfaces, each socket needs to be bound
|
||||
// to the corresponding interface using SO_BINDTODEVICE, otherwise the transport will
|
||||
// receive all packets sent to the other interfaces as well.
|
||||
// This is needed only on Linux. On macOS, the boost::asio::ip::multicast::join_group
|
||||
// option is sufficient to obtain the desired behavior.
|
||||
// We dont't set SO_BINDTODEVICE on Android because this operation requires root privilege
|
||||
// which is not allowed on Android, it will cause "Operation not permitted" error.
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
PrivilegeHelper::runElevated([=] {
|
||||
if (::setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname.data(), ifname.size() + 1) < 0) {
|
||||
NDN_THROW_ERRNO(MulticastUdpTransport::Error("Cannot bind multicast rx socket to " + ifname));
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
MulticastUdpTransport::openRxSocket(protocol::socket& sock,
|
||||
const protocol::endpoint& multicastGroup,
|
||||
const boost::asio::ip::address& localAddress,
|
||||
const shared_ptr<const ndn::net::NetworkInterface>& netif)
|
||||
{
|
||||
BOOST_ASSERT(!sock.is_open());
|
||||
|
||||
sock.open(multicastGroup.protocol());
|
||||
sock.set_option(protocol::socket::reuse_address(true));
|
||||
|
||||
if (multicastGroup.address().is_v4()) {
|
||||
BOOST_ASSERT(localAddress.is_v4());
|
||||
sock.bind(multicastGroup);
|
||||
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v4(),
|
||||
localAddress.to_v4()));
|
||||
}
|
||||
else {
|
||||
BOOST_ASSERT(localAddress.is_v6());
|
||||
sock.set_option(boost::asio::ip::v6_only(true));
|
||||
#ifdef WITH_TESTS
|
||||
// To simplify unit tests, we bind to the "any" IPv6 address if the supplied multicast
|
||||
// address lacks a scope id. Calling bind() without a scope id would otherwise fail.
|
||||
if (multicastGroup.address().to_v6().scope_id() == 0)
|
||||
sock.bind(protocol::endpoint(boost::asio::ip::address_v6::any(), multicastGroup.port()));
|
||||
else
|
||||
#endif
|
||||
sock.bind(multicastGroup);
|
||||
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v6()));
|
||||
}
|
||||
|
||||
if (netif)
|
||||
bindToDevice(sock.native_handle(), netif->getName());
|
||||
}
|
||||
|
||||
void
|
||||
MulticastUdpTransport::openTxSocket(protocol::socket& sock,
|
||||
const protocol::endpoint& localEndpoint,
|
||||
const shared_ptr<const ndn::net::NetworkInterface>& netif,
|
||||
bool enableLoopback)
|
||||
{
|
||||
BOOST_ASSERT(!sock.is_open());
|
||||
|
||||
sock.open(localEndpoint.protocol());
|
||||
sock.set_option(protocol::socket::reuse_address(true));
|
||||
sock.set_option(boost::asio::ip::multicast::enable_loopback(enableLoopback));
|
||||
|
||||
if (localEndpoint.address().is_v4()) {
|
||||
sock.bind(localEndpoint);
|
||||
if (!localEndpoint.address().is_unspecified())
|
||||
sock.set_option(boost::asio::ip::multicast::outbound_interface(localEndpoint.address().to_v4()));
|
||||
}
|
||||
else {
|
||||
sock.set_option(boost::asio::ip::v6_only(true));
|
||||
sock.bind(localEndpoint);
|
||||
if (netif)
|
||||
sock.set_option(boost::asio::ip::multicast::outbound_interface(netif->getIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
Transport::EndpointId
|
||||
EndpointId
|
||||
DatagramTransport<boost::asio::ip::udp, Multicast>::makeEndpointId(const protocol::endpoint& ep)
|
||||
{
|
||||
// IPv6 multicast is not supported
|
||||
BOOST_ASSERT(ep.address().is_v4());
|
||||
|
||||
return (static_cast<uint64_t>(ep.port()) << 32) |
|
||||
static_cast<uint64_t>(ep.address().to_v4().to_ulong());
|
||||
if (ep.address().is_v4()) {
|
||||
return (static_cast<uint64_t>(ep.port()) << 32) |
|
||||
static_cast<uint64_t>(ep.address().to_v4().to_ulong());
|
||||
}
|
||||
else {
|
||||
size_t seed = 0;
|
||||
const auto& addrBytes = ep.address().to_v6().to_bytes();
|
||||
boost::hash_range(seed, addrBytes.begin(), addrBytes.end());
|
||||
boost::hash_combine(seed, ep.port());
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -28,15 +28,19 @@
|
||||
|
||||
#include "datagram-transport.hpp"
|
||||
|
||||
#include <ndn-cxx/net/network-interface.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_MEMBER_DECL_SPECIALIZED((DatagramTransport<boost::asio::ip::udp, Multicast>));
|
||||
|
||||
// Explicit specialization of makeEndpointId for the UDP multicast case.
|
||||
// Note that this "shall be declared before the first use of the specialization
|
||||
// that would cause an implicit instantiation to take place, in every translation
|
||||
// unit in which such a use occurs".
|
||||
template<>
|
||||
Transport::EndpointId
|
||||
EndpointId
|
||||
DatagramTransport<boost::asio::ip::udp, Multicast>::makeEndpointId(const protocol::endpoint& ep);
|
||||
|
||||
/**
|
||||
@@ -45,21 +49,42 @@ DatagramTransport<boost::asio::ip::udp, Multicast>::makeEndpointId(const protoco
|
||||
class MulticastUdpTransport final : public DatagramTransport<boost::asio::ip::udp, Multicast>
|
||||
{
|
||||
public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Creates a UDP-based transport for multicast communication
|
||||
* \param localEndpoint local endpoint
|
||||
* \param multicastGroup multicast group
|
||||
* \param recvSocket socket used to receive packets
|
||||
* \param recvSocket socket used to receive multicast packets
|
||||
* \param sendSocket socket used to send to the multicast group
|
||||
* \param linkType either `ndn::nfd::LINK_TYPE_MULTI_ACCESS` or `ndn::nfd::LINK_TYPE_AD_HOC`
|
||||
*/
|
||||
MulticastUdpTransport(const protocol::endpoint& localEndpoint,
|
||||
const protocol::endpoint& multicastGroup,
|
||||
MulticastUdpTransport(const protocol::endpoint& multicastGroup,
|
||||
protocol::socket&& recvSocket,
|
||||
protocol::socket&& sendSocket);
|
||||
protocol::socket&& sendSocket,
|
||||
ndn::nfd::LinkType linkType);
|
||||
|
||||
ssize_t
|
||||
getSendQueueLength() final;
|
||||
|
||||
static void
|
||||
openRxSocket(protocol::socket& sock,
|
||||
const protocol::endpoint& multicastGroup,
|
||||
const boost::asio::ip::address& localAddress,
|
||||
const shared_ptr<const ndn::net::NetworkInterface>& netif = nullptr);
|
||||
|
||||
static void
|
||||
openTxSocket(protocol::socket& sock,
|
||||
const protocol::endpoint& localEndpoint,
|
||||
const shared_ptr<const ndn::net::NetworkInterface>& netif = nullptr,
|
||||
bool enableLoopback = false);
|
||||
|
||||
private:
|
||||
void
|
||||
doSend(Transport::Packet&& packet) final;
|
||||
doSend(const Block& packet) final;
|
||||
|
||||
void
|
||||
doClose() final;
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "netdev-bound.hpp"
|
||||
#include "face-system.hpp"
|
||||
#include "common/logger.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NFD_LOG_INIT(NetdevBound);
|
||||
|
||||
NetdevBound::NetdevBound(const ProtocolFactoryCtorParams& params, const FaceSystem& faceSystem)
|
||||
: m_faceSystem(faceSystem)
|
||||
, m_addFace(params.addFace)
|
||||
, m_netmon(params.netmon)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NetdevBound::processConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context)
|
||||
{
|
||||
std::vector<Rule> rules;
|
||||
if (configSection) {
|
||||
int ruleIndex = 0;
|
||||
for (const auto& pair : *configSection) {
|
||||
const std::string& key = pair.first;
|
||||
const ConfigSection& value = pair.second;
|
||||
if (key == "rule") {
|
||||
rules.push_back(parseRule(ruleIndex++, value));
|
||||
}
|
||||
else {
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized option face_system.netdev_bound." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context.isDryRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
///\todo #3521 this should be verified in dry-run, but PFs won't publish their *+dev schemes
|
||||
/// in dry-run
|
||||
for (size_t i = 0; i < rules.size(); ++i) {
|
||||
const Rule& rule = rules[i];
|
||||
for (const FaceUri& remote : rule.remotes) {
|
||||
std::string devScheme = remote.getScheme() + "+dev";
|
||||
if (!m_faceSystem.hasFactoryForScheme(devScheme)) {
|
||||
NDN_THROW(RuleParseError(i, "scheme '" + devScheme + "' for " +
|
||||
remote.toString() + " is unavailable"));
|
||||
}
|
||||
}
|
||||
}
|
||||
NFD_LOG_DEBUG("processConfig: processed " << rules.size() << " rules");
|
||||
|
||||
m_rules.swap(rules);
|
||||
std::map<Key, shared_ptr<Face>> oldFaces;
|
||||
oldFaces.swap(m_faces);
|
||||
|
||||
///\todo #3521 for each face needed under m_rules:
|
||||
/// if it's in oldFaces, add to m_faces and remove from oldFaces;
|
||||
/// otherwise, create via factory and add to m_faces
|
||||
|
||||
///\todo #3521 close faces in oldFaces
|
||||
}
|
||||
|
||||
NetdevBound::Rule
|
||||
NetdevBound::parseRule(int index, const ConfigSection& confRule) const
|
||||
{
|
||||
Rule rule;
|
||||
|
||||
bool hasWhitelist = false;
|
||||
bool hasBlacklist = false;
|
||||
for (const auto& pair : confRule) {
|
||||
const std::string& key = pair.first;
|
||||
const ConfigSection& value = pair.second;
|
||||
if (key == "remote") {
|
||||
try {
|
||||
rule.remotes.emplace_back(value.get_value<std::string>());
|
||||
}
|
||||
catch (const FaceUri::Error&) {
|
||||
NDN_THROW_NESTED(RuleParseError(index, "invalid remote FaceUri"));
|
||||
}
|
||||
if (!rule.remotes.back().isCanonical()) {
|
||||
NDN_THROW(RuleParseError(index, "remote FaceUri is not canonical"));
|
||||
}
|
||||
}
|
||||
else if (key == "whitelist") {
|
||||
if (hasWhitelist) {
|
||||
NDN_THROW(RuleParseError(index, "duplicate whitelist"));
|
||||
}
|
||||
try {
|
||||
rule.netifPredicate.parseWhitelist(value);
|
||||
}
|
||||
catch (const ConfigFile::Error&) {
|
||||
NDN_THROW_NESTED(RuleParseError(index, "invalid whitelist"));
|
||||
}
|
||||
hasWhitelist = true;
|
||||
}
|
||||
else if (key == "blacklist") {
|
||||
if (hasBlacklist) {
|
||||
NDN_THROW(RuleParseError(index, "duplicate blacklist"));
|
||||
}
|
||||
try {
|
||||
rule.netifPredicate.parseBlacklist(value);
|
||||
}
|
||||
catch (const ConfigFile::Error&) {
|
||||
NDN_THROW_NESTED(RuleParseError(index, "invalid blacklist"));
|
||||
}
|
||||
hasBlacklist = true;
|
||||
}
|
||||
else {
|
||||
NDN_THROW(RuleParseError(index, "unrecognized option " + key));
|
||||
}
|
||||
}
|
||||
|
||||
if (rule.remotes.empty()) {
|
||||
NDN_THROW(RuleParseError(index, "remote FaceUri is missing"));
|
||||
}
|
||||
|
||||
///\todo #3521 for each remote, check that there is a factory providing scheme+dev scheme
|
||||
return rule;
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
@@ -0,0 +1,88 @@
|
||||
/* -*- 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_NETDEV_BOUND_HPP
|
||||
#define NFD_DAEMON_FACE_NETDEV_BOUND_HPP
|
||||
|
||||
#include "protocol-factory.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
class FaceSystem;
|
||||
|
||||
/** \brief manages netdev-bound faces
|
||||
*/
|
||||
class NetdevBound : noncopyable
|
||||
{
|
||||
public:
|
||||
class RuleParseError : public ConfigFile::Error
|
||||
{
|
||||
public:
|
||||
RuleParseError(int index, std::string msg)
|
||||
: Error("Error parsing face_system.netdev_bound.rule[" + to_string(index) + "]: " + msg)
|
||||
, index(index)
|
||||
, msg(std::move(msg))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
int index;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
NetdevBound(const ProtocolFactoryCtorParams& params, const FaceSystem& faceSystem);
|
||||
|
||||
/** \brief process face_system.netdev_bound config section
|
||||
*/
|
||||
void
|
||||
processConfig(OptionalConfigSection configSection,
|
||||
FaceSystem::ConfigContext& context);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
struct Rule
|
||||
{
|
||||
std::vector<FaceUri> remotes;
|
||||
NetworkInterfacePredicate netifPredicate;
|
||||
};
|
||||
|
||||
Rule
|
||||
parseRule(int index, const ConfigSection& confRule) const;
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
const FaceSystem& m_faceSystem;
|
||||
FaceCreatedCallback m_addFace;
|
||||
shared_ptr<ndn::net::NetworkMonitor> m_netmon;
|
||||
|
||||
std::vector<Rule> m_rules;
|
||||
|
||||
using Key = std::pair<FaceUri, std::string>;
|
||||
std::map<Key, shared_ptr<Face>> m_faces;
|
||||
};
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FACE_NETDEV_BOUND_HPP
|
||||
@@ -0,0 +1,227 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#include "network-predicate.hpp"
|
||||
#include "common/config-file.hpp"
|
||||
#include "core/network.hpp"
|
||||
|
||||
#include <fnmatch.h>
|
||||
|
||||
namespace nfd {
|
||||
namespace face {
|
||||
|
||||
NetworkPredicateBase::NetworkPredicateBase()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
NetworkPredicateBase::~NetworkPredicateBase() = default;
|
||||
|
||||
void
|
||||
NetworkPredicateBase::clear()
|
||||
{
|
||||
m_whitelist = std::set<std::string>{"*"};
|
||||
m_blacklist.clear();
|
||||
}
|
||||
|
||||
void
|
||||
NetworkPredicateBase::parseList(std::set<std::string>& set,
|
||||
const boost::property_tree::ptree& list,
|
||||
const std::string& section)
|
||||
{
|
||||
set.clear();
|
||||
|
||||
for (const auto& item : list) {
|
||||
if (item.first == "*") {
|
||||
// insert wildcard
|
||||
set.insert(item.first);
|
||||
}
|
||||
else {
|
||||
if (!isRuleSupported(item.first)) {
|
||||
NDN_THROW(ConfigFile::Error("Unrecognized rule '" + item.first +
|
||||
"' in section '" + section + "'"));
|
||||
}
|
||||
|
||||
auto value = item.second.get_value<std::string>();
|
||||
if (!isRuleValid(item.first, value)) {
|
||||
NDN_THROW(ConfigFile::Error("Malformed " + item.first + " '" + value +
|
||||
"' in section '" + section + "'"));
|
||||
}
|
||||
set.insert(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkPredicateBase::parseList(std::set<std::string>& set,
|
||||
std::initializer_list<std::pair<std::string, std::string>> list)
|
||||
{
|
||||
set.clear();
|
||||
|
||||
for (const auto& item : list) {
|
||||
if (item.first == "*") {
|
||||
// insert wildcard
|
||||
set.insert(item.first);
|
||||
}
|
||||
else {
|
||||
if (!isRuleSupported(item.first)) {
|
||||
NDN_THROW(std::runtime_error("Unrecognized rule '" + item.first + "'"));
|
||||
}
|
||||
|
||||
if (!isRuleValid(item.first, item.second)) {
|
||||
NDN_THROW(std::runtime_error("Malformed " + item.first + " '" + item.second + "'"));
|
||||
}
|
||||
set.insert(item.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkPredicateBase::parseWhitelist(const boost::property_tree::ptree& list)
|
||||
{
|
||||
parseList(m_whitelist, list, "whitelist");
|
||||
}
|
||||
|
||||
void
|
||||
NetworkPredicateBase::parseBlacklist(const boost::property_tree::ptree& list)
|
||||
{
|
||||
parseList(m_blacklist, list, "blacklist");
|
||||
}
|
||||
|
||||
void
|
||||
NetworkPredicateBase::assign(std::initializer_list<std::pair<std::string, std::string>> whitelist,
|
||||
std::initializer_list<std::pair<std::string, std::string>> blacklist)
|
||||
{
|
||||
parseList(m_whitelist, whitelist);
|
||||
parseList(m_blacklist, blacklist);
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkInterfacePredicate::isRuleSupported(const std::string& key)
|
||||
{
|
||||
return key == "ifname" || key == "ether" || key == "subnet";
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkInterfacePredicate::isRuleValid(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "ifname") {
|
||||
// very basic sanity check for interface names
|
||||
return !value.empty();
|
||||
}
|
||||
else if (key == "ether") {
|
||||
// validate ethernet address
|
||||
return !ndn::ethernet::Address::fromString(value).isNull();
|
||||
}
|
||||
else if (key == "subnet") {
|
||||
// example subnet: 10.0.0.0/8
|
||||
return Network::isValidCidr(value);
|
||||
}
|
||||
else {
|
||||
NDN_THROW(std::logic_error("Only supported rules are expected"));
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
IpAddressPredicate::isRuleSupported(const std::string& key)
|
||||
{
|
||||
return key == "subnet";
|
||||
}
|
||||
|
||||
bool
|
||||
IpAddressPredicate::isRuleValid(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "subnet") {
|
||||
// example subnet: 10.0.0.0/8
|
||||
return Network::isValidCidr(value);
|
||||
}
|
||||
else {
|
||||
NDN_THROW(std::logic_error("Only supported rules are expected"));
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkPredicateBase::operator==(const NetworkPredicateBase& other) const
|
||||
{
|
||||
return this->m_whitelist == other.m_whitelist &&
|
||||
this->m_blacklist == other.m_blacklist;
|
||||
}
|
||||
|
||||
static bool
|
||||
doesMatchPattern(const std::string& ifname, const std::string& pattern)
|
||||
{
|
||||
// use fnmatch(3) to provide unix glob-style matching for interface names
|
||||
// fnmatch returns 0 if there is a match
|
||||
return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
doesNetifMatchRule(const ndn::net::NetworkInterface& netif, const std::string& rule)
|
||||
{
|
||||
// if '/' is in rule, this is a subnet, check if IP in subnet
|
||||
if (rule.find('/') != std::string::npos) {
|
||||
Network n = boost::lexical_cast<Network>(rule);
|
||||
for (const auto& addr : netif.getNetworkAddresses()) {
|
||||
if (n.doesContain(addr.getIp())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rule == "*" ||
|
||||
doesMatchPattern(netif.getName(), rule) ||
|
||||
netif.getEthernetAddress().toString() == rule;
|
||||
}
|
||||
|
||||
bool
|
||||
NetworkInterfacePredicate::operator()(const ndn::net::NetworkInterface& netif) const
|
||||
{
|
||||
return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1)) &&
|
||||
std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1));
|
||||
}
|
||||
|
||||
static bool
|
||||
doesAddressMatchRule(const boost::asio::ip::address& address, const std::string& rule)
|
||||
{
|
||||
// if '/' is in rule, this is a subnet, check if IP in subnet
|
||||
if (rule.find('/') != std::string::npos) {
|
||||
Network n = boost::lexical_cast<Network>(rule);
|
||||
if (n.doesContain(address)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return rule == "*";
|
||||
}
|
||||
|
||||
bool
|
||||
IpAddressPredicate::operator()(const boost::asio::ip::address& address) const
|
||||
{
|
||||
return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesAddressMatchRule, std::cref(address), _1)) &&
|
||||
std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesAddressMatchRule, std::cref(address), _1));
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
} // namespace nfd
|
||||
Loaded 100 of 631 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user