blob: d8679edb9b5afb3a259da003d3dc4daf3524876b [file] [log] [blame]
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#ifndef __ANNOTATED_TOPOLOGY_READER_H__
22#define __ANNOTATED_TOPOLOGY_READER_H__
23
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -070024#include "ns3/topology-reader.h"
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080025#include "ns3/random-variable.h"
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080026#include "ns3/object-factory.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080027
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080028namespace ns3 {
29
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070030/**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080031 * \brief This class reads annotated topology and apply settings to the corresponding nodes and
32 *links
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080033 *
34 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035class AnnotatedTopologyReader : public TopologyReader {
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070036public:
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080037 /**
38 * \brief Constructor
39 *
40 * \param path ns3::Names path
Alexander Afanasyev011b8592011-12-21 14:45:27 -080041 * \param scale Scaling factor for coordinates in input file
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080042 *
43 * \see ns3::Names class
44 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 AnnotatedTopologyReader(const std::string& path = "", double scale = 1.0);
46 virtual ~AnnotatedTopologyReader();
47
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080048 /**
49 * \brief Main annotated topology reading function.
50 *
51 * This method opens an input stream and reads topology file with annotations.
52 *
53 * \return the container of the nodes created (or empty container if there was an error)
54 */
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080055 virtual NodeContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 Read();
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080057
58 /**
59 * \brief Get nodes read by the reader
60 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070061 virtual NodeContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 GetNodes() const;
63
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080064 /**
Ilya Moiseenkoad9e8ab2012-01-11 19:58:34 -080065 * \brief Get links read by the reader
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070067 virtual const std::list<Link>&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 GetLinks() const;
69
Ilya Moiseenkoad9e8ab2012-01-11 19:58:34 -080070 /**
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080071 * \brief Assign IPv4 addresses to all links
72 *
73 * Note, IPv4 stack should be installed on all nodes prior this call
74 *
75 * Every link will receive /24 netmask
76 *
77 * \param base Starting IPv4 address (second link will have base+256)
78 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070079 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 AssignIpv4Addresses(Ipv4Address base);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080081
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080082 /**
83 * \brief Set bounding box where nodes will be randomly places (if positions are unspecified)
84 * \param ulx Upper left x coordinate
85 * \param uly Upper left y coordinate
86 * \param lrx Lower right x coordinate
87 * \param lry Lower right y coordinate
88 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070089 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 SetBoundingBox(double ulx, double uly, double lrx, double lry);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080091
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080092 /**
93 * \brief Set mobility model to be used on nodes
94 * \param model class name of the model
95 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070096 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 SetMobilityModel(const std::string& model);
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080098
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080099 /**
100 * \brief Apply OSPF metric on Ipv4 (if exists) and Ccnx (if exists) stacks
101 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700102 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 ApplyOspfMetric();
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800104
Alexander Afanasyeved78b632012-01-25 19:26:43 -0800105 /**
106 * \brief Save positions (e.g., after manual modification using visualizer)
107 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700108 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 SaveTopology(const std::string& file);
Alexander Afanasyeved78b632012-01-25 19:26:43 -0800110
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700111 /**
112 * \brief Save topology in graphviz format (.dot file)
113 */
114 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 SaveGraphviz(const std::string& file);
116
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800117protected:
118 Ptr<Node>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 CreateNode(const std::string name, uint32_t systemId);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800120
121 Ptr<Node>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 CreateNode(const std::string name, double posX, double posY, uint32_t systemId);
123
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800124protected:
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800125 /**
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800126 * \brief This method applies setting to corresponding nodes and links
127 * NetDeviceContainer must be allocated
128 * NodeContainer from Read method
129 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 void
131 ApplySettings();
132
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800133protected:
134 std::string m_path;
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -0800135 NodeContainer m_nodes;
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800136
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800137private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 AnnotatedTopologyReader(const AnnotatedTopologyReader&);
139 AnnotatedTopologyReader&
140 operator=(const AnnotatedTopologyReader&);
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800141
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800142 UniformVariable m_randX;
143 UniformVariable m_randY;
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800144
145 ObjectFactory m_mobilityFactory;
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800146 double m_scale;
Alexander Afanasyevff6e3692012-07-30 00:11:02 -0700147
148 uint32_t m_requiredPartitions;
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -0700149};
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800150}
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -0700151
152#endif