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