Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -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 "mgmt/face-manager.hpp" |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame] | 27 | #include "core/random.hpp" |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 28 | #include "face/protocol-factory.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 30 | #include "nfd-manager-common-fixture.hpp" |
| 31 | #include "../face/dummy-face.hpp" |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 32 | #include "../face/dummy-transport.hpp" |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 33 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/encoding/tlv.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/mgmt/nfd/channel-status.hpp> |
| 36 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 37 | |
| 38 | namespace nfd { |
| 39 | namespace tests { |
| 40 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 41 | class FaceManagerFixture : public NfdManagerCommonFixture |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
| 44 | FaceManagerFixture() |
| 45 | : m_faceTable(m_forwarder.getFaceTable()) |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 46 | , m_faceSystem(m_faceTable) |
| 47 | , m_manager(m_faceSystem, m_dispatcher, *m_authenticator) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 48 | { |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 49 | setTopPrefix(); |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 50 | setPrivilege("faces"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 54 | enum AddFaceFlags { |
| 55 | REMOVE_LAST_NOTIFICATION = 1 << 0, |
| 56 | SET_SCOPE_LOCAL = 1 << 1, |
| 57 | SET_URI_TEST = 1 << 2, |
| 58 | RANDOMIZE_COUNTERS = 1 << 3 |
| 59 | }; |
| 60 | |
| 61 | /** \brief adds a face to the FaceTable |
| 62 | * \param options bitwise OR'ed AddFaceFlags |
| 63 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 64 | shared_ptr<Face> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 65 | addFace(int flags = 0) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 66 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 67 | std::string uri = "dummy://"; |
| 68 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL; |
| 69 | |
| 70 | if ((flags & SET_SCOPE_LOCAL) != 0) { |
| 71 | scope = ndn::nfd::FACE_SCOPE_LOCAL; |
| 72 | } |
| 73 | if ((flags & SET_URI_TEST) != 0) { |
| 74 | uri = "test://"; |
| 75 | } |
| 76 | |
| 77 | auto face = make_shared<DummyFace>(uri, uri, scope); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 78 | m_faceTable.add(face); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 79 | |
| 80 | if ((flags & RANDOMIZE_COUNTERS) != 0) { |
| 81 | const face::FaceCounters& counters = face->getCounters(); |
| 82 | randomizeCounter(counters.nInInterests); |
| 83 | randomizeCounter(counters.nOutInterests); |
| 84 | randomizeCounter(counters.nInData); |
| 85 | randomizeCounter(counters.nOutData); |
| 86 | randomizeCounter(counters.nInNacks); |
| 87 | randomizeCounter(counters.nOutNacks); |
| 88 | randomizeCounter(counters.nInPackets); |
| 89 | randomizeCounter(counters.nOutPackets); |
| 90 | randomizeCounter(counters.nInBytes); |
| 91 | randomizeCounter(counters.nOutBytes); |
| 92 | } |
| 93 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 94 | advanceClocks(time::milliseconds(1), 10); // wait for notification posted |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 95 | if ((flags & REMOVE_LAST_NOTIFICATION) != 0) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 96 | m_responses.pop_back(); |
| 97 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 98 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 99 | return face; |
| 100 | } |
| 101 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 102 | private: |
| 103 | template<typename T> |
| 104 | static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type |
| 105 | randomizeCounter(const T& counter) |
| 106 | { |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame] | 107 | static std::uniform_int_distribution<typename T::rep> dist; |
| 108 | const_cast<T&>(counter).set(dist(getGlobalRng())); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 111 | protected: |
| 112 | FaceTable& m_faceTable; |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 113 | FaceSystem m_faceSystem; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 114 | FaceManager m_manager; |
| 115 | }; |
| 116 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 117 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 118 | BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 119 | |
| 120 | BOOST_AUTO_TEST_SUITE(DestroyFace) |
| 121 | |
| 122 | BOOST_AUTO_TEST_CASE(Existing) |
| 123 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 124 | auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 125 | |
| 126 | auto parameters = ControlParameters().setFaceId(addedFace->getId()); |
| 127 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 128 | |
| 129 | receiveInterest(command); |
| 130 | |
| 131 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification |
| 132 | // notification is already tested, so ignore it |
| 133 | |
| 134 | BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)), |
| 135 | CheckResponseResult::OK); |
| 136 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_CASE(NonExisting) |
| 141 | { |
| 142 | auto parameters = ControlParameters().setFaceId(65535); |
| 143 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 144 | |
| 145 | receiveInterest(command); |
| 146 | |
| 147 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 148 | |
| 149 | BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)), |
| 150 | CheckResponseResult::OK); |
| 151 | } |
| 152 | |
| 153 | BOOST_AUTO_TEST_SUITE_END() // DestroyFace |
| 154 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 155 | BOOST_AUTO_TEST_SUITE(Datasets) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 156 | |
| 157 | BOOST_AUTO_TEST_CASE(FaceDataset) |
| 158 | { |
| 159 | size_t nEntries = 303; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 160 | for (size_t i = 0; i < nEntries; ++i) { |
| 161 | addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | receiveInterest(makeInterest("/localhost/nfd/faces/list")); |
| 165 | |
| 166 | Block content; |
| 167 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 168 | BOOST_CHECK_NO_THROW(content.parse()); |
| 169 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 170 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 171 | std::set<FaceId> faceIds; |
| 172 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 173 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 174 | |
| 175 | ndn::nfd::FaceStatus decodedStatus; |
| 176 | BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 177 | BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 178 | faceIds.insert(decodedStatus.getFaceId()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | BOOST_CHECK_EQUAL(faceIds.size(), nEntries); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 182 | // TODO#3325 check dataset contents including counter values |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | BOOST_AUTO_TEST_CASE(FaceQuery) |
| 186 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 187 | auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// |
| 188 | auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local |
| 189 | auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 190 | |
| 191 | auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) { |
| 192 | return Name("/localhost/nfd/faces/query").append(filter.wireEncode()); |
| 193 | }; |
| 194 | |
| 195 | auto querySchemeName = |
| 196 | generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy")); |
| 197 | auto queryIdName = |
| 198 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId())); |
| 199 | auto queryScopeName = |
| 200 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)); |
| 201 | auto invalidQueryName = |
| 202 | Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid")); |
| 203 | |
| 204 | receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected |
| 205 | receiveInterest(makeInterest(queryIdName)); // face1 expected |
| 206 | receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected |
| 207 | receiveInterest(makeInterest(invalidQueryName)); // nack expected |
| 208 | |
| 209 | BOOST_REQUIRE_EQUAL(m_responses.size(), 4); |
| 210 | |
| 211 | Block content; |
| 212 | ndn::nfd::FaceStatus status; |
| 213 | |
| 214 | content = m_responses[0].getContent(); |
| 215 | BOOST_CHECK_NO_THROW(content.parse()); |
| 216 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2 |
| 217 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 218 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 219 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 220 | BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId()); |
| 221 | |
| 222 | content = m_responses[1].getContent(); |
| 223 | BOOST_CHECK_NO_THROW(content.parse()); |
| 224 | BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1 |
| 225 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 226 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 227 | |
| 228 | content = m_responses[2].getContent(); |
| 229 | BOOST_CHECK_NO_THROW(content.parse()); |
| 230 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3 |
| 231 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 232 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 233 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 234 | BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId()); |
| 235 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 236 | ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack), |
| 238 | CheckResponseResult::OK); |
| 239 | } |
| 240 | |
| 241 | class TestChannel : public Channel |
| 242 | { |
| 243 | public: |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 244 | explicit |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 245 | TestChannel(const std::string& uri) |
| 246 | { |
| 247 | setUri(FaceUri(uri)); |
| 248 | } |
| 249 | }; |
| 250 | |
| 251 | class TestProtocolFactory : public ProtocolFactory |
| 252 | { |
| 253 | public: |
Junxiao Shi | c344304 | 2017-01-26 17:21:35 +0000 | [diff] [blame] | 254 | void |
| 255 | processConfig(OptionalConfigSection configSection, |
| 256 | FaceSystem::ConfigContext& context) final |
| 257 | { |
| 258 | } |
| 259 | |
| 260 | void |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 261 | createFace(const FaceUri& uri, |
| 262 | ndn::nfd::FacePersistency persistency, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 263 | bool wantLocalFieldsEnabled, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 264 | const FaceCreatedCallback& onCreated, |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 265 | const FaceCreationFailedCallback& onConnectFailed) final |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 266 | { |
| 267 | } |
| 268 | |
Junxiao Shi | c344304 | 2017-01-26 17:21:35 +0000 | [diff] [blame] | 269 | std::vector<shared_ptr<const Channel>> |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 270 | getChannels() const final |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 271 | { |
| 272 | return m_channels; |
| 273 | } |
| 274 | |
| 275 | public: |
| 276 | shared_ptr<TestChannel> |
| 277 | addChannel(const std::string& channelUri) |
| 278 | { |
| 279 | auto channel = make_shared<TestChannel>(channelUri); |
| 280 | m_channels.push_back(channel); |
| 281 | return channel; |
| 282 | } |
| 283 | |
| 284 | private: |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 285 | std::vector<shared_ptr<const Channel>> m_channels; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | BOOST_AUTO_TEST_CASE(ChannelDataset) |
| 289 | { |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 290 | m_manager.m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>(); |
| 291 | auto factory = static_cast<TestProtocolFactory*>(m_manager.m_faceSystem.getFactoryById("test")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 292 | |
| 293 | std::map<std::string, shared_ptr<TestChannel>> addedChannels; |
| 294 | size_t nEntries = 404; |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 295 | for (size_t i = 0; i < nEntries; i++) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 296 | auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://"); |
| 297 | addedChannels[channel->getUri().toString()] = channel; |
| 298 | } |
| 299 | |
| 300 | receiveInterest(makeInterest("/localhost/nfd/faces/channels")); |
| 301 | |
| 302 | Block content; |
| 303 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 304 | BOOST_CHECK_NO_THROW(content.parse()); |
| 305 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 306 | |
| 307 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 308 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 309 | |
| 310 | ndn::nfd::ChannelStatus decodedStatus; |
| 311 | BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
| 312 | BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end()); |
| 313 | } |
| 314 | } |
| 315 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 316 | BOOST_AUTO_TEST_SUITE_END() // Datasets |
| 317 | |
| 318 | BOOST_AUTO_TEST_SUITE(Notifications) |
| 319 | |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 320 | BOOST_AUTO_TEST_CASE(FaceEventCreated) |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 321 | { |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 322 | auto face = addFace(); // trigger FACE_EVENT_CREATED notification |
| 323 | BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID); |
| 324 | FaceId faceId = face->getId(); |
| 325 | |
| 326 | BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 327 | |
| 328 | // check notification |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 329 | Block payload; |
| 330 | ndn::nfd::FaceEventNotification notification; |
| 331 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 332 | BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue()); |
| 333 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 334 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 335 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED); |
| 336 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 337 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString()); |
| 338 | BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString()); |
| 339 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 340 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 341 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 342 | BOOST_CHECK_EQUAL(notification.getFlags(), 0x0); |
| 343 | } |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 344 | |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 345 | BOOST_AUTO_TEST_CASE(FaceEventDownUp) |
| 346 | { |
| 347 | auto face = addFace(); |
| 348 | BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID); |
| 349 | FaceId faceId = face->getId(); |
| 350 | |
| 351 | // trigger FACE_EVENT_DOWN notification |
| 352 | dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 353 | advanceClocks(time::milliseconds(1), 10); |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 354 | BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 355 | |
| 356 | // check notification |
| 357 | { |
| 358 | Block payload; |
| 359 | ndn::nfd::FaceEventNotification notification; |
| 360 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 361 | BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue()); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 362 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 363 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 364 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 365 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 366 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString()); |
| 367 | BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString()); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 368 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 369 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 370 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(notification.getFlags(), 0x0); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 372 | } |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 373 | |
| 374 | // trigger FACE_EVENT_UP notification |
| 375 | dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP); |
| 376 | advanceClocks(time::milliseconds(1), 10); |
| 377 | BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP); |
| 378 | |
| 379 | // check notification |
| 380 | { |
| 381 | Block payload; |
| 382 | ndn::nfd::FaceEventNotification notification; |
| 383 | BOOST_REQUIRE_EQUAL(m_responses.size(), 3); |
| 384 | BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue()); |
| 385 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 386 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 387 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP); |
| 388 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 389 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString()); |
| 390 | BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString()); |
| 391 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 392 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 393 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 394 | BOOST_CHECK_EQUAL(notification.getFlags(), 0x0); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | BOOST_AUTO_TEST_CASE(FaceEventDestroyed) |
| 399 | { |
| 400 | auto face = addFace(); |
| 401 | BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID); |
| 402 | FaceId faceId = face->getId(); |
| 403 | |
| 404 | BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1); |
| 405 | |
| 406 | face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED |
| 407 | advanceClocks(time::milliseconds(1), 10); |
| 408 | |
| 409 | // check notification |
| 410 | Block payload; |
| 411 | ndn::nfd::FaceEventNotification notification; |
| 412 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
| 413 | BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue()); |
| 414 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 415 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 416 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED); |
| 417 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 418 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString()); |
| 419 | BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString()); |
| 420 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 421 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 422 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 423 | BOOST_CHECK_EQUAL(notification.getFlags(), 0x0); |
| 424 | |
| 425 | BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID); |
| 426 | BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0); |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | BOOST_AUTO_TEST_SUITE_END() // Notifications |
| 430 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 431 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 432 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 433 | |
| 434 | } // namespace tests |
| 435 | } // namespace nfd |