FNSS ns-3 adapter
ns-3 adapter for the Fast Network Simulation Setup (FNSS) toolchain
 All Classes Files Functions Typedefs Pages
topology.h
1 #ifndef TOPOLOGY_H
2 #define TOPOLOGY_H
3 
4 #include "property-container.h"
5 #include "ns3/fnss-node.h"
6 #include "edge.h"
7 #include "pair.h"
8 
9 #include <map>
10 #include <set>
11 #include <utility>
12 #include <string>
13 #include <exception>
14 
15 namespace fnss {
16 
22 class Topology : public PropertyContainer {
23 public:
32  Topology(bool directed = false);
33 
39  bool isDirected() const;
40 
49  void addNode(const std::string &id, const Node &node);
50 
62  Node removeNode(const std::string &id, bool pruneEdges = true);
63 
72  Node getNode(const std::string &id) const;
73 
80  bool hasNode(const std::string &id) const;
81 
87  std::set<std::string> getAllNodes() const;
88 
100  void addEdge(const std::string &id1, const std::string &id2, const Edge &edge);
101 
112  void addEdge(const std::pair<std::string, std::string> &nodes, const Edge &edge);
113 
125  void addEdge(const Pair<std::string, std::string> &nodes, const Edge &edge);
126 
138  Edge removeEdge(const std::string &id1, const std::string &id2);
139 
150  Edge removeEdge(const std::pair <std::string, std::string> &nodes);
151 
164 
176  Edge getEdge(const std::string &id1, const std::string &id2) const;
177 
188  Edge getEdge(const std::pair <std::string, std::string> &nodes) const;
189 
201  Edge getEdge(const Pair <std::string, std::string> &nodes) const;
202 
213  bool hasEdge(const std::string &id1, const std::string &id2) const;
214 
224  bool hasEdge(const std::pair <std::string, std::string> &nodes) const;
225 
236  bool hasEdge(const Pair <std::string, std::string> &nodes) const;
237 
244  std::set<std::pair <std::string, std::string> > getAllEdges() const;
245 
251  unsigned int nodeCount() const;
252 
258  unsigned int edgeCount() const;
259 
260  class EdgeNotFoundException : public std::exception {
261  public:
263  this->exceptionStr = "The edge between nodes with IDs " + nodes.first + " and "
264  + nodes.second + " was not found.";
265  }
266 
267  ~EdgeNotFoundException() throw() {
268  }
269 
270  const char* what() const throw() {
271  return this->exceptionStr.c_str();
272  }
273 
274  private:
275  std::string exceptionStr;
276  };
277 
278  class NodeNotFoundException : public std::exception {
279  public:
280  NodeNotFoundException(const std::string &id) throw() {
281  this->exceptionStr = "The node with ID " + id + " was not found.";
282  }
283 
284  ~NodeNotFoundException() throw() {
285  }
286 
287  const char* what() const throw() {
288  return this->exceptionStr.c_str();
289  }
290 
291  private:
292  std::string exceptionStr;
293  };
294 
295 private:
296  // Map from node ID to node.
297  typedef std::map <std::string, Node> nodesType;
298  nodesType nodes;
299 
300  // Map from the ID of link end-points to the edge.
301  typedef std::map <Pair <std::string, std::string>, Edge> edgesType;
302  edgesType edges;
303 
304  bool directed; // Whether the topology is directed.
305 
306 };
307 
308 } //namespace
309 
310 #endif //TOPOLOGY_H
bool hasEdge(const std::string &id1, const std::string &id2) const
Definition: topology.cpp:141
unsigned int edgeCount() const
Definition: topology.cpp:159
void addEdge(const std::string &id1, const std::string &id2, const Edge &edge)
Definition: topology.cpp:71
unsigned int nodeCount() const
Definition: topology.cpp:155
Definition: topology.h:278
Definition: topology.h:260
bool hasNode(const std::string &id) const
Definition: topology.cpp:53
Topology(bool directed=false)
Definition: topology.cpp:8
Definition: topology.h:22
Definition: pair.h:41
std::set< std::pair< std::string, std::string > > getAllEdges() const
Definition: topology.cpp:145
std::set< std::string > getAllNodes() const
Definition: topology.cpp:61
void addNode(const std::string &id, const Node &node)
Definition: topology.cpp:16
bool isDirected() const
Definition: topology.cpp:12
Node removeNode(const std::string &id, bool pruneEdges=true)
Definition: topology.cpp:20
Definition: fnss-node.h:23
Definition: edge.h:16
Node getNode(const std::string &id) const
Definition: topology.cpp:45
Edge removeEdge(const std::string &id1, const std::string &id2)
Definition: topology.cpp:107
Edge getEdge(const std::string &id1, const std::string &id2) const
Definition: topology.cpp:124
Definition: property-container.h:15