23 #include "ns3/names.h" 24 #include "ns3/string.h" 25 #include "ns3/point-to-point-net-device.h" 26 #include "ns3/point-to-point-channel.h" 36 #include <boost/lexical_cast.hpp> 38 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 39 #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp" 40 #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp" 42 NS_LOG_COMPONENT_DEFINE(
"ndn.StackHelper");
48 : m_isRibManagerDisabled(false)
50 , m_isForwarderStatusManagerDisabled(false)
51 , m_isStrategyChoiceManagerDisabled(false)
52 , m_needSetDefaultRoutes(false)
57 m_csPolicies.insert({
"nfd::cs::lru", [] {
return make_unique<nfd::cs::LruPolicy>(); }});
58 m_csPolicies.insert({
"nfd::cs::priority_fifo", [] () {
return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
60 m_csPolicyCreationFunc = m_csPolicies[
"nfd::cs::lru"];
62 m_ndnFactory.SetTypeId(
"ns3::ndn::L3Protocol");
63 m_contentStoreFactory.SetTypeId(
"ns3::ndn::cs::Lru");
65 m_netDeviceCallbacks.push_back(
66 std::make_pair(PointToPointNetDevice::GetTypeId(),
67 MakeCallback(&StackHelper::PointToPointNetDeviceCallback,
this)));
86 make_shared<ns3::ndn::time::CustomSystemClock>());
92 NS_LOG_FUNCTION(
this << needSet);
93 m_needSetDefaultRoutes = needSet;
98 const std::string& attr2,
const std::string& value2,
99 const std::string& attr3,
const std::string& value3,
100 const std::string& attr4,
const std::string& value4)
103 m_ndnFactory.Set(attr1, StringValue(value1));
105 m_ndnFactory.Set(attr2, StringValue(value2));
107 m_ndnFactory.Set(attr3, StringValue(value3));
109 m_ndnFactory.Set(attr4, StringValue(value4));
114 const std::string& value1,
const std::string& attr2,
115 const std::string& value2,
const std::string& attr3,
116 const std::string& value3,
const std::string& attr4,
117 const std::string& value4)
121 m_contentStoreFactory.SetTypeId(contentStore);
123 m_contentStoreFactory.Set(attr1, StringValue(value1));
125 m_contentStoreFactory.Set(attr2, StringValue(value2));
127 m_contentStoreFactory.Set(attr3, StringValue(value3));
129 m_contentStoreFactory.Set(attr4, StringValue(value4));
135 m_maxCsSize = maxSize;
141 auto found = m_csPolicies.find(policy);
142 if (found != m_csPolicies.end()) {
143 m_csPolicyCreationFunc = found->second;
146 NS_FATAL_ERROR(
"Cache replacement policy " << policy <<
" not found");
147 NS_LOG_DEBUG(
"Available cache replacement policies: ");
148 for (
auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
149 NS_LOG_DEBUG(
" " << it->first);
157 Ptr<FaceContainer> faces = Create<FaceContainer>();
158 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
167 return Install(NodeContainer::GetGlobal());
173 Ptr<FaceContainer> faces = Create<FaceContainer>();
176 NS_FATAL_ERROR(
"Cannot re-install NDN stack on node " 183 if (m_isRibManagerDisabled) {
184 ndn->getConfig().put(
"ndnSIM.disable_rib_manager",
true);
191 if (m_isForwarderStatusManagerDisabled) {
192 ndn->getConfig().put(
"ndnSIM.disable_forwarder_status_manager",
true);
195 if (m_isStrategyChoiceManagerDisabled) {
196 ndn->getConfig().put(
"ndnSIM.disable_strategy_choice_manager",
true);
199 ndn->getConfig().put(
"tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize);
202 if (m_maxCsSize == 0) {
207 ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
211 node->AggregateObject(
ndn);
213 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
214 Ptr<NetDevice> device = node->GetDevice(index);
220 faces->Add(this->createAndRegisterFace(node,
ndn, device));
230 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
237 for (
auto& i : m_netDeviceCallbacks) {
238 if (i.first == netDeviceType) {
249 m_netDeviceCallbacks.remove_if([&] (
const std::pair<TypeId, FaceCreateCallback>& i) {
250 return (i.first == netDeviceType);
257 std::string uri =
"netdev://";
258 Address address = netDevice->GetAddress();
259 if (Mac48Address::IsMatchingType(address)) {
260 uri +=
"[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) +
"]";
268 StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol>
ndn,
269 Ptr<NetDevice> netDevice)
const 271 NS_LOG_DEBUG(
"Creating default Face on node " << node->GetId());
276 opts.allowReassembly =
true;
277 opts.allowCongestionMarking =
true;
279 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
281 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
283 "netdev://[ff:ff:ff:ff:ff:ff]");
285 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
289 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added Face as face #" 290 <<
face->getLocalUri());
296 StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol>
ndn,
297 Ptr<NetDevice> device)
const 299 NS_LOG_DEBUG(
"Creating point-to-point Face on node " << node->GetId());
301 Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device);
302 NS_ASSERT(netDevice !=
nullptr);
305 Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel());
306 NS_ASSERT(channel !=
nullptr);
308 Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0);
309 if (remoteNetDevice->GetNode() == node)
310 remoteNetDevice = channel->GetDevice(1);
318 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
320 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
324 auto face = std::make_shared<Face>(std::move(linkService), std::move(transport));
328 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added Face as face #" 329 <<
face->getLocalUri());
337 Ptr<Node> node = Names::Find<Node>(nodeName);
351 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
353 Ptr<NetDevice> device = node->GetDevice(index);
355 if (
ndn->getFaceByNetDevice(device) ==
nullptr) {
356 this->createAndRegisterFace(node,
ndn, device);
364 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
372 Ptr<Node> node = Names::Find<Node>(nodeName);
379 Update(NodeContainer::GetGlobal());
383 StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol>
ndn, Ptr<NetDevice> device)
const 385 shared_ptr<Face>
face;
387 for (
const auto& item : m_netDeviceCallbacks) {
388 if (device->GetInstanceTypeId() == item.first ||
389 device->GetInstanceTypeId().IsChildOf(item.first)) {
390 face = item.second(node,
ndn, device);
397 face = DefaultNetDeviceCallback(node,
ndn, device);
400 if (m_needSetDefaultRoutes) {
410 m_isRibManagerDisabled =
true;
422 m_isStrategyChoiceManagerDisabled =
true;
428 m_isForwarderStatusManagerDisabled =
true;
virtual ~StackHelper()
Destroy the NdnStackHelper.
Copyright (c) 2011-2015 Regents of the University of California.
void setPolicy(const std::string &policy)
Set the cache replacement policy for NFD's Content Store.
StackHelper()
Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy.
bool allowReassembly
enables reassembly
void RemoveFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback)
Remove callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<Net...
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.
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 disableForwarderStatusManager()
Disable Forwarder Status Manager.
std::string constructFaceUri(Ptr< NetDevice > netDevice)
void setCustomNdnCxxClocks()
Ptr< FaceContainer > Install(const std::string &nodeName) const
Install Ndn stack on the node.
bool allowCongestionMarking
enables send queue congestion detection and marking
Callback< shared_ptr< Face >, Ptr< Node >, Ptr< L3Protocol >, Ptr< NetDevice > > FaceCreateCallback
Copyright (c) 2011-2015 Regents of the University of California.
void AddFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback)
Add callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<NetDev...
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.
Ptr< FaceContainer > InstallAll() const
Install Ndn stack on all nodes in the simulation.
Implementation network-layer of NDN stack.
void setCustomClocks(shared_ptr< CustomSteadyClock > steadyClock=nullptr, shared_ptr< CustomSystemClock > systemClock=nullptr)
Set custom system and steady clocks.
Options that control the behavior of GenericLinkService.
void UpdateAll()
Update Ndn stack on all the nodes (Add faces for new devices)
static KeyChain & getKeyChain()
void UpdateFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback)
Update callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<Net...
void Update(Ptr< Node > node)
Update Ndn stack on a given node (Add faces for new devices)
void disableStrategyChoiceManager()
Disable Face Manager.
Base class for NDN content store.
bool allowFragmentation
enables fragmentation