BIND 10 trac2902, updated. 757a5b14ef9101d99c47e7155a1b19b526d09389 [2902] Added unit test checking reception of the packet over INET DGRAM.

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Apr 24 09:51:16 UTC 2013


The branch, trac2902 has been updated
       via  757a5b14ef9101d99c47e7155a1b19b526d09389 (commit)
      from  c6302d0c4226e13753428df87e7d7864e86ed778 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 757a5b14ef9101d99c47e7155a1b19b526d09389
Author: Marcin Siodelski <marcin at isc.org>
Date:   Wed Apr 24 11:51:07 2013 +0200

    [2902] Added unit test checking reception of the packet over INET DGRAM.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dhcp/tests/pkt_filter_inet_unittest.cc |   68 ++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc b/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc
index 1ae035a..489881a 100644
--- a/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc
+++ b/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc
@@ -27,9 +27,14 @@ using namespace isc::dhcp;
 
 namespace {
 
+/// Port number used by tests.
 const uint16_t PORT = 10067;
+/// Size of the buffer holding received packets.
 const size_t RECV_BUF_SIZE = 2048;
 
+/// This class handles has simple algorithm checking
+/// presence of loopback interface and initializing
+/// its index.
 class PktFilterInetTest : public ::testing::Test {
 public:
     PktFilterInetTest() {
@@ -185,4 +190,67 @@ TEST_F(PktFilterInetTest, send) {
     EXPECT_EQ(pkt->getHlen(), rcvd_pkt->getHlen());
 }
 
+// This test verifies that the DHCPv4 packet is correctly received via
+// INET datagram socket and that it matches sent packet.
+TEST_F(PktFilterInetTest, receive) {
+    // Let's create a DHCPv4 packet.
+    Pkt4Ptr pkt(new Pkt4(DHCPOFFER, 0));
+    ASSERT_TRUE(pkt);
+
+    // Set required fields.
+    pkt->setLocalAddr(IOAddress("127.0.0.1"));
+    pkt->setRemotePort(PORT);
+    pkt->setLocalPort(PORT + 1);
+    pkt->setIndex(ifindex_);
+    pkt->setIface(ifname_);
+    pkt->setHops(6);
+    pkt->setSecs(42);
+    pkt->setCiaddr(IOAddress("192.0.2.1"));
+    pkt->setSiaddr(IOAddress("192.0.2.2"));
+    pkt->setYiaddr(IOAddress("192.0.2.3"));
+    pkt->setGiaddr(IOAddress("192.0.2.4"));
+
+    // Create the on-wire data.
+    ASSERT_NO_THROW(pkt->pack());
+
+    // Packet will be sent over loopback interface.
+    Iface iface(ifname_, ifindex_);
+    IOAddress addr("127.0.0.1");
+
+    // Create an instance of the class which we are testing.
+    PktFilterInet pkt_filter;
+    // Open socket. We don't check that the socket has appropriate
+    // options and family set because we have checked that in the
+    // openSocket test already.
+    socket_ = pkt_filter.openSocket(iface, addr, PORT, false, false);
+    ASSERT_GE(socket_, 0);
+
+    // Send the packet over the socket.
+    ASSERT_NO_THROW(pkt_filter.send(iface, socket_, pkt));
+
+    // Receive the packet.
+    SocketInfo socket_info(socket_, IOAddress("127.0.0.1"), PORT);
+    Pkt4Ptr rcvd_pkt = pkt_filter.receive(iface, socket_info);
+    // Check that the packet has been correctly received.
+    ASSERT_TRUE(rcvd_pkt);
+
+    // Parse the packet.
+    ASSERT_NO_THROW(rcvd_pkt->unpack());
+
+    // Verify that the received packet matches sent packet.
+    EXPECT_EQ(pkt->getHops(), rcvd_pkt->getHops());
+    EXPECT_EQ(pkt->getOp(),   rcvd_pkt->getOp());
+    EXPECT_EQ(pkt->getSecs(), rcvd_pkt->getSecs());
+    EXPECT_EQ(pkt->getFlags(), rcvd_pkt->getFlags());
+    EXPECT_EQ(pkt->getCiaddr(), rcvd_pkt->getCiaddr());
+    EXPECT_EQ(pkt->getSiaddr(), rcvd_pkt->getSiaddr());
+    EXPECT_EQ(pkt->getYiaddr(), rcvd_pkt->getYiaddr());
+    EXPECT_EQ(pkt->getGiaddr(), rcvd_pkt->getGiaddr());
+    EXPECT_EQ(pkt->getTransid(), rcvd_pkt->getTransid());
+    EXPECT_TRUE(pkt->getSname() == rcvd_pkt->getSname());
+    EXPECT_TRUE(pkt->getFile() == rcvd_pkt->getFile());
+    EXPECT_EQ(pkt->getHtype(), rcvd_pkt->getHtype());
+    EXPECT_EQ(pkt->getHlen(), rcvd_pkt->getHlen());
+}
+
 } // anonymous namespace



More information about the bind10-changes mailing list