Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
416
Issues
416
List
Boards
Labels
Service Desk
Milestones
Merge Requests
66
Merge Requests
66
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
bff3d478
Commit
bff3d478
authored
Jun 01, 2012
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[1956] Replaced clock_gettime with posix_time.
parent
25af754f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
24 deletions
+49
-24
src/lib/dhcp/pkt4.cc
src/lib/dhcp/pkt4.cc
+1
-5
src/lib/dhcp/pkt4.h
src/lib/dhcp/pkt4.h
+3
-2
src/lib/dhcp/pkt6.cc
src/lib/dhcp/pkt6.cc
+1
-5
src/lib/dhcp/pkt6.h
src/lib/dhcp/pkt6.h
+3
-2
src/lib/dhcp/tests/pkt4_unittest.cc
src/lib/dhcp/tests/pkt4_unittest.cc
+20
-5
src/lib/dhcp/tests/pkt6_unittest.cc
src/lib/dhcp/tests/pkt6_unittest.cc
+21
-5
No files found.
src/lib/dhcp/pkt4.cc
View file @
bff3d478
...
...
@@ -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
(
&
timestamp_
,
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
(
&
timestamp_
,
0
,
sizeof
(
timestamp_
));
}
size_t
...
...
@@ -309,9 +307,7 @@ Pkt4::getOption(uint8_t type) {
void
Pkt4
::
updateTimestamp
()
{
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
timestamp_
)
<
0
)
{
isc_throw
(
isc
::
Unexpected
,
"Failed to get timestamp for packet"
);
}
timestamp_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
}
}
// end of namespace isc::dhcp
...
...
src/lib/dhcp/pkt4.h
View file @
bff3d478
...
...
@@ -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
;
...
...
src/lib/dhcp/pkt6.cc
View file @
bff3d478
...
...
@@ -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
(
&
timestamp_
,
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
(
&
timestamp_
,
0
,
sizeof
(
timestamp_
));
}
uint16_t
Pkt6
::
len
()
{
...
...
@@ -206,9 +204,7 @@ void Pkt6::repack() {
void
Pkt6
::
updateTimestamp
()
{
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
timestamp_
)
<
0
)
{
isc_throw
(
isc
::
Unexpected
,
"Failed to get timestamp for packet"
);
}
timestamp_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
}
...
...
src/lib/dhcp/pkt6.h
View file @
bff3d478
...
...
@@ -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
;
...
...
src/lib/dhcp/tests/pkt4_unittest.cc
View file @
bff3d478
...
...
@@ -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
src/lib/dhcp/tests/pkt6_unittest.cc
View file @
bff3d478
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment