23#include "ns3/node-container.h"
47 static TypeId tid =
TypeId(
"ns3::RocketfuelTopologyReader")
49 .SetGroupName(
"TopologyReader")
75#define MAYSPACE "[ \t]*"
78#define ROCKETFUEL_MAPS_LINE \
79 START "(-*[0-9]+)" SPACE "(@[?A-Za-z0-9,+-]+)" SPACE "(\\+)*" MAYSPACE "(bb)*" MAYSPACE \
80 "\\(([0-9]+)\\)" SPACE "(&[0-9]+)*" MAYSPACE "->" MAYSPACE "(<[0-9 \t<>]+>)*" MAYSPACE \
81 "(\\{-[0-9\\{\\} \t-]+\\})*" SPACE "=([A-Za-z0-9.!-]+)" SPACE "r([0-9])" MAYSPACE END
84#define ROCKETFUEL_WEIGHTS_LINE START "([^ \t]+)" SPACE "([^ \t]+)" SPACE "([0-9.]+)" MAYSPACE END
113 std::vector<std::string>::size_type neighListSize,
118 NS_LOG_INFO(
"Load Node[" << uid <<
"]: location: " << loc <<
" dns: " << dns <<
" bb: " << bb
119 <<
" neighbors: " << neighListSize <<
"("
121 <<
") externals: \"%s\"(%d) "
122 <<
"name: " << name <<
" radius: " << radius);
135 unsigned int num_neigh = 0;
137 std::vector<std::string> neigh_list;
143 if (!argv[2].
empty())
148 if (!argv[3].
empty())
153 num_neigh_s = std::stoi(argv[4]);
161 num_neigh = num_neigh_s;
165 if (!argv[6].
empty())
170 std::regex replace_regex(
"[<|>]");
171 std::regex_replace(std::back_inserter(temp),
178 std::regex split_regex(
"[ |\t]");
179 std::sregex_token_iterator
first{temp.begin(), temp.end(), split_regex, -1};
180 std::sregex_token_iterator last;
181 neigh_list = std::vector<std::string>{
first, last};
183 if (num_neigh != neigh_list.size())
185 NS_LOG_WARN(
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = "
186 << neigh_list.size());
190 if (!argv[7].
empty())
196 if (!argv[8].
empty())
201 radius = std::atoi(&argv[9][1]);
207 PrintNodeInfo(uid, loc, dns, bb, neigh_list.size(), name, radius);
214 Ptr<Node> tmpNode = CreateObject<Node>();
220 for (
auto& nuid : neigh_list)
229 Ptr<Node> tmpNode = CreateObject<Node>();
254 std::string::size_type endptr;
259 std::stod(argv[2], &endptr);
261 if (argv[2].size() != endptr)
268 if (!sname.empty() && !tname.empty())
272 Ptr<Node> tmpNode = CreateObject<Node>();
280 Ptr<Node> tmpNode = CreateObject<Node>();
286 <<
" to: " << tname);
291 if ((iter->GetFromNode() ==
m_nodeMap[tname]) &&
339 std::ifstream topgen;
343 std::istringstream lineBuffer;
348 if (!topgen.is_open())
354 while (!topgen.eof())
357 std::vector<std::string> argv;
363 getline(topgen, line);
380 if (ret !=
true || matches.empty())
382 NS_LOG_WARN(
"match failed (maps file): %s" << line);
389 if (ret !=
true || matches.empty())
391 NS_LOG_WARN(
"match failed (weights file): %s" << line);
396 std::string matched_string;
398 for (
auto it = matches.begin() + 1; it != matches.end(); it++)
402 matched_string = it->str();
408 argv.push_back(matched_string);
421 NS_LOG_WARN(
"Unsupported file format (only Maps/Weights are supported)");
keep track of a set of node pointers.
Topology file reader (Rocketfuel-format type).
RF_FileType
Enum of the possible file types.
enum RF_FileType GetFileType(const std::string &buf)
Classifies the file type according to its content.
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.
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.
Empty class, used as a default parent class for SimpleRefCount.
#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.
#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 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_maps_regex(ROCKETFUEL_MAPS_LINE, std::regex::extended)
Build a Regex object for RocketFuel topology maps file type.
static const std::regex rocketfuel_weights_regex(ROCKETFUEL_WEIGHTS_LINE, std::regex::extended)
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.