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