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" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 9 | #include <filesystem> |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 10 | #include <sysrepo-cpp/utils/exception.hpp> |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 11 | #include "pretty_printers.h" |
| 12 | #include "system/IETFInterfaces.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 13 | #include "system/IETFInterfacesConfig.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 14 | #include "test_log_setup.h" |
| 15 | #include "test_sysrepo_helpers.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 16 | #include "tests/configure.cmake.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 17 | #include "tests/mock/system.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 18 | #include "utils/io.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 19 | |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 20 | using namespace std::string_literals; |
| 21 | |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 22 | TEST_CASE("ietf-interfaces localhost") |
| 23 | { |
| 24 | TEST_SYSREPO_INIT_LOGS; |
| 25 | TEST_SYSREPO_INIT; |
| 26 | TEST_SYSREPO_INIT_CLIENT; |
| 27 | |
| 28 | auto network = std::make_shared<velia::system::IETFInterfaces>(srSess); |
| 29 | |
| 30 | // We didn't came up with some way of mocking netlink. At least check that there is the loopback |
| 31 | // interface with expected values. It is *probably* safe to assume that there is at least the lo device. |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 32 | auto lo = dataFromSysrepo(client, "/ietf-interfaces:interfaces/interface[name='lo']", sysrepo::Datastore::Operational); |
Tomáš Pecka | 70e5456 | 2021-03-10 12:39:03 +0100 | [diff] [blame] | 33 | |
| 34 | // ensure statistics keys exist and remove them ; we can't really predict the content |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 35 | for (const auto& key : {"/statistics/in-discards", "/statistics/in-errors", "/statistics/in-octets", "/statistics/out-discards", "/statistics/out-errors", "/statistics/out-octets"}) { |
Tomáš Pecka | 70e5456 | 2021-03-10 12:39:03 +0100 | [diff] [blame] | 36 | auto it = lo.find(key); |
| 37 | REQUIRE(it != lo.end()); |
| 38 | lo.erase(it); |
| 39 | } |
| 40 | |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 41 | REQUIRE(lo == std::map<std::string, std::string>{ |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 42 | {"/name", "lo"}, |
| 43 | {"/type", "iana-if-type:softwareLoopback"}, |
| 44 | {"/phys-address", "00:00:00:00:00:00"}, |
| 45 | {"/oper-status", "unknown"}, |
Tomáš Pecka | 0972938 | 2021-03-08 19:36:50 +0100 | [diff] [blame] | 46 | {"/ietf-ip:ipv4", ""}, |
| 47 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']", ""}, |
| 48 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']/ip", "127.0.0.1"}, |
| 49 | {"/ietf-ip:ipv4/address[ip='127.0.0.1']/prefix-length", "8"}, |
| 50 | {"/ietf-ip:ipv6", ""}, |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 51 | {"/ietf-ip:ipv6/autoconf", ""}, |
Tomáš Pecka | 0972938 | 2021-03-08 19:36:50 +0100 | [diff] [blame] | 52 | {"/ietf-ip:ipv6/address[ip='::1']", ""}, |
| 53 | {"/ietf-ip:ipv6/address[ip='::1']/ip", "::1"}, |
| 54 | {"/ietf-ip:ipv6/address[ip='::1']/prefix-length", "128"}, |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 55 | {"/statistics", ""}, |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 56 | }); |
Tomáš Pecka | 3663aae | 2021-03-10 13:46:31 +0100 | [diff] [blame] | 57 | // NOTE: There are no neighbours on loopback |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | struct FakeNetworkReload { |
| 61 | public: |
| 62 | MAKE_CONST_MOCK1(cb, void(const std::vector<std::string>&)); |
| 63 | }; |
| 64 | |
| 65 | TEST_CASE("Config data in ietf-interfaces") |
| 66 | { |
| 67 | TEST_SYSREPO_INIT_LOGS; |
| 68 | TEST_SYSREPO_INIT; |
| 69 | TEST_SYSREPO_INIT_CLIENT; |
| 70 | trompeloeil::sequence seq1; |
| 71 | |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 72 | sysrepo::Connection{}.sessionStart(sysrepo::Datastore::Running).copyConfig(sysrepo::Datastore::Startup, "ietf-interfaces"); |
| 73 | |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 74 | auto fake = FakeNetworkReload(); |
| 75 | |
| 76 | const auto fakeConfigDir = std::filesystem::path(CMAKE_CURRENT_BINARY_DIR) / "tests/network/"s; |
| 77 | std::filesystem::remove_all(fakeConfigDir); |
| 78 | std::filesystem::create_directories(fakeConfigDir); |
| 79 | |
Jan Kundrát | 80113ed | 2022-04-27 18:10:52 +0200 | [diff] [blame^] | 80 | REQUIRE_CALL(fake, cb(std::vector<std::string>{})).IN_SEQUENCE(seq1); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 81 | auto network = std::make_shared<velia::system::IETFInterfacesConfig>(srSess, fakeConfigDir, std::vector<std::string>{"br0", "eth0", "eth1"}, [&fake](const std::vector<std::string>& updatedInterfaces) { fake.cb(updatedInterfaces); }); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 82 | |
| 83 | SECTION("Link changes disabled") |
| 84 | { |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 85 | SECTION("Only specified link names can appear in configurable datastore") |
| 86 | { |
| 87 | for (const auto& [name, type] : {std::pair<const char*, const char*>{"eth0", "iana-if-type:ethernetCsmacd"}, |
| 88 | {"eth1", "iana-if-type:ethernetCsmacd"}, |
| 89 | {"br0", "iana-if-type:bridge"}, |
| 90 | {"osc", "iana-if-type:ethernetCsmacd"}, |
| 91 | {"oscW", "iana-if-type:ethernetCsmacd"}, |
| 92 | {"oscE", "iana-if-type:ethernetCsmacd"}}) { |
Jan Kundrát | b3e9998 | 2022-03-18 17:38:20 +0100 | [diff] [blame] | 93 | client.setItem("/ietf-interfaces:interfaces/interface[name='"s + name + "']/type", type); |
| 94 | client.setItem("/ietf-interfaces:interfaces/interface[name='"s + name + "']/enabled", "false"); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 95 | } |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 96 | |
| 97 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); // only these are monitored by the test |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 98 | client.applyChanges(); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | SECTION("Invalid type for a valid link") |
| 102 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 103 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:softwareLoopback"); |
| 104 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | SECTION("Invalid name") |
| 108 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 109 | client.setItem("/ietf-interfaces:interfaces/interface[name='blah0']/type", "iana-if-type:ethernetCsmacd"); |
| 110 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 111 | } |
| 112 | } |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 113 | |
| 114 | SECTION("There must always be enabled protocol or the interface must be explicitely disabled") |
| 115 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 116 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 117 | |
| 118 | SECTION("Disabled protocols; enabled link") |
| 119 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 120 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 121 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 122 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 123 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | SECTION("Active protocols; disabled link") |
| 127 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 128 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "false"); |
| 129 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 130 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 131 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 132 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 133 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | SECTION("IPv4 only; enabled link") |
| 137 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 138 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 139 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 140 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 141 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 142 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 143 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | SECTION("Every active protocol must have at least one IP address assigned") |
| 148 | { |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 149 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 150 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 151 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1).TIMES(AT_MOST(1)); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 152 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 153 | |
| 154 | SECTION("Enabled IPv4 protocol with some IPs assigned is valid") |
| 155 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 156 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 157 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 158 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 159 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.2']/ietf-ip:prefix-length", "24"); |
| 160 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 161 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 162 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SECTION("Enabled IPv6 protocol with some IPs assigned is valid") |
| 166 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 167 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 168 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 169 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 170 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 171 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 172 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 175 | SECTION("Enabled IPv4 protocol must have at least one IP or the autoconfiguration must be on") |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 176 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 177 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 178 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 179 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 180 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 181 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 184 | SECTION("Enabled IPv6 protocol must have at least one IP or the autoconfiguration must be on") |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 185 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 186 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 187 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 188 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 189 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "false"); |
| 190 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 191 | } |
| 192 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 193 | |
| 194 | std::string expectedContents; |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 195 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 196 | SECTION("Setting IPs to eth0") |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 197 | { |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 198 | const auto expectedFilePath = fakeConfigDir / "eth0.network"; |
| 199 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 200 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 201 | |
| 202 | SECTION("Single IPv4 address") |
| 203 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 204 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/description", "Hello world"); |
| 205 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 206 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 207 | expectedContents = R"([Match] |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 208 | Name=eth0 |
| 209 | |
| 210 | [Network] |
| 211 | Description=Hello world |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 212 | Address=192.0.2.1/24 |
| 213 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 214 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 215 | DHCP=no |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 216 | LLDP=true |
| 217 | EmitLLDP=nearest-bridge |
| 218 | )"; |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 219 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 220 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 221 | SECTION("Two IPv4 addresses") |
| 222 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 223 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 224 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.2']/ietf-ip:prefix-length", "24"); |
| 225 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 226 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 227 | expectedContents = R"([Match] |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 228 | Name=eth0 |
| 229 | |
| 230 | [Network] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 231 | Address=192.0.2.1/24 |
| 232 | Address=192.0.2.2/24 |
| 233 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 234 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 235 | DHCP=no |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 236 | LLDP=true |
| 237 | EmitLLDP=nearest-bridge |
| 238 | )"; |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | SECTION("IPv4 and IPv6 addresses") |
| 242 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 243 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 244 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 245 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 246 | expectedContents = R"([Match] |
| 247 | Name=eth0 |
| 248 | |
| 249 | [Network] |
| 250 | Address=192.0.2.1/24 |
| 251 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 252 | IPv6AcceptRA=true |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 253 | DHCP=no |
| 254 | LLDP=true |
| 255 | EmitLLDP=nearest-bridge |
| 256 | )"; |
| 257 | } |
| 258 | |
| 259 | SECTION("IPv4 and IPv6 addresses but IPv6 disabled") |
| 260 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 261 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 262 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 263 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 264 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/enabled", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 265 | expectedContents = R"([Match] |
| 266 | Name=eth0 |
| 267 | |
| 268 | [Network] |
| 269 | Address=192.0.2.1/24 |
| 270 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 271 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 272 | DHCP=no |
| 273 | LLDP=true |
| 274 | EmitLLDP=nearest-bridge |
| 275 | )"; |
| 276 | } |
| 277 | |
| 278 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 279 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 280 | REQUIRE(std::filesystem::exists(expectedFilePath)); |
| 281 | REQUIRE(velia::utils::readFileToString(expectedFilePath) == expectedContents); |
| 282 | |
| 283 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 284 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 285 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 286 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 287 | REQUIRE(!std::filesystem::exists(expectedFilePath)); |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 290 | SECTION("Two links") |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 291 | { |
| 292 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 293 | const auto expectedFilePathEth1 = fakeConfigDir / "eth1.network"; |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 294 | |
| 295 | std::string expectedContentsEth0 = R"([Match] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 296 | Name=eth0 |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 297 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 298 | [Network] |
| 299 | Address=192.0.2.1/24 |
| 300 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 301 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 302 | DHCP=no |
| 303 | LLDP=true |
| 304 | EmitLLDP=nearest-bridge |
| 305 | )"; |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 306 | std::string expectedContentsEth1 = R"([Match] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 307 | Name=eth1 |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 308 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 309 | [Network] |
| 310 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 311 | IPv6AcceptRA=true |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 312 | DHCP=no |
| 313 | LLDP=true |
| 314 | EmitLLDP=nearest-bridge |
| 315 | )"; |
| 316 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 317 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 318 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 319 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 320 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/type", "iana-if-type:ethernetCsmacd"); |
| 321 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 322 | |
| 323 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 324 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 325 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 326 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 327 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 328 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 329 | |
| 330 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 331 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
| 332 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 333 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 334 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 335 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 336 | REQUIRE(!std::filesystem::exists(expectedFilePathEth1)); |
| 337 | } |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 338 | |
| 339 | SECTION("Setup a bridge br0 over eth0 and eth1") |
| 340 | { |
| 341 | const auto expectedFilePathBr0 = fakeConfigDir / "br0.network"; |
| 342 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 343 | const auto expectedFilePathEth1 = fakeConfigDir / "eth1.network"; |
| 344 | |
| 345 | std::string expectedContentsBr0 = R"([Match] |
| 346 | Name=br0 |
| 347 | |
| 348 | [Network] |
| 349 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 350 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 351 | DHCP=no |
| 352 | LLDP=true |
| 353 | EmitLLDP=nearest-bridge |
| 354 | )"; |
| 355 | |
| 356 | std::string expectedContentsEth0 = R"([Match] |
| 357 | Name=eth0 |
| 358 | |
| 359 | [Network] |
| 360 | Bridge=br0 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 361 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 362 | DHCP=no |
| 363 | LLDP=true |
| 364 | EmitLLDP=nearest-bridge |
| 365 | )"; |
| 366 | |
| 367 | std::string expectedContentsEth1 = R"([Match] |
| 368 | Name=eth1 |
| 369 | |
| 370 | [Network] |
| 371 | Bridge=br0 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 372 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 373 | DHCP=no |
| 374 | LLDP=true |
| 375 | EmitLLDP=nearest-bridge |
| 376 | )"; |
| 377 | |
| 378 | // create br0 bridge over eth0 and eth1 with no IP |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 379 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/enabled", "false"); |
| 380 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/type", "iana-if-type:bridge"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 381 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 382 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 383 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/czechlight-network:bridge", "br0"); |
| 384 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 385 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 386 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 387 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/type", "iana-if-type:ethernetCsmacd"); |
| 388 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/czechlight-network:bridge", "br0"); |
| 389 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 390 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 391 | |
| 392 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 393 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 394 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 395 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 396 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 397 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 398 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 399 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 400 | |
| 401 | // assign an IPv4 address to br0 |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 402 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/enabled", "true"); |
| 403 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 404 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 405 | expectedContentsBr0 = R"([Match] |
| 406 | Name=br0 |
| 407 | |
| 408 | [Network] |
| 409 | Address=192.0.2.1/24 |
| 410 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 411 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 412 | DHCP=no |
| 413 | LLDP=true |
| 414 | EmitLLDP=nearest-bridge |
| 415 | )"; |
| 416 | |
| 417 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 418 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 419 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 420 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 421 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 422 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 423 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 424 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 425 | |
| 426 | // assign also an IPv6 address to br0 |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 427 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 428 | expectedContentsBr0 = R"([Match] |
| 429 | Name=br0 |
| 430 | |
| 431 | [Network] |
| 432 | Address=192.0.2.1/24 |
| 433 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 434 | IPv6AcceptRA=true |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 435 | DHCP=no |
| 436 | LLDP=true |
| 437 | EmitLLDP=nearest-bridge |
| 438 | )"; |
| 439 | |
| 440 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 441 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 442 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 443 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 444 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 445 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 446 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 447 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 448 | |
| 449 | // remove eth1 from bridge |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 450 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']/czechlight-network:bridge"); |
| 451 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::2']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 452 | |
| 453 | expectedContentsEth1 = R"([Match] |
| 454 | Name=eth1 |
| 455 | |
| 456 | [Network] |
| 457 | Address=2001:db8::2/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 458 | IPv6AcceptRA=true |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 459 | DHCP=no |
| 460 | LLDP=true |
| 461 | EmitLLDP=nearest-bridge |
| 462 | )"; |
| 463 | |
| 464 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 465 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 466 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 467 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 468 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 469 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 470 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 471 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 472 | |
| 473 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 474 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='br0']"); |
| 475 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
| 476 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 477 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 478 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 479 | REQUIRE(!std::filesystem::exists(expectedFilePathBr0)); |
| 480 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 481 | REQUIRE(!std::filesystem::exists(expectedFilePathEth1)); |
| 482 | } |
| 483 | |
| 484 | SECTION("Slave interface and enabled/disabled IP protocols") |
| 485 | { |
| 486 | const auto expectedFilePathBr0 = fakeConfigDir / "br0.network"; |
| 487 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 488 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 489 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/type", "iana-if-type:bridge"); |
| 490 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 491 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 492 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/czechlight-network:bridge", "br0"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 493 | |
| 494 | SECTION("Can't be a slave when IPv4 enabled") |
| 495 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 496 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 497 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | SECTION("Can't be a slave when IPv6 enabled") |
| 501 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 502 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 503 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | SECTION("Can't be a slave when both IPv4 and IPv6 enabled") |
| 507 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 508 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 509 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 510 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | SECTION("Can be a slave when addresses present but protocol is disabled") |
| 514 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 515 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 516 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/enabled", "false"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 517 | |
| 518 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 519 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 520 | |
| 521 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 522 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='br0']"); |
| 523 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 524 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 525 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 526 | REQUIRE(!std::filesystem::exists(expectedFilePathBr0)); |
| 527 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 528 | } |
| 529 | } |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 530 | |
| 531 | SECTION("Network autoconfiguration") |
| 532 | { |
| 533 | const auto expectedFilePath = fakeConfigDir / "eth0.network"; |
| 534 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 535 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 536 | |
| 537 | SECTION("IPv4 on with address, IPv6 disabled, DHCPv4 off, RA off") |
| 538 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 539 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 540 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); // in case DHCP is disabled an IP must be present |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 541 | |
| 542 | expectedContents = R"([Match] |
| 543 | Name=eth0 |
| 544 | |
| 545 | [Network] |
| 546 | Address=192.0.2.1/24 |
| 547 | LinkLocalAddressing=no |
| 548 | IPv6AcceptRA=false |
| 549 | DHCP=no |
| 550 | LLDP=true |
| 551 | EmitLLDP=nearest-bridge |
| 552 | )"; |
| 553 | } |
| 554 | |
| 555 | SECTION("IPv4 on with address, IPv6 disabled, DHCPv4 on, RA on") |
| 556 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 557 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 558 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); // in case DHCP is disabled an IP must be present |
| 559 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 560 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 561 | |
| 562 | expectedContents = R"([Match] |
| 563 | Name=eth0 |
| 564 | |
| 565 | [Network] |
| 566 | Address=192.0.2.1/24 |
| 567 | LinkLocalAddressing=no |
| 568 | IPv6AcceptRA=false |
| 569 | DHCP=ipv4 |
| 570 | LLDP=true |
| 571 | EmitLLDP=nearest-bridge |
| 572 | )"; |
| 573 | } |
| 574 | |
| 575 | SECTION("IPv4 disabled, IPv6 enabled, DHCPv4 on, RA on") |
| 576 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 577 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 578 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 579 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 580 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 581 | |
| 582 | expectedContents = R"([Match] |
| 583 | Name=eth0 |
| 584 | |
| 585 | [Network] |
| 586 | IPv6AcceptRA=true |
| 587 | DHCP=no |
| 588 | LLDP=true |
| 589 | EmitLLDP=nearest-bridge |
| 590 | )"; |
| 591 | } |
| 592 | |
| 593 | SECTION("IPv4 enabled, IPv6 enabled, DHCPv4 on, RA on") |
| 594 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 595 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 596 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 597 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 598 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 599 | |
| 600 | expectedContents = R"([Match] |
| 601 | Name=eth0 |
| 602 | |
| 603 | [Network] |
| 604 | IPv6AcceptRA=true |
| 605 | DHCP=ipv4 |
| 606 | LLDP=true |
| 607 | EmitLLDP=nearest-bridge |
| 608 | )"; |
| 609 | } |
| 610 | |
| 611 | SECTION("IPv4 enabled, IPv6 enabled, DHCPv4 off, RA on") |
| 612 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 613 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 614 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/prefix-length", "24"); |
| 615 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 616 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 617 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 618 | |
| 619 | expectedContents = R"([Match] |
| 620 | Name=eth0 |
| 621 | |
| 622 | [Network] |
| 623 | Address=192.0.2.1/24 |
| 624 | IPv6AcceptRA=true |
| 625 | DHCP=no |
| 626 | LLDP=true |
| 627 | EmitLLDP=nearest-bridge |
| 628 | )"; |
| 629 | } |
| 630 | |
| 631 | SECTION("IPv4 disabled, IPv6 disabled, DHCPv4 off, RA off") |
| 632 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 633 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/prefix-length", "24"); |
| 634 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 635 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/prefix-length", "32"); |
| 636 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "false"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 637 | |
| 638 | expectedContents = R"([Match] |
| 639 | Name=eth0 |
| 640 | |
| 641 | [Network] |
| 642 | Address=192.0.2.1/24 |
| 643 | Address=2001:db8::1/32 |
| 644 | IPv6AcceptRA=false |
| 645 | DHCP=no |
| 646 | LLDP=true |
| 647 | EmitLLDP=nearest-bridge |
| 648 | )"; |
| 649 | } |
| 650 | |
| 651 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 652 | client.applyChanges(); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 653 | REQUIRE(std::filesystem::exists(expectedFilePath)); |
| 654 | REQUIRE(velia::utils::readFileToString(expectedFilePath) == expectedContents); |
| 655 | |
| 656 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 657 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 658 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 659 | client.applyChanges(); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 660 | REQUIRE(!std::filesystem::exists(expectedFilePath)); |
| 661 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 662 | } |