From: Wlodek Wencel Date: Fri, 14 May 2021 15:19:28 +0000 (+0200) Subject: [#1416] docs, new tests, v4 and v6 address check X-Git-Tag: Kea-1.9.8~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd9608f50071d4eddeedb6dc3c6bfcebbfd21575;p=thirdparty%2Fkea.git [#1416] docs, new tests, v4 and v6 address check --- diff --git a/doc/sphinx/man/perfdhcp.8.rst b/doc/sphinx/man/perfdhcp.8.rst index 3fe9f4206b..66b32349c5 100644 --- a/doc/sphinx/man/perfdhcp.8.rst +++ b/doc/sphinx/man/perfdhcp.8.rst @@ -15,7 +15,7 @@ perfdhcp - DHCP benchmarking tool Synopsis ~~~~~~~~ -:program:`perfdhcp` [**-1**] [**-4** | **-6**] [**-A** encapsulation-level] [**-b** base] [**-B**] [**-c**] [**-C** separator] [**-d** drop-time] [**-D** max-drop] [-e lease-type] [**-E** time-offset] [**-f** renew-rate] [**-F** release-rate] [**-g** thread-mode] [**-h**] [**-i**] [**-I** ip-offset] [**-J** giaddr-list-file] [**-l** local-address|interface] [**-L** local-port] [**-M** mac-list-file] [**-n** num-request] [**-N** remote-port] [**-O** random-offset] [**-o** code,hexstring] [**-p** test-period] [**-P** preload] [**-r** rate] [**-R** num-clients] [**-s** seed] [**-S** srvid-offset] [**--scenario** name] [**-t** report] [**-T** template-file] [**-u**] [**-v**] [**-W** exit-wait-time] [**-w** script_name] [**-x** diagnostic-selector] [**-X** xid-offset] [server] +:program:`perfdhcp` [**-1**] [**-4** | **-6**] [**-A** encapsulation-level] [**-b** base] [**-B**] [**-c**] [**-C** separator] [**-d** drop-time] [**-D** max-drop] [-e lease-type] [**-E** time-offset] [**-f** renew-rate] [**-F** release-rate] [**-g** thread-mode] [**-h**] [**-i**] [**-I** ip-offset] [**-J** remote-address-list-file] [**-l** local-address|interface] [**-L** local-port] [**-M** mac-list-file] [**-n** num-request] [**-N** remote-port] [**-O** random-offset] [**-o** code,hexstring] [**-p** test-period] [**-P** preload] [**-r** rate] [**-R** num-clients] [**-s** seed] [**-S** srvid-offset] [**--scenario** name] [**-t** report] [**-T** template-file] [**-u**] [**-v**] [**-W** exit-wait-time] [**-w** script_name] [**-x** diagnostic-selector] [**-X** xid-offset] [server] Description ~~~~~~~~~~~ @@ -117,11 +117,11 @@ number of simulated clients exceeds 65535, three bytes will be randomized, and so on. Perfdhcp can now simulate traffic from multiple subnets by enabling option --J and passing path to file that contains v4 addresses that will be used as -giaddr in generated messages. That enable testing of vast numbers of Kea shared -networks. Kea should be started with KEA_TEST_SEND_RESPONSES_TO_SOURCE -environment variable to force Kea to send generated messages to source -address of incoming packet. Feature is not available in kea-dhcp6. +-J and passing path to file that contains v4 or v6 addresses that will be +used as relayin generated messages. That enable testing of vast numbers +of Kea shared networks. While testing Kea v4 it should be started with +KEA_TEST_SEND_RESPONSES_TO_SOURCE environment variable to force Kea +to send generated messages to source address of incoming packet. Templates may currently be used to generate packets being sent to the server in 4-way exchanges, i.e. SOLICIT, REQUEST (DHCPv6) and DISCOVER, @@ -198,6 +198,13 @@ Options ``-D``, ``-E``, ``-S``, ``-I`` and ``-F``. In addition, it cannot be used with multiple instances of ``-O``, ``-T`` and ``-X``. +``-J remote-address-list-file`` + Text file that include multiple addresses. If provided perfdhcp will choose + randomly one of addresses for each exchange. This is used to generate traffic + from multiple subnets. Designed to test shared-networks. While testing kea v4 it + should be started with KEA_TEST_SEND_RESPONSES_TO_SOURCE=ENABLE + env variable otherwise perfdhcp will not be able to receive responses. + ``-l local-addr|interface`` For DHCPv4 operation, specifies the local hostname/address to use when communicating with the server. By default, the interface address @@ -324,13 +331,6 @@ The following options only apply for DHCPv4 (i.e. when ``-4`` is given). ``-B`` Forces broadcast handling. -``-J giaddr-list-file`` - Text file that include multiple addresses. If provided perfdhcp will choose - randomly one of addresses for each exchange. This is used to generate traffic - from multiple subnets. Designed to test shared-networks in kea-dhcp4. Kea should - be started with KEA_TEST_SEND_RESPONSES_TO_SOURCE=ENABLE env variable otherwise - perfdhcp will not be able to receive responses. - DHCPv6-Only Options ~~~~~~~~~~~~~~~~~~~ diff --git a/src/bin/perfdhcp/command_options.cc b/src/bin/perfdhcp/command_options.cc index 51c55e0af5..82e31c8beb 100644 --- a/src/bin/perfdhcp/command_options.cc +++ b/src/bin/perfdhcp/command_options.cc @@ -850,9 +850,11 @@ CommandOptions::convertHexString(const std::string& text) const { bool CommandOptions::validateIP(const std::string& line) { try { - asiolink::IOAddress ip_address_ = isc::asiolink::IOAddress(line); - // let's silence not used warning - (void) ip_address_; + isc::asiolink::IOAddress ip_address(line); + if ((getIpVersion() == 4 && !ip_address.isV4()) || + (getIpVersion() == 6 && !ip_address.isV6())) { + return (true); + } } catch (const isc::asiolink::IOError& e) { return (true); } @@ -868,7 +870,7 @@ void CommandOptions::loadRelayAddr() { while (std::getline(infile, line)) { cnt++; stringstream tmp; - tmp << "invalid address in line: "<< cnt; + tmp << "invalid address or wrong address version in line: "<< cnt; check(validateIP(line), tmp.str()); } check(cnt == 0, "file with addresses is empty!"); @@ -1238,7 +1240,7 @@ CommandOptions::usage() const { " whether -6 is given.\n" "-I: Offset of the (DHCPv4) IP address in the requested-IP\n" " option / (DHCPv6) IA_NA option in the (second/request) template.\n" - "-J: Text file that include multiple addresses.\n" + "-J: Text file that include multiple addresses.\n" " If provided perfdhcp will choose randomly one of addresses for each\n" " exchange.\n" "-l: For DHCPv4 operation, specify the local\n" diff --git a/src/bin/perfdhcp/tests/command_options_unittest.cc b/src/bin/perfdhcp/tests/command_options_unittest.cc index 10cd5431b1..3a03ade5fc 100644 --- a/src/bin/perfdhcp/tests/command_options_unittest.cc +++ b/src/bin/perfdhcp/tests/command_options_unittest.cc @@ -841,17 +841,49 @@ TEST_F(CommandOptionsTest, LoadMacsFromFile) { EXPECT_EQ(4, m.size()); } -TEST_F(CommandOptionsTest, LoadRelayAddrFromFile) { +TEST_F(CommandOptionsTest, LoadRelay4AddrFromFile) { CommandOptions opt; - std::string relay_addr_list_full_path = getFullPath("relay-addr-list.txt"); + std::string relay_addr_list_full_path = getFullPath("relay4-list.txt"); std::ostringstream cmd; - cmd << "perfdhcp -J " << relay_addr_list_full_path << " abc"; + cmd << "perfdhcp -4 -J " << relay_addr_list_full_path << " abc"; EXPECT_NO_THROW(process(opt, cmd.str())); EXPECT_EQ(relay_addr_list_full_path, opt.getRelayAddrListFile()); EXPECT_TRUE(opt.checkMultiSubnet()); - EXPECT_EQ(7, opt.getRelayAddrList().size()); + EXPECT_EQ(5, opt.getRelayAddrList().size()); } +TEST_F(CommandOptionsTest, LoadRelay6AddrFromFile) { + CommandOptions opt; + std::string relay_addr_list_full_path = getFullPath("relay6-list.txt"); + std::ostringstream cmd; + cmd << "perfdhcp -6 -J " << relay_addr_list_full_path << " abc"; + EXPECT_NO_THROW(process(opt, cmd.str())); + EXPECT_EQ(relay_addr_list_full_path, opt.getRelayAddrListFile()); + EXPECT_TRUE(opt.checkMultiSubnet()); + EXPECT_EQ(2, opt.getRelayAddrList().size()); +} + +TEST_F(CommandOptionsTest, RelayAddr6ForVersion4) { + CommandOptions opt; + std::string relay_addr_list_full_path = getFullPath("relay6-list.txt"); + std::ostringstream cmd; + cmd << "perfdhcp -4 -J " << relay_addr_list_full_path << " abc"; + EXPECT_THROW(process(opt, cmd.str()), isc::InvalidParameter); + EXPECT_FALSE(opt.checkMultiSubnet()); + EXPECT_EQ(0, opt.getRelayAddrList().size()); +} + +TEST_F(CommandOptionsTest, RelayAddr4ForVersion6) { + CommandOptions opt; + std::string relay_addr_list_full_path = getFullPath("relay4-list.txt"); + std::ostringstream cmd; + cmd << "perfdhcp -6 -J " << relay_addr_list_full_path << " abc"; + EXPECT_THROW(process(opt, cmd.str()), isc::InvalidParameter); + EXPECT_FALSE(opt.checkMultiSubnet()); + EXPECT_EQ(0, opt.getRelayAddrList().size()); +} + + TEST_F(CommandOptionsTest, LoadMacsFromFileNegativeCases) { CommandOptions opt; // Negative test cases diff --git a/src/bin/perfdhcp/tests/test_control_unittest.cc b/src/bin/perfdhcp/tests/test_control_unittest.cc index 2c04f54daa..9fc3c86a30 100644 --- a/src/bin/perfdhcp/tests/test_control_unittest.cc +++ b/src/bin/perfdhcp/tests/test_control_unittest.cc @@ -1484,7 +1484,7 @@ TEST_F(TestControlTest, Packet6Relayed) { EXPECT_EQ(asiolink::IOAddress("FF05::1:3"), pkt6->getRemoteAddr()); // Packet should be relayed. EXPECT_EQ(pkt6->relay_info_.size(), 1); - EXPECT_EQ(pkt6->relay_info_[0].hop_count_, 1); + EXPECT_EQ(pkt6->relay_info_[0].hop_count_, 0); EXPECT_EQ(pkt6->relay_info_[0].msg_type_, DHCPV6_RELAY_FORW); EXPECT_EQ(pkt6->relay_info_[0].linkaddr_, tc.socket_.addr_); EXPECT_EQ(pkt6->relay_info_[0].peeraddr_, tc.socket_.addr_); diff --git a/src/bin/perfdhcp/tests/testdata/Makefile.am b/src/bin/perfdhcp/tests/testdata/Makefile.am index 9d31291c2f..19cf25da46 100644 --- a/src/bin/perfdhcp/tests/testdata/Makefile.am +++ b/src/bin/perfdhcp/tests/testdata/Makefile.am @@ -2,4 +2,4 @@ SUBDIRS = . EXTRA_DIST = discover-example.hex request4-example.hex EXTRA_DIST += solicit-example.hex request6-example.hex -EXTRA_DIST += mac-list.txt giaddr-list.txt +EXTRA_DIST += mac-list.txt relay4-list.txt relay6-list.txt diff --git a/src/bin/perfdhcp/tests/testdata/relay-list.txt b/src/bin/perfdhcp/tests/testdata/relay-list.txt deleted file mode 100644 index 275047541e..0000000000 --- a/src/bin/perfdhcp/tests/testdata/relay-list.txt +++ /dev/null @@ -1,7 +0,0 @@ -100.95.0.1 -20.86.12.1 -101.64.4.1 -1.86.0.1 -92.86.238.1 -3000::1 -fe80::6e2b:59ff:fe94:19d1 diff --git a/src/bin/perfdhcp/tests/testdata/giaddr-list.txt b/src/bin/perfdhcp/tests/testdata/relay4-list.txt similarity index 100% rename from src/bin/perfdhcp/tests/testdata/giaddr-list.txt rename to src/bin/perfdhcp/tests/testdata/relay4-list.txt diff --git a/src/bin/perfdhcp/tests/testdata/relay6-list.txt b/src/bin/perfdhcp/tests/testdata/relay6-list.txt new file mode 100644 index 0000000000..ce98e94b7d --- /dev/null +++ b/src/bin/perfdhcp/tests/testdata/relay6-list.txt @@ -0,0 +1,2 @@ +3000::1 +fe80::6e2b:59ff:fe94:19d1