14#include "ns3/node-container.h"
37 .SetGroupName(
"TopologyReader")
57 std::map<std::string, Ptr<Node>> nodeMap;
60 if (!topgen.is_open())
62 NS_LOG_WARN(
"Inet topology file object is not open, check file name and permissions");
76 std::istringstream lineBuffer;
79 getline(topgen, line);
82 lineBuffer >> totnode;
83 lineBuffer >> totlink;
84 NS_LOG_INFO(
"Inet topology should have " << totnode <<
" nodes and " << totlink <<
" links");
86 for (
int i = 0; i < totnode && !topgen.eof(); i++)
88 getline(topgen, line);
91 for (
int i = 0; i < totlink && !topgen.eof(); i++)
93 getline(topgen, line);
99 lineBuffer >> linkAttr;
101 if ((!from.empty()) && (!to.empty()))
103 NS_LOG_INFO(
"Link " << linksNumber <<
" from: " << from <<
" to: " << to);
107 NS_LOG_INFO(
"Node " << nodesNumber <<
" name: " << from);
109 std::string nodeName =
"InetTopology/NodeName/" + from;
111 nodeMap[from] = tmpNode;
118 NS_LOG_INFO(
"Node " << nodesNumber <<
" name: " << to);
120 std::string nodename =
"InetTopology/NodeName/" + to;
122 nodeMap[to] = tmpNode;
127 Link link(nodeMap[from], from, nodeMap[to], to);
128 if (!linkAttr.empty())
130 NS_LOG_INFO(
"Link " << linksNumber <<
" weight: " << linkAttr);
131 link.SetAttribute(
"Weight", linkAttr);
139 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.
Smart pointer class similar to boost::intrusive_ptr.
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.