Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * 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 Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * 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 Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * 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 Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 22 | #ifndef ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H |
| 23 | #define ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | dca091a | 2015-01-01 20:51:27 -0800 | [diff] [blame] | 25 | #include "ns3/ndnSIM/utils/topology/annotated-topology-reader.hpp" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 26 | #include "ns3/net-device-container.h" |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 27 | |
| 28 | namespace ns3 { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 30 | // ------------------------------------------------------------ |
| 31 | // -------------------------------------------- |
| 32 | /** |
| 33 | * \brief Topology file reader (extension of Rocketfuel-format type). |
| 34 | * |
| 35 | * http://www.cs.washington.edu/research/networking/rocketfuel/ |
| 36 | * |
| 37 | * Only weights and latencies file is supported |
| 38 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | class RocketfuelWeightsReader : public AnnotatedTopologyReader { |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 40 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | RocketfuelWeightsReader(const std::string& path = "", double scale = 1.0); |
| 42 | virtual ~RocketfuelWeightsReader(); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 43 | |
| 44 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | SetFileType(uint8_t inputType); |
| 46 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 47 | /** |
| 48 | * \brief Main topology reading function. |
| 49 | * |
| 50 | * This method opens an input stream and reads the Rocketfuel-format file. |
| 51 | * Every row represents a topology link (the ids of a couple of nodes), |
| 52 | * so the input file is read line by line to figure out how many links |
| 53 | * and nodes are in the topology. |
| 54 | * |
| 55 | * \return the container of the nodes created (or empty container if there was an error) |
| 56 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | virtual NodeContainer |
| 58 | Read(void); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 59 | |
| 60 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | Commit(); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | enum { LINKS, WEIGHTS, LATENCIES, POSITIONS }; |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 64 | |
| 65 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | SetDefaultBandwidth(const std::string& bw); |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 67 | |
| 68 | inline std::string |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | GetDefaultBandwidth() const; |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 70 | |
| 71 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 72 | SetDefaultQueue(const std::string& queue); |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 73 | |
| 74 | inline std::string |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | GetDefaultQueue() const; |
| 76 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 77 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | RocketfuelWeightsReader(const RocketfuelWeightsReader&); |
| 79 | RocketfuelWeightsReader& |
| 80 | operator=(const RocketfuelWeightsReader&); |
| 81 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 82 | private: |
| 83 | uint8_t m_inputType; |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 84 | std::string m_defaultBandwidth; // since the topology files don't provide bandwidth parameter |
| 85 | std::string m_queue; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 87 | }; // end class RocketfuelWeightsReader |
| 88 | |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 89 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | RocketfuelWeightsReader::SetDefaultBandwidth(const std::string& bw) |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 91 | { |
| 92 | m_defaultBandwidth = bw; |
| 93 | } |
| 94 | |
| 95 | inline std::string |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | RocketfuelWeightsReader::GetDefaultBandwidth() const |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 97 | { |
| 98 | return m_defaultBandwidth; |
| 99 | } |
| 100 | |
| 101 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | RocketfuelWeightsReader::SetDefaultQueue(const std::string& queue) |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 103 | { |
| 104 | m_queue = queue; |
| 105 | } |
| 106 | |
| 107 | inline std::string |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | RocketfuelWeightsReader::GetDefaultQueue() const |
Alexander Afanasyev | 455e441 | 2013-05-11 12:51:11 -0700 | [diff] [blame] | 109 | { |
| 110 | return m_queue; |
| 111 | } |
| 112 | |
JonnyKong | 6c53c75 | 2019-04-21 00:25:39 -0700 | [diff] [blame] | 113 | } // end namespace ns3 |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 115 | #endif /* ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H */ |