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;
189 Ptr<ContentStore> m_csFromNdnSim;
196 NS_LOG_FUNCTION(
this);
201 NS_LOG_FUNCTION(
this);
205 L3Protocol::initialize()
207 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
209 initializeManagement();
215 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_rib_manager",
false)) {
216 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager,
this);
219 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
220 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
232 operator()(
const std::string& filename,
const std::string& sectionName,
236 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
241 std::vector<std::string> m_ignored;
247 m_impl->m_internalFace->sendInterest(interest);
253 m_impl->m_policy = policy;
257 L3Protocol::initializeManagement()
259 auto& forwarder = m_impl->m_forwarder;
266 m_impl->m_authenticator = CommandAuthenticator::create();
268 m_impl->m_fibManager.reset(
new FibManager(forwarder->getFib(),
269 forwarder->getFaceTable(),
270 *m_impl->m_dispatcher,
271 *m_impl->m_authenticator));
275 m_impl->m_faceManager.reset(
new FaceManager(forwarder->getFaceTable(),
276 *m_impl->m_dispatcher,
277 *m_impl->m_authenticator));
283 if (!this->
getConfig().get<
bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
285 *m_impl->m_dispatcher,
286 *m_impl->m_authenticator));
289 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
292 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_forwarder_status_manager",
false)) {
296 ConfigFile config(&ConfigFile::ignoreUnknownSection);
299 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
300 if (m_impl->m_csFromNdnSim ==
nullptr) {
301 forwarder->getCs().setPolicy(m_impl->m_policy());
307 m_impl->m_authenticator->setConfigFile(config);
310 m_impl->m_faceManager->setConfigFile(config);
314 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
319 Name topPrefix(
"/localhost/nfd");
320 auto entry = forwarder->getFib().insert(topPrefix).first;
321 entry->addNextHop(*(m_impl->m_internalFace), 0);
322 m_impl->m_dispatcher->addTopPrefix(topPrefix,
false);
326 L3Protocol::initializeRibManager()
331 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
335 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_dispatcherRib), *(m_impl->m_internalRibClientFace),
338 ConfigFile config([] (
const std::string& filename,
const std::string& sectionName,
342 if (sectionName !=
"rib" || sectionName ==
"log") {
347 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
351 m_impl->m_ribManager->setConfigFile(config);
354 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
356 m_impl->m_ribManager->registerWithNfd();
359 shared_ptr<nfd::Forwarder>
362 return m_impl->m_forwarder;
365 shared_ptr<nfd::FibManager>
368 return m_impl->m_fibManager;
371 shared_ptr<nfd::StrategyChoiceManager>
374 return m_impl->m_strategyChoiceManager;
380 return m_impl->m_config;
390 if (m_node ==
nullptr) {
391 m_node = GetObject<Node>();
392 if (m_node !=
nullptr) {
395 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
396 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
397 if (m_impl->m_csFromNdnSim !=
nullptr) {
398 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
403 Object::NotifyNewAggregate();
409 NS_LOG_FUNCTION(
this);
424 NS_LOG_FUNCTION(
this << face.get());
426 m_impl->m_forwarder->addFace(face);
428 std::weak_ptr<Face> weakFace = face;
431 face->afterReceiveInterest.connect([
this, weakFace](
const Interest& interest) {
432 shared_ptr<Face> face = weakFace.lock();
433 if (face !=
nullptr) {
434 this->m_inInterests(interest, *face);
438 face->afterReceiveData.connect([
this, weakFace](
const Data& data) {
439 shared_ptr<Face> face = weakFace.lock();
440 if (face !=
nullptr) {
441 this->m_inData(data, *face);
445 face->afterReceiveNack.connect([
this, weakFace](
const lp::Nack& nack) {
446 shared_ptr<Face> face = weakFace.lock();
447 if (face !=
nullptr) {
448 this->m_inNack(nack, *face);
452 auto tracingLink = face->getLinkService();
453 NS_LOG_LOGIC(
"Adding trace sources for afterSendInterest and afterSendData");
454 tracingLink->afterSendInterest.connect([
this, weakFace](
const Interest& interest) {
455 shared_ptr<Face> face = weakFace.lock();
456 if (face !=
nullptr) {
457 this->m_outInterests(interest, *face);
461 tracingLink->afterSendData.connect([
this, weakFace](
const Data& data) {
462 shared_ptr<Face> face = weakFace.lock();
463 if (face !=
nullptr) {
464 this->m_outData(data, *face);
468 tracingLink->afterSendNack.connect([
this, weakFace](
const lp::Nack& nack) {
469 shared_ptr<Face> face = weakFace.lock();
470 if (face !=
nullptr) {
471 this->m_outNack(nack, *face);
475 return face->getId();
481 return m_impl->m_forwarder->getFaceTable().get(
id)->shared_from_this();
487 for (
auto& i : m_impl->m_forwarder->getFaceTable()) {
489 if (transport ==
nullptr)
492 if (transport->GetNetDevice() == netDevice)
493 return i.shared_from_this();
501 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
502 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.
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
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...
shared_ptr< Face > getFaceByNetDevice(Ptr< NetDevice > netDevice) const
Remove face from ndn stack (remove callbacks)
ndn mgmt Dispatcher
Copyright (c) 2013-2016 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
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)
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore
shared_ptr< Face > getFaceById(nfd::FaceId face) const
Get face by face ID.
Scheduler & getGlobalScheduler()