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)
48 m_ndnFactory.SetTypeId(
"ns3::ndn::L3Protocol");
49 m_contentStoreFactory.SetTypeId(
"ns3::ndn::cs::Lru");
51 m_netDeviceCallbacks.push_back(
52 std::make_pair(PointToPointNetDevice::GetTypeId(),
53 MakeCallback(&StackHelper::PointToPointNetDeviceCallback,
this)));
64 static ::ndn::KeyChain keyChain(
"pib-dummy",
"tpm-dummy");
71 ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(),
72 make_shared<ns3::ndn::time::CustomSystemClock>());
78 NS_LOG_FUNCTION(
this << needSet);
79 m_needSetDefaultRoutes = needSet;
84 const std::string& attr2,
const std::string& value2,
85 const std::string& attr3,
const std::string& value3,
86 const std::string& attr4,
const std::string& value4)
89 m_ndnFactory.Set(attr1, StringValue(value1));
91 m_ndnFactory.Set(attr2, StringValue(value2));
93 m_ndnFactory.Set(attr3, StringValue(value3));
95 m_ndnFactory.Set(attr4, StringValue(value4));
100 const std::string& value1,
const std::string& attr2,
101 const std::string& value2,
const std::string& attr3,
102 const std::string& value3,
const std::string& attr4,
103 const std::string& value4)
107 m_contentStoreFactory.SetTypeId(contentStore);
109 m_contentStoreFactory.Set(attr1, StringValue(value1));
111 m_contentStoreFactory.Set(attr2, StringValue(value2));
113 m_contentStoreFactory.Set(attr3, StringValue(value3));
115 m_contentStoreFactory.Set(attr4, StringValue(value4));
121 m_maxCsSize = maxSize;
127 Ptr<FaceContainer> faces = Create<FaceContainer>();
128 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
137 return Install(NodeContainer::GetGlobal());
143 Ptr<FaceContainer> faces = Create<FaceContainer>();
146 NS_FATAL_ERROR(
"StackHelper::Install (): Installing "
147 "a NdnStack to a node with an existing Ndn object");
151 Ptr<L3Protocol> ndn = m_ndnFactory.Create<
L3Protocol>();
153 ndn->
getConfig().put(
"tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize);
159 if (m_maxCsSize == 0) {
160 ndn->AggregateObject(m_contentStoreFactory.Create<
ContentStore>());
164 node->AggregateObject(ndn);
166 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
167 Ptr<NetDevice> device = node->GetDevice(index);
173 shared_ptr<NetDeviceFace> face;
175 for (
const auto& item : m_netDeviceCallbacks) {
176 if (device->GetInstanceTypeId() == item.first ||
177 device->GetInstanceTypeId().IsChildOf(item.first)) {
178 face = item.second(node, ndn, device);
185 face = DefaultNetDeviceCallback(node, ndn, device);
188 if (m_needSetDefaultRoutes) {
203 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
210 for (
auto& i : m_netDeviceCallbacks) {
211 if (i.first == netDeviceType) {
222 m_netDeviceCallbacks.remove_if([&] (
const std::pair<TypeId, NetDeviceFaceCreateCallback>& i) {
223 return (i.first == netDeviceType);
227 shared_ptr<NetDeviceFace>
228 StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
229 Ptr<NetDevice> netDevice)
const
231 NS_LOG_DEBUG(
"Creating default NetDeviceFace on node " << node->GetId());
233 shared_ptr<NetDeviceFace> face = std::make_shared<NetDeviceFace>(node, netDevice);
236 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added NetDeviceFace as face #"
237 << face->getLocalUri());
242 shared_ptr<NetDeviceFace>
243 StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
244 Ptr<NetDevice> device)
const
246 NS_LOG_DEBUG(
"Creating point-to-point NetDeviceFace on node " << node->GetId());
248 shared_ptr<NetDeviceFace> face = std::make_shared<NetDeviceFace>(node, device);
251 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added NetDeviceFace as face #"
252 << face->getLocalUri());
260 Ptr<Node> node = Names::Find<Node>(nodeName);
void AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Add callback to create and configure instance of the face, based on supplied Ptr
and Ptr
void UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Update callback to create and configure instance of the face, based on supplied Ptr
and Ptr
virtual ~StackHelper()
Destroy the NdnStackHelper.
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.
void RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback)
Remove callback to create and configure instance of the face, based on supplied Ptr
and Ptr
void setCustomNdnCxxClocks()
Callback< shared_ptr< NetDeviceFace >, Ptr< Node >, Ptr< L3Protocol >, Ptr< NetDevice > > NetDeviceFaceCreateCallback
Ptr< FaceContainer > InstallAll() const
Install Ndn stack on all nodes in the simulation.
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.
static KeyChain & getKeyChain()
static void AddRoute(const std::string &nodeName, const Name &prefix, uint32_t faceId, int32_t metric)
Add forwarding entry to FIB.
Base class for NDN content store.