13#include "ns3/node-container.h"
37 static TypeId tid =
TypeId(
"ns3::RocketfuelTopologyReader")
39 .SetGroupName(
"TopologyReader")
65#define MAYSPACE "[ \t]*"
68#define ROCKETFUEL_MAPS_LINE \
69 START "(-*[0-9]+)" SPACE "(@[?A-Za-z0-9,+-]+)" SPACE "(\\+)*" MAYSPACE "(bb)*" MAYSPACE \
70 "\\(([0-9]+)\\)" SPACE "(&[0-9]+)*" MAYSPACE "->" MAYSPACE "(<[0-9 \t<>]+>)*" MAYSPACE \
71 "(\\{-[0-9\\{\\} \t-]+\\})*" SPACE "=([A-Za-z0-9.!-]+)" SPACE "r([0-9])" MAYSPACE END
74#define ROCKETFUEL_WEIGHTS_LINE START "([^ \t]+)" SPACE "([^ \t]+)" SPACE "([0-9.]+)" MAYSPACE END
103 std::vector<std::string>::size_type neighListSize,
108 NS_LOG_INFO(
"Load Node[" << uid <<
"]: location: " << loc <<
" dns: " << dns <<
" bb: " << bb
109 <<
" neighbors: " << neighListSize <<
"(%d) externals: \"%s\"(%d) "
110 <<
"name: " << name <<
" radius: " << radius);
123 unsigned int num_neigh = 0;
125 std::vector<std::string> neigh_list;
131 if (!argv[2].empty())
136 if (!argv[3].empty())
141 num_neigh_s = std::stoi(argv[4]);
149 num_neigh = num_neigh_s;
153 if (!argv[6].empty())
158 std::regex replace_regex(
"[<|>]");
159 std::regex_replace(std::back_inserter(temp),
166 std::regex split_regex(
"[ |\t]");
167 std::sregex_token_iterator
first{temp.begin(), temp.end(), split_regex, -1};
168 std::sregex_token_iterator last;
169 neigh_list = std::vector<std::string>{
first, last};
171 if (num_neigh != neigh_list.size())
173 NS_LOG_WARN(
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = "
174 << neigh_list.size());
178 if (!argv[7].empty())
184 if (!argv[8].empty())
189 radius = std::atoi(&argv[9][1]);
195 PrintNodeInfo(uid, loc, dns, bb, neigh_list.size(), name, radius);
203 std::string nodename =
"RocketFuelTopology/NodeName/" + uid;
210 for (
auto& nuid : neigh_list)
220 std::string nodename =
"RocketFuelTopology/NodeName/" + nuid;
246 std::string::size_type endptr;
251 double weight [[maybe_unused]] = std::stod(argv[2], &endptr);
253 if (argv[2].size() != endptr)
260 if (!sname.empty() && !tname.empty())
265 std::string nodename =
"RocketFuelTopology/NodeName/" + sname;
275 std::string nodename =
"RocketFuelTopology/NodeName/" + tname;
282 <<
" to: " << tname);
287 if ((iter->GetFromNode() ==
m_nodeMap[tname]) &&
331 std::ifstream topgen;
335 std::istringstream lineBuffer;
340 if (!topgen.is_open())
346 while (!topgen.eof())
348 std::vector<std::string> argv;
354 getline(topgen, line);
371 if (!ret || matches.empty())
373 NS_LOG_WARN(
"match failed (maps file): %s" << line);
380 if (!ret || matches.empty())
382 NS_LOG_WARN(
"match failed (weights file): %s" << line);
387 std::string matched_string;
389 for (
auto it = matches.begin() + 1; it != matches.end(); it++)
393 matched_string = it->str();
399 argv.push_back(matched_string);
412 NS_LOG_WARN(
"Unsupported file format (only Maps/Weights are supported)");
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Topology file reader (Rocketfuel-format type).
RF_FileType
Enum of the possible file types.
RocketfuelTopologyReader()
NodeContainer GenerateFromWeightsFile(const std::vector< std::string > &argv)
Topology read function from a file containing the nodes weights.
std::map< std::string, Ptr< Node > > m_nodeMap
Map of the nodes (name, node).
int m_nodesNumber
Number of nodes.
static TypeId GetTypeId()
Get the type ID.
RF_FileType GetFileType(const std::string &buf)
Classifies the file type according to its content.
NodeContainer GenerateFromMapsFile(const std::vector< std::string > &argv)
Topology read function from a file containing the nodes map.
~RocketfuelTopologyReader() override
NodeContainer Read() override
Main topology reading function.
int m_linksNumber
Number of links.
Inner class holding the details about a link between two nodes.
Interface for input file readers management.
void AddLink(Link link)
Adds a link to the topology.
ConstLinksIterator LinksEnd() const
Returns an iterator to the the last link in this block.
std::string GetFileName() const
Returns the input file name.
ConstLinksIterator LinksBegin() const
Returns an iterator to the the first link in this block.
std::list< Link >::const_iterator ConstLinksIterator
Constant iterator to the list of the links.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const std::regex rocketfuel_maps_regex(ROCKETFUEL_MAPS_LINE)
Build a Regex object for RocketFuel topology maps file type.
static void PrintNodeInfo(std::string &uid, std::string &loc, bool dns, bool bb, std::vector< std::string >::size_type neighListSize, std::string &name, int radius)
Print node info.
static const std::regex rocketfuel_weights_regex(ROCKETFUEL_WEIGHTS_LINE)
Build a Regex object for RocketFuel topology weights file type.
#define ROCKETFUEL_MAPS_LINE
Regex expression matching a MAP line.
#define ROCKETFUEL_WEIGHTS_LINE
Regex expression matching a WEIGHT line.
ns3::RocketfuelTopologyReader declaration.