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-validator.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(
"SatisfiedInterests",
"SatisfiedInterests",
95 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
96 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
97 .AddTraceSource(
"TimedOutInterests",
"TimedOutInterests",
98 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
99 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
109 std::string initialConfig =
116 " cs_max_packets 100\n" 120 " / /localhost/nfd/strategy/best-route\n" 121 " /localhost /localhost/nfd/strategy/multicast\n" 122 " /localhost/nfd /localhost/nfd/strategy/best-route\n" 123 " /ndn/multicast /localhost/nfd/strategy/multicast\n" 147 " localhost_security\n" 157 std::istringstream input(initialConfig);
158 boost::property_tree::read_info(input, m_config);
163 std::shared_ptr<nfd::Forwarder> m_forwarder;
165 std::shared_ptr<nfd::Face> m_internalFace;
166 std::shared_ptr<::ndn::Face> m_internalClientFace;
167 std::unique_ptr<nfd::CommandValidator> m_validator;
169 std::shared_ptr<nfd::Face> m_internalRibFace;
170 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
172 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
173 std::shared_ptr<nfd::FibManager> m_fibManager;
174 std::shared_ptr<nfd::FaceManager> m_faceManager;
175 std::shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
176 std::shared_ptr<nfd::ForwarderStatusManager> m_forwarderStatusManager;
177 std::shared_ptr<nfd::rib::RibManager> m_ribManager;
181 Ptr<ContentStore> m_csFromNdnSim;
188 NS_LOG_FUNCTION(
this);
193 NS_LOG_FUNCTION(
this);
197 L3Protocol::initialize()
199 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
201 initializeManagement();
207 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_rib_manager",
false)) {
208 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager,
this);
211 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
212 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
224 operator()(
const std::string& filename,
const std::string& sectionName,
228 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
233 std::vector<std::string> m_ignored;
239 m_impl->m_internalFace->sendInterest(interest);
245 m_impl->m_policy = policy;
249 L3Protocol::initializeManagement()
251 auto& forwarder = m_impl->m_forwarder;
260 m_impl->m_fibManager.reset(
new FibManager(forwarder->getFib(),
261 bind(&Forwarder::getFace, forwarder.get(), _1),
262 *m_impl->m_dispatcher,
263 *m_impl->m_validator));
267 m_impl->m_faceManager.reset(
new FaceManager(forwarder->getFaceTable(),
268 *m_impl->m_dispatcher,
269 *m_impl->m_validator));
275 if (!this->
getConfig().get<
bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
277 *m_impl->m_dispatcher,
278 *m_impl->m_validator));
281 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
284 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_forwarder_status_manager",
false)) {
288 ConfigFile config(&ConfigFile::ignoreUnknownSection);
291 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
292 if (m_impl->m_csFromNdnSim ==
nullptr) {
293 forwarder->getCs().setPolicy(m_impl->m_policy());
299 forwarder->getStrategyChoice(),
300 forwarder->getMeasurements(),
301 forwarder->getNetworkRegionTable());
304 m_impl->m_validator->setConfigFile(config);
307 m_impl->m_faceManager->setConfigFile(config);
311 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
313 tablesConfig.ensureTablesAreConfigured();
316 Name topPrefix(
"/localhost/nfd");
317 auto entry = forwarder->getFib().insert(topPrefix).first;
318 entry->addNextHop(m_impl->m_internalFace, 0);
319 m_impl->m_dispatcher->addTopPrefix(topPrefix,
false);
323 L3Protocol::initializeRibManager()
328 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
329 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_internalRibClientFace),
332 ConfigFile config([] (
const std::string& filename,
const std::string& sectionName,
336 if (sectionName !=
"rib" || sectionName ==
"log") {
341 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
345 m_impl->m_ribManager->setConfigFile(config);
348 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
350 m_impl->m_ribManager->registerWithNfd();
352 m_impl->m_ribManager->enableLocalControlHeader();
355 shared_ptr<nfd::Forwarder>
358 return m_impl->m_forwarder;
361 shared_ptr<nfd::FibManager>
364 return m_impl->m_fibManager;
367 shared_ptr<nfd::StrategyChoiceManager>
370 return m_impl->m_strategyChoiceManager;
376 return m_impl->m_config;
386 if (m_node ==
nullptr) {
387 m_node = GetObject<Node>();
388 if (m_node !=
nullptr) {
391 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
392 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
393 if (m_impl->m_csFromNdnSim !=
nullptr) {
394 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
399 Object::NotifyNewAggregate();
405 NS_LOG_FUNCTION(
this);
420 NS_LOG_FUNCTION(
this << face.get());
422 m_impl->m_forwarder->addFace(face);
424 std::weak_ptr<Face> weakFace = face;
427 face->afterReceiveInterest.connect([
this, weakFace](
const Interest& interest) {
428 shared_ptr<Face> face = weakFace.lock();
429 if (face !=
nullptr) {
430 this->m_inInterests(interest, *face);
434 face->afterReceiveData.connect([
this, weakFace](
const Data& data) {
435 shared_ptr<Face> face = weakFace.lock();
436 if (face !=
nullptr) {
437 this->m_inData(data, *face);
442 auto tracingLink = face->getLinkService();
443 NS_LOG_LOGIC(
"Adding trace sources for afterSendInterest and afterSendData");
444 tracingLink->afterSendInterest.connect([
this, weakFace](
const Interest& interest) {
445 shared_ptr<Face> face = weakFace.lock();
446 if (face !=
nullptr) {
447 this->m_outInterests(interest, *face);
451 tracingLink->afterSendData.connect([
this, weakFace](
const Data& data) {
452 shared_ptr<Face> face = weakFace.lock();
453 if (face !=
nullptr) {
454 this->m_outData(data, *face);
460 return face->getId();
466 return m_impl->m_forwarder->getFaceTable().get(
id);
472 for (
const auto& i : m_impl->m_forwarder->getFaceTable()) {
474 if (linkService ==
nullptr)
477 if (linkService->GetNetDevice() == netDevice)
486 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
487 NS_ASSERT_MSG(retval !=
nullptr,
"L3Protocol is not aggregated on this object");
Implementation of layer-2 (Ethernet) LinkService (current hack, to be changed eventually) ...
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)
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
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)
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)
Provides parsing for tables configuration file 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()