Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
3e0882c3
Commit
3e0882c3
authored
Mar 03, 2015
by
Stephen Morris
Browse files
[master] Merge branch 'trac3729'
parents
14a6ed7d
bb5bca3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/bin/perfdhcp/rate_control.cc
View file @
3e0882c3
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013
, 2015
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
...
...
@@ -51,15 +51,16 @@ RateControl::getOutboundMessageCount() {
// Reset number of exchanges.
uint64_t
due_exchanges
=
0
;
// If rate is specified from the command line we have to
// synch
o
rnize with it.
// synchr
o
nize with it.
if
(
getRate
()
!=
0
)
{
time_period
period
(
send_due_
,
now
);
time_duration
duration
=
period
.
length
();
// due_factor indicates the number of seconds that
// sending next chunk of packets will take.
double
due_factor
=
duration
.
fractional_seconds
()
/
time_duration
::
ticks_per_second
();
due_factor
+=
duration
.
total_seconds
();
double
due_factor
=
static_cast
<
double
>
(
duration
.
fractional_seconds
())
/
static_cast
<
double
>
(
time_duration
::
ticks_per_second
());
due_factor
+=
static_cast
<
double
>
(
duration
.
total_seconds
());
// Multiplying due_factor by expected rate gives the number
// of exchanges to be initiated.
due_exchanges
=
static_cast
<
uint64_t
>
(
due_factor
*
getRate
());
...
...
src/bin/perfdhcp/tests/rate_control_unittest.cc
View file @
3e0882c3
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013
, 2015
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
...
...
@@ -129,29 +129,51 @@ TEST(RateControl, isLateSent) {
// it is quite hard to fully test this function as its behaviour strongly
// depends on time.
TEST
(
RateControl
,
getOutboundMessageCount
)
{
NakedRateControl
rc1
(
1000
,
1
);
// Set the timestamp of the last sent message well to the past.
// The resulting due time will be in the past too.
// Test that the number of outbound messages is correctly defined by the
// rate. The agressivity is set high enough so that it will not restrict
// the calculated count.
NakedRateControl
rc1
(
1000
,
1000000
);
// Set the timestamp of the last sent message well to the past. The
// resulting due time will be in the past too. A fractional number of
// seconds is used to check the floating point arithmetic performed inside
// the RateControl class.
rc1
.
last_sent_
=
NakedRateControl
::
currentTime
()
-
boost
::
posix_time
::
seconds
(
5
);
// The number of messages to be sent must be greater than 0.
NakedRateControl
::
currentTime
()
-
boost
::
posix_time
::
seconds
(
5
)
-
boost
::
posix_time
::
milliseconds
(
250
);
// The number of messages to be sent must be roughly equal to the time
// between the last sent message and the current time multiplied by the
// rate. ("Roughly", as current time is advancing, so the actual interval
// when the calcuation is made may be different from the interval set.) The
// margin in this test is reasonably generous, allowing for a timing error
// of around 10ms.
uint64_t
count
;
ASSERT_NO_THROW
(
count
=
rc1
.
getOutboundMessageCount
());
EXPECT_GT
(
count
,
0
);
EXPECT_TRUE
((
count
>=
5240
)
&&
(
count
<=
5260
))
<<
"count is "
<<
count
<<
", expected range 5240-5260"
;
// Check that the agressivity limits the count of messages.
NakedRateControl
rc2
(
1000
,
3500
);
rc2
.
last_sent_
=
NakedRateControl
::
currentTime
()
-
boost
::
posix_time
::
seconds
(
5
)
-
boost
::
posix_time
::
milliseconds
(
250
);
ASSERT_NO_THROW
(
count
=
rc2
.
getOutboundMessageCount
());
EXPECT_EQ
(
3500
,
count
);
// Now, don't specify the rate. In this case the aggressivity dictates
// how many messages to send.
NakedRateControl
rc
2
(
0
,
3
);
rc
2
.
last_sent_
=
NakedRateControl
rc
3
(
0
,
3
);
rc
3
.
last_sent_
=
NakedRateControl
::
currentTime
()
-
boost
::
posix_time
::
seconds
(
5
);
ASSERT_NO_THROW
(
count
=
rc
2
.
getOutboundMessageCount
());
ASSERT_NO_THROW
(
count
=
rc
3
.
getOutboundMessageCount
());
EXPECT_EQ
(
3
,
count
);
// Specify the rate and set the timestamp of the last sent message well
// to the future. If the resulting due time is well in the future too,
// the number of messages to be sent must be 0.
NakedRateControl
rc
3
(
10
,
3
);
rc
3
.
last_sent_
=
NakedRateControl
::
currentTime
()
+
NakedRateControl
rc
4
(
10
,
3
);
rc
4
.
last_sent_
=
NakedRateControl
::
currentTime
()
+
boost
::
posix_time
::
seconds
(
5
);
ASSERT_NO_THROW
(
count
=
rc
3
.
getOutboundMessageCount
());
ASSERT_NO_THROW
(
count
=
rc
4
.
getOutboundMessageCount
());
EXPECT_EQ
(
0
,
count
);
}
...
...
Write
Preview
Supports
Markdown
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