25 #include "ns3/node-container.h" 47 .SetGroupName (
"TopologyReader")
68 std::map<std::string, Ptr<Node> > nodeMap;
71 if ( !topgen.is_open () )
73 NS_LOG_WARN (
"Inet topology file object is not open, check file name and permissions");
87 std::istringstream lineBuffer;
90 getline (topgen,line);
91 lineBuffer.str (line);
93 lineBuffer >> totnode;
94 lineBuffer >> totlink;
95 NS_LOG_INFO (
"Inet topology should have " << totnode <<
" nodes and " << totlink <<
" links");
97 for (
int i = 0; i < totnode && !topgen.eof (); i++)
99 getline (topgen,line);
102 for (
int i = 0; i < totlink && !topgen.eof (); i++)
104 getline (topgen,line);
106 lineBuffer.str (line);
110 lineBuffer >> linkAttr;
112 if ( (!from.empty ()) && (!to.empty ()) )
114 NS_LOG_INFO (
"Link " << linksNumber <<
" from: " << from <<
" to: " << to);
116 if ( nodeMap[from] == 0 )
118 NS_LOG_INFO (
"Node " << nodesNumber <<
" name: " << from);
119 Ptr<Node> tmpNode = CreateObject<Node> ();
120 nodeMap[from] = tmpNode;
125 if (nodeMap[to] == 0)
127 NS_LOG_INFO (
"Node " << nodesNumber <<
" name: " << to);
128 Ptr<Node> tmpNode = CreateObject<Node> ();
129 nodeMap[to] = tmpNode;
134 Link link ( nodeMap[from], from, nodeMap[to], to );
135 if ( !linkAttr.empty () )
137 NS_LOG_INFO (
"Link " << linksNumber <<
" weight: " << linkAttr);
146 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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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()
std::string GetFileName(void) const
Returns the input file name.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Topology file reader (Inet-format type).
ns3::InetTopologyReader declaration.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.