Commit 2443a6fc authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[2591] Added est that checks if requested options are appended to offer.

parent 7d4b5581
......@@ -18,6 +18,8 @@
#include <asiolink/io_address.h>
#include <dhcp/dhcp4.h>
#include <dhcp/option.h>
#include <dhcp/option4_addrlst.h>
#include <dhcp/option_int_array.h>
#include <dhcp4/dhcp4_srv.h>
#include <dhcp4/dhcp4_log.h>
#include <dhcpsrv/cfgmgr.h>
......@@ -72,7 +74,7 @@ public:
/// @brief checks that the response matches request
/// @param q query (client's message)
/// @param a answer (server's message)
void MessageCheck(const boost::shared_ptr<Pkt4>& q,
void messageCheck(const boost::shared_ptr<Pkt4>& q,
const boost::shared_ptr<Pkt4>& a) {
ASSERT_TRUE(q);
ASSERT_TRUE(a);
......@@ -312,6 +314,34 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
pkt->setHops(3);
pkt->setRemotePort(DHCP4_SERVER_PORT);
// We are going to test that certain options are returned
// in the OFFER message when requested using 'Parameter
// Request List' option. Let's configure those options that
// are returned when requested.
OptionPtr option_log_servers(new Option4AddrLst(DHO_LOG_SERVERS));
ASSERT_NO_THROW(subnet_->addOption(option_log_servers, false, "dhcp4"));
OptionPtr option_cookie_servers(new Option4AddrLst(DHO_COOKIE_SERVERS));
ASSERT_NO_THROW(subnet_->addOption(option_cookie_servers, false, "dhcp4"));
// Add 'Parameter Request List' option. In this option we are going
// specify which options we request to be retured in the OFFER
// message.
OptionUint8ArrayPtr option_prl =
OptionUint8ArrayPtr(new OptionUint8Array(Option::V4,
DHO_DHCP_PARAMETER_REQUEST_LIST));
std::vector<uint8_t> opts;
// Let's request options that have been configured for the subnet.
opts.push_back(DHO_LOG_SERVERS);
opts.push_back(DHO_COOKIE_SERVERS);
// Let's also request the option that hasn't been configured. In such
// case server should ignore request for this particular option.
opts.push_back(DHO_LPR_SERVERS);
// Put the requested option codes into the 'Parameter Request List'.
option_prl->setValues(opts);
// And add 'Parameter Request List' option into the DISCOVER packet.
pkt->addOption(option_prl);
// Should not throw
EXPECT_NO_THROW(
offer = srv->processDiscover(pkt);
......@@ -325,7 +355,7 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
// This is relayed message. It should be sent back to relay address.
EXPECT_EQ(pkt->getGiaddr(), offer->getRemoteAddr());
MessageCheck(pkt, offer);
messageCheck(pkt, offer);
// Now repeat the test for directly sent message
pkt->setHops(0);
......@@ -345,7 +375,15 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
// to relay.
EXPECT_EQ(pkt->getRemoteAddr(), offer->getRemoteAddr());
MessageCheck(pkt, offer);
messageCheck(pkt, offer);
// Check that the requested and configured options are returned
// in the OFFER message.
EXPECT_TRUE(offer->getOption(DHO_LOG_SERVERS));
EXPECT_TRUE(offer->getOption(DHO_COOKIE_SERVERS));
// Check that the requested but not configured options are not
// returned in the OFFER message.
EXPECT_FALSE(offer->getOption(DHO_LPR_SERVERS));
delete srv;
}
......@@ -386,7 +424,7 @@ TEST_F(Dhcpv4SrvTest, processRequest) {
// This is relayed message. It should be sent back to relay address.
EXPECT_EQ(req->getGiaddr(), ack->getRemoteAddr());
MessageCheck(req, ack);
messageCheck(req, ack);
// Now repeat the test for directly sent message
req->setHops(0);
......@@ -406,7 +444,7 @@ TEST_F(Dhcpv4SrvTest, processRequest) {
// to relay.
EXPECT_EQ(ack->getRemoteAddr(), req->getRemoteAddr());
MessageCheck(req, ack);
messageCheck(req, ack);
delete srv;
}
......
......@@ -29,6 +29,11 @@
namespace isc {
namespace dhcp {
/// Forward declaration to Option4AddrLst class.
class Option4AddrLst;
/// A pointer to the Option4AddrLst object.
typedef boost::shared_ptr<Option4AddrLst> Option4AddrLstPtr;
/// @brief DHCPv4 Option class for handling list of IPv4 addresses.
///
......
......@@ -25,6 +25,23 @@
namespace isc {
namespace dhcp {
/// Forward declaration of OptionIntArray.
template<typename T>
class OptionIntArray;
/// @defgroup option_int_array_defs Typedefs for OptionIntArray class.
///
/// @brief Classes that represent options comprising array of integers.
///
/// @{
typedef OptionIntArray<uint8_t> OptionUint8Array;
typedef boost::shared_ptr<OptionUint8Array> OptionUint8ArrayPtr;
typedef OptionIntArray<uint16_t> OptionUint16Array;
typedef boost::shared_ptr<OptionUint16Array> OptionUint16ArrayPtr;
typedef OptionIntArray<uint32_t> OptionUint32Array;
typedef boost::shared_ptr<OptionUint32Array> OptionUint32ArrayPtr;
/// @}
/// This template class represents DHCP (v4 or v6) option with an
/// array of integer values. The type of the elements in the array
/// can be any of the following:
......
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