Browse Source

[3242] Use library with IfaceMgrTestConfig to test DHCPv4 server.

Marcin Siodelski 11 years ago
parent
commit
c3a1bd5a60

+ 171 - 69
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

@@ -29,6 +29,7 @@
 #include <dhcp/pkt_filter.h>
 #include <dhcp/pkt_filter.h>
 #include <dhcp/pkt_filter_inet.h>
 #include <dhcp/pkt_filter_inet.h>
 #include <dhcp/docsis3_option_defs.h>
 #include <dhcp/docsis3_option_defs.h>
+#include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp4/dhcp4_srv.h>
 #include <dhcp4/dhcp4_srv.h>
 #include <dhcp4/dhcp4_log.h>
 #include <dhcp4/dhcp4_log.h>
 #include <dhcp4/config_parser.h>
 #include <dhcp4/config_parser.h>
@@ -61,7 +62,10 @@ namespace {
 // This test verifies that the destination address of the response
 // This test verifies that the destination address of the response
 // message is set to giaddr, when giaddr is set to non-zero address
 // message is set to giaddr, when giaddr is set to non-zero address
 // in the received message.
 // in the received message.
-TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRelay) {
+TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelay) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     // Create the instance of the incoming packet.
     // Create the instance of the incoming packet.
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     // Set the giaddr to non-zero address and hops to non-zero value
     // Set the giaddr to non-zero address and hops to non-zero value
@@ -77,7 +81,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRelay) {
     // Set local address, port and interface.
     // Set local address, port and interface.
     req->setLocalAddr(IOAddress("192.0.2.1"));
     req->setLocalAddr(IOAddress("192.0.2.1"));
     req->setLocalPort(1001);
     req->setLocalPort(1001);
-    req->setIface("eth0");
+    req->setIface("eth1");
     req->setIndex(1);
     req->setIndex(1);
 
 
     // Create a response packet. Assume that the new lease have
     // Create a response packet. Assume that the new lease have
@@ -97,13 +101,13 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRelay) {
     EXPECT_EQ("192.0.1.1", resp->getRemoteAddr().toText());
     EXPECT_EQ("192.0.1.1", resp->getRemoteAddr().toText());
     // The query has been relayed, so the response must be sent to the port 67.
     // The query has been relayed, so the response must be sent to the port 67.
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
-    // Local address should be copied from the query message.
-    EXPECT_EQ("192.0.2.1", resp->getLocalAddr().toText());
+    // Local address should be the address assigned to interface eth1.
+    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
     // The local port is always DHCPv4 server port 67.
     // The local port is always DHCPv4 server port 67.
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     // We will send response over the same interface which was used to receive
     // We will send response over the same interface which was used to receive
     // query.
     // query.
-    EXPECT_EQ("eth0", resp->getIface());
+    EXPECT_EQ("eth1", resp->getIface());
     EXPECT_EQ(1, resp->getIndex());
     EXPECT_EQ(1, resp->getIndex());
 
 
     // Let's do another test and set other fields: ciaddr and
     // Let's do another test and set other fields: ciaddr and
@@ -127,7 +131,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRelay) {
 // is set to ciaddr when giaddr is set to zero and the ciaddr is set to
 // is set to ciaddr when giaddr is set to zero and the ciaddr is set to
 // non-zero address in the received message. This is the case when the
 // non-zero address in the received message. This is the case when the
 // client is in Renew or Rebind state.
 // client is in Renew or Rebind state.
-TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRenew) {
+TEST_F(Dhcpv4SrvTest, adjustIfaceDataRenew) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     // Create instance of the incoming packet.
     // Create instance of the incoming packet.
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
 
 
@@ -151,7 +158,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRenew) {
     // Request is received on the DHCPv4 server port.
     // Request is received on the DHCPv4 server port.
     req->setLocalPort(DHCP4_SERVER_PORT);
     req->setLocalPort(DHCP4_SERVER_PORT);
     // Set the interface. The response should be sent over the same interface.
     // Set the interface. The response should be sent over the same interface.
-    req->setIface("eth0");
+    req->setIface("eth1");
     req->setIndex(1);
     req->setIndex(1);
 
 
     // Create a response.
     // Create a response.
@@ -175,11 +182,11 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRenew) {
     EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getRemotePort());
     EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getRemotePort());
     // The response should be sent from the unicast address on which the
     // The response should be sent from the unicast address on which the
     // query has been received.
     // query has been received.
-    EXPECT_EQ("192.0.2.1", resp->getLocalAddr().toText());
+    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
     // The response should be sent from the DHCPv4 server port.
     // The response should be sent from the DHCPv4 server port.
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     // The interface data should match the data in the query.
     // The interface data should match the data in the query.
-    EXPECT_EQ("eth0", resp->getIface());
+    EXPECT_EQ("eth1", resp->getIface());
     EXPECT_EQ(1, resp->getIndex());
     EXPECT_EQ(1, resp->getIndex());
 
 
 }
 }
@@ -191,7 +198,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataRenew) {
 // of the response should be set to yiaddr if server supports direct responses
 // of the response should be set to yiaddr if server supports direct responses
 // to the client which doesn't have an address yet or broadcast if the server
 // to the client which doesn't have an address yet or broadcast if the server
 // doesn't support direct responses.
 // doesn't support direct responses.
-TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
+TEST_F(Dhcpv4SrvTest, adjustIfaceDataSelect) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     // Create instance of the incoming packet.
     // Create instance of the incoming packet.
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
 
 
@@ -210,7 +220,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
     // The query has been received on the DHCPv4 server port 67.
     // The query has been received on the DHCPv4 server port 67.
     req->setLocalPort(DHCP4_SERVER_PORT);
     req->setLocalPort(DHCP4_SERVER_PORT);
     // Set the interface. The response should be sent via the same interface.
     // Set the interface. The response should be sent via the same interface.
-    req->setIface("eth0");
+    req->setIface("eth1");
     req->setIndex(1);
     req->setIndex(1);
 
 
     // Create a response.
     // Create a response.
@@ -227,7 +237,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
     // case, the server should send its response to the broadcast address.
     // case, the server should send its response to the broadcast address.
     // We can control whether the current packet filter returns that its support
     // We can control whether the current packet filter returns that its support
     // direct responses or not.
     // direct responses or not.
-    current_pkt_filter_->direct_resp_supported_ = false;
+    test_config.setDirectResponse(false);
 
 
     // When running unit tests, the IfaceMgr is using the default Packet
     // When running unit tests, the IfaceMgr is using the default Packet
     // Filtering class, PktFilterInet. This class does not support direct
     // Filtering class, PktFilterInet. This class does not support direct
@@ -244,14 +254,14 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
     // Although the query has been sent to the broadcast address, the
     // Although the query has been sent to the broadcast address, the
     // server should select a unicast address on the particular interface
     // server should select a unicast address on the particular interface
     // as a source address for the response.
     // as a source address for the response.
-    EXPECT_EQ("192.0.2.1", resp->getLocalAddr().toText());
+    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
 
 
     // The response should be sent from the DHCPv4 server port.
     // The response should be sent from the DHCPv4 server port.
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
 
 
     // The response should be sent via the same interface through which
     // The response should be sent via the same interface through which
     // query has been received.
     // query has been received.
-    EXPECT_EQ("eth0", resp->getIface());
+    EXPECT_EQ("eth1", resp->getIface());
     EXPECT_EQ(1, resp->getIndex());
     EXPECT_EQ(1, resp->getIndex());
 
 
     // We also want to test the case when the server has capability to
     // We also want to test the case when the server has capability to
@@ -260,7 +270,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
     // response based on the capability reported by IfaceMgr. We can
     // response based on the capability reported by IfaceMgr. We can
     // control whether the current packet filter returns that it supports
     // control whether the current packet filter returns that it supports
     // direct responses or not.
     // direct responses or not.
-    current_pkt_filter_->direct_resp_supported_ = true;
+    test_config.setDirectResponse(true);
 
 
     // Now we expect that the server will send its response to the
     // Now we expect that the server will send its response to the
     // address assigned for the client.
     // address assigned for the client.
@@ -274,7 +284,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataSelect) {
 // query. Client sets this flag to indicate that it can't receive direct
 // query. Client sets this flag to indicate that it can't receive direct
 // responses from the server when it doesn't have its interface configured.
 // responses from the server when it doesn't have its interface configured.
 // Server must respect broadcast flag.
 // Server must respect broadcast flag.
-TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataBroadcast) {
+TEST_F(Dhcpv4SrvTest, adjustIfaceDataBroadcast) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     // Create instance of the incoming packet.
     // Create instance of the incoming packet.
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
 
 
@@ -287,7 +300,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataBroadcast) {
     // The query has been received on the DHCPv4 server port 67.
     // The query has been received on the DHCPv4 server port 67.
     req->setLocalPort(DHCP4_SERVER_PORT);
     req->setLocalPort(DHCP4_SERVER_PORT);
     // Set the interface. The response should be sent via the same interface.
     // Set the interface. The response should be sent via the same interface.
-    req->setIface("eth0");
+    req->setIface("eth1");
     req->setIndex(1);
     req->setIndex(1);
 
 
     // Let's set the broadcast flag.
     // Let's set the broadcast flag.
@@ -310,21 +323,21 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataBroadcast) {
     // Although the query has been sent to the broadcast address, the
     // Although the query has been sent to the broadcast address, the
     // server should select a unicast address on the particular interface
     // server should select a unicast address on the particular interface
     // as a source address for the response.
     // as a source address for the response.
-    EXPECT_EQ("192.0.2.1", resp->getLocalAddr().toText());
+    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
 
 
     // The response should be sent from the DHCPv4 server port.
     // The response should be sent from the DHCPv4 server port.
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
     EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
 
 
     // The response should be sent via the same interface through which
     // The response should be sent via the same interface through which
     // query has been received.
     // query has been received.
-    EXPECT_EQ("eth0", resp->getIface());
+    EXPECT_EQ("eth1", resp->getIface());
     EXPECT_EQ(1, resp->getIndex());
     EXPECT_EQ(1, resp->getIndex());
 
 
 }
 }
 
 
 // This test verifies that exception is thrown of the invalid combination
 // This test verifies that exception is thrown of the invalid combination
 // of giaddr and hops is specified in a client's message.
 // of giaddr and hops is specified in a client's message.
-TEST_F(Dhcpv4SrvFakeIfaceTest, adjustIfaceDataInvalid) {
+TEST_F(Dhcpv4SrvTest, adjustIfaceDataInvalid) {
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
     boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
 
 
     // The hops and giaddr values are used to determine if the client's
     // The hops and giaddr values are used to determine if the client's
@@ -435,7 +448,7 @@ TEST_F(Dhcpv4SrvTest, openActiveSockets) {
 // are other tests that verify correctness of the allocation
 // are other tests that verify correctness of the allocation
 // engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
 // engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
 // and DiscoverInvalidHint.
 // and DiscoverInvalidHint.
-TEST_F(Dhcpv4SrvFakeIfaceTest, processDiscover) {
+TEST_F(Dhcpv4SrvTest, processDiscover) {
     testDiscoverRequest(DHCPDISCOVER);
     testDiscoverRequest(DHCPDISCOVER);
 }
 }
 
 
@@ -447,11 +460,11 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, processDiscover) {
 // are other tests that verify correctness of the allocation
 // are other tests that verify correctness of the allocation
 // engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
 // engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
 // and DiscoverInvalidHint.
 // and DiscoverInvalidHint.
-TEST_F(Dhcpv4SrvFakeIfaceTest, processRequest) {
+TEST_F(Dhcpv4SrvTest, processRequest) {
     testDiscoverRequest(DHCPREQUEST);
     testDiscoverRequest(DHCPREQUEST);
 }
 }
 
 
-TEST_F(Dhcpv4SrvFakeIfaceTest, processRelease) {
+TEST_F(Dhcpv4SrvTest, processRelease) {
     NakedDhcpv4Srv srv;
     NakedDhcpv4Srv srv;
     Pkt4Ptr pkt(new Pkt4(DHCPRELEASE, 1234));
     Pkt4Ptr pkt(new Pkt4(DHCPRELEASE, 1234));
 
 
@@ -459,7 +472,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, processRelease) {
     EXPECT_NO_THROW(srv.processRelease(pkt));
     EXPECT_NO_THROW(srv.processRelease(pkt));
 }
 }
 
 
-TEST_F(Dhcpv4SrvFakeIfaceTest, processDecline) {
+TEST_F(Dhcpv4SrvTest, processDecline) {
     NakedDhcpv4Srv srv;
     NakedDhcpv4Srv srv;
     Pkt4Ptr pkt(new Pkt4(DHCPDECLINE, 1234));
     Pkt4Ptr pkt(new Pkt4(DHCPDECLINE, 1234));
 
 
@@ -467,7 +480,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, processDecline) {
     EXPECT_NO_THROW(srv.processDecline(pkt));
     EXPECT_NO_THROW(srv.processDecline(pkt));
 }
 }
 
 
-TEST_F(Dhcpv4SrvFakeIfaceTest, processInform) {
+TEST_F(Dhcpv4SrvTest, processInform) {
     NakedDhcpv4Srv srv;
     NakedDhcpv4Srv srv;
     Pkt4Ptr pkt(new Pkt4(DHCPINFORM, 1234));
     Pkt4Ptr pkt(new Pkt4(DHCPINFORM, 1234));
 
 
@@ -524,7 +537,10 @@ TEST_F(Dhcpv4SrvTest, serverReceivedPacketName) {
 // - copy of client-id
 // - copy of client-id
 // - server-id
 // - server-id
 // - offered address
 // - offered address
-TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverBasic) {
+TEST_F(Dhcpv4SrvTest, DiscoverBasic) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -532,7 +548,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverBasic) {
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv->processDiscover(dis);
     Pkt4Ptr offer = srv->processDiscover(dis);
@@ -562,7 +578,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverBasic) {
 // - copy of client-id
 // - copy of client-id
 // - server-id
 // - server-id
 // - offered address
 // - offered address
-TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverHint) {
+TEST_F(Dhcpv4SrvTest, DiscoverHint) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     IOAddress hint("192.0.2.107");
     IOAddress hint("192.0.2.107");
@@ -572,7 +591,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverHint) {
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
     dis->setYiaddr(hint);
     dis->setYiaddr(hint);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv->processDiscover(dis);
     Pkt4Ptr offer = srv->processDiscover(dis);
@@ -603,7 +622,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverHint) {
 // - copy of client-id
 // - copy of client-id
 // - server-id
 // - server-id
 // - offered address
 // - offered address
-TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverNoClientId) {
+TEST_F(Dhcpv4SrvTest, DiscoverNoClientId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     IOAddress hint("192.0.2.107");
     IOAddress hint("192.0.2.107");
@@ -612,7 +634,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverNoClientId) {
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setYiaddr(hint);
     dis->setYiaddr(hint);
     dis->setHWAddr(generateHWAddr(6));
     dis->setHWAddr(generateHWAddr(6));
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv->processDiscover(dis);
     Pkt4Ptr offer = srv->processDiscover(dis);
@@ -642,7 +664,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverNoClientId) {
 // - copy of client-id
 // - copy of client-id
 // - server-id
 // - server-id
 // - offered address (!= hint)
 // - offered address (!= hint)
-TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverInvalidHint) {
+TEST_F(Dhcpv4SrvTest, DiscoverInvalidHint) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     IOAddress hint("10.1.2.3");
     IOAddress hint("10.1.2.3");
@@ -652,7 +677,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverInvalidHint) {
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
     dis->setYiaddr(hint);
     dis->setYiaddr(hint);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv->processDiscover(dis);
     Pkt4Ptr offer = srv->processDiscover(dis);
@@ -681,7 +706,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, DiscoverInvalidHint) {
 // and this is a correct behavior. It is REQUEST that will fail for the third
 // and this is a correct behavior. It is REQUEST that will fail for the third
 // client. OFFER is basically saying "if you send me a request, you will
 // client. OFFER is basically saying "if you send me a request, you will
 // probably get an address like this" (there are no guarantees).
 // probably get an address like this" (there are no guarantees).
-TEST_F(Dhcpv4SrvFakeIfaceTest, ManyDiscovers) {
+TEST_F(Dhcpv4SrvTest, ManyDiscovers) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -694,9 +722,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ManyDiscovers) {
     dis3->setRemoteAddr(IOAddress("192.0.2.3"));
     dis3->setRemoteAddr(IOAddress("192.0.2.3"));
 
 
     // Assign interfaces
     // Assign interfaces
-    dis1->setIface("eth0");
-    dis2->setIface("eth0");
-    dis3->setIface("eth0");
+    dis1->setIface("eth1");
+    dis2->setIface("eth1");
+    dis3->setIface("eth1");
 
 
     // Different client-id sizes
     // Different client-id sizes
     OptionPtr clientid1 = generateClientId(4); // length 4
     OptionPtr clientid1 = generateClientId(4); // length 4
@@ -746,14 +774,17 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ManyDiscovers) {
 // Checks whether echoing back client-id is controllable, i.e.
 // Checks whether echoing back client-id is controllable, i.e.
 // whether the server obeys echo-client-id and sends (or not)
 // whether the server obeys echo-client-id and sends (or not)
 // client-id
 // client-id
-TEST_F(Dhcpv4SrvFakeIfaceTest, discoverEchoClientId) {
+TEST_F(Dhcpv4SrvTest, discoverEchoClientId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv.processDiscover(dis);
     Pkt4Ptr offer = srv.processDiscover(dis);
@@ -785,7 +816,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, discoverEchoClientId) {
 // - assigned address
 // - assigned address
 //
 //
 // Test verifies that the lease is actually in the database.
 // Test verifies that the lease is actually in the database.
-TEST_F(Dhcpv4SrvFakeIfaceTest, RequestBasic) {
+TEST_F(Dhcpv4SrvTest, RequestBasic) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -795,7 +829,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, RequestBasic) {
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     req->addOption(clientid);
     req->addOption(clientid);
     req->setYiaddr(hint);
     req->setYiaddr(hint);
-    req->setIface("eth0");
+    req->setIface("eth1");
 
 
     // Pass it to the server and get an advertise
     // Pass it to the server and get an advertise
     Pkt4Ptr ack = srv->processRequest(req);
     Pkt4Ptr ack = srv->processRequest(req);
@@ -831,7 +865,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, RequestBasic) {
 // - copy of client-id
 // - copy of client-id
 // - server-id
 // - server-id
 // - assigned address (different for each client)
 // - assigned address (different for each client)
-TEST_F(Dhcpv4SrvFakeIfaceTest, ManyRequests) {
+TEST_F(Dhcpv4SrvTest, ManyRequests) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
@@ -850,9 +886,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ManyRequests) {
     req3->setRemoteAddr(relay);
     req3->setRemoteAddr(relay);
 
 
     // Assign interfaces
     // Assign interfaces
-    req1->setIface("eth0");
-    req2->setIface("eth0");
-    req3->setIface("eth0");
+    req1->setIface("eth1");
+    req2->setIface("eth1");
+    req3->setIface("eth1");
 
 
     req1->setYiaddr(req_addr1);
     req1->setYiaddr(req_addr1);
     req2->setYiaddr(req_addr2);
     req2->setYiaddr(req_addr2);
@@ -919,14 +955,17 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ManyRequests) {
 }
 }
 
 
 // Checks whether echoing back client-id is controllable
 // Checks whether echoing back client-id is controllable
-TEST_F(Dhcpv4SrvFakeIfaceTest, requestEchoClientId) {
+TEST_F(Dhcpv4SrvTest, requestEchoClientId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get ACK
     // Pass it to the server and get ACK
     Pkt4Ptr ack = srv.processRequest(dis);
     Pkt4Ptr ack = srv.processRequest(dis);
@@ -953,7 +992,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, requestEchoClientId) {
 // - returned REPLY message has server-id
 // - returned REPLY message has server-id
 // - returned REPLY message has IA that includes IAADDR
 // - returned REPLY message has IA that includes IAADDR
 // - lease is actually renewed in LeaseMgr
 // - lease is actually renewed in LeaseMgr
-TEST_F(Dhcpv4SrvFakeIfaceTest, RenewBasic) {
+TEST_F(Dhcpv4SrvTest, RenewBasic) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -1038,7 +1080,10 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, RenewBasic) {
 // identifiers used by a server is accepted,
 // identifiers used by a server is accepted,
 // - a message with a server identifier which doesn't match any server
 // - a message with a server identifier which doesn't match any server
 // identifier used by a server, is not accepted.
 // identifier used by a server, is not accepted.
-TEST_F(Dhcpv4SrvFakeIfaceTest, acceptServerId) {
+TEST_F(Dhcpv4SrvTest, acceptServerId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
     Pkt4Ptr pkt(new Pkt4(DHCPREQUEST, 1234));
     Pkt4Ptr pkt(new Pkt4(DHCPREQUEST, 1234));
@@ -1065,7 +1110,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, acceptServerId) {
     // Add a server id being an IPv4 address configured on eth0 interface.
     // Add a server id being an IPv4 address configured on eth0 interface.
     // A DHCPv4 message holding this server identifier should be accepted.
     // A DHCPv4 message holding this server identifier should be accepted.
     OptionCustomPtr eth0_serverid(new OptionCustom(def, Option::V6));
     OptionCustomPtr eth0_serverid(new OptionCustom(def, Option::V6));
-    eth0_serverid->writeAddress(IOAddress("192.0.2.1"));
+    eth0_serverid->writeAddress(IOAddress("192.0.2.3"));
     ASSERT_NO_THROW(pkt->addOption(eth0_serverid));
     ASSERT_NO_THROW(pkt->addOption(eth0_serverid));
     EXPECT_TRUE(srv.acceptServerId(pkt));
     EXPECT_TRUE(srv.acceptServerId(pkt));
 
 
@@ -1117,7 +1162,7 @@ TEST_F(Dhcpv4SrvTest, sanityCheck) {
 // This test verifies that incoming (positive) RELEASE can be handled properly.
 // This test verifies that incoming (positive) RELEASE can be handled properly.
 // As there is no REPLY in DHCPv4, the only thing to verify here is that
 // As there is no REPLY in DHCPv4, the only thing to verify here is that
 // the lease is indeed removed from the database.
 // the lease is indeed removed from the database.
-TEST_F(Dhcpv4SrvFakeIfaceTest, ReleaseBasic) {
+TEST_F(Dhcpv4SrvTest, ReleaseBasic) {
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -1189,7 +1234,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ReleaseBasic) {
 // 1. there is no such lease at all
 // 1. there is no such lease at all
 // 2. there is such a lease, but it is assigned to a different IAID
 // 2. there is such a lease, but it is assigned to a different IAID
 // 3. there is such a lease, but it belongs to a different client
 // 3. there is such a lease, but it belongs to a different client
-TEST_F(Dhcpv4SrvFakeIfaceTest, ReleaseReject) {
+TEST_F(Dhcpv4SrvTest, ReleaseReject) {
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
 
 
@@ -1278,7 +1323,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, ReleaseReject) {
 }
 }
 
 
 // Checks if received relay agent info option is echoed back to the client
 // Checks if received relay agent info option is echoed back to the client
-TEST_F(Dhcpv4SrvFakeIfaceTest, relayAgentInfoEcho) {
+TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
@@ -1321,7 +1368,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, relayAgentInfoEcho) {
 
 
 // Checks if vendor options are parsed correctly and requested vendor options
 // Checks if vendor options are parsed correctly and requested vendor options
 // are echoed back.
 // are echoed back.
-TEST_F(Dhcpv4SrvFakeIfaceTest, vendorOptionsDocsis) {
+TEST_F(Dhcpv4SrvTest, vendorOptionsDocsis) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
@@ -1515,7 +1564,10 @@ TEST_F(Dhcpv4SrvTest, unpackOptions) {
 
 
 // Checks whether the server uses default (0.0.0.0) siaddr value, unless
 // Checks whether the server uses default (0.0.0.0) siaddr value, unless
 // explicitly specified
 // explicitly specified
-TEST_F(Dhcpv4SrvFakeIfaceTest, siaddrDefault) {
+TEST_F(Dhcpv4SrvTest, siaddrDefault) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     IOAddress hint("192.0.2.107");
     IOAddress hint("192.0.2.107");
@@ -1525,7 +1577,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, siaddrDefault) {
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
     dis->setYiaddr(hint);
     dis->setYiaddr(hint);
-    dis->setIface("eth0");
+    dis->setIface("eth1");
 
 
     // Pass it to the server and get an offer
     // Pass it to the server and get an offer
     Pkt4Ptr offer = srv->processDiscover(dis);
     Pkt4Ptr offer = srv->processDiscover(dis);
@@ -1539,14 +1591,17 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, siaddrDefault) {
 }
 }
 
 
 // Checks whether the server uses specified siaddr value
 // Checks whether the server uses specified siaddr value
-TEST_F(Dhcpv4SrvFakeIfaceTest, siaddr) {
+TEST_F(Dhcpv4SrvTest, siaddr) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     boost::scoped_ptr<NakedDhcpv4Srv> srv;
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
     subnet_->setSiaddr(IOAddress("192.0.2.123"));
     subnet_->setSiaddr(IOAddress("192.0.2.123"));
 
 
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
-    dis->setIface("eth0");
+    dis->setIface("eth1");
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
 
 
@@ -1565,7 +1620,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, siaddr) {
 // specific value and returned in server messages. There's also similar test for
 // specific value and returned in server messages. There's also similar test for
 // checking parser only configuration, see Dhcp4ParserTest.nextServerOverride in
 // checking parser only configuration, see Dhcp4ParserTest.nextServerOverride in
 // config_parser_unittest.cc.
 // config_parser_unittest.cc.
-TEST_F(Dhcpv4SrvFakeIfaceTest, nextServerOverride) {
+TEST_F(Dhcpv4SrvTest, nextServerOverride) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
@@ -1592,7 +1649,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, nextServerOverride) {
 
 
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
-    dis->setIface("eth0");
+    dis->setIface("eth1");
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
 
 
@@ -1608,7 +1665,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, nextServerOverride) {
 // when there is no specific value defined in subnet and returned to the client
 // when there is no specific value defined in subnet and returned to the client
 // properly. There's also similar test for checking parser only configuration,
 // properly. There's also similar test for checking parser only configuration,
 // see Dhcp4ParserTest.nextServerGlobal in config_parser_unittest.cc.
 // see Dhcp4ParserTest.nextServerGlobal in config_parser_unittest.cc.
-TEST_F(Dhcpv4SrvFakeIfaceTest, nextServerGlobal) {
+TEST_F(Dhcpv4SrvTest, nextServerGlobal) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
@@ -1634,7 +1693,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, nextServerGlobal) {
 
 
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
     dis->setRemoteAddr(IOAddress("192.0.2.1"));
-    dis->setIface("eth0");
+    dis->setIface("eth1");
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     dis->addOption(clientid);
     dis->addOption(clientid);
 
 
@@ -1671,7 +1730,7 @@ const uint8_t dummySname[] = "Lorem ipsum dolor sit amet, consectetur "
 /// can't modify non-static members (for obvious reasons), so many
 /// can't modify non-static members (for obvious reasons), so many
 /// fields are declared static. It is still better to keep them as
 /// fields are declared static. It is still better to keep them as
 /// one class rather than unrelated collection of global objects.
 /// one class rather than unrelated collection of global objects.
-class HooksDhcpv4SrvTest : public Dhcpv4SrvFakeIfaceTest {
+class HooksDhcpv4SrvTest : public Dhcpv4SrvTest {
 
 
 public:
 public:
 
 
@@ -1771,7 +1830,7 @@ public:
         // name to select a subnet for a client. This test is using fake interfaces
         // name to select a subnet for a client. This test is using fake interfaces
         // and the fake eth0 interface has IPv4 address matching the subnet
         // and the fake eth0 interface has IPv4 address matching the subnet
         // currently configured for this test.
         // currently configured for this test.
-        dis->setIface("eth0");
+        dis->setIface("eth1");
         return (dis);
         return (dis);
     }
     }
 
 
@@ -2132,6 +2191,8 @@ vector<string> HooksDhcpv4SrvTest::callback_argument_names_;
 // Note that the test name does not follow test naming convention,
 // Note that the test name does not follow test naming convention,
 // but the proper hook name is "buffer4_receive".
 // but the proper hook name is "buffer4_receive".
 TEST_F(HooksDhcpv4SrvTest, Buffer4ReceiveSimple) {
 TEST_F(HooksDhcpv4SrvTest, Buffer4ReceiveSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2165,6 +2226,9 @@ TEST_F(HooksDhcpv4SrvTest, Buffer4ReceiveSimple) {
 // Checks if callouts installed on buffer4_receive is able to change
 // Checks if callouts installed on buffer4_receive is able to change
 // the values and the parameters are indeed used by the server.
 // the values and the parameters are indeed used by the server.
 TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveValueChange) {
 TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveValueChange) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
 
 
     // Install callback that modifies MAC addr of incoming packet
     // Install callback that modifies MAC addr of incoming packet
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2204,6 +2268,8 @@ TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveValueChange) {
 // the server should eventually drop it, because there won't be mandatory options
 // the server should eventually drop it, because there won't be mandatory options
 // (or rather option objects) in it.
 // (or rather option objects) in it.
 TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveSkip) {
 TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveSkip) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2231,6 +2297,8 @@ TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveSkip) {
 // Note that the test name does not follow test naming convention,
 // Note that the test name does not follow test naming convention,
 // but the proper hook name is "pkt4_receive".
 // but the proper hook name is "pkt4_receive".
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSimple) {
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2264,6 +2332,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSimple) {
 // Checks if callouts installed on pkt4_received is able to change
 // Checks if callouts installed on pkt4_received is able to change
 // the values and the parameters are indeed used by the server.
 // the values and the parameters are indeed used by the server.
 TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) {
 TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2300,6 +2370,8 @@ TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) {
 // existing options and that change impacts server processing (mandatory
 // existing options and that change impacts server processing (mandatory
 // client-id option is deleted, so the packet is expected to be dropped)
 // client-id option is deleted, so the packet is expected to be dropped)
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDeleteClientId) {
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDeleteClientId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2324,6 +2396,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDeleteClientId) {
 // Checks if callouts installed on pkt4_received is able to set skip flag that
 // Checks if callouts installed on pkt4_received is able to set skip flag that
 // will cause the server to not process the packet (drop), even though it is valid.
 // will cause the server to not process the packet (drop), even though it is valid.
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSkip) {
 TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSkip) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2349,6 +2423,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSkip) {
 // Checks if callouts installed on pkt4_send are indeed called and the
 // Checks if callouts installed on pkt4_send are indeed called and the
 // all necessary parameters are passed.
 // all necessary parameters are passed.
 TEST_F(HooksDhcpv4SrvTest, pkt4SendSimple) {
 TEST_F(HooksDhcpv4SrvTest, pkt4SendSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2385,6 +2461,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendSimple) {
 // Checks if callouts installed on pkt4_send is able to change
 // Checks if callouts installed on pkt4_send is able to change
 // the values and the packet sent contains those changes
 // the values and the packet sent contains those changes
 TEST_F(HooksDhcpv4SrvTest, pkt4SendValueChange) {
 TEST_F(HooksDhcpv4SrvTest, pkt4SendValueChange) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2422,6 +2500,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendValueChange) {
 // we are trying to send a packet without server-id. The packet should
 // we are trying to send a packet without server-id. The packet should
 // be sent
 // be sent
 TEST_F(HooksDhcpv4SrvTest, pkt4SendDeleteServerId) {
 TEST_F(HooksDhcpv4SrvTest, pkt4SendDeleteServerId) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2453,6 +2533,8 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendDeleteServerId) {
 // Checks if callouts installed on pkt4_skip is able to set skip flag that
 // Checks if callouts installed on pkt4_skip is able to set skip flag that
 // will cause the server to not process the packet (drop), even though it is valid.
 // will cause the server to not process the packet (drop), even though it is valid.
 TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) {
 TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2482,6 +2564,8 @@ TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) {
 // Checks if callouts installed on buffer4_send are indeed called and the
 // Checks if callouts installed on buffer4_send are indeed called and the
 // all necessary parameters are passed.
 // all necessary parameters are passed.
 TEST_F(HooksDhcpv4SrvTest, buffer4SendSimple) {
 TEST_F(HooksDhcpv4SrvTest, buffer4SendSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2518,6 +2602,8 @@ TEST_F(HooksDhcpv4SrvTest, buffer4SendSimple) {
 // Checks if callouts installed on buffer4_send are indeed called and that
 // Checks if callouts installed on buffer4_send are indeed called and that
 // the output buffer can be changed.
 // the output buffer can be changed.
 TEST_F(HooksDhcpv4SrvTest, buffer4Send) {
 TEST_F(HooksDhcpv4SrvTest, buffer4Send) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2547,6 +2633,8 @@ TEST_F(HooksDhcpv4SrvTest, buffer4Send) {
 // Checks if callouts installed on buffer4_send can set skip flag and that flag
 // Checks if callouts installed on buffer4_send can set skip flag and that flag
 // causes the packet to not be sent
 // causes the packet to not be sent
 TEST_F(HooksDhcpv4SrvTest, buffer4SendSkip) {
 TEST_F(HooksDhcpv4SrvTest, buffer4SendSkip) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2572,6 +2660,8 @@ TEST_F(HooksDhcpv4SrvTest, buffer4SendSkip) {
 // This test checks if subnet4_select callout is triggered and reports
 // This test checks if subnet4_select callout is triggered and reports
 // valid parameters
 // valid parameters
 TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
 TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install pkt4_receive_callout
     // Install pkt4_receive_callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2604,7 +2694,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
     // Prepare discover packet. Server should select first subnet for it
     // Prepare discover packet. Server should select first subnet for it
     Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
     sol->setRemoteAddr(IOAddress("192.0.2.1"));
     sol->setRemoteAddr(IOAddress("192.0.2.1"));
-    sol->setIface("eth0");
+    sol->setIface("eth1");
     OptionPtr clientid = generateClientId();
     OptionPtr clientid = generateClientId();
     sol->addOption(clientid);
     sol->addOption(clientid);
 
 
@@ -2638,6 +2728,8 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
 // This test checks if callout installed on subnet4_select hook point can pick
 // This test checks if callout installed on subnet4_select hook point can pick
 // a different subnet.
 // a different subnet.
 TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
 TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     // Install a callout
     // Install a callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2698,6 +2790,8 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
 // properly and that callout installed on lease4_renew is triggered with
 // properly and that callout installed on lease4_renew is triggered with
 // expected parameters.
 // expected parameters.
 TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
 TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     const IOAddress addr("192.0.2.106");
     const IOAddress addr("192.0.2.106");
     const uint32_t temp_t1 = 50;
     const uint32_t temp_t1 = 50;
@@ -2783,6 +2877,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
 // This test verifies that a callout installed on lease4_renew can trigger
 // This test verifies that a callout installed on lease4_renew can trigger
 // the server to not renew a lease.
 // the server to not renew a lease.
 TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
 TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     const IOAddress addr("192.0.2.106");
     const IOAddress addr("192.0.2.106");
     const uint32_t temp_t1 = 50;
     const uint32_t temp_t1 = 50;
@@ -2848,6 +2944,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
 
 
 // This test verifies that valid RELEASE triggers lease4_release callouts
 // This test verifies that valid RELEASE triggers lease4_release callouts
 TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) {
 TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     const IOAddress addr("192.0.2.106");
     const IOAddress addr("192.0.2.106");
     const uint32_t temp_t1 = 50;
     const uint32_t temp_t1 = 50;
@@ -2933,6 +3031,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) {
 // This test verifies that skip flag returned by a callout installed on the
 // This test verifies that skip flag returned by a callout installed on the
 // lease4_release hook point will keep the lease
 // lease4_release hook point will keep the lease
 TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) {
 TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     const IOAddress addr("192.0.2.106");
     const IOAddress addr("192.0.2.106");
     const uint32_t temp_t1 = 50;
     const uint32_t temp_t1 = 50;
@@ -2996,7 +3096,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) {
 }
 }
 
 
 // Checks if server is able to handle a relayed traffic from DOCSIS3.0 modems
 // Checks if server is able to handle a relayed traffic from DOCSIS3.0 modems
-TEST_F(Dhcpv4SrvFakeIfaceTest, docsisVendorOptionsParse) {
+TEST_F(Dhcpv4SrvTest, docsisVendorOptionsParse) {
 
 
     // Let's get a traffic capture from DOCSIS3.0 modem
     // Let's get a traffic capture from DOCSIS3.0 modem
     Pkt4Ptr dis = captureRelayedDiscover();
     Pkt4Ptr dis = captureRelayedDiscover();
@@ -3020,7 +3120,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, docsisVendorOptionsParse) {
 }
 }
 
 
 // Checks if server is able to parse incoming docsis option and extract suboption 1 (docsis ORO)
 // Checks if server is able to parse incoming docsis option and extract suboption 1 (docsis ORO)
-TEST_F(Dhcpv4SrvFakeIfaceTest, docsisVendorORO) {
+TEST_F(Dhcpv4SrvTest, docsisVendorORO) {
 
 
     // Let's get a traffic capture from DOCSIS3.0 modem
     // Let's get a traffic capture from DOCSIS3.0 modem
     Pkt4Ptr dis = captureRelayedDiscover();
     Pkt4Ptr dis = captureRelayedDiscover();
@@ -3042,7 +3142,9 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, docsisVendorORO) {
 
 
 // This test checks if Option Request Option (ORO) in docsis (vendor-id=4491)
 // This test checks if Option Request Option (ORO) in docsis (vendor-id=4491)
 // vendor options is parsed correctly and the requested options are actually assigned.
 // vendor options is parsed correctly and the requested options are actually assigned.
-TEST_F(Dhcpv4SrvFakeIfaceTest, vendorOptionsORO) {
+TEST_F(Dhcpv4SrvTest, vendorOptionsORO) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
     NakedDhcpv4Srv srv(0);
     NakedDhcpv4Srv srv(0);
 
 
@@ -3130,7 +3232,7 @@ TEST_F(Dhcpv4SrvFakeIfaceTest, vendorOptionsORO) {
 
 
 // Test checks whether it is possible to use option definitions defined in
 // Test checks whether it is possible to use option definitions defined in
 // src/lib/dhcp/docsis3_option_defs.h.
 // src/lib/dhcp/docsis3_option_defs.h.
-TEST_F(Dhcpv4SrvFakeIfaceTest, vendorOptionsDocsisDefinitions) {
+TEST_F(Dhcpv4SrvTest, vendorOptionsDocsisDefinitions) {
     ConstElementPtr x;
     ConstElementPtr x;
     string config_prefix = "{ \"interfaces\": [ \"all\" ],"
     string config_prefix = "{ \"interfaces\": [ \"all\" ],"
         "\"rebind-timer\": 2000, "
         "\"rebind-timer\": 2000, "

+ 4 - 50
src/bin/dhcp4/tests/dhcp4_test_utils.cc

@@ -21,6 +21,7 @@
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/iface_mgr.h>
+#include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr.h>
@@ -404,58 +405,11 @@ void Dhcpv4SrvTest::TearDown() {
 
 
 }
 }
 
 
-Dhcpv4SrvFakeIfaceTest::Dhcpv4SrvFakeIfaceTest()
-: Dhcpv4SrvTest(), current_pkt_filter_() {
-    // Remove current interface configuration. Instead we want to add
-    // a couple of fake interfaces.
-    IfaceMgr& ifacemgr = IfaceMgr::instance();
-    ifacemgr.closeSockets();
-    ifacemgr.clearIfaces();
-
-    // Add fake interfaces.
-    ifacemgr.addInterface(createIface("lo", 0, "127.0.0.1"));
-    ifacemgr.addInterface(createIface("eth0", 1, "192.0.2.1"));
-    ifacemgr.addInterface(createIface("eth1", 2, "10.0.0.1"));
-
-    // In order to use fake interfaces we have to supply the custom
-    // packet filtering class, which can mimic opening sockets on
-    // fake interafaces.
-    current_pkt_filter_.reset(new PktFilterTest());
-    ifacemgr.setPacketFilter(current_pkt_filter_);
-    ifacemgr.openSockets4();
-}
-
 void
 void
-Dhcpv4SrvFakeIfaceTest::TearDown() {
-    // The base class function restores the original packet filtering class.
-    Dhcpv4SrvTest::TearDown();
-    // The base class however, doesn't re-detect real interfaces.
-    try {
-        IfaceMgr::instance().clearIfaces();
-        IfaceMgr::instance().detectIfaces();
+Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
 
-    } catch (const Exception& ex) {
-        FAIL() << "Failed to restore interface configuration after using"
-            " fake interfaces";
-    }
-}
-
-Iface
-Dhcpv4SrvFakeIfaceTest::createIface(const std::string& name, const int ifindex,
-                                    const std::string& addr) {
-    Iface iface(name, ifindex);
-    iface.addAddress(IOAddress(addr));
-    if (name == "lo") {
-        iface.flag_loopback_ = true;
-    }
-    iface.flag_up_ = true;
-    iface.flag_running_ = true;
-    iface.inactive4_ = false;
-    return (iface);
-}
-
-void
-Dhcpv4SrvFakeIfaceTest::testDiscoverRequest(const uint8_t msg_type) {
     // Create an instance of the tested class.
     // Create an instance of the tested class.
     boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
     boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
 
 

+ 14 - 57
src/bin/dhcp4/tests/dhcp4_test_utils.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
 // purpose with or without fee is hereby granted, provided that the above
@@ -267,6 +267,19 @@ public:
     /// @return created packet
     /// @return created packet
     Pkt4Ptr packetFromCapture(const std::string& hex_string);
     Pkt4Ptr packetFromCapture(const std::string& hex_string);
 
 
+    /// @brief Tests if Discover or Request message is processed correctly
+    ///
+    /// This test verifies that the Parameter Request List option is handled
+    /// correctly, i.e. it checks that certain options are present in the
+    /// server's response when they are requested and that they are not present
+    /// when they are not requested or NAK occurs.
+    ///
+    /// @todo We need an additional test for PRL option using real traffic
+    /// capture.
+    ///
+    /// @param msg_type DHCPDISCOVER or DHCPREQUEST
+    void testDiscoverRequest(const uint8_t msg_type);
+
     /// @brief This function cleans up after the test.
     /// @brief This function cleans up after the test.
     virtual void TearDown();
     virtual void TearDown();
 
 
@@ -285,62 +298,6 @@ public:
 
 
 };
 };
 
 
-/// @brief Test fixture class to be used for tests which require fake
-/// interfaces.
-///
-/// The DHCPv4 server must always append the server identifier to its response.
-/// The server identifier is typically an IP address assigned to the interface
-/// on which the query has been received. The DHCPv4 server uses IfaceMgr to
-/// check this address. In order to test this functionality, a set of interfaces
-/// must be known to the test. This test fixture class creates a set of well
-/// known (fake) interfaces which can be assigned to the test DHCPv4 messages
-/// so as the response (including server identifier) can be validated.
-/// The real interfaces are removed from the IfaceMgr in the constructor and
-/// they are re-assigned in the destructor.
-class Dhcpv4SrvFakeIfaceTest : public Dhcpv4SrvTest {
-public:
-    /// @brief Constructor.
-    ///
-    /// Creates a set of fake interfaces:
-    /// - lo, index: 0, address: 127.0.0.1
-    /// - eth0, index: 1, address: 192.0.3.1
-    /// - eth1, index: 2, address: 10.0.0.1
-    ///
-    /// These interfaces replace the real interfaces detected by the IfaceMgr.
-    Dhcpv4SrvFakeIfaceTest();
-
-    /// @brief Restores the original interface configuration.
-    virtual void TearDown();
-
-    /// @brief Creates an instance of the interface.
-    ///
-    /// @param name Name of the interface.
-    /// @param ifindex Index of the interface.
-    /// @param addr IP address assigned to the interface, represented as string.
-    ///
-    /// @return Iface Instance of the interface.
-    static Iface createIface(const std::string& name, const int ifindex,
-                             const std::string& addr);
-
-    /// @brief Tests if Discover or Request message is processed correctly
-    ///
-    /// This test verifies that the Parameter Request List option is handled
-    /// correctly, i.e. it checks that certain options are present in the
-    /// server's response when they are requested and that they are not present
-    /// when they are not requested or NAK occurs.
-    ///
-    /// @todo We need an additional test for PRL option using real traffic
-    /// capture.
-    ///
-    /// @param msg_type DHCPDISCOVER or DHCPREQUEST
-    void testDiscoverRequest(const uint8_t msg_type);
-
-    /// @brief Holds a pointer to the packet filter object currently used
-    /// by the IfaceMgr.
-    PktFilterTestPtr current_pkt_filter_;
-
-};
-
 /// @brief "Naked" DHCPv4 server, exposes internal fields
 /// @brief "Naked" DHCPv4 server, exposes internal fields
 class NakedDhcpv4Srv: public Dhcpv4Srv {
 class NakedDhcpv4Srv: public Dhcpv4Srv {
 public:
 public:

+ 26 - 7
src/bin/dhcp4/tests/fqdn_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
 // purpose with or without fee is hereby granted, provided that the above
@@ -16,6 +16,7 @@
 #include <asiolink/io_address.h>
 #include <asiolink/io_address.h>
 #include <dhcp/option4_client_fqdn.h>
 #include <dhcp/option4_client_fqdn.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_int_array.h>
+#include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp_ddns/ncr_msg.h>
 #include <dhcp_ddns/ncr_msg.h>
 
 
@@ -30,9 +31,9 @@ using namespace isc::dhcp_ddns;
 
 
 namespace {
 namespace {
 
 
-class NameDhcpv4SrvTest : public Dhcpv4SrvFakeIfaceTest {
+class NameDhcpv4SrvTest : public Dhcpv4SrvTest {
 public:
 public:
-    NameDhcpv4SrvTest() : Dhcpv4SrvFakeIfaceTest() {
+    NameDhcpv4SrvTest() : Dhcpv4SrvTest() {
         srv_ = new NakedDhcpv4Srv(0);
         srv_ = new NakedDhcpv4Srv(0);
     }
     }
     virtual ~NameDhcpv4SrvTest() {
     virtual ~NameDhcpv4SrvTest() {
@@ -110,7 +111,7 @@ public:
                                 const bool include_clientid = true) {
                                 const bool include_clientid = true) {
         Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(msg_type, 1234));
         Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(msg_type, 1234));
         pkt->setRemoteAddr(IOAddress("192.0.2.3"));
         pkt->setRemoteAddr(IOAddress("192.0.2.3"));
-        pkt->setIface("eth0");
+        pkt->setIface("eth1");
         // For DISCOVER we don't include server id, because client broadcasts
         // For DISCOVER we don't include server id, because client broadcasts
         // the message to all servers.
         // the message to all servers.
         if (msg_type != DHCPDISCOVER) {
         if (msg_type != DHCPDISCOVER) {
@@ -574,6 +575,9 @@ TEST_F(NameDhcpv4SrvTest, createNameChangeRequestsLeaseMismatch) {
 // Test that the OFFER message generated as a result of the DISCOVER message
 // Test that the OFFER message generated as a result of the DISCOVER message
 // processing will not result in generation of the NameChangeRequests.
 // processing will not result in generation of the NameChangeRequests.
 TEST_F(NameDhcpv4SrvTest, processDiscover) {
 TEST_F(NameDhcpv4SrvTest, processDiscover) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req = generatePktWithFqdn(DHCPDISCOVER, Option4ClientFqdn::FLAG_S |
     Pkt4Ptr req = generatePktWithFqdn(DHCPDISCOVER, Option4ClientFqdn::FLAG_S |
                                       Option4ClientFqdn::FLAG_E,
                                       Option4ClientFqdn::FLAG_E,
                                       "myhost.example.com.",
                                       "myhost.example.com.",
@@ -589,6 +593,9 @@ TEST_F(NameDhcpv4SrvTest, processDiscover) {
 // Test that server generates client's hostname from the IP address assigned
 // Test that server generates client's hostname from the IP address assigned
 // to it when DHCPv4 Client FQDN option specifies an empty domain-name.
 // to it when DHCPv4 Client FQDN option specifies an empty domain-name.
 TEST_F(NameDhcpv4SrvTest, processRequestFqdnEmptyDomainName) {
 TEST_F(NameDhcpv4SrvTest, processRequestFqdnEmptyDomainName) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
     Pkt4Ptr req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
                                       Option4ClientFqdn::FLAG_E,
                                       Option4ClientFqdn::FLAG_E,
                                       "", Option4ClientFqdn::PARTIAL, true);
                                       "", Option4ClientFqdn::PARTIAL, true);
@@ -614,10 +621,13 @@ TEST_F(NameDhcpv4SrvTest, processRequestFqdnEmptyDomainName) {
 // Test that server generates client's hostname from the IP address assigned
 // Test that server generates client's hostname from the IP address assigned
 // to it when Hostname option carries the top level domain-name.
 // to it when Hostname option carries the top level domain-name.
 TEST_F(NameDhcpv4SrvTest, processRequestEmptyHostname) {
 TEST_F(NameDhcpv4SrvTest, processRequestEmptyHostname) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req = generatePktWithHostname(DHCPREQUEST, ".");
     Pkt4Ptr req = generatePktWithHostname(DHCPREQUEST, ".");
     // Set interface for the incoming packet. The server requires it to
     // Set interface for the incoming packet. The server requires it to
     // generate client id.
     // generate client id.
-    req->setIface("eth0");
+    req->setIface("eth1");
 
 
     Pkt4Ptr reply;
     Pkt4Ptr reply;
     ASSERT_NO_THROW(reply = srv_->processRequest(req));
     ASSERT_NO_THROW(reply = srv_->processRequest(req));
@@ -640,6 +650,9 @@ TEST_F(NameDhcpv4SrvTest, processRequestEmptyHostname) {
 // request but modify the DNS entries for the lease according to the contents
 // request but modify the DNS entries for the lease according to the contents
 // of the FQDN sent in the second request.
 // of the FQDN sent in the second request.
 TEST_F(NameDhcpv4SrvTest, processTwoRequestsFqdn) {
 TEST_F(NameDhcpv4SrvTest, processTwoRequestsFqdn) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req1 = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
     Pkt4Ptr req1 = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
                                        Option4ClientFqdn::FLAG_E,
                                        Option4ClientFqdn::FLAG_E,
                                        "myhost.example.com.",
                                        "myhost.example.com.",
@@ -692,11 +705,14 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsFqdn) {
 // but modify the DNS entries for the lease according to the contents of the
 // but modify the DNS entries for the lease according to the contents of the
 // Hostname sent in the second request.
 // Hostname sent in the second request.
 TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) {
 TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req1 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com.");
     Pkt4Ptr req1 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com.");
 
 
     // Set interface for the incoming packet. The server requires it to
     // Set interface for the incoming packet. The server requires it to
     // generate client id.
     // generate client id.
-    req1->setIface("eth0");
+    req1->setIface("eth1");
 
 
 
 
     Pkt4Ptr reply;
     Pkt4Ptr reply;
@@ -719,7 +735,7 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) {
 
 
     // Set interface for the incoming packet. The server requires it to
     // Set interface for the incoming packet. The server requires it to
     // generate client id.
     // generate client id.
-    req2->setIface("eth0");
+    req2->setIface("eth1");
 
 
     ASSERT_NO_THROW(reply = srv_->processRequest(req2));
     ASSERT_NO_THROW(reply = srv_->processRequest(req2));
 
 
@@ -746,6 +762,9 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) {
 // lease, then server genenerates a NameChangeRequest to remove the entries
 // lease, then server genenerates a NameChangeRequest to remove the entries
 // corresponding to the lease being released.
 // corresponding to the lease being released.
 TEST_F(NameDhcpv4SrvTest, processRequestRelease) {
 TEST_F(NameDhcpv4SrvTest, processRequestRelease) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
     Pkt4Ptr req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
     Pkt4Ptr req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
                                       Option4ClientFqdn::FLAG_E,
                                       Option4ClientFqdn::FLAG_E,
                                       "myhost.example.com.",
                                       "myhost.example.com.",

+ 14 - 1
src/lib/dhcp/tests/iface_mgr_test_config.cc

@@ -26,7 +26,8 @@ namespace test {
 IfaceMgrTestConfig::IfaceMgrTestConfig(const bool default_config) {
 IfaceMgrTestConfig::IfaceMgrTestConfig(const bool default_config) {
     IfaceMgr::instance().closeSockets();
     IfaceMgr::instance().closeSockets();
     IfaceMgr::instance().clearIfaces();
     IfaceMgr::instance().clearIfaces();
-    IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterTestStub()));
+    packet_filter4_ = PktFilterPtr(new PktFilterTestStub());
+    IfaceMgr::instance().setPacketFilter(packet_filter4_);
 
 
     // Create default set of fake interfaces: lo, eth0 and eth1.
     // Create default set of fake interfaces: lo, eth0 and eth1.
     if (default_config) {
     if (default_config) {
@@ -102,6 +103,18 @@ IfaceMgrTestConfig::createIfaces() {
 }
 }
 
 
 void
 void
+IfaceMgrTestConfig::setDirectResponse(const bool direct_resp) {
+    boost::shared_ptr<PktFilterTestStub> stub =
+        boost::dynamic_pointer_cast<PktFilterTestStub>(getPacketFilter4());
+    if (!stub) {
+        isc_throw(isc::Unexpected, "unable to set direct response capability for"
+                  " test packet filter - current packet filter is not"
+                  " of a PktFilterTestStub");
+    }
+    stub->direct_response_supported_ = direct_resp;
+}
+
+void
 IfaceMgrTestConfig::setIfaceFlags(const std::string& name,
 IfaceMgrTestConfig::setIfaceFlags(const std::string& name,
                                   const FlagLoopback& loopback,
                                   const FlagLoopback& loopback,
                                   const FlagUp& up,
                                   const FlagUp& up,

+ 21 - 0
src/lib/dhcp/tests/iface_mgr_test_config.h

@@ -144,6 +144,23 @@ public:
     /// @brief Creates a default (example) set of fake interfaces.
     /// @brief Creates a default (example) set of fake interfaces.
     void createIfaces();
     void createIfaces();
 
 
+    /// @brief Returns currently used packet filter for DHCPv4.
+    PktFilterPtr getPacketFilter4() const {
+        return (packet_filter4_);
+    }
+
+    /// @brief Sets the direct response capability for current packet filter.
+    ///
+    /// The test uses stub implementation of packet filter object. It is
+    /// possible to configure that object to report having a capability
+    /// to directly repond to clients which don't have an address yet.
+    /// This function sets this property for packet filter object.
+    ///
+    /// @param direct_resp Value to be set.
+    ///
+    /// @throw isc::Unexpected if unable to set the property.
+    void setDirectResponse(const bool direct_resp);
+
     /// @brief Sets various flags on the specified interface.
     /// @brief Sets various flags on the specified interface.
     ///
     ///
     /// This function configures interface with new values for flags.
     /// This function configures interface with new values for flags.
@@ -162,6 +179,10 @@ public:
                        const FlagInactive4& inactive4,
                        const FlagInactive4& inactive4,
                        const FlagInactive6& inactive6);
                        const FlagInactive6& inactive6);
 
 
+private:
+    /// @brief Currently used packet filter for DHCPv4.
+    PktFilterPtr packet_filter4_;
+
 };
 };
 
 
 };
 };

+ 5 - 1
src/lib/dhcp/tests/pkt_filter_test_stub.cc

@@ -18,9 +18,13 @@ namespace isc {
 namespace dhcp {
 namespace dhcp {
 namespace test {
 namespace test {
 
 
+PktFilterTestStub::PktFilterTestStub()
+    : direct_response_supported_(true) {
+}
+
 bool
 bool
 PktFilterTestStub::isDirectResponseSupported() const {
 PktFilterTestStub::isDirectResponseSupported() const {
-    return (true);
+    return (direct_response_supported_);
 }
 }
 
 
 SocketInfo
 SocketInfo

+ 5 - 0
src/lib/dhcp/tests/pkt_filter_test_stub.h

@@ -33,6 +33,9 @@ namespace test {
 class PktFilterTestStub : public PktFilter {
 class PktFilterTestStub : public PktFilter {
 public:
 public:
 
 
+    /// @brief Constructor.
+    PktFilterTestStub();
+
     /// @brief Checks if the direct DHCPv4 response is supported.
     /// @brief Checks if the direct DHCPv4 response is supported.
     ///
     ///
     /// This function checks if the direct response capability is supported,
     /// This function checks if the direct response capability is supported,
@@ -89,6 +92,8 @@ public:
 
 
     // Change the scope of the protected function so as they can be unit tested.
     // Change the scope of the protected function so as they can be unit tested.
     using PktFilter::openFallbackSocket;
     using PktFilter::openFallbackSocket;
+
+    bool direct_response_supported_;
 };
 };
 
 
 } // namespace isc::dhcp::test
 } // namespace isc::dhcp::test