blob: 59a283e0e50ed64f73faf362c063eaef219b08b5 [file] [log] [blame]
Junxiao Shiea48d8b2014-03-16 13:53:47 -07001/* -*- 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
15namespace nfd {
16namespace tests {
17
18BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture)
19
Junxiao Shiea48d8b2014-03-16 13:53:47 -070020shared_ptr<const Data> g_response;
21
22void
23interceptResponse(const Data& data)
24{
25 g_response = data.shared_from_this();
26}
27
28BOOST_AUTO_TEST_CASE(Status)
29{
30 // initialize
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070031 time::system_clock::TimePoint t1 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070032 Forwarder forwarder;
33 shared_ptr<InternalFace> internalFace = make_shared<InternalFace>();
34 internalFace->onReceiveData += &interceptResponse;
35 StatusServer statusServer(internalFace, boost::ref(forwarder));
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070036 time::system_clock::TimePoint t2 = time::system_clock::now();
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070037
Junxiao Shiea48d8b2014-03-16 13:53:47 -070038 // 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 Shi16d1b7d2014-03-27 21:29:09 -070050
Junxiao Shiea48d8b2014-03-16 13:53:47 -070051 // request
52 shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status");
53 request->setMustBeFresh(true);
54 request->setChildSelector(1);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070055
Junxiao Shiea48d8b2014-03-16 13:53:47 -070056 g_response.reset();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070057 time::system_clock::TimePoint t3 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070058 internalFace->sendInterest(*request);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070059 g_io.run_one();
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070060 time::system_clock::TimePoint t4 = time::system_clock::now();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070061 BOOST_REQUIRE(static_cast<bool>(g_response));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070062
Junxiao Shiea48d8b2014-03-16 13:53:47 -070063 // verify
64 ndn::nfd::Status status;
65 BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent()));
Junxiao Shi16d1b7d2014-03-27 21:29:09 -070066
Junxiao Shiea48d8b2014-03-16 13:53:47 -070067 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070068 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 Shi16d1b7d2014-03-27 21:29:09 -070072
Junxiao Shiea48d8b2014-03-16 13:53:47 -070073 // 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
82BOOST_AUTO_TEST_SUITE_END()
83
84} // namespace tests
85} // namespace nfd