23 #include "ns3/names.h" 24 #include "ns3/string.h" 25 #include "ns3/point-to-point-net-device.h" 35 #include <boost/lexical_cast.hpp> 37 NS_LOG_COMPONENT_DEFINE(
"ndn.StackHelper");
43 : m_needSetDefaultRoutes(false)
45 , m_isRibManagerDisabled(false)
46 , m_isFaceManagerDisabled(false)
47 , m_isStatusServerDisabled(false)
48 , m_isStrategyChoiceManagerDisabled(false)
52 m_ndnFactory.SetTypeId(
"ns3::ndn::L3Protocol");
53 m_contentStoreFactory.SetTypeId(
"ns3::ndn::cs::Lru");
55 m_netDeviceCallbacks.push_back(
56 std::make_pair(PointToPointNetDevice::GetTypeId(),
57 MakeCallback(&StackHelper::PointToPointNetDeviceCallback,
this)));
68 static ::ndn::KeyChain keyChain(
"pib-dummy",
"tpm-dummy");
76 make_shared<ns3::ndn::time::CustomSystemClock>());
82 NS_LOG_FUNCTION(
this << needSet);
83 m_needSetDefaultRoutes = needSet;
88 const std::string& attr2,
const std::string& value2,
89 const std::string& attr3,
const std::string& value3,
90 const std::string& attr4,
const std::string& value4)
93 m_ndnFactory.Set(attr1, StringValue(value1));
95 m_ndnFactory.Set(attr2, StringValue(value2));
97 m_ndnFactory.Set(attr3, StringValue(value3));
99 m_ndnFactory.Set(attr4, StringValue(value4));
104 const std::string& value1,
const std::string& attr2,
105 const std::string& value2,
const std::string& attr3,
106 const std::string& value3,
const std::string& attr4,
107 const std::string& value4)
111 m_contentStoreFactory.SetTypeId(contentStore);
113 m_contentStoreFactory.Set(attr1, StringValue(value1));
115 m_contentStoreFactory.Set(attr2, StringValue(value2));
117 m_contentStoreFactory.Set(attr3, StringValue(value3));
119 m_contentStoreFactory.Set(attr4, StringValue(value4));
125 m_maxCsSize = maxSize;
131 Ptr<FaceContainer> faces = Create<FaceContainer>();
132 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
141 return Install(NodeContainer::GetGlobal());
147 Ptr<FaceContainer> faces = Create<FaceContainer>();
150 NS_FATAL_ERROR(
"Cannot re-install NDN stack on node " 157 if (m_isRibManagerDisabled) {
158 ndn->
getConfig().put(
"ndnSIM.disable_rib_manager",
true);
161 if (m_isFaceManagerDisabled) {
162 ndn->getConfig().put(
"ndnSIM.disable_face_manager",
true);
165 if (m_isStatusServerDisabled) {
166 ndn->getConfig().put(
"ndnSIM.disable_status_server",
true);
169 if (m_isStrategyChoiceManagerDisabled) {
170 ndn->getConfig().put(
"ndnSIM.disable_strategy_choice_manager",
true);
173 ndn->getConfig().put(
"tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize);
176 if (m_maxCsSize == 0) {
177 ndn->AggregateObject(m_contentStoreFactory.Create<
ContentStore>());
181 node->AggregateObject(ndn);
183 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
184 Ptr<NetDevice> device = node->GetDevice(index);
190 faces->Add(this->createAndRegisterFace(node, ndn, device));
200 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
207 for (
auto& i : m_netDeviceCallbacks) {
208 if (i.first == netDeviceType) {
219 m_netDeviceCallbacks.remove_if([&] (
const std::pair<TypeId, NetDeviceFaceCreateCallback>& i) {
220 return (i.first == netDeviceType);
224 shared_ptr<NetDeviceFace>
225 StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol>
ndn,
226 Ptr<NetDevice> netDevice)
const 228 NS_LOG_DEBUG(
"Creating default NetDeviceFace on node " << node->GetId());
230 shared_ptr<NetDeviceFace> face = std::make_shared<NetDeviceFace>(node, netDevice);
233 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added NetDeviceFace as face #" 234 << face->getLocalUri());
239 shared_ptr<NetDeviceFace>
240 StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
241 Ptr<NetDevice> device)
const 243 NS_LOG_DEBUG(
"Creating point-to-point NetDeviceFace on node " << node->GetId());
245 shared_ptr<NetDeviceFace> face = std::make_shared<NetDeviceFace>(node, device);
248 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added NetDeviceFace as face #" 249 << face->getLocalUri());
257 Ptr<Node> node = Names::Find<Node>(nodeName);
269 Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol>();
271 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
273 Ptr<NetDevice> device = node->GetDevice(index);
275 if (ndn->getFaceByNetDevice(device) ==
nullptr) {
276 this->createAndRegisterFace(node, ndn, device);
284 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
292 Ptr<Node> node = Names::Find<Node>(nodeName);
299 Update(NodeContainer::GetGlobal());
302 shared_ptr<NetDeviceFace>
303 StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device)
const 305 shared_ptr<NetDeviceFace> face;
307 for (
const auto& item : m_netDeviceCallbacks) {
308 if (device->GetInstanceTypeId() == item.first ||
309 device->GetInstanceTypeId().IsChildOf(item.first)) {
310 face = item.second(node, ndn, device);
317 face = DefaultNetDeviceCallback(node, ndn, device);
320 if (m_needSetDefaultRoutes) {
330 m_isRibManagerDisabled =
true;
336 m_isFaceManagerDisabled =
true;
342 m_isStrategyChoiceManagerDisabled =
true;
348 m_isStatusServerDisabled =
true;
void AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Add callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<NetDev...
void UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Update callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<Net...
virtual ~StackHelper()
Destroy the NdnStackHelper.
Copyright (c) 2011-2015 Regents of the University of California.
Ptr< FaceContainer > Install(const std::string &nodeName) const
Install Ndn stack on the node.
StackHelper()
Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy.
void setCsSize(size_t maxSize)
Set maximum size for NFD's Content Store (in number of packets)
void SetDefaultRoutes(bool needSet)
Set flag indicating necessity to install default routes in FIB.
nfd::ConfigSection & getConfig()
Get NFD config (boost::property_tree)
void SetStackAttributes(const std::string &attr1="", const std::string &value1="", const std::string &attr2="", const std::string &value2="", const std::string &attr3="", const std::string &value3="", const std::string &attr4="", const std::string &value4="")
Set parameters of NdnL3Protocol.
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
void RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Remove callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<Net...
void setCustomNdnCxxClocks()
Callback< shared_ptr< NetDeviceFace >, Ptr< Node >, Ptr< L3Protocol >, Ptr< NetDevice > > NetDeviceFaceCreateCallback
void disableFaceManager()
Disable Face Manager.
Ptr< FaceContainer > InstallAll() const
Install Ndn stack on all nodes in the simulation.
Copyright (c) 2011-2015 Regents of the University of California.
void disableRibManager()
Disable the RIB manager of NFD.
void SetOldContentStore(const std::string &contentStoreClass, const std::string &attr1="", const std::string &value1="", const std::string &attr2="", const std::string &value2="", const std::string &attr3="", const std::string &value3="", const std::string &attr4="", const std::string &value4="")
Set ndnSIM 1.0 content store implementation and its attributes.
Implementation network-layer of NDN stack.
void setCustomClocks(shared_ptr< CustomSteadyClock > steadyClock=nullptr, shared_ptr< CustomSystemClock > systemClock=nullptr)
Set custom system and steady clocks.
void disableStatusServer()
Disable Status Server.
void UpdateAll()
Update Ndn stack on all the nodes (Add faces for new devices)
static KeyChain & getKeyChain()
void Update(Ptr< Node > node)
Update Ndn stack on a given node (Add faces for new devices)
void disableStrategyChoiceManager()
Disable Strategy Choice Manager.
Base class for NDN content store.