1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include <gtest/gtest.h>
#include "kafka.h"
#include "sf_metrics.h"
uuid_t rule_uuid1;
uuid_t rule_uuid2;
uuid_t sff_uuid1;
uuid_t sff_uuid2;
uuid_t sf_uuid1;
uuid_t sf_uuid2;
#if 1
TEST(SF_METRICS, TEST1)
{
uint16_t thr_idx0 = 0;
uint16_t thr_idx1 = 1;
struct kafka *kfk = kafka_create("./test_resource/sce.conf");
EXPECT_TRUE(kfk != NULL);
struct sf_metrics *metrics = sf_metrics_create("./test_resource/sce.conf", kfk);
EXPECT_TRUE(metrics != NULL);
struct sf_metrics_key key1 = {0};
key1.vsys_id = 1;
uuid_copy(key1.rule_uuid, rule_uuid1);
uuid_copy(key1.sff_uuid, sff_uuid1);
uuid_copy(key1.sf_uuid, sf_uuid1);
struct sf_metrics_key key2 = {0};
key2.vsys_id = 4;
uuid_copy(key2.rule_uuid, rule_uuid2);
uuid_copy(key2.sff_uuid, sff_uuid2);
uuid_copy(key2.sf_uuid, sf_uuid2);
// thread 0
// rx_pkts, rx_bytes, tx_pkts, tx_bytes);
sf_metrics_input(metrics, thr_idx0, &key1, 1, 2, 2, 4);
sf_metrics_input(metrics, thr_idx0, &key2, 2, 4, 1, 2);
sf_metrics_output(metrics, thr_idx0);
sf_metrics_reset(metrics, thr_idx0);
printf("\n========================================\nworker thread 0 done\n========================================\n");
sleep(3);
// thread 1
sf_metrics_input(metrics, thr_idx1, &key1, 2, 4, 1, 2);
sf_metrics_input(metrics, thr_idx1, &key2, 1, 2, 2, 4);
sf_metrics_output(metrics, thr_idx1);
sf_metrics_reset(metrics, thr_idx1);
printf("\n========================================\nworker thread 1 done\n========================================\n");
sleep(3);
sf_metrics_destory(metrics);
kafka_destroy(kfk);
}
#endif
#if 1
TEST(SF_METRICS, TEST2)
{
uint16_t thr_idx0 = 0;
uint16_t thr_idx1 = 1;
struct kafka *kfk = kafka_create("./test_resource/sce.conf");
EXPECT_TRUE(kfk != NULL);
struct sf_metrics *metrics = sf_metrics_create("./test_resource/sce.conf", kfk);
EXPECT_TRUE(metrics != NULL);
struct sf_metrics_key key1 = {0};
key1.vsys_id = 1;
uuid_copy(key1.rule_uuid, rule_uuid1);
uuid_copy(key1.sff_uuid, sff_uuid1);
uuid_copy(key1.sf_uuid, sf_uuid1);
struct sf_metrics_key key2 = {0};
key2.vsys_id = 4;
uuid_copy(key2.rule_uuid, rule_uuid2);
uuid_copy(key2.sff_uuid, sff_uuid2);
uuid_copy(key2.sf_uuid, sf_uuid2);
// thread 0
// rx_pkts, rx_bytes, tx_pkts, tx_bytes);
sf_metrics_input(metrics, thr_idx0, &key1, 1, 2, 2, 4);
sf_metrics_input(metrics, thr_idx0, &key2, 2, 4, 1, 2);
sf_metrics_output(metrics, thr_idx0);
sf_metrics_reset(metrics, thr_idx0);
printf("\n========================================\nworker thread 0 done\n========================================\n");
// thread 1
sf_metrics_input(metrics, thr_idx1, &key1, 2, 4, 1, 2);
sf_metrics_input(metrics, thr_idx1, &key2, 1, 2, 2, 4);
sf_metrics_output(metrics, thr_idx1);
sf_metrics_reset(metrics, thr_idx1);
printf("\n========================================\nworker thread 1 done\n========================================\n");
sleep(3);
sf_metrics_destory(metrics);
kafka_destroy(kfk);
}
#endif
int main(int argc, char **argv)
{
uuid_parse("00000000-0000-0000-0000-000000000001", rule_uuid1);
uuid_parse("00000000-0000-0000-0000-000000000002", rule_uuid2);
uuid_parse("00000000-0000-0000-0000-000000000003", sff_uuid1);
uuid_parse("00000000-0000-0000-0000-000000000004", sff_uuid2);
uuid_parse("00000000-0000-0000-0000-000000000005", sf_uuid1);
uuid_parse("00000000-0000-0000-0000-000000000006", sf_uuid2);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|