]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1416] docs, new tests, v4 and v6 address check
authorWlodek Wencel <wlodek@isc.org>
Fri, 14 May 2021 15:19:28 +0000 (17:19 +0200)
committerWlodzimierz Wencel <wlodek@isc.org>
Mon, 17 May 2021 12:53:34 +0000 (12:53 +0000)
doc/sphinx/man/perfdhcp.8.rst
src/bin/perfdhcp/command_options.cc
src/bin/perfdhcp/tests/command_options_unittest.cc
src/bin/perfdhcp/tests/test_control_unittest.cc
src/bin/perfdhcp/tests/testdata/Makefile.am
src/bin/perfdhcp/tests/testdata/relay-list.txt [deleted file]
src/bin/perfdhcp/tests/testdata/relay4-list.txt [moved from src/bin/perfdhcp/tests/testdata/giaddr-list.txt with 100% similarity]
src/bin/perfdhcp/tests/testdata/relay6-list.txt [new file with mode: 0644]

index 3fe9f4206b97e8dcb52a615b2ac5967f2eaa2d5a..66b32349c563ce8869787cf5156efb604467d9b6 100644 (file)
@@ -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
 ~~~~~~~~~~~~~~~~~~~
 
index 51c55e0af5f643183c0d731b40b6e4897b829619..82e31c8bebe87ef02be2087907f4c80df30da624 100644 (file)
@@ -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<ip-offset>: Offset of the (DHCPv4) IP address in the requested-IP\n"
         "    option / (DHCPv6) IA_NA option in the (second/request) template.\n"
-        "-J<giaddr-list-file>: Text file that include multiple addresses.\n"
+        "-J<remote-address-list-file>: Text file that include multiple addresses.\n"
         "    If provided perfdhcp will choose randomly one of addresses for each\n"
         "    exchange.\n"
         "-l<local-addr|interface>: For DHCPv4 operation, specify the local\n"
index 10cd5431b1d4cbad3f092f7b6c3a3e965709444b..3a03ade5fc3f91571f9078d7971b9cef52a983ab 100644 (file)
@@ -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
index 2c04f54daa5c50e687028a13f543073dfbc56657..9fc3c86a30ad34a9c5143837e53869138345f529 100644 (file)
@@ -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_);
index 9d31291c2fb585a3bff9695024e3de113e0d946d..19cf25da46754797871b2f202ae3ce92f4cf639d 100644 (file)
@@ -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 (file)
index 2750475..0000000
+++ /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/relay6-list.txt b/src/bin/perfdhcp/tests/testdata/relay6-list.txt
new file mode 100644 (file)
index 0000000..ce98e94
--- /dev/null
@@ -0,0 +1,2 @@
+3000::1
+fe80::6e2b:59ff:fe94:19d1