blob: 14cdf44ec696882e0e09c841d8ad54a9fc2a6faf [file] [log] [blame]
Junxiao Shiea48d8b2014-03-16 13:53:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shiea48d8b2014-03-16 13:53:47 -070024
25#include "mgmt/status-server.hpp"
26#include "fw/forwarder.hpp"
27#include "core/version.hpp"
28#include "mgmt/internal-face.hpp"
29
30#include "tests/test-common.hpp"
31#include "tests/face/dummy-face.hpp"
32
33namespace nfd {
34namespace tests {
35
36BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture)
37
Junxiao Shiea48d8b2014-03-16 13:53:47 -070038shared_ptr<const Data> g_response;
39
40void
41interceptResponse(const Data& data)
42{
43 g_response = data.shared_from_this();
44}
45
46BOOST_AUTO_TEST_CASE(Status)
47{
48 // initialize
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070049 time::system_clock::TimePoint t1 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070050 Forwarder forwarder;
51 shared_ptr<InternalFace> internalFace = make_shared<InternalFace>();
52 internalFace->onReceiveData += &interceptResponse;
53 StatusServer statusServer(internalFace, boost::ref(forwarder));
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070054 time::system_clock::TimePoint t2 = time::system_clock::now();
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070055
Junxiao Shiea48d8b2014-03-16 13:53:47 -070056 // populate tables
57 forwarder.getFib().insert("ndn:/fib1");
58 forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
59 forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
60 forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
61 forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
62 forwarder.getMeasurements().get("ndn:/measurements1");
63 forwarder.getMeasurements().get("ndn:/measurements2");
64 forwarder.getMeasurements().get("ndn:/measurements3");
65 BOOST_CHECK_GE(forwarder.getFib().size(), 1);
66 BOOST_CHECK_GE(forwarder.getPit().size(), 4);
67 BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070068
Junxiao Shiea48d8b2014-03-16 13:53:47 -070069 // request
70 shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status");
71 request->setMustBeFresh(true);
72 request->setChildSelector(1);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070073
Junxiao Shiea48d8b2014-03-16 13:53:47 -070074 g_response.reset();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070075 time::system_clock::TimePoint t3 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070076 internalFace->sendInterest(*request);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070077 g_io.run_one();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070078 time::system_clock::TimePoint t4 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070079 BOOST_REQUIRE(static_cast<bool>(g_response));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070080
Junxiao Shiea48d8b2014-03-16 13:53:47 -070081 // verify
Junxiao Shi88d69372014-03-28 11:52:39 -070082 ndn::nfd::ForwarderStatus status;
Junxiao Shiea48d8b2014-03-16 13:53:47 -070083 BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent()));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070084
Junxiao Shiea48d8b2014-03-16 13:53:47 -070085 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070086 BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1));
87 BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2));
88 BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3));
89 BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070090
Junxiao Shiea48d8b2014-03-16 13:53:47 -070091 // StatusServer under test isn't added to Forwarder,
92 // so request and response won't affect table size
93 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size());
94 BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size());
95 BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size());
96 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size());
97 BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size());
98}
99
100BOOST_AUTO_TEST_SUITE_END()
101
102} // namespace tests
103} // namespace nfd