dhcp4_test_utils.cc 20 KB

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