Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0a05f7a | 2023-10-16 20:28:06 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "topology-tester.hpp" |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 27 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 28 | #include "common/global.hpp" |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 29 | #include "face/generic-link-service.hpp" |
| 30 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 31 | #include <ndn-cxx/encoding/encoding-buffer-fwd.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 35 | using face::GenericLinkService; |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 36 | using face::InternalClientTransport; |
| 37 | using face::InternalForwarderTransport; |
| 38 | |
| 39 | TopologyLink::NodeTransport::NodeTransport(shared_ptr<Face> f, ReceiveProxy::Callback cb) |
| 40 | : face(std::move(f)) |
| 41 | , transport(dynamic_cast<InternalForwarderTransport*>(face->getTransport())) |
| 42 | , proxy(std::move(cb)) |
| 43 | { |
| 44 | BOOST_ASSERT(transport != nullptr); |
| 45 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 46 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 47 | TopologyLink::TopologyLink(time::nanoseconds delay) |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 48 | { |
| 49 | this->setDelay(delay); |
| 50 | } |
| 51 | |
| 52 | void |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 53 | TopologyLink::block(TopologyNode i, TopologyNode j) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 54 | { |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 55 | m_transports.at(i).blockedDestinations.insert(j); |
| 56 | } |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 57 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 58 | void |
| 59 | TopologyLink::unblock(TopologyNode i, TopologyNode j) |
| 60 | { |
| 61 | m_transports.at(i).blockedDestinations.erase(j); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | TopologyLink::setDelay(time::nanoseconds delay) |
| 66 | { |
| 67 | BOOST_ASSERT(delay > time::nanoseconds::zero()); // zero delay does not work on macOS |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 68 | m_delay = delay; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 72 | TopologyLink::addFace(TopologyNode i, shared_ptr<Face> face) |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 73 | { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 74 | auto receiveCb = [this, i] (const Block& packet) { transmit(i, packet); }; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 75 | auto ret = m_transports.try_emplace(i, std::move(face), std::move(receiveCb)); |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 76 | BOOST_ASSERT(ret.second); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 77 | |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 78 | auto& node = ret.first->second; |
| 79 | node.transport->setPeer(&node.proxy); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 83 | TopologyLink::transmit(TopologyNode i, const Block& packet) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 84 | { |
| 85 | if (!m_isUp) { |
| 86 | return; |
| 87 | } |
| 88 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 89 | const auto& blockedDestinations = m_transports.at(i).blockedDestinations; |
| 90 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 91 | for (const auto& [node, transport] : m_transports) { |
| 92 | if (node == i || blockedDestinations.count(node) > 0) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 93 | continue; |
| 94 | } |
| 95 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 96 | getScheduler().schedule(m_delay, [packet, recipient = transport.transport] { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 97 | recipient->receivePacket(packet); |
| 98 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 102 | TopologySingleLink::TopologySingleLink(shared_ptr<Face> forwarderFace) |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 103 | : m_face(std::move(forwarderFace)) |
| 104 | , m_forwarderTransport(static_cast<InternalForwarderTransport*>(m_face->getTransport())) |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 105 | { |
| 106 | } |
| 107 | |
| 108 | TopologyAppLink::TopologyAppLink(shared_ptr<Face> forwarderFace) |
| 109 | : TopologySingleLink(std::move(forwarderFace)) |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 110 | , m_clientTransport(make_shared<InternalClientTransport>()) |
| 111 | , m_client(make_shared<ndn::Face>(m_clientTransport, getGlobalIoService())) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 112 | { |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 113 | this->recover(); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 117 | TopologyAppLink::fail() |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 118 | { |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 119 | m_clientTransport->connectToForwarder(nullptr); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | TopologyAppLink::recover() |
| 124 | { |
| 125 | m_clientTransport->connectToForwarder(m_forwarderTransport); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Davide Pesavento | 0a05f7a | 2023-10-16 20:28:06 -0400 | [diff] [blame] | 128 | class TopologyBareLink::Observer final : public face::InternalTransportBase |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 129 | { |
| 130 | public: |
| 131 | explicit |
| 132 | Observer(std::vector<Block>& receivedPackets) |
| 133 | : m_receivedPackets(receivedPackets) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void |
| 138 | receivePacket(const Block& packet) final |
| 139 | { |
| 140 | m_receivedPackets.push_back(packet); |
| 141 | } |
| 142 | |
| 143 | private: |
| 144 | std::vector<Block>& m_receivedPackets; |
| 145 | }; |
| 146 | |
| 147 | TopologyBareLink::TopologyBareLink(shared_ptr<Face> forwarderFace) |
| 148 | : TopologySingleLink(std::move(forwarderFace)) |
| 149 | , m_observer(make_unique<Observer>(sentPackets)) |
| 150 | { |
| 151 | m_forwarderTransport->setPeer(m_observer.get()); |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | TopologyBareLink::receivePacket(const Block& packet) |
| 156 | { |
| 157 | m_forwarderTransport->receivePacket(packet); |
| 158 | } |
| 159 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 160 | class TopologyPcapLinkService : public GenericLinkService |
| 161 | , public TopologyPcap |
| 162 | { |
| 163 | private: |
| 164 | ///\todo #3941 call GenericLinkServiceCounters constructor in TopologyPcapLinkService constructor |
| 165 | |
| 166 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 167 | doSendInterest(const Interest& interest) override |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 168 | { |
| 169 | this->sentInterests.push_back(interest); |
| 170 | this->sentInterests.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now())); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 171 | this->GenericLinkService::doSendInterest(interest); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 175 | doSendData(const Data& data) override |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 176 | { |
| 177 | this->sentData.push_back(data); |
| 178 | this->sentData.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now())); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 179 | this->GenericLinkService::doSendData(data); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 183 | doSendNack(const lp::Nack& nack) override |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 184 | { |
| 185 | this->sentNacks.push_back(nack); |
| 186 | this->sentNacks.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now())); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 187 | this->GenericLinkService::doSendNack(nack); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 188 | } |
| 189 | }; |
| 190 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 191 | TopologyNode |
| 192 | TopologyTester::addForwarder(const std::string& label) |
| 193 | { |
| 194 | size_t i = m_forwarders.size(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 195 | m_forwarders.push_back(make_unique<TopologyForwarder>(label)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 196 | return i; |
| 197 | } |
| 198 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 199 | shared_ptr<Face> |
| 200 | TopologyTester::makeFace(TopologyNode i, const FaceUri& localUri, const FaceUri& remoteUri, |
| 201 | ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType) |
| 202 | { |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 203 | unique_ptr<GenericLinkService> service = m_wantPcap ? make_unique<TopologyPcapLinkService>() : |
| 204 | make_unique<GenericLinkService>(); |
| 205 | auto transport = make_unique<InternalForwarderTransport>(localUri, remoteUri, scope, linkType); |
| 206 | auto face = make_shared<Face>(std::move(service), std::move(transport)); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 207 | m_forwarders.at(i)->faceTable.add(face); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 208 | return face; |
| 209 | } |
| 210 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 211 | shared_ptr<TopologyLink> |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 212 | TopologyTester::addLink(const std::string& label, time::nanoseconds delay, |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 213 | std::initializer_list<TopologyNode> forwarders, |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 214 | ndn::nfd::LinkType linkType) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 215 | { |
Yumin Xia | ab49745 | 2016-05-10 20:23:24 +0800 | [diff] [blame] | 216 | auto link = std::make_shared<TopologyLink>(delay); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 217 | FaceUri remoteUri("topology://link/" + label); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 218 | if (linkType == ndn::nfd::LINK_TYPE_NONE) { |
| 219 | linkType = forwarders.size() > 2 ? ndn::nfd::LINK_TYPE_MULTI_ACCESS : |
| 220 | ndn::nfd::LINK_TYPE_POINT_TO_POINT; |
| 221 | } |
| 222 | BOOST_ASSERT(forwarders.size() <= 2 || linkType != ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 223 | |
| 224 | for (TopologyNode i : forwarders) { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 225 | FaceUri localUri("topology://" + m_forwarders.at(i)->label + "/" + label); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 226 | auto face = makeFace(i, localUri, remoteUri, ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType); |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 227 | link->addFace(i, std::move(face)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | m_links.push_back(link); // keep a shared_ptr so callers don't have to |
| 231 | return link; |
| 232 | } |
| 233 | |
| 234 | shared_ptr<TopologyAppLink> |
| 235 | TopologyTester::addAppFace(const std::string& label, TopologyNode i) |
| 236 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 237 | FaceUri localUri("topology://" + m_forwarders.at(i)->label + "/local/" + label); |
| 238 | FaceUri remoteUri("topology://" + m_forwarders.at(i)->label + "/app/" + label); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 239 | auto face = makeFace(i, localUri, remoteUri, ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 240 | |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 241 | auto al = make_shared<TopologyAppLink>(std::move(face)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 242 | m_appLinks.push_back(al); // keep a shared_ptr so callers don't have to |
| 243 | return al; |
| 244 | } |
| 245 | |
| 246 | shared_ptr<TopologyAppLink> |
| 247 | TopologyTester::addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost) |
| 248 | { |
| 249 | shared_ptr<TopologyAppLink> al = this->addAppFace(label, i); |
| 250 | this->registerPrefix(i, al->getForwarderFace(), prefix, cost); |
| 251 | return al; |
| 252 | } |
| 253 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 254 | shared_ptr<TopologyBareLink> |
| 255 | TopologyTester::addBareLink(const std::string& label, TopologyNode i, ndn::nfd::FaceScope scope, |
| 256 | ndn::nfd::LinkType linkType) |
| 257 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 258 | FaceUri localUri("topology://" + m_forwarders.at(i)->label + "/local/" + label); |
| 259 | FaceUri remoteUri("topology://" + m_forwarders.at(i)->label + "/bare/" + label); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 260 | auto face = makeFace(i, localUri, remoteUri, scope, linkType); |
| 261 | |
| 262 | auto bl = make_shared<TopologyBareLink>(std::move(face)); |
| 263 | m_bareLinks.push_back(bl); // keep a shared_ptr so callers don't have to |
| 264 | return bl; |
| 265 | } |
| 266 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 267 | TopologyPcap& |
| 268 | TopologyTester::getPcap(const Face& face) |
| 269 | { |
| 270 | return dynamic_cast<TopologyPcapLinkService&>(*face.getLinkService()); |
| 271 | } |
| 272 | |
| 273 | void |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 274 | TopologyTester::registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost) |
| 275 | { |
| 276 | Forwarder& forwarder = this->getForwarder(i); |
| 277 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 278 | fib::Entry* entry = fib.insert(prefix).first; |
| 279 | fib.addOrUpdateNextHop(*entry, const_cast<Face&>(face), cost); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 283 | TopologyTester::addEchoProducer(ndn::Face& face, const Name& prefix, time::nanoseconds replyDelay) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 284 | { |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 285 | BOOST_ASSERT(replyDelay >= 0_ns); |
| 286 | |
| 287 | face.setInterestFilter(prefix, [=, &face] (const auto&, const auto& interest) { |
| 288 | auto data = makeData(interest.getName()); |
| 289 | if (replyDelay == 0_ns) { |
| 290 | // reply immediately |
| 291 | face.put(*data); |
| 292 | } |
| 293 | else { |
| 294 | // delay the reply |
| 295 | getScheduler().schedule(replyDelay, [&face, data = std::move(data)] { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 296 | face.put(*data); |
| 297 | }); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 298 | } |
| 299 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void |
| 303 | TopologyTester::addIntervalConsumer(ndn::Face& face, const Name& prefix, |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 304 | time::nanoseconds interval, size_t n, int seq) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 305 | { |
| 306 | Name name(prefix); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 307 | if (seq >= 0) { |
| 308 | name.appendSequenceNumber(seq); |
| 309 | ++seq; |
| 310 | } |
| 311 | else { |
| 312 | name.appendTimestamp(); |
| 313 | } |
| 314 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 315 | auto interest = makeInterest(name); |
Junxiao Shi | 9ede5bd | 2016-08-09 03:51:27 +0000 | [diff] [blame] | 316 | face.expressInterest(*interest, nullptr, nullptr, nullptr); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 317 | |
| 318 | if (n > 1) { |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 319 | getScheduler().schedule(interval, [=, &face] { |
| 320 | addIntervalConsumer(face, prefix, interval, n - 1, seq); |
| 321 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 325 | } // namespace nfd::tests |