blob: 0192008182746b36f3b2b044f8ca956e36ff633c [file] [log] [blame]
Eric Newberrya93680e2015-07-15 19:25:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiaa1b3c92016-07-14 14:56:53 +00003 * Copyright (c) 2014-2016, 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"
21#include <ndn-cxx/util/dummy-client-face.hpp>
22
23#include "tests/test-common.hpp"
Davide Pesavento013de9b2016-09-01 12:06:56 +000024#include "../../identity-management-fixture.hpp"
Eric Newberrya93680e2015-07-15 19:25:29 -070025
26namespace ndn {
27namespace ping {
28namespace server {
29namespace tests {
30
31using namespace ndn::tests;
32
Davide Pesavento013de9b2016-09-01 12:06:56 +000033BOOST_AUTO_TEST_SUITE(Ping)
34BOOST_AUTO_TEST_SUITE(TestPingServer)
Eric Newberrya93680e2015-07-15 19:25:29 -070035
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070036class CreatePingServerFixture : public IdentityManagementTimeFixture
Eric Newberrya93680e2015-07-15 19:25:29 -070037{
38protected:
39 CreatePingServerFixture()
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000040 : face(io, m_keyChain, {false, true})
Eric Newberrya93680e2015-07-15 19:25:29 -070041 , pingOptions(makeOptions())
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000042 , pingServer(face, m_keyChain, pingOptions)
Eric Newberrya93680e2015-07-15 19:25:29 -070043 {
44 }
45
46 Interest
47 makePingInterest(int seq) const
48 {
49 Name name(pingOptions.prefix);
50 name.append("ping");
51 name.append(std::to_string(seq));
52 Interest interest(name);
53 interest.setMustBeFresh(true);
54 interest.setInterestLifetime(time::milliseconds(2000));
55 return interest;
56 }
57
58private:
59 static Options
60 makeOptions()
61 {
62 Options opt;
63 opt.prefix = "ndn:/test-prefix";
64 opt.freshnessPeriod = time::milliseconds(5000);
65 opt.nMaxPings = 2;
66 opt.shouldPrintTimestamp = false;
67 opt.payloadSize = 0;
68 return opt;
69 }
70
71protected:
72 boost::asio::io_service io;
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000073 util::DummyClientFace face;
Eric Newberrya93680e2015-07-15 19:25:29 -070074 Options pingOptions;
75 PingServer pingServer;
76};
77
78BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
79{
80 BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
81 pingServer.start();
82
83 this->advanceClocks(io, time::milliseconds(1), 200);
84
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000085 face.receive(makePingInterest(1000));
86 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070087
88 io.run();
89
90 BOOST_REQUIRE_EQUAL(2, pingServer.getNPings());
91}
92
Davide Pesavento013de9b2016-09-01 12:06:56 +000093BOOST_AUTO_TEST_SUITE_END() // TestPingServer
94BOOST_AUTO_TEST_SUITE_END() // Ping
Eric Newberrya93680e2015-07-15 19:25:29 -070095
96} // namespace tests
97} // namespace server
98} // namespace ping
99} // namespace ndn