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