blob: f7ad619cab2faf5bad7f7e186aab291803f496e9 [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 Afanasyevab1d5602011-08-17 19:17:18 -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 Afanasyevab1d5602011-08-17 19:17:18 -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 Afanasyevab1d5602011-08-17 19:17:18 -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 Afanasyevab1d5602011-08-17 19:17:18 -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 Afanasyev08d984e2011-08-13 19:20:22 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-l3-protocol.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070021
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022#include "ns3/packet.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070023#include "ns3/node.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070024#include "ns3/log.h"
25#include "ns3/callback.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include "ns3/uinteger.h"
27#include "ns3/trace-source-accessor.h"
28#include "ns3/object-vector.h"
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080029#include "ns3/pointer.h"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080030#include "ns3/simulator.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080032#include "ndn-net-device-transport.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080033
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080034#include "../helper/ndn-stack-helper.hpp"
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080035
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080036#include <boost/property_tree/info_parser.hpp>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080038#include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070039#include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
40#include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080041#include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp"
42#include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp"
43#include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050044#include "ns3/ndnSIM/NFD/daemon/mgmt/cs-manager.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070045#include "ns3/ndnSIM/NFD/daemon/mgmt/forwarder-status-manager.hpp"
46// #include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp"
47#include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp"
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -080048#include "ns3/ndnSIM/NFD/daemon/mgmt/command-authenticator.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070049
Alexander Afanasyev11dfcb72019-07-27 17:47:32 -040050#include "ns3/ndnSIM/NFD/daemon/rib/service.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080051
52#include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070053#include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
54
Alexander Afanasyev11dfcb72019-07-27 17:47:32 -040055#include "ns3/ndnSIM/NFD/daemon/common/global.hpp"
56#include "ns3/ndnSIM/NFD/daemon/common/config-file.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070057
58#include <ndn-cxx/mgmt/dispatcher.hpp>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080059
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061
62namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070064
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070066const uint16_t L3Protocol::IP_STACK_PORT = 9695;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070067
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068NS_OBJECT_ENSURE_REGISTERED(L3Protocol);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080070TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071L3Protocol::GetTypeId(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 static TypeId tid =
74 TypeId("ns3::ndn::L3Protocol")
75 .SetGroupName("ndn")
76 .SetParent<Object>()
77 .AddConstructor<L3Protocol>()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080078
79 .AddTraceSource("OutInterests", "OutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070080 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
81 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080082 .AddTraceSource("InInterests", "InInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070083 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
84 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080085
86 ////////////////////////////////////////////////////////////////////
87
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070088 .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData),
89 "ns3::ndn::L3Protocol::DataTraceCallback")
90 .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData),
91 "ns3::ndn::L3Protocol::DataTraceCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080092
93 ////////////////////////////////////////////////////////////////////
94
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080095 .AddTraceSource("OutNack", "OutNack", MakeTraceSourceAccessor(&L3Protocol::m_outNack),
96 "ns3::ndn::L3Protocol::NackTraceCallback")
97 .AddTraceSource("InNack", "InNack", MakeTraceSourceAccessor(&L3Protocol::m_inNack),
98 "ns3::ndn::L3Protocol::NackTraceCallback")
99
100 ////////////////////////////////////////////////////////////////////
101
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800102 .AddTraceSource("SatisfiedInterests", "SatisfiedInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700103 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
104 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800105 .AddTraceSource("TimedOutInterests", "TimedOutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700106 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
107 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800108 ;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 return tid;
110}
111
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800112class L3Protocol::Impl {
113private:
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800114 Impl()
115 {
116 // Do not modify initial config file. Use helpers to set specific NFD parameters
117 std::string initialConfig =
118 "general\n"
119 "{\n"
120 "}\n"
121 "\n"
122 "tables\n"
123 "{\n"
124 " cs_max_packets 100\n"
125 "\n"
126 " strategy_choice\n"
127 " {\n"
128 " / /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700129 " /localhost /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800130 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700131 " /ndn/multicast /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800132 " }\n"
133 "}\n"
134 "\n"
135 // "face_system\n"
136 // "{\n"
137 // "}\n"
138 "\n"
139 "authorizations\n"
140 "{\n"
141 " authorize\n"
142 " {\n"
143 " certfile any\n"
144 " privileges\n"
145 " {\n"
146 " faces\n"
147 " fib\n"
148 " strategy-choice\n"
149 " }\n"
150 " }\n"
151 "}\n"
152 "\n"
153 "rib\n"
154 "{\n"
155 " localhost_security\n"
156 " {\n"
157 " trust-anchor\n"
158 " {\n"
159 " type any\n"
160 " }\n"
161 " }\n"
162 "}\n"
163 "\n";
164
165 std::istringstream input(initialConfig);
166 boost::property_tree::read_info(input, m_config);
167 }
168
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800169 friend class L3Protocol;
170
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500171 // note that shared_ptr needed for Python bindings
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800172
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500173 std::shared_ptr<::nfd::Forwarder> m_forwarder;
174 std::unique_ptr<::nfd::face::FaceSystem> m_faceSystem;
175
176 std::shared_ptr<::nfd::face::Face> m_internalFace;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700177 std::shared_ptr<::ndn::Face> m_internalClientFace;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700178 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500179 std::shared_ptr<::nfd::CommandAuthenticator> m_authenticator;
180 std::unique_ptr<::nfd::ForwarderStatusManager> m_forwarderStatusManager;
181 std::unique_ptr<::nfd::FaceManager> m_faceManager;
182 std::shared_ptr<::nfd::FibManager> m_fibManager;
183 std::unique_ptr<::nfd::CsManager> m_csManager;
184 std::unique_ptr<::nfd::StrategyChoiceManager> m_strategyChoiceManager;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800185
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500186 std::shared_ptr<::nfd::face::Face> m_internalFaceForInjects;
187 std::shared_ptr<::ndn::Face> m_internalClientFaceForInjects;
188
189 std::shared_ptr<::nfd::Face> m_internalRibFace;
190 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
191 std::unique_ptr<::nfd::rib::Service> m_ribService;
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700192
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800193 nfd::ConfigSection m_config;
194
spirosmastorakis34eed982016-11-02 15:20:50 -0700195 PolicyCreationCallback m_policy;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800196};
197
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800198L3Protocol::L3Protocol()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800199 : m_impl(new Impl())
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700200{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800201 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700202}
203
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800204L3Protocol::~L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700205{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800206 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700207}
208
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800209void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800210L3Protocol::initialize()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800211{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500212 m_impl->m_forwarder = make_shared<::nfd::Forwarder>();
213
214 ::nfd::FaceTable& faceTable = m_impl->m_forwarder->getFaceTable();
215 faceTable.addReserved(::nfd::face::makeNullFace(), ::nfd::face::FACEID_NULL);
216 // faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), face::FACEID_CONTENT_STORE);
217 m_impl->m_faceSystem = make_unique<::nfd::face::FaceSystem>(faceTable, nullptr);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800218
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800219 initializeManagement();
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500220 initializeRibManager();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800221
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800222 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
223 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800224}
225
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800226class IgnoreSections
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800227{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800228public:
229 IgnoreSections(const std::vector<std::string>& ignored)
230 : m_ignored(ignored)
231 {
232 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800233
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800234 void
235 operator()(const std::string& filename, const std::string& sectionName,
236 const nfd::ConfigSection& section, bool isDryRun)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800237
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800238 {
239 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
240 nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
241 }
242 }
243private:
244 std::vector<std::string> m_ignored;
245};
246
247void
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700248L3Protocol::injectInterest(const Interest& interest)
249{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500250 m_impl->m_internalClientFaceForInjects->expressInterest(interest, nullptr, nullptr, nullptr);
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700251}
252
253void
spirosmastorakis34eed982016-11-02 15:20:50 -0700254L3Protocol::setCsReplacementPolicy(const PolicyCreationCallback& policy)
255{
256 m_impl->m_policy = policy;
257}
258
259void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800260L3Protocol::initializeManagement()
261{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800262 auto& forwarder = m_impl->m_forwarder;
263 using namespace nfd;
264
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700265 std::tie(m_impl->m_internalFace, m_impl->m_internalClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
266 forwarder->getFaceTable().addReserved(m_impl->m_internalFace, face::FACEID_INTERNAL_FACE);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800267
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500268 std::tie(m_impl->m_internalFaceForInjects, m_impl->m_internalClientFaceForInjects) = face::makeInternalFace(StackHelper::getKeyChain());
269 forwarder->getFaceTable().addReserved(m_impl->m_internalFaceForInjects, face::FACEID_INTERNAL_FACE + 1);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800270
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500271 m_impl->m_dispatcher = make_unique<::ndn::mgmt::Dispatcher>(*m_impl->m_internalClientFace, StackHelper::getKeyChain());
272 m_impl->m_authenticator = ::nfd::CommandAuthenticator::create();
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700273
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500274 if (!this->getConfig().get<bool>("ndnSIM.disable_forwarder_status_manager", false)) {
275 m_impl->m_forwarderStatusManager = make_unique<::nfd::ForwarderStatusManager>(*m_impl->m_forwarder, *m_impl->m_dispatcher);
276 }
277 m_impl->m_faceManager = make_unique<::nfd::FaceManager>(*m_impl->m_faceSystem, *m_impl->m_dispatcher, *m_impl->m_authenticator);
278 m_impl->m_fibManager = make_shared<::nfd::FibManager>(m_impl->m_forwarder->getFib(), m_impl->m_forwarder->getFaceTable(),
279 *m_impl->m_dispatcher, *m_impl->m_authenticator);
280 m_impl->m_csManager = make_unique<::nfd::CsManager>(m_impl->m_forwarder->getCs(), m_impl->m_forwarder->getCounters(),
281 *m_impl->m_dispatcher, *m_impl->m_authenticator);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800282 if (!this->getConfig().get<bool>("ndnSIM.disable_strategy_choice_manager", false)) {
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500283 m_impl->m_strategyChoiceManager = make_unique<::nfd::StrategyChoiceManager>(m_impl->m_forwarder->getStrategyChoice(),
284 *m_impl->m_dispatcher, *m_impl->m_authenticator);
285
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800286 }
287 else {
288 this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("strategy-choice");
289 }
290
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700291 ConfigFile config(&ConfigFile::ignoreUnknownSection);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800292
Alexander Afanasyev8fbcc642019-07-27 16:53:37 -0400293 forwarder->getCs().setPolicy(m_impl->m_policy());
spirosmastorakis34eed982016-11-02 15:20:50 -0700294
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800295 TablesConfigSection tablesConfig(*forwarder);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800296 tablesConfig.setConfigFile(config);
297
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800298 m_impl->m_authenticator->setConfigFile(config);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800299
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700300 // if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) {
Alexander Afanasyeve93e8b02018-05-08 20:10:01 -0400301 m_impl->m_faceSystem->setConfigFile(config);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700302 // }
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800303
304 // apply config
305 config.parse(m_impl->m_config, false, "ndnSIM.conf");
306
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800307 tablesConfig.ensureConfigured();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800308
309 // add FIB entry for NFD Management Protocol
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700310 Name topPrefix("/localhost/nfd");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500311 m_impl->m_forwarder->getFib().insert(topPrefix).first->addOrUpdateNextHop(*m_impl->m_internalFace, 0, 0);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700312 m_impl->m_dispatcher->addTopPrefix(topPrefix, false);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800313}
314
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700315void
316L3Protocol::initializeRibManager()
317{
318 using namespace nfd;
319
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700320 std::tie(m_impl->m_internalRibFace, m_impl->m_internalRibClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
321 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800322
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500323 m_impl->m_ribService = make_unique<rib::Service>(m_impl->m_config,
324 std::ref(*m_impl->m_internalRibClientFace),
325 std::ref(StackHelper::getKeyChain()));
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700326}
327
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800328shared_ptr<nfd::Forwarder>
329L3Protocol::getForwarder()
330{
331 return m_impl->m_forwarder;
332}
333
334shared_ptr<nfd::FibManager>
335L3Protocol::getFibManager()
336{
337 return m_impl->m_fibManager;
338}
339
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500340nfd::StrategyChoiceManager&
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800341L3Protocol::getStrategyChoiceManager()
342{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500343 return *m_impl->m_strategyChoiceManager;
344}
345
346::nfd::rib::Service&
347L3Protocol::getRibService()
348{
349 return *m_impl->m_ribService;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800350}
351
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800352nfd::ConfigSection&
353L3Protocol::getConfig()
354{
355 return m_impl->m_config;
356}
357
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700358/*
359 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700360 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700361 */
362void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800363L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700364{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800365 if (m_node == nullptr) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800366 m_node = GetObject<Node>();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800367 if (m_node != nullptr) {
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700368 initialize();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700369 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800370 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700371
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800372 Object::NotifyNewAggregate();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700373}
374
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800375void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800376L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700377{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800378 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700379
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700380 // MUST HAPPEN BEFORE Simulator IS DESTROYED
381 m_impl.reset();
382
Alexander Afanasyev11dfcb72019-07-27 17:47:32 -0400383 nfd::resetGlobalScheduler();
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700384
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700385 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800386
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800387 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700388}
389
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800390nfd::FaceId
391L3Protocol::addFace(shared_ptr<Face> face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700392{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800393 NS_LOG_FUNCTION(this << face.get());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700394
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800395 m_impl->m_forwarder->addFace(face);
396
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700397 std::weak_ptr<Face> weakFace = face;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800398
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700399 // // Connect Signals to TraceSource
400 face->afterReceiveInterest.connect([this, weakFace](const Interest& interest) {
401 shared_ptr<Face> face = weakFace.lock();
402 if (face != nullptr) {
403 this->m_inInterests(interest, *face);
404 }
405 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800406
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700407 face->afterReceiveData.connect([this, weakFace](const Data& data) {
408 shared_ptr<Face> face = weakFace.lock();
409 if (face != nullptr) {
410 this->m_inData(data, *face);
411 }
412 });
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800413
414 face->afterReceiveNack.connect([this, weakFace](const lp::Nack& nack) {
415 shared_ptr<Face> face = weakFace.lock();
416 if (face != nullptr) {
417 this->m_inNack(nack, *face);
418 }
419 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800420
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700421 auto tracingLink = face->getLinkService();
422 NS_LOG_LOGIC("Adding trace sources for afterSendInterest and afterSendData");
423 tracingLink->afterSendInterest.connect([this, weakFace](const Interest& interest) {
424 shared_ptr<Face> face = weakFace.lock();
425 if (face != nullptr) {
426 this->m_outInterests(interest, *face);
427 }
428 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700429
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700430 tracingLink->afterSendData.connect([this, weakFace](const Data& data) {
431 shared_ptr<Face> face = weakFace.lock();
432 if (face != nullptr) {
433 this->m_outData(data, *face);
434 }
435 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700436
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800437 tracingLink->afterSendNack.connect([this, weakFace](const lp::Nack& nack) {
438 shared_ptr<Face> face = weakFace.lock();
439 if (face != nullptr) {
440 this->m_outNack(nack, *face);
441 }
442 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800443
444 return face->getId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700445}
446
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800447shared_ptr<Face>
448L3Protocol::getFaceById(nfd::FaceId id) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700449{
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800450 return m_impl->m_forwarder->getFaceTable().get(id)->shared_from_this();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700451}
452
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700453shared_ptr<Face>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800454L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700455{
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800456 for (auto& i : m_impl->m_forwarder->getFaceTable()) {
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800457 auto transport = dynamic_cast<NetDeviceTransport*>(i.getTransport());
458 if (transport == nullptr)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800459 continue;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700460
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800461 if (transport->GetNetDevice() == netDevice)
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800462 return i.shared_from_this();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800463 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700464 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700465}
466
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800467Ptr<L3Protocol>
468L3Protocol::getL3Protocol(Ptr<Object> node)
469{
470 Ptr<L3Protocol> retval = node->GetObject<L3Protocol>();
471 NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object");
472 return retval;
473}
474
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800475} // namespace ndn
476} // namespace ns3