blob: 3d8442b2b244652e9cdb445509e7b4b056c2f393 [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
20static inline ndn::nfd::Status::Timestamp
21now()
22{
23 return ndn::nfd::Status::Timestamp(
24 boost::chrono::duration_cast<ndn::nfd::Status::Timestamp::duration>(
25 boost::chrono::system_clock::now().time_since_epoch()
26 )
27 );
28}
29
30shared_ptr<const Data> g_response;
31
32void
33interceptResponse(const Data& data)
34{
35 g_response = data.shared_from_this();
36}
37
38BOOST_AUTO_TEST_CASE(Status)
39{
40 // initialize
41 ndn::nfd::Status::Timestamp t1 = now();
42 Forwarder forwarder;
43 shared_ptr<InternalFace> internalFace = make_shared<InternalFace>();
44 internalFace->onReceiveData += &interceptResponse;
45 StatusServer statusServer(internalFace, boost::ref(forwarder));
46 ndn::nfd::Status::Timestamp t2 = now();
47
48 // populate tables
49 forwarder.getFib().insert("ndn:/fib1");
50 forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
51 forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
52 forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
53 forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
54 forwarder.getMeasurements().get("ndn:/measurements1");
55 forwarder.getMeasurements().get("ndn:/measurements2");
56 forwarder.getMeasurements().get("ndn:/measurements3");
57 BOOST_CHECK_GE(forwarder.getFib().size(), 1);
58 BOOST_CHECK_GE(forwarder.getPit().size(), 4);
59 BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3);
60
61 // request
62 shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status");
63 request->setMustBeFresh(true);
64 request->setChildSelector(1);
65
66 g_response.reset();
67 ndn::nfd::Status::Timestamp t3 = now();
68 internalFace->sendInterest(*request);
69 ndn::nfd::Status::Timestamp t4 = now();
70 BOOST_REQUIRE(static_cast<bool>(g_response));
71
72 // verify
73 ndn::nfd::Status status;
74 BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent()));
75
76 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION);
77 BOOST_CHECK_GE(status.getStartTimestamp(), t1);
78 BOOST_CHECK_LE(status.getStartTimestamp(), t2);
79 BOOST_CHECK_GE(status.getCurrentTimestamp(), t3);
80 BOOST_CHECK_LE(status.getCurrentTimestamp(), t4);
81
82 // StatusServer under test isn't added to Forwarder,
83 // so request and response won't affect table size
84 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size());
85 BOOST_CHECK_EQUAL(status.getNFibEntries(), forwarder.getFib().size());
86 BOOST_CHECK_EQUAL(status.getNPitEntries(), forwarder.getPit().size());
87 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), forwarder.getMeasurements().size());
88 BOOST_CHECK_EQUAL(status.getNCsEntries(), forwarder.getCs().size());
89}
90
91BOOST_AUTO_TEST_SUITE_END()
92
93} // namespace tests
94} // namespace nfd