27 #include "ns3/unused.h" 28 #include "ns3/node-container.h" 45 static TypeId tid =
TypeId (
"ns3::RocketfuelTopologyReader")
47 .SetGroupName (
"TopologyReader")
68 #define REGMATCH_MAX 16 72 #define SPACE "[ \t]+" 73 #define MAYSPACE "[ \t]*" 75 #define ROCKETFUEL_MAPS_LINE \ 76 START "(-*[0-9]+)" SPACE "(@[?A-Za-z0-9,+]+)" SPACE \ 77 "(\\+)*" MAYSPACE "(bb)*" MAYSPACE \ 78 "\\(([0-9]+)\\)" SPACE "(&[0-9]+)*" MAYSPACE \ 79 "->" MAYSPACE "(<[0-9 \t<>]+>)*" MAYSPACE \ 80 "(\\{-[0-9\\{\\} \t-]+\\})*" SPACE \ 81 "=([A-Za-z0-9.!-]+)" SPACE "r([0-9])" \ 84 #define ROCKETFUEL_WEIGHTS_LINE \ 85 START "([^ \t]+)" SPACE "([^ \t]+)" SPACE "([0-9.]+)" MAYSPACE END 99 std::vector <std::string>::size_type neighListSize,
100 std::string & name,
int radius)
103 NS_LOG_INFO (
"Load Node[" << uid <<
"]: location: " << loc <<
" dns: " << dns
104 <<
" bb: " << bb <<
" neighbors: " << neighListSize
105 <<
"(" <<
"%d" <<
") externals: \"%s\"(%d) " 106 <<
"name: " << name <<
" radius: " << radius);
120 unsigned int num_neigh = 0;
122 std::vector <std::string> neigh_list;
138 num_neigh_s = ::atoi (argv[4]);
142 NS_LOG_WARN (
"Negative number of neighbors given");
146 num_neigh = num_neigh_s;
153 char *stringp = argv[6];
154 while ((nbr = strsep (&stringp,
" \t")) != NULL)
156 nbr[strlen (nbr) - 1] =
'\0';
157 neigh_list.push_back (nbr + 1);
160 if (num_neigh != neigh_list.size ())
162 NS_LOG_WARN (
"Given number of neighbors = " << num_neigh <<
" != size of neighbors list = " << neigh_list.size ());
177 radius = ::atoi (&argv[9][1]);
183 PrintNodeInfo (uid, loc, dns, bb, neigh_list.size (), name, radius);
190 Ptr<Node> tmpNode = CreateObject<Node> ();
196 for (uint32_t i = 0; i < neigh_list.size (); ++i)
198 nuid = neigh_list[i];
207 Ptr<Node> tmpNode = CreateObject<Node> ();
235 double v = strtod (argv[2], &endptr);
244 if (!sname.empty () && !tname.empty ())
248 Ptr<Node> tmpNode = CreateObject<Node> ();
256 Ptr<Node> tmpNode = CreateObject<Node> ();
266 if ((iter->GetFromNode () ==
m_nodeMap[tname])
267 && (iter->GetToNode () ==
m_nodeMap[sname]))
299 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
302 ret = regexec (®ex, line,
REGMATCH_MAX, regmatch, 0);
303 if (ret != REG_NOMATCH)
314 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
317 ret = regexec (®ex, line,
REGMATCH_MAX, regmatch, 0);
318 if (ret != REG_NOMATCH)
332 std::ifstream topgen;
336 std::istringstream lineBuffer;
342 if (!topgen.is_open ())
348 while (!topgen.eof ())
359 getline (topgen, line);
360 buf = (
char *)line.c_str ();
380 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
386 if (ret == REG_NOMATCH)
388 NS_LOG_WARN (
"match failed (maps file): %s" << buf);
398 regerror (ret, ®ex, errbuf,
sizeof (errbuf));
404 if (ret == REG_NOMATCH)
406 NS_LOG_WARN (
"match failed (weights file): %s" << buf);
418 if (regmatch[i].rm_so == -1)
424 line[regmatch[i].rm_eo] =
'\0';
425 argv[i - 1] = &line[regmatch[i].rm_so];
440 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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define ROCKETFUEL_MAPS_LINE
#define NS_UNUSED(x)
Mark a local variable as unused.
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.
ns3::RocketfuelTopologyReader declaration.
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.
Interface for input file readers management.
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.
ConstLinksIterator LinksEnd(void) const
Returns an iterator to the the last link in this block.
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.
virtual NodeContainer Read(void)
Main topology reading function.
RF_FileType
Enum of the possible file types.
std::string GetFileName(void) const
Returns the input file name.
Topology file reader (Rocketfuel-format type).
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
a unique identifier for an interface.
ConstLinksIterator LinksBegin(void) const
Returns an iterator to the the first link in this block.
TypeId SetParent(TypeId tid)
Set the parent TypeId.