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"
31 #include "ns3/random-variable.h"
36 #include "../helper/ndn-stack-helper.hpp"
39 #include <boost/property_tree/info_parser.hpp>
41 #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
42 #include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.hpp"
43 #include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp"
44 #include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp"
45 #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
46 #include "ns3/ndnSIM/NFD/daemon/mgmt/status-server.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 .AddTraceSource(
"InInterests",
"InInterests",
75 MakeTraceSourceAccessor(&L3Protocol::m_inInterests))
79 .AddTraceSource(
"OutData",
"OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData))
80 .AddTraceSource(
"InData",
"InData", MakeTraceSourceAccessor(&L3Protocol::m_inData))
84 .AddTraceSource(
"SatisfiedInterests",
"SatisfiedInterests",
85 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests))
86 .AddTraceSource(
"TimedOutInterests",
"TimedOutInterests",
87 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests))
97 std::string initialConfig =
104 " cs_max_packets 100\n"
108 " / /localhost/nfd/strategy/best-route\n"
109 " /localhost /localhost/nfd/strategy/broadcast\n"
110 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
111 " /ndn/broadcast /localhost/nfd/strategy/broadcast\n"
135 " localhost_security\n"
145 std::istringstream input(initialConfig);
146 boost::property_tree::read_info(input, m_config);
151 shared_ptr<nfd::Forwarder> m_forwarder;
153 shared_ptr<nfd::InternalFace> m_internalFace;
154 shared_ptr<nfd::FibManager> m_fibManager;
155 shared_ptr<nfd::FaceManager> m_faceManager;
156 shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
157 shared_ptr<nfd::StatusServer> m_statusServer;
161 Ptr<ContentStore> m_csFromNdnSim;
167 NS_LOG_FUNCTION(
this);
172 NS_LOG_FUNCTION(
this);
178 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
180 initializeManagement();
182 m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(),
nfd::FACEID_NULL);
184 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
185 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
197 operator()(
const std::string& filename,
const std::string& sectionName,
201 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
206 std::vector<std::string> m_ignored;
210 L3Protocol::initializeManagement()
213 auto& forwarder = m_impl->m_forwarder;
216 m_impl->m_internalFace = make_shared<InternalFace>();
218 m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()),
219 bind(&Forwarder::getFace, forwarder.get(), _1),
220 m_impl->m_internalFace, keyChain);
222 m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()),
223 m_impl->m_internalFace,
226 m_impl->m_strategyChoiceManager =
227 make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()),
228 m_impl->m_internalFace,
231 m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace,
235 ConfigFile config((IgnoreSections({
"general",
"log",
"rib"})));
240 forwarder->getStrategyChoice(),
241 forwarder->getMeasurements());
244 m_impl->m_internalFace->getValidator().setConfigFile(config);
248 m_impl->m_faceManager->setConfigFile(config);
251 config.parse(m_impl->m_config,
false,
"ndnSIM.conf");
253 tablesConfig.ensureTablesAreConfigured();
256 shared_ptr<fib::Entry> entry = forwarder->getFib().insert(
"/localhost/nfd").first;
257 entry->addNextHop(m_impl->m_internalFace, 0);
260 shared_ptr<nfd::Forwarder>
263 return m_impl->m_forwarder;
266 shared_ptr<nfd::FibManager>
269 return m_impl->m_fibManager;
272 shared_ptr<nfd::StrategyChoiceManager>
275 return m_impl->m_strategyChoiceManager;
281 return m_impl->m_config;
291 if (m_node ==
nullptr) {
292 m_node = GetObject<Node>();
293 if (m_node !=
nullptr) {
294 NS_ASSERT(m_impl->m_forwarder !=
nullptr);
295 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
296 if (m_impl->m_csFromNdnSim !=
nullptr) {
297 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
302 Object::NotifyNewAggregate();
308 NS_LOG_FUNCTION(
this);
318 NS_LOG_FUNCTION(
this << face.get());
320 m_impl->m_forwarder->addFace(face);
323 face->onReceiveInterest +=
324 [
this, face](
const Interest& interest) { this->m_inInterests(interest, *face); };
326 face->onSendInterest +=
327 [
this, face](
const Interest& interest) { this->m_outInterests(interest, *face); };
329 face->onReceiveData += [
this, face](
const Data& data) { this->m_inData(data, *face); };
331 face->onSendData += [
this, face](
const Data& data) { this->m_outData(data, *face); };
333 return face->getId();
345 return m_impl->m_forwarder->getFaceTable().get(
id);
351 for (
const auto& i : m_impl->m_forwarder->getFaceTable()) {
352 shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<
NetDeviceFace>(i);
353 if (netDeviceFace ==
nullptr)
356 if (netDeviceFace->GetNetDevice() == netDevice)
365 Ptr<L3Protocol> retval = node->GetObject<
L3Protocol>();
366 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.
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)
nfd::FaceId addFace(shared_ptr< Face > face)
Add face to NDN stack.
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)
void initialize()
Initialize NFD instance.
virtual void DoDispose(void)
Do cleanup.
IgnoreSections(const std::vector< std::string > &ignored)
static KeyChain & getKeyChain()
void setConfigFile(ConfigFile &configFile)