dhcp4_test_utils.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <asiolink/io_address.h>
  16. #include <config/ccsession.h>
  17. #include <dhcp4/tests/dhcp4_test_utils.h>
  18. #include <dhcp/option4_addrlst.h>
  19. #include <dhcp/option_int_array.h>
  20. #include <dhcp/option_custom.h>
  21. #include <dhcp/iface_mgr.h>
  22. #include <dhcpsrv/cfgmgr.h>
  23. #include <dhcpsrv/lease.h>
  24. #include <dhcpsrv/lease_mgr.h>
  25. #include <dhcpsrv/lease_mgr_factory.h>
  26. using namespace std;
  27. using namespace isc::asiolink;
  28. namespace isc {
  29. namespace dhcp {
  30. namespace test {
  31. /// dummy server-id file location
  32. static const char* SRVID_FILE = "server-id-test.txt";
  33. Dhcpv4SrvTest::Dhcpv4SrvTest()
  34. :rcode_(-1) {
  35. subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1000,
  36. 2000, 3000));
  37. pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.100"), IOAddress("192.0.2.110")));
  38. subnet_->addPool(pool_);
  39. CfgMgr::instance().deleteActiveIfaces();
  40. CfgMgr::instance().deleteSubnets4();
  41. CfgMgr::instance().addSubnet4(subnet_);
  42. // Add Router option.
  43. Option4AddrLstPtr opt_routers(new Option4AddrLst(DHO_ROUTERS));
  44. opt_routers->setAddress(IOAddress("192.0.2.2"));
  45. subnet_->addOption(opt_routers, false, "dhcp4");
  46. // it's ok if that fails. There should not be such a file anyway
  47. unlink(SRVID_FILE);
  48. const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
  49. // There must be some interface detected
  50. if (ifaces.empty()) {
  51. // We can't use ASSERT in constructor
  52. ADD_FAILURE() << "No interfaces detected.";
  53. }
  54. valid_iface_ = ifaces.begin()->getName();
  55. }
  56. Dhcpv4SrvTest::~Dhcpv4SrvTest() {
  57. // Make sure that we revert to default value
  58. CfgMgr::instance().echoClientId(true);
  59. }
  60. void Dhcpv4SrvTest::addPrlOption(Pkt4Ptr& pkt) {
  61. OptionUint8ArrayPtr option_prl =
  62. OptionUint8ArrayPtr(new OptionUint8Array(Option::V4,
  63. DHO_DHCP_PARAMETER_REQUEST_LIST));
  64. // Let's request options that have been configured for the subnet.
  65. option_prl->addValue(DHO_DOMAIN_NAME_SERVERS);
  66. option_prl->addValue(DHO_DOMAIN_NAME);
  67. option_prl->addValue(DHO_LOG_SERVERS);
  68. option_prl->addValue(DHO_COOKIE_SERVERS);
  69. // Let's also request the option that hasn't been configured. In such
  70. // case server should ignore request for this particular option.
  71. option_prl->addValue(DHO_LPR_SERVERS);
  72. // And add 'Parameter Request List' option into the DISCOVER packet.
  73. pkt->addOption(option_prl);
  74. }
  75. void Dhcpv4SrvTest::configureRequestedOptions() {
  76. // dns-servers
  77. Option4AddrLstPtr
  78. option_dns_servers(new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS));
  79. option_dns_servers->addAddress(IOAddress("192.0.2.1"));
  80. option_dns_servers->addAddress(IOAddress("192.0.2.100"));
  81. ASSERT_NO_THROW(subnet_->addOption(option_dns_servers, false, "dhcp4"));
  82. // domain-name
  83. OptionDefinition def("domain-name", DHO_DOMAIN_NAME, OPT_FQDN_TYPE);
  84. OptionCustomPtr option_domain_name(new OptionCustom(def, Option::V4));
  85. option_domain_name->writeFqdn("example.com");
  86. subnet_->addOption(option_domain_name, false, "dhcp4");
  87. // log-servers
  88. Option4AddrLstPtr option_log_servers(new Option4AddrLst(DHO_LOG_SERVERS));
  89. option_log_servers->addAddress(IOAddress("192.0.2.2"));
  90. option_log_servers->addAddress(IOAddress("192.0.2.10"));
  91. ASSERT_NO_THROW(subnet_->addOption(option_log_servers, false, "dhcp4"));
  92. // cookie-servers
  93. Option4AddrLstPtr option_cookie_servers(new Option4AddrLst(DHO_COOKIE_SERVERS));
  94. option_cookie_servers->addAddress(IOAddress("192.0.2.1"));
  95. ASSERT_NO_THROW(subnet_->addOption(option_cookie_servers, false, "dhcp4"));
  96. }
  97. void Dhcpv4SrvTest::messageCheck(const Pkt4Ptr& q, const Pkt4Ptr& a) {
  98. ASSERT_TRUE(q);
  99. ASSERT_TRUE(a);
  100. EXPECT_EQ(q->getHops(), a->getHops());
  101. EXPECT_EQ(q->getIface(), a->getIface());
  102. EXPECT_EQ(q->getIndex(), a->getIndex());
  103. EXPECT_EQ(q->getGiaddr(), a->getGiaddr());
  104. // When processing an incoming packet the remote address
  105. // is copied as a src address, and the source address is
  106. // copied as a remote address to the response.
  107. EXPECT_TRUE(q->getLocalHWAddr() == a->getLocalHWAddr());
  108. EXPECT_TRUE(q->getRemoteHWAddr() == a->getRemoteHWAddr());
  109. // Check that the server identifier is present in the response.
  110. // Presence (or absence) of other options is checked elsewhere.
  111. EXPECT_TRUE(a->getOption(DHO_DHCP_SERVER_IDENTIFIER));
  112. // Check that something is offered
  113. EXPECT_NE("0.0.0.0", a->getYiaddr().toText());
  114. }
  115. ::testing::AssertionResult
  116. Dhcpv4SrvTest::basicOptionsPresent(const Pkt4Ptr& pkt) {
  117. std::ostringstream errmsg;
  118. errmsg << "option missing in the response";
  119. if (!pkt->getOption(DHO_DOMAIN_NAME)) {
  120. return (::testing::AssertionFailure(::testing::Message()
  121. << "domain-name " << errmsg));
  122. } else if (!pkt->getOption(DHO_DOMAIN_NAME_SERVERS)) {
  123. return (::testing::AssertionFailure(::testing::Message()
  124. << "dns-servers " << errmsg));
  125. } else if (!pkt->getOption(DHO_SUBNET_MASK)) {
  126. return (::testing::AssertionFailure(::testing::Message()
  127. << "subnet-mask " << errmsg));
  128. } else if (!pkt->getOption(DHO_ROUTERS)) {
  129. return (::testing::AssertionFailure(::testing::Message() << "routers "
  130. << errmsg));
  131. } else if (!pkt->getOption(DHO_DHCP_LEASE_TIME)) {
  132. return (::testing::AssertionFailure(::testing::Message() <<
  133. "dhcp-lease-time " << errmsg));
  134. }
  135. return (::testing::AssertionSuccess());
  136. }
  137. ::testing::AssertionResult
  138. Dhcpv4SrvTest::noBasicOptions(const Pkt4Ptr& pkt) {
  139. std::ostringstream errmsg;
  140. errmsg << "option present in the response";
  141. if (pkt->getOption(DHO_DOMAIN_NAME)) {
  142. return (::testing::AssertionFailure(::testing::Message()
  143. << "domain-name " << errmsg));
  144. } else if (pkt->getOption(DHO_DOMAIN_NAME_SERVERS)) {
  145. return (::testing::AssertionFailure(::testing::Message()
  146. << "dns-servers " << errmsg));
  147. } else if (pkt->getOption(DHO_SUBNET_MASK)) {
  148. return (::testing::AssertionFailure(::testing::Message()
  149. << "subnet-mask " << errmsg));
  150. } else if (pkt->getOption(DHO_ROUTERS)) {
  151. return (::testing::AssertionFailure(::testing::Message() << "routers "
  152. << errmsg));
  153. } else if (pkt->getOption(DHO_DHCP_LEASE_TIME)) {
  154. return (::testing::AssertionFailure(::testing::Message()
  155. << "dhcp-lease-time " << errmsg));
  156. }
  157. return (::testing::AssertionSuccess());
  158. }
  159. ::testing::AssertionResult
  160. Dhcpv4SrvTest::requestedOptionsPresent(const Pkt4Ptr& pkt) {
  161. std::ostringstream errmsg;
  162. errmsg << "option missing in the response";
  163. if (!pkt->getOption(DHO_LOG_SERVERS)) {
  164. return (::testing::AssertionFailure(::testing::Message()
  165. << "log-servers " << errmsg));
  166. } else if (!pkt->getOption(DHO_COOKIE_SERVERS)) {
  167. return (::testing::AssertionFailure(::testing::Message()
  168. << "cookie-servers " << errmsg));
  169. }
  170. return (::testing::AssertionSuccess());
  171. }
  172. ::testing::AssertionResult
  173. Dhcpv4SrvTest::noRequestedOptions(const Pkt4Ptr& pkt) {
  174. std::ostringstream errmsg;
  175. errmsg << "option present in the response";
  176. if (pkt->getOption(DHO_LOG_SERVERS)) {
  177. return (::testing::AssertionFailure(::testing::Message()
  178. << "log-servers " << errmsg));
  179. } else if (pkt->getOption(DHO_COOKIE_SERVERS)) {
  180. return (::testing::AssertionFailure(::testing::Message()
  181. << "cookie-servers " << errmsg));
  182. }
  183. return (::testing::AssertionSuccess());
  184. }
  185. OptionPtr Dhcpv4SrvTest::generateClientId(size_t size /*= 4*/) {
  186. OptionBuffer clnt_id(size);
  187. for (int i = 0; i < size; i++) {
  188. clnt_id[i] = 100 + i;
  189. }
  190. client_id_ = ClientIdPtr(new ClientId(clnt_id));
  191. return (OptionPtr(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER,
  192. clnt_id.begin(),
  193. clnt_id.begin() + size)));
  194. }
  195. HWAddrPtr Dhcpv4SrvTest::generateHWAddr(size_t size /*= 6*/) {
  196. const uint8_t hw_type = 123; // Just a fake number (typically 6=HTYPE_ETHER, see dhcp4.h)
  197. OptionBuffer mac(size);
  198. for (int i = 0; i < size; ++i) {
  199. mac[i] = 50 + i;
  200. }
  201. return (HWAddrPtr(new HWAddr(mac, hw_type)));
  202. }
  203. void Dhcpv4SrvTest::checkAddressParams(const Pkt4Ptr& rsp, const SubnetPtr subnet,
  204. bool t1_mandatory /*= false*/,
  205. bool t2_mandatory /*= false*/) {
  206. // Technically inPool implies inRange, but let's be on the safe
  207. // side and check both.
  208. EXPECT_TRUE(subnet->inRange(rsp->getYiaddr()));
  209. EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, rsp->getYiaddr()));
  210. // Check lease time
  211. OptionPtr opt = rsp->getOption(DHO_DHCP_LEASE_TIME);
  212. if (!opt) {
  213. ADD_FAILURE() << "Lease time option missing in response";
  214. } else {
  215. EXPECT_EQ(opt->getUint32(), subnet->getValid());
  216. }
  217. // Check T1 timer
  218. opt = rsp->getOption(DHO_DHCP_RENEWAL_TIME);
  219. if (opt) {
  220. EXPECT_EQ(opt->getUint32(), subnet->getT1());
  221. } else {
  222. if (t1_mandatory) {
  223. ADD_FAILURE() << "Required T1 option missing";
  224. }
  225. }
  226. // Check T2 timer
  227. opt = rsp->getOption(DHO_DHCP_REBINDING_TIME);
  228. if (opt) {
  229. EXPECT_EQ(opt->getUint32(), subnet->getT2());
  230. } else {
  231. if (t2_mandatory) {
  232. ADD_FAILURE() << "Required T2 option missing";
  233. }
  234. }
  235. }
  236. void Dhcpv4SrvTest::checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
  237. uint32_t expected_transid) {
  238. ASSERT_TRUE(rsp);
  239. EXPECT_EQ(expected_message_type, rsp->getType());
  240. EXPECT_EQ(expected_transid, rsp->getTransid());
  241. }
  242. Lease4Ptr Dhcpv4SrvTest::checkLease(const Pkt4Ptr& rsp,
  243. const OptionPtr& client_id,
  244. const HWAddrPtr&,
  245. const IOAddress& expected_addr) {
  246. ClientIdPtr id;
  247. if (client_id) {
  248. OptionBuffer data = client_id->getData();
  249. id.reset(new ClientId(data));
  250. }
  251. Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(expected_addr);
  252. if (!lease) {
  253. cout << "Lease for " << expected_addr
  254. << " not found in the database backend.";
  255. return (Lease4Ptr());
  256. }
  257. EXPECT_EQ(rsp->getYiaddr(), expected_addr);
  258. EXPECT_EQ(expected_addr, lease->addr_);
  259. if (client_id) {
  260. EXPECT_TRUE(*lease->client_id_ == *id);
  261. }
  262. EXPECT_EQ(subnet_->getID(), lease->subnet_id_);
  263. return (lease);
  264. }
  265. /// @brief Checks if server response (OFFER, ACK, NAK) includes proper server-id
  266. /// @param rsp response packet to be validated
  267. /// @param expected_srvid expected value of server-id
  268. void Dhcpv4SrvTest::checkServerId(const Pkt4Ptr& rsp, const OptionPtr& expected_srvid) {
  269. // Check that server included its server-id
  270. OptionPtr opt = rsp->getOption(DHO_DHCP_SERVER_IDENTIFIER);
  271. ASSERT_TRUE(opt);
  272. EXPECT_EQ(opt->getType(), expected_srvid->getType() );
  273. EXPECT_EQ(opt->len(), expected_srvid->len() );
  274. EXPECT_TRUE(opt->getData() == expected_srvid->getData());
  275. }
  276. void Dhcpv4SrvTest::checkClientId(const Pkt4Ptr& rsp, const OptionPtr& expected_clientid) {
  277. bool include_clientid = CfgMgr::instance().echoClientId();
  278. // check that server included our own client-id
  279. OptionPtr opt = rsp->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
  280. if (include_clientid) {
  281. // Normal mode: echo back (see RFC6842)
  282. ASSERT_TRUE(opt);
  283. EXPECT_EQ(expected_clientid->getType(), opt->getType());
  284. EXPECT_EQ(expected_clientid->len(), opt->len());
  285. EXPECT_TRUE(expected_clientid->getData() == opt->getData());
  286. } else {
  287. // Backward compatibility mode for pre-RFC6842 devices
  288. ASSERT_FALSE(opt);
  289. }
  290. }
  291. ::testing::AssertionResult
  292. Dhcpv4SrvTest::createPacketFromBuffer(const Pkt4Ptr& src_pkt,
  293. Pkt4Ptr& dst_pkt) {
  294. // Create on-wire format of the packet. If pack() has been called
  295. // on this instance of the packet already, the next call to pack()
  296. // should remove all contents of the output buffer.
  297. try {
  298. src_pkt->pack();
  299. } catch (const Exception& ex) {
  300. return (::testing::AssertionFailure(::testing::Message()
  301. << "Failed to parse source packet: "
  302. << ex.what()));
  303. }
  304. // Get the output buffer from the source packet.
  305. const util::OutputBuffer& buf = src_pkt->getBuffer();
  306. // Create a copy of the packet using the output buffer from the source
  307. // packet.
  308. try {
  309. dst_pkt.reset(new Pkt4(static_cast<const uint8_t*>(buf.getData()),
  310. buf.getLength()));
  311. } catch (const Exception& ex) {
  312. return (::testing::AssertionFailure(::testing::Message()
  313. << "Failed to create a"
  314. " destination packet from"
  315. " the buffer: "
  316. << ex.what()));
  317. }
  318. try {
  319. // Parse the new packet and return to the caller.
  320. dst_pkt->unpack();
  321. } catch (const Exception& ex) {
  322. return (::testing::AssertionFailure(::testing::Message()
  323. << "Failed to parse a"
  324. << " destination packet: "
  325. << ex.what()));
  326. }
  327. return (::testing::AssertionSuccess());
  328. }
  329. void Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) {
  330. // Create an instance of the tested class.
  331. boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
  332. // Initialize the source HW address.
  333. vector<uint8_t> mac(6);
  334. for (int i = 0; i < 6; ++i) {
  335. mac[i] = i * 10;
  336. }
  337. // Initialized the destination HW address.
  338. vector<uint8_t> dst_mac(6);
  339. for (int i = 0; i < 6; ++i) {
  340. dst_mac[i] = i * 20;
  341. }
  342. // Create a DHCP message. It will be used to simulate the
  343. // incoming message.
  344. boost::shared_ptr<Pkt4> req(new Pkt4(msg_type, 1234));
  345. // Create a response message. It will hold a reponse packet.
  346. // Initially, set it to NULL.
  347. boost::shared_ptr<Pkt4> rsp;
  348. // Set the name of the interface on which packet is received.
  349. req->setIface("eth0");
  350. // Set the interface index. It is just a dummy value and will
  351. // not be interpreted.
  352. req->setIndex(17);
  353. // Set the target HW address. This value is normally used to
  354. // construct the data link layer header.
  355. req->setRemoteHWAddr(1, 6, dst_mac);
  356. // Set the HW address. This value is set on DHCP level (in chaddr).
  357. req->setHWAddr(1, 6, mac);
  358. // Set local HW address. It is used to construct the data link layer
  359. // header.
  360. req->setLocalHWAddr(1, 6, mac);
  361. // Set target IP address.
  362. req->setRemoteAddr(IOAddress("192.0.2.55"));
  363. // Set relay address.
  364. req->setGiaddr(IOAddress("192.0.2.10"));
  365. // We are going to test that certain options are returned
  366. // in the response message when requested using 'Parameter
  367. // Request List' option. Let's configure those options that
  368. // are returned when requested.
  369. configureRequestedOptions();
  370. // Create a copy of the original packet by parsing its wire format.
  371. // This simulates the real life scenario when we process the packet
  372. // which was parsed from its wire format.
  373. Pkt4Ptr received;
  374. ASSERT_TRUE(createPacketFromBuffer(req, received));
  375. if (msg_type == DHCPDISCOVER) {
  376. ASSERT_NO_THROW(
  377. rsp = srv->processDiscover(received);
  378. );
  379. // Should return OFFER
  380. ASSERT_TRUE(rsp);
  381. EXPECT_EQ(DHCPOFFER, rsp->getType());
  382. } else {
  383. ASSERT_NO_THROW(rsp = srv->processRequest(received));
  384. // Should return ACK
  385. ASSERT_TRUE(rsp);
  386. EXPECT_EQ(DHCPACK, rsp->getType());
  387. }
  388. messageCheck(received, rsp);
  389. // Basic options should be present when we got the lease.
  390. EXPECT_TRUE(basicOptionsPresent(rsp));
  391. // We did not request any options so these should not be present
  392. // in the RSP.
  393. EXPECT_TRUE(noRequestedOptions(rsp));
  394. // Repeat the test but request some options.
  395. // Add 'Parameter Request List' option.
  396. addPrlOption(req);
  397. ASSERT_TRUE(createPacketFromBuffer(req, received));
  398. ASSERT_TRUE(received->getOption(DHO_DHCP_PARAMETER_REQUEST_LIST));
  399. if (msg_type == DHCPDISCOVER) {
  400. ASSERT_NO_THROW(rsp = srv->processDiscover(received));
  401. // Should return non-NULL packet.
  402. ASSERT_TRUE(rsp);
  403. EXPECT_EQ(DHCPOFFER, rsp->getType());
  404. } else {
  405. ASSERT_NO_THROW(rsp = srv->processRequest(received));
  406. // Should return non-NULL packet.
  407. ASSERT_TRUE(rsp);
  408. EXPECT_EQ(DHCPACK, rsp->getType());
  409. }
  410. // Check that the requested options are returned.
  411. EXPECT_TRUE(basicOptionsPresent(rsp));
  412. EXPECT_TRUE(requestedOptionsPresent(rsp));
  413. // The following part of the test will test that the NAK is sent when
  414. // there is no address pool configured. In the same time, we expect
  415. // that the requested options are not included in NAK message, but that
  416. // they are only included when yiaddr is set to non-zero value.
  417. ASSERT_NO_THROW(subnet_->delPools(Lease::TYPE_V4));
  418. // There has been a lease allocated for the particular client. So,
  419. // even though we deleted the subnet, the client would get the
  420. // existing lease (not a NAK). Therefore, we have to change the chaddr
  421. // in the packet so as the existing lease is not returned.
  422. req->setHWAddr(1, 6, std::vector<uint8_t>(2, 6));
  423. ASSERT_TRUE(createPacketFromBuffer(req, received));
  424. ASSERT_TRUE(received->getOption(DHO_DHCP_PARAMETER_REQUEST_LIST));
  425. if (msg_type == DHCPDISCOVER) {
  426. ASSERT_NO_THROW(rsp = srv->processDiscover(received));
  427. // Should return non-NULL packet.
  428. ASSERT_TRUE(rsp);
  429. } else {
  430. ASSERT_NO_THROW(rsp = srv->processRequest(received));
  431. // Should return non-NULL packet.
  432. ASSERT_TRUE(rsp);
  433. }
  434. // We should get the NAK packet with yiaddr set to 0.
  435. EXPECT_EQ(DHCPNAK, rsp->getType());
  436. ASSERT_EQ("0.0.0.0", rsp->getYiaddr().toText());
  437. // Make sure that none of the requested options is returned in NAK.
  438. // Also options such as Routers or Subnet Mask should not be there,
  439. // because lease hasn't been acquired.
  440. EXPECT_TRUE(noRequestedOptions(rsp));
  441. EXPECT_TRUE(noBasicOptions(rsp));
  442. }
  443. /// @brief This function cleans up after the test.
  444. void Dhcpv4SrvTest::TearDown() {
  445. CfgMgr::instance().deleteSubnets4();
  446. // Let's clean up if there is such a file.
  447. unlink(SRVID_FILE);
  448. // Close all open sockets.
  449. IfaceMgr::instance().closeSockets();
  450. // Some unit tests override the default packet filtering class, used
  451. // by the IfaceMgr. The dummy class, called PktFilterTest, reports the
  452. // capability to directly respond to the clients without IP address
  453. // assigned. This capability is not supported by the default packet
  454. // filtering class: PktFilterInet. Therefore setting the dummy class
  455. // allows to test scenarios, when server responds to the broadcast address
  456. // on client's request, despite having support for direct response.
  457. // The following call restores the use of original packet filtering class
  458. // after the test.
  459. try {
  460. IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterInet()));
  461. } catch (const Exception& ex) {
  462. FAIL() << "Failed to restore the default (PktFilterInet) packet filtering"
  463. << " class after the test. Exception has been caught: "
  464. << ex.what();
  465. }
  466. }
  467. }; // end of isc::dhcp::test namespace
  468. }; // end of isc::dhcp namespace
  469. }; // end of isc namespace