TSG-8372, 增加三层vlan 自测试用例.
This commit is contained in:
@@ -34,11 +34,6 @@
|
||||
#define GTEST_SAPP_ERR (-1)
|
||||
#define GTEST_SAPP_SUCC 0
|
||||
|
||||
static void sendto_test_result(int n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static pcap_t *g_jmp_pcap_handle;
|
||||
|
||||
|
||||
@@ -1279,6 +1274,124 @@ TEST(jump_layer, eth_vlan_ip6_udp_gtpext_ip4_tcp)
|
||||
ASSERT_EQ(chk_res, 0);
|
||||
}
|
||||
|
||||
static void jump_layer_eth_vxlan_3vlan_ipv4_udp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
int ret;
|
||||
const void *eth_header = data;
|
||||
const void *outer_ipv4_header;
|
||||
const void *outer_udp_header;
|
||||
//const void *gtp_header;
|
||||
const void *inner_ipv4_header;
|
||||
|
||||
outer_ipv4_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(NULL == outer_ipv4_header){
|
||||
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv4 error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
ret = jump_check_ipv4_pkt((struct ip *)outer_ipv4_header, 209, IPPROTO_UDP, "10.10.0.8", "10.252.20.1");
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
outer_udp_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
||||
if(NULL == outer_udp_header){
|
||||
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->vlan->ipv6->udp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
ret = jump_check_udp_pkt((const struct udphdr *)outer_udp_header, 189, 61717, 4789);
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const struct ethhdr *inner_mac_header = (struct ethhdr *)MESA_jump_layer_greedy(outer_ipv4_header, ADDR_TYPE_IPV4, ADDR_TYPE_MAC);
|
||||
if(NULL == inner_mac_header){
|
||||
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->mac error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned char expect_src_mac[6] = {0x6c, 0x3b, 0x6b, 0xc0, 0x01, 0x1f};
|
||||
const unsigned char expect_dst_mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
|
||||
if(memcmp(inner_mac_header->h_source, expect_src_mac, 6) != 0){
|
||||
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->src_mac error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
if(memcmp(inner_mac_header->h_dest, expect_dst_mac, 6) != 0){
|
||||
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->dst_mac error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
inner_ipv4_header = ( struct ip *)MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(NULL == inner_ipv4_header){
|
||||
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->gtp->ipv4 error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = jump_check_ipv4_pkt((struct ip *)inner_ipv4_header, 147, IPPROTO_UDP, "0.0.0.0", "255.255.255.255");
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const void *greedy_udp_hdr = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
||||
if(NULL == greedy_udp_hdr){
|
||||
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): greedy jump eth->vlan->ipv6->udp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
ret = jump_check_udp_pkt((const struct udphdr *)greedy_udp_hdr, 127, 5678, 5678);
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\033[32m jump_layer_eth_vxlan_3vlan_ipv4_udp() test succ\033[0m\n");
|
||||
|
||||
*result_val = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#define __jump_layer_eth_vxlan_3vlan_ipv4_udp 1
|
||||
TEST(jump_layer, eth_vxlan_3vlan_ipv4_udp)
|
||||
{
|
||||
int fun_ret;
|
||||
u_char chk_res = -1;
|
||||
|
||||
fun_ret = jmp_file_md5_checksum("./sample_pcap/vxlan_inner_3_vlan_udp.pcap", "3d9da66edfe7e8958f797ca57fff9ba5");
|
||||
ASSERT_EQ(fun_ret, 0);
|
||||
|
||||
fun_ret = jmp_pcap_init("./sample_pcap/vxlan_inner_3_vlan_udp.pcap", jump_layer_eth_vxlan_3vlan_ipv4_udp, (u_char *)&chk_res);
|
||||
ASSERT_EQ(fun_ret, 0);
|
||||
|
||||
ASSERT_EQ(chk_res, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
基础协议跳转测试用例;
|
||||
各种隧道嵌套协议跳转测试用例.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
BIN
test/sample_pcap/vxlan_inner_3_vlan_udp.pcap
Normal file
BIN
test/sample_pcap/vxlan_inner_3_vlan_udp.pcap
Normal file
Binary file not shown.
Reference in New Issue
Block a user