blob: 47ce00cac172259dc0b913c97377397fab12ea2c [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 Afanasyevdc3c3a32019-02-17 20:17:32 -050050#include "ns3/ndnSIM/NFD/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
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080055#include "ns3/ndnSIM/NFD/core/config-file.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070056
57#include <ndn-cxx/mgmt/dispatcher.hpp>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080058
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060
61namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070063
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070064const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070065const uint16_t L3Protocol::IP_STACK_PORT = 9695;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067NS_OBJECT_ENSURE_REGISTERED(L3Protocol);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080069TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070L3Protocol::GetTypeId(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 static TypeId tid =
73 TypeId("ns3::ndn::L3Protocol")
74 .SetGroupName("ndn")
75 .SetParent<Object>()
76 .AddConstructor<L3Protocol>()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080077
78 .AddTraceSource("OutInterests", "OutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070079 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
80 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080081 .AddTraceSource("InInterests", "InInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070082 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
83 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080084
85 ////////////////////////////////////////////////////////////////////
86
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070087 .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData),
88 "ns3::ndn::L3Protocol::DataTraceCallback")
89 .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData),
90 "ns3::ndn::L3Protocol::DataTraceCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080091
92 ////////////////////////////////////////////////////////////////////
93
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080094 .AddTraceSource("OutNack", "OutNack", MakeTraceSourceAccessor(&L3Protocol::m_outNack),
95 "ns3::ndn::L3Protocol::NackTraceCallback")
96 .AddTraceSource("InNack", "InNack", MakeTraceSourceAccessor(&L3Protocol::m_inNack),
97 "ns3::ndn::L3Protocol::NackTraceCallback")
98
99 ////////////////////////////////////////////////////////////////////
100
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800101 .AddTraceSource("SatisfiedInterests", "SatisfiedInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700102 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
103 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800104 .AddTraceSource("TimedOutInterests", "TimedOutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700105 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
106 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800107 ;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108 return tid;
109}
110
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800111class L3Protocol::Impl {
112private:
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800113 Impl()
114 {
115 // Do not modify initial config file. Use helpers to set specific NFD parameters
116 std::string initialConfig =
117 "general\n"
118 "{\n"
119 "}\n"
120 "\n"
121 "tables\n"
122 "{\n"
123 " cs_max_packets 100\n"
124 "\n"
125 " strategy_choice\n"
126 " {\n"
127 " / /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700128 " /localhost /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800129 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700130 " /ndn/multicast /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800131 " }\n"
132 "}\n"
133 "\n"
134 // "face_system\n"
135 // "{\n"
136 // "}\n"
137 "\n"
138 "authorizations\n"
139 "{\n"
140 " authorize\n"
141 " {\n"
142 " certfile any\n"
143 " privileges\n"
144 " {\n"
145 " faces\n"
146 " fib\n"
147 " strategy-choice\n"
148 " }\n"
149 " }\n"
150 "}\n"
151 "\n"
152 "rib\n"
153 "{\n"
154 " localhost_security\n"
155 " {\n"
156 " trust-anchor\n"
157 " {\n"
158 " type any\n"
159 " }\n"
160 " }\n"
161 "}\n"
162 "\n";
163
164 std::istringstream input(initialConfig);
165 boost::property_tree::read_info(input, m_config);
166 }
167
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800168 friend class L3Protocol;
169
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500170 // note that shared_ptr needed for Python bindings
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800171
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500172 std::shared_ptr<::nfd::Forwarder> m_forwarder;
173 std::unique_ptr<::nfd::face::FaceSystem> m_faceSystem;
174
175 std::shared_ptr<::nfd::face::Face> m_internalFace;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700176 std::shared_ptr<::ndn::Face> m_internalClientFace;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700177 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500178 std::shared_ptr<::nfd::CommandAuthenticator> m_authenticator;
179 std::unique_ptr<::nfd::ForwarderStatusManager> m_forwarderStatusManager;
180 std::unique_ptr<::nfd::FaceManager> m_faceManager;
181 std::shared_ptr<::nfd::FibManager> m_fibManager;
182 std::unique_ptr<::nfd::CsManager> m_csManager;
183 std::unique_ptr<::nfd::StrategyChoiceManager> m_strategyChoiceManager;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800184
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500185 std::shared_ptr<::nfd::face::Face> m_internalFaceForInjects;
186 std::shared_ptr<::ndn::Face> m_internalClientFaceForInjects;
187
188 std::shared_ptr<::nfd::Face> m_internalRibFace;
189 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
190 std::unique_ptr<::nfd::rib::Service> m_ribService;
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700191
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800192 nfd::ConfigSection m_config;
193
spirosmastorakis34eed982016-11-02 15:20:50 -0700194 PolicyCreationCallback m_policy;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800195};
196
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800197L3Protocol::L3Protocol()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800198 : m_impl(new Impl())
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700199{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800200 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700201}
202
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800203L3Protocol::~L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700204{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800205 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700206}
207
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800208void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800209L3Protocol::initialize()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800210{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500211 m_impl->m_forwarder = make_shared<::nfd::Forwarder>();
212
213 ::nfd::FaceTable& faceTable = m_impl->m_forwarder->getFaceTable();
214 faceTable.addReserved(::nfd::face::makeNullFace(), ::nfd::face::FACEID_NULL);
215 // faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), face::FACEID_CONTENT_STORE);
216 m_impl->m_faceSystem = make_unique<::nfd::face::FaceSystem>(faceTable, nullptr);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800217
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800218 initializeManagement();
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500219 initializeRibManager();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800220
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800221 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
222 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800223}
224
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800225class IgnoreSections
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800226{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800227public:
228 IgnoreSections(const std::vector<std::string>& ignored)
229 : m_ignored(ignored)
230 {
231 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800232
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800233 void
234 operator()(const std::string& filename, const std::string& sectionName,
235 const nfd::ConfigSection& section, bool isDryRun)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800236
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800237 {
238 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
239 nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
240 }
241 }
242private:
243 std::vector<std::string> m_ignored;
244};
245
246void
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700247L3Protocol::injectInterest(const Interest& interest)
248{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500249 m_impl->m_internalClientFaceForInjects->expressInterest(interest, nullptr, nullptr, nullptr);
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700250}
251
252void
spirosmastorakis34eed982016-11-02 15:20:50 -0700253L3Protocol::setCsReplacementPolicy(const PolicyCreationCallback& policy)
254{
255 m_impl->m_policy = policy;
256}
257
258void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800259L3Protocol::initializeManagement()
260{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800261 auto& forwarder = m_impl->m_forwarder;
262 using namespace nfd;
263
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700264 std::tie(m_impl->m_internalFace, m_impl->m_internalClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
265 forwarder->getFaceTable().addReserved(m_impl->m_internalFace, face::FACEID_INTERNAL_FACE);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800266
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500267 std::tie(m_impl->m_internalFaceForInjects, m_impl->m_internalClientFaceForInjects) = face::makeInternalFace(StackHelper::getKeyChain());
268 forwarder->getFaceTable().addReserved(m_impl->m_internalFaceForInjects, face::FACEID_INTERNAL_FACE + 1);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800269
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500270 m_impl->m_dispatcher = make_unique<::ndn::mgmt::Dispatcher>(*m_impl->m_internalClientFace, StackHelper::getKeyChain());
271 m_impl->m_authenticator = ::nfd::CommandAuthenticator::create();
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700272
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500273 if (!this->getConfig().get<bool>("ndnSIM.disable_forwarder_status_manager", false)) {
274 m_impl->m_forwarderStatusManager = make_unique<::nfd::ForwarderStatusManager>(*m_impl->m_forwarder, *m_impl->m_dispatcher);
275 }
276 m_impl->m_faceManager = make_unique<::nfd::FaceManager>(*m_impl->m_faceSystem, *m_impl->m_dispatcher, *m_impl->m_authenticator);
277 m_impl->m_fibManager = make_shared<::nfd::FibManager>(m_impl->m_forwarder->getFib(), m_impl->m_forwarder->getFaceTable(),
278 *m_impl->m_dispatcher, *m_impl->m_authenticator);
279 m_impl->m_csManager = make_unique<::nfd::CsManager>(m_impl->m_forwarder->getCs(), m_impl->m_forwarder->getCounters(),
280 *m_impl->m_dispatcher, *m_impl->m_authenticator);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800281 if (!this->getConfig().get<bool>("ndnSIM.disable_strategy_choice_manager", false)) {
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500282 m_impl->m_strategyChoiceManager = make_unique<::nfd::StrategyChoiceManager>(m_impl->m_forwarder->getStrategyChoice(),
283 *m_impl->m_dispatcher, *m_impl->m_authenticator);
284
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800285 }
286 else {
287 this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("strategy-choice");
288 }
289
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700290 ConfigFile config(&ConfigFile::ignoreUnknownSection);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800291
Alexander Afanasyev8fbcc642019-07-27 16:53:37 -0400292 forwarder->getCs().setPolicy(m_impl->m_policy());
spirosmastorakis34eed982016-11-02 15:20:50 -0700293
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800294 TablesConfigSection tablesConfig(*forwarder);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800295 tablesConfig.setConfigFile(config);
296
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800297 m_impl->m_authenticator->setConfigFile(config);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800298
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700299 // if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) {
Alexander Afanasyeve93e8b02018-05-08 20:10:01 -0400300 m_impl->m_faceSystem->setConfigFile(config);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700301 // }
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800302
303 // apply config
304 config.parse(m_impl->m_config, false, "ndnSIM.conf");
305
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800306 tablesConfig.ensureConfigured();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800307
308 // add FIB entry for NFD Management Protocol
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700309 Name topPrefix("/localhost/nfd");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500310 m_impl->m_forwarder->getFib().insert(topPrefix).first->addOrUpdateNextHop(*m_impl->m_internalFace, 0, 0);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700311 m_impl->m_dispatcher->addTopPrefix(topPrefix, false);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800312}
313
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700314void
315L3Protocol::initializeRibManager()
316{
317 using namespace nfd;
318
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700319 std::tie(m_impl->m_internalRibFace, m_impl->m_internalRibClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
320 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800321
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500322 m_impl->m_ribService = make_unique<rib::Service>(m_impl->m_config,
323 std::ref(*m_impl->m_internalRibClientFace),
324 std::ref(StackHelper::getKeyChain()));
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700325}
326
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800327shared_ptr<nfd::Forwarder>
328L3Protocol::getForwarder()
329{
330 return m_impl->m_forwarder;
331}
332
333shared_ptr<nfd::FibManager>
334L3Protocol::getFibManager()
335{
336 return m_impl->m_fibManager;
337}
338
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500339nfd::StrategyChoiceManager&
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800340L3Protocol::getStrategyChoiceManager()
341{
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500342 return *m_impl->m_strategyChoiceManager;
343}
344
345::nfd::rib::Service&
346L3Protocol::getRibService()
347{
348 return *m_impl->m_ribService;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800349}
350
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800351nfd::ConfigSection&
352L3Protocol::getConfig()
353{
354 return m_impl->m_config;
355}
356
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700357/*
358 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700359 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700360 */
361void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800362L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700363{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800364 if (m_node == nullptr) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800365 m_node = GetObject<Node>();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800366 if (m_node != nullptr) {
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700367 initialize();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700368 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800369 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700370
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800371 Object::NotifyNewAggregate();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700372}
373
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800374void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800375L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700376{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800377 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700378
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700379 // MUST HAPPEN BEFORE Simulator IS DESTROYED
380 m_impl.reset();
381
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500382 nfd::scheduler::resetGlobalScheduler();
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700383
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700384 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800385
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800386 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700387}
388
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800389nfd::FaceId
390L3Protocol::addFace(shared_ptr<Face> face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700391{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800392 NS_LOG_FUNCTION(this << face.get());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700393
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800394 m_impl->m_forwarder->addFace(face);
395
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700396 std::weak_ptr<Face> weakFace = face;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800397
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700398 // // Connect Signals to TraceSource
399 face->afterReceiveInterest.connect([this, weakFace](const Interest& interest) {
400 shared_ptr<Face> face = weakFace.lock();
401 if (face != nullptr) {
402 this->m_inInterests(interest, *face);
403 }
404 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800405
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700406 face->afterReceiveData.connect([this, weakFace](const Data& data) {
407 shared_ptr<Face> face = weakFace.lock();
408 if (face != nullptr) {
409 this->m_inData(data, *face);
410 }
411 });
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800412
413 face->afterReceiveNack.connect([this, weakFace](const lp::Nack& nack) {
414 shared_ptr<Face> face = weakFace.lock();
415 if (face != nullptr) {
416 this->m_inNack(nack, *face);
417 }
418 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800419
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700420 auto tracingLink = face->getLinkService();
421 NS_LOG_LOGIC("Adding trace sources for afterSendInterest and afterSendData");
422 tracingLink->afterSendInterest.connect([this, weakFace](const Interest& interest) {
423 shared_ptr<Face> face = weakFace.lock();
424 if (face != nullptr) {
425 this->m_outInterests(interest, *face);
426 }
427 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700428
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700429 tracingLink->afterSendData.connect([this, weakFace](const Data& data) {
430 shared_ptr<Face> face = weakFace.lock();
431 if (face != nullptr) {
432 this->m_outData(data, *face);
433 }
434 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700435
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800436 tracingLink->afterSendNack.connect([this, weakFace](const lp::Nack& nack) {
437 shared_ptr<Face> face = weakFace.lock();
438 if (face != nullptr) {
439 this->m_outNack(nack, *face);
440 }
441 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800442
443 return face->getId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700444}
445
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800446shared_ptr<Face>
447L3Protocol::getFaceById(nfd::FaceId id) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700448{
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800449 return m_impl->m_forwarder->getFaceTable().get(id)->shared_from_this();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700450}
451
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700452shared_ptr<Face>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800453L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700454{
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800455 for (auto& i : m_impl->m_forwarder->getFaceTable()) {
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800456 auto transport = dynamic_cast<NetDeviceTransport*>(i.getTransport());
457 if (transport == nullptr)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800458 continue;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700459
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800460 if (transport->GetNetDevice() == netDevice)
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800461 return i.shared_from_this();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800462 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700463 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700464}
465
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800466Ptr<L3Protocol>
467L3Protocol::getL3Protocol(Ptr<Object> node)
468{
469 Ptr<L3Protocol> retval = node->GetObject<L3Protocol>();
470 NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object");
471 return retval;
472}
473
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800474} // namespace ndn
475} // namespace ns3