Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 3 | * 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 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 25 | |
| 26 | #include "mgmt/status-server.hpp" |
| 27 | #include "fw/forwarder.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 28 | #include "version.hpp" |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 29 | #include "mgmt/internal-face.hpp" |
| 30 | |
| 31 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 32 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace tests { |
| 36 | |
| 37 | BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture) |
| 38 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 39 | shared_ptr<const Data> g_response; |
| 40 | |
| 41 | void |
| 42 | interceptResponse(const Data& data) |
| 43 | { |
| 44 | g_response = data.shared_from_this(); |
| 45 | } |
| 46 | |
| 47 | BOOST_AUTO_TEST_CASE(Status) |
| 48 | { |
| 49 | // initialize |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 50 | time::system_clock::TimePoint t1 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 51 | Forwarder forwarder; |
| 52 | shared_ptr<InternalFace> internalFace = make_shared<InternalFace>(); |
| 53 | internalFace->onReceiveData += &interceptResponse; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 54 | ndn::KeyChain keyChain; |
| 55 | StatusServer statusServer(internalFace, ref(forwarder), keyChain); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 56 | time::system_clock::TimePoint t2 = time::system_clock::now(); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 57 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 58 | // 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 Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 71 | // request |
| 72 | shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status"); |
| 73 | request->setMustBeFresh(true); |
| 74 | request->setChildSelector(1); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 76 | g_response.reset(); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 77 | time::system_clock::TimePoint t3 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 78 | internalFace->sendInterest(*request); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 79 | g_io.run_one(); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 80 | time::system_clock::TimePoint t4 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 81 | BOOST_REQUIRE(static_cast<bool>(g_response)); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 82 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 83 | // verify |
Junxiao Shi | 88d6937 | 2014-03-28 11:52:39 -0700 | [diff] [blame] | 84 | ndn::nfd::ForwarderStatus status; |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 85 | BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent())); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 88 | 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 Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 92 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 93 | // 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 | |
| 102 | BOOST_AUTO_TEST_SUITE_END() |
| 103 | |
| 104 | } // namespace tests |
| 105 | } // namespace nfd |