Add support for parsing PW Ethernet and Enhanced MPLS parsing

This commit is contained in:
luwenpeng
2024-06-02 00:07:33 +08:00
parent f3b92a8a15
commit 18fe1e2e41
13 changed files with 615 additions and 250 deletions

View File

@@ -0,0 +1,42 @@
#include <gtest/gtest.h>
#include "mpls_utils.h"
/*
* MultiProtocol Label Switching Header, Label: 779408, Exp: 0, S: 0, TTL: 255
* 1011 1110 0100 1001 0000 .... .... .... = MPLS Label: 779408 (0xbe490)
* .... .... .... .... .... 000. .... .... = MPLS Experimental Bits: 0
* .... .... .... .... .... ...0 .... .... = MPLS Bottom Of Label Stack: 0
* .... .... .... .... .... .... 1111 1111 = MPLS TTL: 255
*/
unsigned char data[] = {
0xbe, 0x49, 0x00, 0xff};
TEST(MPLS_UTILS, GET)
{
const struct mpls_hdr *hdr = (struct mpls_hdr *)data;
EXPECT_TRUE(mpls_hdr_get_label(hdr) == 0xbe490);
EXPECT_TRUE(mpls_hdr_get_exp(hdr) == 0);
EXPECT_TRUE(mpls_hdr_get_bos(hdr) == 0);
EXPECT_TRUE(mpls_hdr_get_ttl(hdr) == 255);
}
TEST(MPLS_UTILS, SET)
{
char buff[4] = {0};
struct mpls_hdr *hdr = (struct mpls_hdr *)buff;
mpls_hdr_set_label(hdr, 0xbe490);
mpls_hdr_set_exp(hdr, 0);
mpls_hdr_set_bos(hdr, 0);
mpls_hdr_set_ttl(hdr, 255);
EXPECT_TRUE(memcmp(buff, data, 4) == 0);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}