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