blob: af9c055d303d1b704aeb44d5e85ae3f00d57d157 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-stack-helper.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080021
22#include "ns3/log.h"
23#include "ns3/names.h"
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080024#include "ns3/string.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080025#include "ns3/point-to-point-net-device.h"
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -070026#include "ns3/point-to-point-channel.h"
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -070027#include "ns3/node-list.h"
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050028#include "ns3/simulator.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080029
Alexander Afanasyev6995bb72019-02-23 15:53:26 -050030#if HAVE_NS3_VISUALIZER
31#include "../../visualizer/model/visual-simulator-impl.h"
32#endif // HAVE_NS3_VISUALIZER
33
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080034#include "model/ndn-l3-protocol.hpp"
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080035#include "model/ndn-net-device-transport.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080036#include "utils/ndn-time.hpp"
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080037#include "utils/dummy-keychain.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070038
39#include <limits>
40#include <map>
Alexander Afanasyevb7626842012-01-12 13:43:33 -080041#include <boost/lexical_cast.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080042
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080043#include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp"
spirosmastorakis34eed982016-11-02 15:20:50 -070044#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp"
45#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp"
46
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047NS_LOG_COMPONENT_DEFINE("ndn.StackHelper");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070048
49namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070050namespace ndn {
Alexander Afanasyev122f3782013-02-02 00:04:40 -080051
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052StackHelper::StackHelper()
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050053 : m_isForwarderStatusManagerDisabled(false)
spirosmastorakis0df15ba2015-11-14 08:46:24 -080054 , m_isStrategyChoiceManagerDisabled(false)
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070055 , m_needSetDefaultRoutes(false)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070056{
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080057 setCustomNdnCxxClocks();
58
spirosmastorakis34eed982016-11-02 15:20:50 -070059 m_csPolicies.insert({"nfd::cs::lru", [] { return make_unique<nfd::cs::LruPolicy>(); }});
60 m_csPolicies.insert({"nfd::cs::priority_fifo", [] () { return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
61
62 m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"];
63
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080065
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 m_netDeviceCallbacks.push_back(
67 std::make_pair(PointToPointNetDevice::GetTypeId(),
68 MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this)));
Alexander Afanasyev122f3782013-02-02 00:04:40 -080069 // default callback will be fired if non of others callbacks fit or did the job
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070070}
Alexander Afanasyev122f3782013-02-02 00:04:40 -080071
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072StackHelper::~StackHelper()
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073{
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070074}
75
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080076KeyChain&
77StackHelper::getKeyChain()
78{
Alexander Afanasyevdf26b5a2015-01-15 23:30:56 -080079 static ::ndn::KeyChain keyChain("pib-dummy", "tpm-dummy");
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080080 return keyChain;
81}
82
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070083void
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080084StackHelper::setCustomNdnCxxClocks()
85{
86 ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(),
87 make_shared<ns3::ndn::time::CustomSystemClock>());
88}
89
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080090void
91StackHelper::SetDefaultRoutes(bool needSet)
92{
93 NS_LOG_FUNCTION(this << needSet);
94 m_needSetDefaultRoutes = needSet;
95}
96
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080097void
98StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1,
99 const std::string& attr2, const std::string& value2,
100 const std::string& attr3, const std::string& value3,
101 const std::string& attr4, const std::string& value4)
102{
103 if (attr1 != "")
104 m_ndnFactory.Set(attr1, StringValue(value1));
105 if (attr2 != "")
106 m_ndnFactory.Set(attr2, StringValue(value2));
107 if (attr3 != "")
108 m_ndnFactory.Set(attr3, StringValue(value3));
109 if (attr4 != "")
110 m_ndnFactory.Set(attr4, StringValue(value4));
111}
112
113void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800114StackHelper::setCsSize(size_t maxSize)
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800115{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800116 m_maxCsSize = maxSize;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800117}
118
spirosmastorakis34eed982016-11-02 15:20:50 -0700119void
120StackHelper::setPolicy(const std::string& policy)
121{
122 auto found = m_csPolicies.find(policy);
123 if (found != m_csPolicies.end()) {
124 m_csPolicyCreationFunc = found->second;
125 }
126 else {
127 NS_FATAL_ERROR("Cache replacement policy " << policy << " not found");
128 NS_LOG_DEBUG("Available cache replacement policies: ");
129 for (auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
130 NS_LOG_DEBUG(" " << it->first);
131 }
132 }
133}
134
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500135void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800136StackHelper::Install(const NodeContainer& c) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700137{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500139 Install(*i);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140 }
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700141}
142
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500143void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144StackHelper::InstallAll() const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700145{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500146 Install(NodeContainer::GetGlobal());
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700147}
148
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500149void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800150StackHelper::Install(Ptr<Node> node) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700151{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800152 if (node->GetObject<L3Protocol>() != 0) {
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700153 NS_FATAL_ERROR("Cannot re-install NDN stack on node "
154 << node->GetId());
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500155 return;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800156 }
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500157 Simulator::ScheduleWithContext(node->GetId(), Seconds(0), &StackHelper::doInstall, this, node);
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500158 ProcessWarmupEvents();
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500159}
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700160
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500161void
162StackHelper::doInstall(Ptr<Node> node) const
163{
164 // async install to ensure proper context
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800165 Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800166
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700167 if (m_isForwarderStatusManagerDisabled) {
168 ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800169 }
170
171 if (m_isStrategyChoiceManagerDisabled) {
172 ndn->getConfig().put("ndnSIM.disable_strategy_choice_manager", true);
173 }
174
Alexander Afanasyev25e4d8f2019-07-29 13:44:04 -0400175 ndn->getConfig().put("tables.cs_max_packets", m_maxCsSize);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800176
Alexander Afanasyev8fbcc642019-07-27 16:53:37 -0400177 ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800178
179 // Aggregate L3Protocol on node (must be after setting ndnSIM CS)
180 node->AggregateObject(ndn);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800181
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800182 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
183 Ptr<NetDevice> device = node->GetDevice(index);
184 // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed,
185 // Normally, ndnSIM works without IP stack, so no reason to check
186 // if (DynamicCast<LoopbackNetDevice> (device) != 0)
187 // continue; // don't create face for a LoopbackNetDevice
Alexander Afanasyev11453142011-11-25 16:13:33 -0800188
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500189 this->createAndRegisterFace(node, ndn, device);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800190 }
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700191}
192
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800193void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700194StackHelper::AddFaceCreateCallback(TypeId netDeviceType,
195 StackHelper::FaceCreateCallback callback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800196{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800197 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800198}
199
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700200void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700201StackHelper::UpdateFaceCreateCallback(TypeId netDeviceType,
202 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700203{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800204 for (auto& i : m_netDeviceCallbacks) {
205 if (i.first == netDeviceType) {
206 i.second = callback;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800207 return;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700208 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800209 }
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700210}
211
212void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700213StackHelper::RemoveFaceCreateCallback(TypeId netDeviceType,
214 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700215{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700216 m_netDeviceCallbacks.remove_if([&] (const std::pair<TypeId, FaceCreateCallback>& i) {
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800217 return (i.first == netDeviceType);
218 });
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700219}
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800220
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700221std::string
222constructFaceUri(Ptr<NetDevice> netDevice)
223{
224 std::string uri = "netdev://";
225 Address address = netDevice->GetAddress();
226 if (Mac48Address::IsMatchingType(address)) {
227 uri += "[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) + "]";
228 }
229
230 return uri;
231}
232
233
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700234shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800235StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
236 Ptr<NetDevice> netDevice) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800237{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700238 NS_LOG_DEBUG("Creating default Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800239
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800240 // Create an ndnSIM-specific transport instance
241 ::nfd::face::GenericLinkService::Options opts;
242 opts.allowFragmentation = true;
243 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700244 opts.allowCongestionMarking = true;
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800245
246 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
247
248 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
249 constructFaceUri(netDevice),
250 "netdev://[ff:ff:ff:ff:ff:ff]");
251
252 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700253 face->setMetric(1);
254
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800255 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700256 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800257 << face->getLocalUri());
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800258
259 return face;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800260}
261
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700262shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800263StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
264 Ptr<NetDevice> device) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800265{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700266 NS_LOG_DEBUG("Creating point-to-point Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800267
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700268 Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device);
269 NS_ASSERT(netDevice != nullptr);
270
271 // access the other end of the link
272 Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel());
273 NS_ASSERT(channel != nullptr);
274
275 Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0);
276 if (remoteNetDevice->GetNode() == node)
277 remoteNetDevice = channel->GetDevice(1);
278
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800279 // Create an ndnSIM-specific transport instance
280 ::nfd::face::GenericLinkService::Options opts;
281 opts.allowFragmentation = true;
282 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700283 opts.allowCongestionMarking = true;
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700284
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800285 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
286
287 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
288 constructFaceUri(netDevice),
289 constructFaceUri(remoteNetDevice));
290
291 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700292 face->setMetric(1);
293
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800294 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700295 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800296 << face->getLocalUri());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800297
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800298 return face;
299}
300
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500301void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800302StackHelper::Install(const std::string& nodeName) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700303{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800304 Ptr<Node> node = Names::Find<Node>(nodeName);
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500305 Install(node);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700306}
307
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700308void
309StackHelper::Update(Ptr<Node> node)
310{
311 if (node->GetObject<L3Protocol>() == 0) {
312 Install(node);
313 return;
314 }
315
316 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
317
318 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
319
320 Ptr<NetDevice> device = node->GetDevice(index);
321
322 if (ndn->getFaceByNetDevice(device) == nullptr) {
323 this->createAndRegisterFace(node, ndn, device);
324 }
325 }
326}
327
328void
329StackHelper::Update(const NodeContainer& c)
330{
331 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
332 Update(*i);
333 }
334}
335
336void
337StackHelper::Update(const std::string& nodeName)
338{
339 Ptr<Node> node = Names::Find<Node>(nodeName);
340 Update(node);
341}
342
343void
344StackHelper::UpdateAll()
345{
346 Update(NodeContainer::GetGlobal());
347}
348
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700349shared_ptr<Face>
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700350StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const
351{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700352 shared_ptr<Face> face;
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700353
354 for (const auto& item : m_netDeviceCallbacks) {
355 if (device->GetInstanceTypeId() == item.first ||
356 device->GetInstanceTypeId().IsChildOf(item.first)) {
357 face = item.second(node, ndn, device);
358 if (face != 0)
359 break;
360 }
361 }
362
363 if (face == 0) {
364 face = DefaultNetDeviceCallback(node, ndn, device);
365 }
366
367 if (m_needSetDefaultRoutes) {
368 // default route with lowest priority possible
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500369 FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700370 }
371 return face;
372}
373
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800374void
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800375StackHelper::disableStrategyChoiceManager()
376{
377 m_isStrategyChoiceManagerDisabled = true;
378}
379
380void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700381StackHelper::disableForwarderStatusManager()
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800382{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700383 m_isForwarderStatusManagerDisabled = true;
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800384}
385
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -0700386void
387StackHelper::SetLinkDelayAsFaceMetric()
388{
389 for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i) {
390 auto ndn = NodeList::GetNode(i)->GetObject<L3Protocol>();
391 if (ndn == nullptr)
392 continue;
393
Alexander Afanasyev59090db2020-02-21 16:37:43 -0500394 for (auto& face : ndn->getFaceTable()) {
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -0700395 auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
396 if (transport == nullptr)
397 continue;
398 auto p2p = dynamic_cast<PointToPointChannel*>(&(*(transport->GetNetDevice()->GetChannel())));
399 TimeValue currentDelay;
400 p2p->GetAttribute("Delay", currentDelay);
401 face.setMetric((currentDelay.Get().ToDouble(Time::S)) * 1000);
402
403 std::cout << "Node " << i << ": Face " << face.getId()
404 << " with metric " << face.getMetric() << "\n";
405 }
406 }
407}
408
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500409void
410StackHelper::ProcessWarmupEvents()
411{
412 Simulator::Stop(Seconds(0));
413#if HAVE_NS3_VISUALIZER
414 auto impl = DynamicCast<VisualSimulatorImpl>(Simulator::GetImplementation());
415 if (impl != nullptr) {
416 impl->RunRealSimulator();
417 }
418 else {
419 Simulator::Run();
420 }
421#else
422 Simulator::Run();
423#endif // HAVE_NS3_VISUALIZER
424}
425
426
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700427} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700428} // namespace ns3