feature: TSG-21852 service_chaining_rule_hits support fieldstat4
This commit is contained in:
@@ -1,29 +1,98 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "kafka.h"
|
||||
#include "sf_metrics.h"
|
||||
|
||||
TEST(SF_METRICS, TEST)
|
||||
#if 1
|
||||
TEST(SF_METRICS, TEST1)
|
||||
{
|
||||
struct sf_metrics *metrics = sf_metrics_create("./test_resource/sce.conf");
|
||||
EXPECT_TRUE(sf_metrics_get_interval(metrics) == 1);
|
||||
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.rule_id = 1;
|
||||
key1.sff_profile_id = 2;
|
||||
key1.sf_profile_id = 3;
|
||||
key1.vsys_id = 4;
|
||||
sf_metrics_inc(metrics, &key1, 4, 5, 6, 7);
|
||||
|
||||
key1.vsys_id = 1;
|
||||
key1.rule_id = 2;
|
||||
key1.sff_profile_id = 3;
|
||||
key1.sf_profile_id = 4;
|
||||
struct sf_metrics_key key2 = {0};
|
||||
key2.rule_id = 1;
|
||||
key2.sff_profile_id = 2;
|
||||
key2.sf_profile_id = 3;
|
||||
key2.vsys_id = 4;
|
||||
sf_metrics_inc(metrics, &key2, 4, 5, 6, 7);
|
||||
key2.rule_id = 3;
|
||||
key2.sff_profile_id = 2;
|
||||
key2.sf_profile_id = 1;
|
||||
|
||||
// thread 0
|
||||
// uint64_t rx_pkts, uint64_t rx_bytes, uint64_t tx_pkts, uint64_t 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_send(metrics);
|
||||
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;
|
||||
key1.rule_id = 2;
|
||||
key1.sff_profile_id = 3;
|
||||
key1.sf_profile_id = 4;
|
||||
struct sf_metrics_key key2 = {0};
|
||||
key2.vsys_id = 4;
|
||||
key2.rule_id = 3;
|
||||
key2.sff_profile_id = 2;
|
||||
key2.sf_profile_id = 1;
|
||||
|
||||
// thread 0
|
||||
// uint64_t rx_pkts, uint64_t rx_bytes, uint64_t tx_pkts, uint64_t 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)
|
||||
{
|
||||
|
||||
@@ -23,14 +23,25 @@ redis_server=127.0.0.1
|
||||
redis_port_range=6379
|
||||
|
||||
[metrics]
|
||||
# Kafka Topic: POLICY-RULE-METRICS
|
||||
# Kafka Topic: POLICY-RULE-METRIC
|
||||
enable=1
|
||||
interval_s=1
|
||||
telegraf_bind_address=127.0.0.1
|
||||
telegraf_listen_port=8300
|
||||
output_fs_interval_ms=500
|
||||
output_kafka_interval_ms=1000
|
||||
data_center=center-xxg-tsgx
|
||||
device_group=group-xxg-tsgx
|
||||
device_id=9800165603247024
|
||||
|
||||
[bfdd]
|
||||
path=/var/run/frr/bfdd.vty
|
||||
device=eth0
|
||||
local_address=127.0.0.1
|
||||
gateway=127.0.0.1
|
||||
gateway=127.0.0.1
|
||||
|
||||
[kafka]
|
||||
brokerlist=192.168.40.224:9092
|
||||
sasl_username=admin
|
||||
sasl_passwd=galaxy2019
|
||||
topic_name=POLICY-RULE-METRIC
|
||||
Reference in New Issue
Block a user