blob: 1c089f0a502eae761b0c1cbb7dff385829381a30 [file] [log] [blame]
Alexander Afanasyev957a84a2013-01-23 10:21:06 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08002/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev957a84a2013-01-23 10:21:06 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev957a84a2013-01-23 10:21:06 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080021
22#ifndef ROCKETFUEL_MAP_READER_H
23#define ROCKETFUEL_MAP_READER_H
24
Alexander Afanasyevdca091a2015-01-01 20:51:27 -080025#include "annotated-topology-reader.hpp"
26
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080027#include "ns3/net-device-container.h"
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080028#include "ns3/data-rate.h"
29
Alexander Afanasyevdca091a2015-01-01 20:51:27 -080030#include <set>
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080031#include <boost/graph/adjacency_list.hpp>
32
33using namespace std;
34
35namespace ns3 {
36
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037struct RocketfuelParams {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080038 double averageRtt;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 int clientNodeDegrees;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080040
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 // parameters for links Backbone <->Backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080042 string minb2bBandwidth;
43 string minb2bDelay;
44
45 string maxb2bBandwidth;
46 string maxb2bDelay;
47
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048 // parameters for links Backbone<->Gateway and Gateway <-> Gateway
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080049 string minb2gBandwidth;
50 string minb2gDelay;
51
52 string maxb2gBandwidth;
53 string maxb2gDelay;
54
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 // parameters for links Gateway <-> Customer
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080056 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 Afanasyevbe55cf62014-12-20 17:51:09 -080070 * In addition to reading specified topology from the .cch file, this class divides nodes into three
71 *categories:
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080072 * - 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 Afanasyevbe55cf62014-12-20 17:51:09 -080076 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080078 * network graph component.
79 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080class RocketfuelMapReader : public AnnotatedTopologyReader {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080081public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 RocketfuelMapReader(const std::string& path = "", double scale = 1.0,
83 const string& referenceOspfRate = "100Mbps");
84 virtual ~RocketfuelMapReader();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080085
86 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 * @brief Deprecated call. Read (RocketfuelParams params, bool keepOneComponent=true, bool
88 * connectBackbones=true) should be used instead
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080089 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 virtual NodeContainer
91 Read();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080092
93 /**
94 * \brief Main topology reading function.
95 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 * @param params parameters specifying range from which link bandwidths and delays should be
97 *assigned
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080098 * @param keepOneComponent if true, then only the largest connected component will be kept
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 * @param connectBackbones if true, then extra links will be added to ensure connectivity of
100 *estimated backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800101 *
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800110 Read(RocketfuelParams params, bool keepOneComponent = true, bool connectBackbones = true);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800111
112 const NodeContainer&
113 GetBackboneRouters() const;
114
115 const NodeContainer&
116 GetGatewayRouters() const;
117
118 const NodeContainer&
119 GetCustomerRouters() const;
120
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700121 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 SaveTopology(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800123
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700124 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800125 SaveGraphviz(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800126
127private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 RocketfuelMapReader(const RocketfuelMapReader&);
129 RocketfuelMapReader&
130 operator=(const RocketfuelMapReader&);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800131
132 // NodeContainer
133 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 GenerateFromMapsFile(int argc, char* argv[]);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800135
136 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 CreateLink(string nodeName1, string nodeName2, double averageRtt, const string& minBw,
138 const string& maxBw, const string& minDelay, const string& maxDelay);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800139 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140 KeepOnlyBiggestConnectedComponent();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800141
142 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800143 AssignClients(uint32_t clientDegree, uint32_t gwDegree);
144
145 void
146 ConnectBackboneRouters();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800147
148private:
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700149 Ptr<UniformRandomVariable> m_randVar;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800150
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800157 enum node_type_t { UNKNOWN = 0, CLIENT = 1, GATEWAY = 2, BACKBONE = 3 };
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800158
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 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 Afanasyev957a84a2013-01-23 10:21:06 -0800165
166 typedef boost::no_property edgeProperty;
167
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, nodeProperty,
169 edgeProperty> Graph;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800170
171 typedef map<string, Traits::vertex_descriptor> node_map_t;
172 node_map_t m_graphNodes;
173
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800174 Graph m_graph;
175 uint32_t m_maxNodeId;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800176
177 const DataRate m_referenceOspfRate; // reference rate of OSPF metric calculation
178
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800179private:
180 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800181 assignGw(Traits::vertex_descriptor vertex, uint32_t degree, node_type_t nodeType);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800182}; // end class RocketfuelMapReader
183
184}; // end namespace ns3
185
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800186#endif /* ROCKETFUEL_MAP_READER_H */