Commit 09695b7f authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3184] Changes after review:

 - ASSERT added to unit-tests
 - packetFromCapture() created
 - comments changes
parent 77c44b84
......@@ -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);
......
......@@ -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
......@@ -19,9 +19,9 @@
#include <util/encode/hex.h>
/// @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<uint8_t> 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<uint8_t> 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment