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 <<
"("
111 <<
") externals: \"%s\"(%d) "
112 <<
"name: " << name <<
" radius: " << radius);
125 unsigned int num_neigh = 0;
127 std::vector<std::string> neigh_list;
133 if (!argv[2].empty())
138 if (!argv[3].empty())
143 num_neigh_s = std::stoi(argv[4]);
151 num_neigh = num_neigh_s;
155 if (!argv[6].empty())
160 std::regex replace_regex(
"[<|>]");
161 std::regex_replace(std::back_inserter(temp),
168 std::regex split_regex(
"[ |\t]");
169 std::sregex_token_iterator
first{temp.begin(), temp.end(), split_regex, -1};
170 std::sregex_token_iterator last;
171 neigh_list = std::vector<std::string>{
first, last};
173 if (num_neigh != neigh_list.size())
175 NS_LOG_WARN(
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = "
176 << neigh_list.size());
180 if (!argv[7].empty())
186 if (!argv[8].empty())
191 radius = std::atoi(&argv[9][1]);
197 PrintNodeInfo(uid, loc, dns, bb, neigh_list.size(), name, radius);
205 std::string nodename =
"RocketFuelTopology/NodeName/" + uid;
212 for (
auto& nuid : neigh_list)
222 std::string nodename =
"RocketFuelTopology/NodeName/" + nuid;
248 std::string::size_type endptr;
253 std::stod(argv[2], &endptr);
255 if (argv[2].size() != endptr)
262 if (!sname.empty() && !tname.empty())
267 std::string nodename =
"RocketFuelTopology/NodeName/" + sname;
277 std::string nodename =
"RocketFuelTopology/NodeName/" + tname;
284 <<
" to: " << tname);
289 if ((iter->GetFromNode() ==
m_nodeMap[tname]) &&
333 std::ifstream topgen;
337 std::istringstream lineBuffer;
342 if (!topgen.is_open())
348 while (!topgen.eof())
350 std::vector<std::string> argv;
356 getline(topgen, line);
373 if (!ret || matches.empty())
375 NS_LOG_WARN(
"match failed (maps file): %s" << line);
382 if (!ret || matches.empty())
384 NS_LOG_WARN(
"match failed (weights file): %s" << line);
389 std::string matched_string;
391 for (
auto it = matches.begin() + 1; it != matches.end(); it++)
395 matched_string = it->str();
401 argv.push_back(matched_string);
414 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.