blob: a900d4da1051b08d8f7357e72e451b0f077c91ef [file] [log] [blame]
Tomáš Peckaf10b9302021-02-23 19:02:02 +01001/*
2 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
5 *
6*/
7
8#include "trompeloeil_doctest.h"
9#include "pretty_printers.h"
10#include "system/IETFInterfaces.h"
11#include "test_log_setup.h"
12#include "test_sysrepo_helpers.h"
13#include "tests/mock/system.h"
14
15TEST_CASE("ietf-interfaces localhost")
16{
17 TEST_SYSREPO_INIT_LOGS;
18 TEST_SYSREPO_INIT;
Tomáš Pecka70e54562021-03-10 12:39:03 +010019
Tomáš Peckaf10b9302021-02-23 19:02:02 +010020 TEST_SYSREPO_INIT_CLIENT;
21
22 auto network = std::make_shared<velia::system::IETFInterfaces>(srSess);
23
24 // We didn't came up with some way of mocking netlink. At least check that there is the loopback
25 // interface with expected values. It is *probably* safe to assume that there is at least the lo device.
Tomáš Pecka70e54562021-03-10 12:39:03 +010026 auto lo = dataFromSysrepo(client, "/ietf-interfaces:interfaces/interface[name='lo']", SR_DS_OPERATIONAL);
27
28 // ensure statistics keys exist and remove them ; we can't really predict the content
29 for (const auto& key : {"/statistics", "/statistics/in-discards", "/statistics/in-errors", "/statistics/in-octets", "/statistics/out-discards", "/statistics/out-errors", "/statistics/out-octets"}) {
30 auto it = lo.find(key);
31 REQUIRE(it != lo.end());
32 lo.erase(it);
33 }
34
35 REQUIRE(lo == std::map<std::string, std::string> {
Tomáš Peckaf10b9302021-02-23 19:02:02 +010036 {"/name", "lo"},
37 {"/type", "iana-if-type:softwareLoopback"},
38 {"/phys-address", "00:00:00:00:00:00"},
39 {"/oper-status", "unknown"},
Tomáš Pecka09729382021-03-08 19:36:50 +010040 {"/ietf-ip:ipv4", ""},
41 {"/ietf-ip:ipv4/address[ip='127.0.0.1']", ""},
42 {"/ietf-ip:ipv4/address[ip='127.0.0.1']/ip", "127.0.0.1"},
43 {"/ietf-ip:ipv4/address[ip='127.0.0.1']/prefix-length", "8"},
44 {"/ietf-ip:ipv6", ""},
45 {"/ietf-ip:ipv6/address[ip='::1']", ""},
46 {"/ietf-ip:ipv6/address[ip='::1']/ip", "::1"},
47 {"/ietf-ip:ipv6/address[ip='::1']/prefix-length", "128"},
Tomáš Peckaf10b9302021-02-23 19:02:02 +010048 });
Tomáš Pecka3663aae2021-03-10 13:46:31 +010049 // NOTE: There are no neighbours on loopback
Tomáš Peckaf10b9302021-02-23 19:02:02 +010050}