Browse Source

[5003] Test local port of the received message in pkt filter tests.

Marcin Siodelski 8 years ago
parent
commit
3c0afa727a

+ 1 - 2
src/lib/dhcp/pkt_filter_inet.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -198,7 +198,6 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
         if ((cmsg->cmsg_level == IPPROTO_IP) &&
             (cmsg->cmsg_type == IP_RECVDSTADDR)) {
             to_addr = (struct in_addr*)CMSG_DATA(cmsg);
-
             pkt->setLocalAddr(IOAddress(htonl(to_addr->s_addr)));
             break;
         }

+ 2 - 1
src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -192,6 +192,7 @@ TEST_F(PktFilterBPFTest, DISABLED_receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 // This test verifies that if the packet is received over the raw

+ 2 - 1
src/lib/dhcp/tests/pkt_filter_inet_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -140,6 +140,7 @@ TEST_F(PktFilterInetTest, receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 } // anonymous namespace

+ 2 - 1
src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -179,6 +179,7 @@ TEST_F(PktFilterLPFTest, DISABLED_receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 // This test verifies that if the packet is received over the raw

+ 9 - 1
src/lib/dhcp/tests/pkt_filter_test_utils.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -160,6 +160,14 @@ PktFilterTest::testRcvdMessage(const Pkt4Ptr& rcvd_msg) const {
     EXPECT_EQ(test_message_->getHlen(), rcvd_msg->getHlen());
 }
 
+void
+PktFilterTest::testRcvdMessageAddressPort(const Pkt4Ptr& rcvd_msg) const {
+    EXPECT_EQ(test_message_->getRemoteAddr(), rcvd_msg->getLocalAddr());
+    EXPECT_EQ(test_message_->getLocalAddr(), rcvd_msg->getRemoteAddr());
+    EXPECT_EQ(test_message_->getRemotePort(), rcvd_msg->getLocalPort());
+    EXPECT_EQ(test_message_->getLocalPort(), rcvd_msg->getRemotePort());
+}
+
 bool
 PktFilterStub::isDirectResponseSupported() const {
     return (true);

+ 8 - 2
src/lib/dhcp/tests/pkt_filter_test_utils.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -71,11 +71,17 @@ public:
     /// @param sock A descriptor of the open socket.
     void testDgramSocket(const int sock) const;
 
-    /// @brief Checks if the received message matches the test_message_.
+    /// @brief Checks if a received message matches the test_message_.
     ///
     /// @param rcvd_msg An instance of the message to be tested.
     void testRcvdMessage(const Pkt4Ptr& rcvd_msg) const;
 
+    /// @brief Checks if received message has appropriate addresses and
+    /// port values set.
+    ///
+    /// @param rcvd_msg An instance of the message to be tested.
+    void testRcvdMessageAddressPort(const Pkt4Ptr& rcvd_msg) const;
+
     std::string ifname_;   ///< Loopback interface name
     uint16_t ifindex_;     ///< Loopback interface index.
     uint16_t port_;        ///< A port number used for the test.