blob: cd7fce2d5ae9b7399399d14bd63b266b82be9840 [file] [log] [blame]
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, 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.
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/>.
24 */
25
26#include "mgmt/forwarder-status-manager.hpp"
27#include "fw/forwarder.hpp"
28#include "version.hpp"
29
30#include "tests/test-common.hpp"
31#include "tests/daemon/face/dummy-face.hpp"
32#include <ndn-cxx/util/dummy-client-face.hpp>
33#include <ndn-cxx/mgmt/dispatcher.hpp>
34
35namespace nfd {
36namespace tests {
37
38BOOST_FIXTURE_TEST_SUITE(Mgmt, UnitTestTimeFixture)
39BOOST_AUTO_TEST_SUITE(TestForwarderStatusManager)
40
41BOOST_AUTO_TEST_CASE(Status)
42{
43 // initialize
44 time::system_clock::TimePoint t1 = time::system_clock::now();
45 Forwarder forwarder;
46 auto face = ndn::util::makeDummyClientFace(g_io, {true, true});
47 ndn::KeyChain keyChain;
48 ndn::mgmt::Dispatcher dispatcher(*face, ref(keyChain));
49 ForwarderStatusManager statusServer(ref(forwarder), ref(dispatcher));
50 dispatcher.addTopPrefix("/localhost/nfd");
51 advanceClocks(time::milliseconds(1));
52
53 // populate tables
54 time::system_clock::TimePoint t2 = time::system_clock::now();
55 forwarder.getFib().insert("ndn:/fib1");
56 forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
57 forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
58 forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
59 forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
60 forwarder.getMeasurements().get("ndn:/measurements1");
61 forwarder.getMeasurements().get("ndn:/measurements2");
62 forwarder.getMeasurements().get("ndn:/measurements3");
63 BOOST_CHECK_GE(forwarder.getFib().size(), 1);
64 BOOST_CHECK_GE(forwarder.getPit().size(), 4);
65 BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3);
66
67 // request
68 time::system_clock::TimePoint t3 = time::system_clock::now();
69 auto request = makeInterest("ndn:/localhost/nfd/status");
70 request->setMustBeFresh(true);
71 request->setChildSelector(1);
72
73 face->receive<Interest>(*request);
74 advanceClocks(time::milliseconds(1));
75
76 // verify
77 time::system_clock::TimePoint t4 = time::system_clock::now();
78 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
79 ndn::nfd::ForwarderStatus status;
Alexander Afanasyevecbf5842015-09-08 17:25:23 -070080 BOOST_REQUIRE_NO_THROW(status.wireDecode(face->sentDatas[0].getContent()));
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070081
82 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING);
83 BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1));
84 BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2));
85 BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3));
86 BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4));
87
88 // Interest/Data toward ForwarderStatusManager don't go through Forwarder,
89 // so request and response won't affect table size
90 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size());
91 BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size());
92 BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size());
93 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size());
94 BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size());
Junxiao Shida93f1f2015-11-11 06:13:16 -070095 // TODO#3325 check packet counter values
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070096}
97
98BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatusManager
99BOOST_AUTO_TEST_SUITE_END() // Mgmt
100
101} // namespace tests
102} // namespace nfd