Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 27 | namespace ns3 { |
| 28 | namespace ndn { |
| 29 | |
| 30 | const boost::filesystem::path TEST_TRACE = boost::filesystem::path(TEST_CONFIG_PATH) / "trace.txt"; |
| 31 | |
| 32 | class AppDelayTracerFixture : public ScenarioHelperWithCleanupFixture |
| 33 | { |
| 34 | public: |
| 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")); |
Spyridon Mastorakis | f98a341 | 2017-10-30 11:47:58 -0700 | [diff] [blame] | 42 | Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20)); |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 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 | |
| 75 | BOOST_FIXTURE_TEST_SUITE(UtilsTracersNdnAppDelayTracer, AppDelayTracerFixture) |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(InstallAll) |
| 78 | { |
| 79 | AppDelayTracer::InstallAll(TEST_TRACE.string()); |
| 80 | |
| 81 | Simulator::Stop(Seconds(4)); |
| 82 | Simulator::Run(); |
| 83 | |
| 84 | AppDelayTracer::Destroy(); // to force log to be written |
| 85 | |
| 86 | std::ifstream t(TEST_TRACE.string().c_str()); |
| 87 | std::stringstream buffer; |
| 88 | buffer << t.rdbuf(); |
| 89 | |
| 90 | BOOST_CHECK_EQUAL(buffer.str(), |
| 91 | "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n" |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame^] | 92 | "0.0417664 1 0 0 LastDelay 0.0417664 41766.4 1 2\n" |
| 93 | "0.0417664 1 0 0 FullDelay 0.0417664 41766.4 1 2\n" |
Alexander Afanasyev | 6a720c1 | 2015-08-21 12:50:13 -0700 | [diff] [blame] | 94 | "2 2 0 0 LastDelay 0 0 1 0\n" |
| 95 | "2 2 0 0 FullDelay 0 0 1 0\n" |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame^] | 96 | "3.02088 2 0 1 LastDelay 0.0208832 20883.2 1 1\n" |
| 97 | "3.02088 2 0 1 FullDelay 0.0208832 20883.2 1 1\n"); |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | BOOST_AUTO_TEST_CASE(InstallNodeContainer) |
| 101 | { |
| 102 | NodeContainer nodes; |
| 103 | nodes.Add(getNode("1")); |
| 104 | |
| 105 | AppDelayTracer::Install(nodes, TEST_TRACE.string()); |
| 106 | |
| 107 | Simulator::Stop(Seconds(4)); |
| 108 | Simulator::Run(); |
| 109 | |
| 110 | AppDelayTracer::Destroy(); // to force log to be written |
| 111 | |
| 112 | std::ifstream t(TEST_TRACE.string().c_str()); |
| 113 | std::stringstream buffer; |
| 114 | buffer << t.rdbuf(); |
| 115 | |
| 116 | BOOST_CHECK_EQUAL(buffer.str(), |
| 117 | "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n" |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame^] | 118 | "0.0417664 1 0 0 LastDelay 0.0417664 41766.4 1 2\n" |
| 119 | "0.0417664 1 0 0 FullDelay 0.0417664 41766.4 1 2\n"); |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | BOOST_AUTO_TEST_CASE(InstallNode) |
| 123 | { |
| 124 | AppDelayTracer::Install(getNode("2"), TEST_TRACE.string()); |
| 125 | |
| 126 | Simulator::Stop(Seconds(4)); |
| 127 | Simulator::Run(); |
| 128 | |
| 129 | AppDelayTracer::Destroy(); // to force log to be written |
| 130 | |
| 131 | std::ifstream t(TEST_TRACE.string().c_str()); |
| 132 | std::stringstream buffer; |
| 133 | buffer << t.rdbuf(); |
| 134 | |
| 135 | BOOST_CHECK_EQUAL(buffer.str(), |
| 136 | "Time Node AppId SeqNo Type DelayS DelayUS RetxCount HopCount\n" |
Alexander Afanasyev | 6a720c1 | 2015-08-21 12:50:13 -0700 | [diff] [blame] | 137 | "2 2 0 0 LastDelay 0 0 1 0\n" |
| 138 | "2 2 0 0 FullDelay 0 0 1 0\n" |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame^] | 139 | "3.02088 2 0 1 LastDelay 0.0208832 20883.2 1 1\n" |
| 140 | "3.02088 2 0 1 FullDelay 0.0208832 20883.2 1 1\n"); |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | BOOST_AUTO_TEST_CASE(InstallNodeDumpStream) |
| 144 | { |
| 145 | auto output = make_shared<boost::test_tools::output_test_stream>(); |
| 146 | Ptr<AppDelayTracer> tracer = AppDelayTracer::Install(getNode("2"), output); |
| 147 | |
| 148 | Simulator::Stop(Seconds(4)); |
| 149 | Simulator::Run(); |
| 150 | |
| 151 | tracer = nullptr; // destroy tracer |
| 152 | |
| 153 | BOOST_CHECK(output->is_equal( |
Alexander Afanasyev | 6a720c1 | 2015-08-21 12:50:13 -0700 | [diff] [blame] | 154 | "2 2 0 0 LastDelay 0 0 1 0\n" |
| 155 | "2 2 0 0 FullDelay 0 0 1 0\n" |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame^] | 156 | "3.02088 2 0 1 LastDelay 0.0208832 20883.2 1 1\n" |
| 157 | "3.02088 2 0 1 FullDelay 0.0208832 20883.2 1 1\n")); |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | BOOST_AUTO_TEST_SUITE_END() |
| 161 | |
| 162 | } // namespace ndn |
| 163 | } // namespace ns3 |