28 #include "ns3/unused.h"
39 static TypeId tid =
TypeId (
"ns3::RocketfuelTopologyReader")
60 #define REGMATCH_MAX 16
64 #define SPACE "[ \t]+"
65 #define MAYSPACE "[ \t]*"
67 #define ROCKETFUEL_MAPS_LINE \
68 START "(-*[0-9]+)" SPACE "(@[?A-Za-z0-9,+]+)" SPACE \
69 "(\\+)*" MAYSPACE "(bb)*" MAYSPACE \
70 "\\(([0-9]+)\\)" SPACE "(&[0-9]+)*" MAYSPACE \
71 "->" MAYSPACE "(<[0-9 \t<>]+>)*" MAYSPACE \
72 "(\\{-[0-9\\{\\} \t-]+\\})*" SPACE \
73 "=([A-Za-z0-9.!-]+)" SPACE "r([0-9])" \
76 #define ROCKETFUEL_WEIGHTS_LINE \
77 START "([^ \t]+)" SPACE "([^ \t]+)" SPACE "([0-9.]+)" MAYSPACE END
91 std::vector <std::string>::size_type neighListSize,
92 std::string & name,
int radius)
95 NS_LOG_INFO (
"Load Node[" << uid <<
"]: location: " << loc <<
" dns: " << dns
96 <<
" bb: " << bb <<
" neighbors: " << neighListSize
97 <<
"(" <<
"%d" <<
") externals: \"%s\"(%d) "
98 <<
"name: " << name <<
" radius: " << radius);
112 unsigned int num_neigh = 0;
114 std::vector <std::string> neigh_list;
130 num_neigh_s = ::atoi (argv[4]);
134 NS_LOG_WARN (
"Negative number of neighbors given");
138 num_neigh = num_neigh_s;
145 char *stringp = argv[6];
146 while ((nbr = strsep (&stringp,
" \t")) != NULL)
148 nbr[strlen (nbr) - 1] =
'\0';
149 neigh_list.push_back (nbr + 1);
152 if (num_neigh != neigh_list.size ())
154 NS_LOG_WARN (
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = " << neigh_list.size ());
169 radius = ::atoi (&argv[9][1]);
175 PrintNodeInfo (uid, loc, dns, bb, neigh_list.size (), name, radius);
182 Ptr<Node> tmpNode = CreateObject<Node> ();
188 for (uint32_t i = 0; i < neigh_list.size (); ++i)
190 nuid = neigh_list[i];
199 Ptr<Node> tmpNode = CreateObject<Node> ();
227 double v = strtod (argv[2], &endptr);
236 if (!sname.empty () && !tname.empty ())
240 Ptr<Node> tmpNode = CreateObject<Node> ();
248 Ptr<Node> tmpNode = CreateObject<Node> ();
258 if ((iter->GetFromNode () ==
m_nodeMap[tname])
259 && (iter->GetToNode () ==
m_nodeMap[sname]))
291 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
294 ret = regexec (®ex, line,
REGMATCH_MAX, regmatch, 0);
295 if (ret != REG_NOMATCH)
306 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
309 ret = regexec (®ex, line,
REGMATCH_MAX, regmatch, 0);
310 if (ret != REG_NOMATCH)
324 std::ifstream topgen;
328 std::istringstream lineBuffer;
334 if (!topgen.is_open ())
340 while (!topgen.eof ())
351 getline (topgen, line);
352 buf = (
char *)line.c_str ();
372 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
378 if (ret == REG_NOMATCH)
380 NS_LOG_WARN (
"match failed (maps file): %s" << buf);
390 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
396 if (ret == REG_NOMATCH)
398 NS_LOG_WARN (
"match failed (weights file): %s" << buf);
410 if (regmatch[i].rm_so == -1)
416 line[regmatch[i].rm_eo] =
'\0';
417 argv[i - 1] = &line[regmatch[i].rm_so];
432 NS_LOG_WARN (
"Unsupported file format (only Maps/Weights are supported)");
RocketfuelTopologyReader()
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
ConstLinksIterator LinksBegin(void) const
Returns an iterator to the the first link in this block.
std::string GetFileName(void) const
Returns the input file name.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define ROCKETFUEL_MAPS_LINE
NodeContainer GenerateFromMapsFile(int argc, char *argv[])
Topology read function from a file containing the nodes map.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void AddLink(Link link)
Adds a link to the topology.
enum RF_FileType GetFileType(const char *)
Classifies the file type according to its content.
NodeContainer GenerateFromWeightsFile(int argc, char *argv[])
Topology read function from a file containing the nodes weights.
Inner class holding the details about a link between two nodes.
int m_nodesNumber
number of nodes
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.
virtual ~RocketfuelTopologyReader()
#define ROCKETFUEL_WEIGHTS_LINE
std::map< std::string, Ptr< Node > > m_nodeMap
map of the nodes (name, node)
std::list< Link >::const_iterator ConstLinksIterator
Constant iterator to the list of the links.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
int m_linksNumber
number of links
RF_FileType
Enum of the possible file types.
virtual NodeContainer Read(void)
Main topology reading function.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
A base class which provides memory management and object aggregation.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
ConstLinksIterator LinksEnd(void) const
Returns an iterator to the the last link in this block.