blob: 2efae0e50b1e9df676e4a2232f1d52d2185ac762 [file] [log] [blame]
Eric Newberrya93680e2015-07-15 19:25:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento5923bf82018-08-09 01:55:44 -04002/*
Davide Pesavento11fc3eb2024-01-26 01:46:56 -05003 * Copyright (c) 2014-2024, Arizona Board of Regents.
Eric Newberrya93680e2015-07-15 19:25:29 -07004 *
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 Newberrya93680e2015-07-15 19:25:29 -070021
22#include "tests/test-common.hpp"
Davide Pesavento66777622020-10-09 18:46:03 -040023#include "tests/io-fixture.hpp"
24#include "tests/key-chain-fixture.hpp"
Eric Newberrya93680e2015-07-15 19:25:29 -070025
Davide Pesavento5923bf82018-08-09 01:55:44 -040026#include <ndn-cxx/util/dummy-client-face.hpp>
27
Davide Pesaventob3570c62022-02-19 19:19:00 -050028namespace ndn::ping::server::tests {
Eric Newberrya93680e2015-07-15 19:25:29 -070029
30using namespace ndn::tests;
31
Davide Pesaventof8d9a532021-07-03 16:04:12 -040032class PingServerFixture : public IoFixture, public KeyChainFixture
Eric Newberrya93680e2015-07-15 19:25:29 -070033{
34protected:
Eric Newberrya93680e2015-07-15 19:25:29 -070035 Interest
36 makePingInterest(int seq) const
37 {
38 Name name(pingOptions.prefix);
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040039 name.append("ping")
Davide Pesavento11fc3eb2024-01-26 01:46:56 -050040 .append(std::to_string(seq));
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040041
42 return Interest(name)
43 .setMustBeFresh(true)
44 .setInterestLifetime(2_s);
Eric Newberrya93680e2015-07-15 19:25:29 -070045 }
46
47private:
48 static Options
49 makeOptions()
50 {
51 Options opt;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040052 opt.prefix = "/test-prefix";
53 opt.freshnessPeriod = 5_s;
Eric Newberrya93680e2015-07-15 19:25:29 -070054 opt.nMaxPings = 2;
Eric Newberrya93680e2015-07-15 19:25:29 -070055 opt.payloadSize = 0;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040056 opt.wantTimestamp = false;
57 opt.wantQuiet = true;
Eric Newberrya93680e2015-07-15 19:25:29 -070058 return opt;
59 }
60
61protected:
Junxiao Shi869d73e2023-08-10 22:52:26 +000062 DummyClientFace face{m_io, m_keyChain, {false, true}};
Davide Pesaventob3570c62022-02-19 19:19:00 -050063 Options pingOptions{makeOptions()};
64 PingServer pingServer{face, m_keyChain, pingOptions};
Eric Newberrya93680e2015-07-15 19:25:29 -070065};
66
Davide Pesaventob3570c62022-02-19 19:19:00 -050067BOOST_AUTO_TEST_SUITE(Ping)
68BOOST_AUTO_TEST_SUITE(TestServer)
69
Davide Pesaventof8d9a532021-07-03 16:04:12 -040070BOOST_FIXTURE_TEST_CASE(Receive, PingServerFixture)
Eric Newberrya93680e2015-07-15 19:25:29 -070071{
Davide Pesaventof8d9a532021-07-03 16:04:12 -040072 BOOST_TEST(pingServer.getNPings() == 0);
Eric Newberrya93680e2015-07-15 19:25:29 -070073 pingServer.start();
74
Davide Pesavento66777622020-10-09 18:46:03 -040075 advanceClocks(1_ms, 200);
Eric Newberrya93680e2015-07-15 19:25:29 -070076
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000077 face.receive(makePingInterest(1000));
78 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070079
Davide Pesavento66777622020-10-09 18:46:03 -040080 m_io.run();
Eric Newberrya93680e2015-07-15 19:25:29 -070081
Davide Pesaventof8d9a532021-07-03 16:04:12 -040082 BOOST_TEST(pingServer.getNPings() == 2);
Eric Newberrya93680e2015-07-15 19:25:29 -070083}
84
Davide Pesaventof8d9a532021-07-03 16:04:12 -040085BOOST_AUTO_TEST_SUITE_END() // TestServer
Davide Pesavento013de9b2016-09-01 12:06:56 +000086BOOST_AUTO_TEST_SUITE_END() // Ping
Eric Newberrya93680e2015-07-15 19:25:29 -070087
Davide Pesaventob3570c62022-02-19 19:19:00 -050088} // namespace ndn::ping::server::tests