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