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 | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 37 | |
| 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); |
| 50 | |
| 51 | // request |
| 52 | shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status"); |
| 53 | request->setMustBeFresh(true); |
| 54 | request->setChildSelector(1); |
| 55 | |
| 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); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame^] | 59 | time::system_clock::TimePoint t4 = time::system_clock::now(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 60 | BOOST_REQUIRE(static_cast<bool>(g_response)); |
| 61 | |
| 62 | // verify |
| 63 | ndn::nfd::Status status; |
| 64 | BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent())); |
| 65 | |
| 66 | BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame^] | 67 | BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1)); |
| 68 | BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2)); |
| 69 | BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3)); |
| 70 | BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4)); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 71 | |
| 72 | // StatusServer under test isn't added to Forwarder, |
| 73 | // so request and response won't affect table size |
| 74 | BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size()); |
| 75 | BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size()); |
| 76 | BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size()); |
| 77 | BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size()); |
| 78 | BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size()); |
| 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_SUITE_END() |
| 82 | |
| 83 | } // namespace tests |
| 84 | } // namespace nfd |