blob: 82dab49b5d682de3a889328f5cac2a74f0921730 [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"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080027
28#include "model/ndn-l3-protocol.hpp"
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080029#include "model/ndn-net-device-transport.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080030#include "utils/ndn-time.hpp"
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080031#include "utils/dummy-keychain.hpp"
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080032#include "model/cs/ndn-content-store.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070033
34#include <limits>
35#include <map>
Alexander Afanasyevb7626842012-01-12 13:43:33 -080036#include <boost/lexical_cast.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080037
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080038#include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp"
spirosmastorakis34eed982016-11-02 15:20:50 -070039#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp"
40#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp"
41
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042NS_LOG_COMPONENT_DEFINE("ndn.StackHelper");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070043
44namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045namespace ndn {
Alexander Afanasyev122f3782013-02-02 00:04:40 -080046
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047StackHelper::StackHelper()
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070048 : m_isRibManagerDisabled(false)
49 // , m_isFaceManagerDisabled(false)
50 , m_isForwarderStatusManagerDisabled(false)
spirosmastorakis0df15ba2015-11-14 08:46:24 -080051 , m_isStrategyChoiceManagerDisabled(false)
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070052 , m_needSetDefaultRoutes(false)
53 , m_maxCsSize(100)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070054{
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080055 setCustomNdnCxxClocks();
56
spirosmastorakis34eed982016-11-02 15:20:50 -070057 m_csPolicies.insert({"nfd::cs::lru", [] { return make_unique<nfd::cs::LruPolicy>(); }});
58 m_csPolicies.insert({"nfd::cs::priority_fifo", [] () { return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
59
60 m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"];
61
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol");
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080063 m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080064
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 m_netDeviceCallbacks.push_back(
66 std::make_pair(PointToPointNetDevice::GetTypeId(),
67 MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this)));
Alexander Afanasyev122f3782013-02-02 00:04:40 -080068 // default callback will be fired if non of others callbacks fit or did the job
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070069}
Alexander Afanasyev122f3782013-02-02 00:04:40 -080070
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071StackHelper::~StackHelper()
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070072{
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073}
74
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080075KeyChain&
76StackHelper::getKeyChain()
77{
Alexander Afanasyevdf26b5a2015-01-15 23:30:56 -080078 static ::ndn::KeyChain keyChain("pib-dummy", "tpm-dummy");
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080079 return keyChain;
80}
81
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070082void
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -080083StackHelper::setCustomNdnCxxClocks()
84{
85 ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(),
86 make_shared<ns3::ndn::time::CustomSystemClock>());
87}
88
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080089void
90StackHelper::SetDefaultRoutes(bool needSet)
91{
92 NS_LOG_FUNCTION(this << needSet);
93 m_needSetDefaultRoutes = needSet;
94}
95
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080096void
97StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1,
98 const std::string& attr2, const std::string& value2,
99 const std::string& attr3, const std::string& value3,
100 const std::string& attr4, const std::string& value4)
101{
102 if (attr1 != "")
103 m_ndnFactory.Set(attr1, StringValue(value1));
104 if (attr2 != "")
105 m_ndnFactory.Set(attr2, StringValue(value2));
106 if (attr3 != "")
107 m_ndnFactory.Set(attr3, StringValue(value3));
108 if (attr4 != "")
109 m_ndnFactory.Set(attr4, StringValue(value4));
110}
111
112void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800113StackHelper::SetOldContentStore(const std::string& contentStore, const std::string& attr1,
114 const std::string& value1, const std::string& attr2,
115 const std::string& value2, const std::string& attr3,
116 const std::string& value3, const std::string& attr4,
117 const std::string& value4)
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800118{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800119 m_maxCsSize = 0;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800120
121 m_contentStoreFactory.SetTypeId(contentStore);
122 if (attr1 != "")
123 m_contentStoreFactory.Set(attr1, StringValue(value1));
124 if (attr2 != "")
125 m_contentStoreFactory.Set(attr2, StringValue(value2));
126 if (attr3 != "")
127 m_contentStoreFactory.Set(attr3, StringValue(value3));
128 if (attr4 != "")
129 m_contentStoreFactory.Set(attr4, StringValue(value4));
130}
131
132void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800133StackHelper::setCsSize(size_t maxSize)
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800134{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800135 m_maxCsSize = maxSize;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800136}
137
spirosmastorakis34eed982016-11-02 15:20:50 -0700138void
139StackHelper::setPolicy(const std::string& policy)
140{
141 auto found = m_csPolicies.find(policy);
142 if (found != m_csPolicies.end()) {
143 m_csPolicyCreationFunc = found->second;
144 }
145 else {
146 NS_FATAL_ERROR("Cache replacement policy " << policy << " not found");
147 NS_LOG_DEBUG("Available cache replacement policies: ");
148 for (auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
149 NS_LOG_DEBUG(" " << it->first);
150 }
151 }
152}
153
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800155StackHelper::Install(const NodeContainer& c) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700156{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800157 Ptr<FaceContainer> faces = Create<FaceContainer>();
158 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
159 faces->AddAll(Install(*i));
160 }
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700161 return faces;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700162}
163
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700164Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800165StackHelper::InstallAll() const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700166{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800167 return Install(NodeContainer::GetGlobal());
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700168}
169
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700170Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800171StackHelper::Install(Ptr<Node> node) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700172{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173 Ptr<FaceContainer> faces = Create<FaceContainer>();
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800174
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800178 return 0;
179 }
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700180
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800181 Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800182
183 if (m_isRibManagerDisabled) {
184 ndn->getConfig().put("ndnSIM.disable_rib_manager", true);
185 }
186
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700187 // if (m_isFaceManagerDisabled) {
188 // ndn->getConfig().put("ndnSIM.disable_face_manager", true);
189 // }
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800190
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700191 if (m_isForwarderStatusManagerDisabled) {
192 ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800193 }
194
195 if (m_isStrategyChoiceManagerDisabled) {
196 ndn->getConfig().put("ndnSIM.disable_strategy_choice_manager", true);
197 }
198
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800199 ndn->getConfig().put("tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize);
200
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800201 // Create and aggregate content store if NFD's contest store has been disabled
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800202 if (m_maxCsSize == 0) {
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800203 ndn->AggregateObject(m_contentStoreFactory.Create<ContentStore>());
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800204 }
spirosmastorakis34eed982016-11-02 15:20:50 -0700205 // if NFD's CS is enabled, check if a replacement policy has been specified
206 else {
207 ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
208 }
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800209
210 // Aggregate L3Protocol on node (must be after setting ndnSIM CS)
211 node->AggregateObject(ndn);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800212
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800213 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
214 Ptr<NetDevice> device = node->GetDevice(index);
215 // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed,
216 // Normally, ndnSIM works without IP stack, so no reason to check
217 // if (DynamicCast<LoopbackNetDevice> (device) != 0)
218 // continue; // don't create face for a LoopbackNetDevice
Alexander Afanasyev11453142011-11-25 16:13:33 -0800219
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700220 faces->Add(this->createAndRegisterFace(node, ndn, device));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800221 }
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800222
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700223 return faces;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700224}
225
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800226void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700227StackHelper::AddFaceCreateCallback(TypeId netDeviceType,
228 StackHelper::FaceCreateCallback callback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800229{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800230 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800231}
232
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700233void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700234StackHelper::UpdateFaceCreateCallback(TypeId netDeviceType,
235 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700236{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800237 for (auto& i : m_netDeviceCallbacks) {
238 if (i.first == netDeviceType) {
239 i.second = callback;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800240 return;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700241 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800242 }
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700243}
244
245void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700246StackHelper::RemoveFaceCreateCallback(TypeId netDeviceType,
247 FaceCreateCallback callback)
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700248{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700249 m_netDeviceCallbacks.remove_if([&] (const std::pair<TypeId, FaceCreateCallback>& i) {
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800250 return (i.first == netDeviceType);
251 });
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700252}
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800253
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700254std::string
255constructFaceUri(Ptr<NetDevice> netDevice)
256{
257 std::string uri = "netdev://";
258 Address address = netDevice->GetAddress();
259 if (Mac48Address::IsMatchingType(address)) {
260 uri += "[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) + "]";
261 }
262
263 return uri;
264}
265
266
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700267shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800268StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
269 Ptr<NetDevice> netDevice) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800270{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700271 NS_LOG_DEBUG("Creating default Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800272
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800273 // Create an ndnSIM-specific transport instance
274 ::nfd::face::GenericLinkService::Options opts;
275 opts.allowFragmentation = true;
276 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700277 opts.allowCongestionMarking = true;
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800278
279 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
280
281 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
282 constructFaceUri(netDevice),
283 "netdev://[ff:ff:ff:ff:ff:ff]");
284
285 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700286 face->setMetric(1);
287
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800288 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700289 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800290 << face->getLocalUri());
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800291
292 return face;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800293}
294
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700295shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800296StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
297 Ptr<NetDevice> device) const
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800298{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700299 NS_LOG_DEBUG("Creating point-to-point Face on node " << node->GetId());
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800300
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700301 Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device);
302 NS_ASSERT(netDevice != nullptr);
303
304 // access the other end of the link
305 Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel());
306 NS_ASSERT(channel != nullptr);
307
308 Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0);
309 if (remoteNetDevice->GetNode() == node)
310 remoteNetDevice = channel->GetDevice(1);
311
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800312 // Create an ndnSIM-specific transport instance
313 ::nfd::face::GenericLinkService::Options opts;
314 opts.allowFragmentation = true;
315 opts.allowReassembly = true;
schneiderklaus5f5c9922018-07-25 20:35:03 -0700316 opts.allowCongestionMarking = true;
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700317
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800318 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
319
320 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
321 constructFaceUri(netDevice),
322 constructFaceUri(remoteNetDevice));
323
324 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700325 face->setMetric(1);
326
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800327 ndn->addFace(face);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700328 NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800329 << face->getLocalUri());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800330
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800331 return face;
332}
333
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700334Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800335StackHelper::Install(const std::string& nodeName) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700336{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800337 Ptr<Node> node = Names::Find<Node>(nodeName);
338 return Install(node);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700339}
340
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700341void
342StackHelper::Update(Ptr<Node> node)
343{
344 if (node->GetObject<L3Protocol>() == 0) {
345 Install(node);
346 return;
347 }
348
349 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
350
351 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
352
353 Ptr<NetDevice> device = node->GetDevice(index);
354
355 if (ndn->getFaceByNetDevice(device) == nullptr) {
356 this->createAndRegisterFace(node, ndn, device);
357 }
358 }
359}
360
361void
362StackHelper::Update(const NodeContainer& c)
363{
364 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
365 Update(*i);
366 }
367}
368
369void
370StackHelper::Update(const std::string& nodeName)
371{
372 Ptr<Node> node = Names::Find<Node>(nodeName);
373 Update(node);
374}
375
376void
377StackHelper::UpdateAll()
378{
379 Update(NodeContainer::GetGlobal());
380}
381
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700382shared_ptr<Face>
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700383StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const
384{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700385 shared_ptr<Face> face;
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700386
387 for (const auto& item : m_netDeviceCallbacks) {
388 if (device->GetInstanceTypeId() == item.first ||
389 device->GetInstanceTypeId().IsChildOf(item.first)) {
390 face = item.second(node, ndn, device);
391 if (face != 0)
392 break;
393 }
394 }
395
396 if (face == 0) {
397 face = DefaultNetDeviceCallback(node, ndn, device);
398 }
399
400 if (m_needSetDefaultRoutes) {
401 // default route with lowest priority possible
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700402 FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700403 }
404 return face;
405}
406
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800407void
408StackHelper::disableRibManager()
409{
410 m_isRibManagerDisabled = true;
411}
412
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700413// void
414// StackHelper::disableFaceManager()
415// {
416// m_isFaceManagerDisabled = true;
417// }
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800418
419void
420StackHelper::disableStrategyChoiceManager()
421{
422 m_isStrategyChoiceManagerDisabled = true;
423}
424
425void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700426StackHelper::disableForwarderStatusManager()
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800427{
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700428 m_isForwarderStatusManagerDisabled = true;
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800429}
430
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700431} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700432} // namespace ns3