41 .SetGroupName (
"TopologyReader")
62 std::map<std::string, Ptr<Node> > nodeMap;
65 if ( !topgen.is_open () )
67 NS_LOG_WARN (
"Inet topology file object is not open, check file name and permissions");
81 std::istringstream lineBuffer;
84 getline (topgen,line);
85 lineBuffer.str (line);
87 lineBuffer >> totnode;
88 lineBuffer >> totlink;
89 NS_LOG_INFO (
"Inet topology should have " << totnode <<
" nodes and " << totlink <<
" links");
91 for (
int i = 0; i < totnode && !topgen.eof (); i++)
93 getline (topgen,line);
96 for (
int i = 0; i < totlink && !topgen.eof (); i++)
98 getline (topgen,line);
100 lineBuffer.str (line);
104 lineBuffer >> linkAttr;
106 if ( (!from.empty ()) && (!to.empty ()) )
108 NS_LOG_INFO (
"Link " << linksNumber <<
" from: " << from <<
" to: " << to);
110 if ( nodeMap[from] == 0 )
112 NS_LOG_INFO (
"Node " << nodesNumber <<
" name: " << from);
113 Ptr<Node> tmpNode = CreateObject<Node> ();
114 nodeMap[from] = tmpNode;
119 if (nodeMap[to] == 0)
121 NS_LOG_INFO (
"Node " << nodesNumber <<
" name: " << to);
122 Ptr<Node> tmpNode = CreateObject<Node> ();
123 nodeMap[to] = tmpNode;
128 Link link ( nodeMap[from], from, nodeMap[to], to );
129 if ( !linkAttr.empty () )
131 NS_LOG_INFO (
"Link " << linksNumber <<
" weight: " << linkAttr);
140 NS_LOG_INFO (
"Inet topology created with " << nodesNumber <<
" nodes and " << linksNumber <<
" links");
#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.
std::string GetFileName(void) const
Returns the input file name.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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.
Inner class holding the details about a link between two nodes.
Interface for input file readers management.
virtual NodeContainer Read(void)
Main topology reading function.
keep track of a set of node pointers.
void SetAttribute(const std::string &name, const std::string &value)
Sets an arbitrary link attribute.
virtual ~InetTopologyReader()
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.
Topology file reader (Inet-format type).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.