This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tsg-service-chaining-…/platform/test/gtest_policy.cpp

70 lines
2.8 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "sce.h"
#include "policy.h"
#include "raw_packet.h"
#include "global_metrics.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 global_metrics g_metrics;
struct thread_ctx t_ctx;
struct session_ctx s_ctx;
t_ctx.ref_metrics = &g_metrics;
s_ctx.ref_thread_ctx = &t_ctx;
struct raw_pkt_parser handler;
raw_packet_parser_init(&handler, 0, LAYER_TYPE_ALL, 8);
const void *payload = raw_packet_parser_parse(&handler, (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 dir_is_internal = 1;
struct selected_chaining *chaining = selected_chaining_create(64);
EXPECT_TRUE(chaining != nullptr);
policy_enforce_select_chaining(chaining, enforcer, &handler, 1, dir_is_internal, &s_ctx);
policy_enforce_select_chaining(chaining, enforcer, &handler, 2, dir_is_internal, &s_ctx);
policy_enforce_select_chaining(chaining, enforcer, &handler, 11, dir_is_internal, &s_ctx);
policy_enforce_select_chaining(chaining, enforcer, &handler, 12, dir_is_internal, &s_ctx);
selected_chaining_dump(chaining);
selected_chaining_bref(chaining);
selected_chaining_destory(chaining);
printf("Before Sleep\n");
sleep(15);
printf("After Sleep\n");
policy_enforcer_destory(enforcer);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}