A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
orbis-topology-reader.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Universita' di Firenze, Italy
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tommaso Pecorella (tommaso.pecorella@unifi.it)
7
* Author: Valerio Sartini (valesar@gmail.com)
8
*/
9
10
#include "
orbis-topology-reader.h
"
11
12
#include "ns3/log.h"
13
#include "ns3/names.h"
14
#include "ns3/node-container.h"
15
16
#include <cstdlib>
17
#include <fstream>
18
#include <sstream>
19
20
/**
21
* \file
22
* \ingroup topology
23
* ns3::OrbisTopologyReader implementation.
24
*/
25
26
namespace
ns3
27
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"OrbisTopologyReader"
);
30
31
NS_OBJECT_ENSURE_REGISTERED
(OrbisTopologyReader);
32
33
TypeId
34
OrbisTopologyReader::GetTypeId
()
35
{
36
static
TypeId
tid =
TypeId
(
"ns3::OrbisTopologyReader"
)
37
.
SetParent
<
TopologyReader
>()
38
.SetGroupName(
"TopologyReader"
)
39
.AddConstructor<
OrbisTopologyReader
>();
40
return
tid;
41
}
42
43
OrbisTopologyReader::OrbisTopologyReader
()
44
{
45
NS_LOG_FUNCTION
(
this
);
46
}
47
48
OrbisTopologyReader::~OrbisTopologyReader
()
49
{
50
NS_LOG_FUNCTION
(
this
);
51
}
52
53
NodeContainer
54
OrbisTopologyReader::Read
()
55
{
56
std::ifstream topgen;
57
topgen.open(
GetFileName
());
58
std::map<std::string, Ptr<Node>> nodeMap;
59
NodeContainer
nodes
;
60
61
if
(!topgen.is_open())
62
{
63
return
nodes
;
64
}
65
66
std::string from;
67
std::string to;
68
std::istringstream lineBuffer;
69
std::string line;
70
71
int
linksNumber = 0;
72
int
nodesNumber = 0;
73
74
while
(!topgen.eof())
75
{
76
line.clear();
77
lineBuffer.clear();
78
from.clear();
79
to.clear();
80
81
getline(topgen, line);
82
lineBuffer.str(line);
83
lineBuffer >> from;
84
lineBuffer >> to;
85
86
if
((!from.empty()) && (!to.empty()))
87
{
88
NS_LOG_INFO
(linksNumber <<
" From: "
<< from <<
" to: "
<< to);
89
if
(!nodeMap[from])
90
{
91
Ptr<Node>
tmpNode =
CreateObject<Node>
();
92
std::string nodename =
"OrbisTopology/NodeName/"
+ from;
93
Names::Add
(nodename, tmpNode);
94
nodeMap[from] = tmpNode;
95
nodes
.Add(tmpNode);
96
nodesNumber++;
97
}
98
99
if
(!nodeMap[to])
100
{
101
Ptr<Node>
tmpNode =
CreateObject<Node>
();
102
std::string nodename =
"OrbisTopology/NodeName/"
+ to;
103
Names::Add
(nodename, tmpNode);
104
nodeMap[to] = tmpNode;
105
nodes
.Add(tmpNode);
106
nodesNumber++;
107
}
108
109
Link
link(nodeMap[from], from, nodeMap[to], to);
110
AddLink
(link);
111
112
linksNumber++;
113
}
114
}
115
NS_LOG_INFO
(
"Orbis topology created with "
<< nodesNumber <<
" nodes and "
<< linksNumber
116
<<
" links"
);
117
topgen.close();
118
119
return
nodes
;
120
}
121
122
}
/* namespace ns3 */
ns3::Names::Add
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition
names.cc:764
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::OrbisTopologyReader
Topology file reader (Orbis-format type).
Definition
orbis-topology-reader.h:38
ns3::OrbisTopologyReader::OrbisTopologyReader
OrbisTopologyReader()
Definition
orbis-topology-reader.cc:43
ns3::OrbisTopologyReader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
orbis-topology-reader.cc:34
ns3::OrbisTopologyReader::Read
NodeContainer Read() override
Main topology reading function.
Definition
orbis-topology-reader.cc:54
ns3::OrbisTopologyReader::~OrbisTopologyReader
~OrbisTopologyReader() override
Definition
orbis-topology-reader.cc:48
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TopologyReader::Link
Inner class holding the details about a link between two nodes.
Definition
topology-reader.h:50
ns3::TopologyReader
Interface for input file readers management.
Definition
topology-reader.h:40
ns3::TopologyReader::AddLink
void AddLink(Link link)
Adds a link to the topology.
Definition
topology-reader.cc:84
ns3::TopologyReader::GetFileName
std::string GetFileName() const
Returns the input file name.
Definition
topology-reader.cc:52
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
nodes
NodeContainer nodes
Definition
lr-wpan-bootstrap.cc:43
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
orbis-topology-reader.h
ns3::OrbisTopologyReader declaration.
src
topology-read
model
orbis-topology-reader.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0