diff options
| author | Lu Qiuwen <[email protected]> | 2021-11-16 23:41:52 +0300 |
|---|---|---|
| committer | Lu Qiuwen <[email protected]> | 2021-11-16 23:52:06 +0300 |
| commit | ad801d927c33328d242ed989ed5b813a8e319228 (patch) | |
| tree | 74f0380e35ef934f6145d591c169a2521f167b71 /infra/test/TestDistributer.cc | |
| parent | 6c0a8ae4c86f588522c476257c67f46a16bf28d2 (diff) | |
增加GTP-over-VXLAN封装报文的内层二元组、四元组解析功能。v4.4.11-2021117rel-4.4dev-4.4
Diffstat (limited to 'infra/test/TestDistributer.cc')
| -rw-r--r-- | infra/test/TestDistributer.cc | 346 |
1 files changed, 304 insertions, 42 deletions
diff --git a/infra/test/TestDistributer.cc b/infra/test/TestDistributer.cc index c3d9a37..414054f 100644 --- a/infra/test/TestDistributer.cc +++ b/infra/test/TestDistributer.cc @@ -19,6 +19,14 @@ extern "C" #define TEST_PCAP_FILE_PREFIX "" #endif +using test_table_t = std::tuple<const char *, enum e_dist_mode, enum e_hash_mode, const char *, const char *, uint16_t, uint16_t>; + +extern "C" +{ +extern uint32_t EXPORT_FOR_UNITTEST_hash_sym_crc(struct distributer * dist, const void * data, int layer_type, uint32_t orin_hash); +extern uint32_t EXPORT_FOR_UNITTEST_hash_sym_rss(struct distributer * dist, const void * data, int layer_type, uint32_t orin_hash); +} + class PacketLoader { private: @@ -68,15 +76,12 @@ public: } }; -class TestFixtureDistributer : public ::testing::TestWithParam< - std::tuple<const char *, enum e_dist_mode, enum e_hash_mode>> +class TestFixtureDistributer : public ::testing::TestWithParam<test_table_t> { void SetUp() override { /* Load Test Param */ - auto * pcap_file = std::get<0>(GetParam()); - dist_mode_ = std::get<1>(GetParam()); - hash_mode_ = std::get<2>(GetParam()); + auto *pcap_file = std::get<0>(GetParam()); /* Perpare PCAP reader */ pkt_loader_ = new PacketLoader(); @@ -85,7 +90,48 @@ class TestFixtureDistributer : public ::testing::TestWithParam< pkt_loader_->LoadFromPcapFile(testfile); /* Prepare Distributer Handle */ + dist_mode_ = std::get<1>(GetParam()); + hash_mode_ = std::get<2>(GetParam()); dist_object_ = distributer_create(dist_mode_, hash_mode_, 0); + + /* Retrive the expected SIP, DIP, SPORT, DPORT */ + uint32_t sip = 0; + uint32_t dip = 0; + + const char *str_sip = std::get<3>(GetParam()); + const char *str_dip = std::get<4>(GetParam()); + uint16_t sport = htons(std::get<5>(GetParam())); + uint16_t dport = htons(std::get<6>(GetParam())); + + ASSERT_EQ(inet_pton(AF_INET, str_sip, &sip), 1); + ASSERT_EQ(inet_pton(AF_INET, str_dip, &dip), 1); + + /* Perpare fake headers to caculate the hash values */ + struct rte_ipv4_hdr ipv4_hdr_expected {}; + ipv4_hdr_expected.src_addr = sip; + ipv4_hdr_expected.dst_addr = dip; + + struct __fake_tcp_or_udp_hdr { + uint16_t sport; + uint16_t dport; + } fake_tcp_or_udp_hdr{sport, dport}; + + expected_hash_value_ = 0; + if (dist_object_->fn_hash_0 != nullptr) + { + expected_hash_value_ = dist_object_->fn_hash_0( + dist_object_, (const void *) &ipv4_hdr_expected, LAYER_TYPE_IPV4, dist_object_->orin_hash); + } + + if (dist_mode_ == LDBC_DIST_OUTER_TUPLE4 || dist_mode_ == LDBC_DIST_INNER_TUPLE4) + { + if (dist_object_->fn_hash_1 != nullptr) + { + expected_hash_value_ = dist_object_->fn_hash_1( + dist_object_, (const void *) &fake_tcp_or_udp_hdr, + LAYER_TYPE_TCP, expected_hash_value_); + } + } } void TearDown() override @@ -98,98 +144,314 @@ protected: enum e_dist_mode dist_mode_; enum e_hash_mode hash_mode_; struct distributer * dist_object_; + uint32_t expected_hash_value_; }; TEST_P(TestFixtureDistributer, TestDistHashResult) { - uint32_t hash_result{0}; - bool hash_result_set{false}; - for (auto m = pkt_loader_->FetchPacket(); m != nullptr; m = pkt_loader_->FetchPacket()) { struct rte_mbuf * __mbuf = m.get(); distributer_caculate(dist_object_, &__mbuf, 1); - - if (hash_result_set) - { - EXPECT_EQ(m->hash.usr, hash_result); - } - else - { - hash_result_set = true; - hash_result = m->hash.usr; - } + EXPECT_EQ(m->hash.usr, expected_hash_value_); } - - EXPECT_NE(hash_result, 0); } -std::tuple<const char *, enum e_dist_mode, enum e_hash_mode> testTable[] +test_table_t testTable[] { + /* Frame 1: 195 bytes on wire (1560 bits), 195 bytes captured (1560 bits) + Ethernet II, Src: HuaweiTe_2f:a8:08 (34:0a:98:2f:a8:08), Dst: 5a:78:88:20:66:db (5a:78:88:20:66:db) + Internet Protocol Version 4, Src: 10.4.127.4, Dst: 10.4.36.1 + User Datagram Protocol, Src Port: 10000, Dst Port: 4789 + Virtual eXtensible Local Area Network + Ethernet II, Src: JuniperN_46:5f:c7 (00:24:dc:46:5f:c7), Dst: JuniperN_a5:bb:f5 (3c:61:04:a5:bb:f5) + MultiProtocol Label Switching Header, Label: 444673, Exp: 1, S: 1, TTL: 125 + Internet Protocol Version 4, Src: 178.89.4.219, Dst: 117.122.217.89 + Transmission Control Protocol, Src Port: 58062, Dst Port: 443, Seq: 1, Ack: 1, Len: 87 + Transport Layer Security + */ std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", LDBC_DIST_INNER_TUPLE2, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.219", + "117.122.217.89", + 58062, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", LDBC_DIST_INNER_TUPLE2, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.219", + "117.122.217.89", + 58062, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", LDBC_DIST_INNER_TUPLE4, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.219", + "117.122.217.89", + 58062, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", LDBC_DIST_INNER_TUPLE4, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.219", + "117.122.217.89", + 58062, + 443), + + /* Frame 1: 1498 bytes on wire (11984 bits), 1498 bytes captured (11984 bits) + Ethernet II, Src: 00:00:00_00:04:34 (00:00:00:00:04:34), Dst: 18:10:04:00:01:26 (18:10:04:00:01:26) + MultiProtocol Label Switching Header, Label: 594864, Exp: 0, S: 0, TTL: 60 + MultiProtocol Label Switching Header, Label: 18, Exp: 0, S: 1, TTL: 60 + Internet Protocol Version 4, Src: 172.16.51.180, Dst: 10.224.139.116 + User Datagram Protocol, Src Port: 2152, Dst Port: 2152 + GPRS Tunneling Protocol + Internet Protocol Version 4, Src: 149.3.200.32, Dst: 100.95.37.122 + Transmission Control Protocol, Src Port: 443, Dst Port: 44672, Seq: 1, Ack: 1, Len: 1388 + Transport Layer Security + */ + + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_OUTER_TUPLE2, + LDBC_HASH_SYM_CRC, + "172.16.51.180", + "10.224.139.116", + 2152, + 2152), + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_OUTER_TUPLE2, + LDBC_HASH_SYM_RSS, + "172.16.51.180", + "10.224.139.116", + 2152, + 2152), + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_CRC, + "172.16.51.180", + "10.224.139.116", + 2152, + 2152), + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_RSS, + "172.16.51.180", + "10.224.139.116", + 2152, + 2152), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE2, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "149.3.200.32", + "100.95.37.122", + 443, + 44672), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE2, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "149.3.200.32", + "100.95.37.122", + 443, + 44672), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE4, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "149.3.200.32", + "100.95.37.122", + 443, + 44672), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE4, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "149.3.200.32", + "100.95.37.122", + 443, + 44672), + + /*Frame 1: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) + Ethernet II, Src: 5f:c2:88:47:7f:7f (5f:c2:88:47:7f:7f), Dst: 0d:6a:00:24:dc:46 (0d:6a:00:24:dc:46) + Internet Protocol Version 4, Src: 178.89.4.219, Dst: 213.180.204.183 + Transmission Control Protocol, Src Port: 55189, Dst Port: 443, Seq: 0, Len: 0 */ + std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.219", + "213.180.204.183", + 55189, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.219", + "213.180.204.183", + 55189, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.219", + "213.180.204.183", + 55189, + 443), std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.219", + "213.180.204.183", + 55189, + 443), + + /* + Frame 1: 214 bytes on wire (1712 bits), 214 bytes captured (1712 bits) + Ethernet II, Src: 00:00:00_00:04:10 (00:00:00:00:04:10), Dst: 18:10:04:00:00:26 (18:10:04:00:00:26) + MultiProtocol Label Switching Header, Label: 506305, Exp: 1, S: 1, TTL: 61 + Internet Protocol Version 4, Src: 178.89.4.221, Dst: 31.13.70.49 + Transmission Control Protocol, Src Port: 58100, Dst Port: 443, Seq: 1, Ack: 1, Len: 144 + Transport Layer Security + */ + std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.221", + "31.13.70.49", + 58100, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.221", + "31.13.70.49", + 58100, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.221", + "31.13.70.49", + 58100, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.221", + "31.13.70.49", + 58100, + 443), + + /* Frame 1: 82 bytes on wire (656 bits), 82 bytes captured (656 bits) + Ethernet II, Src: 00:00:00_00:04:10 (00:00:00:00:04:10), Dst: 18:10:04:00:00:26 (18:10:04:00:00:26) + MultiProtocol Label Switching Header, Label: 506305, Exp: 1, S: 1, TTL: 61 + Internet Protocol Version 4, Src: 178.89.4.221, Dst: 31.13.70.49 + Transmission Control Protocol, Src Port: 54282, Dst Port: 443, Seq: 0, Len: 0 + */ + std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.221", + "31.13.70.49", + 54282, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.221", + "31.13.70.49", + 54282, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_CRC), + LDBC_HASH_SYM_CRC, + "178.89.4.221", + "31.13.70.49", + 54282, + 443), std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE4, - LDBC_HASH_SYM_RSS), + LDBC_HASH_SYM_RSS, + "178.89.4.221", + "31.13.70.49", + 54282, + 443), + + /* + Frame 1: 168 bytes on wire (1344 bits), 168 bytes captured (1344 bits) + Ethernet II, Src: 0a:0a:0a:0a:00:10 (0a:0a:0a:0a:00:10), Dst: 90:00:00:91:40:46 (90:00:00:91:40:46) + Internet Protocol Version 4, Src: 10.10.0.16, Dst: 10.252.22.1 + User Datagram Protocol, Src Port: 61163, Dst Port: 4789 + Virtual eXtensible Local Area Network + Ethernet II, Src: HuaweiTe_2a:dc:03 (10:51:72:2a:dc:03), Dst: Broadcast (ff:ff:ff:ff:ff:ff) + 802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 600 + Internet Protocol Version 4, Src: 10.254.142.4, Dst: 197.156.73.235 + User Datagram Protocol, Src Port: 65535, Dst Port: 2152 + GPRS Tunneling Protocol + Internet Protocol Version 4, Src: 10.23.160.163, Dst: 129.226.103.217 + Transmission Control Protocol, Src Port: 8235, Dst Port: 80, Seq: 0, Len: 0 + */ + + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_OUTER_TUPLE2, + LDBC_HASH_SYM_CRC, + "10.10.0.16", + "10.252.22.1", + 61163, + 4789), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_OUTER_TUPLE2, + LDBC_HASH_SYM_RSS, + "10.10.0.16", + "10.252.22.1", + 61163, + 4789), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_CRC, + "10.10.0.16", + "10.252.22.1", + 61163, + 4789), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_RSS, + "10.10.0.16", + "10.252.22.1", + 61163, + 4789), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_INNER_TUPLE2, + LDBC_HASH_SYM_CRC, + "10.23.160.163", + "129.226.103.217", + 8235, + 80), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_INNER_TUPLE2, + LDBC_HASH_SYM_RSS, + "10.23.160.163", + "129.226.103.217", + 8235, + 80), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_CRC, + "10.23.160.163", + "129.226.103.217", + 8235, + 80), + std::make_tuple("10.23.160.163_to_129.226.103.217_gtp_u_in_vxlan.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_RSS, + "10.23.160.163", + "129.226.103.217", + 8235, + 80) }; INSTANTIATE_TEST_CASE_P(TestOuterTuple2, TestFixtureDistributer, ::testing::ValuesIn(testTable)); + /* 分流算法测试 */ /* 测试用例1: Ether/IPv4,按外层IP地址分流 */ static const unsigned char stream_ipv4_pkt_0[78] = { @@ -677,4 +939,4 @@ TEST(DistributerInner2, EtherIPv4OffloadVxLANIPv4) { EXPECT_NE(__mbufs[__nr_mbufs - 1].hash.usr, __mbufs[i].hash.usr); } -}
\ No newline at end of file +} |
