blob: 863b191e2a5a321eb99fd5e890e4880495a941bd [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"
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080038#include "model/cs/ndn-content-store.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070039
40#include <limits>
41#include <map>
Alexander Afanasyevb7626842012-01-12 13:43:33 -080042#include <boost/lexical_cast.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080043
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080044#include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp"
spirosmastorakis34eed982016-11-02 15:20:50 -070045#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp"
46#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp"
47
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048NS_LOG_COMPONENT_DEFINE("ndn.StackHelper");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070049
50namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051namespace ndn {
Alexander Afanasyev122f3782013-02-02 00:04:40 -080052
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053StackHelper::StackHelper()
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050054 : m_isForwarderStatusManagerDisabled(false)
spirosmastorakis0df15ba2015-11-14 08:46:24 -080055 , m_isStrategyChoiceManagerDisabled(false)
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070056 , m_needSetDefaultRoutes(false)
57 , m_maxCsSize(100)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070058{
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080059 setCustomNdnCxxClocks();
60
spirosmastorakis34eed982016-11-02 15:20:50 -070061 m_csPolicies.insert({"nfd::cs::lru", [] { return make_unique<nfd::cs::LruPolicy>(); }});
62 m_csPolicies.insert({"nfd::cs::priority_fifo", [] () { return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
63
64 m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"];
65
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol");
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080067 m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080068
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 m_netDeviceCallbacks.push_back(
70 std::make_pair(PointToPointNetDevice::GetTypeId(),
71 MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this)));
Alexander Afanasyev122f3782013-02-02 00:04:40 -080072 // default callback will be fired if non of others callbacks fit or did the job
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070073}
Alexander Afanasyev122f3782013-02-02 00:04:40 -080074
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075StackHelper::~StackHelper()
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070076{
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070077}
78
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080079KeyChain&
80StackHelper::getKeyChain()
81{
Alexander Afanasyevdf26b5a2015-01-15 23:30:56 -080082 static ::ndn::KeyChain keyChain("pib-dummy", "tpm-dummy");
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080083 return keyChain;
84}
85
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070086void
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080087StackHelper::setCustomNdnCxxClocks()
88{
89 ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(),
90 make_shared<ns3::ndn::time::CustomSystemClock>());
91}
92
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080093void
94StackHelper::SetDefaultRoutes(bool needSet)
95{
96 NS_LOG_FUNCTION(this << needSet);
97 m_needSetDefaultRoutes = needSet;
98}
99
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800100void
101StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1,
102 const std::string& attr2, const std::string& value2,
103 const std::string& attr3, const std::string& value3,
104 const std::string& attr4, const std::string& value4)
105{
106 if (attr1 != "")
107 m_ndnFactory.Set(attr1, StringValue(value1));
108 if (attr2 != "")
109 m_ndnFactory.Set(attr2, StringValue(value2));
110 if (attr3 != "")
111 m_ndnFactory.Set(attr3, StringValue(value3));
112 if (attr4 != "")
113 m_ndnFactory.Set(attr4, StringValue(value4));
114}
115
116void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800117StackHelper::SetOldContentStore(const std::string& contentStore, const std::string& attr1,
118 const std::string& value1, const std::string& attr2,
119 const std::string& value2, const std::string& attr3,
120 const std::string& value3, const std::string& attr4,
121 const std::string& value4)
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800122{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800123 m_maxCsSize = 0;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800124
125 m_contentStoreFactory.SetTypeId(contentStore);
126 if (attr1 != "")
127 m_contentStoreFactory.Set(attr1, StringValue(value1));
128 if (attr2 != "")
129 m_contentStoreFactory.Set(attr2, StringValue(value2));
130 if (attr3 != "")
131 m_contentStoreFactory.Set(attr3, StringValue(value3));
132 if (attr4 != "")
133 m_contentStoreFactory.Set(attr4, StringValue(value4));
134}
135
136void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800137StackHelper::setCsSize(size_t maxSize)
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800138{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800139 m_maxCsSize = maxSize;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800140}
141
spirosmastorakis34eed982016-11-02 15:20:50 -0700142void
143StackHelper::setPolicy(const std::string& policy)
144{
145 auto found = m_csPolicies.find(policy);
146 if (found != m_csPolicies.end()) {
147 m_csPolicyCreationFunc = found->second;
148 }
149 else {
150 NS_FATAL_ERROR("Cache replacement policy " << policy << " not found");
151 NS_LOG_DEBUG("Available cache replacement policies: ");
152 for (auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
153 NS_LOG_DEBUG(" " << it->first);
154 }
155 }
156}
157
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500158void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159StackHelper::Install(const NodeContainer& c) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700160{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500162 Install(*i);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163 }
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700164}
165
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500166void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800167StackHelper::InstallAll() const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700168{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500169 Install(NodeContainer::GetGlobal());
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700170}
171
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500172void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173StackHelper::Install(Ptr<Node> node) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700174{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 if (node->GetObject<L3Protocol>() != 0) {
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700176 NS_FATAL_ERROR("Cannot re-install NDN stack on node "
177 << node->GetId());
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500178 return;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800179 }
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500180 Simulator::ScheduleWithContext(node->GetId(), Seconds(0), &StackHelper::doInstall, this, node);
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500181 ProcessWarmupEvents();
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500182}
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700183
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500184void
185StackHelper::doInstall(Ptr<Node> node) const
186{
187 // async install to ensure proper context
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800188 Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800189
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700190 if (m_isForwarderStatusManagerDisabled) {
191 ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800192 }
193
194 if (m_isStrategyChoiceManagerDisabled) {
195 ndn->getConfig().put("ndnSIM.disable_strategy_choice_manager", true);
196 }
197
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800198 ndn->getConfig().put("tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize);
199
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800200 // Create and aggregate content store if NFD's contest store has been disabled
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800201 if (m_maxCsSize == 0) {
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800202 ndn->AggregateObject(m_contentStoreFactory.Create<ContentStore>());
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800203 }
spirosmastorakis34eed982016-11-02 15:20:50 -0700204 // if NFD's CS is enabled, check if a replacement policy has been specified
205 else {
206 ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
207 }
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800208
209 // Aggregate L3Protocol on node (must be after setting ndnSIM CS)
210 node->AggregateObject(ndn);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800211
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800212 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
213 Ptr<NetDevice> device = node->GetDevice(index);
214 // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed,
215 // Normally, ndnSIM works without IP stack, so no reason to check
216 // if (DynamicCast<LoopbackNetDevice> (device) != 0)
217 // continue; // don't create face for a LoopbackNetDevice
Alexander Afanasyev11453142011-11-25 16:13:33 -0800218
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500219 this->createAndRegisterFace(node, ndn, device);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800220 }
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700221}
222
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800223void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700224StackHelper::AddFaceCreateCallback(TypeId netDeviceType,
225 StackHelper::FaceCreateCallback callback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800226{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800227 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800228}
229
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700230void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700231StackHelper::UpdateFaceCreateCallback(TypeId netDeviceType,
232 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700233{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800234 for (auto& i : m_netDeviceCallbacks) {
235 if (i.first == netDeviceType) {
236 i.second = callback;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800237 return;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700238 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800239 }
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700240}
241
242void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700243StackHelper::RemoveFaceCreateCallback(TypeId netDeviceType,
244 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700245{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700246 m_netDeviceCallbacks.remove_if([&] (const std::pair<TypeId, FaceCreateCallback>& i) {
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800247 return (i.first == netDeviceType);
248 });
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700249}
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800250
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700251std::string
252constructFaceUri(Ptr<NetDevice> netDevice)
253{
254 std::string uri = "netdev://";
255 Address address = netDevice->GetAddress();
256 if (Mac48Address::IsMatchingType(address)) {
257 uri += "[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) + "]";
258 }
259
260 return uri;
261}
262
263
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700264shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800265StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
266 Ptr<NetDevice> netDevice) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800267{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700268 NS_LOG_DEBUG("Creating default Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800269
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800270 // Create an ndnSIM-specific transport instance
271 ::nfd::face::GenericLinkService::Options opts;
272 opts.allowFragmentation = true;
273 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700274 opts.allowCongestionMarking = true;
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800275
276 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
277
278 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
279 constructFaceUri(netDevice),
280 "netdev://[ff:ff:ff:ff:ff:ff]");
281
282 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700283 face->setMetric(1);
284
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800285 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700286 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800287 << face->getLocalUri());
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800288
289 return face;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800290}
291
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700292shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800293StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
294 Ptr<NetDevice> device) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800295{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700296 NS_LOG_DEBUG("Creating point-to-point Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800297
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700298 Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device);
299 NS_ASSERT(netDevice != nullptr);
300
301 // access the other end of the link
302 Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel());
303 NS_ASSERT(channel != nullptr);
304
305 Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0);
306 if (remoteNetDevice->GetNode() == node)
307 remoteNetDevice = channel->GetDevice(1);
308
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800309 // Create an ndnSIM-specific transport instance
310 ::nfd::face::GenericLinkService::Options opts;
311 opts.allowFragmentation = true;
312 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700313 opts.allowCongestionMarking = true;
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700314
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800315 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
316
317 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
318 constructFaceUri(netDevice),
319 constructFaceUri(remoteNetDevice));
320
321 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700322 face->setMetric(1);
323
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800324 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700325 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800326 << face->getLocalUri());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800327
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800328 return face;
329}
330
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500331void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800332StackHelper::Install(const std::string& nodeName) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700333{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800334 Ptr<Node> node = Names::Find<Node>(nodeName);
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500335 Install(node);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700336}
337
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700338void
339StackHelper::Update(Ptr<Node> node)
340{
341 if (node->GetObject<L3Protocol>() == 0) {
342 Install(node);
343 return;
344 }
345
346 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
347
348 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
349
350 Ptr<NetDevice> device = node->GetDevice(index);
351
352 if (ndn->getFaceByNetDevice(device) == nullptr) {
353 this->createAndRegisterFace(node, ndn, device);
354 }
355 }
356}
357
358void
359StackHelper::Update(const NodeContainer& c)
360{
361 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
362 Update(*i);
363 }
364}
365
366void
367StackHelper::Update(const std::string& nodeName)
368{
369 Ptr<Node> node = Names::Find<Node>(nodeName);
370 Update(node);
371}
372
373void
374StackHelper::UpdateAll()
375{
376 Update(NodeContainer::GetGlobal());
377}
378
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700379shared_ptr<Face>
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700380StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const
381{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700382 shared_ptr<Face> face;
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700383
384 for (const auto& item : m_netDeviceCallbacks) {
385 if (device->GetInstanceTypeId() == item.first ||
386 device->GetInstanceTypeId().IsChildOf(item.first)) {
387 face = item.second(node, ndn, device);
388 if (face != 0)
389 break;
390 }
391 }
392
393 if (face == 0) {
394 face = DefaultNetDeviceCallback(node, ndn, device);
395 }
396
397 if (m_needSetDefaultRoutes) {
398 // default route with lowest priority possible
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500399 FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700400 }
401 return face;
402}
403
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800404void
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800405StackHelper::disableStrategyChoiceManager()
406{
407 m_isStrategyChoiceManagerDisabled = true;
408}
409
410void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700411StackHelper::disableForwarderStatusManager()
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800412{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700413 m_isForwarderStatusManagerDisabled = true;
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800414}
415
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -0700416void
417StackHelper::SetLinkDelayAsFaceMetric()
418{
419 for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i) {
420 auto ndn = NodeList::GetNode(i)->GetObject<L3Protocol>();
421 if (ndn == nullptr)
422 continue;
423
424 for (auto& face : ndn->getForwarder()->getFaceTable()) {
425 auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
426 if (transport == nullptr)
427 continue;
428 auto p2p = dynamic_cast<PointToPointChannel*>(&(*(transport->GetNetDevice()->GetChannel())));
429 TimeValue currentDelay;
430 p2p->GetAttribute("Delay", currentDelay);
431 face.setMetric((currentDelay.Get().ToDouble(Time::S)) * 1000);
432
433 std::cout << "Node " << i << ": Face " << face.getId()
434 << " with metric " << face.getMetric() << "\n";
435 }
436 }
437}
438
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500439void
440StackHelper::ProcessWarmupEvents()
441{
442 Simulator::Stop(Seconds(0));
443#if HAVE_NS3_VISUALIZER
444 auto impl = DynamicCast<VisualSimulatorImpl>(Simulator::GetImplementation());
445 if (impl != nullptr) {
446 impl->RunRealSimulator();
447 }
448 else {
449 Simulator::Run();
450 }
451#else
452 Simulator::Run();
453#endif // HAVE_NS3_VISUALIZER
454}
455
456
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700457} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700458} // namespace ns3