blob: 4cf7c132410d19d50bedbab533aa3c2908c9a1b3 [file] [log] [blame]
Junxiao Shiea48d8b2014-03-16 13:53:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince Lehman5144f822014-07-23 15:12:56 -070024 */
Junxiao Shiea48d8b2014-03-16 13:53:47 -070025
26#include "mgmt/status-server.hpp"
27#include "fw/forwarder.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070028#include "version.hpp"
Junxiao Shiea48d8b2014-03-16 13:53:47 -070029#include "mgmt/internal-face.hpp"
30
31#include "tests/test-common.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070032#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shiea48d8b2014-03-16 13:53:47 -070033
34namespace nfd {
35namespace tests {
36
37BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture)
38
Junxiao Shiea48d8b2014-03-16 13:53:47 -070039shared_ptr<const Data> g_response;
40
41void
42interceptResponse(const Data& data)
43{
44 g_response = data.shared_from_this();
45}
46
47BOOST_AUTO_TEST_CASE(Status)
48{
49 // initialize
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070050 time::system_clock::TimePoint t1 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070051 Forwarder forwarder;
52 shared_ptr<InternalFace> internalFace = make_shared<InternalFace>();
Junxiao Shic099ddb2014-12-25 20:53:20 -070053 internalFace->onReceiveData.connect(&interceptResponse);
Vince Lehman5144f822014-07-23 15:12:56 -070054 ndn::KeyChain keyChain;
55 StatusServer statusServer(internalFace, ref(forwarder), keyChain);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070056 time::system_clock::TimePoint t2 = time::system_clock::now();
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070057
Junxiao Shiea48d8b2014-03-16 13:53:47 -070058 // populate tables
59 forwarder.getFib().insert("ndn:/fib1");
60 forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
61 forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
62 forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
63 forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
64 forwarder.getMeasurements().get("ndn:/measurements1");
65 forwarder.getMeasurements().get("ndn:/measurements2");
66 forwarder.getMeasurements().get("ndn:/measurements3");
67 BOOST_CHECK_GE(forwarder.getFib().size(), 1);
68 BOOST_CHECK_GE(forwarder.getPit().size(), 4);
69 BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070070
Junxiao Shiea48d8b2014-03-16 13:53:47 -070071 // request
72 shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status");
73 request->setMustBeFresh(true);
74 request->setChildSelector(1);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070075
Junxiao Shiea48d8b2014-03-16 13:53:47 -070076 g_response.reset();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070077 time::system_clock::TimePoint t3 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070078 internalFace->sendInterest(*request);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070079 g_io.run_one();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070080 time::system_clock::TimePoint t4 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070081 BOOST_REQUIRE(static_cast<bool>(g_response));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070082
Junxiao Shiea48d8b2014-03-16 13:53:47 -070083 // verify
Junxiao Shi88d69372014-03-28 11:52:39 -070084 ndn::nfd::ForwarderStatus status;
Junxiao Shiea48d8b2014-03-16 13:53:47 -070085 BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent()));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070086
Hila Ben Abraham2ef99572014-12-02 02:45:51 -060087 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070088 BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1));
89 BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2));
90 BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3));
91 BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070092
Junxiao Shiea48d8b2014-03-16 13:53:47 -070093 // StatusServer under test isn't added to Forwarder,
94 // so request and response won't affect table size
95 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size());
96 BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size());
97 BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size());
98 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size());
99 BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size());
100}
101
102BOOST_AUTO_TEST_SUITE_END()
103
104} // namespace tests
105} // namespace nfd