Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 11fc3eb | 2024-01-26 01:46:56 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, Arizona Board of Regents. |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 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 <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "tools/ping/server/ping-server.hpp" |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 21 | |
| 22 | #include "tests/test-common.hpp" |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 23 | #include "tests/io-fixture.hpp" |
| 24 | #include "tests/key-chain-fixture.hpp" |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame] | 26 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 27 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 28 | namespace ndn::ping::server::tests { |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 29 | |
| 30 | using namespace ndn::tests; |
| 31 | |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 32 | class PingServerFixture : public IoFixture, public KeyChainFixture |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 33 | { |
| 34 | protected: |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 35 | Interest |
| 36 | makePingInterest(int seq) const |
| 37 | { |
| 38 | Name name(pingOptions.prefix); |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 39 | name.append("ping") |
Davide Pesavento | 11fc3eb | 2024-01-26 01:46:56 -0500 | [diff] [blame^] | 40 | .append(std::to_string(seq)); |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 41 | |
| 42 | return Interest(name) |
| 43 | .setMustBeFresh(true) |
| 44 | .setInterestLifetime(2_s); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | private: |
| 48 | static Options |
| 49 | makeOptions() |
| 50 | { |
| 51 | Options opt; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 52 | opt.prefix = "/test-prefix"; |
| 53 | opt.freshnessPeriod = 5_s; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 54 | opt.nMaxPings = 2; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 55 | opt.payloadSize = 0; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 56 | opt.wantTimestamp = false; |
| 57 | opt.wantQuiet = true; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 58 | return opt; |
| 59 | } |
| 60 | |
| 61 | protected: |
Junxiao Shi | 869d73e | 2023-08-10 22:52:26 +0000 | [diff] [blame] | 62 | DummyClientFace face{m_io, m_keyChain, {false, true}}; |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 63 | Options pingOptions{makeOptions()}; |
| 64 | PingServer pingServer{face, m_keyChain, pingOptions}; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 67 | BOOST_AUTO_TEST_SUITE(Ping) |
| 68 | BOOST_AUTO_TEST_SUITE(TestServer) |
| 69 | |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 70 | BOOST_FIXTURE_TEST_CASE(Receive, PingServerFixture) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 71 | { |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 72 | BOOST_TEST(pingServer.getNPings() == 0); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 73 | pingServer.start(); |
| 74 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 75 | advanceClocks(1_ms, 200); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 77 | face.receive(makePingInterest(1000)); |
| 78 | face.receive(makePingInterest(1001)); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 79 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame] | 80 | m_io.run(); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 81 | |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 82 | BOOST_TEST(pingServer.getNPings() == 2); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 85 | BOOST_AUTO_TEST_SUITE_END() // TestServer |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 86 | BOOST_AUTO_TEST_SUITE_END() // Ping |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 87 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 88 | } // namespace ndn::ping::server::tests |