Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 1 | /* -*- 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 Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 24 | #include "ns3/topology-reader.h" |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 25 | #include "ns3/random-variable.h" |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 26 | #include "ns3/object-factory.h" |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 27 | |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 28 | namespace ns3 |
| 29 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 32 | * \brief This class reads annotated topology and apply settings to the corresponding nodes and links |
| 33 | * |
| 34 | */ |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 35 | class AnnotatedTopologyReader : public TopologyReader |
| 36 | { |
| 37 | public: |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 38 | /** |
| 39 | * \brief Constructor |
| 40 | * |
| 41 | * \param path ns3::Names path |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 42 | * \param scale Scaling factor for coordinates in input file |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 43 | * |
| 44 | * \see ns3::Names class |
| 45 | */ |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 46 | AnnotatedTopologyReader (const std::string &path="", double scale=1.0); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 47 | virtual ~AnnotatedTopologyReader (); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 49 | /** |
| 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 Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 56 | virtual NodeContainer |
| 57 | Read (); |
| 58 | |
| 59 | /** |
| 60 | * \brief Get nodes read by the reader |
| 61 | */ |
| 62 | NodeContainer |
| 63 | GetNodes () const; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 65 | /** |
Ilya Moiseenko | ad9e8ab | 2012-01-11 19:58:34 -0800 | [diff] [blame] | 66 | * \brief Get links read by the reader |
| 67 | */ |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 68 | const std::list<Link>& |
Ilya Moiseenko | ad9e8ab | 2012-01-11 19:58:34 -0800 | [diff] [blame] | 69 | GetLinks () const; |
| 70 | |
| 71 | /** |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 72 | * \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 | */ |
| 80 | void |
| 81 | AssignIpv4Addresses (Ipv4Address base); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 83 | /** |
| 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 Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 90 | void |
| 91 | SetBoundingBox (double ulx, double uly, double lrx, double lry); |
| 92 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 93 | /** |
| 94 | * \brief Set mobility model to be used on nodes |
| 95 | * \param model class name of the model |
| 96 | */ |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 97 | void |
| 98 | SetMobilityModel (const std::string &model); |
| 99 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 100 | /** |
| 101 | * \brief Apply OSPF metric on Ipv4 (if exists) and Ccnx (if exists) stacks |
| 102 | */ |
| 103 | void ApplyOspfMetric (); |
| 104 | |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 105 | /** |
| 106 | * \brief Save positions (e.g., after manual modification using visualizer) |
| 107 | */ |
| 108 | void |
| 109 | SavePositions (const std::string &file) const; |
| 110 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 111 | protected: |
| 112 | Ptr<Node> |
| 113 | CreateNode (const std::string name); |
| 114 | |
| 115 | Ptr<Node> |
| 116 | CreateNode (const std::string name, double posX, double posY); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 117 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 118 | protected: |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 119 | /** |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 120 | * \brief This method applies setting to corresponding nodes and links |
| 121 | * NetDeviceContainer must be allocated |
| 122 | * NodeContainer from Read method |
| 123 | */ |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 124 | void ApplySettings (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 126 | protected: |
| 127 | std::string m_path; |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame] | 128 | NodeContainer m_nodes; |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 130 | private: |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 131 | AnnotatedTopologyReader (const AnnotatedTopologyReader&); |
| 132 | AnnotatedTopologyReader& operator= (const AnnotatedTopologyReader&); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 134 | UniformVariable m_randX; |
| 135 | UniformVariable m_randY; |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 136 | |
| 137 | ObjectFactory m_mobilityFactory; |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 138 | double m_scale; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 139 | }; |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 141 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 142 | |
| 143 | #endif |
| 144 | |
| 145 | |