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 |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 93 | shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).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 |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 132 | shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 133 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 134 | // dispatch to strategy |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 135 | this->dispatchToStrategy(inFace, interest, fibEntry, pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void |
| 139 | Forwarder::onInterestLoop(Face& inFace, const Interest& interest, |
| 140 | shared_ptr<pit::Entry> pitEntry) |
| 141 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 142 | NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << " interest=" << interest.getName()); |
| 143 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 144 | // do nothing, which means Interest is dropped |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace) |
| 149 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 150 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() << " interest=" << pitEntry->getName()); |
| 151 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 152 | // /localhost scope control |
| 153 | bool violatesLocalhost = !outFace.isLocal() && |
| 154 | s_localhostName.isPrefixOf(pitEntry->getName()); |
| 155 | if (violatesLocalhost) { |
| 156 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() |
| 157 | << " interest=" << pitEntry->getName() << " violates /localhost"); |
| 158 | return; |
| 159 | } |
| 160 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 161 | // pick Interest |
| 162 | const Interest& interest = pitEntry->getInterest(); |
| 163 | // TODO pick the last incoming Interest |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 164 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 165 | // insert OutRecord |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 166 | pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), 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 | // set PIT unsatisfy timer |
| 169 | this->setUnsatisfyTimer(pitEntry); |
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 | // send Interest |
| 172 | outFace.sendInterest(interest); |
| 173 | } |
| 174 | |
| 175 | void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 176 | Forwarder::onInterestReject(shared_ptr<pit::Entry> pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 177 | { |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 178 | NFD_LOG_DEBUG("onInterestReject interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 179 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 180 | // set PIT straggler timer |
| 181 | this->setStragglerTimer(pitEntry); |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | Forwarder::onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry) |
| 186 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 187 | NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName()); |
| 188 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 189 | // invoke PIT unsatisfied callback |
| 190 | // TODO |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 191 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 192 | // PIT erase |
| 193 | m_pit.erase(pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void |
| 197 | Forwarder::onIncomingData(Face& inFace, const Data& data) |
| 198 | { |
| 199 | // receive Data |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 200 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName()); |
Junxiao Shi | 06887ac | 2014-02-13 20:15:42 -0700 | [diff] [blame] | 201 | const_cast<Data&>(data).setIncomingFaceId(inFace.getId()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 202 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 203 | // /localhost scope control |
| 204 | bool violatesLocalhost = !inFace.isLocal() && |
| 205 | s_localhostName.isPrefixOf(data.getName()); |
| 206 | if (violatesLocalhost) { |
| 207 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 208 | << " data=" << data.getName() << " violates /localhost"); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 209 | return; |
| 210 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 211 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 212 | // PIT match |
| 213 | shared_ptr<pit::DataMatchResult> pitMatches = m_pit.findAllDataMatches(data); |
| 214 | if (pitMatches->begin() == pitMatches->end()) { |
| 215 | // goto Data unsolicited pipeline |
| 216 | this->onDataUnsolicited(inFace, data); |
| 217 | return; |
| 218 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 219 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 220 | // CS insert |
| 221 | m_cs.insert(data); |
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 | std::set<shared_ptr<Face> > pendingDownstreams; |
| 224 | // foreach PitEntry |
| 225 | for (pit::DataMatchResult::iterator it = pitMatches->begin(); |
| 226 | it != pitMatches->end(); ++it) { |
| 227 | shared_ptr<pit::Entry> pitEntry = *it; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 228 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 229 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 230 | // cancel unsatisfy & straggler timer |
| 231 | this->cancelUnsatisfyAndStragglerTimer(pitEntry); |
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 | // remember pending downstreams |
| 234 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 235 | for (pit::InRecordCollection::const_iterator it = inRecords.begin(); |
| 236 | it != inRecords.end(); ++it) { |
| 237 | if (it->getExpiry() > time::now()) { |
| 238 | pendingDownstreams.insert(it->getFace()); |
| 239 | } |
| 240 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 241 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 242 | // mark PIT satisfied |
| 243 | pitEntry->deleteInRecords(); |
| 244 | pitEntry->deleteOutRecord(inFace.shared_from_this()); |
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 | // set PIT straggler timer |
| 247 | this->setStragglerTimer(pitEntry); |
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 | // invoke PIT satisfy callback |
| 250 | // TODO |
| 251 | } |
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 | // foreach pending downstream |
| 254 | for (std::set<shared_ptr<Face> >::iterator it = pendingDownstreams.begin(); |
| 255 | it != pendingDownstreams.end(); ++it) { |
| 256 | // goto outgoing Data pipeline |
| 257 | this->onOutgoingData(data, **it); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void |
| 262 | Forwarder::onDataUnsolicited(Face& inFace, const Data& data) |
| 263 | { |
| 264 | // accept to cache? |
| 265 | bool acceptToCache = false;// TODO decision |
| 266 | if (acceptToCache) { |
| 267 | // CS insert |
| 268 | m_cs.insert(data); |
| 269 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 270 | |
| 271 | NFD_LOG_DEBUG("onDataUnsolicited face=" << inFace.getId() << " data=" << data.getName() << " acceptToCache=" << acceptToCache); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void |
| 275 | Forwarder::onOutgoingData(const Data& data, Face& outFace) |
| 276 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 277 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName()); |
| 278 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 279 | // /localhost scope control |
| 280 | bool violatesLocalhost = !outFace.isLocal() && |
| 281 | s_localhostName.isPrefixOf(data.getName()); |
| 282 | if (violatesLocalhost) { |
| 283 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() |
| 284 | << " data=" << data.getName() << " violates /localhost"); |
| 285 | return; |
| 286 | } |
| 287 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 288 | // traffic manager |
| 289 | // pass through |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 290 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 291 | // send Data |
| 292 | outFace.sendData(data); |
| 293 | } |
| 294 | |
| 295 | static inline bool |
| 296 | compare_InRecord_expiry(const pit::InRecord& a, const pit::InRecord& b) |
| 297 | { |
| 298 | return a.getExpiry() < b.getExpiry(); |
| 299 | } |
| 300 | |
| 301 | void |
| 302 | Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry) |
| 303 | { |
| 304 | const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); |
| 305 | pit::InRecordCollection::const_iterator lastExpiring = |
| 306 | std::max_element(inRecords.begin(), inRecords.end(), |
| 307 | &compare_InRecord_expiry); |
| 308 | |
| 309 | time::Point lastExpiry = lastExpiring->getExpiry(); |
| 310 | time::Duration lastExpiryFromNow = lastExpiry - time::now(); |
| 311 | if (lastExpiryFromNow <= time::seconds(0)) { |
| 312 | // TODO all InRecords are already expired; will this happen? |
| 313 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 314 | |
| 315 | pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow, |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 316 | bind(&Forwarder::onInterestUnsatisfied, this, pitEntry)); |
| 317 | } |
| 318 | |
| 319 | void |
| 320 | Forwarder::setStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 321 | { |
| 322 | time::Duration stragglerTime = time::milliseconds(100); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 323 | |
| 324 | pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime, |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 325 | bind(&Pit::erase, &m_pit, pitEntry)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void |
| 329 | Forwarder::cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry) |
| 330 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 331 | scheduler::cancel(pitEntry->m_unsatisfyTimer); |
| 332 | scheduler::cancel(pitEntry->m_stragglerTimer); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 335 | void |
| 336 | Forwarder::dispatchToStrategy(const Face& inFace, |
| 337 | const Interest& interest, |
| 338 | shared_ptr<fib::Entry> fibEntry, |
| 339 | shared_ptr<pit::Entry> pitEntry) |
| 340 | { |
| 341 | m_strategy->afterReceiveInterest(inFace, interest, fibEntry, pitEntry); |
| 342 | // TODO dispatch according to fibEntry |
| 343 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 344 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 345 | } // namespace nfd |