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/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/rib/rib-manager.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/core/config-file.hpp" 57 #include <ndn-cxx/mgmt/dispatcher.hpp> 59 NS_LOG_COMPONENT_DEFINE(
"ndn.L3Protocol");
73 TypeId(
"ns3::ndn::L3Protocol")
76 .AddConstructor<L3Protocol>()
78 .AddTraceSource(
"OutInterests",
"OutInterests",
79 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
80 "ns3::ndn::L3Protocol::InterestTraceCallback")
81 .AddTraceSource(
"InInterests",
"InInterests",
82 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
83 "ns3::ndn::L3Protocol::InterestTraceCallback")
87 .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")
94 .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")
101 .AddTraceSource(
"SatisfiedInterests",
"SatisfiedInterests",
102 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
103 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
104 .AddTraceSource(
"TimedOutInterests",
"TimedOutInterests",
105 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
106 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
116 std::string initialConfig =
123 " cs_max_packets 100\n" 127 " / /localhost/nfd/strategy/best-route\n" 128 " /localhost /localhost/nfd/strategy/multicast\n" 129 " /localhost/nfd /localhost/nfd/strategy/best-route\n" 130 " /ndn/multicast /localhost/nfd/strategy/multicast\n" 154 " localhost_security\n" 164 std::istringstream input(initialConfig);
165 boost::property_tree::read_info(input, m_config);
170 std::shared_ptr<nfd::Forwarder> m_forwarder;
172 std::shared_ptr<nfd::Face> m_internalFace;
173 std::shared_ptr<::ndn::Face> m_internalClientFace;
174 std::shared_ptr<nfd::CommandAuthenticator> m_authenticator;
176 std::shared_ptr<nfd::Face> m_internalRibFace;
177 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
179 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
180 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcherRib;
181 std::shared_ptr<nfd::FibManager> m_fibManager;
182 std::shared_ptr<nfd::FaceManager> m_faceManager;
183 std::shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
184 std::shared_ptr<nfd::ForwarderStatusManager> m_forwarderStatusManager;
185 std::shared_ptr<nfd::rib::RibManager> m_ribManager;
187 std::shared_ptr<nfd::face::FaceSystem> m_faceSystem;
191 Ptr<ContentStore> m_csFromNdnSim;
198 NS_LOG_FUNCTION(
this);
203 NS_LOG_FUNCTION(
this);
207 L3Protocol::initialize()
209 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
211 initializeManagement();
216 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_rib_manager",
false)) {
217 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager,
this);
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_internalFace->sendInterest(interest);
254 m_impl->m_policy = policy;
258 L3Protocol::initializeManagement()
260 auto& forwarder = m_impl->m_forwarder;
263 m_impl->m_faceSystem = make_shared<nfd::face::FaceSystem>(forwarder->getFaceTable(),
nullptr);
269 m_impl->m_authenticator = CommandAuthenticator::create();
271 m_impl->m_fibManager.reset(
new FibManager(forwarder->getFib(),
272 forwarder->getFaceTable(),
273 *m_impl->m_dispatcher,
274 *m_impl->m_authenticator));
279 m_impl->m_faceManager.reset(
new FaceManager(*m_impl->m_faceSystem,
280 *m_impl->m_dispatcher,
281 *m_impl->m_authenticator));
287 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
289 *m_impl->m_dispatcher,
290 *m_impl->m_authenticator));
293 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
296 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_forwarder_status_manager",
false)) {
303 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
304 if (m_impl->m_csFromNdnSim ==
nullptr) {
305 forwarder->getCs().setPolicy(m_impl->m_policy());
311 m_impl->m_authenticator->setConfigFile(config);
314 m_impl->m_faceManager->setConfigFile(config);
318 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
323 Name topPrefix(
"/localhost/nfd");
324 auto entry = forwarder->getFib().insert(topPrefix).first;
325 entry->addNextHop(*(m_impl->m_internalFace), 0);
326 m_impl->m_dispatcher->addTopPrefix(topPrefix,
false);
330 L3Protocol::initializeRibManager()
335 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
339 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_dispatcherRib), *(m_impl->m_internalRibClientFace),
342 ConfigFile config([] (
const std::string& filename,
const std::string& sectionName,
346 if (sectionName !=
"rib" || sectionName ==
"log") {
351 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
355 m_impl->m_ribManager->setConfigFile(
config);
358 config.parse(m_impl->m_config,
false,
"ndnSIM.conf");
360 m_impl->m_ribManager->registerWithNfd();
363 shared_ptr<nfd::Forwarder>
366 return m_impl->m_forwarder;
369 shared_ptr<nfd::FibManager>
372 return m_impl->m_fibManager;
375 shared_ptr<nfd::StrategyChoiceManager>
378 return m_impl->m_strategyChoiceManager;
384 return m_impl->m_config;
394 if (m_node ==
nullptr) {
395 m_node = GetObject<Node>();
396 if (m_node !=
nullptr) {
399 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
400 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
401 if (m_impl->m_csFromNdnSim !=
nullptr) {
402 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
407 Object::NotifyNewAggregate();
413 NS_LOG_FUNCTION(
this);
428 NS_LOG_FUNCTION(
this << face.get());
430 m_impl->m_forwarder->addFace(face);
432 std::weak_ptr<Face> weakFace = face;
435 face->afterReceiveInterest.connect([
this, weakFace](
const Interest& interest) {
436 shared_ptr<Face> face = weakFace.lock();
437 if (face !=
nullptr) {
438 this->m_inInterests(interest, *face);
442 face->afterReceiveData.connect([
this, weakFace](
const Data& data) {
443 shared_ptr<Face> face = weakFace.lock();
444 if (face !=
nullptr) {
445 this->m_inData(data, *face);
449 face->afterReceiveNack.connect([
this, weakFace](
const lp::Nack& nack) {
450 shared_ptr<Face> face = weakFace.lock();
451 if (face !=
nullptr) {
452 this->m_inNack(nack, *face);
456 auto tracingLink = face->getLinkService();
457 NS_LOG_LOGIC(
"Adding trace sources for afterSendInterest and afterSendData");
458 tracingLink->afterSendInterest.connect([
this, weakFace](
const Interest& interest) {
459 shared_ptr<Face> face = weakFace.lock();
460 if (face !=
nullptr) {
461 this->m_outInterests(interest, *face);
465 tracingLink->afterSendData.connect([
this, weakFace](
const Data& data) {
466 shared_ptr<Face> face = weakFace.lock();
467 if (face !=
nullptr) {
468 this->m_outData(data, *face);
472 tracingLink->afterSendNack.connect([
this, weakFace](
const lp::Nack& nack) {
473 shared_ptr<Face> face = weakFace.lock();
474 if (face !=
nullptr) {
475 this->m_outNack(nack, *face);
479 return face->getId();
485 return m_impl->m_forwarder->getFaceTable().get(
id)->shared_from_this();
491 for (
auto& i : m_impl->m_forwarder->getFaceTable()) {
493 if (transport ==
nullptr)
496 if (transport->GetNetDevice() == netDevice)
497 return i.shared_from_this();
505 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
506 NS_ASSERT_MSG(retval !=
nullptr,
"L3Protocol is not aggregated on this object");
shared_ptr< Face > getFaceByNetDevice(Ptr< NetDevice > netDevice) const
Remove face from ndn stack (remove callbacks)
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.
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
nfd::ConfigSection & getConfig()
Get NFD config (boost::property_tree)
configuration file parsing utility
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
shared_ptr< Face > getFaceById(nfd::FaceId face) const
Get face by face ID.
void ensureConfigured()
apply default configuration, if tables section was omitted in configuration file
ndnSIM-specific transport
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
implement the Forwarder Status of NFD Management Protocol.
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...
ndn mgmt Dispatcher
Copyright (c) 2013-2017 Regents of the University of California.
represents a Network Nack
static TypeId GetTypeId()
Interface ID.
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.
boost::property_tree::ptree ConfigSection
a config file section
L3Protocol()
Default constructor.
ndn L3Protocol
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< nfd::StrategyChoiceManager > getStrategyChoiceManager()
Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD.
Implementation network-layer of NDN stack.
static Ptr< L3Protocol > getL3Protocol(Ptr< Object > node)
handles 'tables' config section
virtual void DoDispose(void)
Do cleanup.
void injectInterest(const Interest &interest)
Inject interest through internal Face.
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
void parse(const std::string &filename, bool isDryRun)
void setConfigFile(ConfigFile &configFile)
Scheduler & getGlobalScheduler()