TSG-13500 tsg-service-chaining-engine扫描策略
This commit is contained in:
17
platform/test/CMakeLists.txt
Normal file
17
platform/test/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
###############################################################################
|
||||
# gtest_policy
|
||||
###############################################################################
|
||||
|
||||
add_executable(gtest_policy gtest_policy.cpp)
|
||||
target_include_directories(gtest_policy PUBLIC ${CMAKE_SOURCE_DIR}/common/include)
|
||||
target_include_directories(gtest_policy PUBLIC ${CMAKE_SOURCE_DIR}/platform/include)
|
||||
target_link_libraries(gtest_policy common platform gtest)
|
||||
|
||||
###############################################################################
|
||||
# gtest_discover_tests
|
||||
###############################################################################
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_policy)
|
||||
|
||||
file(COPY ./test_resource/ DESTINATION ./test_resource/)
|
||||
54
platform/test/gtest_policy.cpp
Normal file
54
platform/test/gtest_policy.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "policy.h"
|
||||
#include "raw_packet.h"
|
||||
|
||||
unsigned char data1[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xa4, 0xc6, 0x4f, 0x3b, 0xb3, 0x9a, 0x81, 0x00, 0x66, 0x58, 0x81, 0x00, 0x61, 0xf9, 0x08, 0x00, 0x45, 0xb8, 0x00, 0x94,
|
||||
0xe8, 0x58, 0x00, 0x00, 0xff, 0x04, 0x11, 0x48, 0x45, 0x43, 0x23, 0x92, 0x29, 0xca, 0x2e, 0x6e, 0x45, 0xb8, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00, 0xfe, 0x11,
|
||||
0xde, 0x84, 0x0a, 0x0a, 0x64, 0x19, 0x0a, 0x0a, 0x65, 0x02, 0xf3, 0x9f, 0x42, 0x68, 0x00, 0x6c, 0x4b, 0x9a, 0x00, 0x02, 0x00, 0x00, 0x04, 0x73, 0x6c, 0x10,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
|
||||
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
|
||||
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
|
||||
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd};
|
||||
|
||||
TEST(POLICY, SELECTED_CHAINING_LIFE_CYCLE)
|
||||
{
|
||||
struct selected_chaining *chaining = NULL;
|
||||
|
||||
chaining = selected_chaining_create(128);
|
||||
EXPECT_TRUE(chaining != nullptr);
|
||||
|
||||
selected_chaining_destory(chaining);
|
||||
}
|
||||
|
||||
TEST(POLICY, POLICY_ENFORCER_LIFE_CYCLE)
|
||||
{
|
||||
struct raw_pkt_parser *parser = raw_packet_parser_create(LAYER_TYPE_ALL, 8);
|
||||
EXPECT_TRUE(parser != nullptr);
|
||||
const void *payload = raw_packet_parser_parse(parser, (const void *)data1, sizeof(data1));
|
||||
EXPECT_TRUE(payload != nullptr);
|
||||
EXPECT_TRUE((char *)payload - (char *)&data1 == 70);
|
||||
|
||||
const char *profile = "./test_resource/sce.conf";
|
||||
struct policy_enforcer *enforcer = policy_enforcer_create("SCE", profile, 8, NULL);
|
||||
EXPECT_TRUE(enforcer != nullptr);
|
||||
EXPECT_TRUE(policy_enforcer_register(enforcer) == 0);
|
||||
|
||||
int policy_id = 2;
|
||||
int dir_is_internal = 1;
|
||||
struct selected_chaining *chaining = policy_enforce_select_chaining(enforcer, parser, policy_id, dir_is_internal);
|
||||
EXPECT_TRUE(chaining != nullptr);
|
||||
selected_chaining_dump(chaining);
|
||||
selected_chaining_bref(chaining);
|
||||
|
||||
selected_chaining_destory(chaining);
|
||||
policy_enforcer_destory(enforcer);
|
||||
raw_packet_parser_destory(parser);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
21
platform/test/test_resource/sce.conf
Normal file
21
platform/test/test_resource/sce.conf
Normal file
@@ -0,0 +1,21 @@
|
||||
[system]
|
||||
nr_worker_threads=8
|
||||
|
||||
[maat]
|
||||
# 0:json 1:redis 2:iris
|
||||
input_mode=0
|
||||
stat_switch=1
|
||||
perf_switch=1
|
||||
scan_detail=0
|
||||
deferred_load=0
|
||||
effect_interval_ms=1000
|
||||
stat_file=./sce.fs2
|
||||
table_info=test_resource/table_info.conf
|
||||
accept_path=/opt/tsg/etc/tsg_device_tag.json
|
||||
inc_cfg_dir=test_resource/inc/
|
||||
ful_cfg_dir=test_resource/ful/
|
||||
json_cfg_file=test_resource/sce.json
|
||||
foreign_cont_dir=test_resource/foreign_files
|
||||
redis_db_idx=0
|
||||
redis_server=127.0.0.1
|
||||
redis_port_range=6379
|
||||
41
platform/test/test_resource/sce.json
Normal file
41
platform/test/test_resource/sce.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"plugin_table": [
|
||||
{
|
||||
"table_name": "SERVICE_FUNCTION_PROFILE",
|
||||
"table_content": [
|
||||
"1\tdevice_group_a\t1\t{\"method\":\"vxlan_g\",\"dest_ip\":\"1.1.1.1\"}\t{\"method\":\"none\"}\t1",
|
||||
"2\tdevice_group_a\t1\t{\"method\":\"vxlan_g\",\"dest_ip\":\"1.1.1.1\"}\t{\"method\":\"bfd\",\"address\":\"1.2.3.4\",\"port\":\"10000\",\"interval_ms\":100,\"retires\":5}\t1",
|
||||
"3\tdevice_group_a\t1\t{\"method\":\"vxlan_g\",\"dest_ip\":\"1.1.1.1\"}\t{\"method\":\"in_band_bfd\",\"address\":\"1.2.3.4\",\"port\":\"10000\",\"interval_ms\":100,\"retires\":5}\t1",
|
||||
"4\tdevice_group_a\t1\t{\"method\":\"vxlan_g\",\"dest_ip\":\"1.1.1.1\"}\t{\"method\":\"http\",\"url\":\"http://192.168.100.1:8080/health_check.index\",\"interval_ms\":100,\"retires\":5}\t1",
|
||||
"5\tdevice_group_a\t1\t{\"method\":\"layer2_switch\",\"int_vlan_tag\":10,\"ext_vlan_tag\":5}\t{\"method\":\"none\"}\t1",
|
||||
"6\tdevice_group_a\t1\t{\"method\":\"layer3_switch\",\"int_vlan_tag\":10,\"ext_vlan_tag\":5}\t{\"method\":\"none\"}\t1",
|
||||
"7\tdevice_group_a\t0\t{\"method\":\"layer3_switch\",\"int_vlan_tag\":10,\"ext_vlan_tag\":5}\t{\"method\":\"none\"}\t1",
|
||||
"8\tdevice_group_b\t0\t{\"method\":\"layer3_switch\",\"int_vlan_tag\":10,\"ext_vlan_tag\":5}\t{\"method\":\"none\"}\t1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "SERVICE_FUNCTION_FORWARDER_PROFILE",
|
||||
"table_content": [
|
||||
"1\t1\thash-int-ip\tnearby\tbypass\tnull\t[1]\t1",
|
||||
"2\t1\thash-int-ip\tnearby\tbypass\tnull\t[1,2,3,4,5,6,7,8]\t1",
|
||||
"3\t1\thash-int-ip\tnearby\tblock\tnull\t[1]\t1",
|
||||
"4\t1\thash-int-ip\tnearby\tre-dispatch\t{\"action\":\"bypass\",\"health_service_func_lt\":2}\t[1,2,3]\t1",
|
||||
"5\t1\thash-int-ip\tnearby\tre-dispatch\t{\"action\":\"block\"}\t[1,2,3]\t1",
|
||||
"6\t1\thash-int-ip\tglobal\tblock\tnull\t[1]\t1",
|
||||
"7\t1\thash-ext-ip\tglobal\tblock\tnull\t[1]\t1",
|
||||
"8\t1\thash-int-ip-and-ext-ip\tglobal\tblock\tnull\t[1]\t1",
|
||||
"9\t1\thash-innermost-int-ip\tglobal\tblock\tnull\t[1]\t1",
|
||||
"10\t2\thash-innermost-int-ip\tglobal\tblock\tnull\t[1]\t1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "SERVICE_CHAINING_COMPILE",
|
||||
"table_content": [
|
||||
"1\t0\t2\t1\t1\t{}\t{\"targeted_traffic\":\"raw\",\"sff_profiles\":[1]}\t1\t2",
|
||||
"2\t0\t2\t1\t1\t{}\t{\"targeted_traffic\":\"raw\",\"sff_profiles\":[1,2,3,4,5,6,7,8,9,10]}\t1\t2",
|
||||
"11\t0\t2\t1\t1\t{}\t{\"targeted_traffic\":\"decrypted\",\"sff_profiles\":[1]}\t1\t2",
|
||||
"12\t0\t2\t1\t1\t{}\t{\"targeted_traffic\":\"decrypted\",\"sff_profiles\":[1,2,3,4,5,6,7,8,9,10]}\t1\t2"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
3
platform/test/test_resource/table_info.conf
Normal file
3
platform/test/test_resource/table_info.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
0 SERVICE_CHAINING_COMPILE plugin {"key":1,"valid":8}
|
||||
1 SERVICE_FUNCTION_FORWARDER_PROFILE plugin {"key":1,"valid":8}
|
||||
2 SERVICE_FUNCTION_PROFILE plugin {"key":1,"valid":6}
|
||||
Reference in New Issue
Block a user