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 | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 8 | #include "core/logger.hpp" |
| 9 | #include "best-route-strategy.hpp" |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 10 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 11 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 12 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 13 | NFD_LOG_INIT("Forwarder"); |
| 14 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 15 | const Name Forwarder::s_localhostName("ndn:/localhost"); |
| 16 | |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 17 | Forwarder::Forwarder() |
| 18 | : m_lastFaceId(0) |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame^] | 19 | , m_nameTree(1024) // "1024" could be made as one configurable parameter of the forwarder. |
| 20 | , m_pit(m_nameTree) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 21 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 22 | m_strategy = make_shared<fw::BestRouteStrategy>(boost::ref(*this)); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 26 | Forwarder::addFace(shared_ptr<Face> face) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 27 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 28 | FaceId faceId = ++m_lastFaceId; |
| 29 | face->setId(faceId); |
| 30 | m_faces[faceId] = face; |
| 31 | NFD_LOG_INFO("addFace id=" << faceId); |
| 32 | |
| 33 | face->onReceiveInterest += bind(&Forwarder::onInterest, |
| 34 | this, boost::ref(*face), _1); |
| 35 | face->onReceiveData += bind(&Forwarder::onData, |
| 36 | this, boost::ref(*face), _1); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 40 | Forwarder::removeFace(shared_ptr<Face> face) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 41 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 42 | FaceId faceId = face->getId(); |
| 43 | m_faces.erase(faceId); |
| 44 | face->setId(INVALID_FACEID); |
| 45 | NFD_LOG_INFO("removeFace id=" << faceId); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 46 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 47 | // XXX This clears all subscriptions, because EventEmitter |
| 48 | // does not support only removing Forwarder's subscription |
| 49 | face->onReceiveInterest.clear(); |
| 50 | face->onReceiveData .clear(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 51 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 52 | m_fib.removeNextHopFromAllEntries(face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Steve DiBenedetto | 26b730f | 2014-02-02 18:36:16 -0700 | [diff] [blame] | 55 | shared_ptr<Face> |
| 56 | Forwarder::getFace(FaceId id) |
| 57 | { |
| 58 | std::map<FaceId, shared_ptr<Face> >::iterator i = m_faces.find(id); |
| 59 | return (i == m_faces.end()) ? (shared_ptr<Face>()) : (i->second); |
| 60 | } |
| 61 | |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 62 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 63 | Forwarder::onInterest(Face& face, const Interest& interest) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 64 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 65 | this->onIncomingInterest(face, interest); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | Forwarder::onData(Face& face, const Data& data) |
| 70 | { |
| 71 | this->onIncomingData(face, data); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 74 | void |
| 75 | Forwarder::onIncomingInterest(Face& inFace, const Interest& interest) |
| 76 | { |
| 77 | // receive Interest |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 78 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << " interest=" << interest.getName()); |
Junxiao Shi | 06887ac | 2014-02-13 20:15:42 -0700 | [diff] [blame] | 79 | const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 81 | // /localhost scope control |
| 82 | bool violatesLocalhost = !inFace.isLocal() && |
| 83 | s_localhostName.isPrefixOf(interest.getName()); |
| 84 | if (violatesLocalhost) { |
| 85 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() |
| 86 | << " interest=" << interest.getName() << " violates /localhost"); |
| 87 | return; |
| 88 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 90 | // PIT insert |
| 91 | std::pair<shared_ptr<pit::Entry>, bool> |
| 92 | pitInsertResult = m_pit.insert(interest); |
| 93 | shared_ptr<pit::Entry> pitEntry = pitInsertResult.first; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 95 | // detect loop and record Nonce |
| 96 | bool isLoop = ! pitEntry->addNonce(interest.getNonce()); |
| 97 | if (isLoop) { |
| 98 | // goto Interest loop pipeline |
| 99 | this->onInterestLoop(inFace, interest, pitEntry); |
| 100 | return; |
| 101 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 103 | // cancel unsatisfy & straggler timer |
| 104 | this->cancelUnsatisfyAndStragglerTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 105 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 106 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 107 | bool isPending = inRecords.begin() == inRecords.end(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 109 | if (!isPending) { |
| 110 | // CS lookup |
| 111 | const Data* csMatch = m_cs.find(interest); |
| 112 | if (csMatch != 0) { |
| 113 | // XXX should we lookup PIT for other Interests that also match csMatch? |
| 114 | |
| 115 | // goto outgoing Data pipeline |
| 116 | this->onOutgoingData(*csMatch, inFace); |
| 117 | return; |
| 118 | } |
| 119 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 120 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 121 | // insert InRecord |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 122 | pitEntry->insertOrUpdateInRecord(inFace.shared_from_this(), interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 123 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 124 | // app chosen nexthops |
| 125 | bool isAppChosenNexthops = false; // TODO get from local control header |
| 126 | if (isAppChosenNexthops) { |
| 127 | // TODO foreach chosen nexthop: goto outgoing Interest pipeline |
| 128 | return; |
| 129 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 130 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 131 | // FIB lookup |
| 132 | shared_ptr<fib::Entry> fibEntry |
| 133 | = m_fib.findLongestPrefixMatch(interest.getName()); |
| 134 | // TODO use Fib::findParent(pitEntry) |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 135 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 136 | // dispatch to strategy |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 137 | this->dispatchToStrategy(inFace, interest, fibEntry, pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void |
| 141 | Forwarder::onInterestLoop(Face& inFace, const Interest& interest, |
| 142 | shared_ptr<pit::Entry> pitEntry) |
| 143 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 144 | NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << " interest=" << interest.getName()); |
| 145 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 146 | // do nothing, which means Interest is dropped |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace) |
| 151 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 152 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() << " interest=" << pitEntry->getName()); |
| 153 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 154 | // /localhost scope control |
| 155 | bool violatesLocalhost = !outFace.isLocal() && |
| 156 | s_localhostName.isPrefixOf(pitEntry->getName()); |
| 157 | if (violatesLocalhost) { |
| 158 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() |
| 159 | << " interest=" << pitEntry->getName() << " violates /localhost"); |
| 160 | return; |
| 161 | } |
| 162 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 163 | // pick Interest |
| 164 | const Interest& interest = pitEntry->getInterest(); |
| 165 | // TODO pick the last incoming Interest |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 166 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 167 | // insert OutRecord |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 168 | pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 169 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 170 | // set PIT unsatisfy timer |
| 171 | this->setUnsatisfyTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 172 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 173 | // send Interest |
| 174 | outFace.sendInterest(interest); |
| 175 | } |
| 176 | |
| 177 | void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 178 | Forwarder::onInterestReject(shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 179 | { |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 180 | NFD_LOG_DEBUG("onInterestReject interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 181 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 182 | // set PIT straggler timer |
| 183 | this->setStragglerTimer(pitEntry); |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | Forwarder::onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry) |
| 188 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 189 | NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName()); |
| 190 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 191 | // invoke PIT unsatisfied callback |
| 192 | // TODO |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 193 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame^] | 194 | // PIT erase |
| 195 | m_pit.erase(pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void |
| 199 | Forwarder::onIncomingData(Face& inFace, const Data& data) |
| 200 | { |
| 201 | // receive Data |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 202 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName()); |
Junxiao Shi | 06887ac | 2014-02-13 20:15:42 -0700 | [diff] [blame] | 203 | const_cast<Data&>(data).setIncomingFaceId(inFace.getId()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 204 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 205 | // /localhost scope control |
| 206 | bool violatesLocalhost = !inFace.isLocal() && |
| 207 | s_localhostName.isPrefixOf(data.getName()); |
| 208 | if (violatesLocalhost) { |
| 209 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 210 | << " data=" << data.getName() << " violates /localhost"); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 211 | return; |
| 212 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 213 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 214 | // PIT match |
| 215 | shared_ptr<pit::DataMatchResult> pitMatches = m_pit.findAllDataMatches(data); |
| 216 | if (pitMatches->begin() == pitMatches->end()) { |
| 217 | // goto Data unsolicited pipeline |
| 218 | this->onDataUnsolicited(inFace, data); |
| 219 | return; |
| 220 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 221 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 222 | // CS insert |
| 223 | m_cs.insert(data); |
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 | std::set<shared_ptr<Face> > pendingDownstreams; |
| 226 | // foreach PitEntry |
| 227 | for (pit::DataMatchResult::iterator it = pitMatches->begin(); |
| 228 | it != pitMatches->end(); ++it) { |
| 229 | shared_ptr<pit::Entry> pitEntry = *it; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 230 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
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 | // cancel unsatisfy & straggler timer |
| 233 | this->cancelUnsatisfyAndStragglerTimer(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 | // remember pending downstreams |
| 236 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 237 | for (pit::InRecordCollection::const_iterator it = inRecords.begin(); |
| 238 | it != inRecords.end(); ++it) { |
| 239 | if (it->getExpiry() > time::now()) { |
| 240 | pendingDownstreams.insert(it->getFace()); |
| 241 | } |
| 242 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 243 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 244 | // mark PIT satisfied |
| 245 | pitEntry->deleteInRecords(); |
| 246 | pitEntry->deleteOutRecord(inFace.shared_from_this()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 247 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 248 | // set PIT straggler timer |
| 249 | this->setStragglerTimer(pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 250 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 251 | // invoke PIT satisfy callback |
| 252 | // TODO |
| 253 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 254 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 255 | // foreach pending downstream |
| 256 | for (std::set<shared_ptr<Face> >::iterator it = pendingDownstreams.begin(); |
| 257 | it != pendingDownstreams.end(); ++it) { |
| 258 | // goto outgoing Data pipeline |
| 259 | this->onOutgoingData(data, **it); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | void |
| 264 | Forwarder::onDataUnsolicited(Face& inFace, const Data& data) |
| 265 | { |
| 266 | // accept to cache? |
| 267 | bool acceptToCache = false;// TODO decision |
| 268 | if (acceptToCache) { |
| 269 | // CS insert |
| 270 | m_cs.insert(data); |
| 271 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 272 | |
| 273 | NFD_LOG_DEBUG("onDataUnsolicited face=" << inFace.getId() << " data=" << data.getName() << " acceptToCache=" << acceptToCache); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void |
| 277 | Forwarder::onOutgoingData(const Data& data, Face& outFace) |
| 278 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 279 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName()); |
| 280 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 281 | // /localhost scope control |
| 282 | bool violatesLocalhost = !outFace.isLocal() && |
| 283 | s_localhostName.isPrefixOf(data.getName()); |
| 284 | if (violatesLocalhost) { |
| 285 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() |
| 286 | << " data=" << data.getName() << " violates /localhost"); |
| 287 | return; |
| 288 | } |
| 289 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 290 | // traffic manager |
| 291 | // pass through |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 292 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 293 | // send Data |
| 294 | outFace.sendData(data); |
| 295 | } |
| 296 | |
| 297 | static inline bool |
| 298 | compare_InRecord_expiry(const pit::InRecord& a, const pit::InRecord& b) |
| 299 | { |
| 300 | return a.getExpiry() < b.getExpiry(); |
| 301 | } |
| 302 | |
| 303 | void |
| 304 | Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry) |
| 305 | { |
| 306 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 307 | pit::InRecordCollection::const_iterator lastExpiring = |
| 308 | std::max_element(inRecords.begin(), inRecords.end(), |
| 309 | &compare_InRecord_expiry); |
| 310 | |
| 311 | time::Point lastExpiry = lastExpiring->getExpiry(); |
| 312 | time::Duration lastExpiryFromNow = lastExpiry - time::now(); |
| 313 | if (lastExpiryFromNow <= time::seconds(0)) { |
| 314 | // TODO all InRecords are already expired; will this happen? |
| 315 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 316 | |
| 317 | pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow, |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 318 | bind(&Forwarder::onInterestUnsatisfied, this, pitEntry)); |
| 319 | } |
| 320 | |
| 321 | void |
| 322 | Forwarder::setStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 323 | { |
| 324 | time::Duration stragglerTime = time::milliseconds(100); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 325 | |
| 326 | pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime, |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame^] | 327 | bind(&Pit::erase, &m_pit, pitEntry)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void |
| 331 | Forwarder::cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 332 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 333 | scheduler::cancel(pitEntry->m_unsatisfyTimer); |
| 334 | scheduler::cancel(pitEntry->m_stragglerTimer); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 337 | void |
| 338 | Forwarder::dispatchToStrategy(const Face& inFace, |
| 339 | const Interest& interest, |
| 340 | shared_ptr<fib::Entry> fibEntry, |
| 341 | shared_ptr<pit::Entry> pitEntry) |
| 342 | { |
| 343 | m_strategy->afterReceiveInterest(inFace, interest, fibEntry, pitEntry); |
| 344 | // TODO dispatch according to fibEntry |
| 345 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 346 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 347 | } // namespace nfd |