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