blob: 497d4d6bc37dca336a0154d6f1a11ae3748c79ae [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);
51 name.append("ping");
52 name.append(std::to_string(seq));
53 Interest interest(name);
54 interest.setMustBeFresh(true);
55 interest.setInterestLifetime(time::milliseconds(2000));
56 return interest;
57 }
58
59private:
60 static Options
61 makeOptions()
62 {
63 Options opt;
64 opt.prefix = "ndn:/test-prefix";
65 opt.freshnessPeriod = time::milliseconds(5000);
66 opt.nMaxPings = 2;
Davide Pesavento5923bf82018-08-09 01:55:44 -040067 opt.wantTimestamp = false;
Eric Newberrya93680e2015-07-15 19:25:29 -070068 opt.payloadSize = 0;
69 return opt;
70 }
71
72protected:
73 boost::asio::io_service io;
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000074 util::DummyClientFace face;
Eric Newberrya93680e2015-07-15 19:25:29 -070075 Options pingOptions;
76 PingServer pingServer;
77};
78
79BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
80{
81 BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
82 pingServer.start();
83
Davide Pesavento5923bf82018-08-09 01:55:44 -040084 advanceClocks(io, 1_ms, 200);
Eric Newberrya93680e2015-07-15 19:25:29 -070085
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000086 face.receive(makePingInterest(1000));
87 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070088
89 io.run();
90
Davide Pesavento5923bf82018-08-09 01:55:44 -040091 BOOST_CHECK_EQUAL(2, pingServer.getNPings());
Eric Newberrya93680e2015-07-15 19:25:29 -070092}
93
Davide Pesavento013de9b2016-09-01 12:06:56 +000094BOOST_AUTO_TEST_SUITE_END() // TestPingServer
95BOOST_AUTO_TEST_SUITE_END() // Ping
Eric Newberrya93680e2015-07-15 19:25:29 -070096
97} // namespace tests
98} // namespace server
99} // namespace ping
100} // namespace ndn