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" 27 #include "ns3/node-list.h" 28 #include "ns3/simulator.h" 30 #if HAVE_NS3_VISUALIZER 31 #include "../../visualizer/model/visual-simulator-impl.h" 32 #endif // HAVE_NS3_VISUALIZER 41 #include <boost/lexical_cast.hpp> 43 #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" 44 #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp" 45 #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp" 47 NS_LOG_COMPONENT_DEFINE(
"ndn.StackHelper");
53 : m_isForwarderStatusManagerDisabled(false)
54 , m_isStrategyChoiceManagerDisabled(false)
55 , m_needSetDefaultRoutes(false)
59 m_csPolicies.insert({
"nfd::cs::lru", [] {
return make_unique<nfd::cs::LruPolicy>(); }});
60 m_csPolicies.insert({
"nfd::cs::priority_fifo", [] () {
return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
62 m_csPolicyCreationFunc = m_csPolicies[
"nfd::cs::lru"];
64 m_ndnFactory.SetTypeId(
"ns3::ndn::L3Protocol");
66 m_netDeviceCallbacks.push_back(
67 std::make_pair(PointToPointNetDevice::GetTypeId(),
68 MakeCallback(&StackHelper::PointToPointNetDeviceCallback,
this)));
87 make_shared<ns3::ndn::time::CustomSystemClock>());
93 NS_LOG_FUNCTION(
this << needSet);
94 m_needSetDefaultRoutes = needSet;
99 const std::string& attr2,
const std::string& value2,
100 const std::string& attr3,
const std::string& value3,
101 const std::string& attr4,
const std::string& value4)
104 m_ndnFactory.Set(attr1, StringValue(value1));
106 m_ndnFactory.Set(attr2, StringValue(value2));
108 m_ndnFactory.Set(attr3, StringValue(value3));
110 m_ndnFactory.Set(attr4, StringValue(value4));
116 m_maxCsSize = maxSize;
122 auto found = m_csPolicies.find(policy);
123 if (
found != m_csPolicies.end()) {
124 m_csPolicyCreationFunc =
found->second;
127 NS_FATAL_ERROR(
"Cache replacement policy " << policy <<
" not found");
128 NS_LOG_DEBUG(
"Available cache replacement policies: ");
129 for (
auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
130 NS_LOG_DEBUG(
" " << it->first);
138 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
146 Install(NodeContainer::GetGlobal());
153 NS_FATAL_ERROR(
"Cannot re-install NDN stack on node " 157 Simulator::ScheduleWithContext(node->GetId(), Seconds(0), &StackHelper::doInstall,
this, node);
162 StackHelper::doInstall(Ptr<Node> node)
const 167 if (m_isForwarderStatusManagerDisabled) {
168 ndn->
getConfig().put(
"ndnSIM.disable_forwarder_status_manager",
true);
171 if (m_isStrategyChoiceManagerDisabled) {
172 ndn->getConfig().put(
"ndnSIM.disable_strategy_choice_manager",
true);
175 ndn->getConfig().put(
"tables.cs_max_packets", m_maxCsSize);
177 ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
180 node->AggregateObject(ndn);
182 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
183 Ptr<NetDevice> device = node->GetDevice(index);
189 this->createAndRegisterFace(node, ndn, device);
197 m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback));
204 for (
auto& i : m_netDeviceCallbacks) {
205 if (i.first == netDeviceType) {
216 m_netDeviceCallbacks.remove_if([&] (
const std::pair<TypeId, FaceCreateCallback>& i) {
217 return (i.first == netDeviceType);
224 std::string uri =
"netdev://";
225 Address address = netDevice->GetAddress();
226 if (Mac48Address::IsMatchingType(address)) {
227 uri +=
"[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) +
"]";
235 StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol>
ndn,
236 Ptr<NetDevice> netDevice)
const 238 NS_LOG_DEBUG(
"Creating default Face on node " << node->GetId());
241 ::nfd::face::GenericLinkService::Options opts;
242 opts.allowFragmentation =
true;
243 opts.allowReassembly =
true;
244 opts.allowCongestionMarking =
true;
246 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
248 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
250 "netdev://[ff:ff:ff:ff:ff:ff]");
256 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added Face as face #" 257 << face->getLocalUri());
263 StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
264 Ptr<NetDevice> device)
const 266 NS_LOG_DEBUG(
"Creating point-to-point Face on node " << node->GetId());
268 Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device);
269 NS_ASSERT(netDevice !=
nullptr);
272 Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel());
273 NS_ASSERT(channel !=
nullptr);
275 Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0);
276 if (remoteNetDevice->GetNode() == node)
277 remoteNetDevice = channel->GetDevice(1);
280 ::nfd::face::GenericLinkService::Options opts;
281 opts.allowFragmentation =
true;
282 opts.allowReassembly =
true;
283 opts.allowCongestionMarking =
true;
285 auto linkService = make_unique<::nfd::face::GenericLinkService>(opts);
287 auto transport = make_unique<NetDeviceTransport>(node, netDevice,
295 NS_LOG_LOGIC(
"Node " << node->GetId() <<
": added Face as face #" 296 << face->getLocalUri());
304 Ptr<Node> node = Names::Find<Node>(nodeName);
316 Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol>();
318 for (uint32_t index = 0; index < node->GetNDevices(); index++) {
320 Ptr<NetDevice> device = node->GetDevice(index);
322 if (ndn->getFaceByNetDevice(device) ==
nullptr) {
323 this->createAndRegisterFace(node, ndn, device);
331 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
339 Ptr<Node> node = Names::Find<Node>(nodeName);
346 Update(NodeContainer::GetGlobal());
350 StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device)
const 352 shared_ptr<Face> face;
354 for (
const auto& item : m_netDeviceCallbacks) {
355 if (device->GetInstanceTypeId() == item.first ||
356 device->GetInstanceTypeId().IsChildOf(item.first)) {
357 face = item.second(node, ndn, device);
364 face = DefaultNetDeviceCallback(node, ndn, device);
367 if (m_needSetDefaultRoutes) {
377 m_isStrategyChoiceManagerDisabled =
true;
383 m_isForwarderStatusManagerDisabled =
true;
389 for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i) {
390 auto ndn = NodeList::GetNode(i)->GetObject<
L3Protocol>();
394 for (
auto& face : ndn->getFaceTable()) {
396 if (transport ==
nullptr)
398 auto p2p =
dynamic_cast<PointToPointChannel*
>(&(*(transport->GetNetDevice()->GetChannel())));
399 TimeValue currentDelay;
400 p2p->GetAttribute(
"Delay", currentDelay);
401 face.setMetric((currentDelay.Get().ToDouble(Time::S)) * 1000);
403 std::cout <<
"Node " << i <<
": Face " << face.getId()
404 <<
" with metric " << face.getMetric() <<
"\n";
412 Simulator::Stop(Seconds(0));
413 #if HAVE_NS3_VISUALIZER 414 auto impl = DynamicCast<VisualSimulatorImpl>(Simulator::GetImplementation());
415 if (impl !=
nullptr) {
416 impl->RunRealSimulator();
423 #endif // HAVE_NS3_VISUALIZER 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.
static void ProcessWarmupEvents()
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.
static void SetLinkDelayAsFaceMetric()
Set face metric of all faces connected through PointToPoint channel to channel latency.
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.
ndnSIM-specific transport
void InstallAll() const
Install Ndn stack on all nodes in the simulation.
void disableForwarderStatusManager()
Disable Forwarder Status Manager.
std::string constructFaceUri(Ptr< NetDevice > netDevice)
void setCustomNdnCxxClocks()
Callback< shared_ptr< Face >, Ptr< Node >, Ptr< L3Protocol >, Ptr< NetDevice > > FaceCreateCallback
void Install(const std::string &nodeName) const
Install Ndn stack on the node.
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...
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 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 Strategy Choice Manager.