BIND 10 trac1956, updated. bff3d4786c50018143abe2316c9e837f24c52e81 [1956] Replaced clock_gettime with posix_time.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 1 08:47:09 UTC 2012
The branch, trac1956 has been updated
via bff3d4786c50018143abe2316c9e837f24c52e81 (commit)
from 25af754fb60cdb8e538eeb2111694bd3cf2bf89e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit bff3d4786c50018143abe2316c9e837f24c52e81
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 1 10:46:47 2012 +0200
[1956] Replaced clock_gettime with posix_time.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/pkt4.cc | 6 +-----
src/lib/dhcp/pkt4.h | 5 +++--
src/lib/dhcp/pkt6.cc | 6 +-----
src/lib/dhcp/pkt6.h | 5 +++--
src/lib/dhcp/tests/pkt4_unittest.cc | 25 ++++++++++++++++++++-----
src/lib/dhcp/tests/pkt6_unittest.cc | 26 +++++++++++++++++++++-----
6 files changed, 49 insertions(+), 24 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index 5199551..2c3f1eb 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -53,7 +53,6 @@ Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
memset(chaddr_, 0, MAX_CHADDR_LEN);
memset(sname_, 0, MAX_SNAME_LEN);
memset(file_, 0, MAX_FILE_LEN);
- memset(×tamp_, 0, sizeof(timestamp_));
}
Pkt4::Pkt4(const uint8_t* data, size_t len)
@@ -82,7 +81,6 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
data_.resize(len);
memcpy(&data_[0], data, len);
- memset(×tamp_, 0, sizeof(timestamp_));
}
size_t
@@ -309,9 +307,7 @@ Pkt4::getOption(uint8_t type) {
void
Pkt4::updateTimestamp() {
- if (clock_gettime(CLOCK_REALTIME, ×tamp_) < 0) {
- isc_throw(isc::Unexpected, "Failed to get timestamp for packet");
- }
+ timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
} // end of namespace isc::dhcp
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index ba59e82..c36f5bf 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -19,6 +19,7 @@
#include <time.h>
#include <vector>
#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "asiolink/io_address.h"
#include "util/buffer.h"
#include "dhcp/option.h"
@@ -328,7 +329,7 @@ public:
/// packet is received or send.
///
/// @return packet timestamp.
- timespec getTimestamp() const { return timestamp_; }
+ const boost::posix_time::ptime& getTimestamp() const { return timestamp_; }
/// @brief Sets interface name.
///
@@ -504,7 +505,7 @@ protected:
isc::dhcp::Option::OptionCollection options_;
/// packet timestamp
- timespec timestamp_;
+ boost::posix_time::ptime timestamp_;
}; // Pkt4 class
typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc
index 519698b..e869c7b 100644
--- a/src/lib/dhcp/pkt6.cc
+++ b/src/lib/dhcp/pkt6.cc
@@ -38,7 +38,6 @@ Pkt6::Pkt6(const uint8_t* buf, uint32_t buf_len, DHCPv6Proto proto /* = UDP */)
bufferOut_(0) {
data_.resize(buf_len);
memcpy(&data_[0], buf, buf_len);
- memset(×tamp_, 0, sizeof(timestamp_));
}
Pkt6::Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto /*= UDP*/) :
@@ -52,7 +51,6 @@ Pkt6::Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto /*= UDP*/) :
local_port_(0),
remote_port_(0),
bufferOut_(0) {
- memset(×tamp_, 0, sizeof(timestamp_));
}
uint16_t Pkt6::len() {
@@ -206,9 +204,7 @@ void Pkt6::repack() {
void
Pkt6::updateTimestamp() {
- if (clock_gettime(CLOCK_REALTIME, ×tamp_) < 0) {
- isc_throw(isc::Unexpected, "Failed to get timestamp for packet");
- }
+ timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h
index e02b791..6cca573 100644
--- a/src/lib/dhcp/pkt6.h
+++ b/src/lib/dhcp/pkt6.h
@@ -19,6 +19,7 @@
#include <time.h>
#include <boost/shared_ptr.hpp>
#include <boost/shared_array.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "asiolink/io_address.h"
#include "dhcp/option.h"
@@ -227,7 +228,7 @@ public:
/// packet is received or send.
///
/// @return packet timestamp.
- timespec getTimestamp() const { return timestamp_; }
+ const boost::posix_time::ptime& getTimestamp() const { return timestamp_; }
/// @brief Sets interface name.
///
@@ -324,7 +325,7 @@ protected:
isc::util::OutputBuffer bufferOut_;
/// packet timestamp
- timespec timestamp_;
+ boost::posix_time::ptime timestamp_;
}; // Pkt6 class
typedef boost::shared_ptr<Pkt6> Pkt6Ptr;
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index df6381f..1ac8477 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -600,14 +600,29 @@ TEST(Pkt4Test, metaFields) {
TEST(Pkt4Test, Timestamp) {
Pkt4* pkt = new Pkt4(DHCPOFFER, 1234);
- ASSERT_NO_THROW(pkt->updateTimestamp());
- timespec ts_packet = pkt->getTimestamp();
- timespec ts_now;
- ASSERT_FALSE(clock_gettime(CLOCK_REALTIME, &ts_now) < 0);
- EXPECT_TRUE(ts_packet.tv_sec >= ts_now.tv_sec);
+
+ // Update packet time.
+ pkt->updateTimestamp();
+
+ // Get updated packet time.
+ boost::posix_time::ptime ts_packet = pkt->getTimestamp();
+
+ // After timestamp is updated it should be date-time.
+ ASSERT_FALSE(ts_packet.is_not_a_date_time());
+
+ // Check current time.
+ boost::posix_time::ptime ts_now =
+ boost::posix_time::microsec_clock::universal_time();
+
+ // Calculate period between packet time and now.
+ boost::posix_time::time_period ts_period(ts_packet, ts_now);
+
+ // Duration should be positive or zero.
+ EXPECT_TRUE(ts_period.length().total_microseconds() >= 0);
delete pkt;
}
+
} // end of anonymous namespace
diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc
index 21080f8..fdc9733 100644
--- a/src/lib/dhcp/tests/pkt6_unittest.cc
+++ b/src/lib/dhcp/tests/pkt6_unittest.cc
@@ -16,6 +16,7 @@
#include <iostream>
#include <sstream>
#include <arpa/inet.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include <gtest/gtest.h>
#include <asiolink/io_address.h>
@@ -206,11 +207,26 @@ TEST_F(Pkt6Test, addGetDelOptions) {
TEST_F(Pkt6Test, Timestamp) {
Pkt6* pkt = new Pkt6(DHCPV6_SOLICIT, 0x020304);
- ASSERT_NO_THROW(pkt->updateTimestamp());
- timespec ts_packet = pkt->getTimestamp();
- timespec ts_now;
- ASSERT_FALSE(clock_gettime(CLOCK_REALTIME, &ts_now) < 0);
- EXPECT_TRUE(ts_packet.tv_sec >= ts_now.tv_sec);
+ // Update packet time.
+ pkt->updateTimestamp();
+
+ // Get updated packet time.
+ boost::posix_time::ptime ts_packet = pkt->getTimestamp();
+
+ // After timestamp is updated it should be date-time.
+ ASSERT_FALSE(ts_packet.is_not_a_date_time());
+
+ // Check current time.
+ boost::posix_time::ptime ts_now =
+ boost::posix_time::microsec_clock::universal_time();
+
+ // Calculate period between packet time and now.
+ boost::posix_time::time_period ts_period(ts_packet, ts_now);
+
+ // Duration should be positive or zero.
+ EXPECT_TRUE(ts_period.length().total_microseconds() >= 0);
+
+ delete pkt;
}
}
More information about the bind10-changes
mailing list