From: Marcin Siodelski Date: Fri, 20 Sep 2013 14:26:29 +0000 (+0200) Subject: [3173] Added new parameter to perfdhcp command line to select lease type. X-Git-Tag: bind10-1.2.0beta1-release~201^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3f0e486be9ee295d1556ccb2afe11e843e16009;p=thirdparty%2Fkea.git [3173] Added new parameter to perfdhcp command line to select lease type. --- diff --git a/tests/tools/perfdhcp/command_options.cc b/tests/tools/perfdhcp/command_options.cc index c0ae6fad63..d1cb8372d4 100644 --- a/tests/tools/perfdhcp/command_options.cc +++ b/tests/tools/perfdhcp/command_options.cc @@ -52,6 +52,7 @@ CommandOptions::reset() { // will need to reset all members many times to perform unit tests ipversion_ = 0; exchange_mode_ = DORA_SARR; + lease_type_ = ADDRESS_ONLY; rate_ = 0; report_delay_ = 0; clients_num_ = 0; @@ -150,7 +151,7 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) { // In this section we collect argument values from command line // they will be tuned and validated elsewhere while((opt = getopt(argc, argv, "hv46r:t:R:b:n:p:d:D:l:P:a:L:" - "s:iBc1T:X:O:E:S:I:x:w:")) != -1) { + "s:iBc1T:X:O:E:S:I:x:w:e:")) != -1) { stream << " -" << static_cast(opt); if (optarg) { stream << " " << optarg; @@ -232,6 +233,10 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) { } break; + case 'e': + initLeaseType(); + break; + case 'E': elp_offset_ = nonNegativeInteger("value of time-offset: -E" " must not be a negative integer"); @@ -620,6 +625,11 @@ CommandOptions::validate() const { "-6 (IPv6) must be set to use -c"); check((getExchangeMode() == DO_SA) && (getNumRequests().size() > 1), "second -n is not compatible with -i"); + check((getIpVersion() == 4) && (getLeaseType() != ADDRESS_ONLY), + "-6 option must be used if lease type other than '-e address-only'" + " is specified"); + check(!getTemplateFiles().empty() && (getLeaseType() != ADDRESS_ONLY), + "template files may be only used with '-e address-only'"); check((getExchangeMode() == DO_SA) && (getDropTime()[1] != 1.), "second -d is not compatible with -i"); check((getExchangeMode() == DO_SA) && @@ -705,6 +715,22 @@ CommandOptions::nonEmptyString(const std::string& errmsg) const { return sarg; } +void +CommandOptions::initLeaseType() { + std::string lease_type_arg = optarg; + if (lease_type_arg == "address-only") { + lease_type_ = ADDRESS_ONLY; + + } else if (lease_type_arg == "prefix-only") { + lease_type_ = PREFIX_ONLY; + + } else { + isc_throw(isc::InvalidParameter, "value of lease-type: -e," + " must be one of the following: 'address-only' or" + " 'prefix-only'"); + } +} + void CommandOptions::printCommandLine() const { std::cout << "IPv" << static_cast(ipversion_) << std::endl; @@ -800,13 +826,13 @@ CommandOptions::printCommandLine() const { void CommandOptions::usage() const { std::cout << - "perfdhcp [-hv] [-4|-6] [-r] [-t] [-R] [-b]\n" - " [-n] [-p] [-d] [-D]\n" - " [-l] [-P] [-a]\n" - " [-L] [-s] [-i] [-B] [-c] [-1]\n" - " [-T] [-X] [-O] [-S] [-I]\n" - " [-x] [-w] [server]\n" + "perfdhcp [-hv] [-4|-6] [-e] [-r] [-t]\n" + " [-R] [-b] [-n] [-p]\n" + " [-d] [-D] [-l]\n" + " [-P] [-a] [-L] [-s]\n" + " [-i] [-B] [-c] [-1] [-T] [-X]\n" + " [-O] [-S]\n" + " [-I] [-x] [-w] [server]\n" "\n" "The [server] argument is the name/address of the DHCP server to\n" "contact. For DHCPv4 operation, exchanges are initiated by\n" @@ -838,6 +864,11 @@ CommandOptions::usage() const { "-d: Specify the time after which a requeqst is treated as\n" " having been lost. The value is given in seconds and may contain a\n" " fractional component. The default is 1 second.\n" + "-e: A type of lease being requested from the server. It\n" + " may be one of the following: address-only or prefix-only. The\n" + " former indicates that the regular IP (v4 or v6) will be requested,\n" + " the latter indicates that the IPv6 prefixes will be requested. The\n" + " '-e prefix-only' must not be used with -4.\n" "-E: Offset of the (DHCPv4) secs field / (DHCPv6)\n" " elapsed-time option in the (second/request) template.\n" " The value 0 disables it.\n" diff --git a/tests/tools/perfdhcp/command_options.h b/tests/tools/perfdhcp/command_options.h index 246fea3f92..193e0af69c 100644 --- a/tests/tools/perfdhcp/command_options.h +++ b/tests/tools/perfdhcp/command_options.h @@ -36,6 +36,16 @@ public: DORA_SARR }; + /// @brief A type of lease being requested by the client. + /// + /// Currently it indicates whether perfdhcp is simulating the requests + /// for IPv6 addresses or prefixes (Prefix Delegation). Note that + /// prefixes can be only requested when IPv6 mode is selected. + enum LeaseType { + ADDRESS_ONLY, + PREFIX_ONLY + }; + /// CommandOptions is a singleton class. This method returns reference /// to its sole instance. /// @@ -71,6 +81,11 @@ public: /// \return packet exchange mode. ExchangeMode getExchangeMode() const { return exchange_mode_; } + /// \ brief Returns the type of lease being requested. + /// + /// \return type of lease being requested by perfdhcp. + LeaseType getLeaseType() const { return (lease_type_); } + /// \brief Returns echange rate. /// /// \return exchange rate per second. @@ -300,6 +315,11 @@ private: /// \throw InvalidParameter if string is empty. std::string nonEmptyString(const std::string& errmsg) const; + /// \brief Decodes the lease type requested by perfdhcp from optarg. + /// + /// \throw InvalidParameter if lease type value specified is invalid. + void initLeaseType(); + /// \brief Set number of clients. /// /// Interprets the getopt() "opt" global variable as the number of clients @@ -373,6 +393,8 @@ private: uint8_t ipversion_; /// Packet exchange mode (e.g. DORA/SARR) ExchangeMode exchange_mode_; + /// Lease Type to be obtained: address only, IPv6 prefix only. + LeaseType lease_type_; /// Rate in exchange per second int rate_; /// Delay between generation of two consecutive diff --git a/tests/tools/perfdhcp/tests/command_options_unittest.cc b/tests/tools/perfdhcp/tests/command_options_unittest.cc index 7a109fb32e..634b9eaa97 100644 --- a/tests/tools/perfdhcp/tests/command_options_unittest.cc +++ b/tests/tools/perfdhcp/tests/command_options_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-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 @@ -60,6 +60,7 @@ protected: EXPECT_NO_THROW(process("perfdhcp 192.168.0.1")); EXPECT_EQ(4, opt.getIpVersion()); EXPECT_EQ(CommandOptions::DORA_SARR, opt.getExchangeMode()); + EXPECT_EQ(CommandOptions::ADDRESS_ONLY, opt.getLeaseType()); EXPECT_EQ(0, opt.getRate()); EXPECT_EQ(0, opt.getReportDelay()); EXPECT_EQ(0, opt.getClientsNum()); @@ -181,6 +182,32 @@ TEST_F(CommandOptionsTest, IpVersion) { EXPECT_THROW(process("perfdhcp -c -l ethx all"), isc::InvalidParameter); } +TEST_F(CommandOptionsTest, LeaseType) { + CommandOptions& opt = CommandOptions::instance(); + // Check that the -e address-only works for IPv6. + ASSERT_NO_THROW(process("perfdhcp -6 -l etx -e address-only all")); + EXPECT_EQ(6, opt.getIpVersion()); + EXPECT_EQ("etx", opt.getLocalName()); + EXPECT_EQ(CommandOptions::ADDRESS_ONLY, opt.getLeaseType()); + // Check that the -e address-only works for IPv4. + ASSERT_NO_THROW(process("perfdhcp -4 -l etx -e address-only all")); + EXPECT_EQ(4, opt.getIpVersion()); + EXPECT_EQ("etx", opt.getLocalName()); + EXPECT_EQ(CommandOptions::ADDRESS_ONLY, opt.getLeaseType()); + // Check that the -e prefix-only works. + ASSERT_NO_THROW(process("perfdhcp -6 -l etx -e prefix-only all")); + EXPECT_EQ(6, opt.getIpVersion()); + EXPECT_EQ("etx", opt.getLocalName()); + EXPECT_EQ(CommandOptions::PREFIX_ONLY, opt.getLeaseType()); + // Check that -e prefix-only must not coexist with -4 option. + EXPECT_THROW(process("perfdhcp -4 -l ethx -e prefix-only all"), + InvalidParameter); + // Check that -e prefix-only must not coexist with -T options. + EXPECT_THROW(process("perfdhcp -6 -l ethx -e prefix-only -T file1.hex" + " -T file2.hex -E 4 all"), InvalidParameter); + +} + TEST_F(CommandOptionsTest, Rate) { CommandOptions& opt = CommandOptions::instance(); EXPECT_NO_THROW(process("perfdhcp -4 -r 10 -l ethx all"));