Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -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 "helper/ndn-link-control-helper.hpp" |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 21 | #include "daemon/common/global.hpp" |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 22 | |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 23 | #include "../tests-common.hpp" |
| 24 | |
| 25 | namespace ns3 { |
| 26 | namespace ndn { |
| 27 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 28 | BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, ScenarioHelperWithCleanupFixture) |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 29 | |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE(TwoNodeTopology) |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 31 | { |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 32 | // setting default parameters for PointToPoint links and channels |
| 33 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")); |
| 34 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
Alexander Afanasyev | 77f84c6 | 2018-10-08 13:37:42 -0400 | [diff] [blame] | 35 | Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p")); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 37 | createTopology({ |
| 38 | {"1", "2"}, |
| 39 | }); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 41 | addRoutes({ |
| 42 | {"1", "2", "/prefix", 1}, |
| 43 | }); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 45 | addApps({ |
| 46 | {"1", "ns3::ndn::ConsumerCbr", |
| 47 | {{"Prefix", "/prefix"}, {"Frequency", "1"}}, |
| 48 | "0s", "100s"}, |
| 49 | {"2", "ns3::ndn::Producer", |
| 50 | {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}}, |
| 51 | "0s", "100s"} |
| 52 | }); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 54 | Simulator::Schedule(Seconds(5.1), ndn::LinkControlHelper::FailLink, getNode("1"), getNode("2")); |
| 55 | Simulator::Schedule(Seconds(10.1), ndn::LinkControlHelper::UpLink, getNode("1"), getNode("2")); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 57 | nfd::getScheduler().schedule(time::milliseconds(5200), [&] { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame^] | 58 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 5); |
| 59 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 5); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 60 | }); |
| 61 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 62 | nfd::getScheduler().schedule(time::milliseconds(10200), [&] { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame^] | 63 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 5); |
| 64 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 5); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 65 | }); |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 66 | nfd::getScheduler().schedule(time::milliseconds(15100), [&] { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame^] | 67 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 10); |
| 68 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 10); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 69 | }); |
| 70 | |
| 71 | Simulator::Stop(Seconds(15.2)); |
| 72 | Simulator::Run(); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE(SixNodeTopology) // Bug #2783 |
| 76 | { |
| 77 | // setting default parameters for PointToPoint links and channels |
| 78 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")); |
| 79 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
Alexander Afanasyev | 77f84c6 | 2018-10-08 13:37:42 -0400 | [diff] [blame] | 80 | Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p")); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 82 | // Connecting nodes in 6 node topology: // |
| 83 | // // |
| 84 | // +---+ // |
| 85 | // +- | 2 | -+ // |
| 86 | // / +---+ \ // |
| 87 | // +---+ / \ +---+ // |
| 88 | // +---+ | | --+ +-- | | +---+ // |
| 89 | // | 0 | ------ | 1 | | 4 | ------ | 5 | // |
| 90 | // +---+ | | --+ +-- | | +---+ // |
| 91 | // +---+ \ / +---+ // |
| 92 | // \ +---+ / // |
| 93 | // +- | 3 | -+ // |
| 94 | // +---+ // |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 96 | createTopology({ |
| 97 | {"0", "1"}, |
| 98 | {"1", "2"}, {"1", "3"}, |
| 99 | {"2", "4"}, {"3", "4"}, |
| 100 | {"4", "5"}, |
| 101 | }); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 102 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 103 | addRoutes({ |
| 104 | {"0", "1", "/prefix", 1}, |
| 105 | {"1", "2", "/prefix", 1}, {"1", "3", "/prefix", 1}, |
| 106 | {"2", "4", "/prefix", 1}, {"3", "4", "/prefix", 1}, |
| 107 | {"4", "5", "/prefix", 1}, |
| 108 | }); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 109 | |
| 110 | // Choosing forwarding strategy |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 111 | ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast"); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 112 | |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 113 | addApps({ |
| 114 | {"0", "ns3::ndn::ConsumerCbr", |
| 115 | {{"Prefix", "/prefix"}, {"Frequency", "1"}}, |
| 116 | "0s", "100s"}, |
| 117 | {"5", "ns3::ndn::Producer", |
| 118 | {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}}, |
| 119 | "0s", "100s"} |
| 120 | }); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 122 | nfd::getScheduler().schedule(time::milliseconds(10100), [&] { |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 123 | LinkControlHelper::FailLink(getNode("1"), getNode("2")); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 124 | }); |
| 125 | |
| 126 | // just before link failure |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 127 | nfd::getScheduler().schedule(time::milliseconds(10050), [&] { |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 11); |
| 129 | BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 11); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 130 | }); |
| 131 | |
| 132 | // just before link recovery |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 133 | nfd::getScheduler().schedule(time::milliseconds(20050), [&] { |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 134 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 11); |
| 135 | BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 21); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 136 | }); |
| 137 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 138 | nfd::getScheduler().schedule(time::milliseconds(20100), [&] { |
Alexander Afanasyev | 9eff638 | 2015-08-13 16:54:35 -0700 | [diff] [blame] | 139 | LinkControlHelper::UpLink(getNode("1"), getNode("2")); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 140 | }); |
| 141 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 142 | nfd::getScheduler().schedule(time::milliseconds(30050), [&] { |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 143 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 21); |
| 144 | BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 31); |
Spyridon Mastorakis | f94998b | 2015-07-24 23:10:23 -0700 | [diff] [blame] | 145 | }); |
| 146 | |
| 147 | Simulator::Stop(Seconds(30.1)); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 148 | Simulator::Run(); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | BOOST_AUTO_TEST_SUITE_END() |
| 152 | |
| 153 | } // namespace ndn |
| 154 | } // namespace ns3 |