#include <perfdhcp/basic_scen.h>
-
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace std;
// Send multiple renews to satisfy the desired rate.
if (options_.getIpVersion() == 4) {
- tc_.sendMultipleRequests(renew_packets_due);
+ tc_.sendMultipleMessages(DHCPREQUEST, renew_packets_due);
} else {
tc_.sendMultipleMessages6(DHCPV6_RENEW, renew_packets_due);
}
// If -F<release-rate> option was specified we have to check how many
// Release messages should be sent to catch up with a desired rate.
- if ((options_.getIpVersion() == 6) && (options_.getReleaseRate() != 0)) {
+ if (options_.getReleaseRate() != 0) {
uint64_t release_packets_due =
release_rate_control_.getOutboundMessageCount(!tc_.exit_time_.is_not_a_date_time());
// Send Release messages.
- tc_.sendMultipleMessages6(DHCPV6_RELEASE, release_packets_due);
+
+ if (options_.getIpVersion() == 4) {
+ tc_.sendMultipleMessages(DHCPRELEASE, release_packets_due);
+ } else {
+ tc_.sendMultipleMessages6(DHCPV6_RELEASE, release_packets_due);
+ }
}
// Report delay means that user requested printing number
}
Pkt4Ptr
-TestControl::createRequestFromAck(const dhcp::Pkt4Ptr& ack) {
+TestControl::createMessageFromAck(const uint16_t msg_type,
+ const dhcp::Pkt4Ptr& ack) {
+ // Restrict messages to Release and Renew.
+ if (msg_type != DHCPREQUEST && msg_type != DHCPRELEASE) {
+ isc_throw(isc::BadValue, "invalid message type " << msg_type
+ << " to be created from Reply, expected DHCPREQUEST or"
+ " DHCPRELEASE");
+ }
+
+ // Get the string representation of the message - to be used for error
+ // logging purposes.
+ const char* msg_type_str = (msg_type == DHCPREQUEST ? "Request" :
+ "Release");
+
if (!ack) {
- isc_throw(isc::BadValue, "Unable to create DHCPREQUEST from a"
- " null DHCPACK message");
+ isc_throw(isc::BadValue, "Unable to create "
+ << msg_type_str
+ << " from a null DHCPACK message");
} else if (ack->getYiaddr().isV4Zero()) {
- isc_throw(isc::BadValue, "Unable to create DHCPREQUEST from a"
- " DHCPACK message containing yiaddr of 0");
+ isc_throw(isc::BadValue,
+ "Unable to create "
+ << msg_type_str
+ << " from a DHCPACK message containing yiaddr of 0");
}
- Pkt4Ptr msg(new Pkt4(DHCPREQUEST, generateTransid()));
+ Pkt4Ptr msg(new Pkt4(msg_type, generateTransid()));
msg->setCiaddr(ack->getYiaddr());
msg->setHWAddr(ack->getHWAddr());
msg->addOption(generateClientId(msg->getHWAddr()));
<< " to be created from Reply, expected DHCPV6_RENEW or"
" DHCPV6_RELEASE");
}
+
// Get the string representation of the message - to be used for error
// logging purposes.
const char* msg_type_str = (msg_type == DHCPV6_RENEW ? "Renew" : "Release");
+
// Reply message must be specified.
if (!reply) {
isc_throw(isc::BadValue, "Unable to create " << msg_type_str
}
uint64_t
-TestControl::sendMultipleRequests(const uint64_t msg_num) {
+TestControl::sendMultipleMessages(const uint32_t msg_type,
+ const uint64_t msg_num) {
for (uint64_t i = 0; i < msg_num; ++i) {
- if (!sendRequestFromAck()) {
+ if (!sendMessageFromAck(msg_type)) {
return (i);
}
}
// So, we may need to keep this DHCPACK in the storage if renews.
// Note that, DHCPACK messages hold the information about
// leases assigned. We use this information to renew.
- if (stats_mgr_.hasExchangeStats(ExchangeType::RNA)) {
- // Renew messages are sent, because StatsMgr has the
- // specific exchange type specified. Let's append the DHCPACK.
- // message to a storage
+ if (stats_mgr_.hasExchangeStats(ExchangeType::RNA) ||
+ stats_mgr_.hasExchangeStats(ExchangeType::RLA)) {
+ // Renew or release messages are sent, because StatsMgr has the
+ // specific exchange type specified. Let's append the DHCPACK
+ // message to a storage.
ack_storage_.append(pkt4);
}
// The DHCPACK message is not a server's response to the DHCPREQUEST
}
bool
-TestControl::sendRequestFromAck() {
+TestControl::sendMessageFromAck(const uint16_t msg_type) {
+ // We only permit Request or Release messages to be sent using this
+ // function.
+ if (msg_type != DHCPREQUEST && msg_type != DHCPRELEASE) {
+ isc_throw(isc::BadValue,
+ "invalid message type "
+ << msg_type
+ << " to be sent, expected DHCPREQUEST or DHCPRELEASE");
+ }
+
// Get one of the recorded DHCPACK messages.
Pkt4Ptr ack = ack_storage_.getRandom();
if (!ack) {
}
// Create message of the specified type.
- Pkt4Ptr msg = createRequestFromAck(ack);
+ Pkt4Ptr msg = createMessageFromAck(msg_type, ack);
setDefaults4(msg);
// Override relay address
// Add any extra options that user may have specified.
addExtraOpts(msg);
+ // Pack it.
msg->pack();
+
// And send it.
socket_.send(msg);
- stats_mgr_.passSentPacket(ExchangeType::RNA, msg);
+ address4Uniqueness(msg, ExchangeType::RLA);
+ stats_mgr_.passSentPacket((msg_type == DHCPREQUEST ? ExchangeType::RNA :
+ ExchangeType::RLA),
+ msg);
return (true);
}
isc_throw(isc::BadValue, "invalid message type " << msg_type
<< " to be sent, expected DHCPV6_RENEW or DHCPV6_RELEASE");
}
+
+ // Get one of the recorded DHCPV6_OFFER messages.
Pkt6Ptr reply = reply_storage_.getRandom();
if (!reply) {
return (false);
// Add any extra options that user may have specified.
addExtraOpts(msg);
+ // Pack it.
msg->pack();
+
// And send it.
socket_.send(msg);
address6Uniqueness(msg, ExchangeType::RL);
#include <perfdhcp/perf_socket.h>
#include <dhcp/iface_mgr.h>
+#include <dhcp/dhcp4.h>
#include <dhcp/dhcp6.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
/// \brief Send number of DHCPREQUEST (renew) messages to a server.
///
+ /// \param msg_type A type of the messages to be sent (DHCPREQUEST or
+ /// DHCPRELEASE).
/// \param msg_num A number of messages to be sent.
///
/// \return A number of messages actually sent.
- uint64_t sendMultipleRequests(const uint64_t msg_num);
+ uint64_t sendMultipleMessages(const uint32_t msg_type,
+ const uint64_t msg_num);
/// \brief Send number of DHCPv6 Renew or Release messages to the server.
///
/// create a new message.
///
/// \return Pointer to the created message.
- dhcp::Pkt4Ptr createRequestFromAck(const dhcp::Pkt4Ptr& ack);
+ dhcp::Pkt4Ptr createMessageFromAck(const uint16_t msg_type,
+ const dhcp::Pkt4Ptr& ack);
/// \brief Creates DHCPv6 message from the Reply packet.
///
}
break;
}
+ case ExchangeType::RLA:
case ExchangeType::RL: {
removeUniqueAddr(current);
break;
/// \brief Send DHCPv4 renew (DHCPREQUEST).
///
+ /// \param msg_type A type of the message to be sent (DHCPREQUEST or
+ /// DHCPRELEASE).
+ ///
/// \return true if the message has been sent, false otherwise.
- bool sendRequestFromAck();
+ bool sendMessageFromAck(const uint16_t msg_type);
/// \brief Send DHCPv6 Renew or Release message.
///