├── waf ├── manpages ├── requirements.txt ├── index.rst ├── ndndissect.rst ├── ndnpingserver.rst ├── ndnping.rst ├── conf.py ├── ndnpoke.rst ├── ndnpeek.rst ├── ndndump.rst └── ndnserve.rst ├── tests ├── dump │ ├── nack.pcap │ ├── linux-sll-tcp4.pcap │ ├── linux-sll-tcp6.pcap │ ├── linux-sll-udp4.pcap │ ├── linux-sll-udp6.pcap │ ├── invalid-tlv-length.pcap │ └── unrecognized-lp-field.pcap ├── dissect-wireshark │ ├── ppp.pcap │ ├── bug3603.pcap │ ├── nameuri.pcap │ ├── ndnlpv2.pcap │ ├── ethernet.pcap │ ├── packet03.pcap │ ├── ndnlpv2-more.pcap │ ├── ipv4-tcp-segmented.pcap │ ├── ipv4-udp-fragmented.pcap │ ├── ipv6-tcp-segmented.pcap │ ├── ipv6-udp-fragmented.pcap │ ├── ipv4-websocket-segmented.pcap │ ├── ipv6-websocket-segmented.pcap │ ├── ipv4-tcp-multi-ndn-packets-in-segment.pcap │ ├── packet03.hex │ ├── nameuri.hex │ └── ndnlpv2.hex ├── wscript ├── README.md ├── main.cpp ├── key-chain-fixture.hpp ├── boost-test.hpp ├── io-fixture.hpp ├── clock-fixture.cpp ├── test-case.t.cpp.sample ├── test-common.cpp ├── ping │ ├── server │ │ └── ping-server.t.cpp │ └── client │ │ └── ping.t.cpp ├── test-common.hpp ├── clock-fixture.hpp └── get │ └── pipeline-interests-fixture.hpp ├── .github └── workflows │ ├── docs.yml │ ├── release.yml │ ├── docker.yml │ └── ci.yml ├── .mailmap ├── tools ├── dissect-wireshark │ └── wscript ├── dump │ ├── README.md │ ├── wscript │ └── ndndump.hpp ├── dissect │ ├── README.md │ ├── wscript │ ├── dissector.hpp │ └── main.cpp ├── get │ ├── wscript │ ├── statistics-collector.hpp │ ├── pipeline-interests-aimd.hpp │ ├── statistics-collector.cpp │ ├── README.md │ ├── pipeline-interests-cubic.hpp │ ├── pipeline-interests-aimd.cpp │ ├── discover-version.hpp │ ├── options.hpp │ ├── consumer.cpp │ ├── pipeline-interests-fixed.hpp │ ├── consumer.hpp │ ├── discover-version.cpp │ ├── pipeline-interests-cubic.cpp │ └── data-fetcher.hpp ├── serve │ ├── wscript │ ├── README.md │ └── producer.hpp ├── peek │ ├── README.md │ ├── wscript │ ├── ndnpoke │ │ ├── ndnpoke.hpp │ │ └── ndnpoke.cpp │ └── ndnpeek │ │ ├── ndnpeek.hpp │ │ └── ndnpeek.cpp ├── ping │ ├── wscript │ ├── server │ │ ├── tracer.hpp │ │ ├── tracer.cpp │ │ ├── ping-server.cpp │ │ └── ping-server.hpp │ ├── client │ │ ├── tracer.hpp │ │ ├── tracer.cpp │ │ ├── ping.cpp │ │ ├── statistics-collector.hpp │ │ ├── statistics-collector.cpp │ │ └── ping.hpp │ └── README.md └── wscript ├── .dockerignore ├── .gitignore ├── .editorconfig ├── .waf-tools ├── coverage.py ├── sanitizers.py └── sphinx.py ├── .jenkins.d ├── 10-build.sh ├── 20-tests.sh ├── 30-coverage.sh ├── 01-ndn-cxx.sh ├── README.md └── 00-deps.sh ├── core ├── version.cpp.in ├── version.hpp ├── program-options-ext.cpp ├── program-options-ext.hpp └── common.hpp ├── INSTALL.md ├── .jenkins ├── Dockerfile ├── AUTHORS.md ├── README.md ├── systemd └── ndn-ping-server.service.in └── README-dev.md /waf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/waf -------------------------------------------------------------------------------- /manpages/requirements.txt: -------------------------------------------------------------------------------- 1 | docutils>=0.20 2 | sphinx>=7.0.1,<9 3 | -------------------------------------------------------------------------------- /manpages/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | :glob: 3 | :maxdepth: 1 4 | 5 | ndn* 6 | -------------------------------------------------------------------------------- /tests/dump/nack.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/nack.pcap -------------------------------------------------------------------------------- /tests/dump/linux-sll-tcp4.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/linux-sll-tcp4.pcap -------------------------------------------------------------------------------- /tests/dump/linux-sll-tcp6.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/linux-sll-tcp6.pcap -------------------------------------------------------------------------------- /tests/dump/linux-sll-udp4.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/linux-sll-udp4.pcap -------------------------------------------------------------------------------- /tests/dump/linux-sll-udp6.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/linux-sll-udp6.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ppp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ppp.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/bug3603.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/bug3603.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/nameuri.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/nameuri.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ndnlpv2.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ndnlpv2.pcap -------------------------------------------------------------------------------- /tests/dump/invalid-tlv-length.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/invalid-tlv-length.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ethernet.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ethernet.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/packet03.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/packet03.pcap -------------------------------------------------------------------------------- /tests/dump/unrecognized-lp-field.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dump/unrecognized-lp-field.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ndnlpv2-more.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ndnlpv2-more.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv4-tcp-segmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv4-tcp-segmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv4-udp-fragmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv4-udp-fragmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv6-tcp-segmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv6-tcp-segmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv6-udp-fragmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv6-udp-fragmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv4-websocket-segmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv4-websocket-segmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv6-websocket-segmented.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv6-websocket-segmented.pcap -------------------------------------------------------------------------------- /tests/dissect-wireshark/ipv4-tcp-multi-ndn-packets-in-segment.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-tools/HEAD/tests/dissect-wireshark/ipv4-tcp-multi-ndn-packets-in-segment.pcap -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | on: 3 | push: 4 | workflow_dispatch: 5 | 6 | permissions: {} 7 | 8 | jobs: 9 | man: 10 | uses: named-data/actions/.github/workflows/docs-man.yml@v1 11 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Md Ashiqur Rahman 5 | -------------------------------------------------------------------------------- /tools/dissect-wireshark/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | bld.install_files("${DATADIR}/ndn-dissect-wireshark", "ndn.lua") 6 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | tags: 5 | - 'ndn-tools-[0-9]+*' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | attestations: write 10 | contents: write 11 | id-token: write 12 | 13 | jobs: 14 | release: 15 | uses: named-data/actions/.github/workflows/release.yml@v1 16 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # Waf build system 2 | build/ 3 | .waf-*-*/ 4 | .waf3-*-*/ 5 | .lock-waf* 6 | 7 | # Compiled python code 8 | **/__pycache__/ 9 | **/*.py[cod] 10 | 11 | # Qt Creator 12 | *.creator 13 | *.creator.user 14 | .qtc_clangd/ 15 | 16 | # Visual Studio Code 17 | .vscode/ 18 | 19 | # macOS 20 | **/.DS_Store 21 | **/.AppleDouble 22 | **/.LSOverride 23 | **/._* 24 | 25 | # Other 26 | Dockerfile 27 | VERSION.info 28 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | on: 3 | push: 4 | tags: 5 | - 'ndn-tools-[0-9]+*' 6 | schedule: 7 | # twice a month 8 | - cron: '20 10 5,20 * *' 9 | workflow_dispatch: 10 | 11 | permissions: 12 | attestations: write 13 | id-token: write 14 | packages: write 15 | 16 | jobs: 17 | ndn-tools: 18 | uses: named-data/actions/.github/workflows/docker-image.yml@v1 19 | with: 20 | name: ndn-tools 21 | -------------------------------------------------------------------------------- /tests/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '..' 3 | 4 | def build(bld): 5 | bld.program( 6 | target=f'{top}/unit-tests', 7 | name='unit-tests', 8 | source=bld.path.ant_glob(['*.cpp'] + [f'{tool}/**/*.cpp' for tool in bld.env.BUILD_TOOLS]), 9 | use=['BOOST_TESTS', 'core-objects'] + [f'{tool}-objects' for tool in bld.env.BUILD_TOOLS], 10 | install_path=None) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Backup files 2 | *~ 3 | *.bak 4 | *.orig 5 | *.rej 6 | 7 | # Waf build system 8 | /build/ 9 | .waf-*-*/ 10 | .waf3-*-*/ 11 | .lock-waf* 12 | 13 | # Compiled python code 14 | __pycache__/ 15 | *.py[cod] 16 | 17 | # Emacs 18 | \#*\# 19 | /.emacs.desktop 20 | /.emacs.desktop.lock 21 | *.elc 22 | .\#* 23 | 24 | # Visual Studio Code 25 | .vscode/ 26 | 27 | # macOS 28 | .DS_Store 29 | .AppleDouble 30 | .LSOverride 31 | ._* 32 | 33 | # Other 34 | /VERSION.info 35 | -------------------------------------------------------------------------------- /tools/dump/README.md: -------------------------------------------------------------------------------- 1 | # ndndump 2 | 3 | **ndndump** is a traffic analysis tool that captures Interest, Data, and Nack packets on the wire 4 | and displays brief information about captured packets. 5 | 6 | Usage example: 7 | 8 | 1. start NFD on the local machine 9 | 2. create a UDP tunnel to a remote machine 10 | 3. run `sudo ndndump` 11 | 4. cause some NDN traffic to be sent/received on the tunnel 12 | 5. observe the output of `ndndump` 13 | 14 | For more information, consult the manpage. 15 | -------------------------------------------------------------------------------- /tools/dissect/README.md: -------------------------------------------------------------------------------- 1 | # ndndissect 2 | 3 | **ndndissect** is an NDN packet format inspector. 4 | It reads zero or more NDN packets from either an input file or the standard 5 | input, and displays the Type-Length-Value (TLV) structure of those packets 6 | on the standard output. 7 | 8 | Usage example: 9 | 10 | 1. start NFD on the local machine 11 | 2. run `echo 'HELLO WORLD' | ndnpoke /localhost/demo/hello` 12 | 3. on another console, run `ndnpeek /localhost/demo/hello | ndndissect` 13 | 14 | For more information, consult the manpage. 15 | -------------------------------------------------------------------------------- /tools/get/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | bld.objects( 6 | target='get-objects', 7 | source=bld.path.ant_glob('*.cpp', excl='main.cpp'), 8 | use='core-objects') 9 | 10 | bld.program( 11 | target=f'{top}/bin/ndnget', 12 | name='ndnget', 13 | source='main.cpp', 14 | use='get-objects') 15 | 16 | # backward compatibility 17 | bld.symlink_as('${BINDIR}/ndncatchunks', 'ndnget') 18 | -------------------------------------------------------------------------------- /tools/serve/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | bld.objects( 6 | target='serve-objects', 7 | source=bld.path.ant_glob('*.cpp', excl='main.cpp'), 8 | use='core-objects') 9 | 10 | bld.program( 11 | target=f'{top}/bin/ndnserve', 12 | name='ndnserve', 13 | source='main.cpp', 14 | use='serve-objects') 15 | 16 | # backward compatibility 17 | bld.symlink_as('${BINDIR}/ndnputchunks', 'ndnserve') 18 | -------------------------------------------------------------------------------- /tools/dissect/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | bld.objects( 6 | target='dissect-objects', 7 | source=bld.path.ant_glob('*.cpp', excl='main.cpp'), 8 | use='core-objects') 9 | 10 | bld.program( 11 | target=f'{top}/bin/ndndissect', 12 | name='ndndissect', 13 | source='main.cpp', 14 | use='dissect-objects') 15 | 16 | # backward compatibility 17 | bld.symlink_as('${BINDIR}/ndn-dissect', 'ndndissect') 18 | -------------------------------------------------------------------------------- /tools/peek/README.md: -------------------------------------------------------------------------------- 1 | # ndnpeek and ndnpoke 2 | 3 | **ndnpeek** and **ndnpoke** are a pair of programs to respectively request and serve a single Data packet. 4 | 5 | * **ndnpeek** is a consumer program that sends one Interest and expects one Data. 6 | * **ndnpoke** is a producer program that serves one Data in response to an Interest. 7 | 8 | Usage example: 9 | 10 | 1. start NFD 11 | 2. run `echo 'HELLO WORLD' | ndnpoke /localhost/demo/hello` 12 | 3. in another terminal, run `ndnpeek -p /localhost/demo/hello` 13 | 14 | For more information on these programs, consult their respective manpages. 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | 8 | [*.{cpp,hpp}] 9 | indent_style = space 10 | indent_size = 2 11 | trim_trailing_whitespace = true 12 | 13 | [{*.{py,sh},.jenkins,wscript}] 14 | indent_style = space 15 | indent_size = 4 16 | trim_trailing_whitespace = true 17 | 18 | [*.md] 19 | indent_style = space 20 | trim_trailing_whitespace = false 21 | 22 | [*.rst] 23 | indent_style = space 24 | trim_trailing_whitespace = true 25 | 26 | [*.{yaml,yml}] 27 | indent_style = space 28 | indent_size = 2 29 | trim_trailing_whitespace = true 30 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - '**' 6 | paths-ignore: 7 | - 'Dockerfile' 8 | - '.dockerignore' 9 | - '.editorconfig' 10 | - '.gitignore' 11 | - '.mailmap' 12 | - 'manpages/**' 13 | - '*.md' 14 | workflow_dispatch: 15 | 16 | permissions: {} 17 | 18 | jobs: 19 | Ubuntu: 20 | uses: named-data/actions/.github/workflows/jenkins-script-ubuntu.yml@v1 21 | macOS: 22 | uses: named-data/actions/.github/workflows/jenkins-script-macos.yml@v1 23 | PPA: 24 | uses: named-data/actions/.github/workflows/ppa.yml@v1 25 | with: 26 | extra-deps: libboost-program-options-dev libpcap-dev 27 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # ndn-tools unit tests 2 | 3 | ## Assumptions 4 | 5 | Unit tests for a tool `foo` should be placed in the folder `foo` and the build script 6 | for the tool should define `foo-objects` that includes all object files for that tool, 7 | except the object that contains the `main()` function. 8 | 9 | For example: 10 | 11 | ```python 12 | def build(bld): 13 | bld.objects( 14 | target='tool-subtool-objects', 15 | source=bld.path.ant_glob('subtool/*.cpp', excl='subtool/main.cpp'), 16 | use='core-objects') 17 | 18 | bld.program( 19 | name='subtool', 20 | target='../../bin/subtool', 21 | source='subtool/main.cpp', 22 | use='tool-subtool-objects') 23 | 24 | bld(name='tool-objects', 25 | use='tool-subtool-objects') 26 | ``` 27 | -------------------------------------------------------------------------------- /.waf-tools/coverage.py: -------------------------------------------------------------------------------- 1 | from waflib import TaskGen 2 | 3 | def options(opt): 4 | opt.add_option('--with-coverage', action='store_true', default=False, 5 | help='Add compiler flags to enable code coverage information') 6 | 7 | def configure(conf): 8 | if conf.options.with_coverage: 9 | if not conf.options.debug: 10 | conf.fatal('Code coverage flags require debug mode compilation (add --debug)') 11 | conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'], 12 | linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True) 13 | 14 | @TaskGen.feature('cxx','cc') 15 | @TaskGen.after('process_source') 16 | def add_coverage(self): 17 | if getattr(self, 'use', ''): 18 | self.use += ' GCOV' 19 | else: 20 | self.use = 'GCOV' 21 | -------------------------------------------------------------------------------- /.jenkins.d/10-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | 4 | if [[ -z $DISABLE_ASAN ]]; then 5 | ASAN="--with-sanitizer=address" 6 | fi 7 | if [[ $JOB_NAME == *code-coverage ]]; then 8 | COVERAGE="--with-coverage" 9 | fi 10 | 11 | set -x 12 | 13 | if [[ $JOB_NAME != *code-coverage && $JOB_NAME != *limited-build ]]; then 14 | # Build in release mode with tests 15 | ./waf --color=yes configure --with-tests 16 | ./waf --color=yes build 17 | 18 | # Cleanup 19 | ./waf --color=yes distclean 20 | 21 | # Build in release mode without tests 22 | ./waf --color=yes configure 23 | ./waf --color=yes build 24 | 25 | # Cleanup 26 | ./waf --color=yes distclean 27 | fi 28 | 29 | # Build in debug mode with tests 30 | ./waf --color=yes configure --debug --with-tests $ASAN $COVERAGE 31 | ./waf --color=yes build 32 | 33 | # Install 34 | sudo ./waf --color=yes install 35 | -------------------------------------------------------------------------------- /tools/peek/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | 6 | bld.objects( 7 | target='ndnpeek-objects', 8 | source=bld.path.ant_glob('ndnpeek/*.cpp', excl='ndnpeek/main.cpp'), 9 | use='core-objects') 10 | 11 | bld.program( 12 | target='../../bin/ndnpeek', 13 | name='ndnpeek', 14 | source='ndnpeek/main.cpp', 15 | use='ndnpeek-objects') 16 | 17 | bld.objects( 18 | target='ndnpoke-objects', 19 | source=bld.path.ant_glob('ndnpoke/*.cpp', excl='ndnpoke/main.cpp'), 20 | use='core-objects') 21 | 22 | bld.program( 23 | target='../../bin/ndnpoke', 24 | name='ndnpoke', 25 | source='ndnpoke/main.cpp', 26 | use='ndnpoke-objects') 27 | 28 | ## (for unit tests) 29 | 30 | bld(target='peek-objects', 31 | use='ndnpeek-objects ndnpoke-objects') 32 | -------------------------------------------------------------------------------- /.jenkins.d/20-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | 4 | # https://github.com/google/sanitizers/wiki/SanitizerCommonFlags 5 | # https://github.com/google/sanitizers/wiki/AddressSanitizerFlags 6 | ASAN_OPTIONS="color=always" 7 | ASAN_OPTIONS+=":strip_path_prefix=${PWD}/" 8 | ASAN_OPTIONS+=":check_initialization_order=1" 9 | ASAN_OPTIONS+=":detect_stack_use_after_return=1" 10 | ASAN_OPTIONS+=":strict_init_order=1" 11 | ASAN_OPTIONS+=":strict_string_checks=1" 12 | ASAN_OPTIONS+=":detect_invalid_pointer_pairs=2" 13 | export ASAN_OPTIONS 14 | 15 | # https://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/runtime_config/summary.html 16 | export BOOST_TEST_BUILD_INFO=1 17 | export BOOST_TEST_COLOR_OUTPUT=1 18 | export BOOST_TEST_DETECT_MEMORY_LEAK=0 19 | export BOOST_TEST_LOGGER=HRF,test_suite,stdout:XML,all,build/xunit-log.xml 20 | 21 | set -x 22 | 23 | # Prepare environment 24 | rm -rf ~/.ndn 25 | 26 | # Run unit tests 27 | ./build/unit-tests 28 | -------------------------------------------------------------------------------- /tools/ping/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def build(bld): 5 | 6 | bld.objects( 7 | target='ping-client-objects', 8 | source=bld.path.ant_glob('client/*.cpp', excl='client/main.cpp'), 9 | use='core-objects') 10 | 11 | bld.program( 12 | target='../../bin/ndnping', 13 | name='ndnping', 14 | source='client/main.cpp', 15 | use='ping-client-objects') 16 | 17 | bld.objects( 18 | target='ping-server-objects', 19 | source=bld.path.ant_glob('server/*.cpp', excl='server/main.cpp'), 20 | use='core-objects') 21 | 22 | bld.program( 23 | target='../../bin/ndnpingserver', 24 | name='ndnpingserver', 25 | source='server/main.cpp', 26 | use='ping-server-objects') 27 | 28 | ## (for unit tests) 29 | 30 | bld(target='ping-objects', 31 | use='ping-client-objects ping-server-objects') 32 | -------------------------------------------------------------------------------- /.waf-tools/sanitizers.py: -------------------------------------------------------------------------------- 1 | # Davide Pesavento (LIP6), 2016 2 | 3 | def options(opt): 4 | opt.add_option('--with-sanitizer', action='store', default='', dest='sanitizers', 5 | help='Comma-separated list of compiler sanitizers to enable [default=none]') 6 | 7 | def configure(conf): 8 | for san in conf.options.sanitizers.split(','): 9 | if not san: 10 | continue 11 | 12 | sanflag = '-fsanitize=%s' % san 13 | conf.start_msg('Checking if compiler supports %s' % sanflag) 14 | 15 | if conf.check_cxx(cxxflags=['-Werror', sanflag, '-fno-omit-frame-pointer'], 16 | linkflags=[sanflag], mandatory=False): 17 | conf.end_msg('yes') 18 | conf.env.append_unique('CXXFLAGS', [sanflag, '-fno-omit-frame-pointer']) 19 | conf.env.append_unique('LINKFLAGS', [sanflag]) 20 | else: 21 | conf.end_msg('no', color='RED') 22 | conf.fatal('%s sanitizer is not supported by the current compiler' % san) 23 | -------------------------------------------------------------------------------- /tests/dissect-wireshark/packet03.hex: -------------------------------------------------------------------------------- 1 | A1B2C3D4 2 | 00020004 3 | 00000000 4 | 00000000 5 | 00010000 6 | 00000001 7 | 8 | # packet 1 9 | 00000000 10 | 00000000 11 | 00000039 12 | 00000039 13 | 14 | 01005E0017AA 15 | 000000000000 16 | 8624 17 | 18 | ## Interest with CanBePrefix, MustBeFresh, HopLimit, ApplicationParameters 19 | 0529 20 | 0703080149 21 | 2100 22 | 1200 23 | 1E0B 1F09 1E023E15 0703080148 24 | 0A044ACB1E4C 25 | 0C0276A1 26 | 2201D6 27 | 2404C0C1C2C3 28 | 29 | # packet 2 30 | 00000000 31 | 00000000 32 | 00000050 33 | 00000050 34 | 35 | 01005E0017AA 36 | 000000000000 37 | 8624 38 | 39 | ## Interest Name contains typed name components 40 | 0540 41 | 0738 020141 070142 080143 FC0144 FD01000145 FDFFFF0145 0120EE357C5791DCAA4494D9B301047B875D8833CAA76DADA3E95837BBC3EAF7B300 42 | 0A044ACB1E4C 43 | 44 | # packet 3 45 | 00000000 46 | 00000000 47 | 00000039 48 | 00000039 49 | 50 | 01005E0017AA 51 | 000000000000 52 | 8624 53 | 54 | ## Data without MetaInfo or Content 55 | 0629 56 | 0700 57 | 16031B0100 58 | 1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76 59 | -------------------------------------------------------------------------------- /tests/dissect-wireshark/nameuri.hex: -------------------------------------------------------------------------------- 1 | A1B2C3D4 2 | 00020004 3 | 00000000 4 | 00000000 5 | 00010000 6 | 00000001 7 | 8 | # packet 1 9 | 00000000 10 | 00000000 11 | 00000159 12 | 00000159 13 | 14 | 01005E0017AA 15 | 000000000000 16 | 8624 17 | 18 | ## Data 19 | 06FD0147 20 | 21 | ## Name 22 | 07FD0115 23 | 0800 24 | 08012E 25 | 08022E2E 26 | 08022E41 27 | 0840000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F 28 | 0840404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F 29 | 0840808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF 30 | 0840C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF 31 | 32 | ## MetaInfo 33 | 1405 34 | 1A03080102 35 | 36 | ## SignatureInfo 37 | 1603 38 | 1B0100 39 | 40 | ## SignatureValue 41 | 1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76 42 | -------------------------------------------------------------------------------- /manpages/ndndissect.rst: -------------------------------------------------------------------------------- 1 | ndndissect 2 | ========== 3 | 4 | Synopsis 5 | -------- 6 | 7 | **ndndissect** [**-h**] [**-c**] [**-V**] [*file*] 8 | 9 | Description 10 | ----------- 11 | 12 | :program:`ndndissect` is an NDN packet format inspector. 13 | It reads zero or more NDN packets from either an input file or the standard 14 | input, and displays the Type-Length-Value (TLV) structure of those packets 15 | on the standard output. 16 | 17 | Options 18 | ------- 19 | 20 | .. option:: -h, --help 21 | 22 | Print help and exit. 23 | 24 | .. option:: -c, --content 25 | 26 | Dissect the value of Content elements as well. By default, the value of a 27 | Content element is treated as an opaque blob and is not dissected further. 28 | 29 | .. option:: -V, --version 30 | 31 | Print program version and exit. 32 | 33 | .. option:: file 34 | 35 | The file to read packets from. 36 | If no *file* is given, or if *file* is "-", the standard input is used. 37 | 38 | Examples 39 | -------- 40 | 41 | Inspect the response to Interest ``/app1/video``:: 42 | 43 | ndnpeek /app1/video | ndndissect 44 | -------------------------------------------------------------------------------- /core/version.cpp.in: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2022, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #include "core/version.hpp" 21 | 22 | namespace ndn::tools { 23 | 24 | const char VERSION[] = "@VERSION_BUILD@"; 25 | 26 | } // namespace ndn::tools 27 | -------------------------------------------------------------------------------- /tools/dump/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '../..' 3 | 4 | def configure(conf): 5 | conf.check_cfg(msg='Checking for libpcap', 6 | path='pcap-config', args='--cflags --libs', 7 | package='', uselib_store='PCAP') 8 | conf.check_cxx(msg='Checking if struct tcphdr has member th_off ', 9 | define_name='HAVE_BSD_TCPHDR', mandatory=False, 10 | fragment='''#include 11 | int main() { tcphdr th; th.th_off; }''') 12 | conf.check_cxx(msg='Checking if struct udphdr has member uh_ulen', 13 | define_name='HAVE_BSD_UDPHDR', mandatory=False, 14 | fragment='''#include 15 | int main() { udphdr uh; uh.uh_ulen; }''') 16 | 17 | def build(bld): 18 | bld.objects( 19 | target='dump-objects', 20 | source=bld.path.ant_glob('*.cpp', excl='main.cpp'), 21 | use='core-objects PCAP') 22 | 23 | bld.program( 24 | target='../../bin/ndndump', 25 | name='ndndump', 26 | source='main.cpp', 27 | use='dump-objects') 28 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # ndn-tools Build Instructions 2 | 3 | This document describes how to build and install ndn-tools. 4 | 5 | ## Prerequisites 6 | 7 | * Install the [ndn-cxx](https://github.com/named-data/ndn-cxx) library and its dependencies. 8 | Check out [the documentation](https://docs.named-data.net/ndn-cxx/current/INSTALL.html) for 9 | detailed installation instructions. All platforms supported by ndn-cxx are also supported 10 | by ndn-tools. 11 | 12 | *Note*: If you have installed ndn-cxx from a binary package, please make sure the development 13 | headers are installed (e.g., if using Ubuntu PPA, the `libndn-cxx-dev` package is needed). 14 | 15 | * Install `libpcap` (except on macOS where it is provided by the base system). 16 | 17 | On Debian and Ubuntu: 18 | 19 | ```shell 20 | sudo apt install libpcap-dev 21 | ``` 22 | 23 | On CentOS and Fedora: 24 | 25 | ```shell 26 | sudo dnf install libpcap-devel 27 | ``` 28 | 29 | ## Build Steps 30 | 31 | To configure, compile, and install ndn-tools, type the following commands 32 | in ndn-tools source directory: 33 | 34 | ```shell 35 | ./waf configure 36 | ./waf 37 | sudo ./waf install 38 | ``` 39 | 40 | To uninstall: 41 | 42 | ```shell 43 | sudo ./waf uninstall 44 | ``` 45 | -------------------------------------------------------------------------------- /core/version.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #ifndef NDN_TOOLS_CORE_VERSION_HPP 21 | #define NDN_TOOLS_CORE_VERSION_HPP 22 | 23 | namespace ndn::tools { 24 | 25 | /** 26 | * \brief The version of ndn-tools. 27 | */ 28 | extern const char VERSION[]; 29 | 30 | } // namespace ndn::tools 31 | 32 | #endif // NDN_TOOLS_CORE_VERSION_HPP 33 | -------------------------------------------------------------------------------- /.jenkins.d/30-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | 4 | [[ $JOB_NAME == *code-coverage ]] || exit 0 5 | 6 | export FORCE_COLOR=1 7 | export UV_NO_MANAGED_PYTHON=1 8 | 9 | set -x 10 | 11 | # Generate a detailed HTML report and an XML report in Cobertura format using gcovr 12 | # Note: trailing slashes are important in the paths below. Do not remove them! 13 | uvx --from 'git+https://github.com/gcovr/gcovr@99b82e7' gcovr \ 14 | --decisions \ 15 | --filter tools/ \ 16 | --exclude-throw-branches \ 17 | --exclude-unreachable-branches \ 18 | --cobertura build/coverage.xml \ 19 | --html-details build/gcovr/ \ 20 | --txt-summary \ 21 | build 22 | 23 | # Generate a detailed HTML report using lcov 24 | lcov \ 25 | --quiet \ 26 | --capture \ 27 | --directory . \ 28 | --include "$PWD/tools/*" \ 29 | --branch-coverage \ 30 | --rc no_exception_branch=1 \ 31 | --ignore-errors inconsistent,mismatch,mismatch \ 32 | --output-file build/coverage.info 33 | 34 | genhtml \ 35 | --quiet \ 36 | --branch-coverage \ 37 | --demangle-cpp \ 38 | --legend \ 39 | --missed \ 40 | --show-proportion \ 41 | --title "ndn-tools $(cat VERSION.info)" \ 42 | --ignore-errors inconsistent,inconsistent \ 43 | --output-directory build/lcov \ 44 | build/coverage.info 45 | -------------------------------------------------------------------------------- /tests/main.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2020, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #define BOOST_TEST_MODULE ndn-tools 27 | #include "tests/boost-test.hpp" 28 | -------------------------------------------------------------------------------- /.jenkins.d/01-ndn-cxx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -exo pipefail 3 | 4 | pushd "$CACHE_DIR" >/dev/null 5 | 6 | INSTALLED_VERSION= 7 | if [[ $ID == macos ]]; then 8 | BOOST=$(brew list --formula --versions boost) 9 | OLD_BOOST=$(cat boost.txt || :) 10 | if [[ $OLD_BOOST != $BOOST ]]; then 11 | echo "$BOOST" > boost.txt 12 | INSTALLED_VERSION=NONE 13 | fi 14 | fi 15 | 16 | if [[ -z $INSTALLED_VERSION ]]; then 17 | INSTALLED_VERSION=$(git -C ndn-cxx rev-parse HEAD 2>/dev/null || echo NONE) 18 | fi 19 | 20 | sudo rm -rf ndn-cxx-latest 21 | git clone --depth 1 https://github.com/named-data/ndn-cxx.git ndn-cxx-latest 22 | LATEST_VERSION=$(git -C ndn-cxx-latest rev-parse HEAD 2>/dev/null || echo UNKNOWN) 23 | 24 | if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then 25 | sudo rm -rf ndn-cxx 26 | mv ndn-cxx-latest ndn-cxx 27 | else 28 | sudo rm -rf ndn-cxx-latest 29 | fi 30 | 31 | sudo rm -f /usr/local/bin/ndnsec* 32 | sudo rm -fr /usr/local/include/ndn-cxx 33 | sudo rm -f /usr/local/lib{,64}/libndn-cxx* 34 | sudo rm -f /usr/local/lib{,64}/pkgconfig/libndn-cxx.pc 35 | 36 | pushd ndn-cxx >/dev/null 37 | 38 | ./waf --color=yes configure 39 | ./waf --color=yes build 40 | sudo ./waf --color=yes install 41 | 42 | popd >/dev/null 43 | popd >/dev/null 44 | 45 | if [[ $ID_LIKE == *linux* ]]; then 46 | if [[ $(uname -m) == x86_64 && -d /usr/lib64 ]]; then 47 | sudo tee /etc/ld.so.conf.d/ndn.conf >/dev/null <<< /usr/local/lib64 48 | fi 49 | sudo ldconfig 50 | fi 51 | -------------------------------------------------------------------------------- /tests/key-chain-fixture.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2013-2022 Regents of the University of California. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #ifndef NDN_TOOLS_TESTS_KEY_CHAIN_FIXTURE_HPP 21 | #define NDN_TOOLS_TESTS_KEY_CHAIN_FIXTURE_HPP 22 | 23 | #include 24 | 25 | namespace ndn::tests { 26 | 27 | /** 28 | * @brief A fixture providing an in-memory KeyChain. 29 | */ 30 | class KeyChainFixture 31 | { 32 | protected: 33 | ndn::KeyChain m_keyChain{"pib-memory:", "tpm-memory:"}; 34 | }; 35 | 36 | } // namespace ndn::tests 37 | 38 | #endif // NDN_TOOLS_TESTS_KEY_CHAIN_FIXTURE_HPP 39 | -------------------------------------------------------------------------------- /tools/serve/README.md: -------------------------------------------------------------------------------- 1 | # ndnserve 2 | 3 | **ndnserve** is a producer program that reads a file from the standard input, and makes it 4 | available as a set of NDN Data segments. It appends version and segment number components 5 | to the specified name as needed, according to the [NDN naming conventions]( 6 | https://named-data.net/publications/techreports/ndn-tr-22-3-ndn-memo-naming-conventions/). 7 | 8 | Files published by ndnserve can be fetched with [ndnget](../get/README.md). 9 | 10 | ## Usage examples 11 | 12 | The following command will publish the text of the GPL-3 license under the `/localhost/demo/gpl3` 13 | prefix: 14 | 15 | ndnserve /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3 16 | 17 | To find the published version you have to start ndnserve with the `-p` command line option, 18 | for example: 19 | 20 | ndnserve -p /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3 21 | 22 | This command will print the published version to standard output. 23 | 24 | To publish Data with a specific version, you need to append a version component to the end of the 25 | prefix. The version component must follow the aforementioned NDN naming conventions. For example, 26 | the following command will publish the version 1449078495094 of the `/localhost/demo/gpl3` prefix: 27 | 28 | ndnserve -Nt /localhost/demo/gpl3/v=1449078495094 < /usr/share/common-licenses/GPL-3 29 | 30 | If the specified version component is not valid, ndnserve will exit with an error. If no version 31 | component is specified, one will be generated and appended to the name. 32 | -------------------------------------------------------------------------------- /manpages/ndnpingserver.rst: -------------------------------------------------------------------------------- 1 | ndnpingserver 2 | ============= 3 | 4 | Synopsis 5 | -------- 6 | 7 | **ndnpingserver** [-h] [-f *freshness*] [-p *count*] [-s *size*] [-t] [-q] [-V] *prefix* 8 | 9 | Description 10 | ----------- 11 | 12 | :program:`ndnpingserver` listens for the specified Interest prefix and sends Data packets when 13 | an Interest under that prefix is received. Once :program:`ndnpingserver` either reaches the 14 | specified total number of Interests to be satisfied or receives an interrupt signal, it prints 15 | the number of Data packets sent. 16 | 17 | *prefix* is interpreted as the Interest prefix to listen for. The FreshnessPeriod of Data packets 18 | is set with the **-f** option (default 1 second). The content is by default empty, but if a size 19 | is specified with the **-s** option, it contains the specified number of the letter "a". Finally, 20 | the Data is signed with a SHA-256 digest. 21 | 22 | Options 23 | ------- 24 | 25 | ``-h`` 26 | Print help and exit. 27 | 28 | ``-f`` 29 | Set freshness period in milliseconds. 30 | 31 | ``-p`` 32 | Maximum number of pings to satisfy. A value of 0 means no limit. 33 | 34 | ``-s`` 35 | Size of the response payload. 36 | 37 | ``-t`` 38 | Print a timestamp before each log message. 39 | 40 | ``-q`` 41 | Do not print a log message each time a ping is received. 42 | 43 | ``-V`` 44 | Print version and exit. 45 | 46 | Examples 47 | -------- 48 | 49 | Listen on ``/edu/arizona`` and respond to at most 4 pings, printing the timestamp 50 | on each received ping:: 51 | 52 | ndnpingserver -p 4 -t /edu/arizona 53 | -------------------------------------------------------------------------------- /tools/ping/server/tracer.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2022, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | */ 21 | 22 | #ifndef NDN_TOOLS_PING_SERVER_TRACER_HPP 23 | #define NDN_TOOLS_PING_SERVER_TRACER_HPP 24 | 25 | #include "core/common.hpp" 26 | 27 | #include "ping-server.hpp" 28 | 29 | namespace ndn::ping::server { 30 | 31 | /** 32 | * @brief Logs ping responses 33 | */ 34 | class Tracer : noncopyable 35 | { 36 | public: 37 | Tracer(PingServer& pingServer, const Options& options); 38 | 39 | private: 40 | const Options& m_options; 41 | }; 42 | 43 | } // namespace ndn::ping::server 44 | 45 | #endif // NDN_TOOLS_PING_SERVER_TRACER_HPP 46 | -------------------------------------------------------------------------------- /.jenkins.d/README.md: -------------------------------------------------------------------------------- 1 | # Continuous Integration Scripts 2 | 3 | ## Environment Variables 4 | 5 | - `ID`: lower-case string that identifies the operating system, for example: `ID=ubuntu`, 6 | `ID=centos`. See [os-release(5)] for more information. On macOS, where `os-release` is 7 | not available, we emulate it by setting `ID=macos`. 8 | 9 | - `ID_LIKE`: space-separated list of operating system identifiers that are closely related 10 | to the running OS. See [os-release(5)] for more information. The listed values are used 11 | by the CI scripts to select the proper behavior for different platforms and OS flavors. 12 | 13 | Examples: 14 | 15 | - On CentOS, `ID_LIKE="centos rhel fedora linux"` 16 | - On Ubuntu, `ID_LIKE="ubuntu debian linux"` 17 | 18 | - `VERSION_ID`: identifies the operating system version, excluding any release code names. 19 | See [os-release(5)] for more information. Examples: `VERSION_ID=42`, `VERSION_ID=22.04`. 20 | 21 | - `JOB_NAME`: defines the type of the current CI job. Depending on the job type, the CI 22 | scripts can perform different tasks. 23 | 24 | Supported values: 25 | 26 | - empty: default build task 27 | - `code-coverage`: debug build with tests and code coverage analysis 28 | - `limited-build`: only a single debug build with tests 29 | 30 | - `CACHE_DIR`: directory containing cached files from previous builds, e.g., a compiled 31 | version of ndn-cxx. If not set, `/tmp` is used. 32 | 33 | - `DISABLE_ASAN`: disable building with AddressSanitizer. This is automatically set for 34 | the `code-coverage` job type. 35 | 36 | [os-release(5)]: https://www.freedesktop.org/software/systemd/man/os-release.html 37 | -------------------------------------------------------------------------------- /tools/ping/server/tracer.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | */ 21 | 22 | #include "tracer.hpp" 23 | 24 | #include 25 | 26 | namespace ndn::ping::server { 27 | 28 | Tracer::Tracer(PingServer& pingServer, const Options& options) 29 | : m_options(options) 30 | { 31 | if (!m_options.wantQuiet) { 32 | pingServer.afterReceive.connect([this] (const Name& name) { 33 | if (m_options.wantTimestamp) { 34 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; 35 | } 36 | std::cout << "interest received: seq=" << name.at(-1) << "\n"; 37 | }); 38 | } 39 | } 40 | 41 | } // namespace ndn::ping::server 42 | -------------------------------------------------------------------------------- /.jenkins: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | 4 | case $(uname) in 5 | Linux) 6 | if [[ -e /etc/os-release ]]; then 7 | source /etc/os-release 8 | else 9 | source /usr/lib/os-release 10 | fi 11 | export ID VERSION_ID 12 | export ID_LIKE="${ID} ${ID_LIKE} linux" 13 | if [[ -z $GITHUB_ACTIONS ]]; then 14 | export PATH="${HOME}/.local/bin${PATH:+:}${PATH}" 15 | fi 16 | ;; 17 | Darwin) 18 | # Emulate a subset of os-release(5) 19 | export ID=macos 20 | export VERSION_ID=$(sw_vers -productVersion) 21 | if [[ -z $GITHUB_ACTIONS ]]; then 22 | export PATH="/usr/local/bin${PATH:+:}${PATH}" 23 | fi 24 | if [[ -x /opt/homebrew/bin/brew ]]; then 25 | eval "$(/opt/homebrew/bin/brew shellenv)" 26 | elif [[ -x /usr/local/bin/brew ]]; then 27 | eval "$(/usr/local/bin/brew shellenv)" 28 | fi 29 | ;; 30 | esac 31 | 32 | export CACHE_DIR=${CACHE_DIR:-/tmp} 33 | 34 | if [[ $JOB_NAME == *code-coverage ]]; then 35 | export DISABLE_ASAN=1 36 | export DISABLE_HEADERS_CHECK=1 37 | fi 38 | 39 | # https://reproducible-builds.org/docs/source-date-epoch/ 40 | export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) 41 | 42 | for file in .jenkins.d/*; do 43 | [[ -f $file && -x $file ]] || continue 44 | 45 | if [[ -n $GITHUB_ACTIONS ]]; then 46 | label=$(basename "$file" | sed -E 's/[[:digit:]]+-(.*)\..*/\1/') 47 | echo "::group::${label}" 48 | fi 49 | 50 | echo "\$ $file" 51 | "$file" 52 | 53 | if [[ -n $GITHUB_ACTIONS ]]; then 54 | echo "::endgroup::" 55 | fi 56 | done 57 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | ARG NDN_CXX_VERSION=latest 4 | FROM ghcr.io/named-data/ndn-cxx-build:${NDN_CXX_VERSION} AS build 5 | 6 | RUN apt-get install -Uy --no-install-recommends \ 7 | libpcap-dev \ 8 | && apt-get distclean 9 | 10 | ARG JOBS 11 | ARG SOURCE_DATE_EPOCH 12 | RUN --mount=rw,target=/src < "${binary}" 29 | done 30 | EOF 31 | 32 | 33 | FROM ghcr.io/named-data/ndn-cxx-runtime:${NDN_CXX_VERSION} AS ndn-tools 34 | 35 | COPY --link --from=build /usr/bin/ndndissect /usr/bin/ 36 | COPY --link --from=build /usr/bin/ndndump /usr/bin/ 37 | COPY --link --from=build /usr/bin/ndnget /usr/bin/ 38 | COPY --link --from=build /usr/bin/ndnpeek /usr/bin/ 39 | COPY --link --from=build /usr/bin/ndnpoke /usr/bin/ 40 | COPY --link --from=build /usr/bin/ndnping /usr/bin/ 41 | COPY --link --from=build /usr/bin/ndnpingserver /usr/bin/ 42 | COPY --link --from=build /usr/bin/ndnserve /usr/bin/ 43 | 44 | RUN --mount=from=build,source=/deps,target=/deps \ 45 | apt-get install -Uy --no-install-recommends \ 46 | $(cat /deps/ndn*) \ 47 | && apt-get distclean 48 | 49 | ENV HOME=/config 50 | VOLUME /config 51 | VOLUME /run/nfd 52 | -------------------------------------------------------------------------------- /tests/boost-test.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2019, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_TESTS_BOOST_TEST_HPP 27 | #define NDN_TOOLS_TESTS_BOOST_TEST_HPP 28 | 29 | // suppress warnings from Boost.Test 30 | #pragma GCC system_header 31 | #pragma clang system_header 32 | 33 | #define BOOST_TEST_DYN_LINK 34 | #include 35 | 36 | #endif // NDN_TOOLS_TESTS_BOOST_TEST_HPP 37 | -------------------------------------------------------------------------------- /tools/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | top = '..' 3 | 4 | from waflib import Options 5 | 6 | def options(opt): 7 | for subdir in opt.path.ant_glob('*', dir=True, src=False): 8 | tool = subdir.path_from(opt.path) 9 | opt.add_option(f'--enable-{tool}', 10 | help=f'Build tool {tool} (enabled by default)', 11 | action='store_true', dest=f'enable_{tool}') 12 | opt.add_option(f'--disable-{tool}', 13 | help=f'Do not build tool {tool}', 14 | action='store_true', dest=f'disable_{tool}') 15 | opt.recurse(str(tool), mandatory=False) 16 | 17 | def configure(conf): 18 | all_tools = set() # all available tools 19 | enabled_tools = set() # --enable-X 20 | disabled_tools = set() # --disable-X 21 | 22 | for subdir in conf.path.ant_glob('*', dir=True, src=False): 23 | tool = subdir.path_from(conf.path) 24 | all_tools.add(tool) 25 | 26 | is_enabled = getattr(Options.options, f'enable_{tool}') 27 | is_disabled = getattr(Options.options, f'disable_{tool}') 28 | 29 | if is_enabled and is_disabled: 30 | conf.fatal(f'--enable-{tool} and --disable-{tool} cannot be both specified') 31 | 32 | if is_enabled: 33 | enabled_tools.add(tool) 34 | 35 | if is_disabled: 36 | disabled_tools.add(tool) 37 | 38 | if len(enabled_tools) == 0: 39 | conf.env.BUILD_TOOLS = list(all_tools - disabled_tools) 40 | else: 41 | conf.env.BUILD_TOOLS = list(enabled_tools) 42 | 43 | for tool in conf.env.BUILD_TOOLS: 44 | conf.recurse(tool, mandatory=False) 45 | 46 | def build(bld): 47 | for tool in bld.env.BUILD_TOOLS: 48 | bld.recurse(tool) 49 | -------------------------------------------------------------------------------- /tools/get/statistics-collector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2025, Regents of the University of California, 3 | * Colorado State University, 4 | * University Pierre & Marie Curie, Sorbonne University. 5 | * 6 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 7 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 8 | * 9 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 10 | * of the GNU General Public License as published by the Free Software Foundation, 11 | * either version 3 of the License, or (at your option) any later version. 12 | * 13 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 | * PURPOSE. See the GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * ndn-tools, e.g., in COPYING.md file. If not, see . 19 | * 20 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 21 | * 22 | * @author Weiwei Liu 23 | */ 24 | 25 | #ifndef NDN_TOOLS_GET_STATISTICS_COLLECTOR_HPP 26 | #define NDN_TOOLS_GET_STATISTICS_COLLECTOR_HPP 27 | 28 | #include "pipeline-interests-adaptive.hpp" 29 | 30 | namespace ndn::get { 31 | 32 | /** 33 | * @brief Statistics collector for Adaptive pipelines 34 | */ 35 | class StatisticsCollector : noncopyable 36 | { 37 | public: 38 | StatisticsCollector(PipelineInterestsAdaptive& pipeline, 39 | std::ostream& osCwnd, std::ostream& osRtt); 40 | 41 | private: 42 | std::ostream& m_osCwnd; 43 | std::ostream& m_osRtt; 44 | }; 45 | 46 | } // namespace ndn::get 47 | 48 | #endif // NDN_TOOLS_GET_STATISTICS_COLLECTOR_HPP 49 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # ndn-tools Authors 2 | 3 | The following lists maintainers, primary developers, and all much-appreciated contributors to ndn-tools in alphabetical order. 4 | The specific contributions of individual authors can be obtained from the git history of the [official ndn-tools repository](https://github.com/named-data/ndn-tools). 5 | If you would like to become a contributor to the official repository, please follow the recommendations in . 6 | 7 | * Jerald Paul Abraham 8 | * ***(Maintainer)*** Alexander Afanasyev 9 | * Stephanie DiBenedetto 10 | * Ashlesh Gawande 11 | * Chavoosh Ghasemi 12 | * Nick Gordon 13 | * Xiaoke Jiang 14 | * Seungbae Kim 15 | * Vince Lehman 16 | * Zhuo Li 17 | * Teng Liang 18 | * Weiwei Liu 19 | * Eric Newberry 20 | * João Pereira 21 | * ***(Maintainer)*** Davide Pesavento 22 | * Klaus Schneider 23 | * Wentao Shang 24 | * Susmit Shannigrahi 25 | * Junxiao Shi 26 | * Jeff Thompson 27 | * Andrea Tosatto 28 | * Zipeng Wang 29 | * Ryan Wickman 30 | * Seunghyun Yoo 31 | * Qianshan Yu 32 | * Yingdi Yu 33 | * Qi Zhao 34 | -------------------------------------------------------------------------------- /.jenkins.d/00-deps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | 4 | APT_PKGS=( 5 | dpkg-dev 6 | g++ 7 | libboost-chrono-dev 8 | libboost-date-time-dev 9 | libboost-dev 10 | libboost-log-dev 11 | libboost-program-options-dev 12 | libboost-stacktrace-dev 13 | libboost-test-dev 14 | libboost-thread-dev 15 | libpcap-dev 16 | libsqlite3-dev 17 | libssl-dev 18 | pkgconf 19 | python3 20 | ) 21 | DNF_PKGS=( 22 | boost-devel 23 | gcc-c++ 24 | libasan 25 | libpcap-devel 26 | lld 27 | openssl-devel 28 | pkgconf 29 | python3 30 | sqlite-devel 31 | ) 32 | FORMULAE=(boost openssl pkgconf) 33 | case $JOB_NAME in 34 | *code-coverage) 35 | APT_PKGS+=(lcov libjson-xs-perl) 36 | ;; 37 | *Docs) 38 | ;; 39 | esac 40 | 41 | install_uv() { 42 | if [[ -z $GITHUB_ACTIONS && $ID_LIKE == *debian* ]]; then 43 | sudo apt-get install -qy --no-install-recommends pipx 44 | pipx upgrade uv || pipx install uv 45 | fi 46 | } 47 | 48 | set -x 49 | 50 | if [[ $ID == macos ]]; then 51 | export HOMEBREW_COLOR=1 52 | export HOMEBREW_NO_ENV_HINTS=1 53 | if [[ -n $GITHUB_ACTIONS ]]; then 54 | export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 55 | fi 56 | brew update 57 | brew install --formula "${FORMULAE[@]}" 58 | elif [[ $ID_LIKE == *debian* ]]; then 59 | sudo apt-get update -qq 60 | sudo apt-get install -qy --no-install-recommends "${APT_PKGS[@]}" 61 | elif [[ $ID_LIKE == *fedora* ]]; then 62 | sudo dnf install -y "${DNF_PKGS[@]}" 63 | fi 64 | 65 | case $JOB_NAME in 66 | *code-coverage) 67 | install_uv 68 | ;; 69 | *Docs) 70 | install_uv 71 | export FORCE_COLOR=1 72 | export UV_NO_MANAGED_PYTHON=1 73 | uv tool install sphinx --upgrade --with-requirements manpages/requirements.txt 74 | ;; 75 | esac 76 | -------------------------------------------------------------------------------- /core/program-options-ext.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2022, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #include "core/program-options-ext.hpp" 27 | 28 | namespace ndn { 29 | 30 | void 31 | validate(boost::any& v, const std::vector& values, Name*, int) 32 | { 33 | using namespace boost::program_options; 34 | 35 | validators::check_first_occurrence(v); 36 | const std::string& s = validators::get_single_string(values); 37 | 38 | try { 39 | v = Name(s); 40 | } catch (const Name::Error&) { 41 | throw invalid_option_value(s); 42 | } 43 | } 44 | 45 | } // namespace ndn 46 | -------------------------------------------------------------------------------- /core/program-options-ext.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP 27 | #define NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace ndn { 34 | 35 | /** 36 | * @brief Provide a Boost.Program_options custom validator for ndn::Name type. 37 | */ 38 | void 39 | validate(boost::any& v, const std::vector& values, Name*, int); 40 | 41 | } // namespace ndn 42 | 43 | #endif // NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP 44 | -------------------------------------------------------------------------------- /tests/io-fixture.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2023, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_TESTS_IO_FIXTURE_HPP 27 | #define NDN_TOOLS_TESTS_IO_FIXTURE_HPP 28 | 29 | #include "tests/clock-fixture.hpp" 30 | 31 | #include 32 | 33 | namespace ndn::tests { 34 | 35 | class IoFixture : public ClockFixture 36 | { 37 | private: 38 | void 39 | afterTick() final 40 | { 41 | if (m_io.stopped()) { 42 | m_io.restart(); 43 | } 44 | m_io.poll(); 45 | } 46 | 47 | protected: 48 | boost::asio::io_context m_io; 49 | }; 50 | 51 | } // namespace ndn::tests 52 | 53 | #endif // NDN_TOOLS_TESTS_IO_FIXTURE_HPP 54 | -------------------------------------------------------------------------------- /tools/dissect/dissector.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #ifndef NDN_TOOLS_DISSECT_DISSECTOR_HPP 21 | #define NDN_TOOLS_DISSECT_DISSECTOR_HPP 22 | 23 | #include "core/common.hpp" 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace ndn::dissect { 30 | 31 | struct Options 32 | { 33 | bool dissectContent = false; 34 | }; 35 | 36 | class Dissector : noncopyable 37 | { 38 | public: 39 | Dissector(std::istream& input, std::ostream& output, const Options& options); 40 | 41 | void 42 | dissect(); 43 | 44 | private: 45 | void 46 | printBranches(); 47 | 48 | void 49 | printType(uint32_t type); 50 | 51 | void 52 | printBlock(const Block& block); 53 | 54 | private: 55 | const Options& m_options; 56 | std::istream& m_in; 57 | std::ostream& m_out; 58 | 59 | // m_branches[i] is true iff the i-th level of the tree has more branches after the current one 60 | std::vector m_branches; 61 | }; 62 | 63 | } // namespace ndn::dissect 64 | 65 | #endif // NDN_TOOLS_DISSECT_DISSECTOR_HPP 66 | -------------------------------------------------------------------------------- /manpages/ndnping.rst: -------------------------------------------------------------------------------- 1 | ndnping 2 | ======= 3 | 4 | Usage 5 | ----- 6 | 7 | :: 8 | 9 | ndnping [-h] [-V] [-i interval] [-o timeout] [-c count] [-n start] [-p identifier] [-a] [-t] prefix 10 | 11 | Description 12 | ----------- 13 | 14 | ``ndnping`` is a reachability testing tool that sends Interest packets and expects Data packets in 15 | response. If Data packets are not received within the timeout period for their Interest, 16 | ``ndnping`` marks them as timed out. If ``ndnping`` does receive a Data packet within the timeout, 17 | the time from sending the Interest to receiving the Data is recorded and displayed. Once 18 | ``ndnping`` either reaches the specified total number of Interests to be sent or receives an 19 | interrupt signal, it prints statistics on the Interests, including the number of Interests sent, 20 | the number of Data packets received, and the average response time of the Data. 21 | 22 | ``prefix`` is interpreted as the Interest prefix. The name of the sent Interest consists of the 23 | prefix followed by "ping", the optional identifier specified by the '-p' option, and finally a 24 | sequence number as a decimal number string. 25 | 26 | Options 27 | ------- 28 | 29 | ``-h`` 30 | Print help and exit. 31 | 32 | ``-V`` 33 | Print version and exit. 34 | 35 | ``-i`` 36 | Set ping interval in milliseconds (default 1000ms - minimum 1ms). 37 | 38 | ``-o`` 39 | Set ping timeout in milliseconds (default 4000ms). 40 | 41 | ``-c`` 42 | Set total number of Interests to be sent. 43 | 44 | ``-n`` 45 | Set the starting sequence number, which is incremented by 1 after each Interest sent. 46 | 47 | ``-p`` 48 | Adds specified identifier to the Interest names before the numbers to avoid conflict. 49 | 50 | ``-a`` 51 | Allows routers to return stale Data from cache. 52 | 53 | ``-t`` 54 | Prints a timestamp with received Data and timeouts. 55 | 56 | Examples 57 | -------- 58 | 59 | Test reachability for ``ndn:/edu/arizona`` using 4 Interest packets and print timestamp 60 | 61 | :: 62 | 63 | ndnping -c 4 -t ndn:/edu/arizona -------------------------------------------------------------------------------- /tools/get/pipeline-interests-aimd.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Shuo Yang 24 | * @author Weiwei Liu 25 | * @author Chavoosh Ghasemi 26 | * @author Klaus Schneider 27 | */ 28 | 29 | #ifndef NDN_TOOLS_GET_PIPELINE_INTERESTS_AIMD_HPP 30 | #define NDN_TOOLS_GET_PIPELINE_INTERESTS_AIMD_HPP 31 | 32 | #include "pipeline-interests-adaptive.hpp" 33 | 34 | namespace ndn::get { 35 | 36 | /** 37 | * @brief Implements AIMD window increase and decrease. 38 | */ 39 | class PipelineInterestsAimd final : public PipelineInterestsAdaptive 40 | { 41 | public: 42 | PipelineInterestsAimd(Face& face, RttEstimatorWithStats& rttEstimator, const Options& opts); 43 | 44 | private: 45 | void 46 | increaseWindow() final; 47 | 48 | void 49 | decreaseWindow() final; 50 | }; 51 | 52 | } // namespace ndn::get 53 | 54 | #endif // NDN_TOOLS_GET_PIPELINE_INTERESTS_AIMD_HPP 55 | -------------------------------------------------------------------------------- /tools/get/statistics-collector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2025, Regents of the University of California, 3 | * Colorado State University, 4 | * University Pierre & Marie Curie, Sorbonne University. 5 | * 6 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 7 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 8 | * 9 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 10 | * of the GNU General Public License as published by the Free Software Foundation, 11 | * either version 3 of the License, or (at your option) any later version. 12 | * 13 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 | * PURPOSE. See the GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * ndn-tools, e.g., in COPYING.md file. If not, see . 19 | * 20 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 21 | * 22 | * @author Weiwei Liu 23 | */ 24 | 25 | #include "statistics-collector.hpp" 26 | 27 | namespace ndn::get { 28 | 29 | StatisticsCollector::StatisticsCollector(PipelineInterestsAdaptive& pipeline, 30 | std::ostream& osCwnd, std::ostream& osRtt) 31 | : m_osCwnd(osCwnd) 32 | , m_osRtt(osRtt) 33 | { 34 | m_osCwnd << "time\tcwndsize\n"; 35 | m_osRtt << "segment\trtt\trttvar\tsrtt\trto\n"; 36 | 37 | pipeline.afterCwndChange.connect([this] (time::nanoseconds timeElapsed, double cwnd) { 38 | m_osCwnd << timeElapsed.count() / 1e9 << '\t' << cwnd << '\n'; 39 | }); 40 | 41 | pipeline.afterRttMeasurement.connect([this] (const auto& sample) { 42 | m_osRtt << sample.segNum << '\t' 43 | << sample.rtt.count() / 1e6 << '\t' 44 | << sample.rttVar.count() / 1e6 << '\t' 45 | << sample.sRtt.count() / 1e6 << '\t' 46 | << sample.rto.count() / 1e6 << '\n'; 47 | }); 48 | } 49 | 50 | } // namespace ndn::get 51 | -------------------------------------------------------------------------------- /manpages/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | # -- Project information ----------------------------------------------------- 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 8 | 9 | project = 'NDN Essential Tools' 10 | copyright = 'Copyright © 2014-2025 Named Data Networking Project.' 11 | author = 'Named Data Networking Project' 12 | 13 | # The short X.Y version. 14 | #version = '' 15 | 16 | # The full version, including alpha/beta/rc tags. 17 | #release = '' 18 | 19 | # There are two options for replacing |today|: either, you set today to some 20 | # non-false value, then it is used: 21 | #today = '' 22 | # Else, today_fmt is used as the format for a strftime call. 23 | today_fmt = '%Y-%m-%d' 24 | 25 | 26 | # -- General configuration --------------------------------------------------- 27 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 28 | 29 | needs_sphinx = '4.0' 30 | extensions = [] 31 | 32 | exclude_patterns = ['Thumbs.db', '.DS_Store'] 33 | 34 | 35 | # -- Options for manual page output ------------------------------------------ 36 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-manual-page-output 37 | 38 | # One entry per manual page. List of tuples 39 | # (source start file, name, description, authors, manual section). 40 | man_pages = [ 41 | ('ndndissect', 'ndndissect', 'NDN packet format inspector', [], 1), 42 | ('ndndump', 'ndndump', 'NDN traffic analysis tool', [], 8), 43 | ('ndnpeek', 'ndnpeek', 'simple NDN consumer to send one Interest and receive one Data', [], 1), 44 | ('ndnpoke', 'ndnpoke', 'simple NDN producer to publish one Data', [], 1), 45 | ('ndnping', 'ndnping', 'NDN reachability testing client', [], 1), 46 | ('ndnpingserver', 'ndnpingserver', 'NDN reachability testing server', [], 1), 47 | ('ndnserve', 'ndnserve', 'NDN producer with content segmentation', [], 1), 48 | ] 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NDN Essential Tools 2 | 3 | ![Latest version](https://img.shields.io/github/v/tag/named-data/ndn-tools?label=Latest%20version) 4 | ![Language](https://img.shields.io/badge/C%2B%2B-17-blue) 5 | [![CI](https://github.com/named-data/ndn-tools/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/ndn-tools/actions/workflows/ci.yml) 6 | [![Docker](https://github.com/named-data/ndn-tools/actions/workflows/docker.yml/badge.svg)](https://github.com/named-data/ndn-tools/actions/workflows/docker.yml) 7 | [![Docs](https://github.com/named-data/ndn-tools/actions/workflows/docs.yml/badge.svg)](https://github.com/named-data/ndn-tools/actions/workflows/docs.yml) 8 | 9 | This repository contains a collection of basic tools for [Named Data Networking (NDN)](https://named-data.net/). 10 | The tools currently included are: 11 | 12 | * [**ndnpeek** and **ndnpoke**](tools/peek): transmit a single Interest/Data packet 13 | between a consumer and a producer 14 | * [**ndnget**](tools/get) and [**ndnserve**](tools/serve): segmented file transfer 15 | between a consumer and a producer 16 | * [**ndnping**](tools/ping): test reachability between two NDN nodes 17 | * [**ndndump**](tools/dump): capture and analyze live traffic on an NDN network 18 | * [**ndndissect**](tools/dissect): inspect the TLV structure of an NDN packet 19 | * [**dissect-wireshark**](tools/dissect-wireshark): Wireshark extension to inspect 20 | the TLV structure of NDN packets 21 | 22 | ## Installation 23 | 24 | See [`INSTALL.md`](INSTALL.md) for build instructions. 25 | 26 | ## Reporting bugs 27 | 28 | Please submit any bug reports or feature requests to the 29 | [ndn-tools issue tracker](https://redmine.named-data.net/projects/ndn-tools/issues). 30 | 31 | ## Contributing 32 | 33 | Contributions to ndn-tools are greatly appreciated and can be made through our 34 | [Gerrit code review site](https://gerrit.named-data.net/). 35 | If you are new to the NDN software community, please read our 36 | [Contributor's Guide](https://github.com/named-data/.github/blob/main/CONTRIBUTING.md) 37 | and [`README-dev.md`](README-dev.md) to get started. 38 | 39 | ## License 40 | 41 | ndn-tools is free software distributed under the GNU General Public License version 3. 42 | See [`COPYING.md`](COPYING.md) for details. 43 | -------------------------------------------------------------------------------- /tools/get/README.md: -------------------------------------------------------------------------------- 1 | # ndnget 2 | 3 | **ndnget** is a consumer program that fetches the segments (Data packets) of a named object, 4 | optionally discovering the latest version of the object, and then writes the content of the 5 | retrieved object to the standard output. 6 | 7 | ## Version discovery in ndnget 8 | 9 | If a version component is present at the end of the user-specified NDN name, the provided version 10 | number will be used, without any version discovery process. Otherwise, discovery Interest(s) will 11 | be sent out to fetch metadata of the solicited content from which the Data version will be resolved. 12 | For more information about the packet format and naming conventions of Interest and Data packets 13 | used for version discovery in ndnget, please refer to: 14 | [Realtime Data Retrieval (RDR) protocol](https://redmine.named-data.net/projects/ndn-tlv/wiki/RDR). 15 | 16 | ## Interest pipeline types in ndnget 17 | 18 | * `fixed`: maintains a fixed-size window of Interests in flight; the window size is configurable 19 | via a command line option and defaults to 1. 20 | 21 | * `aimd` : adjusts the window size via additive-increase/multiplicative-decrease (AIMD). 22 | By default, it uses a Conservative Window Adaptation, that is, the congestion window 23 | will be decreased at most once per round-trip-time. 24 | 25 | * `cubic`: adjusts the window size similar to the TCP CUBIC algorithm. 26 | For details about both aimd and cubic please refer to: 27 | [A Practical Congestion Control Scheme for Named Data 28 | Networking](https://conferences2.sigcomm.org/acm-icn/2016/proceedings/p21-schneider.pdf). 29 | 30 | The default Interest pipeline type is `cubic`. 31 | 32 | ## Usage examples 33 | 34 | To retrieve the latest version of a published object, the following command can be used: 35 | 36 | ndnget /localhost/demo/gpl3 37 | 38 | To fetch a specific version of a published object, you can specify the version number at the end 39 | of the name. For example, if the version is known to be 1449078495094, the following command 40 | will fetch that exact version of the object (without version discovery): 41 | 42 | ndnget -Nt /localhost/demo/gpl3/v=1449078495094 43 | 44 | For more information, run the programs with `--help` as argument. 45 | -------------------------------------------------------------------------------- /tests/clock-fixture.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #include "tests/clock-fixture.hpp" 27 | 28 | namespace ndn::tests { 29 | 30 | ClockFixture::ClockFixture() 31 | : m_steadyClock(std::make_shared()) 32 | , m_systemClock(std::make_shared()) 33 | { 34 | time::setCustomClocks(m_steadyClock, m_systemClock); 35 | } 36 | 37 | ClockFixture::~ClockFixture() 38 | { 39 | time::setCustomClocks(nullptr, nullptr); 40 | } 41 | 42 | void 43 | ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total) 44 | { 45 | BOOST_ASSERT(tick > time::nanoseconds::zero()); 46 | BOOST_ASSERT(total >= time::nanoseconds::zero()); 47 | 48 | while (total > time::nanoseconds::zero()) { 49 | auto t = std::min(tick, total); 50 | m_steadyClock->advance(t); 51 | m_systemClock->advance(t); 52 | total -= t; 53 | 54 | afterTick(); 55 | } 56 | } 57 | 58 | } // namespace ndn::tests 59 | -------------------------------------------------------------------------------- /manpages/ndnpoke.rst: -------------------------------------------------------------------------------- 1 | ndnpoke 2 | ======= 3 | 4 | Synopsis 5 | -------- 6 | 7 | **ndnpoke** [-h] [-f *freshness*] [-F] [-S *info*] [-u\|\ -w *timeout*] [-v] [-V] *name* 8 | 9 | Description 10 | ----------- 11 | 12 | :program:`ndnpoke` is a simple producer program that reads a payload from the standard 13 | input and publishes it as a single Data packet. The Data packet is either sent as a 14 | response to an incoming Interest matching *name*, or immediately pushed to the local 15 | NDN forwarder as "unsolicited Data" if the **-u** flag is specified. 16 | 17 | Options 18 | ------- 19 | 20 | ``-h, --help`` 21 | Print help and exit. 22 | 23 | ``-f, --freshness `` 24 | Set ``freshness`` (in milliseconds) as the ``FreshnessPeriod``. 25 | 26 | ``-F, --final`` 27 | Set the ``FinalBlockId`` to the last component of *name*. 28 | 29 | ``-S, --signing-info `` 30 | Specify the parameters used to sign the Data packet. If omitted, the default key of 31 | the default identity is used. The general syntax is ``:``. The most 32 | common supported combinations are as follows: 33 | 34 | * Sign with the default certificate of the default key of an identity: ``id:/``. 35 | * Sign with the default certificate of a specific key: ``key://ksk-1``. 36 | * Sign with a specific certificate: ``cert://KEY/ksk-1/ID-CERT/v=1``. 37 | * Sign with a SHA-256 digest: ``id:/localhost/identity/digest-sha256``. Note that this 38 | is only a hash function, not a real signature, but it can significantly speed up 39 | packet signing operations. 40 | 41 | ``-u, --unsolicited`` 42 | Send the Data packet without waiting for an incoming Interest. 43 | 44 | ``-w, --timeout `` 45 | Quit the program after ``timeout`` milliseconds, even if no Interest has been received. 46 | 47 | ``-v, --verbose`` 48 | Turn on verbose output. 49 | 50 | ``-V, --version`` 51 | Print version and exit. 52 | 53 | Exit Status 54 | ----------- 55 | 56 | 0: Success 57 | 58 | 1: An unspecified error occurred 59 | 60 | 2: Malformed command line 61 | 62 | 3: No Interests received before the timeout 63 | 64 | 5: Prefix registration failed 65 | 66 | Examples 67 | -------- 68 | 69 | Create a Data packet with content ``hello`` and name ``/app/video`` and wait at 70 | most 3 seconds for a matching Interest to arrive:: 71 | 72 | echo "hello" | ndnpoke -w 3000 /app/video 73 | -------------------------------------------------------------------------------- /tools/get/pipeline-interests-cubic.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Klaus Schneider 24 | */ 25 | 26 | #ifndef NDN_TOOLS_GET_PIPELINE_INTERESTS_CUBIC_HPP 27 | #define NDN_TOOLS_GET_PIPELINE_INTERESTS_CUBIC_HPP 28 | 29 | #include "pipeline-interests-adaptive.hpp" 30 | 31 | namespace ndn::get { 32 | 33 | /** 34 | * @brief Implements Cubic window increase and decrease. 35 | * 36 | * This implementation follows the RFC8312 https://tools.ietf.org/html/rfc8312 37 | * and the Linux kernel implementation https://github.com/torvalds/linux/blob/master/net/ipv4/tcp_cubic.c 38 | */ 39 | class PipelineInterestsCubic final : public PipelineInterestsAdaptive 40 | { 41 | public: 42 | PipelineInterestsCubic(Face& face, RttEstimatorWithStats& rttEstimator, const Options& opts); 43 | 44 | private: 45 | void 46 | increaseWindow() final; 47 | 48 | void 49 | decreaseWindow() final; 50 | 51 | private: 52 | double m_wmax = 0.0; ///< window size before last window decrease 53 | double m_lastWmax = 0.0; ///< last wmax 54 | time::steady_clock::time_point m_lastDecrease; ///< time of last window decrease 55 | }; 56 | 57 | } // namespace ndn::get 58 | 59 | #endif // NDN_TOOLS_GET_PIPELINE_INTERESTS_CUBIC_HPP 60 | -------------------------------------------------------------------------------- /manpages/ndnpeek.rst: -------------------------------------------------------------------------------- 1 | ndnpeek 2 | ======= 3 | 4 | Synopsis 5 | -------- 6 | 7 | **ndnpeek** [-h] [-P] [-f] [-l *lifetime*] [-H *hops*] [-A *parameters*] 8 | [-p] [-w *timeout*] [-v] [-V] *name* 9 | 10 | Description 11 | ----------- 12 | 13 | :program:`ndnpeek` is a simple consumer program that sends one Interest and 14 | expects one Data packet in response. By default, the full Data packet (in TLV 15 | format) is written to the standard output. 16 | 17 | *name* is interpreted as the Interest name. 18 | 19 | Options 20 | ------- 21 | 22 | ``-h, --help`` 23 | Print help and exit. 24 | 25 | ``-P, --prefix`` 26 | If specified, include ``CanBePrefix`` element in the Interest packet. 27 | 28 | ``-f, --fresh`` 29 | If specified, include ``MustBeFresh`` element in the Interest packet. 30 | 31 | ``-F, --fwhint `` 32 | Add a delegation name to the ``ForwardingHint`` of the Interest packet. 33 | This option may be repeated to specify multiple delegation names. 34 | 35 | ``-l, --lifetime `` 36 | Set ``lifetime`` (in milliseconds) as the ``InterestLifetime``. 37 | 38 | ``-H, --hop-limit `` 39 | Set the Interest's ``HopLimit`` to the specified number of hops. 40 | 41 | ``-A, --app-params `` 42 | Set the Interest's ``ApplicationParameters`` from a base64-encoded string. 43 | 44 | ``--app-params-file `` 45 | Set the Interest's ``ApplicationParameters`` from the specified file. 46 | 47 | ``-p, --payload`` 48 | If specified, print the received payload only, not the full packet. 49 | 50 | ``-w, --timeout `` 51 | Quit the program after ``timeout`` milliseconds, even if no reply has been received. 52 | 53 | ``-v, --verbose`` 54 | Turn on verbose output. 55 | 56 | ``-V, --version`` 57 | Print version and exit. 58 | 59 | Exit Status 60 | ----------- 61 | 62 | 0: Success 63 | 64 | 1: An unspecified error occurred 65 | 66 | 2: Malformed command line 67 | 68 | 3: Operation timed out 69 | 70 | 4: Nack received 71 | 72 | Examples 73 | -------- 74 | 75 | Send an Interest for ``/app1/video`` and print the received payload only:: 76 | 77 | ndnpeek -p /app1/video 78 | 79 | Send an Interest for ``/app2/foo``, requesting fresh content, with an InterestLifetime 80 | of 8 seconds, and with the ApplicationParameters containing the ASCII string "hello"; 81 | print the performed operations verbosely but discard the received Data packet:: 82 | 83 | ndnpeek -vf -l 8000 -A "aGVsbG8=" /app2/foo >/dev/null 84 | -------------------------------------------------------------------------------- /tests/test-case.t.cpp.sample: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2025 Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | // The unit being tested should be included first, to ensure the header compiles on its own. 21 | // For further information about test naming conventions, see 22 | // https://redmine.named-data.net/projects/nfd/wiki/UnitTesting 23 | //#include "unit-under-test.hpp" 24 | 25 | #include "tests/test-common.hpp" 26 | #include "tests/io-fixture.hpp" // optional, for IoFixture 27 | //#include "tests/key-chain-fixture.hpp" // optional, for KeyChainFixture 28 | 29 | // Unit tests should go inside the ndn::tool_name::tests namespace. 30 | namespace ndn::tool_name::tests { 31 | 32 | // Common fixtures in ndn::tests can be imported if needed. 33 | using namespace ndn::tests; 34 | 35 | // See https://redmine.named-data.net/projects/nfd/wiki/UnitTesting 36 | // for a guide on how to name a test suite. 37 | BOOST_AUTO_TEST_SUITE(TestSkeleton) 38 | 39 | BOOST_AUTO_TEST_CASE(Test1) 40 | { 41 | int i = 0; 42 | 43 | // For reference of available Boost.Test macros, see 44 | // https://www.boost.org/doc/libs/1_74_0/libs/test/doc/html/boost_test/testing_tools/summary.html 45 | 46 | BOOST_REQUIRE_NO_THROW(i = 1); 47 | BOOST_CHECK_EQUAL(i, 1); 48 | } 49 | 50 | // Use ClockFixture or IoFixture to mock clocks. 51 | BOOST_FIXTURE_TEST_CASE(Test2, IoFixture) 52 | { 53 | // advanceClocks() increments mock clocks. 54 | advanceClocks(500_ms); 55 | } 56 | 57 | BOOST_AUTO_TEST_SUITE_END() // TestSkeleton 58 | 59 | } // namespace ndn::tool_name::tests 60 | -------------------------------------------------------------------------------- /tests/test-common.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #include "tests/test-common.hpp" 27 | 28 | namespace ndn::tests { 29 | 30 | std::shared_ptr 31 | makeInterest(const Name& name, bool canBePrefix, std::optional lifetime, 32 | std::optional nonce) 33 | { 34 | auto interest = std::make_shared(name); 35 | interest->setCanBePrefix(canBePrefix); 36 | if (lifetime) { 37 | interest->setInterestLifetime(*lifetime); 38 | } 39 | interest->setNonce(nonce); 40 | return interest; 41 | } 42 | 43 | std::shared_ptr 44 | makeData(const Name& name) 45 | { 46 | auto data = std::make_shared(name); 47 | return signData(data); 48 | } 49 | 50 | Data& 51 | signData(Data& data) 52 | { 53 | data.setSignatureInfo(SignatureInfo(tlv::NullSignature)); 54 | data.setSignatureValue(std::make_shared()); 55 | data.wireEncode(); 56 | return data; 57 | } 58 | 59 | lp::Nack 60 | makeNack(Interest interest, lp::NackReason reason) 61 | { 62 | lp::Nack nack(std::move(interest)); 63 | nack.setReason(reason); 64 | return nack; 65 | } 66 | 67 | } // namespace ndn::tests 68 | -------------------------------------------------------------------------------- /manpages/ndndump.rst: -------------------------------------------------------------------------------- 1 | ndndump 2 | ======= 3 | 4 | Usage 5 | ----- 6 | 7 | :: 8 | 9 | ndndump [-hvV] [-i INTERFACE] [-r FILE] [-f FILTER] [PCAP-FILTER] 10 | 11 | Description 12 | ----------- 13 | 14 | :program:`ndndump` is a traffic analysis tool that captures NDN packets on the wire and 15 | displays brief information about them. 16 | 17 | Currently, :program:`ndndump` is capable of extracting Interest, Data, and Nack packets from: 18 | 19 | * Ethernet frame 20 | * PPP link (e.g., pcap trace from ndnSIM) 21 | * IPv4 UDP unicast tunnel 22 | * IPv4 UDP multicast group 23 | * IPv4 TCP tunnel, when Interest/Data/Nack is aligned to the beginning of a TCP segment 24 | 25 | For more complex scenarios, including the case of NDN packets that span multiple IP fragments 26 | or multiple TCP segments, it is recommended to use the **NDN Wireshark dissector**, either via 27 | :manpage:`wireshark(1)` or :manpage:`tshark(1)`. 28 | 29 | Options 30 | ------- 31 | 32 | .. option:: -h, --help 33 | 34 | Print help and exit. 35 | 36 | .. option:: -i INTERFACE, --interface=INTERFACE 37 | 38 | Listen on *INTERFACE*. 39 | If unspecified, ndndump searches the system interface list for the lowest numbered, 40 | configured up interface (excluding loopback). 41 | On Linux, a value of "any" can be used to capture packets from all interfaces. 42 | Note that captures on the "any" pseudo-interface will not be done in promiscuous mode. 43 | 44 | .. option:: -r FILE, --read=FILE 45 | 46 | Read packets from *FILE*, which can be created by :manpage:`tcpdump(8)` with its 47 | ``-w`` option, or by similar programs. 48 | 49 | .. option:: -f FILTER, --filter=FILTER 50 | 51 | Print a packet only if its name matches the regular expression *FILTER*. 52 | 53 | .. option:: -p, --no-promiscuous-mode 54 | 55 | Do not put the interface into promiscuous mode. 56 | 57 | .. option:: -t, --no-timestamp 58 | 59 | Do not print a timestamp for each packet. 60 | 61 | .. option:: -v, --verbose 62 | 63 | Produce verbose output. 64 | 65 | .. option:: -V, --version 66 | 67 | Print ndndump and libpcap version strings and exit. 68 | 69 | .. option:: PCAP-FILTER 70 | 71 | :option:`PCAP-FILTER` is an expression in :manpage:`pcap-filter(7)` format that 72 | selects which packets will be analyzed. 73 | If no :option:`PCAP-FILTER` is given, a default filter is used. The default filter 74 | can be seen with the :option:`--help` option. 75 | 76 | Examples 77 | -------- 78 | 79 | Capture on eth1 and print packets containing "ping":: 80 | 81 | ndndump -i eth1 -f '.*ping.*' 82 | -------------------------------------------------------------------------------- /tools/ping/client/tracer.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2022, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Teng Liang 21 | */ 22 | 23 | #ifndef NDN_TOOLS_PING_CLIENT_TRACER_HPP 24 | #define NDN_TOOLS_PING_CLIENT_TRACER_HPP 25 | 26 | #include "core/common.hpp" 27 | 28 | #include "ping.hpp" 29 | 30 | namespace ndn::ping::client { 31 | 32 | /** 33 | * @brief prints ping responses and timeouts 34 | */ 35 | class Tracer : noncopyable 36 | { 37 | public: 38 | /** 39 | * @param ping NDN ping client 40 | * @param options ping client options 41 | */ 42 | Tracer(Ping& ping, const Options& options); 43 | 44 | /** 45 | * @brief Prints ping results when a Data packet is received 46 | * 47 | * @param seq ping sequence number 48 | * @param rtt round trip time 49 | */ 50 | void 51 | onData(uint64_t seq, Rtt rtt); 52 | 53 | /** 54 | * @brief Prints NackReason when a Nack is received 55 | * 56 | * @param seq ping sequence number 57 | * @param rtt round trip time 58 | * @param header the header of Nack 59 | */ 60 | void 61 | onNack(uint64_t seq, Rtt rtt, const lp::NackHeader& header); 62 | 63 | /** 64 | * @brief Prints ping results when timed out 65 | * 66 | * @param seq ping sequence number 67 | */ 68 | void 69 | onTimeout(uint64_t seq); 70 | 71 | /** 72 | * @brief Outputs ping errors to cerr 73 | */ 74 | void 75 | onError(const std::string& msg); 76 | 77 | private: 78 | const Options& m_options; 79 | }; 80 | 81 | } // namespace ndn::ping::client 82 | 83 | #endif // NDN_TOOLS_PING_CLIENT_TRACER_HPP 84 | -------------------------------------------------------------------------------- /core/common.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_CORE_COMMON_HPP 27 | #define NDN_TOOLS_CORE_COMMON_HPP 28 | 29 | #ifdef WITH_TESTS 30 | #define VIRTUAL_WITH_TESTS virtual 31 | #define PUBLIC_WITH_TESTS_ELSE_PROTECTED public 32 | #define PUBLIC_WITH_TESTS_ELSE_PRIVATE public 33 | #define PROTECTED_WITH_TESTS_ELSE_PRIVATE protected 34 | #else 35 | #define VIRTUAL_WITH_TESTS 36 | #define PUBLIC_WITH_TESTS_ELSE_PROTECTED protected 37 | #define PUBLIC_WITH_TESTS_ELSE_PRIVATE private 38 | #define PROTECTED_WITH_TESTS_ELSE_PRIVATE private 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | namespace ndn { 59 | using boost::noncopyable; 60 | } // namespace ndn 61 | 62 | #define FORWARD_TO_MEM_FN(func) \ 63 | [this] (auto&&... args) { this->func(std::forward(args)...); } 64 | 65 | #endif // NDN_TOOLS_CORE_COMMON_HPP 66 | -------------------------------------------------------------------------------- /tools/get/pipeline-interests-aimd.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Shuo Yang 24 | * @author Weiwei Liu 25 | * @author Chavoosh Ghasemi 26 | * @author Klaus Schneider 27 | */ 28 | 29 | #include "pipeline-interests-aimd.hpp" 30 | 31 | #include 32 | 33 | namespace ndn::get { 34 | 35 | PipelineInterestsAimd::PipelineInterestsAimd(Face& face, RttEstimatorWithStats& rttEstimator, 36 | const Options& opts) 37 | : PipelineInterestsAdaptive(face, rttEstimator, opts) 38 | { 39 | if (m_options.isVerbose) { 40 | printOptions(); 41 | } 42 | } 43 | 44 | void 45 | PipelineInterestsAimd::increaseWindow() 46 | { 47 | if (m_cwnd < m_ssthresh) { 48 | m_cwnd += m_options.aiStep; // additive increase 49 | } 50 | else { 51 | m_cwnd += m_options.aiStep / std::floor(m_cwnd); // congestion avoidance 52 | } 53 | 54 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); 55 | } 56 | 57 | void 58 | PipelineInterestsAimd::decreaseWindow() 59 | { 60 | // please refer to RFC 5681, Section 3.1 for the rationale behind it 61 | m_ssthresh = std::max(MIN_SSTHRESH, m_cwnd * m_options.mdCoef); // multiplicative decrease 62 | m_cwnd = m_options.resetCwndToInit ? m_options.initCwnd : m_ssthresh; 63 | 64 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); 65 | } 66 | 67 | } // namespace ndn::get 68 | -------------------------------------------------------------------------------- /tools/ping/client/tracer.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Teng Liang 21 | */ 22 | 23 | #include "tracer.hpp" 24 | 25 | #include 26 | 27 | namespace ndn::ping::client { 28 | 29 | Tracer::Tracer(Ping& ping, const Options& options) 30 | : m_options(options) 31 | { 32 | ping.afterData.connect(FORWARD_TO_MEM_FN(onData)); 33 | ping.afterNack.connect(FORWARD_TO_MEM_FN(onNack)); 34 | ping.afterTimeout.connect(FORWARD_TO_MEM_FN(onTimeout)); 35 | } 36 | 37 | void 38 | Tracer::onData(uint64_t seq, Rtt rtt) 39 | { 40 | if (m_options.shouldPrintTimestamp) { 41 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; 42 | } 43 | 44 | std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time=" 45 | << rtt.count() << " ms\n"; 46 | } 47 | 48 | void 49 | Tracer::onNack(uint64_t seq, Rtt rtt, const lp::NackHeader& header) 50 | { 51 | if (m_options.shouldPrintTimestamp) { 52 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; 53 | } 54 | 55 | std::cout << "nack from " << m_options.prefix << ": seq=" << seq << " time=" 56 | << rtt.count() << " ms" << " reason=" << header.getReason() << "\n"; 57 | } 58 | 59 | void 60 | Tracer::onTimeout(uint64_t seq) 61 | { 62 | if (m_options.shouldPrintTimestamp) { 63 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; 64 | } 65 | 66 | std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << "\n"; 67 | } 68 | 69 | void 70 | Tracer::onError(const std::string& msg) 71 | { 72 | std::cerr << "ERROR: " << msg << "\n"; 73 | } 74 | 75 | } // namespace ndn::ping::client 76 | -------------------------------------------------------------------------------- /tools/get/discover-version.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | * @author Chavoosh Ghasemi 27 | */ 28 | 29 | #ifndef NDN_TOOLS_GET_DISCOVER_VERSION_HPP 30 | #define NDN_TOOLS_GET_DISCOVER_VERSION_HPP 31 | 32 | #include "options.hpp" 33 | 34 | #include 35 | #include 36 | 37 | namespace ndn::get { 38 | 39 | class DataFetcher; 40 | 41 | /** 42 | * @brief Service for discovering the latest Data version. 43 | * 44 | * DiscoverVersion's user is notified once after identifying the latest retrievable version or 45 | * on failure to find any Data version. 46 | */ 47 | class DiscoverVersion 48 | { 49 | public: 50 | DiscoverVersion(Face& face, const Name& prefix, const Options& options); 51 | 52 | /** 53 | * @brief Signal emitted when the versioned name of Data is found. 54 | */ 55 | signal::Signal onDiscoverySuccess; 56 | 57 | /** 58 | * @brief Signal emitted when a failure occurs. 59 | */ 60 | signal::Signal onDiscoveryFailure; 61 | 62 | void 63 | run(); 64 | 65 | private: 66 | void 67 | handleData(const Interest& interest, const Data& data); 68 | 69 | private: 70 | Face& m_face; 71 | const Name m_prefix; 72 | const Options& m_options; 73 | std::shared_ptr m_fetcher; 74 | }; 75 | 76 | } // namespace ndn::get 77 | 78 | #endif // NDN_TOOLS_GET_DISCOVER_VERSION_HPP 79 | -------------------------------------------------------------------------------- /systemd/ndn-ping-server.service.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2019, Regents of the University of California, 2 | # Arizona Board of Regents, 3 | # Colorado State University, 4 | # University Pierre & Marie Curie, Sorbonne University, 5 | # Washington University in St. Louis, 6 | # Beijing Institute of Technology, 7 | # The University of Memphis. 8 | # 9 | # This file is part of ndn-tools (Named Data Networking Essential Tools). 10 | # See AUTHORS.md for complete list of ndn-tools authors and contributors. 11 | # 12 | # ndn-tools is free software: you can redistribute it and/or modify it under the terms 13 | # of the GNU General Public License as published by the Free Software Foundation, 14 | # either version 3 of the License, or (at your option) any later version. 15 | # 16 | # ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 17 | # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 18 | # PURPOSE. See the GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License along with 21 | # ndn-tools, e.g., in COPYING.md file. If not, see . 22 | 23 | [Unit] 24 | Description=NDN Ping Server 25 | Documentation=man:ndnpingserver(1) 26 | BindsTo=nfd.service 27 | After=nfd.service 28 | 29 | [Service] 30 | Environment=HOME=%S/ndn/ndnping 31 | EnvironmentFile=-@SYSCONFDIR@/default/ndnping 32 | ExecStart=@BINDIR@/ndnpingserver ${PREFIX} $FLAGS 33 | Restart=on-failure 34 | RestartPreventExitStatus=2 35 | User=ndn 36 | 37 | CapabilityBoundingSet= 38 | LockPersonality=yes 39 | MemoryDenyWriteExecute=yes 40 | NoNewPrivileges=yes 41 | PrivateDevices=yes 42 | PrivateNetwork=yes 43 | PrivateTmp=yes 44 | PrivateUsers=yes 45 | ProtectControlGroups=yes 46 | ProtectHome=yes 47 | ProtectKernelModules=yes 48 | ProtectKernelTunables=yes 49 | # systemd older than v232 doesn't support a value of "strict" for ProtectSystem, 50 | # so it will ignore that line and use ProtectSystem=full; with newer systemd, 51 | # the latter assignment is recognized and takes precedence, resulting in an 52 | # effective setting of ProtectSystem=strict 53 | ProtectSystem=full 54 | ProtectSystem=strict 55 | RestrictAddressFamilies=AF_UNIX 56 | RestrictNamespaces=yes 57 | RestrictRealtime=yes 58 | StateDirectory=ndn/ndnping 59 | SystemCallArchitectures=native 60 | SystemCallErrorNumber=EPERM 61 | SystemCallFilter=~@aio @chown @clock @cpu-emulation @debug @keyring @module @mount @obsolete @privileged @raw-io @reboot @resources @setuid @swap 62 | 63 | [Install] 64 | WantedBy=multi-user.target 65 | WantedBy=nfd.service 66 | -------------------------------------------------------------------------------- /tools/ping/server/ping-server.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Jerald Paul Abraham 21 | */ 22 | 23 | #include "ping-server.hpp" 24 | 25 | #include 26 | #include 27 | 28 | namespace ndn::ping::server { 29 | 30 | PingServer::PingServer(Face& face, KeyChain& keyChain, const Options& options) 31 | : m_options(options) 32 | , m_face(face) 33 | , m_keyChain(keyChain) 34 | { 35 | auto b = std::make_shared(); 36 | b->assign(m_options.payloadSize, 'a'); 37 | m_payload = Block(tlv::Content, std::move(b)); 38 | } 39 | 40 | void 41 | PingServer::start() 42 | { 43 | m_registeredPrefix = m_face.setInterestFilter(Name(m_options.prefix).append("ping"), 44 | [this] (const auto&, const auto& interest) { onInterest(interest); }, 45 | [] (const auto&, const auto& reason) { 46 | NDN_THROW(std::runtime_error("Failed to register prefix: " + reason)); 47 | }); 48 | } 49 | 50 | void 51 | PingServer::stop() 52 | { 53 | m_registeredPrefix.cancel(); 54 | } 55 | 56 | size_t 57 | PingServer::getNPings() const 58 | { 59 | return m_nPings; 60 | } 61 | 62 | void 63 | PingServer::onInterest(const Interest& interest) 64 | { 65 | afterReceive(interest.getName()); 66 | 67 | auto data = std::make_shared(interest.getName()); 68 | data->setFreshnessPeriod(m_options.freshnessPeriod); 69 | data->setContent(m_payload); 70 | m_keyChain.sign(*data, signingWithSha256()); 71 | m_face.put(*data); 72 | 73 | ++m_nPings; 74 | if (m_options.nMaxPings > 0 && m_options.nMaxPings == m_nPings) { 75 | afterFinish(); 76 | } 77 | } 78 | 79 | } // namespace ndn::ping::server 80 | -------------------------------------------------------------------------------- /tests/ping/server/ping-server.t.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #include "tools/ping/server/ping-server.hpp" 21 | 22 | #include "tests/test-common.hpp" 23 | #include "tests/io-fixture.hpp" 24 | #include "tests/key-chain-fixture.hpp" 25 | 26 | #include 27 | 28 | namespace ndn::ping::server::tests { 29 | 30 | using namespace ndn::tests; 31 | 32 | class PingServerFixture : public IoFixture, public KeyChainFixture 33 | { 34 | protected: 35 | Interest 36 | makePingInterest(int seq) const 37 | { 38 | Name name(pingOptions.prefix); 39 | name.append("ping") 40 | .append(std::to_string(seq)); 41 | 42 | return Interest(name) 43 | .setMustBeFresh(true) 44 | .setInterestLifetime(2_s); 45 | } 46 | 47 | private: 48 | static Options 49 | makeOptions() 50 | { 51 | Options opt; 52 | opt.prefix = "/test-prefix"; 53 | opt.freshnessPeriod = 5_s; 54 | opt.nMaxPings = 2; 55 | opt.payloadSize = 0; 56 | opt.wantTimestamp = false; 57 | opt.wantQuiet = true; 58 | return opt; 59 | } 60 | 61 | protected: 62 | DummyClientFace face{m_io, m_keyChain, {false, true}}; 63 | Options pingOptions{makeOptions()}; 64 | PingServer pingServer{face, m_keyChain, pingOptions}; 65 | }; 66 | 67 | BOOST_AUTO_TEST_SUITE(Ping) 68 | BOOST_AUTO_TEST_SUITE(TestServer) 69 | 70 | BOOST_FIXTURE_TEST_CASE(Receive, PingServerFixture) 71 | { 72 | BOOST_TEST(pingServer.getNPings() == 0); 73 | pingServer.start(); 74 | 75 | advanceClocks(1_ms, 200); 76 | 77 | face.receive(makePingInterest(1000)); 78 | face.receive(makePingInterest(1001)); 79 | 80 | m_io.run(); 81 | 82 | BOOST_TEST(pingServer.getNPings() == 2); 83 | } 84 | 85 | BOOST_AUTO_TEST_SUITE_END() // TestServer 86 | BOOST_AUTO_TEST_SUITE_END() // Ping 87 | 88 | } // namespace ndn::ping::server::tests 89 | -------------------------------------------------------------------------------- /tools/get/options.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Andrea Tosatto 24 | * @author Davide Pesavento 25 | */ 26 | 27 | #ifndef NDN_TOOLS_GET_OPTIONS_HPP 28 | #define NDN_TOOLS_GET_OPTIONS_HPP 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | namespace ndn::get { 36 | 37 | struct Options 38 | { 39 | // Common options 40 | time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME; 41 | int maxRetriesOnTimeoutOrNack = 15; 42 | bool disableVersionDiscovery = false; 43 | bool mustBeFresh = false; 44 | bool isQuiet = false; 45 | bool isVerbose = false; 46 | 47 | // Fixed pipeline options 48 | size_t maxPipelineSize = 1; 49 | 50 | // Adaptive pipeline common options 51 | double initCwnd = 2.0; ///< initial congestion window size 52 | double initSsthresh = std::numeric_limits::max(); ///< initial slow start threshold 53 | time::milliseconds rtoCheckInterval{10}; ///< interval for checking retransmission timer 54 | bool ignoreCongMarks = false; ///< disable window decrease after receiving congestion mark 55 | bool disableCwa = false; ///< disable conservative window adaptation 56 | 57 | // AIMD pipeline options 58 | double aiStep = 1.0; ///< AIMD additive increase step (in segments) 59 | double mdCoef = 0.5; ///< AIMD multiplicative decrease factor 60 | bool resetCwndToInit = false; ///< reduce cwnd to initCwnd when loss event occurs 61 | 62 | // Cubic pipeline options 63 | double cubicBeta = 0.7; ///< cubic multiplicative decrease factor 64 | bool enableFastConv = false; ///< use cubic fast convergence 65 | }; 66 | 67 | } // namespace ndn::get 68 | 69 | #endif // NDN_TOOLS_GET_OPTIONS_HPP 70 | -------------------------------------------------------------------------------- /.waf-tools/sphinx.py: -------------------------------------------------------------------------------- 1 | # inspired by code by Hans-Martin von Gaudecker, 2012 2 | 3 | """Support for Sphinx documentation""" 4 | 5 | import os 6 | from waflib import Task, TaskGen 7 | 8 | 9 | class sphinx_build(Task.Task): 10 | color = 'BLUE' 11 | run_str = '${SPHINX_BUILD} -q -b ${BUILDERNAME} -D ${VERSION} -D ${RELEASE} -d ${DOCTREEDIR} ${SRCDIR} ${OUTDIR}' 12 | 13 | def keyword(self): 14 | return f'Processing ({self.env.BUILDERNAME})' 15 | 16 | 17 | # from https://docs.python.org/3.12/whatsnew/3.12.html#imp 18 | def load_source(modname, filename): 19 | import importlib.util 20 | from importlib.machinery import SourceFileLoader 21 | loader = SourceFileLoader(modname, filename) 22 | spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) 23 | module = importlib.util.module_from_spec(spec) 24 | loader.exec_module(module) 25 | return module 26 | 27 | 28 | @TaskGen.feature('sphinx') 29 | @TaskGen.before_method('process_source') 30 | def process_sphinx(self): 31 | """Set up the task generator with a Sphinx instance and create a task.""" 32 | 33 | conf = self.path.find_node(self.config) 34 | if not conf: 35 | self.bld.fatal(f'Sphinx configuration file {repr(self.config)} not found') 36 | 37 | inputs = [conf] + self.to_nodes(self.source) 38 | task = self.create_task('sphinx_build', inputs, always_run=getattr(self, 'always', False)) 39 | 40 | confdir = conf.parent.abspath() 41 | buildername = getattr(self, 'builder', 'html') 42 | srcdir = getattr(self, 'srcdir', confdir) 43 | outdir = self.path.find_or_declare(getattr(self, 'outdir', buildername)).get_bld() 44 | doctreedir = getattr(self, 'doctreedir', os.path.join(outdir.abspath(), '.doctrees')) 45 | release = getattr(self, 'release', self.version) 46 | 47 | task.env['BUILDERNAME'] = buildername 48 | task.env['SRCDIR'] = srcdir 49 | task.env['OUTDIR'] = outdir.abspath() 50 | task.env['DOCTREEDIR'] = doctreedir 51 | task.env['VERSION'] = f'version={self.version}' 52 | task.env['RELEASE'] = f'release={release}' 53 | 54 | if buildername == 'man': 55 | confdata = load_source('sphinx_conf', conf.abspath()) 56 | for i in confdata.man_pages: 57 | target = outdir.find_or_declare(f'{i[1]}.{i[4]}') 58 | task.outputs.append(target) 59 | if self.install_path: 60 | self.bld.install_files(f'{self.install_path}/man{i[4]}/', target) 61 | else: 62 | task.outputs.append(outdir) 63 | 64 | # prevent process_source from complaining that there is no extension mapping for .rst files 65 | self.source = [] 66 | 67 | 68 | def configure(conf): 69 | """Check if sphinx-build program is available.""" 70 | conf.find_program('sphinx-build', var='SPHINX_BUILD', mandatory=False) 71 | 72 | 73 | # sphinx command 74 | from waflib.Build import BuildContext 75 | class sphinx(BuildContext): 76 | cmd = 'sphinx' 77 | fun = 'sphinx' 78 | -------------------------------------------------------------------------------- /tests/test-common.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_TESTS_TEST_COMMON_HPP 27 | #define NDN_TOOLS_TESTS_TEST_COMMON_HPP 28 | 29 | #include "core/common.hpp" 30 | #include "tests/boost-test.hpp" 31 | 32 | #include 33 | #include 34 | 35 | namespace ndn::tests { 36 | 37 | /** 38 | * \brief Create an Interest. 39 | */ 40 | std::shared_ptr 41 | makeInterest(const Name& name, bool canBePrefix = false, 42 | std::optional lifetime = std::nullopt, 43 | std::optional nonce = std::nullopt); 44 | 45 | /** 46 | * \brief Create a Data with a null (i.e., empty) signature. 47 | * 48 | * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`. 49 | */ 50 | std::shared_ptr 51 | makeData(const Name& name); 52 | 53 | /** 54 | * \brief Add a null signature to \p data. 55 | */ 56 | Data& 57 | signData(Data& data); 58 | 59 | /** 60 | * \brief Add a null signature to \p data. 61 | */ 62 | inline std::shared_ptr 63 | signData(std::shared_ptr data) 64 | { 65 | signData(*data); 66 | return data; 67 | } 68 | 69 | /** 70 | * \brief Create a Nack. 71 | */ 72 | lp::Nack 73 | makeNack(Interest interest, lp::NackReason reason); 74 | 75 | /** 76 | * \brief Replace a name component in a packet. 77 | * \param[in,out] pkt the packet 78 | * \param index the index of the name component to replace 79 | * \param args arguments to name::Component constructor 80 | */ 81 | template 82 | void 83 | setNameComponent(Packet& pkt, ssize_t index, Args&& ...args) 84 | { 85 | Name name = pkt.getName(); 86 | name.set(index, name::Component(std::forward(args)...)); 87 | pkt.setName(name); 88 | } 89 | 90 | } // namespace ndn::tests 91 | 92 | #endif // NDN_TOOLS_TESTS_TEST_COMMON_HPP 93 | -------------------------------------------------------------------------------- /tests/clock-fixture.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | */ 25 | 26 | #ifndef NDN_TOOLS_TESTS_CLOCK_FIXTURE_HPP 27 | #define NDN_TOOLS_TESTS_CLOCK_FIXTURE_HPP 28 | 29 | #include 30 | 31 | namespace ndn::tests { 32 | 33 | /** \brief A test fixture that overrides steady clock and system clock. 34 | */ 35 | class ClockFixture 36 | { 37 | public: 38 | virtual 39 | ~ClockFixture(); 40 | 41 | /** \brief Advance steady and system clocks. 42 | * 43 | * Clocks are advanced in increments of \p tick for \p nTicks ticks. 44 | * afterTick() is called after each tick. 45 | * 46 | * Exceptions thrown during I/O events are propagated to the caller. 47 | * Clock advancement will stop in the event of an exception. 48 | */ 49 | void 50 | advanceClocks(time::nanoseconds tick, size_t nTicks = 1) 51 | { 52 | advanceClocks(tick, tick * nTicks); 53 | } 54 | 55 | /** \brief Advance steady and system clocks. 56 | * 57 | * Clocks are advanced in increments of \p tick for \p total time. 58 | * The last increment might be shorter than \p tick. 59 | * afterTick() is called after each tick. 60 | * 61 | * Exceptions thrown during I/O events are propagated to the caller. 62 | * Clock advancement will stop in the event of an exception. 63 | */ 64 | void 65 | advanceClocks(time::nanoseconds tick, time::nanoseconds total); 66 | 67 | protected: 68 | ClockFixture(); 69 | 70 | private: 71 | /** \brief Called by advanceClocks() after each clock advancement (tick). 72 | * 73 | * The base class implementation is a no-op. 74 | */ 75 | virtual void 76 | afterTick() 77 | { 78 | } 79 | 80 | protected: 81 | std::shared_ptr m_steadyClock; 82 | std::shared_ptr m_systemClock; 83 | }; 84 | 85 | } // namespace ndn::tests 86 | 87 | #endif // NDN_TOOLS_TESTS_CLOCK_FIXTURE_HPP 88 | -------------------------------------------------------------------------------- /tests/get/pipeline-interests-fixture.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Andrea Tosatto 24 | * @author Davide Pesavento 25 | * @author Weiwei Liu 26 | * @author Chavoosh Ghasemi 27 | */ 28 | 29 | #ifndef NDN_TOOLS_TESTS_GET_PIPELINE_INTERESTS_FIXTURE_HPP 30 | #define NDN_TOOLS_TESTS_GET_PIPELINE_INTERESTS_FIXTURE_HPP 31 | 32 | #include "tools/get/pipeline-interests.hpp" 33 | 34 | #include "tests/test-common.hpp" 35 | #include "tests/io-fixture.hpp" 36 | 37 | #include 38 | 39 | namespace ndn::tests { 40 | 41 | using namespace ndn::get; 42 | 43 | class PipelineInterestsFixture : public IoFixture 44 | { 45 | protected: 46 | void 47 | setPipeline(std::unique_ptr pline) 48 | { 49 | m_pipeline = std::move(pline); 50 | } 51 | 52 | std::shared_ptr 53 | makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const 54 | { 55 | auto data = std::make_shared(Name(name).appendVersion(0).appendSegment(segmentNo)); 56 | if (setFinalBlockId) 57 | data->setFinalBlock(name::Component::fromSegment(nDataSegments - 1)); 58 | return signData(data); 59 | } 60 | 61 | std::shared_ptr 62 | makeDataWithSegmentAndCongMark(uint64_t segmentNo, 63 | uint64_t congestionMark = 1, 64 | bool setFinalBlockId = true) const 65 | { 66 | auto data = makeDataWithSegment(segmentNo, setFinalBlockId); 67 | data->setCongestionMark(congestionMark); 68 | return data; 69 | } 70 | 71 | void 72 | run(const Name& name, uint64_t version = 0) 73 | { 74 | m_pipeline->run(Name(name).appendVersion(version), 75 | [] (const Data&) {}, 76 | [this] (const std::string&) { hasFailed = true; }); 77 | } 78 | 79 | protected: 80 | DummyClientFace face{m_io}; 81 | Name name{"/ndn/chunks/test"}; 82 | uint64_t nDataSegments = 0; 83 | bool hasFailed = false; 84 | 85 | private: 86 | std::unique_ptr m_pipeline; 87 | }; 88 | 89 | } // namespace ndn::tests 90 | 91 | #endif // NDN_TOOLS_TESTS_GET_PIPELINE_INTERESTS_FIXTURE_HPP 92 | -------------------------------------------------------------------------------- /tools/get/consumer.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | */ 27 | 28 | #include "consumer.hpp" 29 | 30 | #include 31 | 32 | namespace ndn::get { 33 | 34 | Consumer::Consumer(security::Validator& validator, std::ostream& os) 35 | : m_validator(validator) 36 | , m_outputStream(os) 37 | { 38 | } 39 | 40 | void 41 | Consumer::run(std::unique_ptr discover, std::unique_ptr pipeline) 42 | { 43 | m_discover = std::move(discover); 44 | m_pipeline = std::move(pipeline); 45 | m_nextToPrint = 0; 46 | m_bufferedData.clear(); 47 | 48 | m_discover->onDiscoverySuccess.connect([this] (const Name& versionedName) { 49 | m_pipeline->run(versionedName, 50 | FORWARD_TO_MEM_FN(handleData), 51 | [] (const std::string& msg) { NDN_THROW(std::runtime_error(msg)); }); 52 | }); 53 | m_discover->onDiscoveryFailure.connect([] (const std::string& msg) { 54 | NDN_THROW(std::runtime_error(msg)); 55 | }); 56 | m_discover->run(); 57 | } 58 | 59 | void 60 | Consumer::handleData(const Data& data) 61 | { 62 | auto dataPtr = data.shared_from_this(); 63 | 64 | m_validator.validate(data, 65 | [this, dataPtr] (const Data& data) { 66 | if (data.getContentType() == ndn::tlv::ContentType_Nack) { 67 | NDN_THROW(ApplicationNackError(data)); 68 | } 69 | 70 | // 'data' passed to callback comes from DataValidationState and was not created with make_shared 71 | m_bufferedData[getSegmentFromPacket(data)] = dataPtr; 72 | writeInOrderData(); 73 | }, 74 | [] (const Data&, const security::ValidationError& error) { 75 | NDN_THROW(DataValidationError(error)); 76 | }); 77 | } 78 | 79 | void 80 | Consumer::writeInOrderData() 81 | { 82 | for (auto it = m_bufferedData.begin(); 83 | it != m_bufferedData.end() && it->first == m_nextToPrint; 84 | it = m_bufferedData.erase(it), ++m_nextToPrint) { 85 | const Block& content = it->second->getContent(); 86 | m_outputStream.write(reinterpret_cast(content.value()), content.value_size()); 87 | } 88 | } 89 | 90 | } // namespace ndn::get 91 | -------------------------------------------------------------------------------- /manpages/ndnserve.rst: -------------------------------------------------------------------------------- 1 | ndnserve 2 | ======== 3 | 4 | Synopsis 5 | -------- 6 | 7 | **ndnserve** [*option*]... *name* 8 | 9 | Description 10 | ----------- 11 | 12 | :program:`ndnserve` is a producer program that reads a file from the standard input 13 | and makes it available as NDN Data segments. 14 | 15 | Version and segment number components are appended to the specified *name* as needed, 16 | according to the `NDN naming conventions`_. 17 | 18 | .. _NDN naming conventions: https://named-data.net/publications/techreports/ndn-tr-22-3-ndn-memo-naming-conventions/ 19 | 20 | Options 21 | ------- 22 | 23 | .. option:: -h, --help 24 | 25 | Print help and exit. 26 | 27 | .. option:: -f, --freshness MILLISECS 28 | 29 | FreshnessPeriod of the published Data packets, in milliseconds. 30 | The default is 10000 (10 seconds). 31 | 32 | .. option:: -s, --size BYTES 33 | 34 | Maximum chunk size, in bytes. The default is 8000 bytes. 35 | 36 | .. option:: -N, --naming-convention CONVENTION 37 | 38 | Select the convention used to encode NDN name components. The available choices are: 39 | 40 | * ``marker`` (shorthand: ``m`` or ``1``) for the old marker-based encoding; 41 | * ``typed`` (shorthand: ``t`` or ``2``) for the new encoding based on typed name components. 42 | 43 | If this option is not specified, the ndn-cxx library's default is used. 44 | 45 | .. option:: -S, --signing-info STRING 46 | 47 | Specify the parameters used to sign the Data packets. If omitted, the default key 48 | of the default identity is used. The general syntax is ``:``. The 49 | most common supported combinations are as follows: 50 | 51 | * Sign with the default certificate of the default key of an identity: ``id:/``. 52 | * Sign with the default certificate of a specific key: ``key://ksk-1``. 53 | * Sign with a specific certificate: ``cert://KEY/ksk-1/ID-CERT/v=1``. 54 | * Sign with a SHA-256 digest: ``id:/localhost/identity/digest-sha256``. Note that this 55 | is only a hash function, not a real signature, but it can significantly speed up 56 | packet signing operations. 57 | 58 | .. option:: -p, --print-data-version 59 | 60 | Print version of the published Data to the standard output. 61 | 62 | .. option:: -q, --quiet 63 | 64 | Turn off all non-error output. 65 | 66 | .. option:: -v, --verbose 67 | 68 | Produce verbose output. 69 | 70 | .. option:: -V, --version 71 | 72 | Print program version and exit. 73 | 74 | Examples 75 | -------- 76 | 77 | The following command will publish the text of the GPL-3 license under the ``/localhost/demo/gpl3`` 78 | prefix:: 79 | 80 | ndnserve /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3 81 | 82 | To see the published version, you can run the program with the **-p** option:: 83 | 84 | ndnserve -p /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3 85 | 86 | This command will print the published version to the standard output. 87 | 88 | To publish Data with a specific version, you must append a version component to the end of the 89 | prefix. The version component must follow the aforementioned NDN naming conventions. 90 | For example, the following command will publish version 1615519151142 of ``/localhost/demo/gpl3`` 91 | using the "typed" naming convention:: 92 | 93 | ndnserve -Nt /localhost/demo/gpl3/v=1615519151142 < /usr/share/common-licenses/GPL-3 94 | 95 | See Also 96 | -------- 97 | 98 | .. target-notes:: 99 | -------------------------------------------------------------------------------- /tests/ping/client/ping.t.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2023, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #include "tools/ping/client/ping.hpp" 21 | 22 | #include "tests/test-common.hpp" 23 | #include "tests/io-fixture.hpp" 24 | 25 | #include 26 | 27 | namespace ndn::ping::client::tests { 28 | 29 | using namespace ndn::tests; 30 | 31 | BOOST_AUTO_TEST_SUITE(Ping) 32 | BOOST_AUTO_TEST_SUITE(TestClient) 33 | 34 | using client::Ping; 35 | 36 | BOOST_FIXTURE_TEST_CASE(Basic, IoFixture) 37 | { 38 | DummyClientFace face(m_io, {true, true}); 39 | Options pingOptions; 40 | pingOptions.prefix = "/test-prefix"; 41 | pingOptions.shouldAllowStaleData = false; 42 | pingOptions.shouldGenerateRandomSeq = false; 43 | pingOptions.shouldPrintTimestamp = false; 44 | pingOptions.nPings = 4; 45 | pingOptions.interval = 100_ms; 46 | pingOptions.timeout = 2_s; 47 | pingOptions.startSeq = 1000; 48 | Ping ping(face, pingOptions); 49 | 50 | int nFinishSignals = 0; 51 | std::vector dataSeqs; 52 | std::vector nackSeqs; 53 | std::vector timeoutSeqs; 54 | 55 | ping.afterData.connect([&] (uint64_t seq, auto&&...) { dataSeqs.push_back(seq); }); 56 | ping.afterNack.connect([&] (uint64_t seq, auto&&...) { nackSeqs.push_back(seq); }); 57 | ping.afterTimeout.connect([&] (uint64_t seq, auto&&...) { timeoutSeqs.push_back(seq); }); 58 | ping.afterFinish.connect([&] { 59 | BOOST_REQUIRE_EQUAL(dataSeqs.size(), 2); 60 | BOOST_REQUIRE_EQUAL(nackSeqs.size(), 1); 61 | BOOST_REQUIRE_EQUAL(timeoutSeqs.size(), 1); 62 | 63 | BOOST_CHECK_EQUAL(dataSeqs[0], 1000); 64 | BOOST_CHECK_EQUAL(nackSeqs[0], 1001); 65 | BOOST_CHECK_EQUAL(dataSeqs[1], 1002); 66 | BOOST_CHECK_EQUAL(timeoutSeqs[0], 1003); 67 | 68 | nFinishSignals++; 69 | }); 70 | 71 | ping.start(); 72 | 73 | this->advanceClocks(1_ms, 500); 74 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 4); 75 | 76 | auto data = makeData("/test-prefix/ping/1000"); 77 | data->setFreshnessPeriod(1_s); 78 | face.receive(*data); 79 | 80 | face.receive(makeNack(face.sentInterests[1], lp::NackReason::DUPLICATE)); 81 | 82 | data = makeData("/test-prefix/ping/1002"); 83 | data->setFreshnessPeriod(1_s); 84 | face.receive(*data); 85 | 86 | this->advanceClocks(100_ms, 20); 87 | 88 | // /test-prefix/ping/1003 is unanswered and will timeout 89 | 90 | BOOST_CHECK_EQUAL(nFinishSignals, 1); 91 | } 92 | 93 | BOOST_AUTO_TEST_SUITE_END() // TestClient 94 | BOOST_AUTO_TEST_SUITE_END() // Ping 95 | 96 | } // namespace ndn::ping::client::tests 97 | -------------------------------------------------------------------------------- /tests/dissect-wireshark/ndnlpv2.hex: -------------------------------------------------------------------------------- 1 | A1B2C3D4 2 | 00020004 3 | 00000000 4 | 00000000 5 | 00010000 6 | 00000001 7 | 8 | # packet 1 9 | 00000000 10 | 00000000 11 | 00000030 12 | 00000030 13 | 14 | 01005E0017AA 15 | 000000000000 16 | 8624 17 | 18 | ## LpPacket with unrecognized headers 19 | 6420 20 | 5500 21 | 5600 22 | 5700 23 | 5800 24 | 5900 25 | 6000 26 | 6100 27 | 6300 28 | FD032400 29 | FD032500 30 | FD032600 31 | FD032700 32 | 33 | # packet 2 34 | 00000000 35 | 00000000 36 | 00000029 37 | 00000029 38 | 39 | 01005E0017AA 40 | 000000000000 41 | 8624 42 | 43 | ## LpPacket with reordered headers 44 | 6419 45 | 530102 46 | 5108B0B1B2B3B4B5B600 47 | 5007 050B0703080141 48 | 520100 49 | 50 | # packet 3 51 | 00000000 52 | 00000000 53 | 00000029 54 | 00000029 55 | 56 | 01005E0017AA 57 | 000000000000 58 | 8624 59 | 60 | ## first half of fragmented Interest 61 | 6419 62 | 5108B0B1B2B3B4B5B600 63 | 520100 64 | 530102 65 | 5007 66 | 050B0703080141 67 | 68 | # packet 4 69 | 00000000 70 | 00000000 71 | 00000028 72 | 00000028 73 | 74 | 01005E0017AA 75 | 000000000000 76 | 8624 77 | 78 | ## second half of fragmented Interest 79 | 6418 80 | 5108B0B1B2B3B4B5B601 81 | 520101 82 | 530102 83 | 5006 84 | 0A04A0A1A2A3 85 | 86 | # packet 5 87 | 00000000 88 | 00000000 89 | 00000028 90 | 00000028 91 | 92 | 01005E0017AA 93 | 000000000000 94 | 8624 95 | 96 | ## Nack~Congestion 97 | 6418 98 | FD032005 FD03210132 99 | 500D 100 | 050B07030801410A04A0A1A2A3 101 | 102 | # packet 6 103 | 00000000 104 | 00000000 105 | 00000028 106 | 00000028 107 | 108 | 01005E0017AA 109 | 000000000000 110 | 8624 111 | 112 | ## Nack~Duplicate 113 | 6418 114 | FD032005 FD03210164 115 | 500D 116 | 050B07030801410A04A0A1A2A3 117 | 118 | # packet 7 119 | 00000000 120 | 00000000 121 | 00000028 122 | 00000028 123 | 124 | 01005E0017AA 125 | 000000000000 126 | 8624 127 | 128 | ## Nack~NoRoute 129 | 6418 130 | FD032005 FD03210196 131 | 500D 132 | 050B07030801410A04A0A1A2A3 133 | 134 | # packet 8 135 | 00000000 136 | 00000000 137 | 00000028 138 | 00000028 139 | 140 | 01005E0017AA 141 | 000000000000 142 | 8624 143 | 144 | ## Nack unrecognized reason 145 | 6418 146 | FD032005 FD03210101 147 | 500D 148 | 050B07030801410A04A0A1A2A3 149 | 150 | # packet 9 151 | 00000000 152 | 00000000 153 | 00000023 154 | 00000023 155 | 156 | 01005E0017AA 157 | 000000000000 158 | 8624 159 | 160 | ## Nack no reason 161 | 6413 162 | FD032000 163 | 500D 164 | 050B07030801410A04A0A1A2A3 165 | 166 | # packet 10 167 | 00000000 168 | 00000000 169 | 00000029 170 | 00000029 171 | 172 | 01005E0017AA 173 | 000000000000 174 | 8624 175 | 176 | ## Interest with PIT token 177 | 6419 178 | 6208D0D1D2D3D4D5D6D7 179 | 500D 180 | 050B07030801410A04A0A1A2A3 181 | 182 | # packet 11 183 | 00000000 184 | 00000000 185 | 0000004E 186 | 0000004E 187 | 188 | 01005E0017AA 189 | 000000000000 190 | 8624 191 | 192 | ## Data with CongestionMark=1 and TxSequence 193 | 643E 194 | FD03400101 195 | FD034808E0E1E2E3E4E5E6E7 196 | 502B 197 | 0629 0700 16031B0100 1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76 198 | 199 | # packet 12 200 | 00000000 201 | 00000000 202 | 00000070 203 | 00000070 204 | 205 | 01005E0017AA 206 | 000000000000 207 | 8624 208 | 209 | ## IDLE packet with Acks 210 | 6460 211 | FD034408E0E1E2E3E4E5E600 212 | FD034408E0E1E2E3E4E5E601 213 | FD034408E0E1E2E3E4E5E602 214 | FD034408E0E1E2E3E4E5E603 215 | FD034408E0E1E2E3E4E5E604 216 | FD034408E0E1E2E3E4E5E605 217 | FD034408E0E1E2E3E4E5E606 218 | FD034408E0E1E2E3E4E5E607 219 | -------------------------------------------------------------------------------- /tools/get/pipeline-interests-fixed.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | * @author Davide Pesavento 27 | * @author Chavoosh Ghasemi 28 | */ 29 | 30 | #ifndef NDN_TOOLS_GET_PIPELINE_INTERESTS_FIXED_HPP 31 | #define NDN_TOOLS_GET_PIPELINE_INTERESTS_FIXED_HPP 32 | 33 | #include "pipeline-interests.hpp" 34 | 35 | #include 36 | 37 | namespace ndn::get { 38 | 39 | class DataFetcher; 40 | 41 | /** 42 | * @brief Service for retrieving Data via an Interest pipeline 43 | * 44 | * Retrieves all segments of Data under a given prefix by maintaining a fixed-size window of 45 | * N Interests in flight. A user-specified callback function is used to notify the arrival of 46 | * each segment of Data. 47 | * 48 | * No guarantees are made as to the order in which segments are fetched or callbacks are invoked, 49 | * i.e. out-of-order delivery is possible. 50 | */ 51 | class PipelineInterestsFixed final : public PipelineInterests 52 | { 53 | public: 54 | PipelineInterestsFixed(Face& face, const Options& opts); 55 | 56 | ~PipelineInterestsFixed() final; 57 | 58 | private: 59 | /** 60 | * @brief fetch all the segments between 0 and m_lastSegmentNo 61 | * 62 | * Starts a fixed-window pipeline with size equal to m_options.maxPipelineSize. The pipeline 63 | * will fetch every segment until the last segment is successfully received or an error occurs. 64 | */ 65 | void 66 | doRun() final; 67 | 68 | void 69 | doCancel() final; 70 | 71 | /** 72 | * @brief fetch the next segment that has not been requested yet 73 | * 74 | * @return false if there is an error or all the segments have been fetched, true otherwise 75 | */ 76 | bool 77 | fetchNextSegment(size_t pipeNo); 78 | 79 | void 80 | handleData(const Interest& interest, const Data& data, size_t pipeNo); 81 | 82 | void 83 | handleFail(const std::string& reason, size_t pipeNo); 84 | 85 | private: 86 | std::vector, uint64_t>> m_segmentFetchers; 87 | 88 | /** 89 | * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId 90 | * is false, this is usually not a fatal error for the pipeline 91 | */ 92 | bool m_hasFailure = false; 93 | }; 94 | 95 | } // namespace ndn::get 96 | 97 | #endif // NDN_TOOLS_GET_PIPELINE_INTERESTS_FIXED_HPP 98 | -------------------------------------------------------------------------------- /tools/serve/producer.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | * @author Davide Pesavento 27 | * @author Klaus Schneider 28 | */ 29 | 30 | #ifndef NDN_TOOLS_SERVE_PRODUCER_HPP 31 | #define NDN_TOOLS_SERVE_PRODUCER_HPP 32 | 33 | #include "core/common.hpp" 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | namespace ndn::serve { 41 | 42 | /** 43 | * @brief Segmented & versioned data publisher. 44 | * 45 | * Packetizes and publishes data from an input stream as `/prefix//`. 46 | * Unless another value is provided, the current time is used as the version number. 47 | * The packet store always has at least one item, even when the input is empty. 48 | */ 49 | class Producer : noncopyable 50 | { 51 | public: 52 | struct Options 53 | { 54 | security::SigningInfo signingInfo; 55 | time::milliseconds freshnessPeriod = 10_s; 56 | size_t maxSegmentSize = 8000; 57 | bool isQuiet = false; 58 | bool isVerbose = false; 59 | bool wantShowVersion = false; 60 | }; 61 | 62 | /** 63 | * @brief Create the producer. 64 | * @param prefix prefix used to publish data; if the last component is not a valid 65 | * version number, the current system time is used as version number. 66 | */ 67 | Producer(const Name& prefix, Face& face, KeyChain& keyChain, std::istream& is, 68 | const Options& opts); 69 | 70 | /** 71 | * @brief Run the producer. 72 | */ 73 | void 74 | run(); 75 | 76 | private: 77 | /** 78 | * @brief Respond with a metadata packet containing the versioned content name. 79 | */ 80 | void 81 | processDiscoveryInterest(const Interest& interest); 82 | 83 | /** 84 | * @brief Respond with the requested segment of content. 85 | */ 86 | void 87 | processSegmentInterest(const Interest& interest); 88 | 89 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: 90 | std::vector> m_store; 91 | 92 | private: 93 | Name m_prefix; 94 | Name m_versionedPrefix; 95 | Face& m_face; 96 | KeyChain& m_keyChain; 97 | const Options m_options; 98 | }; 99 | 100 | } // namespace ndn::serve 101 | 102 | #endif // NDN_TOOLS_SERVE_PRODUCER_HPP 103 | -------------------------------------------------------------------------------- /tools/get/consumer.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | */ 27 | 28 | #ifndef NDN_TOOLS_GET_CONSUMER_HPP 29 | #define NDN_TOOLS_GET_CONSUMER_HPP 30 | 31 | #include "discover-version.hpp" 32 | #include "pipeline-interests.hpp" 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | namespace ndn::get { 42 | 43 | /** 44 | * @brief Segmented version consumer. 45 | * 46 | * Discover the latest version of the data published under a specified prefix, and retrieve all the 47 | * segments associated to that version. The segments are fetched in order and written to a 48 | * user-specified stream in the same order. 49 | */ 50 | class Consumer : noncopyable 51 | { 52 | public: 53 | class ApplicationNackError : public std::runtime_error 54 | { 55 | public: 56 | explicit 57 | ApplicationNackError(const Data& data) 58 | : std::runtime_error("Application generated Nack: " + boost::lexical_cast(data)) 59 | { 60 | } 61 | }; 62 | 63 | class DataValidationError : public std::runtime_error 64 | { 65 | public: 66 | explicit 67 | DataValidationError(const security::ValidationError& error) 68 | : std::runtime_error(boost::lexical_cast(error)) 69 | { 70 | } 71 | }; 72 | 73 | /** 74 | * @brief Create the consumer 75 | */ 76 | explicit 77 | Consumer(security::Validator& validator, std::ostream& os = std::cout); 78 | 79 | /** 80 | * @brief Run the consumer 81 | */ 82 | void 83 | run(std::unique_ptr discover, std::unique_ptr pipeline); 84 | 85 | private: 86 | void 87 | handleData(const Data& data); 88 | 89 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: 90 | void 91 | writeInOrderData(); 92 | 93 | private: 94 | security::Validator& m_validator; 95 | std::ostream& m_outputStream; 96 | std::unique_ptr m_discover; 97 | std::unique_ptr m_pipeline; 98 | uint64_t m_nextToPrint = 0; 99 | 100 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: 101 | std::map> m_bufferedData; 102 | }; 103 | 104 | } // namespace ndn::get 105 | 106 | #endif // NDN_TOOLS_GET_CONSUMER_HPP 107 | -------------------------------------------------------------------------------- /tools/dissect/main.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2025, Regents of the University of California. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #include "dissector.hpp" 21 | #include "core/version.hpp" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace ndn::dissect { 31 | 32 | namespace po = boost::program_options; 33 | 34 | static void 35 | usage(std::ostream& os, std::string_view programName, const po::options_description& options) 36 | { 37 | os << "Usage: " << programName << " [options] [input-file]\n" 38 | << "\n" 39 | << options; 40 | } 41 | 42 | static int 43 | main(int argc, char* argv[]) 44 | { 45 | Options options; 46 | std::string inputFileName; 47 | 48 | po::options_description visibleOptions("Options"); 49 | visibleOptions.add_options() 50 | ("help,h", "print this help message and exit") 51 | ("content,c", po::bool_switch(&options.dissectContent), "dissect the value of Content elements") 52 | ("version,V", "print program version and exit") 53 | ; 54 | 55 | po::options_description hiddenOptions; 56 | hiddenOptions.add_options() 57 | ("input-file", po::value(&inputFileName)); 58 | 59 | po::options_description allOptions; 60 | allOptions.add(visibleOptions).add(hiddenOptions); 61 | 62 | po::positional_options_description pos; 63 | pos.add("input-file", -1); 64 | 65 | po::variables_map vm; 66 | try { 67 | po::store(po::command_line_parser(argc, argv).options(allOptions).positional(pos).run(), vm); 68 | po::notify(vm); 69 | } 70 | catch (const po::error& e) { 71 | std::cerr << "ERROR: " << e.what() << "\n"; 72 | return 2; 73 | } 74 | 75 | if (vm.count("help") > 0) { 76 | usage(std::cout, argv[0], visibleOptions); 77 | return 0; 78 | } 79 | 80 | if (vm.count("version") > 0) { 81 | std::cout << "ndndissect " << tools::VERSION << "\n"; 82 | return 0; 83 | } 84 | 85 | std::ifstream inputFile; 86 | std::istream* inputStream = &std::cin; 87 | if (vm.count("input-file") > 0 && inputFileName != "-") { 88 | inputFile.open(inputFileName); 89 | if (!inputFile) { 90 | std::cerr << argv[0] << ": " << inputFileName << ": File does not exist or is unreadable\n"; 91 | return 3; 92 | } 93 | inputStream = &inputFile; 94 | } 95 | 96 | Dissector d(*inputStream, std::cout, options); 97 | d.dissect(); 98 | 99 | return 0; 100 | } 101 | 102 | } // namespace ndn::dissect 103 | 104 | int 105 | main(int argc, char* argv[]) 106 | { 107 | return ndn::dissect::main(argc, argv); 108 | } 109 | -------------------------------------------------------------------------------- /tools/peek/ndnpoke/ndnpoke.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | * 25 | * @author Jerald Paul Abraham 26 | * @author Davide Pesavento 27 | */ 28 | 29 | #ifndef NDN_TOOLS_NDNPOKE_NDNPOKE_HPP 30 | #define NDN_TOOLS_NDNPOKE_NDNPOKE_HPP 31 | 32 | #include "core/common.hpp" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | namespace ndn::peek { 41 | 42 | /** 43 | * \brief options for NdnPoke 44 | */ 45 | struct PokeOptions 46 | { 47 | // Data construction options 48 | Name name; 49 | time::milliseconds freshnessPeriod = DEFAULT_FRESHNESS_PERIOD; 50 | bool wantFinalBlockId = false; 51 | security::SigningInfo signingInfo; 52 | 53 | // program behavior options 54 | bool isVerbose = false; 55 | bool wantUnsolicited = false; 56 | std::optional timeout; 57 | }; 58 | 59 | class NdnPoke : noncopyable 60 | { 61 | public: 62 | NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options); 63 | 64 | enum class Result { 65 | DATA_SENT = 0, 66 | UNKNOWN = 1, 67 | // 2 is reserved for "malformed command line" 68 | TIMEOUT = 3, 69 | // 4 is reserved for "nack" 70 | PREFIX_REG_FAIL = 5, 71 | }; 72 | 73 | /** 74 | * @return the result of NdnPoke execution 75 | */ 76 | Result 77 | getResult() const 78 | { 79 | return m_result; 80 | } 81 | 82 | void 83 | start(); 84 | 85 | private: 86 | std::shared_ptr 87 | createData() const; 88 | 89 | void 90 | sendData(const Data& data); 91 | 92 | void 93 | onInterest(const Interest& interest, const Data& data); 94 | 95 | void 96 | onRegSuccess(); 97 | 98 | void 99 | onRegFailure(std::string_view reason); 100 | 101 | private: 102 | const PokeOptions m_options; 103 | Face& m_face; 104 | KeyChain& m_keyChain; 105 | std::istream& m_input; 106 | Scheduler m_scheduler; 107 | ScopedRegisteredPrefixHandle m_registeredPrefix; 108 | scheduler::ScopedEventId m_timeoutEvent; 109 | Result m_result = Result::UNKNOWN; 110 | }; 111 | 112 | } // namespace ndn::peek 113 | 114 | #endif // NDN_TOOLS_NDNPOKE_NDNPOKE_HPP 115 | -------------------------------------------------------------------------------- /tools/get/discover-version.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Wentao Shang 24 | * @author Steve DiBenedetto 25 | * @author Andrea Tosatto 26 | * @author Chavoosh Ghasemi 27 | */ 28 | 29 | #include "discover-version.hpp" 30 | #include "data-fetcher.hpp" 31 | 32 | #include 33 | 34 | #include 35 | 36 | namespace ndn::get { 37 | 38 | DiscoverVersion::DiscoverVersion(Face& face, const Name& prefix, const Options& options) 39 | : m_face(face) 40 | , m_prefix(prefix) 41 | , m_options(options) 42 | { 43 | } 44 | 45 | void 46 | DiscoverVersion::run() 47 | { 48 | if (m_options.disableVersionDiscovery || (!m_prefix.empty() && m_prefix[-1].isVersion())) { 49 | onDiscoverySuccess(m_prefix); 50 | return; 51 | } 52 | 53 | Interest interest = MetadataObject::makeDiscoveryInterest(m_prefix) 54 | .setInterestLifetime(m_options.interestLifetime); 55 | 56 | m_fetcher = DataFetcher::fetch(m_face, interest, 57 | m_options.maxRetriesOnTimeoutOrNack, 58 | m_options.maxRetriesOnTimeoutOrNack, 59 | FORWARD_TO_MEM_FN(handleData), 60 | [this] (const auto&, const auto& reason) { 61 | onDiscoveryFailure(reason); 62 | }, 63 | [this] (const auto&, const auto& reason) { 64 | onDiscoveryFailure(reason); 65 | }, 66 | m_options.isVerbose); 67 | } 68 | 69 | void 70 | DiscoverVersion::handleData(const Interest& interest, const Data& data) 71 | { 72 | if (m_options.isVerbose) 73 | std::cerr << "Data: " << data << "\n"; 74 | 75 | // make a metadata object from received metadata packet 76 | MetadataObject mobject; 77 | try { 78 | mobject = MetadataObject(data); 79 | } 80 | catch (const tlv::Error& e) { 81 | onDiscoveryFailure("Invalid metadata packet: "s + e.what()); 82 | return; 83 | } 84 | 85 | if (mobject.getVersionedName().empty() || !mobject.getVersionedName()[-1].isVersion()) { 86 | onDiscoveryFailure(mobject.getVersionedName().toUri() + " is not a valid versioned name"); 87 | return; 88 | } 89 | 90 | if (m_options.isVerbose) { 91 | std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << "\n"; 92 | } 93 | 94 | onDiscoverySuccess(mobject.getVersionedName()); 95 | } 96 | 97 | } // namespace ndn::get 98 | -------------------------------------------------------------------------------- /tools/dump/ndndump.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2011-2024, Regents of the University of California. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | */ 19 | 20 | #ifndef NDN_TOOLS_DUMP_NDNDUMP_HPP 21 | #define NDN_TOOLS_DUMP_NDNDUMP_HPP 22 | 23 | #include "core/common.hpp" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #ifdef HAVE_BSD_TCPHDR 31 | #define TH_OFF th_off 32 | #else 33 | #define TH_OFF doff 34 | #endif 35 | 36 | #ifdef HAVE_BSD_UDPHDR 37 | #define UH_LEN uh_ulen 38 | #else 39 | #define UH_LEN len 40 | #endif 41 | 42 | namespace ndn::dump { 43 | 44 | class OutputFormatter; 45 | 46 | class NdnDump : noncopyable 47 | { 48 | public: 49 | class Error : public std::runtime_error 50 | { 51 | public: 52 | using std::runtime_error::runtime_error; 53 | }; 54 | 55 | ~NdnDump(); 56 | 57 | void 58 | run(); 59 | 60 | void 61 | printPacket(const pcap_pkthdr* pkthdr, const uint8_t* payload) const; 62 | 63 | static constexpr std::string_view 64 | getDefaultPcapFilter() noexcept 65 | { 66 | return "(ether proto 0x8624) or (tcp port 6363) or (udp port 6363) or (udp port 56363)"; 67 | } 68 | 69 | private: 70 | static void 71 | printTimestamp(std::ostream& os, const timeval& tv); 72 | 73 | bool 74 | dispatchByEtherType(OutputFormatter& out, const uint8_t* pkt, size_t len, uint16_t etherType) const; 75 | 76 | bool 77 | dispatchByIpProto(OutputFormatter& out, const uint8_t* pkt, size_t len, uint8_t ipProto) const; 78 | 79 | bool 80 | printEther(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 81 | 82 | bool 83 | printLinuxSll(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 84 | 85 | bool 86 | printPpp(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 87 | 88 | bool 89 | printIp4(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 90 | 91 | bool 92 | printIp6(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 93 | 94 | bool 95 | printTcp(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 96 | 97 | bool 98 | printUdp(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 99 | 100 | bool 101 | printNdn(OutputFormatter& out, const uint8_t* pkt, size_t len) const; 102 | 103 | [[nodiscard]] bool 104 | matchesFilter(const Name& name) const; 105 | 106 | public: // options 107 | std::string interface; 108 | std::string inputFile; 109 | std::string pcapFilter{getDefaultPcapFilter()}; 110 | std::optional nameFilter; 111 | bool wantPromisc = true; 112 | bool wantTimestamp = true; 113 | bool wantVerbose = false; 114 | 115 | private: 116 | pcap_t* m_pcap = nullptr; 117 | 118 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: 119 | int m_dataLinkType = -1; 120 | }; 121 | 122 | } // namespace ndn::dump 123 | 124 | #endif // NDN_TOOLS_DUMP_NDNDUMP_HPP 125 | -------------------------------------------------------------------------------- /tools/ping/client/ping.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author: Jerald Paul Abraham 20 | * @author: Eric Newberry 21 | * @author: Teng Liang 22 | */ 23 | 24 | #include "ping.hpp" 25 | 26 | #include 27 | 28 | namespace ndn::ping::client { 29 | 30 | Ping::Ping(Face& face, const Options& options) 31 | : m_options(options) 32 | , m_nextSeq(options.startSeq) 33 | , m_face(face) 34 | , m_scheduler(m_face.getIoContext()) 35 | { 36 | if (m_options.shouldGenerateRandomSeq) { 37 | m_nextSeq = random::generateWord64(); 38 | } 39 | } 40 | 41 | void 42 | Ping::start() 43 | { 44 | performPing(); 45 | } 46 | 47 | void 48 | Ping::stop() 49 | { 50 | m_nextPingEvent.cancel(); 51 | } 52 | 53 | void 54 | Ping::performPing() 55 | { 56 | BOOST_ASSERT((m_options.nPings < 0) || (m_nSent < m_options.nPings)); 57 | 58 | Interest interest(makePingName(m_nextSeq)); 59 | interest.setMustBeFresh(!m_options.shouldAllowStaleData); 60 | interest.setInterestLifetime(m_options.timeout); 61 | 62 | auto now = time::steady_clock::now(); 63 | m_face.expressInterest(interest, 64 | [this, seq = m_nextSeq, now] (auto&&...) { onData(seq, now); }, 65 | [this, seq = m_nextSeq, now] (auto&&, const auto& nack) { onNack(seq, now, nack); }, 66 | [this, seq = m_nextSeq] (auto&&...) { onTimeout(seq); }); 67 | 68 | ++m_nSent; 69 | ++m_nextSeq; 70 | ++m_nOutstanding; 71 | 72 | if ((m_options.nPings < 0) || (m_nSent < m_options.nPings)) { 73 | m_nextPingEvent = m_scheduler.schedule(m_options.interval, [this] { performPing(); }); 74 | } 75 | else { 76 | finish(); 77 | } 78 | } 79 | 80 | void 81 | Ping::onData(uint64_t seq, const time::steady_clock::time_point& sendTime) 82 | { 83 | time::nanoseconds rtt = time::steady_clock::now() - sendTime; 84 | afterData(seq, rtt); 85 | finish(); 86 | } 87 | 88 | void 89 | Ping::onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack) 90 | { 91 | time::nanoseconds rtt = time::steady_clock::now() - sendTime; 92 | afterNack(seq, rtt, nack.getHeader()); 93 | finish(); 94 | } 95 | 96 | void 97 | Ping::onTimeout(uint64_t seq) 98 | { 99 | afterTimeout(seq); 100 | finish(); 101 | } 102 | 103 | void 104 | Ping::finish() 105 | { 106 | if (--m_nOutstanding >= 0) { 107 | return; 108 | } 109 | afterFinish(); 110 | } 111 | 112 | Name 113 | Ping::makePingName(uint64_t seq) const 114 | { 115 | Name name(m_options.prefix); 116 | name.append("ping"); 117 | if (!m_options.clientIdentifier.empty()) { 118 | name.append(m_options.clientIdentifier); 119 | } 120 | name.append(std::to_string(seq)); 121 | return name; 122 | } 123 | 124 | } // namespace ndn::ping::client 125 | -------------------------------------------------------------------------------- /tools/ping/server/ping-server.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Jerald Paul Abraham 21 | */ 22 | 23 | #ifndef NDN_TOOLS_PING_SERVER_PING_SERVER_HPP 24 | #define NDN_TOOLS_PING_SERVER_PING_SERVER_HPP 25 | 26 | #include "core/common.hpp" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace ndn::ping::server { 33 | 34 | /** 35 | * @brief Options for PingServer 36 | */ 37 | struct Options 38 | { 39 | Name prefix; //!< prefix to register 40 | time::milliseconds freshnessPeriod = 1_s; //!< data freshness period 41 | size_t nMaxPings = 0; //!< max number of pings to satisfy (0 == no limit) 42 | size_t payloadSize = 0; //!< response payload size (0 == no payload) 43 | bool wantTimestamp = false; //!< print timestamp when response sent 44 | bool wantQuiet = false; //!< suppress printing per-packet log message 45 | }; 46 | 47 | /** 48 | * @brief NDN modular ping server 49 | */ 50 | class PingServer : noncopyable 51 | { 52 | public: 53 | PingServer(Face& face, KeyChain& keyChain, const Options& options); 54 | 55 | /** 56 | * @brief Signals when Interest received 57 | * 58 | * @param name incoming interest name 59 | */ 60 | signal::Signal afterReceive; 61 | 62 | /** 63 | * @brief Signals when finished pinging 64 | */ 65 | signal::Signal afterFinish; 66 | 67 | /** @brief starts ping server 68 | * 69 | * If options.shouldLimitSatisfied is false, this method does not return unless there's an error. 70 | * Otherwise, this method returns when options.nMaxPings Interests are processed. 71 | */ 72 | void 73 | run(); 74 | 75 | /** 76 | * @brief starts the Interest filter 77 | * 78 | * @note This method is non-blocking and caller need to call face.processEvents() 79 | */ 80 | void 81 | start(); 82 | 83 | /** 84 | * @brief Unregister set interest filter 85 | */ 86 | void 87 | stop(); 88 | 89 | /** 90 | * @brief gets the number of pings received 91 | */ 92 | size_t 93 | getNPings() const; 94 | 95 | private: 96 | /** 97 | * @brief Called when interest received 98 | * 99 | * @param interest incoming interest 100 | */ 101 | void 102 | onInterest(const Interest& interest); 103 | 104 | private: 105 | const Options& m_options; 106 | Face& m_face; 107 | KeyChain& m_keyChain; 108 | size_t m_nPings = 0; 109 | Block m_payload; 110 | RegisteredPrefixHandle m_registeredPrefix; 111 | }; 112 | 113 | } // namespace ndn::ping::server 114 | 115 | #endif // NDN_TOOLS_PING_SERVER_PING_SERVER_HPP 116 | -------------------------------------------------------------------------------- /tools/ping/README.md: -------------------------------------------------------------------------------- 1 | # ndnping and ndnpingserver 2 | 3 | ## Introduction 4 | 5 | **ndnping** and **ndnpingserver** are reachability testing tools for NDN. They can be used 6 | to test the network reachability between two nodes. The client sends an Interest intended 7 | for a node running **ndnpingserver**. The server then sends Data in response. The client 8 | then calculates the roundtrip time for the Interest-Data exchange, or marks it as a timeout 9 | if the Data packet is not received within the timeout period. 10 | 11 | ## Using the client 12 | 13 | The client can be invoked by calling `ndnping` with a name to ping. For example, to ping 14 | `/edu/arizona`, one would run: 15 | 16 | ndnping /edu/arizona 17 | 18 | There are also a variety of options to control the behavior of the ping client. For example, 19 | to send only four pings to `/edu/arizona`, displaying a timestamp with each received Data or 20 | timeout, type: 21 | 22 | ndnping -c 4 -t /edu/arizona 23 | 24 | A list of the available options can be found with `man ndnping`. 25 | 26 | ## Using the server 27 | 28 | The server can be invoked by calling `ndnpingserver` with a name to listen for pings to. For 29 | example, to listen for pings to `/edu/arizona`, one would run: 30 | 31 | ndnpingserver /edu/arizona 32 | 33 | There are also a variety of options to control the behavior of the ping server. For example, 34 | to satisfy only 4 ping requests before exiting, run the following: 35 | 36 | ndnpingserver -p 4 /edu/arizona 37 | 38 | A list of the available options can be found with `man ndnpingserver`. 39 | 40 | ## NDN ping protocol 41 | 42 | This section briefly describes ndnping's protocol, in order to allow alternate implementations 43 | to be compatible with this implementation. 44 | 45 | The current protocol version is **ndnping protocol version 1**. 46 | This version number will be incremented whenever there is an incompatible change. 47 | 48 | ### Probe Interests 49 | 50 | The client expresses probe Interests that are intended to be forwarded to the server 51 | without being aggregated. 52 | The Interests MUST have one of the following name structures: 53 | 54 | ndn://ping/ 55 | ndn://ping// 56 | 57 | where: 58 | 59 | * `` is the server prefix that contains zero or more NameComponents. 60 | * `` is one NameComponent whose value is an unsigned 64-bit integer, represented as 61 | a decimal number in ASCII encoding. 62 | * `` is one NameComponent with arbitrary value. 63 | 64 | If a client expresses multiple probe Interests, it is RECOMMENDED for those Interests to 65 | have consecutive increasing integers in `` field. 66 | 67 | If a client uses the name structure with `` field, it is RECOMMENDED to use 68 | one or more printable characters only, to make it easier for a human operator to read the logs. 69 | A client implementation MAY restrict this field to be non-empty and have printable characters only. 70 | 71 | The probe Interest SHOULD NOT carry CanBePrefix element. 72 | 73 | The probe Interest SHOULD carry MustBeFresh element. 74 | A client implementation MAY allow the operator to remove MustBeFresh element. 75 | 76 | ### Reply Data 77 | 78 | The server SHOULD register the prefix `ndn://ping`, and MUST reply to probe Interests 79 | under this prefix with Data. 80 | The Data MUST have the same name as the probe Interest. 81 | 82 | The Data MUST have BLOB as its ContentType. 83 | The Data MAY have arbitrary payload in its Content field. 84 | A server implementation MAY allow the operator to configure the length and contents of the payload. 85 | 86 | The Data SHOULD have a valid signature. 87 | The server SHOULD use DigestSha256 signature by default. 88 | A server implementation MAY allow the operator to configure a different signature algorithm. 89 | The client SHOULD NOT verify the signature by default. 90 | A client implementation MAY allow the operator to enable signature verification. 91 | -------------------------------------------------------------------------------- /tools/ping/client/statistics-collector.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Jerald Paul Abraham 21 | * @author Teng Liang 22 | */ 23 | 24 | #ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP 25 | #define NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP 26 | 27 | #include "core/common.hpp" 28 | #include "ping.hpp" 29 | 30 | #include 31 | 32 | namespace ndn::ping::client { 33 | 34 | class Statistics 35 | { 36 | public: 37 | void 38 | printSummary(std::ostream& os) const; 39 | 40 | void 41 | printFull(std::ostream& os) const; 42 | 43 | public: 44 | Name prefix; //!< prefix pinged 45 | int nSent; //!< number of pings sent 46 | int nReceived; //!< number of pings received 47 | int nNacked; //!< number of nacks received 48 | time::steady_clock::time_point pingStartTime; //!< time pings started 49 | double minRtt; //!< minimum round trip time 50 | double maxRtt; //!< maximum round trip time 51 | double packetLossRate; //!< packet loss rate 52 | double packetNackedRate; //!< packet nacked rate 53 | double sumRtt; //!< sum of round trip times 54 | double avgRtt; //!< average round trip time 55 | double stdDevRtt; //!< std dev of round trip time 56 | }; 57 | 58 | /** 59 | * @brief Statistics collector from ping client. 60 | */ 61 | class StatisticsCollector : noncopyable 62 | { 63 | public: 64 | /** 65 | * @param ping NDN ping client 66 | * @param options ping client options 67 | */ 68 | StatisticsCollector(Ping& ping, const Options& options); 69 | 70 | /** 71 | * @brief Compute and return ping statistics as structure 72 | */ 73 | [[nodiscard]] Statistics 74 | computeStatistics() const; 75 | 76 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: 77 | /** 78 | * @brief Called when a Data packet is received 79 | */ 80 | void 81 | recordData(Rtt rtt); 82 | 83 | /** 84 | * @brief Called when a Nack is received 85 | */ 86 | void 87 | recordNack(); 88 | 89 | /** 90 | * @brief Called on ping timeout 91 | */ 92 | void 93 | recordTimeout(); 94 | 95 | private: 96 | Ping& m_ping; 97 | const Options& m_options; 98 | time::steady_clock::time_point m_pingStartTime = time::steady_clock::now(); 99 | int m_nSent = 0; 100 | int m_nReceived = 0; 101 | int m_nNacked = 0; 102 | double m_minRtt = std::numeric_limits::max(); 103 | double m_maxRtt = 0.0; 104 | double m_sumRtt = 0.0; 105 | double m_sumRttSquared = 0.0; 106 | }; 107 | 108 | } // namespace ndn::ping::client 109 | 110 | #endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP 111 | -------------------------------------------------------------------------------- /tools/peek/ndnpeek/ndnpeek.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | * 25 | * @author Jerald Paul Abraham 26 | * @author Zhuo Li 27 | * @author Davide Pesavento 28 | */ 29 | 30 | #ifndef NDN_TOOLS_NDNPEEK_NDNPEEK_HPP 31 | #define NDN_TOOLS_NDNPEEK_NDNPEEK_HPP 32 | 33 | #include "core/common.hpp" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | namespace ndn::peek { 43 | 44 | /** 45 | * @brief options for NdnPeek 46 | */ 47 | struct PeekOptions 48 | { 49 | // Interest construction options 50 | Name name; 51 | bool canBePrefix = false; 52 | bool mustBeFresh = false; 53 | std::vector forwardingHint; 54 | time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME; 55 | std::optional hopLimit; 56 | std::shared_ptr applicationParameters; 57 | 58 | // program behavior options 59 | bool isVerbose = false; 60 | bool wantPayloadOnly = false; 61 | std::optional timeout; 62 | }; 63 | 64 | class NdnPeek : noncopyable 65 | { 66 | public: 67 | NdnPeek(Face& face, const PeekOptions& options); 68 | 69 | enum class Result { 70 | DATA = 0, 71 | UNKNOWN = 1, 72 | // 2 is reserved for "malformed command line" 73 | TIMEOUT = 3, 74 | NACK = 4, 75 | }; 76 | 77 | /** 78 | * @return the result of NdnPeek execution 79 | */ 80 | Result 81 | getResult() const 82 | { 83 | return m_result; 84 | } 85 | 86 | /** 87 | * @brief express the Interest 88 | * @note The caller must invoke face.processEvents() afterwards 89 | */ 90 | void 91 | start(); 92 | 93 | private: 94 | Interest 95 | createInterest() const; 96 | 97 | /** 98 | * @brief called when a Data packet is received 99 | */ 100 | void 101 | onData(const Data& data); 102 | 103 | /** 104 | * @brief called when a Nack packet is received 105 | */ 106 | void 107 | onNack(const lp::Nack& nack); 108 | 109 | /** 110 | * @brief called when the Interest times out 111 | */ 112 | void 113 | onTimeout(); 114 | 115 | private: 116 | const PeekOptions m_options; 117 | Face& m_face; 118 | Scheduler m_scheduler; 119 | time::steady_clock::time_point m_sendTime; 120 | ScopedPendingInterestHandle m_pendingInterest; 121 | scheduler::ScopedEventId m_timeoutEvent; 122 | Result m_result = Result::UNKNOWN; 123 | }; 124 | 125 | } // namespace ndn::peek 126 | 127 | #endif // NDN_TOOLS_NDNPEEK_NDNPEEK_HPP 128 | -------------------------------------------------------------------------------- /tools/peek/ndnpoke/ndnpoke.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | * 25 | * @author Jerald Paul Abraham 26 | * @author Davide Pesavento 27 | */ 28 | 29 | #include "ndnpoke.hpp" 30 | 31 | #include 32 | 33 | #include 34 | 35 | namespace ndn::peek { 36 | 37 | NdnPoke::NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options) 38 | : m_options(options) 39 | , m_face(face) 40 | , m_keyChain(keyChain) 41 | , m_input(input) 42 | , m_scheduler(m_face.getIoContext()) 43 | { 44 | } 45 | 46 | void 47 | NdnPoke::start() 48 | { 49 | auto data = createData(); 50 | 51 | if (m_options.wantUnsolicited) { 52 | return sendData(*data); 53 | } 54 | 55 | m_registeredPrefix = m_face.setInterestFilter(m_options.name, 56 | [this, data] (auto&&, const auto& interest) { this->onInterest(interest, *data); }, 57 | [this] (auto&&) { this->onRegSuccess(); }, 58 | [this] (auto&&, const auto& reason) { this->onRegFailure(reason); }); 59 | } 60 | 61 | std::shared_ptr 62 | NdnPoke::createData() const 63 | { 64 | auto data = std::make_shared(m_options.name); 65 | data->setFreshnessPeriod(m_options.freshnessPeriod); 66 | if (m_options.wantFinalBlockId) { 67 | data->setFinalBlock(m_options.name.at(-1)); 68 | } 69 | 70 | OBufferStream os; 71 | os << m_input.rdbuf(); 72 | data->setContent(os.buf()); 73 | 74 | m_keyChain.sign(*data, m_options.signingInfo); 75 | 76 | return data; 77 | } 78 | 79 | void 80 | NdnPoke::sendData(const Data& data) 81 | { 82 | m_face.put(data); 83 | m_result = Result::DATA_SENT; 84 | 85 | if (m_options.isVerbose) { 86 | std::cerr << "DATA: " << data; 87 | } 88 | } 89 | 90 | void 91 | NdnPoke::onInterest(const Interest& interest, const Data& data) 92 | { 93 | if (m_options.isVerbose) { 94 | std::cerr << "INTEREST: " << interest << std::endl; 95 | } 96 | 97 | if (interest.matchesData(data)) { 98 | m_timeoutEvent.cancel(); 99 | m_registeredPrefix.cancel(); 100 | sendData(data); 101 | } 102 | else if (m_options.isVerbose) { 103 | std::cerr << "Interest cannot be satisfied" << std::endl; 104 | } 105 | } 106 | 107 | void 108 | NdnPoke::onRegSuccess() 109 | { 110 | if (m_options.isVerbose) { 111 | std::cerr << "Prefix registration successful" << std::endl; 112 | } 113 | 114 | if (m_options.timeout) { 115 | m_timeoutEvent = m_scheduler.schedule(*m_options.timeout, [this] { 116 | m_result = Result::TIMEOUT; 117 | m_registeredPrefix.cancel(); 118 | 119 | if (m_options.isVerbose) { 120 | std::cerr << "TIMEOUT" << std::endl; 121 | } 122 | }); 123 | } 124 | } 125 | 126 | void 127 | NdnPoke::onRegFailure(std::string_view reason) 128 | { 129 | m_result = Result::PREFIX_REG_FAIL; 130 | std::cerr << "Prefix registration failure (" << reason << ")" << std::endl; 131 | } 132 | 133 | } // namespace ndn::peek 134 | -------------------------------------------------------------------------------- /README-dev.md: -------------------------------------------------------------------------------- 1 | # Notes for ndn-tools developers 2 | 3 | ## Licensing Requirements 4 | 5 | Contributions to ndn-tools must be licensed under the GPL v3 or a compatible license. 6 | If you choose the GPL v3, please use the following license boilerplate in all `.hpp` 7 | and `.cpp` files: 8 | 9 | ```cpp 10 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 11 | /* 12 | * Copyright (c) [Year(s)], [Copyright Holder(s)]. 13 | * 14 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 15 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 16 | * 17 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 18 | * of the GNU General Public License as published by the Free Software Foundation, 19 | * either version 3 of the License, or (at your option) any later version. 20 | * 21 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 22 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 23 | * PURPOSE. See the GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License along with 26 | * ndn-tools, e.g., in COPYING.md file. If not, see . 27 | */ 28 | ``` 29 | 30 | ## Directory Structure and Build Script 31 | 32 | All tools are placed in subdirectories of the [`tools`](tools) directory. 33 | 34 | A tool can consist of one or more programs. 35 | For instance, a pair of consumer and producer programs that are designed to work together 36 | should be considered a single tool, not two separate tools. 37 | 38 | Each tool must have a `wscript` build script in its subdirectory. This script will be 39 | invoked automatically if the corresponding tool is selected for the build. It should 40 | compile the source code and produce one or more binaries in the `build/bin` directory 41 | (e.g., use `target='../../bin/foo'`). 42 | 43 | ### Shared Modules 44 | 45 | Modules shared among multiple tools should be placed in the [`core`](core) directory. 46 | They are available for use in all tools. 47 | 48 | A header in `core/` can be included in a tool like `#include "core/foo.hpp"`. 49 | 50 | The `wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`. 51 | 52 | ### Documentation 53 | 54 | A file named `README.md` in the subdirectory of each tool should provide a brief 55 | description. 56 | 57 | Manual pages for each program should be written in reStructuredText format 58 | and placed in the [`manpages`](manpages) directory. 59 | 60 | ## Code Guidelines 61 | 62 | C++ code should conform to the 63 | [ndn-cxx code style](https://docs.named-data.net/ndn-cxx/current/code-style.html). 64 | 65 | ### Namespace 66 | 67 | Types in each tool should be declared in a sub-namespace inside `namespace ndn`. 68 | For example, a tool in `tools/foo` directory has namespace `ndn::foo`. 69 | This allows the tool to reference ndn-cxx types with unqualified name lookup. 70 | This also prevents name conflicts between ndn-cxx and tools. 71 | 72 | Types in `core/` should be declared directly inside `namespace ndn`, 73 | or in a sub-namespace if desired. 74 | 75 | ### main Function 76 | 77 | The `main` function of a program should be declared as a static function in 78 | the namespace of the corresponding tool. This allows referencing types in 79 | ndn-cxx and the tool via unqualified name lookup. 80 | 81 | Then, another (non-static) `main` function must be defined in the global 82 | namespace, and from there call the `main` function in the tool namespace. 83 | 84 | These two functions should appear in a file named `main.cpp` in the tool's 85 | subdirectory. 86 | 87 | Example: 88 | 89 | ```cpp 90 | namespace ndn { 91 | namespace foo { 92 | 93 | class Bar 94 | { 95 | public: 96 | explicit 97 | Bar(Face& face); 98 | 99 | void 100 | run(); 101 | }; 102 | 103 | static int 104 | main(int argc, char* argv[]) 105 | { 106 | Face face; 107 | Bar program(face); 108 | program.run(); 109 | return 0; 110 | } 111 | 112 | } // namespace foo 113 | } // namespace ndn 114 | 115 | int 116 | main(int argc, char* argv[]) 117 | { 118 | return ndn::foo::main(argc, argv); 119 | } 120 | ``` 121 | 122 | ### Command Line Arguments 123 | 124 | [Boost.Program\_options](https://www.boost.org/doc/libs/1_74_0/doc/html/program_options.html) 125 | is strongly preferred over `getopt(3)` for parsing command line arguments. 126 | -------------------------------------------------------------------------------- /tools/get/pipeline-interests-cubic.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Klaus Schneider 24 | */ 25 | 26 | #include "pipeline-interests-cubic.hpp" 27 | 28 | #include 29 | #include 30 | 31 | namespace ndn::get { 32 | 33 | constexpr double CUBIC_C = 0.4; 34 | 35 | PipelineInterestsCubic::PipelineInterestsCubic(Face& face, RttEstimatorWithStats& rttEstimator, 36 | const Options& opts) 37 | : PipelineInterestsAdaptive(face, rttEstimator, opts) 38 | , m_lastDecrease(time::steady_clock::now()) 39 | { 40 | if (m_options.isVerbose) { 41 | printOptions(); 42 | std::cerr << "\tCubic beta = " << m_options.cubicBeta << "\n" 43 | << "\tFast convergence = " << (m_options.enableFastConv ? "yes" : "no") << "\n"; 44 | } 45 | } 46 | 47 | void 48 | PipelineInterestsCubic::increaseWindow() 49 | { 50 | // Slow start phase 51 | if (m_cwnd < m_ssthresh) { 52 | m_cwnd += 1.0; 53 | } 54 | // Congestion avoidance phase 55 | else { 56 | // If wmax is still 0, set it to the current cwnd. Usually unnecessary, 57 | // if m_ssthresh is large enough. 58 | if (m_wmax < m_options.initCwnd) { 59 | m_wmax = m_cwnd; 60 | } 61 | 62 | // 1. Time since last congestion event in seconds 63 | const double t = (time::steady_clock::now() - m_lastDecrease).count() / 1e9; 64 | 65 | // 2. Time it takes to increase the window to m_wmax = the cwnd right before the last 66 | // window decrease. 67 | // K = cubic_root(wmax*(1-beta_cubic)/C) (Eq. 2) 68 | const double k = std::cbrt(m_wmax * (1 - m_options.cubicBeta) / CUBIC_C); 69 | 70 | // 3. Target: W_cubic(t) = C*(t-K)^3 + wmax (Eq. 1) 71 | const double wCubic = CUBIC_C * std::pow(t - k, 3) + m_wmax; 72 | 73 | // 4. Estimate of Reno Increase (Eq. 4) 74 | const double rtt = m_rttEstimator.getSmoothedRtt().count() / 1e9; 75 | const double wEst = m_wmax * m_options.cubicBeta + 76 | (3 * (1 - m_options.cubicBeta) / (1 + m_options.cubicBeta)) * (t / rtt); 77 | 78 | // Actual adaptation 79 | double cubicIncrement = std::max(wCubic, wEst) - m_cwnd; 80 | // Cubic increment must be positive 81 | // Note: This change is not part of the RFC, but I added it to improve performance. 82 | cubicIncrement = std::max(0.0, cubicIncrement); 83 | 84 | m_cwnd += cubicIncrement / m_cwnd; 85 | } 86 | 87 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); 88 | } 89 | 90 | void 91 | PipelineInterestsCubic::decreaseWindow() 92 | { 93 | // A flow remembers the last value of wmax, 94 | // before it updates wmax for the current congestion event. 95 | 96 | // Current wmax < last_wmax 97 | if (m_options.enableFastConv && m_cwnd < m_lastWmax) { 98 | m_lastWmax = m_cwnd; 99 | m_wmax = m_cwnd * (1.0 + m_options.cubicBeta) / 2.0; 100 | } 101 | else { 102 | // Save old cwnd as wmax 103 | m_lastWmax = m_cwnd; 104 | m_wmax = m_cwnd; 105 | } 106 | 107 | m_ssthresh = std::max(m_options.initCwnd, m_cwnd * m_options.cubicBeta); 108 | m_cwnd = m_ssthresh; 109 | m_lastDecrease = time::steady_clock::now(); 110 | 111 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); 112 | } 113 | 114 | } // namespace ndn::get 115 | -------------------------------------------------------------------------------- /tools/ping/client/statistics-collector.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author Eric Newberry 20 | * @author Jerald Paul Abraham 21 | * @author Teng Liang 22 | */ 23 | 24 | #include "statistics-collector.hpp" 25 | 26 | #include 27 | 28 | namespace ndn::ping::client { 29 | 30 | StatisticsCollector::StatisticsCollector(Ping& ping, const Options& options) 31 | : m_ping(ping) 32 | , m_options(options) 33 | { 34 | m_ping.afterData.connect([this] (auto&&, Rtt rtt) { recordData(rtt); }); 35 | m_ping.afterNack.connect([this] (auto&&...) { recordNack(); }); 36 | m_ping.afterTimeout.connect([this] (auto&&...) { recordTimeout(); }); 37 | } 38 | 39 | void 40 | StatisticsCollector::recordData(Rtt rtt) 41 | { 42 | m_nSent++; 43 | m_nReceived++; 44 | 45 | double rttMs = rtt.count(); 46 | 47 | m_minRtt = std::min(m_minRtt, rttMs); 48 | m_maxRtt = std::max(m_maxRtt, rttMs); 49 | 50 | m_sumRtt += rttMs; 51 | m_sumRttSquared += rttMs * rttMs; 52 | } 53 | 54 | void 55 | StatisticsCollector::recordNack() 56 | { 57 | m_nSent++; 58 | m_nNacked++; 59 | } 60 | 61 | void 62 | StatisticsCollector::recordTimeout() 63 | { 64 | m_nSent++; 65 | } 66 | 67 | Statistics 68 | StatisticsCollector::computeStatistics() const 69 | { 70 | Statistics statistics; 71 | 72 | statistics.prefix = m_options.prefix; 73 | statistics.nSent = m_nSent; 74 | statistics.nReceived = m_nReceived; 75 | statistics.nNacked = m_nNacked; 76 | statistics.pingStartTime = m_pingStartTime; 77 | statistics.minRtt = m_minRtt; 78 | statistics.maxRtt = m_maxRtt; 79 | 80 | if (m_nSent > 0) { 81 | statistics.packetLossRate = static_cast(m_nSent - m_nReceived - m_nNacked) / static_cast(m_nSent); 82 | statistics.packetNackedRate = static_cast(m_nNacked) / static_cast(m_nSent); 83 | } 84 | else { 85 | statistics.packetLossRate = std::numeric_limits::quiet_NaN(); 86 | statistics.packetNackedRate = std::numeric_limits::quiet_NaN(); 87 | } 88 | 89 | statistics.sumRtt = m_sumRtt; 90 | 91 | if (m_nReceived > 0) { 92 | statistics.avgRtt = m_sumRtt / m_nReceived; 93 | statistics.stdDevRtt = std::sqrt((m_sumRttSquared / m_nReceived) - (statistics.avgRtt * statistics.avgRtt)); 94 | } 95 | else { 96 | statistics.avgRtt = std::numeric_limits::quiet_NaN(); 97 | statistics.stdDevRtt = std::numeric_limits::quiet_NaN(); 98 | } 99 | 100 | return statistics; 101 | } 102 | 103 | void 104 | Statistics::printSummary(std::ostream& os) const 105 | { 106 | os << nReceived << "/" << nSent << " packets"; 107 | 108 | if (nSent > 0) { 109 | os << ", " << packetLossRate * 100.0 << "% lost, " << packetNackedRate * 100.0 << "% nacked"; 110 | } 111 | 112 | if (nReceived > 0) { 113 | os << ", min/avg/max/mdev = " << minRtt << "/" << avgRtt << "/" << maxRtt 114 | << "/" << stdDevRtt << " ms"; 115 | } 116 | 117 | os << "\n"; 118 | } 119 | 120 | void 121 | Statistics::printFull(std::ostream& os) const 122 | { 123 | os << "\n--- " << prefix << " ping statistics ---\n" 124 | << nSent << " packets transmitted" 125 | << ", " << nReceived << " received" 126 | << ", " << nNacked << " nacked"; 127 | 128 | if (nSent > 0) { 129 | os << ", " << packetLossRate * 100.0 << "% lost, " << packetNackedRate * 100.0 << "% nacked"; 130 | } 131 | 132 | os << ", time " << sumRtt << " ms"; 133 | 134 | if (nReceived > 0) { 135 | os << "\nrtt min/avg/max/mdev = " << minRtt << "/" << avgRtt << "/" << maxRtt 136 | << "/" << stdDevRtt << " ms"; 137 | } 138 | 139 | os << "\n"; 140 | } 141 | 142 | } // namespace ndn::ping::client 143 | -------------------------------------------------------------------------------- /tools/peek/ndnpeek/ndnpeek.cpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2014-2024, Regents of the University of California, 4 | * Arizona Board of Regents, 5 | * Colorado State University, 6 | * University Pierre & Marie Curie, Sorbonne University, 7 | * Washington University in St. Louis, 8 | * Beijing Institute of Technology, 9 | * The University of Memphis. 10 | * 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 13 | * 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 15 | * of the GNU General Public License as published by the Free Software Foundation, 16 | * either version 3 of the License, or (at your option) any later version. 17 | * 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | * PURPOSE. See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * ndn-tools, e.g., in COPYING.md file. If not, see . 24 | * 25 | * @author Jerald Paul Abraham 26 | * @author Zhuo Li 27 | * @author Davide Pesavento 28 | */ 29 | 30 | #include "ndnpeek.hpp" 31 | 32 | #include 33 | 34 | namespace ndn::peek { 35 | 36 | NdnPeek::NdnPeek(Face& face, const PeekOptions& options) 37 | : m_options(options) 38 | , m_face(face) 39 | , m_scheduler(m_face.getIoContext()) 40 | { 41 | } 42 | 43 | void 44 | NdnPeek::start() 45 | { 46 | m_pendingInterest = m_face.expressInterest(createInterest(), 47 | [this] (auto&&, const auto& data) { this->onData(data); }, 48 | [this] (auto&&, const auto& nack) { this->onNack(nack); }, 49 | [this] (auto&&) { this->onTimeout(); }); 50 | 51 | if (m_options.timeout) { 52 | m_timeoutEvent = m_scheduler.schedule(*m_options.timeout, [this] { 53 | m_pendingInterest.cancel(); 54 | onTimeout(); 55 | }); 56 | } 57 | 58 | m_sendTime = time::steady_clock::now(); 59 | } 60 | 61 | Interest 62 | NdnPeek::createInterest() const 63 | { 64 | Interest interest(m_options.name); 65 | interest.setCanBePrefix(m_options.canBePrefix); 66 | interest.setMustBeFresh(m_options.mustBeFresh); 67 | interest.setForwardingHint(m_options.forwardingHint); 68 | interest.setInterestLifetime(m_options.interestLifetime); 69 | if (m_options.hopLimit) { 70 | interest.setHopLimit(*m_options.hopLimit); 71 | } 72 | if (m_options.applicationParameters) { 73 | interest.setApplicationParameters(m_options.applicationParameters); 74 | } 75 | 76 | if (m_options.isVerbose) { 77 | std::cerr << "INTEREST: " << interest << std::endl; 78 | } 79 | 80 | return interest; 81 | } 82 | 83 | static void 84 | writeToCout(span bytes) 85 | { 86 | std::cout.write(reinterpret_cast(bytes.data()), bytes.size()); 87 | } 88 | 89 | void 90 | NdnPeek::onData(const Data& data) 91 | { 92 | m_result = Result::DATA; 93 | m_timeoutEvent.cancel(); 94 | 95 | if (m_options.isVerbose) { 96 | std::cerr << "DATA: " << data.getName() << "\nRTT: " 97 | << time::duration_cast(time::steady_clock::now() - m_sendTime).count() 98 | << " ms" << std::endl; 99 | } 100 | 101 | if (m_options.wantPayloadOnly) { 102 | writeToCout(data.getContent().value_bytes()); 103 | } 104 | else { 105 | writeToCout(data.wireEncode()); 106 | } 107 | } 108 | 109 | void 110 | NdnPeek::onNack(const lp::Nack& nack) 111 | { 112 | m_result = Result::NACK; 113 | m_timeoutEvent.cancel(); 114 | 115 | const auto& header = nack.getHeader(); 116 | if (m_options.isVerbose) { 117 | std::cerr << "NACK: " << header.getReason() << "\nRTT: " 118 | << time::duration_cast(time::steady_clock::now() - m_sendTime).count() 119 | << " ms" << std::endl; 120 | } 121 | 122 | if (m_options.wantPayloadOnly) { 123 | std::cout << header.getReason() << std::endl; 124 | } 125 | else { 126 | writeToCout(header.wireEncode()); 127 | } 128 | } 129 | 130 | void 131 | NdnPeek::onTimeout() 132 | { 133 | m_result = Result::TIMEOUT; 134 | m_timeoutEvent.cancel(); 135 | 136 | if (m_options.isVerbose) { 137 | std::cerr << "TIMEOUT" << std::endl; 138 | } 139 | } 140 | 141 | } // namespace ndn::peek 142 | -------------------------------------------------------------------------------- /tools/ping/client/ping.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. 4 | * 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 7 | * 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 9 | * of the GNU General Public License as published by the Free Software Foundation, 10 | * either version 3 of the License, or (at your option) any later version. 11 | * 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | * PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * ndn-tools, e.g., in COPYING.md file. If not, see . 18 | * 19 | * @author: Jerald Paul Abraham 20 | * @author: Eric Newberry 21 | * @author: Teng Liang 22 | */ 23 | 24 | #ifndef NDN_TOOLS_PING_CLIENT_PING_HPP 25 | #define NDN_TOOLS_PING_CLIENT_PING_HPP 26 | 27 | #include "core/common.hpp" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace ndn::ping::client { 34 | 35 | using Rtt = time::duration; 36 | 37 | /** 38 | * @brief %Options for ndnping client. 39 | */ 40 | struct Options 41 | { 42 | Name prefix; //!< prefix pinged 43 | bool shouldAllowStaleData; //!< allow stale Data 44 | bool shouldGenerateRandomSeq; //!< random ping sequence 45 | bool shouldPrintTimestamp; //!< print timestamp 46 | int nPings; //!< number of pings 47 | time::milliseconds interval; //!< ping interval 48 | time::milliseconds timeout; //!< timeout threshold 49 | uint64_t startSeq; //!< start ping sequence number 50 | name::Component clientIdentifier; //!< client identifier 51 | }; 52 | 53 | /** 54 | * @brief NDN modular ping client 55 | */ 56 | class Ping : noncopyable 57 | { 58 | public: 59 | Ping(Face& face, const Options& options); 60 | 61 | /** 62 | * @brief Signals on the successful return of a Data packet 63 | * 64 | * @param seq ping sequence number 65 | * @param rtt round trip time 66 | */ 67 | signal::Signal afterData; 68 | 69 | /** 70 | * @brief Signals on the return of a Nack 71 | * 72 | * @param seq ping sequence number 73 | * @param rtt round trip time 74 | * @param header the received Network NACK header 75 | */ 76 | signal::Signal afterNack; 77 | 78 | /** 79 | * @brief Signals on timeout of a packet 80 | * 81 | * @param seq ping sequence number 82 | */ 83 | signal::Signal afterTimeout; 84 | 85 | /** 86 | * @brief Signals when finished pinging 87 | */ 88 | signal::Signal afterFinish; 89 | 90 | /** 91 | * @brief Start sending ping interests 92 | * 93 | * @note This method is non-blocking and caller need to call face.processEvents() 94 | */ 95 | void 96 | start(); 97 | 98 | /** 99 | * @brief Stop sending ping interests 100 | * 101 | * This method cancels any future ping interests and does not affect already pending interests. 102 | * 103 | * @todo Cancel pending ping interest 104 | */ 105 | void 106 | stop(); 107 | 108 | private: 109 | /** 110 | * @brief Creates a ping Name from the sequence number 111 | */ 112 | Name 113 | makePingName(uint64_t seq) const; 114 | 115 | /** 116 | * @brief Performs individual ping 117 | */ 118 | void 119 | performPing(); 120 | 121 | /** 122 | * @brief Called when a Data packet is received in response to a ping 123 | */ 124 | void 125 | onData(uint64_t seq, const time::steady_clock::time_point& sendTime); 126 | 127 | /** 128 | * @brief Called when a Nack is received in response to a ping 129 | */ 130 | void 131 | onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack); 132 | 133 | /** 134 | * @brief Called when ping timed out 135 | */ 136 | void 137 | onTimeout(uint64_t seq); 138 | 139 | /** 140 | * @brief Called after ping received or timed out 141 | */ 142 | void 143 | finish(); 144 | 145 | private: 146 | const Options& m_options; 147 | int m_nSent = 0; 148 | uint64_t m_nextSeq; 149 | int m_nOutstanding = 0; 150 | Face& m_face; 151 | Scheduler m_scheduler; 152 | scheduler::ScopedEventId m_nextPingEvent; 153 | }; 154 | 155 | } // namespace ndn::ping::client 156 | 157 | #endif // NDN_TOOLS_PING_CLIENT_PING_HPP 158 | -------------------------------------------------------------------------------- /tools/get/data-fetcher.hpp: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | /* 3 | * Copyright (c) 2016-2025, Regents of the University of California, 4 | * Colorado State University, 5 | * University Pierre & Marie Curie, Sorbonne University. 6 | * 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. 9 | * 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms 11 | * of the GNU General Public License as published by the Free Software Foundation, 12 | * either version 3 of the License, or (at your option) any later version. 13 | * 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 | * PURPOSE. See the GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * ndn-tools, e.g., in COPYING.md file. If not, see . 20 | * 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. 22 | * 23 | * @author Andrea Tosatto 24 | * @author Davide Pesavento 25 | */ 26 | 27 | #ifndef NDN_TOOLS_GET_DATA_FETCHER_HPP 28 | #define NDN_TOOLS_GET_DATA_FETCHER_HPP 29 | 30 | #include "core/common.hpp" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | namespace ndn::get { 38 | 39 | /** 40 | * @brief Fetch data for a given interest and handle timeout or nack error with retries. 41 | * 42 | * To instantiate a DataFetcher you need to use the static method fetch, this will also express the 43 | * interest. After a timeout or nack is received, the same interest with a different nonce will be 44 | * requested for a maximum number of time specified by the class user. There are separate retry 45 | * counters for timeouts and nacks. 46 | * 47 | * A specified callback is called after the data matching the expressed interest is received. A 48 | * different callback is called in case one of the retries counter reach the maximum. This callback 49 | * can be different for timeout and nack. The data callback must be defined but the others callback 50 | * are optional. 51 | * 52 | */ 53 | class DataFetcher 54 | { 55 | public: 56 | /** 57 | * @brief means that there is no maximum number of retries, 58 | * i.e. fetching must be retried indefinitely 59 | */ 60 | static constexpr int MAX_RETRIES_INFINITE = -1; 61 | 62 | /** 63 | * @brief ceiling value for backoff time used in congestion handling 64 | */ 65 | static constexpr time::milliseconds MAX_CONGESTION_BACKOFF_TIME = 10_s; 66 | 67 | using FailureCallback = std::function; 68 | 69 | /** 70 | * @brief instantiate a DataFetcher object and start fetching data 71 | * 72 | * @param onData callback for segment correctly received, must not be empty 73 | */ 74 | static std::shared_ptr 75 | fetch(Face& face, const Interest& interest, int maxNackRetries, int maxTimeoutRetries, 76 | DataCallback onData, FailureCallback onTimeout, FailureCallback onNack, 77 | bool isVerbose); 78 | 79 | /** 80 | * @brief stop data fetching without error and calling any callback 81 | */ 82 | void 83 | cancel(); 84 | 85 | bool 86 | isRunning() const 87 | { 88 | return !m_isStopped && !m_hasError; 89 | } 90 | 91 | bool 92 | hasError() const 93 | { 94 | return m_hasError; 95 | } 96 | 97 | private: 98 | DataFetcher(Face& face, int maxNackRetries, int maxTimeoutRetries, 99 | DataCallback onData, FailureCallback onNack, FailureCallback onTimeout, 100 | bool isVerbose); 101 | 102 | void 103 | expressInterest(const Interest& interest, const std::shared_ptr& self); 104 | 105 | void 106 | handleData(const Interest& interest, const Data& data, const std::shared_ptr& self); 107 | 108 | void 109 | handleNack(const Interest& interest, const lp::Nack& nack, const std::shared_ptr& self); 110 | 111 | void 112 | handleTimeout(const Interest& interest, const std::shared_ptr& self); 113 | 114 | private: 115 | Face& m_face; 116 | Scheduler m_scheduler; 117 | PendingInterestHandle m_pendingInterest; 118 | DataCallback m_onData; 119 | FailureCallback m_onNack; 120 | FailureCallback m_onTimeout; 121 | 122 | int m_maxNackRetries; 123 | int m_maxTimeoutRetries; 124 | int m_nNacks = 0; 125 | int m_nTimeouts = 0; 126 | uint32_t m_nCongestionRetries = 0; 127 | 128 | bool m_isVerbose = false; 129 | bool m_isStopped = false; 130 | bool m_hasError = false; 131 | }; 132 | 133 | } // namespace ndn::get 134 | 135 | #endif // NDN_TOOLS_GET_DATA_FETCHER_HPP 136 | --------------------------------------------------------------------------------