Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/status-server.hpp" |
| 8 | #include "fw/forwarder.hpp" |
| 9 | #include "core/version.hpp" |
| 10 | #include "mgmt/internal-face.hpp" |
| 11 | |
| 12 | #include "tests/test-common.hpp" |
| 13 | #include "tests/face/dummy-face.hpp" |
| 14 | |
| 15 | namespace nfd { |
| 16 | namespace tests { |
| 17 | |
| 18 | BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture) |
| 19 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 20 | shared_ptr<const Data> g_response; |
| 21 | |
| 22 | void |
| 23 | interceptResponse(const Data& data) |
| 24 | { |
| 25 | g_response = data.shared_from_this(); |
| 26 | } |
| 27 | |
| 28 | BOOST_AUTO_TEST_CASE(Status) |
| 29 | { |
| 30 | // initialize |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 31 | time::system_clock::TimePoint t1 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 32 | Forwarder forwarder; |
| 33 | shared_ptr<InternalFace> internalFace = make_shared<InternalFace>(); |
| 34 | internalFace->onReceiveData += &interceptResponse; |
| 35 | StatusServer statusServer(internalFace, boost::ref(forwarder)); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 36 | time::system_clock::TimePoint t2 = time::system_clock::now(); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 37 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 38 | // populate tables |
| 39 | forwarder.getFib().insert("ndn:/fib1"); |
| 40 | forwarder.getPit().insert(*makeInterest("ndn:/pit1")); |
| 41 | forwarder.getPit().insert(*makeInterest("ndn:/pit2")); |
| 42 | forwarder.getPit().insert(*makeInterest("ndn:/pit3")); |
| 43 | forwarder.getPit().insert(*makeInterest("ndn:/pit4")); |
| 44 | forwarder.getMeasurements().get("ndn:/measurements1"); |
| 45 | forwarder.getMeasurements().get("ndn:/measurements2"); |
| 46 | forwarder.getMeasurements().get("ndn:/measurements3"); |
| 47 | BOOST_CHECK_GE(forwarder.getFib().size(), 1); |
| 48 | BOOST_CHECK_GE(forwarder.getPit().size(), 4); |
| 49 | BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 50 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 51 | // request |
| 52 | shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status"); |
| 53 | request->setMustBeFresh(true); |
| 54 | request->setChildSelector(1); |
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 | g_response.reset(); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 57 | time::system_clock::TimePoint t3 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 58 | internalFace->sendInterest(*request); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 59 | g_io.run_one(); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 60 | time::system_clock::TimePoint t4 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 61 | BOOST_REQUIRE(static_cast<bool>(g_response)); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 62 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 63 | // verify |
| 64 | ndn::nfd::Status status; |
| 65 | BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent())); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 66 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 67 | BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 68 | BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1)); |
| 69 | BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2)); |
| 70 | BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3)); |
| 71 | BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4)); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 72 | |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 73 | // StatusServer under test isn't added to Forwarder, |
| 74 | // so request and response won't affect table size |
| 75 | BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size()); |
| 76 | BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size()); |
| 77 | BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size()); |
| 78 | BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size()); |
| 79 | BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size()); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_SUITE_END() |
| 83 | |
| 84 | } // namespace tests |
| 85 | } // namespace nfd |