std::set<std::string>& getAllUniqueAddrAdvert() {
return unique_address_;
}
+
+ /// \brief Convert binary value to hex string.
+ ///
+ /// \todo Consider moving this function to src/lib/util.
+ ///
+ /// \param b byte to convert.
+ /// \return hex string.
+ static std::string byte2Hex(const uint8_t b);
+
+ /// \brief Convert vector in hexadecimal string.
+ ///
+ /// \todo Consider moving this function to src/lib/util.
+ ///
+ /// \param vec vector to be converted.
+ /// \param separator separator.
+ static std::string vector2Hex(const std::vector<uint8_t>& vec,
+ const std::string& separator = "");
+
/// \brief Initialized at first exit condition with the time perfdhcp
/// should exit
boost::posix_time::ptime exit_time_;
/// is NULL.
void copyIaOptions(const dhcp::Pkt6Ptr& pkt_from, dhcp::Pkt6Ptr& pkt_to);
- /// \brief Convert binary value to hex string.
- ///
- /// \todo Consider moving this function to src/lib/util.
- ///
- /// \param b byte to convert.
- /// \return hex string.
- std::string byte2Hex(const uint8_t b) const;
-
/// \brief Calculate elapsed time between two packets.
///
/// This function calculates the time elapsed between two packets. If
/// \return transaction id offset in packet.
int getTransactionIdOffset(const int arg_idx) const;
- /// \brief Convert vector in hexadecimal string.
- ///
- /// \todo Consider moving this function to src/lib/util.
- ///
- /// \param vec vector to be converted.
- /// \param separator separator.
- std::string vector2Hex(const std::vector<uint8_t>& vec,
- const std::string& separator = "") const;
-
/// \brief Handle child signal.
///
/// Function handles child signal by waiting for
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/foreach.hpp>
+#include <boost/format.hpp>
#include <algorithm>
#include <cstddef>
1 : opt.getClientsNum();
setMacAddrGenerator(NumberGeneratorPtr(new TestControl::SequentialGenerator(clients_num)));
};
-
};
}
+ /// @brief Check presence and content of v4 options 55.
+ ///
+ /// \param pkt packet to be checked
+ /// \param expected_option_requests only these option requests should be
+ /// found under option 55 in the packet, nothing more, nothing less
+ void checkOptions55(Pkt4Ptr const& pkt,
+ vector<uint8_t> const& expected_option_requests) {
+ // Sanity checks
+ ASSERT_TRUE(pkt);
+ OptionPtr const& opt(pkt->getOption(55));
+ ASSERT_TRUE(opt);
+ EXPECT_TRUE(opt->getUniverse() == Option::V4);
+
+ // Create the text of the expected option.
+ string const length(to_string(expected_option_requests.size()));
+ string const buffer(
+ TestControl::vector2Hex(expected_option_requests, ":"));
+ string const expected_option_text(boost::str(
+ boost::format("type=055, len=%03u: %s") % length % buffer));
+
+ // Compare.
+ EXPECT_EQ(opt->toText(), expected_option_text);
+ }
+
/// @brief check if v4 options 200 and 201 are present.
///
/// The options are expected to have specific format, as if parameters
checkOptions20x(req->second);
}
+// Test checks if multiple v4 PRL options can be sent. They should be merged
+// into a single PRL option by perfdhcp.
+TEST_F(TestControlTest, sendDiscoverMultiplePRLs) {
+ // Important paramters here:
+ // -o 55,1234 - send option 55 with hex content '1234'
+ // -o 55,abcd - send option 55 with hex content 'abcd'
+ CommandOptions opt;
+ processCmdLine(
+ opt, "perfdhcp -4 -l fake -o 55,1234 -o 55,abcd -r 1 -xT 127.0.0.1");
+
+ // Create test control and set up some basic defaults.
+ NakedTestControl tc(opt);
+ tc.registerOptionFactories();
+ NakedTestControl::IncrementalGeneratorPtr gen(
+ boost::make_shared<NakedTestControl::IncrementalGenerator>());
+ tc.setTransidGenerator(gen);
+
+ // Send the packet.
+ tc.sendDiscover4();
+
+ // Let's find the packet and see if it includes the right option.
+ auto const pkt_it(tc.template_packets_v4_.find(DHCPDISCOVER));
+ ASSERT_TRUE(pkt_it != tc.template_packets_v4_.end());
+
+ checkOptions55(pkt_it->second,
+ {
+ // Added to all perfdhcp egress packets by default
+ DHO_SUBNET_MASK,
+ DHO_BROADCAST_ADDRESS,
+ DHO_TIME_OFFSET,
+ DHO_ROUTERS,
+ DHO_DOMAIN_NAME,
+ DHO_DOMAIN_NAME_SERVERS,
+ DHO_HOST_NAME,
+ // Explicitly added in this test
+ 0x12,
+ 0x34,
+ 0xab,
+ 0xcd,
+ });
+}
+
// This test checks if HA failure can be simulated using -y and -Y options with DHCPv4.
TEST_F(TestControlTest, haFailure4) {
CommandOptions opt;
EXPECT_EQ(elapsed1->getValue(), 100);
EXPECT_GT(elapsed2->getValue(), 100);
-}
\ No newline at end of file
+}