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 | /* |
| 3 | * Copyright (c) 2014-2018, 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 | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 23 | #include "../../identity-management-fixture.hpp" |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame] | 25 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 26 | |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 27 | namespace ndn { |
| 28 | namespace ping { |
| 29 | namespace server { |
| 30 | namespace tests { |
| 31 | |
| 32 | using namespace ndn::tests; |
| 33 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(Ping) |
| 35 | BOOST_AUTO_TEST_SUITE(TestPingServer) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 37 | class CreatePingServerFixture : public IdentityManagementTimeFixture |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 38 | { |
| 39 | protected: |
| 40 | CreatePingServerFixture() |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 41 | : face(io, m_keyChain, {false, true}) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 42 | , pingOptions(makeOptions()) |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 43 | , pingServer(face, m_keyChain, pingOptions) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | Interest |
| 48 | makePingInterest(int seq) const |
| 49 | { |
| 50 | Name name(pingOptions.prefix); |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 51 | name.append("ping") |
| 52 | .append(to_string(seq)); |
| 53 | |
| 54 | return Interest(name) |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 55 | .setCanBePrefix(false) |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 56 | .setMustBeFresh(true) |
| 57 | .setInterestLifetime(2_s); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | private: |
| 61 | static Options |
| 62 | makeOptions() |
| 63 | { |
| 64 | Options opt; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 65 | opt.prefix = "/test-prefix"; |
| 66 | opt.freshnessPeriod = 5_s; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 67 | opt.nMaxPings = 2; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 68 | opt.payloadSize = 0; |
Davide Pesavento | 2bdda1d | 2018-08-09 19:35:49 -0400 | [diff] [blame] | 69 | opt.wantTimestamp = false; |
| 70 | opt.wantQuiet = true; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 71 | return opt; |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | boost::asio::io_service io; |
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 | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame] | 86 | advanceClocks(io, 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 | |
| 91 | io.run(); |
| 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 |