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-…/test/gtest_data_pkt_stee_rx_egress.cpp
2024-09-27 19:11:47 +08:00

77 lines
4.1 KiB
C++

#include "gtest_utils.h"
// 160 bytes
static u_char ctrl_pkt_active[] = {
// Eth + IPv4 + TCP
0x48, 0x73, 0x97, 0x96, 0x38, 0x10, 0x0c, 0xa7, 0x5c, 0x64, 0x00, 0x01, 0x08, 0x00, 0x45, 0x00,
0x00, 0xab, 0x76, 0x23, 0x40, 0x00, 0x7d, 0x06, 0x67, 0x66, 0xc0, 0xa8, 0x29, 0x40, 0x5d, 0xb8,
0xd8, 0x22, 0xce, 0xec, 0x00, 0x50, 0xf8, 0x77, 0x0e, 0x1e, 0x47, 0x34, 0x32, 0xb9, 0x50, 0x18,
0x04, 0x88, 0x7a, 0xe8, 0x00, 0x00,
// msg payload
0x85, 0xA5, 0x74, 0x73, 0x79, 0x6E, 0x63, 0xA3, 0x32, 0x2E, 0x30, 0xAA, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x64, 0xCF, 0x04, 0x08, 0x02, 0x1B, 0x68, 0x4C, 0x04, 0x00, 0xA5,
0x73, 0x74, 0x61, 0x74, 0x65, 0xA6, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0xA6, 0x6D, 0x65, 0x74,
0x68, 0x6F, 0x64, 0xAD, 0x70, 0x6F, 0x6C, 0x69, 0x63, 0x79, 0x5F, 0x75, 0x70, 0x64, 0x61, 0x74,
0x65, 0xA6, 0x70, 0x61, 0x72, 0x61, 0x6D, 0x73, 0x81, 0xA3, 0x73, 0x63, 0x65, 0x81, 0xA8, 0x72,
0x75, 0x6C, 0x65, 0x5F, 0x69, 0x64, 0x73, 0x91, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
// 145 bytes
static u_char data_pkt[] = {
0x48, 0x73, 0x97, 0x96, 0x38, 0x10, 0x0c, 0xa7, 0x5c, 0x64, 0x00, 0x01, 0x08, 0x00, 0x45, 0x00,
0x00, 0x83, 0x46, 0x1f, 0x40, 0x00, 0x40, 0x06, 0xd4, 0x92, 0xc0, 0xa8, 0x29, 0x40, 0x5d, 0xb8,
0xd8, 0x22, 0xce, 0xec, 0x00, 0x50, 0xf8, 0x77, 0x0d, 0xcf, 0x47, 0x34, 0x32, 0xb9, 0x80, 0x18,
0xfa, 0xf0, 0xad, 0xf4, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x45, 0xfc, 0x39, 0x3d, 0xc1, 0x1f,
0x8d, 0x76, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31,
0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x77, 0x77, 0x77, 0x2e, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67,
0x65, 0x6e, 0x74, 0x3a, 0x20, 0x63, 0x75, 0x72, 0x6c, 0x2f, 0x37, 0x2e, 0x36, 0x31, 0x2e, 0x31,
0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, 0x2f, 0x2a, 0x0d, 0x0a, 0x0d,
0x0a};
TEST(PACKET_IO, DATA_PKT_STEE_RX_EGRESS)
{
marsio_buff_t *tx_mbuf1 = NULL;
marsio_buff_t *tx_mbuf2 = NULL;
marsio_buff_t *dup_mbuf1 = NULL;
marsio_buff_t *dup_mbuf2 = NULL;
marsio_buff_t *vxlan_mbuf = NULL;
struct gtest_frame *gtest_frame = NULL;
struct mr_instance *mr_instance = NULL;
build_mbuf_for_ctrl_pkt(tx_mbuf1, ctrl_pkt_active, sizeof(ctrl_pkt_active), 290484492702581760, 54);
build_mbuf_for_data_pkt(tx_mbuf2, data_pkt, sizeof(data_pkt), 290484492702581760, 0);
dup_mbuf1 = marsio_mbuff_dup(tx_mbuf1);
dup_mbuf2 = marsio_mbuff_dup(tx_mbuf2);
gtest_frame = gtest_frame_new("data_pkt_stee_forward.json", "data_pkt_stee_rx_egress");
mr_instance = packet_io_get_mr_instance(gtest_frame->sce_ctx->io);
// recv ctrl_pkt_active from nf
// send ctrl_pkt_active to nf
gtest_frame_run(gtest_frame, tx_mbuf1, dup_mbuf1, 1);
// recv data_pkt from nf
// send vxlan_pkt to sf
marsio_set_recv_mbuff(mr_instance, tx_mbuf2);
EXPECT_TRUE(packet_io_polling_nf(gtest_frame->sce_ctx->io, &gtest_frame->sce_ctx->work_threads[0]) == 1);
vxlan_mbuf = marsio_get_send_mbuff(mr_instance);
EXPECT_TRUE(mbuff_cmp_payload(dup_mbuf2, vxlan_mbuf) == 0);
// recv vxlan_pkt from sf
// send data_pkt to nf
marsio_set_recv_mbuff(mr_instance, vxlan_mbuf);
EXPECT_TRUE(packet_io_polling_endpoint_l3(gtest_frame->sce_ctx->io, &gtest_frame->sce_ctx->work_threads[0]) == 1);
EXPECT_TRUE(marsio_mbuff_cmp(dup_mbuf2, marsio_get_send_mbuff(mr_instance)) == 0);
gtest_frame_log(gtest_frame);
marsio_buff_free(packet_io_get_mr_instance(gtest_frame->sce_ctx->io), &tx_mbuf1, 1, 0, 0);
marsio_buff_free(packet_io_get_mr_instance(gtest_frame->sce_ctx->io), &tx_mbuf2, 1, 0, 0);
marsio_buff_free(packet_io_get_mr_instance(gtest_frame->sce_ctx->io), &dup_mbuf1, 1, 0, 0);
marsio_buff_free(packet_io_get_mr_instance(gtest_frame->sce_ctx->io), &dup_mbuf2, 1, 0, 0);
gtest_frame_free(gtest_frame);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}