blob: 84e967f47aad78b076106cab0e3236f5083b0d70 [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)
55 .setMustBeFresh(true)
56 .setInterestLifetime(2_s);
Eric Newberrya93680e2015-07-15 19:25:29 -070057 }
58
59private:
60 static Options
61 makeOptions()
62 {
63 Options opt;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040064 opt.prefix = "/test-prefix";
65 opt.freshnessPeriod = 5_s;
Eric Newberrya93680e2015-07-15 19:25:29 -070066 opt.nMaxPings = 2;
Eric Newberrya93680e2015-07-15 19:25:29 -070067 opt.payloadSize = 0;
Davide Pesavento2bdda1d2018-08-09 19:35:49 -040068 opt.wantTimestamp = false;
69 opt.wantQuiet = true;
Eric Newberrya93680e2015-07-15 19:25:29 -070070 return opt;
71 }
72
73protected:
74 boost::asio::io_service io;
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000075 util::DummyClientFace face;
Eric Newberrya93680e2015-07-15 19:25:29 -070076 Options pingOptions;
77 PingServer pingServer;
78};
79
80BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
81{
82 BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
83 pingServer.start();
84
Davide Pesavento5923bf82018-08-09 01:55:44 -040085 advanceClocks(io, 1_ms, 200);
Eric Newberrya93680e2015-07-15 19:25:29 -070086
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000087 face.receive(makePingInterest(1000));
88 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070089
90 io.run();
91
Davide Pesavento5923bf82018-08-09 01:55:44 -040092 BOOST_CHECK_EQUAL(2, pingServer.getNPings());
Eric Newberrya93680e2015-07-15 19:25:29 -070093}
94
Davide Pesavento013de9b2016-09-01 12:06:56 +000095BOOST_AUTO_TEST_SUITE_END() // TestPingServer
96BOOST_AUTO_TEST_SUITE_END() // Ping
Eric Newberrya93680e2015-07-15 19:25:29 -070097
98} // namespace tests
99} // namespace server
100} // namespace ping
101} // namespace ndn