Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [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. |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [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. |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [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. |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [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 | **/ |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 20 | #ifndef BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |
| 21 | #define BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 23 | /// @cond include_hidden |
| 24 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 25 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 26 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 27 | #include <boost/graph/graph_traits.hpp> |
| 28 | #include <boost/graph/properties.hpp> |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 29 | #include <boost/ref.hpp> |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 30 | |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 31 | #include "ns3/ndnSIM/model/ndn-global-router.hpp" |
| 32 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 33 | #include "ns3/node-list.h" |
| 34 | #include "ns3/channel-list.h" |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 36 | #include <list> |
| 37 | #include <map> |
| 38 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | namespace boost { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | class NdnGlobalRouterGraph { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 42 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 43 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> Vertice; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 44 | typedef uint16_t edge_property_type; |
| 45 | typedef uint32_t vertex_property_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 46 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | NdnGlobalRouterGraph() |
| 48 | { |
| 49 | for (ns3::NodeList::Iterator node = ns3::NodeList::Begin(); node != ns3::NodeList::End(); |
| 50 | node++) { |
| 51 | ns3::Ptr<ns3::ndn::GlobalRouter> gr = (*node)->GetObject<ns3::ndn::GlobalRouter>(); |
| 52 | if (gr != 0) |
| 53 | m_vertices.push_back(gr); |
| 54 | } |
| 55 | |
| 56 | for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin(); |
| 57 | channel != ns3::ChannelList::End(); channel++) { |
| 58 | ns3::Ptr<ns3::ndn::GlobalRouter> gr = (*channel)->GetObject<ns3::ndn::GlobalRouter>(); |
| 59 | if (gr != 0) |
| 60 | m_vertices.push_back(gr); |
| 61 | } |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | const std::list<Vertice>& |
| 65 | GetVertices() const |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 66 | { |
| 67 | return m_vertices; |
| 68 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 70 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | std::list<Vertice> m_vertices; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | class ndn_global_router_graph_category : public virtual vertex_list_graph_tag, |
| 75 | public virtual incidence_graph_tag { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 78 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | struct graph_traits<NdnGlobalRouterGraph> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 80 | // Graph concept |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 81 | typedef NdnGlobalRouterGraph::Vertice vertex_descriptor; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 82 | typedef ns3::ndn::GlobalRouter::Incidency edge_descriptor; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 83 | typedef directed_tag directed_category; |
| 84 | typedef disallow_parallel_edge_tag edge_parallel_category; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 85 | typedef ndn_global_router_graph_category traversal_category; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 86 | |
| 87 | // VertexList concept |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | typedef std::list<vertex_descriptor>::const_iterator vertex_iterator; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 89 | typedef size_t vertices_size_type; |
| 90 | |
| 91 | // AdjacencyGraph concept |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | typedef ns3::ndn::GlobalRouter::IncidencyList::iterator out_edge_iterator; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 93 | typedef size_t degree_size_type; |
| 94 | |
| 95 | // typedef size_t edges_size_type; |
| 96 | }; |
| 97 | |
| 98 | } // namespace boost |
| 99 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | namespace boost { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor |
| 103 | source(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e, const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 104 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 105 | return std::get<0>(e); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor |
| 109 | target(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e, const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 110 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 111 | return std::get<2>(e); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 114 | inline std::pair<graph_traits<NdnGlobalRouterGraph>::vertex_iterator, |
| 115 | graph_traits<NdnGlobalRouterGraph>::vertex_iterator> |
| 116 | vertices(const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 117 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | return make_pair(g.GetVertices().begin(), g.GetVertices().end()); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 121 | inline graph_traits<NdnGlobalRouterGraph>::vertices_size_type |
| 122 | num_vertices(const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 123 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 124 | return g.GetVertices().size(); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 127 | inline std::pair<graph_traits<NdnGlobalRouterGraph>::out_edge_iterator, |
| 128 | graph_traits<NdnGlobalRouterGraph>::out_edge_iterator> |
| 129 | out_edges(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u, const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 130 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | return std::make_pair(u->GetIncidencies().begin(), u->GetIncidencies().end()); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | inline graph_traits<NdnGlobalRouterGraph>::degree_size_type |
| 135 | out_degree(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u, const NdnGlobalRouterGraph& g) |
| 136 | { |
| 137 | return u->GetIncidencies().size(); |
| 138 | } |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 139 | |
| 140 | ////////////////////////////////////////////////////////////// |
| 141 | // Property maps |
| 142 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 143 | struct EdgeWeights { |
| 144 | EdgeWeights(const NdnGlobalRouterGraph& graph) |
| 145 | : m_graph(graph) |
| 146 | { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 150 | const NdnGlobalRouterGraph& m_graph; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 153 | struct VertexIds { |
| 154 | VertexIds(const NdnGlobalRouterGraph& graph) |
| 155 | : m_graph(graph) |
| 156 | { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | const NdnGlobalRouterGraph& m_graph; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 164 | struct property_map<NdnGlobalRouterGraph, edge_weight_t> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 165 | typedef const EdgeWeights const_type; |
| 166 | typedef EdgeWeights type; |
| 167 | }; |
| 168 | |
| 169 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 170 | struct property_map<NdnGlobalRouterGraph, vertex_index_t> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 171 | typedef const VertexIds const_type; |
| 172 | typedef VertexIds type; |
| 173 | }; |
| 174 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 175 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 176 | struct property_traits<EdgeWeights> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 177 | // Metric property map |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 178 | typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t, double> value_type; |
| 179 | typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t, double> reference; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 180 | typedef ns3::ndn::GlobalRouter::Incidency key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 181 | typedef readable_property_map_tag category; |
| 182 | }; |
| 183 | |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 184 | const property_traits<EdgeWeights>::value_type WeightZero(nullptr, 0, 0.0); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 185 | const property_traits<EdgeWeights>::value_type |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 186 | WeightInf(nullptr, std::numeric_limits<uint16_t>::max(), 0.0); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 187 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 188 | struct WeightCompare : public std::binary_function<property_traits<EdgeWeights>::reference, |
| 189 | property_traits<EdgeWeights>::reference, bool> { |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 190 | bool |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 191 | operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> a, |
| 192 | std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 193 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 194 | return std::get<1>(a) < std::get<1>(b); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 198 | operator()(property_traits<EdgeWeights>::reference a, uint32_t b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 199 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 200 | return std::get<1>(a) < b; |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 201 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 202 | |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 203 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 204 | operator()(uint32_t a, uint32_t b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 205 | { |
| 206 | return a < b; |
| 207 | } |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 210 | struct WeightCombine |
| 211 | : public std::binary_function<uint32_t, property_traits<EdgeWeights>::reference, uint32_t> { |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 212 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 213 | operator()(uint32_t a, property_traits<EdgeWeights>::reference b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 214 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 215 | return a + std::get<1>(b); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 218 | std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> |
| 219 | operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> a, |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 220 | property_traits<EdgeWeights>::reference b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 221 | { |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 222 | if (std::get<0>(a) == nullptr) |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 223 | return std::make_tuple(std::get<0>(b), std::get<1>(a) + std::get<1>(b), |
| 224 | std::get<2>(a) + std::get<2>(b)); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 225 | else |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 226 | return std::make_tuple(std::get<0>(a), std::get<1>(a) + std::get<1>(b), |
| 227 | std::get<2>(a) + std::get<2>(b)); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 228 | } |
| 229 | }; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 230 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 231 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 232 | struct property_traits<VertexIds> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 233 | // Metric property map |
| 234 | typedef uint32_t value_type; |
| 235 | typedef uint32_t reference; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 236 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 237 | typedef readable_property_map_tag category; |
| 238 | }; |
| 239 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 240 | inline EdgeWeights |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 241 | get(edge_weight_t, const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 242 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 243 | return EdgeWeights(g); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 246 | inline VertexIds |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 247 | get(vertex_index_t, const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 248 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 249 | return VertexIds(g); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 252 | template<class M, class K, class V> |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 253 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 254 | put(reference_wrapper<M> mapp, K a, V p) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 255 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 256 | mapp.get()[a] = p; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 260 | // put (cref< std::map< ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter> > > map, |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 261 | |
Alexander Afanasyev | b2a11fe | 2012-12-12 11:38:39 -0800 | [diff] [blame] | 262 | inline uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 263 | get(const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter>& gr) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 264 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 265 | return gr->GetId(); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 268 | inline property_traits<EdgeWeights>::reference |
| 269 | get(const boost::EdgeWeights&, ns3::ndn::GlobalRouter::Incidency& edge) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 270 | { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 271 | if (std::get<1>(edge) == 0) |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 272 | return property_traits<EdgeWeights>::reference(nullptr, 0, 0.0); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 273 | else { |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 274 | return property_traits<EdgeWeights>::reference(std::get<1>(edge), |
| 275 | static_cast<uint16_t>( |
| 276 | std::get<1>(edge)->getMetric()), |
| 277 | 0.0); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 278 | } |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 281 | struct PredecessorsMap |
| 282 | : public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter>> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 286 | struct property_traits<reference_wrapper<PredecessorsMap>> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 287 | // Metric property map |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 288 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> value_type; |
| 289 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> reference; |
| 290 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 291 | typedef read_write_property_map_tag category; |
| 292 | }; |
| 293 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 294 | struct DistancesMap : public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>, |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 295 | std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | template<> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 299 | struct property_traits<reference_wrapper<DistancesMap>> { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 300 | // Metric property map |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 301 | typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> value_type; |
| 302 | typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> reference; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 303 | typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 304 | typedef read_write_property_map_tag category; |
| 305 | }; |
| 306 | |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 307 | } // boost |
| 308 | |
| 309 | namespace std { |
| 310 | template<> |
| 311 | class numeric_limits<std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>> |
| 312 | { |
| 313 | public: |
| 314 | typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> value; |
| 315 | static value |
| 316 | max() |
| 317 | { |
| 318 | return boost::WeightInf; |
| 319 | } |
| 320 | }; |
| 321 | } |
| 322 | |
| 323 | namespace boost { |
| 324 | |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 325 | inline std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 326 | get(DistancesMap& map, ns3::Ptr<ns3::ndn::GlobalRouter> key) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 327 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 328 | boost::DistancesMap::iterator i = map.find(key); |
| 329 | if (i == map.end()) |
Spyridon Mastorakis | 60f4b99 | 2014-11-07 15:51:38 -0800 | [diff] [blame] | 330 | return std::tuple<std::shared_ptr<nfd::Face>, uint32_t, |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 331 | double>(nullptr, std::numeric_limits<uint32_t>::max(), 0.0); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 332 | else |
| 333 | return i->second; |
| 334 | } |
| 335 | |
| 336 | } // namespace boost |
| 337 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 338 | /// @endcond |
| 339 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 340 | #endif // BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |