From: Tomek Mrugalski Date: Fri, 11 Oct 2013 15:07:32 +0000 (+0200) Subject: [3184] Changes after review: X-Git-Tag: bind10-1.2.0beta1-release~185^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09695b7ff9631f67e247fa43f89a6653635dd8fa;p=thirdparty%2Fkea.git [3184] Changes after review: - ASSERT added to unit-tests - packetFromCapture() created - comments changes --- diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 23bedb36cc..c1ea5f7916 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -1604,7 +1604,8 @@ TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) { // Let's create a relayed DISCOVER. This particular relayed DISCOVER has // added option 82 (relay agent info) with 3 suboptions. The server // is supposed to echo it back in its response. - Pkt4Ptr dis = captureRelayedDiscover(); + Pkt4Ptr dis; + ASSERT_NO_THROW(dis = captureRelayedDiscover()); // Simulate that we have received that traffic srv.fakeReceive(dis); diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index b02e4cec4f..8939358d6d 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -144,6 +144,11 @@ public: /// @return relayed DISCOVER Pkt4Ptr captureRelayedDiscover(); + /// @brief generates a DHCPv4 packet based on provided hex string + /// + /// @return created packet + Pkt4Ptr packetFromCapture(const std::string& hex_string); + /// @brief Tests if Discover or Request message is processed correctly /// /// @param msg_type DHCPDISCOVER or DHCPREQUEST @@ -173,4 +178,4 @@ public: }; // end of isc::dhcp namespace }; // end of isc namespace -#endif // DHCP6_TEST_UTILS_H +#endif // DHCP4_TEST_UTILS_H diff --git a/src/bin/dhcp4/tests/wireshark.cc b/src/bin/dhcp4/tests/wireshark.cc index a338c377a5..b563354d3b 100644 --- a/src/bin/dhcp4/tests/wireshark.cc +++ b/src/bin/dhcp4/tests/wireshark.cc @@ -19,9 +19,9 @@ #include /// @file wireshark.cc -/// +/// /// @brief contains packet captures imported from Wireshark -/// +/// /// These are actual packets captured over wire. They are used in various /// tests. /// @@ -47,6 +47,19 @@ namespace isc { namespace dhcp { namespace test { +Pkt4Ptr Dhcpv4SrvTest::packetFromCapture(const std::string& hex_string) { + std::vector bin; + + // Decode the hex string and store it in bin (which happens + // to be OptionBuffer format) + isc::util::encode::decodeHex(hex_string, bin); + + Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size())); + captureSetDefaultFields(pkt); + + return (pkt); +} + void Dhcpv4SrvTest::captureSetDefaultFields(const Pkt4Ptr& pkt) { pkt->setRemotePort(546); pkt->setRemoteAddr(IOAddress("fe80::1")); @@ -93,7 +106,7 @@ Bootstrap Protocol Option: (82) Agent Information Option Option: (255) End */ - string hex_string = + string hex_string = "010106015d05478d000000000000000000000000000000000afee20120e52ab8151400" "0000000000000000000000000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000000000000000" @@ -111,16 +124,7 @@ Bootstrap Protocol "140003000120e52ab81514390205dc5219010420000002020620e52ab8151409090000" "118b0401020300ff"; - std::vector bin; - - // Decode the hex string and store it in bin (which happens - // to be OptionBuffer format) - isc::util::encode::decodeHex(hex_string, bin); - - Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size())); - captureSetDefaultFields(pkt); - - return (pkt); + return (packetFromCapture(hex_string)); } }; // end of isc::dhcp::test namespace