A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
orbis-topology-reader.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Universita' di Firenze, Italy
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Tommaso Pecorella (tommaso.pecorella@unifi.it)
18
* Author: Valerio Sartini (valesar@gmail.com)
19
*/
20
21
#include "
orbis-topology-reader.h
"
22
23
#include "ns3/log.h"
24
#include "ns3/node-container.h"
25
26
#include <cstdlib>
27
#include <fstream>
28
#include <sstream>
29
36
namespace
ns3
37
{
38
39
NS_LOG_COMPONENT_DEFINE
(
"OrbisTopologyReader"
);
40
41
NS_OBJECT_ENSURE_REGISTERED
(OrbisTopologyReader);
42
43
TypeId
44
OrbisTopologyReader::GetTypeId
()
45
{
46
static
TypeId
tid =
TypeId
(
"ns3::OrbisTopologyReader"
)
47
.
SetParent
<
TopologyReader
>()
48
.SetGroupName(
"TopologyReader"
)
49
.AddConstructor<
OrbisTopologyReader
>();
50
return
tid;
51
}
52
53
OrbisTopologyReader::OrbisTopologyReader
()
54
{
55
NS_LOG_FUNCTION
(
this
);
56
}
57
58
OrbisTopologyReader::~OrbisTopologyReader
()
59
{
60
NS_LOG_FUNCTION
(
this
);
61
}
62
63
NodeContainer
64
OrbisTopologyReader::Read
()
65
{
66
std::ifstream topgen;
67
topgen.open(
GetFileName
());
68
std::map<std::string, Ptr<Node>> nodeMap;
69
NodeContainer
nodes
;
70
71
if
(!topgen.is_open())
72
{
73
return
nodes
;
74
}
75
76
std::string from;
77
std::string to;
78
std::istringstream lineBuffer;
79
std::string line;
80
81
int
linksNumber = 0;
82
int
nodesNumber = 0;
83
84
while
(!topgen.eof())
85
{
86
line.clear();
87
lineBuffer.clear();
88
from.clear();
89
to.clear();
90
91
getline(topgen, line);
92
lineBuffer.str(line);
93
lineBuffer >> from;
94
lineBuffer >> to;
95
96
if
((!from.empty()) && (!to.empty()))
97
{
98
NS_LOG_INFO
(linksNumber <<
" From: "
<< from <<
" to: "
<< to);
99
if
(!nodeMap[from])
100
{
101
Ptr<Node>
tmpNode = CreateObject<Node>();
102
nodeMap[from] = tmpNode;
103
nodes
.Add(tmpNode);
104
nodesNumber++;
105
}
106
107
if
(!nodeMap[to])
108
{
109
Ptr<Node>
tmpNode = CreateObject<Node>();
110
nodeMap[to] = tmpNode;
111
nodes
.Add(tmpNode);
112
nodesNumber++;
113
}
114
115
Link
link(nodeMap[from], from, nodeMap[to], to);
116
AddLink
(link);
117
118
linksNumber++;
119
}
120
}
121
NS_LOG_INFO
(
"Orbis topology created with "
<< nodesNumber <<
" nodes and "
<< linksNumber
122
<<
" links"
);
123
topgen.close();
124
125
return
nodes
;
126
}
127
128
}
/* namespace ns3 */
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:40
ns3::OrbisTopologyReader
Topology file reader (Orbis-format type).
Definition:
orbis-topology-reader.h:49
ns3::OrbisTopologyReader::OrbisTopologyReader
OrbisTopologyReader()
Definition:
orbis-topology-reader.cc:53
ns3::OrbisTopologyReader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
orbis-topology-reader.cc:44
ns3::OrbisTopologyReader::Read
NodeContainer Read() override
Main topology reading function.
Definition:
orbis-topology-reader.cc:64
ns3::OrbisTopologyReader::~OrbisTopologyReader
~OrbisTopologyReader() override
Definition:
orbis-topology-reader.cc:58
ns3::Ptr< Node >
ns3::TopologyReader::Link
Inner class holding the details about a link between two nodes.
Definition:
topology-reader.h:61
ns3::TopologyReader
Interface for input file readers management.
Definition:
topology-reader.h:51
ns3::TopologyReader::AddLink
void AddLink(Link link)
Adds a link to the topology.
Definition:
topology-reader.cc:95
ns3::TopologyReader::GetFileName
std::string GetFileName() const
Returns the input file name.
Definition:
topology-reader.cc:63
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:60
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:935
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:238
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:275
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
nodes
NodeContainer nodes
Definition:
lr-wpan-bootstrap.cc:50
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 Tue Nov 1 2022 23:00:36 for ns-3 by
1.9.3