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