dhcp4_test_utils.h 5.84 KB
 Tomek Mrugalski committed Oct 09, 2013 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. /// @file dhcp4_test_utils.h /// /// @brief This file contains utility classes used for DHCPv4 server testing #ifndef DHCP4_TEST_UTILS_H #define DHCP4_TEST_UTILS_H #include #include #include #include #include #include namespace isc { namespace dhcp { namespace test { class Dhcpv4SrvTest : public ::testing::Test { public: /// @brief Constructor /// /// Initializes common objects used in many tests. /// Also sets up initial configuration in CfgMgr. Dhcpv4SrvTest(); virtual ~Dhcpv4SrvTest() { } /// @brief Add 'Parameter Request List' option to the packet. /// /// This function PRL option comprising the following option codes: /// - 5 - Name Server /// - 15 - Domain Name /// - 7 - Log Server /// - 8 - Quotes Server /// - 9 - LPR Server /// /// @param pkt packet to add PRL option to. void addPrlOption(Pkt4Ptr& pkt); /// @brief Configures options being requested in the PRL option. /// /// The lpr-servers option is NOT configured here although it is /// added to the 'Parameter Request List' option in the /// \ref addPrlOption. When requested option is not configured /// the server should not return it in its response. The goal /// of not configuring the requested option is to verify that /// the server will not return it. void configureRequestedOptions(); /// @brief checks that the response matches request /// @param q query (client's message) /// @param a answer (server's message) void messageCheck(const Pkt4Ptr& q, const Pkt4Ptr& a); /// @brief Check that requested options are present. /// /// @param pkt packet to be checked. void optionsCheck(const Pkt4Ptr& pkt); /// @brief generates client-id option /// /// Generate client-id option of specified length /// Ids with different lengths are sufficent to generate /// unique ids. If more fine grained control is required, /// tests generate client-ids on their own. /// Sets client_id_ field. /// @param size size of the client-id to be generated OptionPtr generateClientId(size_t size = 4); /// @brief generate hardware address /// /// @param size size of the generated MAC address /// @param pointer to Hardware Address object HWAddrPtr generateHWAddr(size_t size = 6); /// Check that address was returned from proper range, that its lease /// lifetime is correct, that T1 and T2 are returned properly /// @param rsp response to be checked /// @param subnet subnet that should be used to verify assigned address /// and options /// @param t1_mandatory is T1 mandatory? /// @param t2_mandatory is T2 mandatory? void checkAddressParams(const Pkt4Ptr& rsp, const SubnetPtr subnet, bool t1_mandatory = false, bool t2_mandatory = false); /// @brief Basic checks for generated response (message type and trans-id). /// /// @param rsp response packet to be validated /// @param expected_message_type expected message type /// @param expected_transid expected transaction-id void checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type, uint32_t expected_transid); /// @brief Checks if the lease sent to client is present in the database /// /// @param rsp response packet to be validated /// @param client_id expected client-identifier (or NULL) /// @param HWAddr expected hardware address (not used now) /// @param expected_addr expected address Lease4Ptr checkLease(const Pkt4Ptr& rsp, const OptionPtr& client_id, const HWAddrPtr&, const isc::asiolink::IOAddress& expected_addr); /// @brief Checks if server response (OFFER, ACK, NAK) includes proper server-id /// @param rsp response packet to be validated /// @param expected_srvid expected value of server-id void checkServerId(const Pkt4Ptr& rsp, const OptionPtr& expected_srvid); /// @brief Checks if server response (OFFER, ACK, NAK) includes proper client-id /// @param rsp response packet to be validated /// @param expected_clientid expected value of client-id void checkClientId(const Pkt4Ptr& rsp, const OptionPtr& expected_clientid); /// @brief Tests if Discover or Request message is processed correctly /// /// @param msg_type DHCPDISCOVER or DHCPREQUEST void testDiscoverRequest(const uint8_t msg_type); /// @brief This function cleans up after the test. virtual void TearDown(); /// @brief A subnet used in most tests Subnet4Ptr subnet_; /// @brief A pool used in most tests Pool4Ptr pool_; /// @brief A client-id used in most tests ClientIdPtr client_id_; int rcode_; isc::data::ConstElementPtr comment_; // Name of a valid network interface std::string valid_iface_; }; }; // end of isc::dhcp::test namespace }; // end of isc::dhcp namespace }; // end of isc namespace #endif // DHCP6_TEST_UTILS_H