2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[github19] Integrated pull request 19 with unit test fix.

This commit is contained in:
Marcin Siodelski 2016-04-11 14:47:28 +02:00
parent d02a46f2b7
commit efdaab1b74
2 changed files with 13 additions and 8 deletions

View File

@ -1699,7 +1699,8 @@ void
TestControl::sendRequest4(const TestControlSocket& socket, TestControl::sendRequest4(const TestControlSocket& socket,
const dhcp::Pkt4Ptr& discover_pkt4, const dhcp::Pkt4Ptr& discover_pkt4,
const dhcp::Pkt4Ptr& offer_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)); Pkt4Ptr pkt4(new Pkt4(DHCPREQUEST, transid));
// Use first flags indicates that we want to use the server // 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 // Get the second argument if multiple the same arguments specified
// in the command line. Second one refers to REQUEST packets. // in the command line. Second one refers to REQUEST packets.
const uint8_t arg_idx = 1; const uint8_t arg_idx = 1;
// Generate new transaction id. // Use the same transaction id as the one used in the discovery packet.
const uint32_t transid = generateTransid(); const uint32_t transid = discover_pkt4->getTransid();
// Get transaction id offset. // Get transaction id offset.
size_t transid_offset = getTransactionIdOffset(arg_idx); size_t transid_offset = getTransactionIdOffset(arg_idx);
// Get the offset of MAC's last octet. // Get the offset of MAC's last octet.

View File

@ -69,6 +69,9 @@ public:
uint32_t transid_; ///< Last generated transaction id. uint32_t transid_; ///< Last generated transaction id.
}; };
/// \brief Pointer to incremental generator.
typedef boost::shared_ptr<IncrementalGenerator> IncrementalGeneratorPtr;
/// \brief Sets the due times for sending Solicit, Renew and Release. /// \brief Sets the due times for sending Solicit, Renew and Release.
/// ///
/// There are three class members that hold the due time for sending DHCP /// 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 // This is important because we need to simulate responses
// from the server and use the same transaction ids as in // from the server and use the same transaction ids as in
// packets sent by client. // packets sent by client.
TestControl::NumberGeneratorPtr NakedTestControl::IncrementalGeneratorPtr
generator(new NakedTestControl::IncrementalGenerator()); generator(new NakedTestControl::IncrementalGenerator());
tc.setTransidGenerator(generator); tc.setTransidGenerator(generator);
// Socket is needed to send packets through the interface. // Socket is needed to send packets through the interface.
ASSERT_NO_THROW(sock_handle = tc.openSocket()); ASSERT_NO_THROW(sock_handle = tc.openSocket());
TestControl::TestControlSocket sock(sock_handle); TestControl::TestControlSocket sock(sock_handle);
uint32_t transid = 0;
for (int i = 0; i < iterations_num; ++i) { 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) { if (use_templates) {
ASSERT_NO_THROW(tc.sendDiscover4(sock, tc.getTemplateBuffer(0))); ASSERT_NO_THROW(tc.sendDiscover4(sock, tc.getTemplateBuffer(0)));
} else { } else {
ASSERT_NO_THROW(tc.sendDiscover4(sock)); ASSERT_NO_THROW(tc.sendDiscover4(sock));
} }
++transid;
// Do not simulate responses for packets later // Do not simulate responses for packets later
// that specified as receive_num. This simulates // that specified as receive_num. This simulates
// packet drops. // packet drops.
if (i < receive_num) { if (i < receive_num) {
boost::shared_ptr<Pkt4> offer_pkt4(createOfferPkt4(transid)); boost::shared_ptr<Pkt4> offer_pkt4(createOfferPkt4(transid));
ASSERT_NO_THROW(tc.processReceivedPacket4(sock, offer_pkt4)); ASSERT_NO_THROW(tc.processReceivedPacket4(sock, offer_pkt4));
++transid;
} }
if (tc.checkExitConditions()) { if (tc.checkExitConditions()) {
iterations_performed = i + 1; iterations_performed = i + 1;
@ -1387,7 +1391,7 @@ TEST_F(TestControlTest, Packet4Exchange) {
EXPECT_EQ(10, iterations_performed); EXPECT_EQ(10, iterations_performed);
// With the following command line we restrict the maximum // 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. // Use templates for this test.
processCmdLine("perfdhcp -l " + loopback_iface processCmdLine("perfdhcp -l " + loopback_iface
+ " -r 100 -R 20 -n 20 -D 10% -L 10547" + " -r 100 -R 20 -n 20 -D 10% -L 10547"