Alexander Afanasyev | abc0d91 | 2015-08-13 16:49:02 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 20 | #ifndef NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP |
| 21 | #define NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP |
| 22 | |
Alexander Afanasyev | abc0d91 | 2015-08-13 16:49:02 -0700 | [diff] [blame] | 23 | #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 | |
| 31 | namespace ns3 { |
| 32 | namespace 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 | */ |
| 63 | class ScenarioHelper |
| 64 | { |
| 65 | public: |
| 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 | |
| 95 | public: |
| 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 Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 111 | createTopology(std::initializer_list<std::initializer_list<std::string>/*node clique*/> topology, |
| 112 | bool shouldInstallNdnStack = true); |
Alexander Afanasyev | abc0d91 | 2015-08-13 16:49:02 -0700 | [diff] [blame] | 113 | |
| 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 | |
| 146 | public: // 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 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 161 | /** |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 162 | * @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 | /** |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 169 | * \brief Disable Strategy Choice Manager |
| 170 | */ |
| 171 | void |
| 172 | disableStrategyChoiceManager(); |
| 173 | |
| 174 | /** |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 175 | * \brief Disable Forwarder Status Manager |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 176 | */ |
| 177 | void |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 178 | disableForwarderStatusManager(); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 179 | |
Alexander Afanasyev | b4102ce | 2016-06-26 21:37:40 -0700 | [diff] [blame] | 180 | /** |
| 181 | * \brief Get NDN stack helper, e.g., to adjust its parameters |
| 182 | */ |
| 183 | StackHelper& |
| 184 | getStackHelper(); |
| 185 | |
Alexander Afanasyev | abc0d91 | 2015-08-13 16:49:02 -0700 | [diff] [blame] | 186 | private: |
| 187 | Ptr<Node> |
| 188 | getOrCreateNode(const std::string& nodeName); |
| 189 | |
| 190 | private: |
| 191 | bool m_isTopologyInitialized; |
| 192 | StackHelper ndnHelper; |
| 193 | std::map<std::string, std::map<std::string, Ptr<NetDevice>>> links; |
| 194 | std::map<std::string, Ptr<Node>> nodes; |
| 195 | }; |
| 196 | |
| 197 | } // namespace ndn |
| 198 | } // namespace ns3 |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 199 | |
| 200 | #endif // NDNSIM_HELPER_NDN_SCENARIO_HELPER_HPP |