Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame^] | 15 | using namespace std::string_literals; |
| 16 | |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 17 | TEST_CASE("ietf-interfaces localhost") |
| 18 | { |
| 19 | TEST_SYSREPO_INIT_LOGS; |
| 20 | TEST_SYSREPO_INIT; |
Tomáš Pecka | 70e5456 | 2021-03-10 12:39:03 +0100 | [diff] [blame] | 21 | |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 22 | TEST_SYSREPO_INIT_CLIENT; |
| 23 | |
| 24 | auto network = std::make_shared<velia::system::IETFInterfaces>(srSess); |
| 25 | |
| 26 | // We didn't came up with some way of mocking netlink. At least check that there is the loopback |
| 27 | // interface with expected values. It is *probably* safe to assume that there is at least the lo device. |
Tomáš Pecka | 70e5456 | 2021-03-10 12:39:03 +0100 | [diff] [blame] | 28 | auto lo = dataFromSysrepo(client, "/ietf-interfaces:interfaces/interface[name='lo']", SR_DS_OPERATIONAL); |
| 29 | |
| 30 | // ensure statistics keys exist and remove them ; we can't really predict the content |
| 31 | for (const auto& key : {"/statistics", "/statistics/in-discards", "/statistics/in-errors", "/statistics/in-octets", "/statistics/out-discards", "/statistics/out-errors", "/statistics/out-octets"}) { |
| 32 | auto it = lo.find(key); |
| 33 | REQUIRE(it != lo.end()); |
| 34 | lo.erase(it); |
| 35 | } |
| 36 | |
| 37 | REQUIRE(lo == std::map<std::string, std::string> { |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 38 | {"/name", "lo"}, |
| 39 | {"/type", "iana-if-type:softwareLoopback"}, |
| 40 | {"/phys-address", "00:00:00:00:00:00"}, |
| 41 | {"/oper-status", "unknown"}, |
Tomáš Pecka | 0972938 | 2021-03-08 19:36:50 +0100 | [diff] [blame] | 42 | {"/ietf-ip:ipv4", ""}, |
| 43 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']", ""}, |
| 44 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']/ip", "127.0.0.1"}, |
| 45 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']/prefix-length", "8"}, |
| 46 | {"/ietf-ip:ipv6", ""}, |
| 47 | {"/ietf-ip:ipv6/address[ip='::1']", ""}, |
| 48 | {"/ietf-ip:ipv6/address[ip='::1']/ip", "::1"}, |
| 49 | {"/ietf-ip:ipv6/address[ip='::1']/prefix-length", "128"}, |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 50 | }); |
Tomáš Pecka | 3663aae | 2021-03-10 13:46:31 +0100 | [diff] [blame] | 51 | // NOTE: There are no neighbours on loopback |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame^] | 52 | |
| 53 | SECTION("Link changes disabled") |
| 54 | { |
| 55 | client->session_switch_ds(SR_DS_STARTUP); |
| 56 | |
| 57 | SECTION("Only specified link names can appear in configurable datastore") |
| 58 | { |
| 59 | for (const auto& [name, type] : {std::pair<const char*, const char*>{"eth0", "iana-if-type:ethernetCsmacd"}, |
| 60 | {"eth1", "iana-if-type:ethernetCsmacd"}, |
| 61 | {"br0", "iana-if-type:bridge"}, |
| 62 | {"osc", "iana-if-type:ethernetCsmacd"}, |
| 63 | {"oscW", "iana-if-type:ethernetCsmacd"}, |
| 64 | {"oscE", "iana-if-type:ethernetCsmacd"}}) { |
| 65 | client->set_item_str(("/ietf-interfaces:interfaces/interface[name='"s + name + "']/type").c_str(), type); |
| 66 | } |
| 67 | client->apply_changes(); |
| 68 | } |
| 69 | |
| 70 | SECTION("Invalid type for a valid link") |
| 71 | { |
| 72 | client->set_item_str("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:softwareLoopback"); |
| 73 | REQUIRE_THROWS_AS(client->apply_changes(), sysrepo::sysrepo_exception); |
| 74 | } |
| 75 | |
| 76 | SECTION("Invalid name") |
| 77 | { |
| 78 | client->set_item_str("/ietf-interfaces:interfaces/interface[name='blah0']/type", "iana-if-type:ethernetCsmacd"); |
| 79 | REQUIRE_THROWS_AS(client->apply_changes(), sysrepo::sysrepo_exception); |
| 80 | } |
| 81 | } |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 82 | } |