blob: a49b2826e47d84f028a1f5f887308572d23864dc [file] [log] [blame]
Tomáš Pecka7acf3922021-08-10 11:16:57 +02001#include "trompeloeil_doctest.h"
2#include <sysrepo-cpp/Connection.hpp>
Tomáš Pecka7acf3922021-08-10 11:16:57 +02003#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
9TEST_CASE("Sysrepo opsdata callback")
10{
11 TEST_SYSREPO_INIT_LOGS;
12 TEST_SYSREPO_INIT;
13 TEST_SYSREPO_INIT_CLIENT;
14
Tomáš Pecka7acf3922021-08-10 11:16:57 +020015 std::map<std::string, std::string> expected;
Tomáš Pecka070f60d2021-10-13 21:48:14 +020016 std::string json;
Tomáš Pecka7acf3922021-08-10 11:16:57 +020017
18 SECTION("Single link, single neighbor")
19 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020020 json = R"({"ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "7062a9e41c924ac6942da39c56e6b820", "enabledCapabilities": "a"}}]})";
Tomáš Pecka7acf3922021-08-10 11:16:57 +020021 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áš Pecka7acf3922021-08-10 11:16:57 +020027 {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
28 };
29 }
30
31 SECTION("Two links per one neighbor")
32 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020033 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áš Pecka7acf3922021-08-10 11:16:57 +020037 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áš Pecka7acf3922021-08-10 11:16:57 +020043 {"/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áš Pecka7acf3922021-08-10 11:16:57 +020049 {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
50 };
51 }
52
53 SECTION("Multiple neighbors")
54 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020055 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áš Pecka7acf3922021-08-10 11:16:57 +020060 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áš Pecka7acf3922021-08-10 11:16:57 +020067 {"/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áš Pecka7acf3922021-08-10 11:16:57 +020073 };
74 }
75
Tomáš Pecka070f60d2021-10-13 21:48:14 +020076 auto lldp = std::make_shared<velia::system::LLDPDataProvider>([&]() { return json; });
Tomáš Pecka7acf3922021-08-10 11:16:57 +020077 srSubs->oper_get_items_subscribe("czechlight-lldp", velia::system::LLDPCallback(lldp), "/czechlight-lldp:nbr-list");
78
Tomáš Pecka7acf3922021-08-10 11:16:57 +020079 client->session_switch_ds(SR_DS_OPERATIONAL);
80 REQUIRE(dataFromSysrepo(client, "/czechlight-lldp:nbr-list") == expected);
81}