From efdaab1b74ab9d2286c68f2da1699e17221cd341 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Mon, 11 Apr 2016 14:47:28 +0200 Subject: [PATCH] [github19] Integrated pull request 19 with unit test fix. --- src/bin/perfdhcp/test_control.cc | 7 ++++--- src/bin/perfdhcp/tests/test_control_unittest.cc | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bin/perfdhcp/test_control.cc b/src/bin/perfdhcp/test_control.cc index 6303addece..ec34875329 100644 --- a/src/bin/perfdhcp/test_control.cc +++ b/src/bin/perfdhcp/test_control.cc @@ -1699,7 +1699,8 @@ void TestControl::sendRequest4(const TestControlSocket& socket, const dhcp::Pkt4Ptr& discover_pkt4, const dhcp::Pkt4Ptr& offer_pkt4) { - const uint32_t transid = generateTransid(); + // Use the same transaction id as the one used in the discovery packet. + const uint32_t transid = discover_pkt4->getTransid(); Pkt4Ptr pkt4(new Pkt4(DHCPREQUEST, transid)); // Use first flags indicates that we want to use the server @@ -1765,8 +1766,8 @@ TestControl::sendRequest4(const TestControlSocket& socket, // Get the second argument if multiple the same arguments specified // in the command line. Second one refers to REQUEST packets. const uint8_t arg_idx = 1; - // Generate new transaction id. - const uint32_t transid = generateTransid(); + // Use the same transaction id as the one used in the discovery packet. + const uint32_t transid = discover_pkt4->getTransid(); // Get transaction id offset. size_t transid_offset = getTransactionIdOffset(arg_idx); // Get the offset of MAC's last octet. diff --git a/src/bin/perfdhcp/tests/test_control_unittest.cc b/src/bin/perfdhcp/tests/test_control_unittest.cc index 0130c67d00..c125d3383b 100644 --- a/src/bin/perfdhcp/tests/test_control_unittest.cc +++ b/src/bin/perfdhcp/tests/test_control_unittest.cc @@ -69,6 +69,9 @@ public: uint32_t transid_; ///< Last generated transaction id. }; + /// \brief Pointer to incremental generator. + typedef boost::shared_ptr IncrementalGeneratorPtr; + /// \brief Sets the due times for sending Solicit, Renew and Release. /// /// There are three class members that hold the due time for sending DHCP @@ -475,27 +478,28 @@ public: // This is important because we need to simulate responses // from the server and use the same transaction ids as in // packets sent by client. - TestControl::NumberGeneratorPtr + NakedTestControl::IncrementalGeneratorPtr generator(new NakedTestControl::IncrementalGenerator()); tc.setTransidGenerator(generator); // Socket is needed to send packets through the interface. ASSERT_NO_THROW(sock_handle = tc.openSocket()); TestControl::TestControlSocket sock(sock_handle); - uint32_t transid = 0; for (int i = 0; i < iterations_num; ++i) { + // Get next transaction id, without actually using it. The same + // id wll be used by the TestControl class for DHCPDISCOVER. + uint32_t transid = generator->getNext(); if (use_templates) { ASSERT_NO_THROW(tc.sendDiscover4(sock, tc.getTemplateBuffer(0))); } else { ASSERT_NO_THROW(tc.sendDiscover4(sock)); } - ++transid; + // Do not simulate responses for packets later // that specified as receive_num. This simulates // packet drops. if (i < receive_num) { boost::shared_ptr offer_pkt4(createOfferPkt4(transid)); ASSERT_NO_THROW(tc.processReceivedPacket4(sock, offer_pkt4)); - ++transid; } if (tc.checkExitConditions()) { iterations_performed = i + 1; @@ -1387,7 +1391,7 @@ TEST_F(TestControlTest, Packet4Exchange) { EXPECT_EQ(10, iterations_performed); // With the following command line we restrict the maximum - // number of dropped packets to 20% of all. + // number of dropped packets to 10% of all. // Use templates for this test. processCmdLine("perfdhcp -l " + loopback_iface + " -r 100 -R 20 -n 20 -D 10% -L 10547" -- 2.47.2