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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
;
42
return
tid;
43
}
44
45
OrbisTopologyReader::OrbisTopologyReader
()
46
{
47
NS_LOG_FUNCTION
(
this
);
48
}
49
50
OrbisTopologyReader::~OrbisTopologyReader
()
51
{
52
NS_LOG_FUNCTION
(
this
);
53
}
54
55
NodeContainer
56
OrbisTopologyReader::Read
(
void
)
57
{
58
std::ifstream topgen;
59
topgen.open (
GetFileName
().c_str ());
60
std::map<std::string, Ptr<Node> >
nodeMap
;
61
NodeContainer
nodes
;
62
63
if
( !topgen.is_open () )
64
{
65
return
nodes
;
66
}
67
68
std::string from;
69
std::string to;
70
std::istringstream lineBuffer;
71
std::string line;
72
73
int
linksNumber
= 0;
74
int
nodesNumber
= 0;
75
76
while
(!topgen.eof ())
77
{
78
line.clear ();
79
lineBuffer.clear ();
80
from.clear ();
81
to.clear ();
82
83
getline (topgen,line);
84
lineBuffer.str (line);
85
lineBuffer >> from;
86
lineBuffer >> to;
87
88
if
( (!from.empty ()) && (!to.empty ()) )
89
{
90
NS_LOG_INFO
( linksNumber <<
" From: "
<< from <<
" to: "
<< to );
91
if
( nodeMap[from] == 0 )
92
{
93
Ptr<Node>
tmpNode = CreateObject<Node> ();
94
nodeMap[from] = tmpNode;
95
nodes.
Add
(tmpNode);
96
nodesNumber++;
97
}
98
99
if
(nodeMap[to] == 0)
100
{
101
Ptr<Node>
tmpNode = CreateObject<Node> ();
102
nodeMap[to] = tmpNode;
103
nodes.
Add
(tmpNode);
104
nodesNumber++;
105
}
106
107
Link
link ( nodeMap[from], from, nodeMap[to], to );
108
AddLink
(link);
109
110
linksNumber++;
111
}
112
}
113
NS_LOG_INFO
(
"Orbis topology created with "
<< nodesNumber <<
" nodes and "
<< linksNumber <<
" links"
);
114
topgen.close ();
115
116
return
nodes
;
117
}
118
119
}
/* namespace ns3 */
120
ns3::OrbisTopologyReader::~OrbisTopologyReader
virtual ~OrbisTopologyReader()
Definition:
orbis-topology-reader.cc:50
ns3::Ptr< Node >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::TopologyReader::GetFileName
std::string GetFileName(void) const
Returns the input file name.
Definition:
topology-reader.cc:58
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Definition:
log.h:264
ns3::TopologyReader::AddLink
void AddLink(Link link)
Adds a link to the topology.
Definition:
topology-reader.cc:90
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::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
ns3::nodesNumber
int nodesNumber
Definition:
rocketfuel-topology-reader.cc:77
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:38
ns3::nodeMap
std::map< std::string, Ptr< Node > > nodeMap
Definition:
rocketfuel-topology-reader.cc:78
ns3::linksNumber
int linksNumber
Definition:
rocketfuel-topology-reader.cc:76
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::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
ns3::OrbisTopologyReader::GetTypeId
static TypeId GetTypeId(void)
Definition:
orbis-topology-reader.cc:37
ns3::OrbisTopologyReader::OrbisTopologyReader
OrbisTopologyReader()
Definition:
orbis-topology-reader.cc:45
ns3::OrbisTopologyReader::Read
virtual NodeContainer Read(void)
Main topology reading function.
Definition:
orbis-topology-reader.cc:56
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:610
src
topology-read
model
orbis-topology-reader.cc
Generated on Sun Apr 20 2014 11:15:03 for ns-3 by
1.8.6