|
@@ -14,10 +14,14 @@
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
+#include <string>
|
|
|
+
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
+#include <dns/opcode.h>
|
|
|
+
|
|
|
#include <cc/data.h>
|
|
|
#include <cc/session.h>
|
|
|
|
|
@@ -170,6 +174,16 @@ TEST_F(AuthCountersTest, incrementInvalidCounter) {
|
|
|
isc::OutOfRange);
|
|
|
}
|
|
|
|
|
|
+TEST_F(AuthCountersTest, incrementOpcodeCounter) {
|
|
|
+ // The counter should be initialized to 0. If we increment it by 1
|
|
|
+ // the counter should be 1.
|
|
|
+ for (int i = 0; i < 16; ++i) {
|
|
|
+ EXPECT_EQ(0, counters.getCounter(Opcode(i)));
|
|
|
+ counters.inc(Opcode(i));
|
|
|
+ EXPECT_EQ(1, counters.getCounter(Opcode(i)));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(AuthCountersTest, submitStatisticsWithoutSession) {
|
|
|
// Set statistics_session to NULL and call submitStatistics().
|
|
|
// Expect to return false.
|
|
@@ -189,6 +203,28 @@ TEST_F(AuthCountersTest, submitStatisticsWithException) {
|
|
|
statistics_session_.setThrowSessionTimeout(false);
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+opcodeDataCheck(ConstElementPtr data, const int expected[16]) {
|
|
|
+ const char* item_names[] = {
|
|
|
+ "query", "iquery", "status", "reserved3", "notify", "update",
|
|
|
+ "reserved6", "reserved7", "reserved8", "reserved9", "reserved10",
|
|
|
+ "reserved11", "reserved12", "reserved13", "reserved14", "reserved15",
|
|
|
+ NULL
|
|
|
+ };
|
|
|
+ int i;
|
|
|
+ for (i = 0; i < 16; ++i) {
|
|
|
+ ASSERT_NE(static_cast<const char*>(NULL), item_names[i]);
|
|
|
+ const string item_name = "opcode." + string(item_names[i]);
|
|
|
+ if (expected[i] == 0) {
|
|
|
+ EXPECT_FALSE(data->get(item_name));
|
|
|
+ } else {
|
|
|
+ EXPECT_EQ(expected[i], data->get(item_name)->intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // We should have examined all names
|
|
|
+ ASSERT_EQ(static_cast<const char*>(NULL), item_names[i]);
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(AuthCountersTest, submitStatisticsWithoutValidator) {
|
|
|
// Submit statistics data.
|
|
|
// Validate if it submits correct data.
|
|
@@ -217,6 +253,44 @@ TEST_F(AuthCountersTest, submitStatisticsWithoutValidator) {
|
|
|
// UDP query counter is 2 and TCP query counter is 1.
|
|
|
EXPECT_EQ(2, statistics_data->get("queries.udp")->intValue());
|
|
|
EXPECT_EQ(1, statistics_data->get("queries.tcp")->intValue());
|
|
|
+
|
|
|
+ // By default opcode counters are all 0 and omitted
|
|
|
+ const int opcode_results[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
+ opcodeDataCheck(statistics_data, opcode_results);
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+updateOpcodeCounters(AuthCounters &counters, const int expected[16]) {
|
|
|
+ for (int i = 0; i < 16; ++i) {
|
|
|
+ for (int j = 0; j < expected[i]; ++j) {
|
|
|
+ counters.inc(Opcode(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(AuthCountersTest, submitStatisticsWithOpcodeCounters) {
|
|
|
+ // Increment some of the opcode counters. Then they should appear in the
|
|
|
+ // submitted data; others shouldn't
|
|
|
+ const int opcode_results[16] = { 1, 2, 3, 0, 4, 5, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
+ updateOpcodeCounters(counters, opcode_results);
|
|
|
+ counters.submitStatistics();
|
|
|
+ ConstElementPtr statistics_data = statistics_session_.sent_msg
|
|
|
+ ->get("command")->get(1)->get("data");
|
|
|
+ opcodeDataCheck(statistics_data, opcode_results);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(AuthCountersTest, submitStatisticsWithAllOpcodeCounters) {
|
|
|
+ // Increment all opcode counters. Then they should appear in the
|
|
|
+ // submitted data.
|
|
|
+ const int opcode_results[16] = { 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
+ 1, 1, 1, 1, 1, 1, 1, 1 };
|
|
|
+ updateOpcodeCounters(counters, opcode_results);
|
|
|
+ counters.submitStatistics();
|
|
|
+ ConstElementPtr statistics_data = statistics_session_.sent_msg
|
|
|
+ ->get("command")->get(1)->get("data");
|
|
|
+ opcodeDataCheck(statistics_data, opcode_results);
|
|
|
}
|
|
|
|
|
|
TEST_F(AuthCountersTest, submitStatisticsWithValidator) {
|