blob: 5131daa1291b85057be35746607a245d152a677b [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
111 createTopology(std::initializer_list<std::initializer_list<std::string>/*node clique*/> topology);
112
113 /**
114 * @brief Create routes between topology nodes
115 * @throw std::invalid_argument if the nodes or links between nodes do not exist
116 *
117 * Example:
118 *
119 * helper.addRoutes({
120 * {"1", "2", "/prefix", 1},
121 * {"2", "3", "/prefix", 1}
122 * });
123 */
124 void
125 addRoutes(std::initializer_list<RouteInfo> routes);
126
127 /**
128 * @brief Create and install application on nodes
129 * @throw std::invalid_argument if the nodes or links between nodes do not exist
130 *
131 * Example:
132 *
133 * helper.addApps({
134 * {"1", "ns3::ndn::ConsumerCbr",
135 * {{"Prefix", "/prefix"}, {"Frequency", "1"}},
136 * "0s", "100s"},
137 * {"3", "ns3::ndn::Producer",
138 * {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
139 * "0s", "100s"}
140 * });
141 */
142 void
143 addApps(std::initializer_list<AppInfo> apps);
144
145public: // topology accessors
146 /**
147 * @brief Get node
148 * @throw std::invalid_argument if the node does not exist
149 */
150 Ptr<Node>
151 getNode(const std::string& nodeName);
152
153 /**
154 * @brief Get face on the @p node1 pointing towards @p node2
155 * @throw std::invalid_argument if the link does not exist
156 */
157 shared_ptr<Face>
158 getFace(const std::string& node1, const std::string& node2);
159
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800160 /**
161 * \brief Disable RIB Manager
162 */
163 void
164 disableRibManager();
165
166 /**
167 * \brief Disable Face Manager
168 */
169 void
170 disableFaceManager();
171
172 /**
173 * \brief Disable Strategy Choice Manager
174 */
175 void
176 disableStrategyChoiceManager();
177
178 /**
179 * \brief Disable Status Server
180 */
181 void
182 disableStatusServer();
183
Alexander Afanasyevabc0d912015-08-13 16:49:02 -0700184private:
185 Ptr<Node>
186 getOrCreateNode(const std::string& nodeName);
187
188private:
189 bool m_isTopologyInitialized;
190 StackHelper ndnHelper;
191 std::map<std::string, std::map<std::string, Ptr<NetDevice>>> links;
192 std::map<std::string, Ptr<Node>> nodes;
193};
194
195} // namespace ndn
196} // namespace ns3
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800197
198#endif // NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP