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" 35 #include "../helper/ndn-stack-helper.hpp" 38 #include <boost/property_tree/info_parser.hpp> 40 #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" 41 #include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.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/status-server.hpp" 46 #include "ns3/ndnSIM/NFD/rib/rib-manager.hpp" 48 #include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp" 49 #include "ns3/ndnSIM/NFD/core/config-file.hpp" 50 #include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp" 51 #include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp" 53 NS_LOG_COMPONENT_DEFINE(
"ndn.L3Protocol");
67 TypeId(
"ns3::ndn::L3Protocol")
70 .AddConstructor<L3Protocol>()
72 .AddTraceSource(
"OutInterests",
"OutInterests",
73 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
74 "ns3::ndn::L3Protocol::InterestTraceCallback")
75 .AddTraceSource(
"InInterests",
"InInterests",
76 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
77 "ns3::ndn::L3Protocol::InterestTraceCallback")
81 .AddTraceSource(
"OutData",
"OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData),
82 "ns3::ndn::L3Protocol::DataTraceCallback")
83 .AddTraceSource(
"InData",
"InData", MakeTraceSourceAccessor(&L3Protocol::m_inData),
84 "ns3::ndn::L3Protocol::DataTraceCallback")
88 .AddTraceSource(
"SatisfiedInterests",
"SatisfiedInterests",
89 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
90 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
91 .AddTraceSource(
"TimedOutInterests",
"TimedOutInterests",
92 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
93 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
103 std::string initialConfig =
110 " cs_max_packets 100\n" 114 " / /localhost/nfd/strategy/best-route\n" 115 " /localhost /localhost/nfd/strategy/multicast\n" 116 " /localhost/nfd /localhost/nfd/strategy/best-route\n" 117 " /ndn/multicast /localhost/nfd/strategy/multicast\n" 141 " localhost_security\n" 151 std::istringstream input(initialConfig);
152 boost::property_tree::read_info(input, m_config);
157 shared_ptr<nfd::Forwarder> m_forwarder;
159 shared_ptr<nfd::InternalFace> m_internalFace;
160 shared_ptr<nfd::FibManager> m_fibManager;
161 shared_ptr<nfd::FaceManager> m_faceManager;
162 shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
163 shared_ptr<nfd::StatusServer> m_statusServer;
164 shared_ptr<nfd::rib::RibManager> m_ribManager;
165 shared_ptr< ::ndn::Face> m_face;
169 Ptr<ContentStore> m_csFromNdnSim;
175 NS_LOG_FUNCTION(
this);
180 NS_LOG_FUNCTION(
this);
184 L3Protocol::initialize()
186 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
188 initializeManagement();
190 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_rib_manager",
false)) {
191 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager,
this);
194 m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(),
nfd::FACEID_NULL);
196 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
197 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
209 operator()(
const std::string& filename,
const std::string& sectionName,
213 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
218 std::vector<std::string> m_ignored;
222 L3Protocol::initializeManagement()
225 auto& forwarder = m_impl->m_forwarder;
228 m_impl->m_internalFace = make_shared<InternalFace>();
230 m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()),
231 bind(&Forwarder::getFace, forwarder.get(), _1),
232 m_impl->m_internalFace, keyChain);
234 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_face_manager",
false)) {
235 m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()),
236 m_impl->m_internalFace,
240 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"faces");
243 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_strategy_choice_manager",
false)) {
244 m_impl->m_strategyChoiceManager =
245 make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()),
246 m_impl->m_internalFace,
250 this->
getConfig().get_child(
"authorizations").get_child(
"authorize").get_child(
"privileges").erase(
"strategy-choice");
253 if (!this->
getConfig().get<bool>(
"ndnSIM.disable_status_server",
false)) {
254 m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace,
264 forwarder->getStrategyChoice(),
265 forwarder->getMeasurements());
268 m_impl->m_internalFace->getValidator().setConfigFile(config);
272 m_impl->m_faceManager->setConfigFile(config);
275 config.parse(m_impl->m_config,
false,
"ndnSIM.conf");
277 tablesConfig.ensureTablesAreConfigured();
280 shared_ptr<fib::Entry> entry = forwarder->getFib().insert(
"/localhost/nfd").first;
281 entry->addNextHop(m_impl->m_internalFace, 0);
285 L3Protocol::initializeRibManager()
289 m_impl->m_face = make_shared< ::ndn::Face>();
290 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_face),
293 ConfigFile config([] (
const std::string& filename,
const std::string& sectionName,
297 if (sectionName !=
"rib" || sectionName ==
"log") {
302 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
306 m_impl->m_ribManager->setConfigFile(config);
309 config.
parse(m_impl->m_config,
false,
"ndnSIM.conf");
311 m_impl->m_ribManager->registerWithNfd();
313 m_impl->m_ribManager->enableLocalControlHeader();
316 shared_ptr<nfd::Forwarder>
319 return m_impl->m_forwarder;
322 shared_ptr<nfd::FibManager>
325 return m_impl->m_fibManager;
328 shared_ptr<nfd::StrategyChoiceManager>
331 return m_impl->m_strategyChoiceManager;
337 return m_impl->m_config;
347 if (m_node ==
nullptr) {
348 m_node = GetObject<Node>();
349 if (m_node !=
nullptr) {
352 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
353 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
354 if (m_impl->m_csFromNdnSim !=
nullptr) {
355 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
360 Object::NotifyNewAggregate();
366 NS_LOG_FUNCTION(
this);
376 NS_LOG_FUNCTION(
this << face.get());
378 m_impl->m_forwarder->addFace(face);
381 face->onReceiveInterest.connect
382 ([
this, face](
const Interest& interest) { this->m_inInterests(interest, *face); });
384 face->onSendInterest.connect
385 ([
this, face](
const Interest& interest) { this->m_outInterests(interest, *face); });
387 face->onReceiveData.connect([
this, face](
const Data& data) { this->m_inData(data, *face); });
389 face->onSendData.connect([
this, face](
const Data& data) { this->m_outData(data, *face); });
391 return face->getId();
403 return m_impl->m_forwarder->getFaceTable().get(
id);
409 for (
const auto& i : m_impl->m_forwarder->getFaceTable()) {
410 shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<
NetDeviceFace>(i);
411 if (netDeviceFace ==
nullptr)
414 if (netDeviceFace->GetNetDevice() == netDevice)
423 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
424 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.
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
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)
Implementation of layer-2 (Ethernet) Ndn face.
shared_ptr< Face > getFaceById(nfd::FaceId face) const
Get face by face ID.
void operator()(const std::string &filename, const std::string §ionName, const nfd::ConfigSection §ion, bool isDryRun)
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...
static TypeId GetTypeId()
Interface ID.
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.
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
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)
virtual void DoDispose(void)
Do cleanup.
IgnoreSections(const std::vector< std::string > &ignored)
static KeyChain & getKeyChain()
void parse(const std::string &filename, bool isDryRun)
void setConfigFile(ConfigFile &configFile)