blob: 292bc855fc97e44fe740074f60cc9a92de99242e [file] [log] [blame]
Alexander Afanasyevabc0d912015-08-13 16:49:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
spirosmastorakis0df15ba2015-11-14 08:46:24 -080020#ifndef NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP
21#define NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP
22
Alexander Afanasyevabc0d912015-08-13 16:49:02 -070023#include "ndn-stack-helper.hpp"
24
25#include "ns3/net-device.h"
26#include "ns3/node.h"
27
28#include <ndn-cxx/name.hpp>
29#include <map>
30
31namespace ns3 {
32namespace ndn {
33
34/**
35 * @ingroup ndn-helpers
36 * @brief Helper class to simplify writing basic simulation scenarios
37 *
38 * The following code with scenario helper creates a 3-node topology,
39 * with manual routes between nodes and 2 applications, installed on first and last node
40 * of the topology:
41 *
42 * ScenarioHelper helper;
43 * helper.createTopology({
44 * {"1", "2"},
45 * {"2", "3"}
46 * });
47 *
48 * helper.addRoutes({
49 * {"1", "2", "/prefix", 1},
50 * {"2", "3", "/prefix", 1}
51 * });
52 *
53 * helper.addApps({
54 * {"1", "ns3::ndn::ConsumerCbr",
55 * {{"Prefix", "/prefix"}, {"Frequency", "1"}},
56 * "0s", "100s"},
57 * {"3", "ns3::ndn::Producer",
58 * {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
59 * "0s", "100s"}
60 * });
61 *
62 */
63class ScenarioHelper
64{
65public:
66 /**
67 * @brief Route information for addRoutes method
68 *
69 * It is preferred to use initializer list to indirectly pass RouteInfo's to addRoutes
70 * method.
71 */
72 struct RouteInfo
73 {
74 std::string node1;
75 std::string node2;
76 Name prefix;
77 int32_t metric;
78 };
79
80 /*
81 * @brief Application information for addApps method
82 *
83 * It is preferred to use initializer list to indirectly pass AppInfo's to addApps
84 * method.
85 */
86 struct AppInfo
87 {
88 std::string node;
89 std::string name;
90 std::initializer_list<std::pair<std::string, std::string>> params;
91 std::string start;
92 std::string end;
93 };
94
95public:
96 ScenarioHelper();
97
98 /**
99 * @brief Create topology
100 * @throw std::logic_error if createTopology is called more than once
101 *
102 * Example:
103 *
104 * ScenarioHelper helper;
105 * helper.createTopology({
106 * {"1", "2"},
107 * {"2", "3"}
108 * });
109 */
110 void
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700111 createTopology(std::initializer_list<std::initializer_list<std::string>/*node clique*/> topology,
112 bool shouldInstallNdnStack = true);
Alexander Afanasyevabc0d912015-08-13 16:49:02 -0700113
114 /**
115 * @brief Create routes between topology nodes
116 * @throw std::invalid_argument if the nodes or links between nodes do not exist
117 *
118 * Example:
119 *
120 * helper.addRoutes({
121 * {"1", "2", "/prefix", 1},
122 * {"2", "3", "/prefix", 1}
123 * });
124 */
125 void
126 addRoutes(std::initializer_list<RouteInfo> routes);
127
128 /**
129 * @brief Create and install application on nodes
130 * @throw std::invalid_argument if the nodes or links between nodes do not exist
131 *
132 * Example:
133 *
134 * helper.addApps({
135 * {"1", "ns3::ndn::ConsumerCbr",
136 * {{"Prefix", "/prefix"}, {"Frequency", "1"}},
137 * "0s", "100s"},
138 * {"3", "ns3::ndn::Producer",
139 * {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
140 * "0s", "100s"}
141 * });
142 */
143 void
144 addApps(std::initializer_list<AppInfo> apps);
145
146public: // topology accessors
147 /**
148 * @brief Get node
149 * @throw std::invalid_argument if the node does not exist
150 */
151 Ptr<Node>
152 getNode(const std::string& nodeName);
153
154 /**
155 * @brief Get face on the @p node1 pointing towards @p node2
156 * @throw std::invalid_argument if the link does not exist
157 */
158 shared_ptr<Face>
159 getFace(const std::string& node1, const std::string& node2);
160
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800161 /**
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700162 * @brief Get NetDevice on the @p node1 pointing towards @p node2
163 * @throw std::invalid_argument if the link does not exist
164 */
165 Ptr<NetDevice>
166 getNetDevice(const std::string& node1, const std::string& node2);
167
168 /**
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800169 * \brief Disable RIB Manager
170 */
171 void
172 disableRibManager();
173
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700174 // Cannot be disabled for now
175 // /**
176 // * \brief Disable Face Manager
177 // */
178 // void
179 // disableFaceManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800180
181 /**
182 * \brief Disable Strategy Choice Manager
183 */
184 void
185 disableStrategyChoiceManager();
186
187 /**
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700188 * \brief Disable Forwarder Status Manager
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800189 */
190 void
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700191 disableForwarderStatusManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800192
Alexander Afanasyevb4102ce2016-06-26 21:37:40 -0700193 /**
194 * \brief Get NDN stack helper, e.g., to adjust its parameters
195 */
196 StackHelper&
197 getStackHelper();
198
Alexander Afanasyevabc0d912015-08-13 16:49:02 -0700199private:
200 Ptr<Node>
201 getOrCreateNode(const std::string& nodeName);
202
203private:
204 bool m_isTopologyInitialized;
205 StackHelper ndnHelper;
206 std::map<std::string, std::map<std::string, Ptr<NetDevice>>> links;
207 std::map<std::string, Ptr<Node>> nodes;
208};
209
210} // namespace ndn
211} // namespace ns3
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800212
213#endif // NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP