blob: e01d3d7f372d75621939808522d4f04431c97546 [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 Pesaventof8d9a532021-07-03 16:04:12 -04003 * Copyright (c) 2014-2021, 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
Eric Newberrya93680e2015-07-15 19:25:29 -070028namespace ndn {
29namespace ping {
30namespace server {
31namespace tests {
32
33using namespace ndn::tests;
34
Davide Pesavento013de9b2016-09-01 12:06:56 +000035BOOST_AUTO_TEST_SUITE(Ping)
Davide Pesaventof8d9a532021-07-03 16:04:12 -040036BOOST_AUTO_TEST_SUITE(TestServer)
Eric Newberrya93680e2015-07-15 19:25:29 -070037
Davide Pesaventof8d9a532021-07-03 16:04:12 -040038class PingServerFixture : public IoFixture, public KeyChainFixture
Eric Newberrya93680e2015-07-15 19:25:29 -070039{
40protected:
Davide Pesaventof8d9a532021-07-03 16:04:12 -040041 PingServerFixture()
Davide Pesavento66777622020-10-09 18:46:03 -040042 : face(m_io, m_keyChain, {false, true})
Eric Newberrya93680e2015-07-15 19:25:29 -070043 , pingOptions(makeOptions())
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000044 , pingServer(face, m_keyChain, pingOptions)
Eric Newberrya93680e2015-07-15 19:25:29 -070045 {
46 }
47
48 Interest
49 makePingInterest(int seq) const
50 {
51 Name name(pingOptions.prefix);
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040052 name.append("ping")
53 .append(to_string(seq));
54
55 return Interest(name)
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060056 .setCanBePrefix(false)
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040057 .setMustBeFresh(true)
58 .setInterestLifetime(2_s);
Eric Newberrya93680e2015-07-15 19:25:29 -070059 }
60
61private:
62 static Options
63 makeOptions()
64 {
65 Options opt;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040066 opt.prefix = "/test-prefix";
67 opt.freshnessPeriod = 5_s;
Eric Newberrya93680e2015-07-15 19:25:29 -070068 opt.nMaxPings = 2;
Eric Newberrya93680e2015-07-15 19:25:29 -070069 opt.payloadSize = 0;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040070 opt.wantTimestamp = false;
71 opt.wantQuiet = true;
Eric Newberrya93680e2015-07-15 19:25:29 -070072 return opt;
73 }
74
75protected:
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000076 util::DummyClientFace face;
Eric Newberrya93680e2015-07-15 19:25:29 -070077 Options pingOptions;
78 PingServer pingServer;
79};
80
Davide Pesaventof8d9a532021-07-03 16:04:12 -040081BOOST_FIXTURE_TEST_CASE(Receive, PingServerFixture)
Eric Newberrya93680e2015-07-15 19:25:29 -070082{
Davide Pesaventof8d9a532021-07-03 16:04:12 -040083 BOOST_TEST(pingServer.getNPings() == 0);
Eric Newberrya93680e2015-07-15 19:25:29 -070084 pingServer.start();
85
Davide Pesavento66777622020-10-09 18:46:03 -040086 advanceClocks(1_ms, 200);
Eric Newberrya93680e2015-07-15 19:25:29 -070087
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000088 face.receive(makePingInterest(1000));
89 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070090
Davide Pesavento66777622020-10-09 18:46:03 -040091 m_io.run();
Eric Newberrya93680e2015-07-15 19:25:29 -070092
Davide Pesaventof8d9a532021-07-03 16:04:12 -040093 BOOST_TEST(pingServer.getNPings() == 2);
Eric Newberrya93680e2015-07-15 19:25:29 -070094}
95
Davide Pesaventof8d9a532021-07-03 16:04:12 -040096BOOST_AUTO_TEST_SUITE_END() // TestServer
Davide Pesavento013de9b2016-09-01 12:06:56 +000097BOOST_AUTO_TEST_SUITE_END() // Ping
Eric Newberrya93680e2015-07-15 19:25:29 -070098
99} // namespace tests
100} // namespace server
101} // namespace ping
102} // namespace ndn