NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-scenario-helper.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-scenario-helper.hpp"
21 #include "ndn-fib-helper.hpp"
22 #include "ndn-app-helper.hpp"
23 
24 #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
25 
26 #include "ns3/names.h"
27 #include "ns3/point-to-point-helper.h"
28 #include "ns3/string.h"
29 
30 namespace ns3 {
31 namespace ndn {
32 
34  : m_isTopologyInitialized(false)
35 {
36 }
37 
38 void
39 ScenarioHelper::createTopology(std::initializer_list<std::initializer_list<std::string>/*node clique*/> topology,
40  bool shouldInstallNdnStack)
41 {
42  if (m_isTopologyInitialized) {
43  throw std::logic_error("Topology cannot be created twice");
44  }
45 
46  PointToPointHelper p2p;
47 
48  for (auto&& clique : topology) {
49  for (auto i = clique.begin(); i != clique.end(); ++i) {
50  auto node1 = getOrCreateNode(*i);
51  for (auto j = i + 1; j != clique.end(); ++j) {
52  auto node2 = getOrCreateNode(*j);
53 
54  auto link = p2p.Install(node1, node2);
55  links[*i][*j] = link.Get(0);
56  links[*j][*i] = link.Get(1);
57  }
58  }
59  }
60 
61  if (shouldInstallNdnStack) {
62  ndnHelper.InstallAll();
63  }
64  m_isTopologyInitialized = true;
65 }
66 
67 void
69 {
70  ndnHelper.disableStrategyChoiceManager();
71 }
72 
73 void
75 {
77 }
78 
79 void
80 ScenarioHelper::addRoutes(std::initializer_list<ScenarioHelper::RouteInfo> routes)
81 {
82  for (auto&& route : routes) {
83  FibHelper::AddRoute(getNode(route.node1), route.prefix,
84  getFace(route.node1, route.node2), route.metric);
85  }
86 }
87 
88 void
89 ScenarioHelper::addApps(std::initializer_list<ScenarioHelper::AppInfo> apps)
90 {
91  for (auto&& app : apps) {
92  AppHelper appHelper(app.name);
93  for (auto&& param : app.params) {
94  appHelper.SetAttribute(param.first, StringValue(param.second));
95  }
96  auto installedApp = appHelper.Install(getNode(app.node));
97  installedApp.Start(Time(app.start));
98  installedApp.Stop(Time(app.end));
99  }
100 }
101 
102 Ptr<Node>
103 ScenarioHelper::getOrCreateNode(const std::string& nodeName)
104 {
105  auto node = nodes.find(nodeName);
106  if (node == nodes.end()) {
107  std::tie(node, std::ignore) = nodes.insert(std::make_pair(nodeName, CreateObject<Node>()));
108  Names::Add(nodeName, node->second);
109  }
110  return node->second;
111 }
112 
113 Ptr<Node>
114 ScenarioHelper::getNode(const std::string& nodeName)
115 {
116  auto node = nodes.find(nodeName);
117  if (node != nodes.end()) {
118  return node->second;
119  }
120 
121  throw std::invalid_argument("Node " + nodeName + " does not exist");
122 }
123 
124 shared_ptr<Face>
125 ScenarioHelper::getFace(const std::string& node1, const std::string& node2)
126 {
127  Ptr<NetDevice> netDevice = getNetDevice(node1, node2);
128  return netDevice->GetNode()->GetObject<L3Protocol>()->getFaceByNetDevice(netDevice);
129 }
130 
131 Ptr<NetDevice>
132 ScenarioHelper::getNetDevice(const std::string& node1, const std::string& node2)
133 {
134  auto i = links.find(node1);
135  if (i != links.end()) {
136  auto j = i->second.find(node2);
137  if (j != i->second.end()) {
138  return j->second;
139  }
140  }
141 
142  throw std::invalid_argument("Link between " + node1 + " and " + node2 + " does not exist");
143 }
144 
147 {
148  return ndnHelper;
149 }
150 
151 } // namespace ndn
152 } // namespace ns3
ns3::ndn::AppHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Definition: ndn-app-helper.cpp:49
ndn-scenario-helper.hpp
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ns3::ndn::ScenarioHelper::addRoutes
void addRoutes(std::initializer_list< RouteInfo > routes)
Create routes between topology nodes.
Definition: ndn-scenario-helper.cpp:80
ns3::ndn::StackHelper::disableStrategyChoiceManager
void disableStrategyChoiceManager()
Disable Strategy Choice Manager.
Definition: ndn-stack-helper.cpp:375
ns3::ndn::StackHelper::disableForwarderStatusManager
void disableForwarderStatusManager()
Disable Forwarder Status Manager.
Definition: ndn-stack-helper.cpp:381
ns3::ndn::ScenarioHelper::addApps
void addApps(std::initializer_list< AppInfo > apps)
Create and install application on nodes.
Definition: ndn-scenario-helper.cpp:89
ns3::ndn::ScenarioHelper::ScenarioHelper
ScenarioHelper()
Definition: ndn-scenario-helper.cpp:33
ns3::ndn::StackHelper::InstallAll
void InstallAll() const
Install Ndn stack on all nodes in the simulation.
Definition: ndn-stack-helper.cpp:144
ns3::ndn::AppHelper
A helper to make it easier to instantiate an ns3::ndn::App applications on a set of nodes.
Definition: ndn-app-helper.hpp:39
ndn-app-helper.hpp
ns3::ndn::ScenarioHelper::getFace
shared_ptr< Face > getFace(const std::string &node1, const std::string &node2)
Get face on the node1 pointing towards node2.
Definition: ndn-scenario-helper.cpp:125
ns3::ndn::FibHelper::AddRoute
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
Definition: ndn-fib-helper.cpp:85
ns3::ndn::ScenarioHelper::disableForwarderStatusManager
void disableForwarderStatusManager()
Disable Forwarder Status Manager.
Definition: ndn-scenario-helper.cpp:74
ns3::ndn::AppHelper::Install
ApplicationContainer Install(NodeContainer c)
Install an ns3::NdnConsumer on each node of the input container configured with all the attributes se...
Definition: ndn-app-helper.cpp:73
ndn-fib-helper.hpp
ns3::ndn::ScenarioHelper::disableStrategyChoiceManager
void disableStrategyChoiceManager()
Disable Strategy Choice Manager.
Definition: ndn-scenario-helper.cpp:68
ns3::ndn::ScenarioHelper::getNode
Ptr< Node > getNode(const std::string &nodeName)
Get node.
Definition: ndn-scenario-helper.cpp:114
ns3::ndn::ScenarioHelper::getNetDevice
Ptr< NetDevice > getNetDevice(const std::string &node1, const std::string &node2)
Get NetDevice on the node1 pointing towards node2.
Definition: ndn-scenario-helper.cpp:132
ns3::ndn::ScenarioHelper::getStackHelper
StackHelper & getStackHelper()
Get NDN stack helper, e.g., to adjust its parameters.
Definition: ndn-scenario-helper.cpp:146
ns3::ndn::StackHelper
Helper class to install NDN stack and configure its parameters.
Definition: ndn-stack-helper.hpp:55
ns3::ndn::L3Protocol
Implementation network-layer of NDN stack.
Definition: ndn-l3-protocol.hpp:81
ns3::ndn::ScenarioHelper::createTopology
void createTopology(std::initializer_list< std::initializer_list< std::string >> topology, bool shouldInstallNdnStack=true)
Create topology.
Definition: ndn-scenario-helper.cpp:39
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34