Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
| 2 | #include <sysrepo-cpp/Connection.hpp> |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 3 | #include "system/LLDP.h" |
| 4 | #include "system/LLDPCallback.h" |
| 5 | #include "test_log_setup.h" |
| 6 | #include "test_sysrepo_helpers.h" |
| 7 | #include "tests/configure.cmake.h" |
| 8 | |
| 9 | TEST_CASE("Sysrepo opsdata callback") |
| 10 | { |
| 11 | TEST_SYSREPO_INIT_LOGS; |
| 12 | TEST_SYSREPO_INIT; |
| 13 | TEST_SYSREPO_INIT_CLIENT; |
| 14 | |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 15 | std::map<std::string, std::string> expected; |
Tomáš Pecka | 070f60d | 2021-10-13 21:48:14 +0200 | [diff] [blame] | 16 | std::string json; |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 17 | |
| 18 | SECTION("Single link, single neighbor") |
| 19 | { |
Tomáš Pecka | 070f60d | 2021-10-13 21:48:14 +0200 | [diff] [blame] | 20 | json = R"({"ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "7062a9e41c924ac6942da39c56e6b820", "enabledCapabilities": "a"}}]})"; |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 21 | expected = { |
| 22 | {"/neighbors[1]", ""}, |
| 23 | {"/neighbors[1]/ifName", "ve-image"}, |
| 24 | {"/neighbors[1]/remotePortId", "host0"}, |
| 25 | {"/neighbors[1]/remoteSysName", "image"}, |
| 26 | {"/neighbors[1]/remoteChassisId", "7062a9e41c924ac6942da39c56e6b820"}, |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 27 | {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"}, |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | SECTION("Two links per one neighbor") |
| 32 | { |
Tomáš Pecka | 070f60d | 2021-10-13 21:48:14 +0200 | [diff] [blame] | 33 | json = R"({ |
| 34 | "enp0s31f6": [{"neighbor": {"systemName": "sw-a1128-01.fit.cvut.cz", "portId": "Gi3/0/7", "chassisId": "00:b8:b3:e6:17:80", "enabledCapabilities": "b"}}], |
| 35 | "ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "8b90f96f448140fb9b5d9d68e86d052e", "enabledCapabilities": "a"}}] |
| 36 | })"; |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 37 | expected = { |
| 38 | {"/neighbors[1]", ""}, |
| 39 | {"/neighbors[1]/ifName", "enp0s31f6"}, |
| 40 | {"/neighbors[1]/remoteSysName", "sw-a1128-01.fit.cvut.cz"}, |
| 41 | {"/neighbors[1]/remotePortId", "Gi3/0/7"}, |
| 42 | {"/neighbors[1]/remoteChassisId", "00:b8:b3:e6:17:80"}, |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 43 | {"/neighbors[1]/systemCapabilitiesEnabled", "bridge"}, |
| 44 | {"/neighbors[2]", ""}, |
| 45 | {"/neighbors[2]/ifName", "ve-image"}, |
| 46 | {"/neighbors[2]/remoteSysName", "image"}, |
| 47 | {"/neighbors[2]/remotePortId", "host0"}, |
| 48 | {"/neighbors[2]/remoteChassisId", "8b90f96f448140fb9b5d9d68e86d052e"}, |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 49 | {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"}, |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | SECTION("Multiple neighbors") |
| 54 | { |
Tomáš Pecka | 070f60d | 2021-10-13 21:48:14 +0200 | [diff] [blame] | 55 | json = R"({"host0": [ |
| 56 | {"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "1631331c24bb499bb644fcdf7c9fd467", "enabledCapabilities": "a"}}, |
| 57 | {"neighbor": {"systemName": "enterprise", "portId": "vb-image2", "chassisId": "1efe5cecbfc248a09065ad6177a98b41", "enabledCapabilities": "a"}} |
| 58 | ]})"; |
| 59 | |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 60 | expected = { |
| 61 | {"/neighbors[1]", ""}, |
| 62 | {"/neighbors[1]/ifName", "host0"}, |
| 63 | {"/neighbors[1]/remoteChassisId", "1631331c24bb499bb644fcdf7c9fd467"}, |
| 64 | {"/neighbors[1]/remotePortId", "host0"}, |
| 65 | {"/neighbors[1]/remoteSysName", "image"}, |
| 66 | {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"}, |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 67 | {"/neighbors[2]", ""}, |
| 68 | {"/neighbors[2]/ifName", "host0"}, |
| 69 | {"/neighbors[2]/remoteChassisId", "1efe5cecbfc248a09065ad6177a98b41"}, |
| 70 | {"/neighbors[2]/remotePortId", "vb-image2"}, |
| 71 | {"/neighbors[2]/remoteSysName", "enterprise"}, |
| 72 | {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"}, |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 73 | }; |
| 74 | } |
| 75 | |
Tomáš Pecka | 070f60d | 2021-10-13 21:48:14 +0200 | [diff] [blame] | 76 | auto lldp = std::make_shared<velia::system::LLDPDataProvider>([&]() { return json; }); |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 77 | srSubs->oper_get_items_subscribe("czechlight-lldp", velia::system::LLDPCallback(lldp), "/czechlight-lldp:nbr-list"); |
| 78 | |
Tomáš Pecka | 7acf392 | 2021-08-10 11:16:57 +0200 | [diff] [blame] | 79 | client->session_switch_ds(SR_DS_OPERATIONAL); |
| 80 | REQUIRE(dataFromSysrepo(client, "/czechlight-lldp:nbr-list") == expected); |
| 81 | } |