blob: 3303274596877b641d1c102b0ac6ba7d3bfa8c70 [file] [log] [blame]
Alexander Afanasyev957a84a2013-01-23 10:21:06 -08001/* -*- 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 Afanasyevdca091a2015-01-01 20:51:27 -080026#include "annotated-topology-reader.hpp"
27
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080028#include "ns3/net-device-container.h"
29#include "ns3/random-variable.h"
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080030#include "ns3/data-rate.h"
31
Alexander Afanasyevdca091a2015-01-01 20:51:27 -080032#include <set>
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080033#include <boost/graph/adjacency_list.hpp>
34
35using namespace std;
36
37namespace ns3 {
38
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039struct RocketfuelParams {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080040 double averageRtt;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 int clientNodeDegrees;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080042
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043 // parameters for links Backbone <->Backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080044 string minb2bBandwidth;
45 string minb2bDelay;
46
47 string maxb2bBandwidth;
48 string maxb2bDelay;
49
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 // parameters for links Backbone<->Gateway and Gateway <-> Gateway
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080051 string minb2gBandwidth;
52 string minb2gDelay;
53
54 string maxb2gBandwidth;
55 string maxb2gDelay;
56
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 // parameters for links Gateway <-> Customer
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080058 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 Afanasyevbe55cf62014-12-20 17:51:09 -080072 * In addition to reading specified topology from the .cch file, this class divides nodes into three
73 *categories:
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080074 * - 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 Afanasyevbe55cf62014-12-20 17:51:09 -080078 * 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 Afanasyev957a84a2013-01-23 10:21:06 -080080 * network graph component.
81 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082class RocketfuelMapReader : public AnnotatedTopologyReader {
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080083public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 RocketfuelMapReader(const std::string& path = "", double scale = 1.0,
85 const string& referenceOspfRate = "100Mbps");
86 virtual ~RocketfuelMapReader();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080087
88 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 * @brief Deprecated call. Read (RocketfuelParams params, bool keepOneComponent=true, bool
90 * connectBackbones=true) should be used instead
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080091 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 virtual NodeContainer
93 Read();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080094
95 /**
96 * \brief Main topology reading function.
97 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 * @param params parameters specifying range from which link bandwidths and delays should be
99 *assigned
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800100 * @param keepOneComponent if true, then only the largest connected component will be kept
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 * @param connectBackbones if true, then extra links will be added to ensure connectivity of
102 *estimated backbone
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800103 *
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800112 Read(RocketfuelParams params, bool keepOneComponent = true, bool connectBackbones = true);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800113
114 const NodeContainer&
115 GetBackboneRouters() const;
116
117 const NodeContainer&
118 GetGatewayRouters() const;
119
120 const NodeContainer&
121 GetCustomerRouters() const;
122
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700123 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800124 SaveTopology(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800125
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700126 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800127 SaveGraphviz(const std::string& file);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800128
129private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 RocketfuelMapReader(const RocketfuelMapReader&);
131 RocketfuelMapReader&
132 operator=(const RocketfuelMapReader&);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800133
134 // NodeContainer
135 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800136 GenerateFromMapsFile(int argc, char* argv[]);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800137
138 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139 CreateLink(string nodeName1, string nodeName2, double averageRtt, const string& minBw,
140 const string& maxBw, const string& minDelay, const string& maxDelay);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800141 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142 KeepOnlyBiggestConnectedComponent();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800143
144 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 AssignClients(uint32_t clientDegree, uint32_t gwDegree);
146
147 void
148 ConnectBackboneRouters();
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800149
150private:
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800159 enum node_type_t { UNKNOWN = 0, CLIENT = 1, GATEWAY = 2, BACKBONE = 3 };
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800160
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 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 Afanasyev957a84a2013-01-23 10:21:06 -0800167
168 typedef boost::no_property edgeProperty;
169
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800170 typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, nodeProperty,
171 edgeProperty> Graph;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800172
173 typedef map<string, Traits::vertex_descriptor> node_map_t;
174 node_map_t m_graphNodes;
175
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800176 Graph m_graph;
177 uint32_t m_maxNodeId;
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800178
179 const DataRate m_referenceOspfRate; // reference rate of OSPF metric calculation
180
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800181private:
182 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800183 assignGw(Traits::vertex_descriptor vertex, uint32_t degree, node_type_t nodeType);
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800184}; // end class RocketfuelMapReader
185
186}; // end namespace ns3
187
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800188#endif /* ROCKETFUEL_MAP_READER_H */