blob: 3cf5ee22f16f1a63c93169d6726d74ed27797dda [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"
28#include "ns3/random-variable.h"
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080029#include "ns3/data-rate.h"
30
Alexander Afanasyevdca091a2015-01-01 20:51:27 -080031#include <set>
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080032#include <boost/graph/adjacency_list.hpp>
33
34using namespace std;
35
36namespace ns3 {
37
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038struct RocketfuelParams {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080039 double averageRtt;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 int clientNodeDegrees;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080041
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042 // parameters for links Backbone <->Backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080043 string minb2bBandwidth;
44 string minb2bDelay;
45
46 string maxb2bBandwidth;
47 string maxb2bDelay;
48
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 // parameters for links Backbone<->Gateway and Gateway <-> Gateway
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080050 string minb2gBandwidth;
51 string minb2gDelay;
52
53 string maxb2gBandwidth;
54 string maxb2gDelay;
55
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 // parameters for links Gateway <-> Customer
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080057 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 Afanasyevbe55cf62014-12-20 17:51:09 -080071 * In addition to reading specified topology from the .cch file, this class divides nodes into three
72 *categories:
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080073 * - 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 Afanasyevbe55cf62014-12-20 17:51:09 -080077 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080079 * network graph component.
80 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081class RocketfuelMapReader : public AnnotatedTopologyReader {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080082public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 RocketfuelMapReader(const std::string& path = "", double scale = 1.0,
84 const string& referenceOspfRate = "100Mbps");
85 virtual ~RocketfuelMapReader();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080086
87 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 * @brief Deprecated call. Read (RocketfuelParams params, bool keepOneComponent=true, bool
89 * connectBackbones=true) should be used instead
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080090 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 virtual NodeContainer
92 Read();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080093
94 /**
95 * \brief Main topology reading function.
96 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 * @param params parameters specifying range from which link bandwidths and delays should be
98 *assigned
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080099 * @param keepOneComponent if true, then only the largest connected component will be kept
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 * @param connectBackbones if true, then extra links will be added to ensure connectivity of
101 *estimated backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800102 *
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800111 Read(RocketfuelParams params, bool keepOneComponent = true, bool connectBackbones = true);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800112
113 const NodeContainer&
114 GetBackboneRouters() const;
115
116 const NodeContainer&
117 GetGatewayRouters() const;
118
119 const NodeContainer&
120 GetCustomerRouters() const;
121
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700122 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 SaveTopology(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800124
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700125 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 SaveGraphviz(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800127
128private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129 RocketfuelMapReader(const RocketfuelMapReader&);
130 RocketfuelMapReader&
131 operator=(const RocketfuelMapReader&);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800132
133 // NodeContainer
134 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 GenerateFromMapsFile(int argc, char* argv[]);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800136
137 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 CreateLink(string nodeName1, string nodeName2, double averageRtt, const string& minBw,
139 const string& maxBw, const string& minDelay, const string& maxDelay);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800140 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 KeepOnlyBiggestConnectedComponent();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800142
143 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 AssignClients(uint32_t clientDegree, uint32_t gwDegree);
145
146 void
147 ConnectBackboneRouters();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800148
149private:
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800158 enum node_type_t { UNKNOWN = 0, CLIENT = 1, GATEWAY = 2, BACKBONE = 3 };
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800159
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 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 Afanasyev957a84a2013-01-23 10:21:06 -0800166
167 typedef boost::no_property edgeProperty;
168
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800169 typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, nodeProperty,
170 edgeProperty> Graph;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800171
172 typedef map<string, Traits::vertex_descriptor> node_map_t;
173 node_map_t m_graphNodes;
174
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 Graph m_graph;
176 uint32_t m_maxNodeId;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800177
178 const DataRate m_referenceOspfRate; // reference rate of OSPF metric calculation
179
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800180private:
181 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800182 assignGw(Traits::vertex_descriptor vertex, uint32_t degree, node_type_t nodeType);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800183}; // end class RocketfuelMapReader
184
185}; // end namespace ns3
186
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800187#endif /* ROCKETFUEL_MAP_READER_H */