23 #include "ns3/names.h"
24 #include "ns3/node-container.h"
48 static TypeId tid =
TypeId(
"ns3::RocketfuelTopologyReader")
50 .SetGroupName(
"TopologyReader")
74 #define SPACE "[ \t]+"
76 #define MAYSPACE "[ \t]*"
79 #define ROCKETFUEL_MAPS_LINE \
80 START "(-*[0-9]+)" SPACE "(@[?A-Za-z0-9,+-]+)" SPACE "(\\+)*" MAYSPACE "(bb)*" MAYSPACE \
81 "\\(([0-9]+)\\)" SPACE "(&[0-9]+)*" MAYSPACE "->" MAYSPACE "(<[0-9 \t<>]+>)*" MAYSPACE \
82 "(\\{-[0-9\\{\\} \t-]+\\})*" SPACE "=([A-Za-z0-9.!-]+)" SPACE "r([0-9])" MAYSPACE END
85 #define ROCKETFUEL_WEIGHTS_LINE START "([^ \t]+)" SPACE "([^ \t]+)" SPACE "([0-9.]+)" MAYSPACE END
114 std::vector<std::string>::size_type neighListSize,
119 NS_LOG_INFO(
"Load Node[" << uid <<
"]: location: " << loc <<
" dns: " << dns <<
" bb: " << bb
120 <<
" neighbors: " << neighListSize <<
"("
122 <<
") externals: \"%s\"(%d) "
123 <<
"name: " << name <<
" radius: " << radius);
136 unsigned int num_neigh = 0;
138 std::vector<std::string> neigh_list;
144 if (!argv[2].empty())
149 if (!argv[3].empty())
154 num_neigh_s = std::stoi(argv[4]);
162 num_neigh = num_neigh_s;
166 if (!argv[6].empty())
171 std::regex replace_regex(
"[<|>]");
172 std::regex_replace(std::back_inserter(temp),
179 std::regex split_regex(
"[ |\t]");
180 std::sregex_token_iterator
first{temp.begin(), temp.end(), split_regex, -1};
181 std::sregex_token_iterator last;
182 neigh_list = std::vector<std::string>{
first, last};
184 if (num_neigh != neigh_list.size())
186 NS_LOG_WARN(
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = "
187 << neigh_list.size());
191 if (!argv[7].empty())
197 if (!argv[8].empty())
202 radius = std::atoi(&argv[9][1]);
208 PrintNodeInfo(uid, loc, dns, bb, neigh_list.size(), name, radius);
215 Ptr<Node> tmpNode = CreateObject<Node>();
216 std::string nodename =
"RocketFuelTopology/NodeName/" + uid;
223 for (
auto& nuid : neigh_list)
232 Ptr<Node> tmpNode = CreateObject<Node>();
233 std::string nodename =
"RocketFuelTopology/NodeName/" + nuid;
259 std::string::size_type endptr;
264 std::stod(argv[2], &endptr);
266 if (argv[2].size() != endptr)
273 if (!sname.empty() && !tname.empty())
277 Ptr<Node> tmpNode = CreateObject<Node>();
278 std::string nodename =
"RocketFuelTopology/NodeName/" + sname;
287 Ptr<Node> tmpNode = CreateObject<Node>();
288 std::string nodename =
"RocketFuelTopology/NodeName/" + tname;
295 <<
" to: " << tname);
300 if ((iter->GetFromNode() ==
m_nodeMap[tname]) &&
344 std::ifstream topgen;
348 std::istringstream lineBuffer;
353 if (!topgen.is_open())
359 while (!topgen.eof())
361 std::vector<std::string> argv;
367 getline(topgen, line);
384 if (!ret || matches.empty())
386 NS_LOG_WARN(
"match failed (maps file): %s" << line);
393 if (!ret || matches.empty())
395 NS_LOG_WARN(
"match failed (weights file): %s" << line);
400 std::string matched_string;
402 for (
auto it = matches.begin() + 1; it != matches.end(); it++)
406 matched_string = it->str();
412 argv.push_back(matched_string);
425 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.
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.
#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.