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