#include <list>
-using namespace isc::dhcp;
-using namespace isc::config;
-using namespace isc::data;
-using namespace isc::hooks;
-using namespace isc::asiolink;
-using namespace isc::util;
-using namespace isc::hooks;
-
namespace isc {
namespace test {
/// @brief "naked" Dhcpv6Srv class that exposes internal members
class NakedDhcpv6Srv: public isc::dhcp::Dhcpv6Srv {
public:
- NakedDhcpv6Srv(uint16_t port) : Dhcpv6Srv(port) {
+ NakedDhcpv6Srv(uint16_t port) : isc::dhcp::Dhcpv6Srv(port) {
// Open the "memfile" database for leases
std::string memfile = "type=memfile";
- LeaseMgrFactory::create(memfile);
+ isc::dhcp::LeaseMgrFactory::create(memfile);
}
/// @brief fakes packet reception
// If there is anything prepared as fake incoming
// traffic, use it
if (!fake_received_.empty()) {
- Pkt6Ptr pkt = fake_received_.front();
+ isc::dhcp::Pkt6Ptr pkt = fake_received_.front();
fake_received_.pop_front();
return (pkt);
}
// If not, just trigger shutdown and
// return immediately
shutdown();
- return (Pkt6Ptr());
+ return (isc::dhcp::Pkt6Ptr());
}
/// @brief fake packet sending
/// Pretend to send a packet, but instead just store
/// it in fake_send_ list where test can later inspect
/// server's response.
- virtual void sendPacket(const Pkt6Ptr& pkt) {
+ virtual void sendPacket(const isc::dhcp::Pkt6Ptr& pkt) {
fake_sent_.push_back(pkt);
}
/// @brief adds a packet to fake receive queue
///
/// See fake_received_ field for description
- void fakeReceive(const Pkt6Ptr& pkt) {
+ void fakeReceive(const isc::dhcp::Pkt6Ptr& pkt) {
fake_received_.push_back(pkt);
}
virtual ~NakedDhcpv6Srv() {
// Close the lease database
- LeaseMgrFactory::destroy();
+ isc::dhcp::LeaseMgrFactory::destroy();
}
using Dhcpv6Srv::processSolicit;
/// @brief packets we pretend to receive
///
- /// Instead of setting up sockets on interfaces that change between OSes, it
- /// is much easier to fake packet reception. This is a list of packets that
- /// we pretend to have received. You can schedule new packets to be received
- /// using fakeReceive() and NakedDhcpv6Srv::receivePacket() methods.
- std::list<Pkt6Ptr> fake_received_;
-
- std::list<Pkt6Ptr> fake_sent_;
+ /// Instead of setting up sockets on interfaces that change between
+ /// OSes, it is much easier to fake packet reception. This is a list
+ /// of packets that we pretend to have received. You can schedule
+ /// new packets to be received using fakeReceive() and
+ /// NakedDhcpv6Srv::receivePacket() methods.
+ std::list<isc::dhcp::Pkt6Ptr> fake_received_;
+
+ std::list<isc::dhcp::Pkt6Ptr> fake_sent_;
};
static const char* DUID_FILE = "server-id-test.txt";
// it's ok if that fails. There should not be such a file anyway
unlink(DUID_FILE);
- const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
+ const isc::dhcp::IfaceMgr::IfaceCollection& ifaces =
+ isc::dhcp::IfaceMgr::instance().getIfaces();
// There must be some interface detected
if (ifaces.empty()) {
}
// Generate IA_NA or IA_PD option with specified parameters
- boost::shared_ptr<Option6IA> generateIA(uint16_t type, uint32_t iaid,
- uint32_t t1, uint32_t t2);
+ boost::shared_ptr<isc::dhcp::Option6IA> generateIA
+ (uint16_t type, uint32_t iaid, uint32_t t1, uint32_t t2);
/// @brief generates interface-id option, based on text
///
/// @param iface_id textual representation of the interface-id content
///
/// @return pointer to the option object
- OptionPtr generateInterfaceId(const std::string& iface_id) {
- OptionBuffer tmp(iface_id.begin(), iface_id.end());
- return OptionPtr(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
+ isc::dhcp::OptionPtr generateInterfaceId(const std::string& iface_id) {
+ isc::dhcp::OptionBuffer tmp(iface_id.begin(), iface_id.end());
+ return (isc::dhcp::OptionPtr
+ (new isc::dhcp::Option(isc::dhcp::Option::V6,
+ D6O_INTERFACE_ID, tmp)));
}
// Generate client-id option
- OptionPtr generateClientId(size_t duid_size = 32) {
+ isc::dhcp::OptionPtr generateClientId(size_t duid_size = 32) {
- OptionBuffer clnt_duid(duid_size);
+ isc::dhcp::OptionBuffer clnt_duid(duid_size);
for (int i = 0; i < duid_size; i++) {
clnt_duid[i] = 100 + i;
}
- duid_ = DuidPtr(new DUID(clnt_duid));
+ duid_ = isc::dhcp::DuidPtr(new isc::dhcp::DUID(clnt_duid));
- return (OptionPtr(new Option(Option::V6, D6O_CLIENTID,
- clnt_duid.begin(),
- clnt_duid.begin() + duid_size)));
+ return (isc::dhcp::OptionPtr
+ (new isc::dhcp::Option(isc::dhcp::Option::V6, D6O_CLIENTID,
+ clnt_duid.begin(),
+ clnt_duid.begin() + duid_size)));
}
- // Checks if server response (ADVERTISE or REPLY) includes proper server-id.
- void checkServerId(const Pkt6Ptr& rsp, const OptionPtr& expected_srvid) {
+ // Checks if server response (ADVERTISE or REPLY) includes proper
+ // server-id.
+ void checkServerId(const isc::dhcp::Pkt6Ptr& rsp,
+ const isc::dhcp::OptionPtr& expected_srvid)
+ {
// check that server included its server-id
- OptionPtr tmp = rsp->getOption(D6O_SERVERID);
+ isc::dhcp::OptionPtr tmp = rsp->getOption(D6O_SERVERID);
EXPECT_EQ(tmp->getType(), expected_srvid->getType() );
ASSERT_EQ(tmp->len(), expected_srvid->len() );
EXPECT_TRUE(tmp->getData() == expected_srvid->getData());
}
- // Checks if server response (ADVERTISE or REPLY) includes proper client-id.
- void checkClientId(const Pkt6Ptr& rsp, const OptionPtr& expected_clientid) {
+ // Checks if server response (ADVERTISE or REPLY) includes proper
+ // client-id.
+ void checkClientId(const isc::dhcp::Pkt6Ptr& rsp,
+ const isc::dhcp::OptionPtr& expected_clientid)
+ {
// check that server included our own client-id
- OptionPtr tmp = rsp->getOption(D6O_CLIENTID);
+ isc::dhcp::OptionPtr tmp = rsp->getOption(D6O_CLIENTID);
ASSERT_TRUE(tmp);
EXPECT_EQ(expected_clientid->getType(), tmp->getType());
ASSERT_EQ(expected_clientid->len(), tmp->len());
}
// Checks if server response is a NAK
- void checkNakResponse(const Pkt6Ptr& rsp, uint8_t expected_message_type,
+ void checkNakResponse(const isc::dhcp::Pkt6Ptr& rsp,
+ uint8_t expected_message_type,
uint32_t expected_transid,
- uint16_t expected_status_code) {
+ uint16_t expected_status_code)
+ {
// Check if we get response at all
checkResponse(rsp, expected_message_type, expected_transid);
// Check that IA_NA was returned
- OptionPtr option_ia_na = rsp->getOption(D6O_IA_NA);
+ isc::dhcp::OptionPtr option_ia_na = rsp->getOption(D6O_IA_NA);
ASSERT_TRUE(option_ia_na);
// check that the status is no address available
- boost::shared_ptr<Option6IA> ia = boost::dynamic_pointer_cast<Option6IA>(option_ia_na);
+ boost::shared_ptr<isc::dhcp::Option6IA> ia =
+ boost::dynamic_pointer_cast<isc::dhcp::Option6IA>(option_ia_na);
ASSERT_TRUE(ia);
checkIA_NAStatusCode(ia, expected_status_code);
// Status code indicates type of error encountered (in theory it can also
// indicate success, but servers typically don't send success status
// as this is the default result and it saves bandwidth)
- void checkIA_NAStatusCode(const boost::shared_ptr<Option6IA>& ia,
- uint16_t expected_status_code) {
+ void checkIA_NAStatusCode
+ (const boost::shared_ptr<isc::dhcp::Option6IA>& ia,
+ uint16_t expected_status_code)
+ {
// Make sure there is no address assigned.
EXPECT_FALSE(ia->getOption(D6O_IAADDR));
EXPECT_EQ(0, ia->getT1());
EXPECT_EQ(0, ia->getT2());
- OptionCustomPtr status =
- boost::dynamic_pointer_cast<OptionCustom>(ia->getOption(D6O_STATUS_CODE));
+ isc::dhcp::OptionCustomPtr status =
+ boost::dynamic_pointer_cast<isc::dhcp::OptionCustom>
+ (ia->getOption(D6O_STATUS_CODE));
- // It is ok to not include status success as this is the default behavior
+ // It is ok to not include status success as this is the default
+ // behavior
if (expected_status_code == STATUS_Success && !status) {
return;
}
EXPECT_TRUE(status);
if (status) {
- // We don't have dedicated class for status code, so let's just interpret
- // first 2 bytes as status. Remainder of the status code option content is
- // just a text explanation what went wrong.
+ // We don't have dedicated class for status code, so let's
+ // just interpret first 2 bytes as status. Remainder of the
+ // status code option content is just a text explanation
+ // what went wrong.
EXPECT_EQ(static_cast<uint16_t>(expected_status_code),
status->readInteger<uint16_t>(0));
}
}
- void checkMsgStatusCode(const Pkt6Ptr& msg, uint16_t expected_status) {
- OptionCustomPtr status =
- boost::dynamic_pointer_cast<OptionCustom>(msg->getOption(D6O_STATUS_CODE));
+ void checkMsgStatusCode(const isc::dhcp::Pkt6Ptr& msg,
+ uint16_t expected_status)
+ {
+ isc::dhcp::OptionCustomPtr status =
+ boost::dynamic_pointer_cast<isc::dhcp::OptionCustom>
+ (msg->getOption(D6O_STATUS_CODE));
- // It is ok to not include status success as this is the default behavior
+ // It is ok to not include status success as this is the default
+ // behavior
if (expected_status == STATUS_Success && !status) {
return;
}
EXPECT_TRUE(status);
if (status) {
- // We don't have dedicated class for status code, so let's just interpret
- // first 2 bytes as status. Remainder of the status code option content is
- // just a text explanation what went wrong.
+ // We don't have dedicated class for status code, so let's
+ // just interpret first 2 bytes as status. Remainder of the
+ // status code option content is just a text explanation
+ // what went wrong.
EXPECT_EQ(static_cast<uint16_t>(expected_status),
status->readInteger<uint16_t>(0));
}
}
// Basic checks for generated response (message type and transaction-id).
- void checkResponse(const Pkt6Ptr& rsp, uint8_t expected_message_type,
+ void checkResponse(const isc::dhcp::Pkt6Ptr& rsp,
+ uint8_t expected_message_type,
uint32_t expected_transid) {
ASSERT_TRUE(rsp);
EXPECT_EQ(expected_message_type, rsp->getType());
virtual ~NakedDhcpv6SrvTest() {
// Let's clean up if there is such a file.
unlink(DUID_FILE);
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "buffer6_receive");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "buffer6_send");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "lease6_renew");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "lease6_release");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "pkt6_receive");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "pkt6_send");
- HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
- "subnet6_select");
-
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("buffer6_receive");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("buffer6_send");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("lease6_renew");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("lease6_release");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("pkt6_receive");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("pkt6_send");
+ isc::hooks::HooksManager::preCalloutsLibraryHandle()
+ .deregisterAllCallouts("subnet6_select");
};
// A DUID used in most tests (typically as client-id)
- DuidPtr duid_;
+ isc::dhcp::DuidPtr duid_;
int rcode_;
- ConstElementPtr comment_;
+ isc::data::ConstElementPtr comment_;
// Name of a valid network interface
std::string valid_iface_;
/// Sets up a single subnet6 with one pool for addresses and second
/// pool for prefixes.
Dhcpv6SrvTest() {
- subnet_ = Subnet6Ptr(new Subnet6(IOAddress("2001:db8:1::"), 48, 1000,
- 2000, 3000, 4000));
- pool_ = Pool6Ptr(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:1::"),
- 64));
+ subnet_ = isc::dhcp::Subnet6Ptr
+ (new isc::dhcp::Subnet6(isc::asiolink::IOAddress("2001:db8:1::"),
+ 48, 1000, 2000, 3000, 4000));
+ pool_ = isc::dhcp::Pool6Ptr
+ (new isc::dhcp::Pool6(isc::dhcp::Lease::TYPE_NA,
+ isc::asiolink::IOAddress("2001:db8:1:1::"),
+ 64));
subnet_->addPool(pool_);
- CfgMgr::instance().deleteSubnets6();
- CfgMgr::instance().addSubnet6(subnet_);
+ isc::dhcp::CfgMgr::instance().deleteSubnets6();
+ isc::dhcp::CfgMgr::instance().addSubnet6(subnet_);
// configure PD pool
- pd_pool_ = Pool6Ptr(new Pool6(Lease::TYPE_PD,
- IOAddress("2001:db8:1:2::"), 64, 80));
+ pd_pool_ = isc::dhcp::Pool6Ptr
+ (new isc::dhcp::Pool6(isc::dhcp::Lease::TYPE_PD,
+ isc::asiolink::IOAddress("2001:db8:1:2::"),
+ 64, 80));
subnet_->addPool(pd_pool_);
}
///
/// Removes existing configuration.
~Dhcpv6SrvTest() {
- CfgMgr::instance().deleteSubnets6();
+ isc::dhcp::CfgMgr::instance().deleteSubnets6();
};
/// @brief Checks that server response (ADVERTISE or REPLY) contains proper
/// @param expected_t1 expected T1 value
/// @param expected_t2 expected T2 value
/// @return IAADDR option for easy chaining with checkIAAddr method
- boost::shared_ptr<Option6IAAddr>
- checkIA_NA(const Pkt6Ptr& rsp, uint32_t expected_iaid,
+ boost::shared_ptr<isc::dhcp::Option6IAAddr>
+ checkIA_NA(const isc::dhcp::Pkt6Ptr& rsp, uint32_t expected_iaid,
uint32_t expected_t1, uint32_t expected_t2);
/// @brief Checks that server response (ADVERTISE or REPLY) contains proper
/// @param expected_t1 expected T1 value
/// @param expected_t2 expected T2 value
/// @return IAPREFIX option for easy chaining with checkIAAddr method
- boost::shared_ptr<Option6IAPrefix>
- checkIA_PD(const Pkt6Ptr& rsp, uint32_t expected_iaid,
+ boost::shared_ptr<isc::dhcp::Option6IAPrefix>
+ checkIA_PD(const isc::dhcp::Pkt6Ptr& rsp, uint32_t expected_iaid,
uint32_t expected_t1, uint32_t expected_t2);
// Check that generated IAADDR option contains expected address
// and lifetime values match the configured subnet
- void checkIAAddr(const boost::shared_ptr<Option6IAAddr>& addr,
- const IOAddress& expected_addr,
- Lease::Type type) {
+ void checkIAAddr(const boost::shared_ptr<isc::dhcp::Option6IAAddr>& addr,
+ const isc::asiolink::IOAddress& expected_addr,
+ isc::dhcp::Lease::Type type) {
// Check that the assigned address is indeed from the configured pool.
// Note that when comparing addresses, we compare the textual
// Checks if the lease sent to client is present in the database
// and is valid when checked agasint the configured subnet
- Lease6Ptr checkLease(const DuidPtr& duid, const OptionPtr& ia_na,
- boost::shared_ptr<Option6IAAddr> addr);
+ isc::dhcp::Lease6Ptr checkLease
+ (const isc::dhcp::DuidPtr& duid, const isc::dhcp::OptionPtr& ia_na,
+ boost::shared_ptr<isc::dhcp::Option6IAAddr> addr);
/// @brief Verifies received IAPrefix option
///
/// @param ia_pd IA_PD option that contains the IAPRefix option
/// @param prefix pointer to the IAPREFIX option
/// @return corresponding IPv6 lease (if found)
- Lease6Ptr checkPdLease(const DuidPtr& duid, const OptionPtr& ia_pd,
- boost::shared_ptr<Option6IAPrefix> prefix);
+ isc::dhcp::Lease6Ptr checkPdLease
+ (const isc::dhcp::DuidPtr& duid, const isc::dhcp::OptionPtr& ia_pd,
+ boost::shared_ptr<isc::dhcp::Option6IAPrefix> prefix);
/// @brief Creates a message with specified IA
///
/// @param prefix_len length of the prefix (used for prefixes only)
/// @param iaid IA identifier (used in IA_XX option)
/// @return created message
- Pkt6Ptr
- createMessage(uint8_t message_type, Lease::Type lease_type,
- const IOAddress& addr, const uint8_t prefix_len,
- uint32_t iaid);
+ isc::dhcp::Pkt6Ptr
+ createMessage(uint8_t message_type, isc::dhcp::Lease::Type lease_type,
+ const isc::asiolink::IOAddress& addr,
+ const uint8_t prefix_len, uint32_t iaid);
/// @brief Performs basic (positive) RENEW test
///
/// @param renew_addr address being sent in RENEW
/// @param prefix_len length of the prefix (128 for addresses)
void
- testRenewBasic(Lease::Type type, const std::string& existing_addr,
+ testRenewBasic(isc::dhcp::Lease::Type type,
+ const std::string& existing_addr,
const std::string& renew_addr, const uint8_t prefix_len);
/// @brief Performs negative RENEW test
/// @param type type (TYPE_NA or TYPE_PD)
/// @param addr address being sent in RENEW
void
- testRenewReject(Lease::Type type, const IOAddress& addr);
+ testRenewReject(isc::dhcp::Lease::Type type,
+ const isc::asiolink::IOAddress& addr);
/// @brief Performs basic (positive) RELEASE test
///
/// @param existing address to be preinserted into the database
/// @param release_addr address being sent in RELEASE
void
- testReleaseBasic(Lease::Type type, const IOAddress& existing,
- const IOAddress& release_addr);
+ testReleaseBasic(isc::dhcp::Lease::Type type,
+ const isc::asiolink::IOAddress& existing,
+ const isc::asiolink::IOAddress& release_addr);
/// @brief Performs negative RELEASE test
///
- /// See releaseReject and pdReleaseReject tests for detailed explanation.
- /// In essence the test attempts to perform couple failed RELEASE scenarios.
+ /// See releaseReject and pdReleaseReject tests for detailed
+ /// explanation. In essence the test attempts to perform couple
+ /// failed RELEASE scenarios.
///
/// This method does not throw, but uses gtest macros to signify failures.
///
/// @param type type (TYPE_NA or TYPE_PD)
/// @param addr address being sent in RELEASE
void
- testReleaseReject(Lease::Type type, const IOAddress& addr);
+ testReleaseReject(isc::dhcp::Lease::Type type,
+ const isc::asiolink::IOAddress& addr);
// see wireshark.cc for descriptions
// The descriptions are too large and too closely related to the
// code, so it is kept in .cc rather than traditionally in .h
- Pkt6Ptr captureSimpleSolicit();
- Pkt6Ptr captureRelayedSolicit();
- Pkt6Ptr captureDocsisRelayedSolicit();
- Pkt6Ptr captureeRouterRelayedSolicit();
+ isc::dhcp::Pkt6Ptr captureSimpleSolicit();
+ isc::dhcp::Pkt6Ptr captureRelayedSolicit();
+ isc::dhcp::Pkt6Ptr captureDocsisRelayedSolicit();
+ isc::dhcp::Pkt6Ptr captureeRouterRelayedSolicit();
/// @brief Auxiliary method that sets Pkt6 fields
///
/// Used to reconstruct captured packets. Sets UDP ports, interface names,
/// and other fields to some believable values.
/// @param pkt packet that will have its fields set
- void captureSetDefaultFields(const Pkt6Ptr& pkt);
+ void captureSetDefaultFields(const isc::dhcp::Pkt6Ptr& pkt);
/// A subnet used in most tests
- Subnet6Ptr subnet_;
+ isc::dhcp::Subnet6Ptr subnet_;
/// A normal, non-temporary pool used in most tests
- Pool6Ptr pool_;
+ isc::dhcp::Pool6Ptr pool_;
/// A prefix pool used in most tests
- Pool6Ptr pd_pool_;
+ isc::dhcp::Pool6Ptr pd_pool_;
};
}; // end of isc::test namespace