Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "forwarder.hpp" |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 8 | #include "available-strategies.hpp" |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 10 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 11 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 12 | NFD_LOG_INIT("Forwarder"); |
| 13 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 14 | using fw::Strategy; |
| 15 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 16 | const Name Forwarder::LOCALHOST_NAME("ndn:/localhost"); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 17 | |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 18 | Forwarder::Forwarder() |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 19 | : m_faceTable(*this) |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 20 | , m_nameTree(1024) // "1024" could be made as one configurable parameter of the forwarder. |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 21 | , m_fib(m_nameTree) |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 22 | , m_pit(m_nameTree) |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 23 | , m_measurements(m_nameTree) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 24 | , m_strategyChoice(m_nameTree, fw::makeDefaultStrategy(*this)) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 25 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 26 | fw::installStrategies(*this); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 30 | Forwarder::onIncomingInterest(Face& inFace, const Interest& interest) |
| 31 | { |
| 32 | // receive Interest |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 33 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << |
| 34 | " interest=" << interest.getName()); |
Junxiao Shi | 06887ac | 2014-02-13 20:15:42 -0700 | [diff] [blame] | 35 | const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId()); |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 36 | m_counters.getInInterest() ++; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 38 | // /localhost scope control |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 39 | bool isViolatingLocalhost = !inFace.isLocal() && |
| 40 | LOCALHOST_NAME.isPrefixOf(interest.getName()); |
| 41 | if (isViolatingLocalhost) { |
| 42 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << |
| 43 | " interest=" << interest.getName() << " violates /localhost"); |
| 44 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 47 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 48 | // PIT insert |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 49 | shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 51 | // detect loop and record Nonce |
| 52 | bool isLoop = ! pitEntry->addNonce(interest.getNonce()); |
| 53 | if (isLoop) { |
| 54 | // goto Interest loop pipeline |
| 55 | this->onInterestLoop(inFace, interest, pitEntry); |
| 56 | return; |
| 57 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 59 | // cancel unsatisfy & straggler timer |
| 60 | this->cancelUnsatisfyAndStragglerTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 62 | // is pending? |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 63 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 64 | bool isPending = inRecords.begin() == inRecords.end(); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 65 | if (!isPending) { |
| 66 | // CS lookup |
| 67 | const Data* csMatch = m_cs.find(interest); |
| 68 | if (csMatch != 0) { |
| 69 | // XXX should we lookup PIT for other Interests that also match csMatch? |
| 70 | |
| 71 | // goto outgoing Data pipeline |
| 72 | this->onOutgoingData(*csMatch, inFace); |
| 73 | return; |
| 74 | } |
| 75 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 77 | // insert InRecord |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 78 | pitEntry->insertOrUpdateInRecord(inFace.shared_from_this(), interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 79 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 80 | // FIB lookup |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 81 | shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 82 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 83 | // dispatch to strategy |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 84 | this->dispatchToStrategy(pitEntry, bind(&Strategy::afterReceiveInterest, _1, |
| 85 | boost::cref(inFace), boost::cref(interest), fibEntry, pitEntry)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void |
| 89 | Forwarder::onInterestLoop(Face& inFace, const Interest& interest, |
| 90 | shared_ptr<pit::Entry> pitEntry) |
| 91 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 92 | NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << |
| 93 | " interest=" << interest.getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 95 | // (drop) |
| 96 | } |
| 97 | |
| 98 | /** \brief compare two InRecords for picking outgoing Interest |
| 99 | * \return true if b is preferred over a |
| 100 | * |
| 101 | * This function should be passed to std::max_element over InRecordCollection. |
| 102 | * The outgoing Interest picked is the last incoming Interest |
| 103 | * that does not come from outFace. |
| 104 | * If all InRecords come from outFace, it's fine to pick that. This happens when |
| 105 | * there's only one InRecord that comes from outFace. The legit use is for |
| 106 | * vehicular network; otherwise, strategy shouldn't send to the sole inFace. |
| 107 | */ |
| 108 | static inline bool |
| 109 | compare_pickInterest(const pit::InRecord& a, const pit::InRecord& b, const Face* outFace) |
| 110 | { |
| 111 | bool isOutFaceA = a.getFace().get() == outFace; |
| 112 | bool isOutFaceB = b.getFace().get() == outFace; |
| 113 | |
| 114 | if (!isOutFaceA && isOutFaceB) { |
| 115 | return false; |
| 116 | } |
| 117 | if (isOutFaceA && !isOutFaceB) { |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | return a.getLastRenewed() > b.getLastRenewed(); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void |
| 125 | Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace) |
| 126 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 127 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() << |
| 128 | " interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 129 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 130 | // scope control |
| 131 | if (pitEntry->violatesScope(outFace)) { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 132 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() << |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 133 | " interest=" << pitEntry->getName() << " violates scope"); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 137 | // pick Interest |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 138 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 139 | pit::InRecordCollection::const_iterator pickedInRecord = std::max_element( |
| 140 | inRecords.begin(), inRecords.end(), bind(&compare_pickInterest, _1, _2, &outFace)); |
| 141 | BOOST_ASSERT(pickedInRecord != inRecords.end()); |
| 142 | const Interest& interest = pickedInRecord->getInterest(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 143 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 144 | // insert OutRecord |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 145 | pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 146 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 147 | // set PIT unsatisfy timer |
| 148 | this->setUnsatisfyTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 149 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 150 | // send Interest |
| 151 | outFace.sendInterest(interest); |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 152 | m_counters.getOutInterest() ++; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 156 | Forwarder::onInterestReject(shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 157 | { |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 158 | NFD_LOG_DEBUG("onInterestReject interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 159 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 160 | // set PIT straggler timer |
| 161 | this->setStragglerTimer(pitEntry); |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | Forwarder::onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry) |
| 166 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 167 | NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName()); |
| 168 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 169 | // invoke PIT unsatisfied callback |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 170 | this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeExpirePendingInterest, _1, |
| 171 | pitEntry)); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 172 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 173 | // PIT delete |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 174 | m_pit.erase(pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void |
| 178 | Forwarder::onIncomingData(Face& inFace, const Data& data) |
| 179 | { |
| 180 | // receive Data |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 181 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName()); |
Junxiao Shi | 06887ac | 2014-02-13 20:15:42 -0700 | [diff] [blame] | 182 | const_cast<Data&>(data).setIncomingFaceId(inFace.getId()); |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 183 | m_counters.getInData() ++; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 184 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 185 | // /localhost scope control |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 186 | bool isViolatingLocalhost = !inFace.isLocal() && |
| 187 | LOCALHOST_NAME.isPrefixOf(data.getName()); |
| 188 | if (isViolatingLocalhost) { |
| 189 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << |
| 190 | " data=" << data.getName() << " violates /localhost"); |
| 191 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 192 | return; |
| 193 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 194 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 195 | // PIT match |
| 196 | shared_ptr<pit::DataMatchResult> pitMatches = m_pit.findAllDataMatches(data); |
| 197 | if (pitMatches->begin() == pitMatches->end()) { |
| 198 | // goto Data unsolicited pipeline |
| 199 | this->onDataUnsolicited(inFace, data); |
| 200 | return; |
| 201 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 202 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 203 | // CS insert |
| 204 | m_cs.insert(data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 205 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 206 | std::set<shared_ptr<Face> > pendingDownstreams; |
| 207 | // foreach PitEntry |
| 208 | for (pit::DataMatchResult::iterator it = pitMatches->begin(); |
| 209 | it != pitMatches->end(); ++it) { |
| 210 | shared_ptr<pit::Entry> pitEntry = *it; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 211 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 212 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 213 | // cancel unsatisfy & straggler timer |
| 214 | this->cancelUnsatisfyAndStragglerTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 215 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 216 | // remember pending downstreams |
| 217 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 218 | for (pit::InRecordCollection::const_iterator it = inRecords.begin(); |
| 219 | it != inRecords.end(); ++it) { |
| 220 | if (it->getExpiry() > time::now()) { |
| 221 | pendingDownstreams.insert(it->getFace()); |
| 222 | } |
| 223 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 224 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 225 | // mark PIT satisfied |
| 226 | pitEntry->deleteInRecords(); |
| 227 | pitEntry->deleteOutRecord(inFace.shared_from_this()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 228 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 229 | // set PIT straggler timer |
| 230 | this->setStragglerTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 231 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 232 | // invoke PIT satisfy callback |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 233 | this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyPendingInterest, _1, |
| 234 | pitEntry, boost::cref(inFace), boost::cref(data))); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 235 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 236 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 237 | // foreach pending downstream |
| 238 | for (std::set<shared_ptr<Face> >::iterator it = pendingDownstreams.begin(); |
| 239 | it != pendingDownstreams.end(); ++it) { |
| 240 | // goto outgoing Data pipeline |
| 241 | this->onOutgoingData(data, **it); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | void |
| 246 | Forwarder::onDataUnsolicited(Face& inFace, const Data& data) |
| 247 | { |
| 248 | // accept to cache? |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 249 | bool acceptToCache = inFace.isLocal(); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 250 | if (acceptToCache) { |
| 251 | // CS insert |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 252 | m_cs.insert(data, true); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 253 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 254 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 255 | NFD_LOG_DEBUG("onDataUnsolicited face=" << inFace.getId() << |
| 256 | " data=" << data.getName() << |
| 257 | (acceptToCache ? " cached" : " not cached")); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void |
| 261 | Forwarder::onOutgoingData(const Data& data, Face& outFace) |
| 262 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 263 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName()); |
| 264 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 265 | // /localhost scope control |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 266 | bool isViolatingLocalhost = !outFace.isLocal() && |
| 267 | LOCALHOST_NAME.isPrefixOf(data.getName()); |
| 268 | if (isViolatingLocalhost) { |
| 269 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << |
| 270 | " data=" << data.getName() << " violates /localhost"); |
| 271 | // (drop) |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 275 | // TODO traffic manager |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 276 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 277 | // send Data |
| 278 | outFace.sendData(data); |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 279 | m_counters.getOutData() ++; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static inline bool |
| 283 | compare_InRecord_expiry(const pit::InRecord& a, const pit::InRecord& b) |
| 284 | { |
| 285 | return a.getExpiry() < b.getExpiry(); |
| 286 | } |
| 287 | |
| 288 | void |
| 289 | Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry) |
| 290 | { |
| 291 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 292 | pit::InRecordCollection::const_iterator lastExpiring = |
| 293 | std::max_element(inRecords.begin(), inRecords.end(), |
| 294 | &compare_InRecord_expiry); |
| 295 | |
| 296 | time::Point lastExpiry = lastExpiring->getExpiry(); |
| 297 | time::Duration lastExpiryFromNow = lastExpiry - time::now(); |
| 298 | if (lastExpiryFromNow <= time::seconds(0)) { |
| 299 | // TODO all InRecords are already expired; will this happen? |
| 300 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 301 | |
| 302 | pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow, |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 303 | bind(&Forwarder::onInterestUnsatisfied, this, pitEntry)); |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | Forwarder::setStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 308 | { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 309 | if (pitEntry->hasUnexpiredOutRecords()) { |
| 310 | NFD_LOG_DEBUG("setStragglerTimer " << pitEntry->getName() << |
| 311 | " cannot set StragglerTimer when an OutRecord is pending"); |
| 312 | return; |
| 313 | } |
| 314 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 315 | time::Duration stragglerTime = time::milliseconds(100); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 316 | |
| 317 | pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime, |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 318 | bind(&Pit::erase, &m_pit, pitEntry)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void |
| 322 | Forwarder::cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 323 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 324 | scheduler::cancel(pitEntry->m_unsatisfyTimer); |
| 325 | scheduler::cancel(pitEntry->m_stragglerTimer); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 328 | } // namespace nfd |