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" 37 #include <boost/property_tree/info_parser.hpp> 39 #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" 40 #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp" 41 #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" 42 #include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp" 43 #include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp" 44 #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp" 45 #include "ns3/ndnSIM/NFD/daemon/mgmt/cs-manager.hpp" 46 #include "ns3/ndnSIM/NFD/daemon/mgmt/forwarder-status-manager.hpp" 48 #include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp" 49 #include "ns3/ndnSIM/NFD/daemon/mgmt/command-authenticator.hpp" 51 #include "ns3/ndnSIM/NFD/rib/service.hpp" 53 #include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp" 54 #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp" 56 #include "ns3/ndnSIM/NFD/core/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::face::FaceSystem> m_faceSystem;
176 std::shared_ptr<::nfd::face::Face> m_internalFace;
177 std::shared_ptr<::ndn::Face> m_internalClientFace;
178 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
179 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;
186 std::shared_ptr<::nfd::face::Face> m_internalFaceForInjects;
187 std::shared_ptr<::ndn::Face> m_internalClientFaceForInjects;
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;
195 Ptr<ContentStore> m_csFromNdnSim;
202 NS_LOG_FUNCTION(
this);
207 NS_LOG_FUNCTION(
this);
211 L3Protocol::initialize()
213 m_impl->m_forwarder = make_shared<::nfd::Forwarder>();
218 m_impl->m_faceSystem = make_unique<::nfd::face::FaceSystem>(faceTable,
nullptr);
220 initializeManagement();
221 initializeRibManager();
223 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
224 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
236 operator()(
const std::string& filename,
const std::string& sectionName,
240 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
245 std::vector<std::string> m_ignored;
251 m_impl->m_internalClientFaceForInjects->expressInterest(interest,
nullptr,
nullptr,
nullptr);
257 m_impl->m_policy = policy;
261 L3Protocol::initializeManagement()
263 auto& forwarder = m_impl->m_forwarder;
272 m_impl->m_dispatcher = make_unique<::ndn::mgmt::Dispatcher>(*m_impl->m_internalClientFace,
StackHelper::getKeyChain());
275 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_forwarder_status_manager",
false)) {
276 m_impl->m_forwarderStatusManager = make_unique<::nfd::ForwarderStatusManager>(*m_impl->m_forwarder, *m_impl->m_dispatcher);
278 m_impl->m_faceManager = make_unique<::nfd::FaceManager>(*m_impl->m_faceSystem, *m_impl->m_dispatcher, *m_impl->m_authenticator);
279 m_impl->m_fibManager = make_shared<::nfd::FibManager>(m_impl->m_forwarder->getFib(), m_impl->m_forwarder->getFaceTable(),
280 *m_impl->m_dispatcher, *m_impl->m_authenticator);
281 m_impl->m_csManager = make_unique<::nfd::CsManager>(m_impl->m_forwarder->getCs(), m_impl->m_forwarder->getCounters(),
282 *m_impl->m_dispatcher, *m_impl->m_authenticator);
283 if (!this->
getConfig().get<
bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
284 m_impl->m_strategyChoiceManager = make_unique<::nfd::StrategyChoiceManager>(m_impl->m_forwarder->getStrategyChoice(),
285 *m_impl->m_dispatcher, *m_impl->m_authenticator);
289 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
292 ConfigFile config(&ConfigFile::ignoreUnknownSection);
295 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
296 if (m_impl->m_csFromNdnSim ==
nullptr) {
297 forwarder->getCs().setPolicy(m_impl->m_policy());
301 tablesConfig.setConfigFile(config);
303 m_impl->m_authenticator->setConfigFile(config);
306 m_impl->m_faceSystem->setConfigFile(config);
310 config.parse(m_impl->m_config,
false,
"ndnSIM.conf");
312 tablesConfig.ensureConfigured();
315 Name topPrefix(
"/localhost/nfd");
316 m_impl->m_forwarder->getFib().insert(topPrefix).first->addOrUpdateNextHop(*m_impl->m_internalFace, 0, 0);
317 m_impl->m_dispatcher->addTopPrefix(topPrefix,
false);
321 L3Protocol::initializeRibManager()
326 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
328 m_impl->m_ribService = make_unique<rib::Service>(m_impl->m_config,
329 std::ref(*m_impl->m_internalRibClientFace),
333 shared_ptr<nfd::Forwarder>
336 return m_impl->m_forwarder;
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) {
375 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
376 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
377 if (m_impl->m_csFromNdnSim !=
nullptr) {
378 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
383 Object::NotifyNewAggregate();
389 NS_LOG_FUNCTION(
this);
404 NS_LOG_FUNCTION(
this << face.get());
406 m_impl->m_forwarder->addFace(face);
408 std::weak_ptr<Face> weakFace = face;
411 face->afterReceiveInterest.connect([
this, weakFace](
const Interest& interest) {
412 shared_ptr<Face> face = weakFace.lock();
413 if (face !=
nullptr) {
414 this->m_inInterests(interest, *face);
418 face->afterReceiveData.connect([
this, weakFace](
const Data& data) {
419 shared_ptr<Face> face = weakFace.lock();
420 if (face !=
nullptr) {
421 this->m_inData(data, *face);
425 face->afterReceiveNack.connect([
this, weakFace](
const lp::Nack& nack) {
426 shared_ptr<Face> face = weakFace.lock();
427 if (face !=
nullptr) {
428 this->m_inNack(nack, *face);
432 auto tracingLink = face->getLinkService();
433 NS_LOG_LOGIC(
"Adding trace sources for afterSendInterest and afterSendData");
434 tracingLink->afterSendInterest.connect([
this, weakFace](
const Interest& interest) {
435 shared_ptr<Face> face = weakFace.lock();
436 if (face !=
nullptr) {
437 this->m_outInterests(interest, *face);
441 tracingLink->afterSendData.connect([
this, weakFace](
const Data& data) {
442 shared_ptr<Face> face = weakFace.lock();
443 if (face !=
nullptr) {
444 this->m_outData(data, *face);
448 tracingLink->afterSendNack.connect([
this, weakFace](
const lp::Nack& nack) {
449 shared_ptr<Face> face = weakFace.lock();
450 if (face !=
nullptr) {
451 this->m_outNack(nack, *face);
455 return face->getId();
461 return m_impl->m_forwarder->getFaceTable().get(
id)->shared_from_this();
467 for (
auto& i : m_impl->m_forwarder->getFaceTable()) {
468 auto transport = dynamic_cast<NetDeviceTransport*>(i.getTransport());
469 if (transport ==
nullptr)
472 if (transport->GetNetDevice() == netDevice)
473 return i.shared_from_this();
481 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
482 NS_ASSERT_MSG(retval !=
nullptr,
"L3Protocol is not aggregated on this object");
static const uint16_t IP_STACK_PORT
TCP/UDP port for NDN stack.
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< Face > makeNullFace(const FaceUri &uri)
std::tuple< shared_ptr< Face >, shared_ptr< ndn::Face > > makeInternalFace(ndn::KeyChain &clientKeyChain)
make a pair of forwarder-side face and client-side face that are connected with each other
shared_ptr< nfd::Forwarder > getForwarder()
Get smart pointer to nfd::Forwarder installed on the node.
static const uint16_t ETHERNET_FRAME_TYPE
Ethernet Frame Type of Ndn.
initializes and executes NFD-RIB service thread
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
implement the Strategy Choice Management of NFD Management Protocol.
nfd::ConfigSection & getConfig()
Get NFD config (boost::property_tree)
configuration file parsing utility
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
void operator()(const std::string &filename, const std::string §ionName, const nfd::ConfigSection §ion, bool isDryRun)
std::function< std::unique_ptr< nfd::cs::Policy >)> PolicyCreationCallback
shared_ptr< nfd::FibManager > getFibManager()
Get smart pointer to nfd::FibManager, used by node's NFD.
virtual void NotifyNewAggregate()
This function will notify other components connected to the node that a new stack member is now conne...
shared_ptr< Face > getFaceByNetDevice(Ptr< NetDevice > netDevice) const
Remove face from ndn stack (remove callbacks)
represents a Network Nack
static TypeId GetTypeId()
Interface ID.
::nfd::rib::Service & getRibService()
void setCsReplacementPolicy(const PolicyCreationCallback &policy)
Set the replacement policy of NFD's CS.
static void throwErrorOnUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
Copyright (c) 2011-2015 Regents of the University of California.
nfd::FaceId addFace(shared_ptr< Face > face)
Add face to NDN stack.
Copyright (c) 2011-2015 Regents of the University of California.
void resetGlobalScheduler()
boost::property_tree::ptree ConfigSection
a config file section
L3Protocol()
Default constructor.
ndn L3Protocol
Copyright (c) 2011-2015 Regents of the University of California.
Implementation network-layer of NDN stack.
static Ptr< L3Protocol > getL3Protocol(Ptr< Object > node)
handles 'tables' config section
virtual void DoDispose(void)
Do cleanup.
nfd::StrategyChoiceManager & getStrategyChoiceManager()
Get nfd::StrategyChoiceManager, used by node's NFD.
void injectInterest(const Interest &interest)
Inject interest through internal Face.
static shared_ptr< CommandAuthenticator > create()
void addReserved(shared_ptr< Face > face, FaceId faceId)
add a special face with a reserved FaceId
IgnoreSections(const std::vector< std::string > &ignored)
static KeyChain & getKeyChain()
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
uint64_t FaceId
identifies a face
shared_ptr< Face > getFaceById(nfd::FaceId face) const
Get face by face ID.