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 | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, 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 | |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 28 | namespace ndn { |
| 29 | namespace ping { |
| 30 | namespace server { |
| 31 | namespace tests { |
| 32 | |
| 33 | using namespace ndn::tests; |
| 34 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Ping) |
| 36 | BOOST_AUTO_TEST_SUITE(TestPingServer) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame^] | 38 | class CreatePingServerFixture : public IoFixture, public KeyChainFixture |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 39 | { |
| 40 | protected: |
| 41 | CreatePingServerFixture() |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame^] | 42 | : face(m_io, m_keyChain, {false, true}) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 43 | , pingOptions(makeOptions()) |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 44 | , pingServer(face, m_keyChain, pingOptions) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
| 48 | Interest |
| 49 | makePingInterest(int seq) const |
| 50 | { |
| 51 | Name name(pingOptions.prefix); |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 52 | name.append("ping") |
| 53 | .append(to_string(seq)); |
| 54 | |
| 55 | return Interest(name) |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 56 | .setCanBePrefix(false) |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 57 | .setMustBeFresh(true) |
| 58 | .setInterestLifetime(2_s); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | private: |
| 62 | static Options |
| 63 | makeOptions() |
| 64 | { |
| 65 | Options opt; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 66 | opt.prefix = "/test-prefix"; |
| 67 | opt.freshnessPeriod = 5_s; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 68 | opt.nMaxPings = 2; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 69 | opt.payloadSize = 0; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 70 | opt.wantTimestamp = false; |
| 71 | opt.wantQuiet = true; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 72 | return opt; |
| 73 | } |
| 74 | |
| 75 | protected: |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 76 | util::DummyClientFace face; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 77 | Options pingOptions; |
| 78 | PingServer pingServer; |
| 79 | }; |
| 80 | |
| 81 | BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture) |
| 82 | { |
| 83 | BOOST_REQUIRE_EQUAL(0, pingServer.getNPings()); |
| 84 | pingServer.start(); |
| 85 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame^] | 86 | advanceClocks(1_ms, 200); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 87 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 88 | face.receive(makePingInterest(1000)); |
| 89 | face.receive(makePingInterest(1001)); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 90 | |
Davide Pesavento | 6677762 | 2020-10-09 18:46:03 -0400 | [diff] [blame^] | 91 | m_io.run(); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 92 | |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(2, pingServer.getNPings()); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 96 | BOOST_AUTO_TEST_SUITE_END() // TestPingServer |
| 97 | BOOST_AUTO_TEST_SUITE_END() // Ping |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 98 | |
| 99 | } // namespace tests |
| 100 | } // namespace server |
| 101 | } // namespace ping |
| 102 | } // namespace ndn |