Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame^] | 22 | #include "annotated-topology-reader.hpp" |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 24 | #include "ns3/nstime.h" |
| 25 | #include "ns3/log.h" |
| 26 | #include "ns3/assert.h" |
| 27 | #include "ns3/names.h" |
| 28 | #include "ns3/net-device-container.h" |
| 29 | #include "ns3/point-to-point-helper.h" |
| 30 | #include "ns3/point-to-point-net-device.h" |
| 31 | #include "ns3/internet-stack-helper.h" |
| 32 | #include "ns3/ipv4-address-helper.h" |
| 33 | #include "ns3/ipv4-global-routing-helper.h" |
| 34 | #include "ns3/drop-tail-queue.h" |
| 35 | #include "ns3/ipv4-interface.h" |
| 36 | #include "ns3/ipv4.h" |
| 37 | #include "ns3/string.h" |
| 38 | #include "ns3/pointer.h" |
| 39 | #include "ns3/uinteger.h" |
| 40 | #include "ns3/ipv4-address.h" |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame^] | 41 | #include "ns3/ndn-l3-protocol.hpp" |
| 42 | #include "ns3/ndn-face.hpp" |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 43 | #include "ns3/random-variable.h" |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 44 | #include "ns3/error-model.h" |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 45 | |
| 46 | #include "ns3/constant-position-mobility-model.h" |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 47 | |
| 48 | #include <boost/foreach.hpp> |
| 49 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 50 | #include <boost/tokenizer.hpp> |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 51 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 52 | #include <boost/graph/adjacency_list.hpp> |
| 53 | #include <boost/graph/graphviz.hpp> |
| 54 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 55 | #include <set> |
| 56 | |
Alexander Afanasyev | ff6e369 | 2012-07-30 00:11:02 -0700 | [diff] [blame] | 57 | #ifdef NS3_MPI |
| 58 | #include <ns3/mpi-interface.h> |
| 59 | #endif |
| 60 | |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 61 | using namespace std; |
| 62 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 63 | namespace ns3 { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 64 | |
| 65 | NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReader"); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 67 | AnnotatedTopologyReader::AnnotatedTopologyReader (const std::string &path, double scale/*=1.0*/) |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 68 | : m_path (path) |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 69 | , m_randX (0, 100.0) |
| 70 | , m_randY (0, 100.0) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 71 | , m_scale (scale) |
Alexander Afanasyev | ff6e369 | 2012-07-30 00:11:02 -0700 | [diff] [blame] | 72 | , m_requiredPartitions (1) |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 73 | { |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 74 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 75 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 76 | SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 77 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 79 | void |
| 80 | AnnotatedTopologyReader::SetBoundingBox (double ulx, double uly, double lrx, double lry) |
| 81 | { |
| 82 | NS_LOG_FUNCTION (this << ulx << uly << lrx << lry); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 84 | m_randX = UniformVariable (ulx, lrx); |
| 85 | m_randY = UniformVariable (uly, lry); |
| 86 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 88 | void |
| 89 | AnnotatedTopologyReader::SetMobilityModel (const std::string &model) |
| 90 | { |
| 91 | NS_LOG_FUNCTION (this << model); |
| 92 | m_mobilityFactory.SetTypeId (model); |
| 93 | } |
| 94 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 95 | AnnotatedTopologyReader::~AnnotatedTopologyReader () |
| 96 | { |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 97 | NS_LOG_FUNCTION (this); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 98 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 100 | Ptr<Node> |
Alexander Afanasyev | 0194543 | 2012-07-27 16:28:10 -0700 | [diff] [blame] | 101 | AnnotatedTopologyReader::CreateNode (const std::string name, uint32_t systemId) |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 102 | { |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 103 | NS_LOG_FUNCTION (this << name); |
| 104 | m_requiredPartitions = std::max (m_requiredPartitions, systemId + 1); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 106 | Ptr<Node> node = CreateObject<Node> (systemId); |
| 107 | |
| 108 | Names::Add (m_path, name, node); |
| 109 | m_nodes.Add (node); |
| 110 | |
| 111 | return node; |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | Ptr<Node> |
Alexander Afanasyev | 0194543 | 2012-07-27 16:28:10 -0700 | [diff] [blame] | 115 | AnnotatedTopologyReader::CreateNode (const std::string name, double posX, double posY, uint32_t systemId) |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 116 | { |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 117 | NS_LOG_FUNCTION (this << name << posX << posY); |
Alexander Afanasyev | ff6e369 | 2012-07-30 00:11:02 -0700 | [diff] [blame] | 118 | m_requiredPartitions = std::max (m_requiredPartitions, systemId + 1); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | 0194543 | 2012-07-27 16:28:10 -0700 | [diff] [blame] | 120 | Ptr<Node> node = CreateObject<Node> (systemId); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 121 | Ptr<MobilityModel> loc = DynamicCast<MobilityModel> (m_mobilityFactory.Create ()); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 122 | node->AggregateObject (loc); |
| 123 | |
| 124 | loc->SetPosition (Vector (posX, posY, 0)); |
| 125 | |
| 126 | Names::Add (m_path, name, node); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 127 | m_nodes.Add (node); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 128 | |
| 129 | return node; |
| 130 | } |
| 131 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 132 | NodeContainer |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 133 | AnnotatedTopologyReader::GetNodes () const |
| 134 | { |
| 135 | return m_nodes; |
| 136 | } |
| 137 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 138 | const std::list<TopologyReader::Link>& |
Ilya Moiseenko | ad9e8ab | 2012-01-11 19:58:34 -0800 | [diff] [blame] | 139 | AnnotatedTopologyReader::GetLinks () const |
| 140 | { |
| 141 | return m_linksList; |
| 142 | } |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 143 | |
| 144 | NodeContainer |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 145 | AnnotatedTopologyReader::Read (void) |
| 146 | { |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 147 | ifstream topgen; |
| 148 | topgen.open (GetFileName ().c_str ()); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 149 | |
Alexander Afanasyev | b5e54f9 | 2012-10-29 10:15:59 -0700 | [diff] [blame] | 150 | if ( !topgen.is_open () || !topgen.good () ) |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 151 | { |
Alexander Afanasyev | b5e54f9 | 2012-10-29 10:15:59 -0700 | [diff] [blame] | 152 | NS_FATAL_ERROR ("Cannot open file " << GetFileName () << " for reading"); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 153 | return m_nodes; |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 154 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 155 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 156 | while (!topgen.eof ()) |
| 157 | { |
| 158 | string line; |
| 159 | getline (topgen, line); |
| 160 | |
| 161 | if (line == "router") break; |
| 162 | } |
| 163 | |
Alexander Afanasyev | b5e54f9 | 2012-10-29 10:15:59 -0700 | [diff] [blame] | 164 | if (topgen.eof ()) |
| 165 | { |
| 166 | NS_FATAL_ERROR ("Topology file " << GetFileName () << " does not have \"router\" section"); |
| 167 | return m_nodes; |
| 168 | } |
| 169 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 170 | while (!topgen.eof ()) |
| 171 | { |
| 172 | string line; |
| 173 | getline (topgen,line); |
| 174 | if (line[0] == '#') continue; // comments |
| 175 | if (line=="link") break; // stop reading nodes |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 176 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 177 | istringstream lineBuffer (line); |
| 178 | string name, city; |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 179 | double latitude = 0, longitude = 0; |
Alexander Afanasyev | 0194543 | 2012-07-27 16:28:10 -0700 | [diff] [blame] | 180 | uint32_t systemId = 0; |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 181 | |
Alexander Afanasyev | 0194543 | 2012-07-27 16:28:10 -0700 | [diff] [blame] | 182 | lineBuffer >> name >> city >> latitude >> longitude >> systemId; |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 183 | if (name.empty ()) continue; |
| 184 | |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 185 | Ptr<Node> node; |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 186 | |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 187 | if (abs(latitude) > 0.001 && abs(latitude) > 0.001) |
| 188 | node = CreateNode (name, m_scale*longitude, -m_scale*latitude, systemId); |
| 189 | else |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 190 | { |
| 191 | UniformVariable var (0,200); |
| 192 | node = CreateNode (name, var.GetValue (), var.GetValue (), systemId); |
| 193 | // node = CreateNode (name, systemId); |
| 194 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | map<string, set<string> > processedLinks; // to eliminate duplications |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | b5e54f9 | 2012-10-29 10:15:59 -0700 | [diff] [blame] | 199 | if (topgen.eof ()) |
| 200 | { |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 201 | NS_LOG_ERROR ("Topology file " << GetFileName () << " does not have \"link\" section"); |
Alexander Afanasyev | b5e54f9 | 2012-10-29 10:15:59 -0700 | [diff] [blame] | 202 | return m_nodes; |
| 203 | } |
| 204 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 205 | // SeekToSection ("link"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 206 | while (!topgen.eof ()) |
| 207 | { |
| 208 | string line; |
| 209 | getline (topgen,line); |
| 210 | if (line == "") continue; |
| 211 | if (line[0] == '#') continue; // comments |
| 212 | |
| 213 | // NS_LOG_DEBUG ("Input: [" << line << "]"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 214 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 215 | istringstream lineBuffer (line); |
| 216 | string from, to, capacity, metric, delay, maxPackets, lossRate; |
| 217 | |
| 218 | lineBuffer >> from >> to >> capacity >> metric >> delay >> maxPackets >> lossRate; |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 219 | |
| 220 | if (processedLinks[to].size () != 0 && |
| 221 | processedLinks[to].find (from) != processedLinks[to].end ()) |
| 222 | { |
| 223 | continue; // duplicated link |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 224 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 225 | processedLinks[from].insert (to); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 226 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 227 | Ptr<Node> fromNode = Names::Find<Node> (m_path, from); |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 228 | NS_ASSERT_MSG (fromNode != 0, from << " node not found"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 229 | Ptr<Node> toNode = Names::Find<Node> (m_path, to); |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 230 | NS_ASSERT_MSG (toNode != 0, to << " node not found"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 231 | |
| 232 | Link link (fromNode, from, toNode, to); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 233 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 234 | link.SetAttribute ("DataRate", capacity); |
| 235 | link.SetAttribute ("OSPF", metric); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 236 | |
| 237 | if (!delay.empty ()) |
| 238 | link.SetAttribute ("Delay", delay); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 239 | if (!maxPackets.empty ()) |
| 240 | link.SetAttribute ("MaxPackets", maxPackets); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 241 | |
| 242 | // Saran Added lossRate |
| 243 | if (!lossRate.empty ()) |
| 244 | link.SetAttribute ("LossRate", lossRate); |
| 245 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 246 | AddLink (link); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 247 | NS_LOG_DEBUG ("New link " << from << " <==> " << to << " / " << capacity << " with " << metric << " metric (" << delay << ", " << maxPackets << ", " << lossRate << ")"); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 248 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 249 | |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 250 | NS_LOG_INFO ("Annotated topology created with " << m_nodes.GetN () << " nodes and " << LinksSize () << " links"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 251 | topgen.close (); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 253 | ApplySettings (); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 254 | |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 255 | return m_nodes; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 256 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 257 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 258 | void |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 259 | AnnotatedTopologyReader::AssignIpv4Addresses (Ipv4Address base) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 260 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 261 | Ipv4AddressHelper address (base, Ipv4Mask ("/24")); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 262 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 263 | BOOST_FOREACH (const Link &link, m_linksList) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 264 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 265 | address.Assign (NetDeviceContainer (link.GetFromNetDevice (), |
| 266 | link.GetToNetDevice ())); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 267 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 268 | base = Ipv4Address (base.Get () + 256); |
| 269 | address.SetBase (base, Ipv4Mask ("/24")); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 270 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 271 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 272 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 273 | void |
| 274 | AnnotatedTopologyReader::ApplyOspfMetric () |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 275 | { |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame] | 276 | BOOST_FOREACH (const Link &link, m_linksList) |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 277 | { |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 278 | NS_LOG_DEBUG ("OSPF: " << link.GetAttribute ("OSPF")); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 279 | uint16_t metric = boost::lexical_cast<uint16_t> (link.GetAttribute ("OSPF")); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 280 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 281 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 282 | Ptr<Ipv4> ipv4 = link.GetFromNode ()->GetObject<Ipv4> (); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 283 | if (ipv4 != 0) |
| 284 | { |
| 285 | int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetFromNetDevice ()); |
| 286 | NS_ASSERT (interfaceId >= 0); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 287 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 288 | ipv4->SetMetric (interfaceId,metric); |
| 289 | } |
| 290 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 291 | Ptr<ndn::L3Protocol> ndn = link.GetFromNode ()->GetObject<ndn::L3Protocol> (); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 292 | if (ndn != 0) |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 293 | { |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 294 | Ptr<ndn::Face> face = ndn->GetFaceByNetDevice (link.GetFromNetDevice ()); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 295 | NS_ASSERT (face != 0); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 296 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 297 | face->SetMetric (metric); |
| 298 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 299 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 300 | |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 301 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 302 | Ptr<Ipv4> ipv4 = link.GetToNode ()->GetObject<Ipv4> (); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 303 | if (ipv4 != 0) |
| 304 | { |
| 305 | int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetToNetDevice ()); |
| 306 | NS_ASSERT (interfaceId >= 0); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 307 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 308 | ipv4->SetMetric (interfaceId,metric); |
| 309 | } |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 310 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 311 | Ptr<ndn::L3Protocol> ndn = link.GetToNode ()->GetObject<ndn::L3Protocol> (); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 312 | if (ndn != 0) |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 313 | { |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 314 | Ptr<ndn::Face> face = ndn->GetFaceByNetDevice (link.GetToNetDevice ()); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 315 | NS_ASSERT (face != 0); |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 316 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 317 | face->SetMetric (metric); |
| 318 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 319 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | void |
| 324 | AnnotatedTopologyReader::ApplySettings () |
| 325 | { |
Alexander Afanasyev | ff6e369 | 2012-07-30 00:11:02 -0700 | [diff] [blame] | 326 | #ifdef NS3_MPI |
Alexander Afanasyev | b1b7f5d | 2012-08-09 09:59:43 -0700 | [diff] [blame] | 327 | if (MpiInterface::IsEnabled () && |
| 328 | MpiInterface::GetSize () != m_requiredPartitions) |
Alexander Afanasyev | ff6e369 | 2012-07-30 00:11:02 -0700 | [diff] [blame] | 329 | { |
| 330 | std::cerr << "MPI interface is enabled, but number of partitions (" << MpiInterface::GetSize () |
| 331 | << ") is not equal to number of partitions in the topology (" << m_requiredPartitions << ")"; |
| 332 | exit (-1); |
| 333 | } |
| 334 | #endif |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 335 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 336 | PointToPointHelper p2p; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 337 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 338 | BOOST_FOREACH (Link &link, m_linksList) |
| 339 | { |
Alexander Afanasyev | 5bcdc99 | 2012-11-19 22:25:55 -0800 | [diff] [blame] | 340 | // cout << "Link: " << Findlink.GetFromNode () << ", " << link.GetToNode () << endl; |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 341 | string tmp; |
| 342 | |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 343 | //////////////////////////////////////////////// |
| 344 | if (link.GetAttributeFailSafe ("MaxPackets", tmp)) |
| 345 | { |
| 346 | NS_LOG_INFO ("MaxPackets = " + link.GetAttribute ("MaxPackets")); |
| 347 | |
| 348 | try |
| 349 | { |
| 350 | uint32_t maxPackets = boost::lexical_cast<uint32_t> (link.GetAttribute ("MaxPackets")); |
| 351 | |
| 352 | // compatibility mode. Only DropTailQueue is supported |
| 353 | p2p.SetQueue ("ns3::DropTailQueue", |
| 354 | "MaxPackets", UintegerValue (maxPackets)); |
| 355 | } |
| 356 | catch (...) |
| 357 | { |
| 358 | typedef boost::tokenizer<boost::escaped_list_separator<char> > tokenizer; |
| 359 | tokenizer tok (link.GetAttribute ("MaxPackets")); |
| 360 | |
| 361 | tokenizer::iterator token = tok.begin (); |
| 362 | p2p.SetQueue (*token); |
| 363 | |
| 364 | for (token ++; token != tok.end (); token ++) |
| 365 | { |
| 366 | boost::escaped_list_separator<char> separator ('\\', '=', '\"'); |
| 367 | tokenizer attributeTok (*token, separator); |
| 368 | |
| 369 | tokenizer::iterator attributeToken = attributeTok.begin (); |
| 370 | |
| 371 | string attribute = *attributeToken; |
| 372 | attributeToken++; |
| 373 | |
| 374 | if (attributeToken == attributeTok.end ()) |
| 375 | { |
| 376 | NS_LOG_ERROR ("Queue attribute [" << *token << "] should be in form <Attribute>=<Value>"); |
| 377 | continue; |
| 378 | } |
| 379 | |
| 380 | string value = *attributeToken; |
| 381 | |
| 382 | p2p.SetQueueAttribute (attribute, StringValue (value)); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 387 | if (link.GetAttributeFailSafe ("DataRate", tmp)) |
| 388 | { |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 389 | NS_LOG_INFO ("DataRate = " + link.GetAttribute("DataRate")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 390 | p2p.SetDeviceAttribute ("DataRate", StringValue (link.GetAttribute ("DataRate"))); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 391 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 392 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 393 | if (link.GetAttributeFailSafe ("Delay", tmp)) |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 394 | { |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 395 | NS_LOG_INFO ("Delay = " + link.GetAttribute("Delay")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 396 | p2p.SetChannelAttribute ("Delay", StringValue (link.GetAttribute ("Delay"))); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 397 | } |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 398 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 399 | NetDeviceContainer nd = p2p.Install(link.GetFromNode (), link.GetToNode ()); |
| 400 | link.SetNetDevices (nd.Get (0), nd.Get (1)); |
| 401 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 402 | //////////////////////////////////////////////// |
| 403 | if (link.GetAttributeFailSafe ("LossRate", tmp)) |
| 404 | { |
| 405 | NS_LOG_INFO ("LinkError = " + link.GetAttribute("LossRate")); |
| 406 | |
| 407 | typedef boost::tokenizer<boost::escaped_list_separator<char> > tokenizer; |
| 408 | tokenizer tok (link.GetAttribute("LossRate")); |
| 409 | |
| 410 | tokenizer::iterator token = tok.begin (); |
| 411 | ObjectFactory factory (*token); |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 412 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 413 | for (token ++; token != tok.end (); token ++) |
| 414 | { |
| 415 | boost::escaped_list_separator<char> separator ('\\', '=', '\"'); |
| 416 | tokenizer attributeTok (*token, separator); |
| 417 | |
| 418 | tokenizer::iterator attributeToken = attributeTok.begin (); |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 419 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 420 | string attribute = *attributeToken; |
| 421 | attributeToken++; |
| 422 | |
| 423 | if (attributeToken == attributeTok.end ()) |
| 424 | { |
| 425 | NS_LOG_ERROR ("ErrorModel attribute [" << *token << "] should be in form <Attribute>=<Value>"); |
| 426 | continue; |
| 427 | } |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 428 | |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 429 | string value = *attributeToken; |
| 430 | |
| 431 | factory.Set (attribute, StringValue (value)); |
| 432 | } |
| 433 | |
| 434 | nd.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (factory.Create<ErrorModel> ())); |
| 435 | nd.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (factory.Create<ErrorModel> ())); |
| 436 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 437 | } |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 438 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 439 | |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 440 | void |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 441 | AnnotatedTopologyReader::SaveTopology (const std::string &file) |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 442 | { |
| 443 | ofstream os (file.c_str (), ios::trunc); |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 444 | os << "# any empty lines and lines starting with '#' symbol is ignored\n" |
| 445 | << "\n" |
| 446 | << "# The file should contain exactly two sections: router and link, each starting with the corresponding keyword\n" |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 447 | << "\n" |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 448 | << "# router section defines topology nodes and their relative positions (e.g., to use in visualizer)\n" |
| 449 | << "router\n" |
| 450 | << "\n" |
| 451 | << "# each line in this section represents one router and should have the following data\n" |
| 452 | << "# node comment yPos xPos\n"; |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 453 | |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 454 | for (NodeContainer::Iterator node = m_nodes.Begin (); |
| 455 | node != m_nodes.End (); |
| 456 | node++) |
| 457 | { |
| 458 | std::string name = Names::FindName (*node); |
| 459 | Ptr<MobilityModel> mobility = (*node)->GetObject<MobilityModel> (); |
| 460 | Vector position = mobility->GetPosition (); |
| 461 | |
Alexander Afanasyev | da02101 | 2012-06-28 14:11:46 -0700 | [diff] [blame] | 462 | os << name << "\t" << "NA" << "\t" << -position.y << "\t" << position.x << "\n"; |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 463 | } |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 464 | |
| 465 | os << "# link section defines point-to-point links between nodes and characteristics of these links\n" |
| 466 | << "\n" |
| 467 | << "link\n" |
| 468 | << "\n" |
| 469 | << "# Each line should be in the following format (only first two are required, the rest can be omitted)\n" |
| 470 | << "# srcNode dstNode bandwidth metric delay queue\n" |
| 471 | << "# bandwidth: link bandwidth\n" |
| 472 | << "# metric: routing metric\n" |
| 473 | << "# delay: link delay\n" |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 474 | << "# queue: MaxPackets for transmission queue on the link (both directions)\n" |
| 475 | << "# error: comma-separated list, specifying class for ErrorModel and necessary attributes\n"; |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 476 | |
| 477 | for (std::list<Link>::const_iterator link = m_linksList.begin (); |
| 478 | link != m_linksList.end (); |
| 479 | link ++) |
| 480 | { |
| 481 | os << Names::FindName (link->GetFromNode ()) << "\t"; |
| 482 | os << Names::FindName (link->GetToNode ()) << "\t"; |
| 483 | |
| 484 | string tmp; |
| 485 | if (link->GetAttributeFailSafe ("DataRate", tmp)) |
| 486 | os << link->GetAttribute("DataRate") << "\t"; |
| 487 | else |
| 488 | NS_FATAL_ERROR ("DataRate must be specified for the link"); |
| 489 | |
| 490 | if (link->GetAttributeFailSafe ("OSPF", tmp)) |
| 491 | os << link->GetAttribute("OSPF") << "\t"; |
| 492 | else |
| 493 | os << "1\t"; |
| 494 | |
| 495 | if (link->GetAttributeFailSafe ("Delay", tmp)) |
| 496 | { |
| 497 | os << link->GetAttribute("Delay") << "\t"; |
| 498 | |
| 499 | if (link->GetAttributeFailSafe ("MaxPackets", tmp)) |
| 500 | { |
| 501 | os << link->GetAttribute("MaxPackets") << "\t"; |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 502 | |
| 503 | if (link->GetAttributeFailSafe ("LossRate", tmp)) |
| 504 | { |
| 505 | os << link->GetAttribute ("LossRate") << "\t"; |
| 506 | } |
Alexander Afanasyev | 7102973 | 2012-11-19 23:50:52 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | os << "\n"; |
Alexander Afanasyev | da2f23a | 2013-04-14 22:52:50 -0700 | [diff] [blame] | 510 | } |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 513 | |
| 514 | template <class Names> |
| 515 | class name_writer { |
| 516 | public: |
| 517 | name_writer(Names _names) : names(_names) {} |
| 518 | |
| 519 | template <class VertexOrEdge> |
| 520 | void operator()(std::ostream& out, const VertexOrEdge& v) const { |
| 521 | // out << "[label=\"" << names[v] << "\",style=filled,fillcolor=\"" << colors[v] << "\"]"; |
| 522 | out << "[shape=\"circle\",width=0.1,label=\"\",style=filled,fillcolor=\"green\"]"; |
| 523 | } |
| 524 | private: |
| 525 | Names names; |
| 526 | }; |
| 527 | |
| 528 | template <class Names> |
| 529 | inline name_writer<Names> |
| 530 | make_name_writer(Names n) { |
| 531 | return name_writer<Names>(n); |
| 532 | } |
| 533 | |
| 534 | |
| 535 | void |
| 536 | AnnotatedTopologyReader::SaveGraphviz (const std::string &file) |
| 537 | { |
| 538 | typedef boost::adjacency_list_traits<boost::setS, boost::setS, boost::undirectedS> Traits; |
| 539 | |
| 540 | typedef boost::property< boost::vertex_name_t, std::string, boost::property |
| 541 | < boost::vertex_index_t, uint32_t > > nodeProperty; |
| 542 | |
| 543 | typedef boost::no_property edgeProperty; |
| 544 | |
| 545 | typedef boost::adjacency_list< boost::setS, boost::setS, boost::undirectedS, |
| 546 | nodeProperty, edgeProperty > Graph; |
| 547 | |
| 548 | typedef map<string, Traits::vertex_descriptor> node_map_t; |
| 549 | node_map_t graphNodes; |
| 550 | Graph graph; |
| 551 | |
| 552 | for (NodeContainer::Iterator node = m_nodes.Begin (); |
| 553 | node != m_nodes.End (); |
| 554 | node++) |
| 555 | { |
| 556 | std::pair<node_map_t::iterator, bool> |
| 557 | retval = graphNodes.insert (make_pair (Names::FindName (*node), |
| 558 | add_vertex (nodeProperty (Names::FindName (*node)), graph))); |
| 559 | // NS_ASSERT (ok == true); |
| 560 | |
| 561 | put (boost::vertex_index, graph, retval.first->second, (*node)->GetId ()); |
| 562 | } |
| 563 | |
| 564 | for (std::list<Link>::const_iterator link = m_linksList.begin (); |
| 565 | link != m_linksList.end (); |
| 566 | link ++) |
| 567 | { |
| 568 | node_map_t::iterator from = graphNodes.find (Names::FindName (link->GetFromNode ())); |
| 569 | node_map_t::iterator to = graphNodes.find (Names::FindName (link->GetToNode ())); |
| 570 | |
| 571 | // add_edge (node->second, otherNode->second, m_graph); |
| 572 | boost::add_edge (from->second, to->second, graph); |
| 573 | } |
Alexander Afanasyev | 0aa1136 | 2013-07-14 15:35:00 -0700 | [diff] [blame] | 574 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 575 | ofstream of (file.c_str ()); |
| 576 | boost::property_map<Graph, boost::vertex_name_t>::type names = get (boost::vertex_name, graph); |
| 577 | write_graphviz (of, graph, make_name_writer (names)); |
| 578 | } |
| 579 | |
| 580 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 581 | } |