blob: 1fe5b35c3f4d4d3ba8aef493c88e3e6fcdd376f5 [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/*
3 * Copyright (c) 2014-2018, 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 Pesavento013de9b2016-09-01 12:06:56 +000023#include "../../identity-management-fixture.hpp"
Eric Newberrya93680e2015-07-15 19:25:29 -070024
Davide Pesavento5923bf82018-08-09 01:55:44 -040025#include <ndn-cxx/util/dummy-client-face.hpp>
26
Eric Newberrya93680e2015-07-15 19:25:29 -070027namespace ndn {
28namespace ping {
29namespace server {
30namespace tests {
31
32using namespace ndn::tests;
33
Davide Pesavento013de9b2016-09-01 12:06:56 +000034BOOST_AUTO_TEST_SUITE(Ping)
35BOOST_AUTO_TEST_SUITE(TestPingServer)
Eric Newberrya93680e2015-07-15 19:25:29 -070036
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070037class CreatePingServerFixture : public IdentityManagementTimeFixture
Eric Newberrya93680e2015-07-15 19:25:29 -070038{
39protected:
40 CreatePingServerFixture()
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000041 : face(io, m_keyChain, {false, true})
Eric Newberrya93680e2015-07-15 19:25:29 -070042 , pingOptions(makeOptions())
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000043 , pingServer(face, m_keyChain, pingOptions)
Eric Newberrya93680e2015-07-15 19:25:29 -070044 {
45 }
46
47 Interest
48 makePingInterest(int seq) const
49 {
50 Name name(pingOptions.prefix);
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040051 name.append("ping")
52 .append(to_string(seq));
53
54 return Interest(name)
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060055 .setCanBePrefix(false)
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040056 .setMustBeFresh(true)
57 .setInterestLifetime(2_s);
Eric Newberrya93680e2015-07-15 19:25:29 -070058 }
59
60private:
61 static Options
62 makeOptions()
63 {
64 Options opt;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040065 opt.prefix = "/test-prefix";
66 opt.freshnessPeriod = 5_s;
Eric Newberrya93680e2015-07-15 19:25:29 -070067 opt.nMaxPings = 2;
Eric Newberrya93680e2015-07-15 19:25:29 -070068 opt.payloadSize = 0;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040069 opt.wantTimestamp = false;
70 opt.wantQuiet = true;
Eric Newberrya93680e2015-07-15 19:25:29 -070071 return opt;
72 }
73
74protected:
75 boost::asio::io_service io;
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
81BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
82{
83 BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
84 pingServer.start();
85
Davide Pesavento5923bf82018-08-09 01:55:44 -040086 advanceClocks(io, 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
91 io.run();
92
Davide Pesavento5923bf82018-08-09 01:55:44 -040093 BOOST_CHECK_EQUAL(2, pingServer.getNPings());
Eric Newberrya93680e2015-07-15 19:25:29 -070094}
95
Davide Pesavento013de9b2016-09-01 12:06:56 +000096BOOST_AUTO_TEST_SUITE_END() // TestPingServer
97BOOST_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