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