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