From: Tomek Mrugalski Date: Fri, 18 Jan 2019 17:12:28 +0000 (+0100) Subject: [#82, !180] Missing unit-test added. X-Git-Tag: 421-create-config-backend-for-dhcpv6-base_base X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4987e17c2712e2e3b11538c638d85a78dc95fd57;p=thirdparty%2Fkea.git [#82, !180] Missing unit-test added. --- diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 412b48b9c4..33078ec38c 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -1511,6 +1511,49 @@ TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) { EXPECT_TRUE(rai_response->equals(rai_query)); } +// Checks if client port can be overridden in packets being sent. +TEST_F(Dhcpv4SrvTest, portsClientPort) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + + NakedDhcpv4Srv srv(0); + + // By default te client port is supposed to be zero. + EXPECT_EQ(0, srv.client_port_); + + // Use of the captured DHCPDISCOVER packet requires that + // subnet 10.254.226.0/24 is in use, because this packet + // contains the giaddr which belongs to this subnet and + // this giaddr is used to select the subnet + configure(CONFIGS[0]); + srv.client_port_ = 1234; + + // Let's create a relayed DISCOVER. This particular relayed DISCOVER has + // added option 82 (relay agent info) with 3 suboptions. The server + // is supposed to echo it back in its response. + Pkt4Ptr dis; + ASSERT_NO_THROW(dis = PktCaptures::captureRelayedDiscover()); + + // Simulate that we have received that traffic + srv.fakeReceive(dis); + + // Server will now process to run its normal loop, but instead of calling + // IfaceMgr::receive4(), it will read all packets from the list set by + // fakeReceive() + // In particular, it should call registered buffer4_receive callback. + srv.run(); + + // Check that the server did send a response + ASSERT_EQ(1, srv.fake_sent_.size()); + + // Make sure that we received a response + Pkt4Ptr offer = srv.fake_sent_.front(); + ASSERT_TRUE(offer); + + // Get Relay Agent Info from query... + EXPECT_EQ(srv.client_port_, offer->getRemotePort()); +} + /// @todo move vendor options tests to a separate file. /// @todo Add more extensive vendor options tests, including multiple /// vendor options