24 #include "ns3/names.h"
25 #include "ns3/node-container.h"
48 .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);
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);
118 NS_LOG_INFO(
"Node " << nodesNumber <<
" name: " << from);
119 Ptr<Node> tmpNode = CreateObject<Node>();
120 std::string nodeName =
"InetTopology/NodeName/" + from;
122 nodeMap[from] = tmpNode;
129 NS_LOG_INFO(
"Node " << nodesNumber <<
" name: " << to);
130 Ptr<Node> tmpNode = CreateObject<Node>();
131 std::string nodename =
"InetTopology/NodeName/" + to;
133 nodeMap[to] = tmpNode;
138 Link link(nodeMap[from], from, nodeMap[to], to);
139 if (!linkAttr.empty())
141 NS_LOG_INFO(
"Link " << linksNumber <<
" weight: " << linkAttr);
142 link.SetAttribute(
"Weight", linkAttr);
150 NS_LOG_INFO(
"Inet topology created with " << nodesNumber <<
" nodes and " << linksNumber
Topology file reader (Inet-format type).
NodeContainer Read() override
Main topology reading function.
static TypeId GetTypeId()
Get the type ID.
~InetTopologyReader() override
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.
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.
std::string GetFileName() const
Returns the input file name.
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.
ns3::InetTopologyReader declaration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.