blob: 343743d94457260202702a86522b60a2e41c6a8f [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20// Based on the code by Hajime Tazaki <tazaki@sfc.wide.ad.jp>
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -070021
22#ifndef __ANNOTATED_TOPOLOGY_READER_H__
23#define __ANNOTATED_TOPOLOGY_READER_H__
24
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -070025#include "ns3/topology-reader.h"
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070026#include "ns3/random-variable-stream.h"
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080027#include "ns3/object-factory.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080028
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080029namespace ns3 {
30
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070031/**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080032 * \brief This class reads annotated topology and apply settings to the corresponding nodes and
33 *links
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080034 *
35 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036class AnnotatedTopologyReader : public TopologyReader {
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070037public:
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080038 /**
39 * \brief Constructor
40 *
41 * \param path ns3::Names path
Alexander Afanasyev011b8592011-12-21 14:45:27 -080042 * \param scale Scaling factor for coordinates in input file
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080043 *
44 * \see ns3::Names class
45 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 AnnotatedTopologyReader(const std::string& path = "", double scale = 1.0);
47 virtual ~AnnotatedTopologyReader();
48
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080049 /**
50 * \brief Main annotated topology reading function.
51 *
52 * This method opens an input stream and reads topology file with annotations.
53 *
54 * \return the container of the nodes created (or empty container if there was an error)
55 */
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080056 virtual NodeContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 Read();
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080058
59 /**
60 * \brief Get nodes read by the reader
61 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070062 virtual NodeContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 GetNodes() const;
64
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080065 /**
Ilya Moiseenkoad9e8ab2012-01-11 19:58:34 -080066 * \brief Get links read by the reader
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070068 virtual const std::list<Link>&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 GetLinks() const;
70
Ilya Moiseenkoad9e8ab2012-01-11 19:58:34 -080071 /**
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080072 * \brief Assign IPv4 addresses to all links
73 *
74 * Note, IPv4 stack should be installed on all nodes prior this call
75 *
76 * Every link will receive /24 netmask
77 *
78 * \param base Starting IPv4 address (second link will have base+256)
79 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070080 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 AssignIpv4Addresses(Ipv4Address base);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080082
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080083 /**
84 * \brief Set bounding box where nodes will be randomly places (if positions are unspecified)
85 * \param ulx Upper left x coordinate
86 * \param uly Upper left y coordinate
87 * \param lrx Lower right x coordinate
88 * \param lry Lower right y coordinate
89 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070090 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 SetBoundingBox(double ulx, double uly, double lrx, double lry);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080092
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080093 /**
94 * \brief Set mobility model to be used on nodes
95 * \param model class name of the model
96 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -070097 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 SetMobilityModel(const std::string& model);
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080099
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800100 /**
101 * \brief Apply OSPF metric on Ipv4 (if exists) and Ccnx (if exists) stacks
102 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700103 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 ApplyOspfMetric();
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800105
Alexander Afanasyeved78b632012-01-25 19:26:43 -0800106 /**
107 * \brief Save positions (e.g., after manual modification using visualizer)
108 */
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700109 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 SaveTopology(const std::string& file);
Alexander Afanasyeved78b632012-01-25 19:26:43 -0800111
Alexander Afanasyev455e4412013-05-11 12:51:11 -0700112 /**
113 * \brief Save topology in graphviz format (.dot file)
114 */
115 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 SaveGraphviz(const std::string& file);
117
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800118protected:
119 Ptr<Node>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 CreateNode(const std::string name, uint32_t systemId);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800121
122 Ptr<Node>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 CreateNode(const std::string name, double posX, double posY, uint32_t systemId);
124
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800125protected:
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800126 /**
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800127 * \brief This method applies setting to corresponding nodes and links
128 * NetDeviceContainer must be allocated
129 * NodeContainer from Read method
130 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800131 void
132 ApplySettings();
133
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800134protected:
135 std::string m_path;
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -0800136 NodeContainer m_nodes;
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800137
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800138private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139 AnnotatedTopologyReader(const AnnotatedTopologyReader&);
140 AnnotatedTopologyReader&
141 operator=(const AnnotatedTopologyReader&);
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800142
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700143 Ptr<UniformRandomVariable> m_randX;
144 Ptr<UniformRandomVariable> m_randY;
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800145
146 ObjectFactory m_mobilityFactory;
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800147 double m_scale;
Alexander Afanasyevff6e3692012-07-30 00:11:02 -0700148
149 uint32_t m_requiredPartitions;
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -0700150};
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -0800151}
Ilya Moiseenko1eff17d2011-08-17 10:55:53 -0700152
153#endif