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