blob: 736987d391288a4cc653a00cd8459d8fd97a9a25 [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"
21#include "model/ndn-l3-protocol.hpp"
22#include "model/ndn-net-device-face.hpp"
23#include "model/ndn-app-face.hpp"
24#include "NFD/daemon/fw/forwarder.hpp"
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070025#include "NFD/core/scheduler.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070026
27#include <ndn-cxx/management/nfd-face-status.hpp>
28
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070029#include "ns3/core-module.h"
30#include "ns3/network-module.h"
31#include "ns3/point-to-point-module.h"
32#include "ns3/ndnSIM-module.h"
33
34#include "../tests-common.hpp"
35
36namespace ns3 {
37namespace ndn {
38
39BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, CleanupFixture)
40
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070041BOOST_AUTO_TEST_CASE(TwoNodeTopology)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070042{
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070043 // setting default parameters for PointToPoint links and channels
44 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
45 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
46 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
47
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070048 NodeContainer nodes;
49 nodes.Create(2);
50
51 PointToPointHelper p2p;
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070052 auto link0_1 = p2p.Install(nodes.Get(0), nodes.Get(1));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070053
54 StackHelper ndnHelper;
55 ndnHelper.SetDefaultRoutes(true);
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070056 ndnHelper.InstallAll();
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070057
58 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
59
60 consumerHelper.SetPrefix("/prefix");
61 consumerHelper.SetAttribute("Frequency", StringValue("1"));
62 ApplicationContainer consumerAppContainer = consumerHelper.Install(nodes.Get(0));
63
64 AppHelper producerHelper("ns3::ndn::Producer");
65
66 producerHelper.SetPrefix("/prefix");
67 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
68 ApplicationContainer producerAppContainer = producerHelper.Install(nodes.Get(1));
69
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070070 auto netDeviceFace1_0 = nodes.Get(1)->GetObject<L3Protocol>()->getFaceByNetDevice(link0_1.Get(1));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070071
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070072 Simulator::Schedule(Seconds(5.1), ndn::LinkControlHelper::FailLink, nodes.Get(0), nodes.Get(1));
73 Simulator::Schedule(Seconds(10.1), ndn::LinkControlHelper::UpLink, nodes.Get(0), nodes.Get(1));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070074
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -070075 nfd::scheduler::schedule(time::milliseconds(5200), [&] {
76 BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
77 });
78
79 nfd::scheduler::schedule(time::milliseconds(10200), [&] {
80 BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
81 });
82 nfd::scheduler::schedule(time::milliseconds(15100), [&] {
83 BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 11);
84 });
85
86 Simulator::Stop(Seconds(15.2));
87 Simulator::Run();
88}
89
90BOOST_AUTO_TEST_CASE(SixNodeTopology) // Bug #2783
91{
92 // setting default parameters for PointToPoint links and channels
93 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
94 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
95 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
96
97 // Creating nodes
98 NodeContainer nodes;
99 nodes.Create(6);
100
101
102 // Connecting nodes in 6 node topology:
103 //
104 // +---+
105 // +- | 2 | -+
106 // / +---+ \
107 // +---+ / \ +---+
108 // +---+ | | --+ +-- | | +---+
109 // | 0 | ------ | 1 | | 4 | ------ | 5 |
110 // +---+ | | --+ +-- | | +---+
111 // +---+ \ / +---+
112 // \ +---+ /
113 // +- | 3 | -+
114 // +---+
115 PointToPointHelper p2p;
116 p2p.Install(nodes.Get(0), nodes.Get(1));
117 auto link1_2 = p2p.Install(nodes.Get(1), nodes.Get(2));
118 auto link1_3 = p2p.Install(nodes.Get(1), nodes.Get(3));
119 p2p.Install(nodes.Get(2), nodes.Get(4));
120 p2p.Install(nodes.Get(3), nodes.Get(4));
121 p2p.Install(nodes.Get(4), nodes.Get(5));
122
123 // Install NDN stack on all nodes
124 ndn::StackHelper ndnHelper;
125 ndnHelper.SetDefaultRoutes(true);
126 ndnHelper.InstallAll();
127
128 // Choosing forwarding strategy
129 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast");
130
131 // Installing applications
132
133 // Consumer
134 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
135 // Consumer will request /prefix/0, /prefix/1, ...
136 consumerHelper.SetPrefix("/prefix");
137 consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests a second
138 consumerHelper.Install(nodes.Get(0)); // first node
139
140 // Producer
141 ndn::AppHelper producerHelper("ns3::ndn::Producer");
142 // Producer will reply to all requests starting with /prefix
143 producerHelper.SetPrefix("/prefix");
144 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
145 producerHelper.Install(nodes.Get(5)); // last node
146
147 auto netDeviceFace2_1 = nodes.Get(2)->GetObject<L3Protocol>()->getFaceByNetDevice(link1_2.Get(1));
148 auto netDeviceFace3_1 = nodes.Get(3)->GetObject<L3Protocol>()->getFaceByNetDevice(link1_3.Get(1));
149
150 nfd::scheduler::schedule(time::milliseconds(10100), [&] {
151 LinkControlHelper::FailLink(nodes.Get(1), nodes.Get(2));
152 });
153
154 // just before link failure
155 nfd::scheduler::schedule(time::milliseconds(10050), [&] {
156 BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 11);
157 BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 11);
158 });
159
160 // just before link recovery
161 nfd::scheduler::schedule(time::milliseconds(20050), [&] {
162 BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 11);
163 BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 21);
164 });
165
166 nfd::scheduler::schedule(time::milliseconds(20100), [&] {
167 LinkControlHelper::UpLink(nodes.Get(1), nodes.Get(2));
168 });
169
170 nfd::scheduler::schedule(time::milliseconds(30050), [&] {
171 BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 21);
172 BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 31);
173 });
174
175 Simulator::Stop(Seconds(30.1));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700176
177 Simulator::Run();
Spyridon Mastorakisf94998b2015-07-24 23:10:23 -0700178 Simulator::Destroy();
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700179}
180
181BOOST_AUTO_TEST_SUITE_END()
182
183} // namespace ndn
184} // namespace ns3