Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ccnx-fib.h" |
| 22 | |
| 23 | #include "ccnx.h" |
| 24 | #include "ccnx-face.h" |
| 25 | #include "ccnx-interest-header.h" |
| 26 | |
| 27 | #include "ns3/node.h" |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 28 | #include "ns3/assert.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 29 | #include "ns3/names.h" |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 30 | #include "ns3/log.h" |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 31 | |
| 32 | #define NDN_RTO_ALPHA 0.125 |
| 33 | #define NDN_RTO_BETA 0.25 |
| 34 | #define NDN_RTO_K 4 |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 36 | #include <boost/ref.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 37 | #include <boost/lambda/lambda.hpp> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 38 | #include <boost/lambda/bind.hpp> |
| 39 | namespace ll = boost::lambda; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 41 | namespace ns3 { |
| 42 | |
| 43 | |
| 44 | ////////////////////////////////////////////////////////////////////// |
| 45 | // Helpers |
| 46 | ////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 47 | namespace __ccnx_private { |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 48 | |
| 49 | struct CcnxFibFaceMetricByFace |
| 50 | { |
| 51 | typedef CcnxFibFaceMetricContainer::type::index<i_face>::type |
| 52 | type; |
| 53 | }; |
| 54 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 55 | } |
| 56 | ////////////////////////////////////////////////////////////////////// |
| 57 | ////////////////////////////////////////////////////////////////////// |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 58 | NS_LOG_COMPONENT_DEFINE ("CcnxFib"); |
| 59 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 60 | using namespace __ccnx_private; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 62 | TypeId |
| 63 | CcnxFib::GetTypeId (void) |
| 64 | { |
| 65 | static TypeId tid = TypeId ("ns3::CcnxFib") |
| 66 | .SetParent<Object> () |
| 67 | .SetGroupName ("Ccnx") |
| 68 | .AddConstructor<CcnxFib> () |
| 69 | |
| 70 | ; |
| 71 | return tid; |
| 72 | } |
| 73 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 74 | ///////////////////////////////////////////////////////////////////// |
| 75 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 76 | void |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 77 | CcnxFibFaceMetric::UpdateRtt (const Time &rttSample) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 78 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 79 | // const Time & this->m_rttSample |
| 80 | |
| 81 | //update srtt and rttvar (RFC 2988) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 82 | if (m_sRtt.IsZero ()) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 83 | { |
| 84 | //first RTT measurement |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 85 | NS_ASSERT_MSG (m_rttVar.IsZero (), "SRTT is zero, but variation is not"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 86 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 87 | m_sRtt = rttSample; |
| 88 | m_rttVar = Time (m_sRtt / 2.0); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 89 | } |
| 90 | else |
| 91 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 92 | m_rttVar = Time ((1 - NDN_RTO_BETA) * m_rttVar + NDN_RTO_BETA * Abs(m_sRtt - rttSample)); |
| 93 | m_sRtt = Time ((1 - NDN_RTO_ALPHA) * m_sRtt + NDN_RTO_ALPHA * rttSample); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 97 | ///////////////////////////////////////////////////////////////////// |
| 98 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 99 | void |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 100 | CcnxFibEntry::UpdateFaceRtt (Ptr<CcnxFace> face, const Time &sample) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 101 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 102 | CcnxFibFaceMetricByFace::type::iterator record = m_faces.get<i_face> ().find (face); |
| 103 | NS_ASSERT_MSG (record != m_faces.get<i_face> ().end (), |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 104 | "Update status can be performed only on existing faces of CcxnFibEntry"); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 106 | m_faces.modify (record, |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 107 | ll::bind (&CcnxFibFaceMetric::UpdateRtt, ll::_1, sample)); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 108 | |
| 109 | // reordering random access index same way as by metric index |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 110 | m_faces.get<i_nth> ().rearrange (m_faces.get<i_metric> ().begin ()); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 113 | void |
| 114 | CcnxFibEntry::UpdateStatus (Ptr<CcnxFace> face, CcnxFibFaceMetric::Status status) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 115 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 116 | NS_LOG_FUNCTION (this << boost::cref(*face) << status); |
| 117 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 118 | CcnxFibFaceMetricByFace::type::iterator record = m_faces.get<i_face> ().find (face); |
| 119 | NS_ASSERT_MSG (record != m_faces.get<i_face> ().end (), |
| 120 | "Update status can be performed only on existing faces of CcxnFibEntry"); |
| 121 | |
| 122 | m_faces.modify (record, |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 123 | (&ll::_1)->*&CcnxFibFaceMetric::m_status = status); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 124 | |
| 125 | // reordering random access index same way as by metric index |
| 126 | m_faces.get<i_nth> ().rearrange (m_faces.get<i_metric> ().begin ()); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | CcnxFibEntry::AddOrUpdateRoutingMetric (Ptr<CcnxFace> face, int32_t metric) |
| 131 | { |
| 132 | NS_LOG_FUNCTION (this); |
| 133 | NS_ASSERT_MSG (face != NULL, "Trying to Add or Update NULL face"); |
| 134 | |
| 135 | CcnxFibFaceMetricByFace::type::iterator record = m_faces.get<i_face> ().find (face); |
| 136 | if (record == m_faces.get<i_face> ().end ()) |
| 137 | { |
| 138 | m_faces.insert (CcnxFibFaceMetric (face, metric)); |
| 139 | } |
| 140 | else |
| 141 | { |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 142 | // don't update metric to higher value |
| 143 | if (record->m_routingCost > metric || record->m_status == CcnxFibFaceMetric::NDN_FIB_RED) |
| 144 | { |
| 145 | m_faces.modify (record, |
| 146 | (&ll::_1)->*&CcnxFibFaceMetric::m_routingCost = metric); |
| 147 | |
| 148 | m_faces.modify (record, |
| 149 | (&ll::_1)->*&CcnxFibFaceMetric::m_status = CcnxFibFaceMetric::NDN_FIB_YELLOW); |
| 150 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // reordering random access index same way as by metric index |
| 154 | m_faces.get<i_nth> ().rearrange (m_faces.get<i_metric> ().begin ()); |
| 155 | } |
| 156 | |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 157 | void |
| 158 | CcnxFibEntry::Invalidate () |
| 159 | { |
| 160 | for (CcnxFibFaceMetricByFace::type::iterator face = m_faces.begin (); |
| 161 | face != m_faces.end (); |
| 162 | face++) |
| 163 | { |
| 164 | m_faces.modify (face, |
| 165 | (&ll::_1)->*&CcnxFibFaceMetric::m_routingCost = std::numeric_limits<uint16_t>::max ()); |
| 166 | |
| 167 | m_faces.modify (face, |
| 168 | (&ll::_1)->*&CcnxFibFaceMetric::m_status = CcnxFibFaceMetric::NDN_FIB_RED); |
| 169 | } |
| 170 | } |
| 171 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 172 | const CcnxFibFaceMetric & |
| 173 | CcnxFibEntry::FindBestCandidate (uint32_t skip/* = 0*/) const |
| 174 | { |
| 175 | if (m_faces.size () == 0) throw CcnxFibEntry::NoFaces (); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 176 | skip = skip % m_faces.size(); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 177 | return m_faces.get<i_nth> () [skip]; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 181 | CcnxFib::CcnxFib () |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 182 | { |
| 183 | } |
| 184 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 185 | void |
| 186 | CcnxFib::NotifyNewAggregate () |
| 187 | { |
| 188 | if (m_node == 0) |
| 189 | m_node = this->GetObject<Node>(); |
| 190 | Object::NotifyNewAggregate (); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | CcnxFib::DoDispose (void) |
| 195 | { |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 196 | m_fib.clear (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 197 | m_node = 0; |
| 198 | Object::DoDispose (); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | CcnxFibEntryContainer::type::iterator |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 203 | CcnxFib::LongestPrefixMatch (const CcnxInterestHeader &interest) const |
| 204 | { |
| 205 | const CcnxNameComponents &name = interest.GetName (); |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 206 | for (size_t componentsCount = name.GetComponents ().size ()+1; |
| 207 | componentsCount > 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 208 | componentsCount--) |
| 209 | { |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 210 | CcnxNameComponents subPrefix (name.GetSubComponents (componentsCount-1)); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 211 | CcnxFibEntryContainer::type::iterator match = m_fib.find (subPrefix); |
| 212 | if (match != m_fib.end()) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 213 | return match; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 216 | return m_fib.end (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | CcnxFibEntryContainer::type::iterator |
| 221 | CcnxFib::Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric) |
| 222 | { |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 223 | return Add (Create<CcnxNameComponents> (prefix), face, metric); |
| 224 | } |
| 225 | |
| 226 | CcnxFibEntryContainer::type::iterator |
| 227 | CcnxFib::Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric) |
| 228 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 229 | // CcnxFibFaceMetric |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 230 | NS_LOG_FUNCTION(this->GetObject<Node> ()->GetId () << boost::cref(*prefix) << boost::cref(*face) << metric); |
| 231 | CcnxFibEntryContainer::type::iterator entry = m_fib.find (*prefix); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 232 | if (entry == m_fib.end ()) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 233 | { |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 234 | entry = m_fib.insert (m_fib.end (), CcnxFibEntry (prefix)); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 235 | // insert new |
| 236 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 237 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 238 | NS_ASSERT_MSG (face != NULL, "Trying to modify NULL face"); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 239 | m_fib.modify (entry, |
| 240 | ll::bind (&CcnxFibEntry::AddOrUpdateRoutingMetric, ll::_1, face, metric)); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 241 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 242 | return entry; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 243 | } |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 244 | |
| 245 | void |
| 246 | CcnxFib::Remove (const Ptr<const CcnxNameComponents> &prefix) |
| 247 | { |
| 248 | NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix)); |
| 249 | CcnxFibEntryContainer::type::iterator entry = m_fib.find (*prefix); |
| 250 | if (entry != m_fib.end ()) |
| 251 | m_fib.erase (entry); |
| 252 | } |
| 253 | |
| 254 | void |
| 255 | CcnxFib::Invalidate (const Ptr<const CcnxNameComponents> &prefix) |
| 256 | { |
| 257 | NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix)); |
| 258 | |
| 259 | CcnxFibEntryContainer::type::iterator entry = m_fib.find (*prefix); |
| 260 | if (entry == m_fib.end ()) |
| 261 | return; // nothing to invalidate |
| 262 | |
| 263 | m_fib.modify (entry, |
| 264 | ll::bind (&CcnxFibEntry::Invalidate, ll::_1)); |
| 265 | } |
| 266 | |
| 267 | void |
| 268 | CcnxFib::InvalidateAll () |
| 269 | { |
| 270 | NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId ()); |
| 271 | |
| 272 | for (CcnxFibEntryContainer::type::iterator entry = m_fib.begin (); |
| 273 | entry != m_fib.end (); |
| 274 | entry ++) |
| 275 | { |
| 276 | m_fib.modify (entry, |
| 277 | ll::bind (&CcnxFibEntry::Invalidate, ll::_1)); |
| 278 | } |
| 279 | } |
| 280 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 281 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 282 | CcnxFib::Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 283 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 284 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 285 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 286 | m_fib.modify (m_fib.iterator_to (entry), |
| 287 | ll::bind (&CcnxFibEntry::RemoveFace, ll::_1, face)); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 288 | if (entry.m_faces.size () == 0) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 289 | { |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 290 | m_fib.erase (m_fib.iterator_to (entry)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 295 | CcnxFib::RemoveFromAll (Ptr<CcnxFace> face) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 296 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 297 | NS_LOG_FUNCTION (this); |
| 298 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 299 | for_each (m_fib.begin (), m_fib.end (), |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 300 | ll::bind (static_cast< void (CcnxFib::*) (const CcnxFibEntry &, Ptr<CcnxFace>) > (&CcnxFib::Remove), |
| 301 | this, ll::_1, face)); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * \brief Get number of FIB entry (for python bindings) |
| 306 | */ |
| 307 | uint32_t |
| 308 | CcnxFib::GetCcnxFibEntryCount () const |
| 309 | { |
| 310 | return m_fib.size (); |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * \brief Get FIB entry by index (for python bindings) |
| 315 | */ |
| 316 | const CcnxFibEntry & |
| 317 | CcnxFib::GetCcnxFibEntry (uint32_t index) |
| 318 | { |
| 319 | NS_ASSERT (0 <= index && index < m_fib.size ()); |
| 320 | return m_fib.get <i_nth> () [index]; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 321 | } |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 322 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 323 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 324 | std::ostream& operator<< (std::ostream& os, const CcnxFib &fib) |
| 325 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 326 | os << "Node " << Names::FindName (fib.m_node) << "\n"; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 327 | os << " Dest prefix Interfaces(Costs) \n"; |
| 328 | os << "+-------------+--------------------------------------+\n"; |
| 329 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 330 | for (CcnxFibEntryContainer::type::iterator entry = fib.m_fib.begin (); |
| 331 | entry != fib.m_fib.end (); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 332 | entry++) |
| 333 | { |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 334 | os << entry->GetPrefix () << "\t" << *entry << "\n"; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 335 | } |
| 336 | return os; |
| 337 | } |
| 338 | |
| 339 | std::ostream& operator<< (std::ostream& os, const CcnxFibEntry &entry) |
| 340 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 341 | for (CcnxFibFaceMetricContainer::type::index<i_nth>::type::iterator metric = |
| 342 | entry.m_faces.get<i_nth> ().begin (); |
| 343 | metric != entry.m_faces.get<i_nth> ().end (); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 344 | metric++) |
| 345 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 346 | if (metric != entry.m_faces.get<i_nth> ().begin ()) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 347 | os << ", "; |
| 348 | |
| 349 | os << *metric; |
| 350 | } |
| 351 | return os; |
| 352 | } |
| 353 | |
| 354 | std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric) |
| 355 | { |
| 356 | static const std::string statusString[] = {"","g","y","r"}; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 357 | |
Alexander Afanasyev | 3661e23 | 2012-01-20 17:36:15 -0800 | [diff] [blame] | 358 | os << *metric.m_face << "(" << metric.m_routingCost << ","<< statusString [metric.m_status] << "," << metric.m_face->GetMetric () << ")"; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 359 | return os; |
| 360 | } |
| 361 | |
| 362 | // void CcnxFib::resetProbing() |
| 363 | // { |
| 364 | // for(FibRangeIterator fib = _fib.begin(); fib != _fib.end(); fib++) |
| 365 | // VALUE(fib).needsProbing = true; |
| 366 | // } |
| 367 | |
| 368 | // void CcnxFib::updateInterfaceStatus( int interface, int status ) |
| 369 | // { |
| 370 | // for( FibRangeIterator fib = _fib.begin(); fib!=_fib.end(); fib++ ) |
| 371 | // { |
| 372 | // VALUE(fib).updateStatus( interface, status ); |
| 373 | // } |
| 374 | // } |
| 375 | |
| 376 | } // namespace ns3 |