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