blob: c5e5f13c036978f674747b4295519e3a5aa97bb0 [file] [log] [blame]
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#include "utils/tracers/ndn-app-delay-tracer.hpp"
21
22#include <boost/filesystem.hpp>
23#include <boost/test/output_test_stream.hpp>
24
25#include "../../tests-common.hpp"
26
27namespace ns3 {
28namespace ndn {
29
30const boost::filesystem::path TEST_TRACE = boost::filesystem::path(TEST_CONFIG_PATH) / "trace.txt";
31
32class AppDelayTracerFixture : public ScenarioHelperWithCleanupFixture
33{
34public:
35 AppDelayTracerFixture()
36 {
37 boost::filesystem::create_directories(TEST_CONFIG_PATH);
38
39 // setting default parameters for PointToPoint links and channels
40 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
41 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
42 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
43
44 createTopology({
45 {"1", "2"},
46 {"2", "3"}
47 });
48
49 addRoutes({
50 {"1", "2", "/prefix", 1},
51 {"2", "3", "/prefix", 1}
52 });
53
54 addApps({
55 {"1", "ns3::ndn::ConsumerCbr",
56 {{"Prefix", "/prefix"}, {"Frequency", "1"}},
57 "0s", "0.9s"}, // send just one packet
58 // Second consumer will capture effect of the bug #2764
59 {"2", "ns3::ndn::ConsumerCbr",
60 {{"Prefix", "/prefix"}, {"Frequency", "1"}},
61 "2s", "100s"},
62 {"3", "ns3::ndn::Producer",
63 {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
64 "0s", "100s"}
65 });
66 }
67
68 ~AppDelayTracerFixture()
69 {
70 boost::filesystem::remove(TEST_TRACE);
71 AppDelayTracer::Destroy(); // additional cleanup
72 }
73};
74
75BOOST_FIXTURE_TEST_SUITE(UtilsTracersNdnAppDelayTracer, AppDelayTracerFixture)
76
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -080077BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(InstallAll, 1);
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -070078BOOST_AUTO_TEST_CASE(InstallAll)
79{
80 AppDelayTracer::InstallAll(TEST_TRACE.string());
81
82 Simulator::Stop(Seconds(4));
83 Simulator::Run();
84
85 AppDelayTracer::Destroy(); // to force log to be written
86
87 std::ifstream t(TEST_TRACE.string().c_str());
88 std::stringstream buffer;
89 buffer << t.rdbuf();
90
91 BOOST_CHECK_EQUAL(buffer.str(),
92 "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n"
Alexander Afanasyev6a720c12015-08-21 12:50:13 -070093 "0.0417424 1 0 0 LastDelay 0.0417424 41742.4 1 2\n"
94 "0.0417424 1 0 0 FullDelay 0.0417424 41742.4 1 2\n"
95 "2 2 0 0 LastDelay 0 0 1 0\n"
96 "2 2 0 0 FullDelay 0 0 1 0\n"
97 "3.02087 2 0 1 LastDelay 0.0208712 20871.2 1 1\n"
98 "3.02087 2 0 1 FullDelay 0.0208712 20871.2 1 1\n");
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -070099}
100
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800101BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(InstallNodeContainer, 1);
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700102BOOST_AUTO_TEST_CASE(InstallNodeContainer)
103{
104 NodeContainer nodes;
105 nodes.Add(getNode("1"));
106
107 AppDelayTracer::Install(nodes, TEST_TRACE.string());
108
109 Simulator::Stop(Seconds(4));
110 Simulator::Run();
111
112 AppDelayTracer::Destroy(); // to force log to be written
113
114 std::ifstream t(TEST_TRACE.string().c_str());
115 std::stringstream buffer;
116 buffer << t.rdbuf();
117
118 BOOST_CHECK_EQUAL(buffer.str(),
119 "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n"
Alexander Afanasyev6a720c12015-08-21 12:50:13 -0700120 "0.0417424 1 0 0 LastDelay 0.0417424 41742.4 1 2\n"
121 "0.0417424 1 0 0 FullDelay 0.0417424 41742.4 1 2\n");
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700122}
123
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800124BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(InstallNode, 1);
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700125BOOST_AUTO_TEST_CASE(InstallNode)
126{
127 AppDelayTracer::Install(getNode("2"), TEST_TRACE.string());
128
129 Simulator::Stop(Seconds(4));
130 Simulator::Run();
131
132 AppDelayTracer::Destroy(); // to force log to be written
133
134 std::ifstream t(TEST_TRACE.string().c_str());
135 std::stringstream buffer;
136 buffer << t.rdbuf();
137
138 BOOST_CHECK_EQUAL(buffer.str(),
139 "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n"
Alexander Afanasyev6a720c12015-08-21 12:50:13 -0700140 "2 2 0 0 LastDelay 0 0 1 0\n"
141 "2 2 0 0 FullDelay 0 0 1 0\n"
142 "3.02087 2 0 1 LastDelay 0.0208712 20871.2 1 1\n"
143 "3.02087 2 0 1 FullDelay 0.0208712 20871.2 1 1\n");
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700144}
145
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800146BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(InstallNodeDumpStream, 1);
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700147BOOST_AUTO_TEST_CASE(InstallNodeDumpStream)
148{
149 auto output = make_shared<boost::test_tools::output_test_stream>();
150 Ptr<AppDelayTracer> tracer = AppDelayTracer::Install(getNode("2"), output);
151
152 Simulator::Stop(Seconds(4));
153 Simulator::Run();
154
155 tracer = nullptr; // destroy tracer
156
157 BOOST_CHECK(output->is_equal(
Alexander Afanasyev6a720c12015-08-21 12:50:13 -0700158 "2 2 0 0 LastDelay 0 0 1 0\n"
159 "2 2 0 0 FullDelay 0 0 1 0\n"
160 "3.02087 2 0 1 LastDelay 0.0208712 20871.2 1 1\n"
161 "3.02087 2 0 1 FullDelay 0.0208712 20871.2 1 1\n"));
Alexander Afanasyev18d8bc92015-08-13 18:26:40 -0700162}
163
164BOOST_AUTO_TEST_SUITE_END()
165
166} // namespace ndn
167} // namespace ns3