blob: 59879d94e7f3cede42fde8f4afbbedf7d1804fb0 [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 Afanasyev0c395372014-12-20 15:54:02 -080026#include "ns3/annotated-topology-reader.hpp"
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080027#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
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 */