blob: 450b248d9a2ec2886bd7569ef4557c9b60c0feff [file] [log] [blame]
Tomáš Pecka7acf3922021-08-10 11:16:57 +02001#include "trompeloeil_doctest.h"
2#include <sysrepo-cpp/Connection.hpp>
3#include <unistd.h>
4#include "dbus-helpers/dbus_network1_server.h"
5#include "system/LLDP.h"
6#include "system/LLDPCallback.h"
7#include "test_log_setup.h"
8#include "test_sysrepo_helpers.h"
9#include "tests/configure.cmake.h"
10
11TEST_CASE("Sysrepo opsdata callback")
12{
13 TEST_SYSREPO_INIT_LOGS;
14 TEST_SYSREPO_INIT;
15 TEST_SYSREPO_INIT_CLIENT;
16
17 const auto serverBus = "local.pid" + std::to_string(getpid()) + ".org.freedesktop.network1";
18 auto dbusServerConnection = sdbus::createSessionBusConnection(serverBus);
19 dbusServerConnection->enterEventLoopAsync();
20
21 std::filesystem::path lldpDirectory;
22 std::vector<std::pair<int, std::string>> links;
23 std::map<std::string, std::string> expected;
24
25 SECTION("Single link, single neighbor")
26 {
27 lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/single-link";
28 links = {{8, "ve-image"}};
29 expected = {
30 {"/neighbors[1]", ""},
31 {"/neighbors[1]/ifName", "ve-image"},
32 {"/neighbors[1]/remotePortId", "host0"},
33 {"/neighbors[1]/remoteSysName", "image"},
34 {"/neighbors[1]/remoteChassisId", "7062a9e41c924ac6942da39c56e6b820"},
35 {"/neighbors[1]/systemCapabilitiesSupported", "bridge router station-only"},
36 {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
37 };
38 }
39
40 SECTION("Two links per one neighbor")
41 {
42 lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/two-links";
43 links = {{3, "enp0s31f6"}, {4, "ve-image"}};
44 expected = {
45 {"/neighbors[1]", ""},
46 {"/neighbors[1]/ifName", "enp0s31f6"},
47 {"/neighbors[1]/remoteSysName", "sw-a1128-01.fit.cvut.cz"},
48 {"/neighbors[1]/remotePortId", "Gi3/0/7"},
49 {"/neighbors[1]/remoteChassisId", "00:b8:b3:e6:17:80"},
50 {"/neighbors[1]/systemCapabilitiesSupported", "bridge router"},
51 {"/neighbors[1]/systemCapabilitiesEnabled", "bridge"},
52 {"/neighbors[2]", ""},
53 {"/neighbors[2]/ifName", "ve-image"},
54 {"/neighbors[2]/remoteSysName", "image"},
55 {"/neighbors[2]/remotePortId", "host0"},
56 {"/neighbors[2]/remoteChassisId", "8b90f96f448140fb9b5d9d68e86d052e"},
57 {"/neighbors[2]/systemCapabilitiesSupported", "bridge router station-only"},
58 {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
59 };
60 }
61
62 SECTION("Multiple neighbors")
63 {
64 lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/multiple-neighbors";
65 links = {{1, "host0"}};
66 expected = {
67 {"/neighbors[1]", ""},
68 {"/neighbors[1]/ifName", "host0"},
69 {"/neighbors[1]/remoteChassisId", "1631331c24bb499bb644fcdf7c9fd467"},
70 {"/neighbors[1]/remotePortId", "host0"},
71 {"/neighbors[1]/remoteSysName", "image"},
72 {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
73 {"/neighbors[1]/systemCapabilitiesSupported", "bridge router station-only"},
74 {"/neighbors[2]", ""},
75 {"/neighbors[2]/ifName", "host0"},
76 {"/neighbors[2]/remoteChassisId", "1efe5cecbfc248a09065ad6177a98b41"},
77 {"/neighbors[2]/remotePortId", "vb-image2"},
78 {"/neighbors[2]/remoteSysName", "enterprise"},
79 {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
80 {"/neighbors[2]/systemCapabilitiesSupported", "bridge router station-only"},
81 };
82 }
83
84 auto dbusClient = sdbus::createSessionBusConnection();
85 auto lldp = std::make_shared<velia::system::LLDPDataProvider>(lldpDirectory, *dbusClient, serverBus);
86 srSubs->oper_get_items_subscribe("czechlight-lldp", velia::system::LLDPCallback(lldp), "/czechlight-lldp:nbr-list");
87
88 auto dbusServer = DbusServer(*dbusServerConnection);
89 dbusServer.setLinks(links);
90 client->session_switch_ds(SR_DS_OPERATIONAL);
91 REQUIRE(dataFromSysrepo(client, "/czechlight-lldp:nbr-list") == expected);
92}