NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rocketfuel-weights-reader.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 // Based on the code by Hajime Tazaki <tazaki@sfc.wide.ad.jp>
21 
23 
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"
41 
42 #include "ns3/mobility-model.h"
43 
44 #include <regex.h>
45 
46 #include <boost/foreach.hpp>
47 #include <boost/lexical_cast.hpp>
48 
49 #include <iomanip>
50 #include <set>
51 
52 using namespace std;
53 
54 NS_LOG_COMPONENT_DEFINE("RocketfuelWeightsReader");
55 
56 namespace ns3 {
57 
58 RocketfuelWeightsReader::RocketfuelWeightsReader(const std::string& path /*=""*/,
59  double scale /*=1.0*/)
60  : AnnotatedTopologyReader(path, scale)
61  , m_defaultBandwidth("100Mbps")
62 {
63  NS_LOG_FUNCTION(this);
64 
65  // TypeId tid;
66  // bool ok = TypeId::LookupByNameFailSafe ("ns3::SpringMobilityModel", &tid);
67  // if (ok)
68  // SetMobilityModel ("ns3::SpringMobilityModel");
69  // else
70  // Use default mobility model (supplied by AnnotatedTopologyReader)
71 }
72 
74 {
75  NS_LOG_FUNCTION(this);
76 }
77 
78 void
80 {
81  m_inputType = inputType;
82 }
83 
84 NodeContainer
86 {
87  if (m_inputType == POSITIONS)
89 
90  ifstream topgen;
91  topgen.open(GetFileName().c_str());
92 
93  if (!topgen.is_open()) {
94  NS_LOG_ERROR("Cannot open file " << GetFileName() << " for reading");
95  return m_nodes;
96  }
97 
98  map<string, set<string>> processedLinks; // to eliminate duplications
99  bool repeatedRun = LinksSize() > 0;
100  std::list<Link>::iterator linkIterator = m_linksList.begin();
101 
102  while (!topgen.eof()) {
103  string line;
104  getline(topgen, line);
105  if (line == "")
106  continue;
107  if (line[0] == '#')
108  continue; // comments
109 
110  // NS_LOG_DEBUG ("Input: [" << line << "]");
111 
112  istringstream lineBuffer(line);
113  string from, to, attribute;
114 
115  lineBuffer >> from >> to >> attribute;
116 
117  if (processedLinks[to].size() != 0
118  && processedLinks[to].find(from) != processedLinks[to].end()) {
119  continue; // duplicated link
120  }
121  processedLinks[from].insert(to);
122 
123  Ptr<Node> fromNode = Names::Find<Node>(m_path, from);
124  if (fromNode == 0) {
125  fromNode = CreateNode(from, 0);
126  }
127 
128  Ptr<Node> toNode = Names::Find<Node>(m_path, to);
129  if (toNode == 0) {
130  toNode = CreateNode(to, 0);
131  }
132 
133  Link* link;
134  if (!repeatedRun)
135  link = new Link(fromNode, from, toNode, to);
136  else {
137  NS_ASSERT(linkIterator != m_linksList.end());
138  link = &(*linkIterator);
139 
140  linkIterator++;
141  }
142 
143  switch (m_inputType) {
144  case LINKS: {
145  // links only
146  // do nothing
147  break;
148  }
149  case WEIGHTS: {
150  if (attribute == "")
151  attribute = "1";
152  uint16_t metric = boost::lexical_cast<uint16_t>(attribute);
153  link->SetAttribute("OSPF", boost::lexical_cast<string>(metric));
154  break;
155  }
156  case LATENCIES:
157  if (attribute == "")
158  attribute = "1";
159 
160  link->SetAttribute("DataRate", m_defaultBandwidth);
161  link->SetAttribute("Delay", attribute + "ms");
162  if (!m_queue.empty()) {
163  link->SetAttribute("MaxPackets", m_queue);
164  }
165  break;
166  default:
167  ; //
168  }
169 
170  NS_LOG_DEBUG("Link " << from << " <==> " << to << " / " << attribute);
171  if (!repeatedRun) {
172  AddLink(*link);
173  delete link;
174  }
175  }
176 
177  topgen.close();
178 
179  if (!repeatedRun) {
180  NS_LOG_INFO("Rocketfuel topology created with " << m_nodes.GetN() << " nodes and "
181  << LinksSize() << " links");
182  }
183  return m_nodes;
184 }
185 
186 void
188 {
189  ApplySettings();
190 
191  // SpringMobilityHelper::InstallSprings (LinksBegin (), LinksEnd ());
192 }
193 
194 } /* namespace ns3 */
virtual NodeContainer Read(void)
Main topology reading function.
This class reads annotated topology and apply settings to the corresponding nodes and links...
void ApplySettings()
This method applies setting to corresponding nodes and links NetDeviceContainer must be allocated Nod...
virtual NodeContainer Read()
Main annotated topology reading function.
Ptr< Node > CreateNode(const std::string name, uint32_t systemId)