22 #include "ns3/packet.h"
25 #include "ns3/callback.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/trace-source-accessor.h"
28 #include "ns3/object-vector.h"
29 #include "ns3/pointer.h"
30 #include "ns3/simulator.h"
34 #include "../helper/ndn-stack-helper.hpp"
36 #include <boost/property_tree/info_parser.hpp>
38 #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
39 #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
40 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp"
41 #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"
44 #include "ns3/ndnSIM/NFD/daemon/mgmt/cs-manager.hpp"
45 #include "ns3/ndnSIM/NFD/daemon/mgmt/forwarder-status-manager.hpp"
47 #include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp"
48 #include "ns3/ndnSIM/NFD/daemon/mgmt/command-authenticator.hpp"
50 #include "ns3/ndnSIM/NFD/daemon/rib/service.hpp"
52 #include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp"
53 #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
55 #include "ns3/ndnSIM/NFD/daemon/common/global.hpp"
56 #include "ns3/ndnSIM/NFD/daemon/common/config-file.hpp"
60 NS_LOG_COMPONENT_DEFINE(
"ndn.L3Protocol");
74 TypeId(
"ns3::ndn::L3Protocol")
77 .AddConstructor<L3Protocol>()
79 .AddTraceSource(
"OutInterests",
"OutInterests",
80 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
81 "ns3::ndn::L3Protocol::InterestTraceCallback")
82 .AddTraceSource(
"InInterests",
"InInterests",
83 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
84 "ns3::ndn::L3Protocol::InterestTraceCallback")
88 .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")
95 .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")
102 .AddTraceSource(
"SatisfiedInterests",
"SatisfiedInterests",
103 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
104 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
105 .AddTraceSource(
"TimedOutInterests",
"TimedOutInterests",
106 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
107 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
117 std::string initialConfig =
124 " cs_max_packets 100\n"
128 " / /localhost/nfd/strategy/best-route\n"
129 " /localhost /localhost/nfd/strategy/multicast\n"
130 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
131 " /ndn/multicast /localhost/nfd/strategy/multicast\n"
155 " localhost_security\n"
165 std::istringstream input(initialConfig);
166 boost::property_tree::read_info(input, m_config);
173 std::shared_ptr<::nfd::Forwarder> m_forwarder;
174 std::unique_ptr<::nfd::FaceTable> m_faceTable;
175 std::unique_ptr<::nfd::face::FaceSystem> m_faceSystem;
177 std::shared_ptr<::nfd::face::Face> m_internalFace;
178 std::shared_ptr<::ndn::Face> m_internalClientFace;
179 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
180 std::shared_ptr<::nfd::CommandAuthenticator> m_authenticator;
181 std::unique_ptr<::nfd::ForwarderStatusManager> m_forwarderStatusManager;
182 std::unique_ptr<::nfd::FaceManager> m_faceManager;
183 std::shared_ptr<::nfd::FibManager> m_fibManager;
184 std::unique_ptr<::nfd::CsManager> m_csManager;
185 std::unique_ptr<::nfd::StrategyChoiceManager> m_strategyChoiceManager;
187 std::shared_ptr<::nfd::face::Face> m_internalFaceForInjects;
188 std::shared_ptr<::ndn::Face> m_internalClientFaceForInjects;
190 std::shared_ptr<::nfd::Face> m_internalRibFace;
191 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
192 std::unique_ptr<::nfd::rib::Service> m_ribService;
202 NS_LOG_FUNCTION(
this);
207 NS_LOG_FUNCTION(
this);
211 L3Protocol::initialize()
213 m_impl->m_faceTable = make_unique<::nfd::FaceTable>();
214 m_impl->m_forwarder = make_shared<::nfd::Forwarder>(*m_impl->m_faceTable);
215 m_impl->m_faceSystem = make_unique<::nfd::face::FaceSystem>(*m_impl->m_faceTable,
nullptr);
217 initializeManagement();
218 initializeRibManager();
220 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
221 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
233 operator()(
const std::string& filename,
const std::string& sectionName,
237 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
242 std::vector<std::string> m_ignored;
248 m_impl->m_internalClientFaceForInjects->expressInterest(interest,
nullptr,
nullptr,
nullptr);
254 m_impl->m_policy = policy;
258 L3Protocol::initializeManagement()
260 auto& forwarder = m_impl->m_forwarder;
269 m_impl->m_dispatcher = make_unique<::ndn::mgmt::Dispatcher>(*m_impl->m_internalClientFace,
StackHelper::getKeyChain());
272 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_forwarder_status_manager",
false)) {
273 m_impl->m_forwarderStatusManager = make_unique<::nfd::ForwarderStatusManager>(*m_impl->m_forwarder, *m_impl->m_dispatcher);
275 m_impl->m_faceManager = make_unique<::nfd::FaceManager>(*m_impl->m_faceSystem, *m_impl->m_dispatcher, *m_impl->m_authenticator);
276 m_impl->m_fibManager = make_shared<::nfd::FibManager>(m_impl->m_forwarder->getFib(), *m_impl->m_faceTable,
277 *m_impl->m_dispatcher, *m_impl->m_authenticator);
278 m_impl->m_csManager = make_unique<::nfd::CsManager>(m_impl->m_forwarder->getCs(), m_impl->m_forwarder->getCounters(),
279 *m_impl->m_dispatcher, *m_impl->m_authenticator);
280 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
281 m_impl->m_strategyChoiceManager = make_unique<::nfd::StrategyChoiceManager>(m_impl->m_forwarder->getStrategyChoice(),
282 *m_impl->m_dispatcher, *m_impl->m_authenticator);
286 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
289 ConfigFile config(&ConfigFile::ignoreUnknownSection);
291 forwarder->getCs().setPolicy(m_impl->m_policy());
294 tablesConfig.setConfigFile(config);
296 m_impl->m_authenticator->setConfigFile(config);
299 m_impl->m_faceSystem->setConfigFile(config);
303 config.parse(m_impl->m_config,
false,
"ndnSIM.conf");
305 tablesConfig.ensureConfigured();
308 Name topPrefix(
"/localhost/nfd");
309 auto entry = m_impl->m_forwarder->getFib().insert(topPrefix).first;
310 m_impl->m_forwarder->getFib().addOrUpdateNextHop(*entry, *m_impl->m_internalFace, 0);
311 m_impl->m_dispatcher->addTopPrefix(topPrefix,
false);
315 L3Protocol::initializeRibManager()
320 m_impl->m_faceTable->add(m_impl->m_internalRibFace);
322 m_impl->m_ribService = make_unique<rib::Service>(m_impl->m_config,
323 std::ref(*m_impl->m_internalRibClientFace),
327 shared_ptr<nfd::Forwarder>
330 return m_impl->m_forwarder;
336 return *m_impl->m_faceTable;
339 shared_ptr<nfd::FibManager>
342 return m_impl->m_fibManager;
348 return *m_impl->m_strategyChoiceManager;
354 return *m_impl->m_ribService;
360 return m_impl->m_config;
370 if (m_node ==
nullptr) {
371 m_node = GetObject<Node>();
372 if (m_node !=
nullptr) {
377 Object::NotifyNewAggregate();
383 NS_LOG_FUNCTION(
this);
398 NS_LOG_FUNCTION(
this << face.get());
400 m_impl->m_faceTable->add(face);
402 std::weak_ptr<Face> weakFace = face;
406 shared_ptr<Face> face = weakFace.lock();
407 if (face !=
nullptr) {
408 this->m_inInterests(interest, *face);
412 face->afterReceiveData.connect([
this, weakFace](
const Data& data,
const nfd::EndpointId&) {
413 shared_ptr<Face> face = weakFace.lock();
414 if (face !=
nullptr) {
415 this->m_inData(data, *face);
420 shared_ptr<Face> face = weakFace.lock();
421 if (face !=
nullptr) {
422 this->m_inNack(nack, *face);
426 auto tracingLink = face->getLinkService();
427 NS_LOG_LOGIC(
"Adding trace sources for afterSendInterest and afterSendData");
428 tracingLink->afterSendInterest.connect([
this, weakFace](
const Interest& interest) {
429 shared_ptr<Face> face = weakFace.lock();
430 if (face !=
nullptr) {
431 this->m_outInterests(interest, *face);
435 tracingLink->afterSendData.connect([
this, weakFace](
const Data& data) {
436 shared_ptr<Face> face = weakFace.lock();
437 if (face !=
nullptr) {
438 this->m_outData(data, *face);
442 tracingLink->afterSendNack.connect([
this, weakFace](
const lp::Nack& nack) {
443 shared_ptr<Face> face = weakFace.lock();
444 if (face !=
nullptr) {
445 this->m_outNack(nack, *face);
449 return face->getId();
455 return m_impl->m_faceTable->get(
id)->shared_from_this();
461 for (
auto& i : *m_impl->m_faceTable) {
463 if (transport ==
nullptr)
466 if (transport->GetNetDevice() == netDevice)
467 return i.shared_from_this();
475 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
476 NS_ASSERT_MSG(retval !=
nullptr,
"L3Protocol is not aggregated on this object");