From: Tomek Mrugalski Date: Mon, 7 Oct 2013 10:26:54 +0000 (+0200) Subject: [3177] Changes after review X-Git-Tag: bind10-1.2.0beta1-release~191^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e43c23bc2d1006c2abb5dd7df7ed575cfce00451;p=thirdparty%2Fkea.git [3177] Changes after review - removed unnecessary filename reference - setting Pkt6 fields is now done in a common function - methods return shared_ptr instead of raw pointer --- diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 024b589b4c..c4a6ef9758 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -2110,7 +2110,7 @@ TEST_F(Dhcpv6SrvTest, portsDirectTraffic) { NakedDhcpv6Srv srv(0); // Let's create a simple SOLICIT - Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit()); + Pkt6Ptr sol = captureSimpleSolicit(); // Simulate that we have received that traffic srv.fakeReceive(sol); @@ -2135,7 +2135,7 @@ TEST_F(Dhcpv6SrvTest, portsRelayedTraffic) { NakedDhcpv6Srv srv(0); // Let's create a simple SOLICIT - Pkt6Ptr sol = Pkt6Ptr(captureRelayedSolicit()); + Pkt6Ptr sol = captureRelayedSolicit(); // Simulate that we have received that traffic srv.fakeReceive(sol); @@ -2162,7 +2162,7 @@ TEST_F(Dhcpv6SrvTest, DISABLED_docsisTraffic) { NakedDhcpv6Srv srv(0); // Let's get a traffic capture from DOCSIS3.0 modem - Pkt6Ptr sol = Pkt6Ptr(captureDocsisRelayedSolicit()); + Pkt6Ptr sol = captureDocsisRelayedSolicit(); // Simulate that we have received that traffic srv.fakeReceive(sol); diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.h b/src/bin/dhcp6/tests/dhcp6_test_utils.h index 6035d269bd..939ae22aca 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.h +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.h @@ -396,9 +396,17 @@ public: // see wireshark.cc for descriptions // The descriptions are too large and too closely related to the // code, so it is kept in .cc rather than traditionally in .h - Pkt6* captureSimpleSolicit(); - Pkt6* captureRelayedSolicit(); - Pkt6* captureDocsisRelayedSolicit(); + Pkt6Ptr captureSimpleSolicit(); + Pkt6Ptr captureRelayedSolicit(); + Pkt6Ptr captureDocsisRelayedSolicit(); + + + /// @brief Auxiliary method that sets Pkt6 fields + /// + /// Used to reconstruct captured packets. Sets UDP ports, interface names, + /// and other fields to some believable values. + /// @param pkt packet that will have its fields set + void captureSetDefaultFields(const Pkt6Ptr& pkt); ~Dhcpv6SrvTest() { CfgMgr::instance().deleteSubnets6(); diff --git a/src/bin/dhcp6/tests/wireshark.cc b/src/bin/dhcp6/tests/wireshark.cc index 1daeeac495..2f590300b2 100644 --- a/src/bin/dhcp6/tests/wireshark.cc +++ b/src/bin/dhcp6/tests/wireshark.cc @@ -39,9 +39,18 @@ using namespace std; namespace isc { namespace test { +void Dhcpv6SrvTest::captureSetDefaultFields(const Pkt6Ptr& pkt) { + pkt->setRemotePort(546); + pkt->setRemoteAddr(IOAddress("fe80::1")); + pkt->setLocalPort(0); + pkt->setLocalAddr(IOAddress("ff02::1:2")); + pkt->setIndex(2); + pkt->setIface("eth0"); +} + // This function returns buffer for very simple Solicit -Pkt6* isc::test::Dhcpv6SrvTest::captureSimpleSolicit() { - Pkt6* pkt; +Pkt6Ptr Dhcpv6SrvTest::captureSimpleSolicit() { + Pkt6Ptr pkt; uint8_t data[] = { 1, // type 1 = SOLICIT 0xca, 0xfe, 0x01, // trans-id = 0xcafe01 @@ -55,18 +64,13 @@ Pkt6* isc::test::Dhcpv6SrvTest::captureSimpleSolicit() { 0, 0, 0, 0 // T2 = 0 }; - pkt = new Pkt6(data, sizeof(data)); - pkt->setRemotePort(546); - pkt->setRemoteAddr(IOAddress("fe80::1")); - pkt->setLocalPort(0); - pkt->setLocalAddr(IOAddress("ff02::1:2")); - pkt->setIndex(2); - pkt->setIface("eth0"); + pkt.reset(new Pkt6(data, sizeof(data))); + captureSetDefaultFields(pkt); return (pkt); } -Pkt6* isc::test::Dhcpv6SrvTest::captureRelayedSolicit() { +Pkt6Ptr Dhcpv6SrvTest::captureRelayedSolicit() { // This is a very simple relayed SOLICIT message: // RELAY-FORW @@ -89,19 +93,14 @@ Pkt6* isc::test::Dhcpv6SrvTest::captureRelayedSolicit() { // to be OptionBuffer format) isc::util::encode::decodeHex(hex_string, bin); - Pkt6* pkt = new Pkt6(&bin[0], bin.size()); - pkt->setRemotePort(547); - pkt->setRemoteAddr(IOAddress("fe80::1234")); - pkt->setLocalPort(547); - pkt->setLocalAddr(IOAddress("ff05::1:3")); - pkt->setIndex(2); - pkt->setIface("eth0"); + Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size())); + captureSetDefaultFields(pkt); + return (pkt); } /// returns a buffer with relayed SOLICIT (from DOCSIS3.0 cable modem) -/// see dhcp6_relay_forw-virginmedia.pcap -Pkt6* isc::test::Dhcpv6SrvTest::captureDocsisRelayedSolicit() { +Pkt6Ptr isc::test::Dhcpv6SrvTest::captureDocsisRelayedSolicit() { // This is an actual DOCSIS packet // RELAY-FORW (12) @@ -156,13 +155,8 @@ Pkt6* isc::test::Dhcpv6SrvTest::captureDocsisRelayedSolicit() { // to be OptionBuffer format) isc::util::encode::decodeHex(hex_string, bin); - Pkt6* pkt = new Pkt6(&bin[0], bin.size()); - pkt->setRemotePort(547); - pkt->setRemoteAddr(IOAddress("fe80::1234")); - pkt->setLocalPort(547); - pkt->setLocalAddr(IOAddress("ff05::1:3")); - pkt->setIndex(2); - pkt->setIface("eth0"); + Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size())); + captureSetDefaultFields(pkt); return (pkt); }