A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
topology-reader.h
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#ifndef TOPOLOGY_READER_H
22#define TOPOLOGY_READER_H
23
24#include "ns3/node.h"
25#include "ns3/object.h"
26
27#include <list>
28#include <map>
29#include <string>
30
31/**
32 * \file
33 * \ingroup topology
34 * ns3::TopologyReader declaration.
35 */
36
37namespace ns3
38{
39
40class NodeContainer;
41
42/**
43 * \ingroup topology
44 *
45 * \brief Interface for input file readers management.
46 *
47 * This interface perform the shared tasks among all possible input file readers.
48 * Each different file format is handled by its own topology reader.
49 */
50class TopologyReader : public Object
51{
52 public:
53 /**
54 * \brief Inner class holding the details about a link between two nodes.
55 *
56 * The link is not described in terms of technology. Rather it is only stating
57 * an association between two nodes. The nodes are characterized also with names
58 * reflecting how the nodes are called in the original topology file.
59 */
60 class Link
61 {
62 public:
63 /**
64 * \brief Constant iterator to scan the map of link attributes.
65 */
66 typedef std::map<std::string, std::string>::const_iterator ConstAttributesIterator;
67
68 /**
69 * \brief Constructor.
70 * \param [in] fromPtr Ptr to the node the link is originating from.
71 * \param [in] fromName Name of the node the link is originating from.
72 * \param [in] toPtr Ptr to the node the link is directed to.
73 * \param [in] toName Name of the node the link is directed to.
74 */
75 Link(Ptr<Node> fromPtr,
76 const std::string& fromName,
77 Ptr<Node> toPtr,
78 const std::string& toName);
79
80 /**
81 * \brief Returns a Ptr<Node> to the "from" node of the link.
82 * \return A Ptr<Node> to the "from" node of the link.
83 */
84 Ptr<Node> GetFromNode() const;
85 /**
86 * \brief Returns the name of the "from" node of the link.
87 * \return The name of the "from" node of the link.
88 */
89 std::string GetFromNodeName() const;
90 /**
91 * \brief Returns a Ptr<Node> to the "to" node of the link.
92 * \return A Ptr<Node> to the "to" node of the link.
93 */
94 Ptr<Node> GetToNode() const;
95 /**
96 * \brief Returns the name of the "to" node of the link.
97 * \return The name of the "to" node of the link.
98 */
99 std::string GetToNodeName() const;
100 /**
101 * \brief Returns the value of a link attribute. The attribute must exist.
102 * \param [in] name the name of the attribute.
103 * \return The value of the attribute.
104 */
105 std::string GetAttribute(const std::string& name) const;
106 /**
107 * \brief Returns the value of a link attribute.
108 * \param [in] name The name of the attribute.
109 * \param [out] value The value of the attribute.
110 *
111 * \return True if the attribute was defined, false otherwise.
112 */
113 bool GetAttributeFailSafe(const std::string& name, std::string& value) const;
114 /**
115 * \brief Sets an arbitrary link attribute.
116 * \param [in] name The name of the attribute.
117 * \param [in] value The value of the attribute.
118 */
119 void SetAttribute(const std::string& name, const std::string& value);
120 /**
121 * \brief Returns an iterator to the begin of the attributes.
122 * \return A const iterator to the first attribute of a link.
123 */
125 /**
126 * \brief Returns an iterator to the end of the attributes.
127 * \return A const iterator to the last attribute of a link.
128 */
130
131 private:
132 Link();
133 std::string m_fromName; //!< Name of the node the links originates from.
134 Ptr<Node> m_fromPtr; //!< The node the links originates from.
135 std::string m_toName; //!< Name of the node the links is directed to.
136 Ptr<Node> m_toPtr; //!< The node the links is directed to.
137 std::map<std::string, std::string>
138 m_linkAttr; //!< Container of the link attributes (if any).
139 };
140
141 /**
142 * \brief Constant iterator to the list of the links.
143 */
144 typedef std::list<Link>::const_iterator ConstLinksIterator;
145
146 /**
147 * \brief Get the type ID.
148 * \return The object TypeId.
149 */
150 static TypeId GetTypeId();
151
153 ~TopologyReader() override;
154
155 // Delete copy constructor and assignment operator to avoid misuse
158
159 /**
160 * \brief Main topology reading function.
161 *
162 * The data is parsed and the results are returned in the passed lists.
163 * The rationale behind this choice is to allow non-progressive node IDs
164 * in the topology files, as well as to separate the topology
165 * reader from the choices about actual IP number assignment and
166 * kind of links between nodes.
167 *
168 * \return The container of the nodes created (or null if there was an error).
169 */
170 virtual NodeContainer Read() = 0;
171
172 /**
173 * \brief Sets the input file name.
174 * \param [in] fileName The input file name.
175 */
176 void SetFileName(const std::string& fileName);
177
178 /**
179 * \brief Returns the input file name.
180 * \return The input file name.
181 */
182 std::string GetFileName() const;
183
184 /**
185 * \brief Returns an iterator to the the first link in this block.
186 * \return A const iterator to the first link in this block.
187 */
189
190 /**
191 * \brief Returns an iterator to the the last link in this block.
192 * \return A const iterator to the last link in this block.
193 */
195
196 /**
197 * \brief Returns the number of links in this block.
198 * \return The number of links in this block.
199 */
200 int LinksSize() const;
201
202 /**
203 * \brief Checks if the block contains any links.
204 * \return True if there are no links in this block, false otherwise.
205 */
206 bool LinksEmpty() const;
207
208 /**
209 * \brief Adds a link to the topology.
210 * \param link [in] The link to be added.
211 */
212 void AddLink(Link link);
213
214 private:
215 /**
216 * The name of the input file.
217 */
218 std::string m_fileName;
219
220 /**
221 * The container of the links between the nodes.
222 */
223 std::list<Link> m_linksList;
224
225 // end class TopologyReader
226};
227
228// end namespace ns3
229}; // namespace ns3
230
231#endif /* TOPOLOGY_READER_H */
keep track of a set of node pointers.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Interface for input file readers management.
int LinksSize() const
Returns the number of links in this block.
std::list< Link > m_linksList
The container of the links between the nodes.
void AddLink(Link link)
Adds a link to the topology.
virtual NodeContainer Read()=0
Main topology reading function.
ConstLinksIterator LinksEnd() const
Returns an iterator to the the last link in this block.
std::string GetFileName() const
Returns the input file name.
void SetFileName(const std::string &fileName)
Sets the input file name.
ConstLinksIterator LinksBegin() const
Returns an iterator to the the first link in this block.
TopologyReader(const TopologyReader &)=delete
static TypeId GetTypeId()
Get the type ID.
std::string m_fileName
The name of the input file.
TopologyReader & operator=(const TopologyReader &)=delete
std::list< Link >::const_iterator ConstLinksIterator
Constant iterator to the list of the links.
~TopologyReader() override
bool LinksEmpty() const
Checks if the block contains any links.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.