blob: 6abcf435e53d2b9c7ebef1dd3c25ccac7521a8a1 [file] [log] [blame]
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -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 "helper/ndn-link-control-helper.hpp"
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070021#include "NFD/core/scheduler.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070022
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070023#include "../tests-common.hpp"
24
25namespace ns3 {
26namespace ndn {
27
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070028BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, ScenarioHelperWithCleanupFixture)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070029
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070030BOOST_AUTO_TEST_CASE(TwoNodeTopology)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070031{
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070032 // setting default parameters for PointToPoint links and channels
33 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
34 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
Spyridon Mastorakisf98a3412017-10-30 11:47:58 -070035 Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20));
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070036
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070037 createTopology({
38 {"1", "2"},
39 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070040
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070041 addRoutes({
42 {"1", "2", "/prefix", 1},
43 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070044
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070045 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 Gaodd516fe2015-04-23 04:18:24 -070053
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070054 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 Gaodd516fe2015-04-23 04:18:24 -070056
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070057 nfd::scheduler::schedule(time::milliseconds(5200), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070058 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 6);
59 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 6);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070060 });
61
62 nfd::scheduler::schedule(time::milliseconds(10200), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070063 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 6);
64 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 6);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070065 });
66 nfd::scheduler::schedule(time::milliseconds(15100), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070067 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 11);
68 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 11);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070069 });
70
71 Simulator::Stop(Seconds(15.2));
72 Simulator::Run();
73}
74
75BOOST_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"));
Spyridon Mastorakisf98a3412017-10-30 11:47:58 -070080 Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20));
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070081
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070082 // 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 Mastorakisf94998b2015-07-24 23:10:23 -070095
Alexander Afanasyev9eff6382015-08-13 16:54:35 -070096 createTopology({
97 {"0", "1"},
98 {"1", "2"}, {"1", "3"},
99 {"2", "4"}, {"3", "4"},
100 {"4", "5"},
101 });
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700102
Alexander Afanasyev9eff6382015-08-13 16:54:35 -0700103 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 Mastorakisf94998b2015-07-24 23:10:23 -0700109
110 // Choosing forwarding strategy
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700111 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast");
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700112
Alexander Afanasyev9eff6382015-08-13 16:54:35 -0700113 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 Mastorakisf94998b2015-07-24 23:10:23 -0700121
122 nfd::scheduler::schedule(time::milliseconds(10100), [&] {
Alexander Afanasyev9eff6382015-08-13 16:54:35 -0700123 LinkControlHelper::FailLink(getNode("1"), getNode("2"));
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700124 });
125
126 // just before link failure
127 nfd::scheduler::schedule(time::milliseconds(10050), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700128 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 11);
129 BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 11);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700130 });
131
132 // just before link recovery
133 nfd::scheduler::schedule(time::milliseconds(20050), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700134 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 11);
135 BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 21);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700136 });
137
138 nfd::scheduler::schedule(time::milliseconds(20100), [&] {
Alexander Afanasyev9eff6382015-08-13 16:54:35 -0700139 LinkControlHelper::UpLink(getNode("1"), getNode("2"));
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700140 });
141
142 nfd::scheduler::schedule(time::milliseconds(30050), [&] {
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700143 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 21);
144 BOOST_CHECK_EQUAL(getFace("3", "1")->getCounters().nInInterests, 31);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700145 });
146
147 Simulator::Stop(Seconds(30.1));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700148 Simulator::Run();
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700149}
150
151BOOST_AUTO_TEST_SUITE_END()
152
153} // namespace ndn
154} // namespace ns3