Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -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 | /** \file |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 27 | * \brief Allows testing forwarding in a network topology. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 28 | */ |
| 29 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 30 | #ifndef NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP |
| 31 | #define NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 33 | #include "face/internal-transport.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | #include "face/face.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 35 | #include "fw/strategy.hpp" |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 36 | #include "choose-strategy.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 37 | #include "tests/test-common.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 39 | #include <ndn-cxx/face.hpp> |
| 40 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 41 | namespace nfd::tests { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 42 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 43 | /** \brief Identifies a node (forwarder) in the topology. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 44 | */ |
| 45 | typedef size_t TopologyNode; |
| 46 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 47 | /** \brief Represents a network link in the topology which connects two or more nodes. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 48 | */ |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 49 | class TopologyLink : noncopyable |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 50 | { |
| 51 | public: |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 52 | explicit |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 53 | TopologyLink(time::nanoseconds delay); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 54 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 55 | /** \brief Fail the link, cause packets to be dropped silently. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 56 | */ |
| 57 | void |
| 58 | fail() |
| 59 | { |
| 60 | m_isUp = false; |
| 61 | } |
| 62 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 63 | /** \brief Recover the link from a failure. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 64 | */ |
| 65 | void |
| 66 | recover() |
| 67 | { |
| 68 | m_isUp = true; |
| 69 | } |
| 70 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 71 | /** \brief Block transmission from i to j. |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 72 | * |
| 73 | * Packets transmitted by i would not be delivered to j. Packets from j to i are unaffected. |
| 74 | * This can be used to simulate a wireless channel. |
| 75 | */ |
| 76 | void |
| 77 | block(TopologyNode i, TopologyNode j); |
| 78 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 79 | /** \brief Unblock transmission from i to j. |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 80 | */ |
| 81 | void |
| 82 | unblock(TopologyNode i, TopologyNode j); |
| 83 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 84 | /** \brief Change the link delay. |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 85 | * \param delay link delay, must be positive |
| 86 | */ |
| 87 | void |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 88 | setDelay(time::nanoseconds delay); |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 89 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 90 | /** \brief Attach a face to the link. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 91 | * \param i forwarder index |
| 92 | * \param face a Face with InternalForwarderTransport |
| 93 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 94 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 95 | addFace(TopologyNode i, shared_ptr<Face> face); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 96 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 97 | /** \return a face of forwarder \p i which is attached to this link |
| 98 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 99 | Face& |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 100 | getFace(TopologyNode i) |
| 101 | { |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 102 | return *m_transports.at(i).face; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 105 | private: |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 106 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 107 | transmit(TopologyNode i, const Block& packet); |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 108 | |
| 109 | private: |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 110 | bool m_isUp = true; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 111 | time::nanoseconds m_delay; |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 112 | |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 113 | class ReceiveProxy : public face::InternalTransportBase |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 114 | { |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 115 | public: |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 116 | using Callback = std::function<void(const Block&)>; |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 117 | |
| 118 | explicit |
| 119 | ReceiveProxy(Callback cb) |
| 120 | : m_cb(std::move(cb)) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 125 | receivePacket(const Block& packet) final |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 126 | { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 127 | m_cb(packet); |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | private: |
| 131 | Callback m_cb; |
| 132 | }; |
| 133 | |
| 134 | class NodeTransport |
| 135 | { |
| 136 | public: |
| 137 | NodeTransport(shared_ptr<Face> face, ReceiveProxy::Callback receiveCallback); |
| 138 | |
| 139 | public: |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 140 | shared_ptr<Face> face; |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 141 | face::InternalForwarderTransport* transport; |
| 142 | ReceiveProxy proxy; |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 143 | std::set<TopologyNode> blockedDestinations; |
| 144 | }; |
Davide Pesavento | 284bd62 | 2019-03-31 02:10:02 -0400 | [diff] [blame] | 145 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 146 | std::unordered_map<TopologyNode, NodeTransport> m_transports; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 149 | /** \brief Represents a link on a single forwarder. |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 150 | */ |
| 151 | class TopologySingleLink : noncopyable |
| 152 | { |
| 153 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 154 | /** \brief Constructor. |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 155 | * \param forwarderFace a Face with InternalForwarderTransport |
| 156 | */ |
| 157 | explicit |
| 158 | TopologySingleLink(shared_ptr<Face> forwarderFace); |
| 159 | |
| 160 | /** \return face on forwarder side |
| 161 | */ |
| 162 | Face& |
| 163 | getForwarderFace() |
| 164 | { |
| 165 | return *m_face; |
| 166 | } |
| 167 | |
| 168 | protected: |
| 169 | shared_ptr<Face> m_face; |
| 170 | face::InternalForwarderTransport* m_forwarderTransport; |
| 171 | }; |
| 172 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 173 | /** \brief Represents a link to a local application. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 174 | */ |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 175 | class TopologyAppLink : public TopologySingleLink |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 176 | { |
| 177 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 178 | /** \brief Constructor. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 179 | * \param forwarderFace a Face with InternalForwarderTransport |
| 180 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 181 | explicit |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 182 | TopologyAppLink(shared_ptr<Face> forwarderFace); |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 183 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 184 | /** \brief Fail the link, cause packets to be dropped silently. |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 185 | */ |
| 186 | void |
| 187 | fail(); |
| 188 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 189 | /** \brief Recover the link from a failure. |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 190 | */ |
| 191 | void |
| 192 | recover(); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 193 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 194 | /** \return face on application side |
| 195 | */ |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 196 | ndn::Face& |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 197 | getClientFace() |
| 198 | { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 199 | return *m_client; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | private: |
Junxiao Shi | 6535f1e | 2015-10-08 13:02:18 -0700 | [diff] [blame] | 203 | shared_ptr<face::InternalClientTransport> m_clientTransport; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 204 | shared_ptr<ndn::Face> m_client; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 207 | /** \brief Allows the test case to inject and observe L2 packets on a link. |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 208 | */ |
| 209 | class TopologyBareLink : public TopologySingleLink |
| 210 | { |
| 211 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 212 | /** \brief Constructor. |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 213 | * \param forwarderFace a Face with InternalForwarderTransport |
| 214 | */ |
| 215 | explicit |
| 216 | TopologyBareLink(shared_ptr<Face> forwarderFace); |
| 217 | |
| 218 | void |
| 219 | receivePacket(const Block& packet); |
| 220 | |
| 221 | public: |
| 222 | std::vector<Block> sentPackets; |
| 223 | |
| 224 | private: |
| 225 | class Observer; |
| 226 | unique_ptr<Observer> m_observer; |
| 227 | }; |
| 228 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 229 | /** \brief Captured packets on a face. |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 230 | */ |
| 231 | class TopologyPcap : noncopyable |
| 232 | { |
| 233 | public: |
| 234 | std::vector<Interest> sentInterests; |
| 235 | std::vector<Data> sentData; |
| 236 | std::vector<lp::Nack> sentNacks; |
| 237 | }; |
| 238 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 239 | /** \brief Captured packet timestamp tag. |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 240 | */ |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 241 | using TopologyPcapTimestamp = ndn::SimpleTag<time::steady_clock::time_point, 0>; |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 242 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 243 | /** \brief Builds a topology for forwarding tests. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 244 | */ |
| 245 | class TopologyTester : noncopyable |
| 246 | { |
| 247 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 248 | /** \brief Creates a forwarder. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 249 | * \return index of new forwarder |
| 250 | */ |
| 251 | TopologyNode |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 252 | addForwarder(const std::string& label); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 253 | |
| 254 | /** \return forwarder instance \p i |
| 255 | */ |
| 256 | Forwarder& |
| 257 | getForwarder(TopologyNode i) |
| 258 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 259 | return m_forwarders.at(i)->forwarder; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 262 | /** \brief Sets strategy on forwarder \p i. |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 263 | * \tparam S the strategy type |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 264 | * \note Test scenario can also access StrategyChoice table directly. |
| 265 | */ |
| 266 | template<typename S> |
| 267 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 268 | setStrategy(TopologyNode i, Name prefix = Name("ndn:/"), |
| 269 | Name instanceName = S::getStrategyName()) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 270 | { |
| 271 | Forwarder& forwarder = this->getForwarder(i); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 272 | choose<S>(forwarder, prefix, instanceName); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 275 | /** \brief Makes a link that interconnects two or more forwarders. |
| 276 | * \param linkType Desired link type; LINK_TYPE_NONE to use point-to-point for two forwarders |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 277 | * and multi-access for more than two forwarders; it's an error to specify |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 278 | * point-to-point when there are more than two forwarders. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 279 | * |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 280 | * A face is created on each of \p forwarders. |
| 281 | * When a packet is sent onto one of the faces on this link, the packet will be |
| 282 | * received by all other faces on this link after the specified delay. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 283 | */ |
| 284 | shared_ptr<TopologyLink> |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 285 | addLink(const std::string& label, time::nanoseconds delay, |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 286 | std::initializer_list<TopologyNode> forwarders, |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 287 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_NONE); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 288 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 289 | /** \brief Makes a link to a local application. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 290 | */ |
| 291 | shared_ptr<TopologyAppLink> |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 292 | addAppFace(const std::string& label, TopologyNode i); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 293 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 294 | /** \brief Makes a link to a local application and registers a prefix. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 295 | */ |
| 296 | shared_ptr<TopologyAppLink> |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 297 | addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost = 0); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 298 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 299 | /** \brief Makes a link that allows the test case to inject and observe layer-2 packets. |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 300 | */ |
| 301 | shared_ptr<TopologyBareLink> |
| 302 | addBareLink(const std::string& label, TopologyNode i, |
| 303 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_LOCAL, |
| 304 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 305 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 306 | /** \brief Enables packet capture on every forwarder face. |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 307 | */ |
| 308 | void |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 309 | enablePcap(bool isEnabled = true) |
| 310 | { |
| 311 | m_wantPcap = isEnabled; |
| 312 | } |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 313 | |
| 314 | /** \return captured packets on a forwarder face |
| 315 | * \pre enablePcap(true) is in effect when the face was created |
| 316 | */ |
| 317 | TopologyPcap& |
| 318 | getPcap(const Face& face); |
| 319 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 320 | /** \brief Registers a prefix on a forwarder face. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 321 | */ |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 322 | void |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 323 | registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost = 0); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 324 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 325 | /** \brief Creates a producer application that answers every Interest with Data of same Name. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 326 | */ |
| 327 | void |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 328 | addEchoProducer(ndn::Face& face, const Name& prefix = "/", time::nanoseconds replyDelay = 0_ns); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 329 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 330 | /** \brief Creates a consumer application that sends \p n Interests under \p prefix |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 331 | * at \p interval fixed rate. |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 332 | * \param seq if non-negative, append sequence number instead of timestamp |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 333 | */ |
| 334 | void |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 335 | addIntervalConsumer(ndn::Face& face, const Name& prefix, time::nanoseconds interval, |
| 336 | size_t n, int seq = -1); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 337 | |
| 338 | private: |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 339 | shared_ptr<Face> |
| 340 | makeFace(TopologyNode i, const FaceUri& localUri, const FaceUri& remoteUri, |
| 341 | ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType); |
| 342 | |
| 343 | private: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 344 | class TopologyForwarder |
| 345 | { |
| 346 | public: |
| 347 | explicit |
| 348 | TopologyForwarder(const std::string& label) |
| 349 | : label(label) |
| 350 | { |
| 351 | } |
| 352 | |
| 353 | public: |
| 354 | std::string label; |
| 355 | FaceTable faceTable; |
| 356 | Forwarder forwarder{faceTable}; |
| 357 | }; |
| 358 | |
| 359 | std::vector<unique_ptr<TopologyForwarder>> m_forwarders; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 360 | std::vector<shared_ptr<TopologyLink>> m_links; |
| 361 | std::vector<shared_ptr<TopologyAppLink>> m_appLinks; |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 362 | std::vector<shared_ptr<TopologyBareLink>> m_bareLinks; |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 363 | bool m_wantPcap = false; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 366 | } // namespace nfd::tests |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 367 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 368 | #endif // NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP |