A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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 <iostream>
25
#include <sstream>
26
27
#include "ns3/log.h"
28
#include "
orbis-topology-reader.h
"
29
30
31
namespace
ns3
{
32
33
NS_LOG_COMPONENT_DEFINE
(
"OrbisTopologyReader"
);
34
35
NS_OBJECT_ENSURE_REGISTERED
(OrbisTopologyReader);
36
37
TypeId
OrbisTopologyReader::GetTypeId
(
void
)
38
{
39
static
TypeId
tid =
TypeId
(
"ns3::OrbisTopologyReader"
)
40
.
SetParent
<
Object
> ()
41
.SetGroupName (
"TopologyReader"
)
42
;
43
return
tid;
44
}
45
46
OrbisTopologyReader::OrbisTopologyReader
()
47
{
48
NS_LOG_FUNCTION
(
this
);
49
}
50
51
OrbisTopologyReader::~OrbisTopologyReader
()
52
{
53
NS_LOG_FUNCTION
(
this
);
54
}
55
56
NodeContainer
57
OrbisTopologyReader::Read
(
void
)
58
{
59
std::ifstream topgen;
60
topgen.open (
GetFileName
().c_str ());
61
std::map<std::string, Ptr<Node> > nodeMap;
62
NodeContainer
nodes
;
63
64
if
( !topgen.is_open () )
65
{
66
return
nodes
;
67
}
68
69
std::string from;
70
std::string to;
71
std::istringstream lineBuffer;
72
std::string line;
73
74
int
linksNumber = 0;
75
int
nodesNumber = 0;
76
77
while
(!topgen.eof ())
78
{
79
line.clear ();
80
lineBuffer.clear ();
81
from.clear ();
82
to.clear ();
83
84
getline (topgen,line);
85
lineBuffer.str (line);
86
lineBuffer >> from;
87
lineBuffer >> to;
88
89
if
( (!from.empty ()) && (!to.empty ()) )
90
{
91
NS_LOG_INFO
( linksNumber <<
" From: "
<< from <<
" to: "
<< to );
92
if
( nodeMap[from] == 0 )
93
{
94
Ptr<Node>
tmpNode = CreateObject<Node> ();
95
nodeMap[from] = tmpNode;
96
nodes.
Add
(tmpNode);
97
nodesNumber++;
98
}
99
100
if
(nodeMap[to] == 0)
101
{
102
Ptr<Node>
tmpNode = CreateObject<Node> ();
103
nodeMap[to] = tmpNode;
104
nodes.
Add
(tmpNode);
105
nodesNumber++;
106
}
107
108
Link
link ( nodeMap[from], from, nodeMap[to], to );
109
AddLink
(link);
110
111
linksNumber++;
112
}
113
}
114
NS_LOG_INFO
(
"Orbis topology created with "
<< nodesNumber <<
" nodes and "
<< linksNumber <<
" links"
);
115
topgen.close ();
116
117
return
nodes
;
118
}
119
120
}
/* namespace ns3 */
121
ns3::OrbisTopologyReader::~OrbisTopologyReader
virtual ~OrbisTopologyReader()
Definition:
orbis-topology-reader.cc:51
ns3::Ptr< Node >
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:213
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::TopologyReader::GetFileName
std::string GetFileName(void) const
Returns the input file name.
Definition:
topology-reader.cc:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:244
ns3::TopologyReader::AddLink
void AddLink(Link link)
Adds a link to the topology.
Definition:
topology-reader.cc:91
first.nodes
tuple nodes
Definition:
first.py:25
ns3::TopologyReader::Link
Inner class holding the details about a link between two nodes.
Definition:
topology-reader.h:54
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:38
orbis-topology-reader.h
ns3::NodeContainer::Add
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Definition:
node-container.cc:109
ns3::OrbisTopologyReader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
orbis-topology-reader.cc:37
ns3::OrbisTopologyReader::OrbisTopologyReader
OrbisTopologyReader()
Definition:
orbis-topology-reader.cc:46
ns3::OrbisTopologyReader::Read
virtual NodeContainer Read(void)
Main topology reading function.
Definition:
orbis-topology-reader.cc:57
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:87
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
src
topology-read
model
orbis-topology-reader.cc
Generated on Thu Aug 13 2015 14:28:10 for ns-3 by
1.8.9.1