123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- #ifndef DHCP6_TEST_UTILS_H
- #define DHCP6_TEST_UTILS_H
- #include <gtest/gtest.h>
- #include <dhcp/pkt6.h>
- #include <dhcp/option6_ia.h>
- #include <dhcp/option6_iaaddr.h>
- #include <dhcp/option6_iaprefix.h>
- #include <dhcp/option6_status_code.h>
- #include <dhcp/option_int_array.h>
- #include <dhcp/option_custom.h>
- #include <dhcp/option.h>
- #include <dhcp/iface_mgr.h>
- #include <dhcpsrv/cfgmgr.h>
- #include <dhcpsrv/lease_mgr.h>
- #include <dhcpsrv/lease_mgr_factory.h>
- #include <dhcp6/dhcp6_srv.h>
- #include <hooks/hooks_manager.h>
- #include <list>
- namespace isc {
- namespace test {
- class NakedDhcpv6Srv: public isc::dhcp::Dhcpv6Srv {
- public:
- NakedDhcpv6Srv(uint16_t port) : isc::dhcp::Dhcpv6Srv(port) {
-
- std::string memfile = "type=memfile universe=6 persist=false";
- isc::dhcp::LeaseMgrFactory::create(memfile);
- }
-
-
-
-
-
-
-
-
- virtual isc::dhcp::Pkt6Ptr receivePacket(int ) {
-
-
- if (!fake_received_.empty()) {
- isc::dhcp::Pkt6Ptr pkt = fake_received_.front();
- fake_received_.pop_front();
- return (pkt);
- }
-
-
- shutdown();
- return (isc::dhcp::Pkt6Ptr());
- }
-
-
-
-
-
- virtual void sendPacket(const isc::dhcp::Pkt6Ptr& pkt) {
- fake_sent_.push_back(pkt);
- }
-
-
-
- void fakeReceive(const isc::dhcp::Pkt6Ptr& pkt) {
- fake_received_.push_back(pkt);
- }
- virtual ~NakedDhcpv6Srv() {
-
- isc::dhcp::LeaseMgrFactory::destroy();
- }
- using Dhcpv6Srv::processSolicit;
- using Dhcpv6Srv::processRequest;
- using Dhcpv6Srv::processRenew;
- using Dhcpv6Srv::processRelease;
- using Dhcpv6Srv::processClientFqdn;
- using Dhcpv6Srv::createNameChangeRequests;
- using Dhcpv6Srv::createRemovalNameChangeRequest;
- using Dhcpv6Srv::selectSubnet;
- using Dhcpv6Srv::testServerID;
- using Dhcpv6Srv::testUnicast;
- using Dhcpv6Srv::sanityCheck;
- using Dhcpv6Srv::classifyPacket;
- using Dhcpv6Srv::loadServerID;
- using Dhcpv6Srv::writeServerID;
- using Dhcpv6Srv::unpackOptions;
- using Dhcpv6Srv::shutdown_;
- using Dhcpv6Srv::name_change_reqs_;
- using Dhcpv6Srv::VENDOR_CLASS_PREFIX;
- using Dhcpv6Srv::createContext;
-
-
-
-
-
-
-
- std::list<isc::dhcp::Pkt6Ptr> fake_received_;
- std::list<isc::dhcp::Pkt6Ptr> fake_sent_;
- };
- class NakedDhcpv6SrvTest : public ::testing::Test {
- public:
-
- NakedDhcpv6SrvTest();
-
- static const char* DUID_FILE;
-
- boost::shared_ptr<isc::dhcp::Option6IA> generateIA
- (uint16_t type, uint32_t iaid, uint32_t t1, uint32_t t2);
-
-
-
-
-
- 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)));
- }
-
- isc::dhcp::OptionPtr generateClientId(size_t duid_size = 32) {
- isc::dhcp::OptionBuffer clnt_duid(duid_size);
- for (size_t i = 0; i < duid_size; i++) {
- clnt_duid[i] = 100 + i;
- }
- duid_ = isc::dhcp::DuidPtr(new isc::dhcp::DUID(clnt_duid));
- 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 isc::dhcp::Pkt6Ptr& rsp,
- const isc::dhcp::OptionPtr& expected_srvid)
- {
- // check that server included its server-id
- 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());
- }
-
-
- void checkClientId(const isc::dhcp::Pkt6Ptr& rsp,
- const isc::dhcp::OptionPtr& expected_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());
-
- EXPECT_TRUE(expected_clientid->getData() == tmp->getData());
- }
-
- void checkNakResponse(const isc::dhcp::Pkt6Ptr& rsp,
- uint8_t expected_message_type,
- uint32_t expected_transid,
- uint16_t expected_status_code,
- uint32_t expected_t1, uint32_t expected_t2)
- {
-
- checkResponse(rsp, expected_message_type, expected_transid);
-
- isc::dhcp::OptionPtr option_ia_na = rsp->getOption(D6O_IA_NA);
- ASSERT_TRUE(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, expected_t1,
- expected_t2);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void checkIA_NAStatusCode
- (const boost::shared_ptr<isc::dhcp::Option6IA>& ia,
- uint16_t expected_status_code, uint32_t expected_t1,
- uint32_t expected_t2, bool check_addr = true);
- void checkMsgStatusCode(const isc::dhcp::Pkt6Ptr& msg,
- uint16_t expected_status)
- {
- isc::dhcp::Option6StatusCodePtr status =
- boost::dynamic_pointer_cast<isc::dhcp::Option6StatusCode>
- (msg->getOption(D6O_STATUS_CODE));
-
-
- if (expected_status == STATUS_Success && !status) {
- return;
- }
- EXPECT_TRUE(status);
- if (status) {
-
-
-
-
- EXPECT_EQ(static_cast<uint16_t>(expected_status),
- status->getStatusCode());
- }
- }
-
- 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());
- EXPECT_EQ(expected_transid, rsp->getTransid());
- }
- virtual ~NakedDhcpv6SrvTest();
-
- isc::dhcp::DuidPtr duid_;
- int rcode_;
- isc::data::ConstElementPtr comment_;
-
- std::string valid_iface_;
- };
- class Dhcpv6SrvTest : public NakedDhcpv6SrvTest {
- public:
-
-
-
-
-
- Dhcpv6SrvTest();
-
-
-
- ~Dhcpv6SrvTest() {
- isc::dhcp::CfgMgr::instance().clear();
- };
-
-
-
- void configure(const std::string& config);
-
-
-
-
- void configure(const std::string& config, NakedDhcpv6Srv& srv);
-
-
-
-
-
-
-
-
- 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);
-
-
-
-
-
-
-
-
- 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);
-
-
- void checkIAAddr(const boost::shared_ptr<isc::dhcp::Option6IAAddr>& addr,
- const isc::asiolink::IOAddress& expected_addr,
- isc::dhcp::Lease::Type type) {
-
-
-
-
- EXPECT_TRUE(subnet_->inPool(type, addr->getAddress()));
- EXPECT_EQ(expected_addr.toText(), addr->getAddress().toText());
- EXPECT_EQ(subnet_->getPreferred(), addr->getPreferred());
- EXPECT_EQ(subnet_->getValid(), addr->getValid());
- }
-
-
- isc::dhcp::Lease6Ptr checkLease
- (const isc::dhcp::DuidPtr& duid, const isc::dhcp::OptionPtr& ia_na,
- boost::shared_ptr<isc::dhcp::Option6IAAddr> addr);
-
-
-
-
- isc::dhcp::Lease6Ptr checkLease(const isc::dhcp::Lease6& lease);
-
-
-
-
-
-
-
-
-
- isc::dhcp::Lease6Ptr checkPdLease
- (const isc::dhcp::DuidPtr& duid, const isc::dhcp::OptionPtr& ia_pd,
- boost::shared_ptr<isc::dhcp::Option6IAPrefix> prefix);
-
-
-
-
-
-
-
-
-
-
-
-
- isc::dhcp::Pkt6Ptr
- createMessage(uint8_t message_type, isc::dhcp::Lease::Type lease_type,
- const isc::asiolink::IOAddress& addr,
- const uint8_t prefix_len, const uint32_t iaid);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- isc::dhcp::Option6IAPtr
- createIA(isc::dhcp::Lease::Type lease_type,
- const isc::asiolink::IOAddress& addr,
- const uint8_t prefix_len, const uint32_t iaid);
-
-
-
-
-
-
-
-
-
-
-
-
-
- bool compareOptions(const isc::dhcp::OptionPtr& option1,
- const isc::dhcp::OptionPtr& option2);
-
-
-
-
-
-
-
-
-
-
-
-
-
- void
- testRenewBasic(isc::dhcp::Lease::Type type,
- const std::string& existing_addr,
- const std::string& renew_addr, const uint8_t prefix_len,
- bool insert_before_renew = true);
-
-
-
-
- void
- testRenewWrongIAID(isc::dhcp::Lease::Type type,
- const asiolink::IOAddress& addr);
-
-
-
-
- void
- testRenewSomeoneElsesLease(isc::dhcp::Lease::Type type,
- const asiolink::IOAddress& addr);
-
-
-
-
-
-
-
-
-
- void
- testRenewReject(isc::dhcp::Lease::Type type,
- const isc::asiolink::IOAddress& addr);
-
-
-
-
-
-
-
-
-
-
- void
- testReleaseBasic(isc::dhcp::Lease::Type type,
- const isc::asiolink::IOAddress& existing,
- const isc::asiolink::IOAddress& release_addr);
-
-
-
-
-
-
-
-
-
-
- void
- testReleaseReject(isc::dhcp::Lease::Type type,
- const isc::asiolink::IOAddress& addr);
-
-
-
-
- void testReceiveStats(uint8_t pkt_type, const std::string& stat_name);
-
- isc::dhcp::Subnet6Ptr subnet_;
-
- isc::dhcp::Pool6Ptr pool_;
-
- isc::dhcp::Pool6Ptr pd_pool_;
-
- NakedDhcpv6Srv srv_;
- };
- };
- };
- #endif
|