Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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. |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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. |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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 | |
| 20 | // Based on the code by Hajime Tazaki <tazaki@sfc.wide.ad.jp> |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 21 | |
| 22 | #ifndef ROCKETFUEL_MAP_READER_H |
| 23 | #define ROCKETFUEL_MAP_READER_H |
| 24 | |
Alexander Afanasyev | dca091a | 2015-01-01 20:51:27 -0800 | [diff] [blame] | 25 | #include "annotated-topology-reader.hpp" |
| 26 | |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 27 | #include "ns3/net-device-container.h" |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 28 | #include "ns3/data-rate.h" |
| 29 | |
Alexander Afanasyev | dca091a | 2015-01-01 20:51:27 -0800 | [diff] [blame] | 30 | #include <set> |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 31 | #include <boost/graph/adjacency_list.hpp> |
| 32 | |
| 33 | using namespace std; |
| 34 | |
| 35 | namespace ns3 { |
| 36 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 37 | struct RocketfuelParams { |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 38 | double averageRtt; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | int clientNodeDegrees; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | // parameters for links Backbone <->Backbone |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 42 | string minb2bBandwidth; |
| 43 | string minb2bDelay; |
| 44 | |
| 45 | string maxb2bBandwidth; |
| 46 | string maxb2bDelay; |
| 47 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 48 | // parameters for links Backbone<->Gateway and Gateway <-> Gateway |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 49 | string minb2gBandwidth; |
| 50 | string minb2gDelay; |
| 51 | |
| 52 | string maxb2gBandwidth; |
| 53 | string maxb2gDelay; |
| 54 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | // parameters for links Gateway <-> Customer |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 56 | string ming2cBandwidth; |
| 57 | string ming2cDelay; |
| 58 | |
| 59 | string maxg2cBandwidth; |
| 60 | string maxg2cDelay; |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * \brief Topology file reader and topology estimator (extension of Rocketfuel-format type). |
| 65 | * |
| 66 | * http://www.cs.washington.edu/research/networking/rocketfuel/ |
| 67 | * |
| 68 | * Only map file (.cch) is supported |
| 69 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | * In addition to reading specified topology from the .cch file, this class divides nodes into three |
| 71 | *categories: |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 72 | * - client nodes (nodes with degrees less or equal to RocketfuelParams.clientNodeDegrees |
| 73 | * - gateway nodes (nodes that directly connected to client nodes) |
| 74 | * - backbone nodes (all the rest) |
| 75 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | * As some of the .cch files do not give a connected network graph, this reader also allows to keep |
| 77 | *only the largest connected |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 78 | * network graph component. |
| 79 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | class RocketfuelMapReader : public AnnotatedTopologyReader { |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 81 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | RocketfuelMapReader(const std::string& path = "", double scale = 1.0, |
| 83 | const string& referenceOspfRate = "100Mbps"); |
| 84 | virtual ~RocketfuelMapReader(); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | * @brief Deprecated call. Read (RocketfuelParams params, bool keepOneComponent=true, bool |
| 88 | * connectBackbones=true) should be used instead |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 89 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | virtual NodeContainer |
| 91 | Read(); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * \brief Main topology reading function. |
| 95 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | * @param params parameters specifying range from which link bandwidths and delays should be |
| 97 | *assigned |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 98 | * @param keepOneComponent if true, then only the largest connected component will be kept |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 99 | * @param connectBackbones if true, then extra links will be added to ensure connectivity of |
| 100 | *estimated backbone |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 101 | * |
| 102 | * This method opens an input stream and reads the Rocketfuel-format file. |
| 103 | * Every row represents a topology link (the ids of a couple of nodes), |
| 104 | * so the input file is read line by line to figure out how many links |
| 105 | * and nodes are in the topology. |
| 106 | * |
| 107 | * \return the container of the nodes created (or empty container if there was an error) |
| 108 | */ |
| 109 | virtual NodeContainer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | Read(RocketfuelParams params, bool keepOneComponent = true, bool connectBackbones = true); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 111 | |
| 112 | const NodeContainer& |
| 113 | GetBackboneRouters() const; |
| 114 | |
| 115 | const NodeContainer& |
| 116 | GetGatewayRouters() const; |
| 117 | |
| 118 | const NodeContainer& |
| 119 | GetCustomerRouters() const; |
| 120 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 121 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 122 | SaveTopology(const std::string& file); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 123 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 124 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 125 | SaveGraphviz(const std::string& file); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 126 | |
| 127 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | RocketfuelMapReader(const RocketfuelMapReader&); |
| 129 | RocketfuelMapReader& |
| 130 | operator=(const RocketfuelMapReader&); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 131 | |
| 132 | // NodeContainer |
| 133 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | GenerateFromMapsFile(int argc, char* argv[]); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 135 | |
| 136 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 137 | CreateLink(string nodeName1, string nodeName2, double averageRtt, const string& minBw, |
| 138 | const string& maxBw, const string& minDelay, const string& maxDelay); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 139 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 140 | KeepOnlyBiggestConnectedComponent(); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 141 | |
| 142 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 143 | AssignClients(uint32_t clientDegree, uint32_t gwDegree); |
| 144 | |
| 145 | void |
| 146 | ConnectBackboneRouters(); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 147 | |
| 148 | private: |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame^] | 149 | Ptr<UniformRandomVariable> m_randVar; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 150 | |
| 151 | NodeContainer m_backboneRouters; |
| 152 | NodeContainer m_gatewayRouters; |
| 153 | NodeContainer m_customerRouters; |
| 154 | |
| 155 | typedef boost::adjacency_list_traits<boost::setS, boost::setS, boost::undirectedS> Traits; |
| 156 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 157 | enum node_type_t { UNKNOWN = 0, CLIENT = 1, GATEWAY = 2, BACKBONE = 3 }; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 158 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 159 | typedef boost:: |
| 160 | property<boost::vertex_name_t, std::string, |
| 161 | boost::property<boost::vertex_index_t, uint32_t, |
| 162 | boost::property<boost::vertex_rank_t, node_type_t, |
| 163 | boost::property<boost::vertex_color_t, std::string>>>> |
| 164 | nodeProperty; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 165 | |
| 166 | typedef boost::no_property edgeProperty; |
| 167 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 168 | typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, nodeProperty, |
| 169 | edgeProperty> Graph; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 170 | |
| 171 | typedef map<string, Traits::vertex_descriptor> node_map_t; |
| 172 | node_map_t m_graphNodes; |
| 173 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 174 | Graph m_graph; |
| 175 | uint32_t m_maxNodeId; |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 176 | |
| 177 | const DataRate m_referenceOspfRate; // reference rate of OSPF metric calculation |
| 178 | |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 179 | private: |
| 180 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 181 | assignGw(Traits::vertex_descriptor vertex, uint32_t degree, node_type_t nodeType); |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 182 | }; // end class RocketfuelMapReader |
| 183 | |
| 184 | }; // end namespace ns3 |
| 185 | |
Alexander Afanasyev | 957a84a | 2013-01-23 10:21:06 -0800 | [diff] [blame] | 186 | #endif /* ROCKETFUEL_MAP_READER_H */ |