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