diff options
| author | luqiuwen <[email protected]> | 2019-01-18 12:20:04 +0600 |
|---|---|---|
| committer | luqiuwen <[email protected]> | 2019-01-18 12:20:04 +0600 |
| commit | 7d286a2705add2a72e6c39b4de2d33583bf2003c (patch) | |
| tree | 9649ac99747ecfaf1f43d9ed90af4a15c071d562 | |
| parent | f47f133b11b377009ede396bd8db83cd5fd69cdb (diff) | |
增加按内层、外层四元组分流的实现及对应的单元测试用例v4.3.7-20190118
| -rw-r--r-- | infra/src/ldbc.c | 130 | ||||
| -rw-r--r-- | infra/test/TestDistributer.cc | 32 |
2 files changed, 129 insertions, 33 deletions
diff --git a/infra/src/ldbc.c b/infra/src/ldbc.c index e246702..b0e11d6 100644 --- a/infra/src/ldbc.c +++ b/infra/src/ldbc.c @@ -584,8 +584,61 @@ static inline uint32_t __distributer_inner_tuple2(struct distributer * dist_obje static inline uint32_t __distributer_inner_tuple4(struct distributer * dist_object, struct rte_mbuf * mbuf) { - assert(0); - return 0; + struct pkt_parser pkt_parser; + pkt_parser_init(&pkt_parser, LAYER_TYPE_L3 | LAYER_TYPE_L4, 4); + + /* 根据硬件的解析能力,找到最外层的IP */ +#if ENABLE_LDBC_BASED_NIC_PTYPE + bool is_no_l2_label = (mbuf->packet_type & RTE_PTYPE_L2_MASK) == RTE_PTYPE_L2_ETHER; + if (is_no_l2_label && RTE_ETH_IS_IPV4_HDR(mbuf->packet_type)) + { + outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); + __complex_parser_ipv4(&pkt_parser, outer_data, LAYER_TYPE_IPV4); + } + else if (is_no_l2_label && RTE_ETH_IS_IPV6_HDR(mbuf->packet_type)) + { + outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); + __complex_parser_ipv6(&pkt_parser, outer_data, LAYER_TYPE_IPV6); + } + else + { +#endif + const char * outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, 0); + __complex_parser_ether(&pkt_parser, outer_data, LAYER_TYPE_ETHER); + +#if ENABLE_LDBC_BASED_NIC_PTYPE + } +#endif + + if (pkt_parser.nr_results == 0) return 0; + + const struct pkt_parser_result * l3_layer_result = NULL; + const struct pkt_parser_result * l4_layer_result = NULL; + + /* 逆序查找L3层和L4层 */ + for(unsigned int i = pkt_parser.nr_results - 1; i >= 0; i--) + { + const struct pkt_parser_result * layer = &pkt_parser.results[i]; + + /* 找到L3层后,就不查找了,因为L3层后不会有L4层,如果有,为上层隧道的L4,不参与计算 */ + if(layer->this_layer_type & LAYER_TYPE_L3) { l3_layer_result = layer; break; } + + /* 找到L4层后,继续查找L3层 */ + if(layer->this_layer_type & LAYER_TYPE_L4) { l4_layer_result = layer; } + } + + uint32_t hash = dist_object->orin_hash; + if(l3_layer_result != NULL) + { + hash = dist_object->fn_hash_0(dist_object, l3_layer_result->data, l3_layer_result->this_layer_type, hash); + } + + if(l4_layer_result != NULL) + { + hash = dist_object->fn_hash_1(dist_object, l4_layer_result->data, l4_layer_result->this_layer_type, hash); + } + + return hash; } static inline uint32_t __distributer_outer_tuple2(struct distributer * dist_object, @@ -638,54 +691,65 @@ _calc_hash: return dist_object->fn_hash_0(dist_object, data, layer_type, 0); } +/* TODO: 整理该部分代码,与InnerTuple4合并 */ static inline uint32_t __distributer_outer_tuple4(struct distributer * dist_object, struct rte_mbuf * mbuf) { - const char * data = NULL; - int layer_type = 0; - int layer_len = 0; - uint8_t l4_layer_type; - - if (RTE_ETH_IS_IPV4_HDR(mbuf->packet_type)) - { - data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); - layer_type = LAYER_TYPE_IPV4; - } - else if (RTE_ETH_IS_IPV6_HDR(mbuf->packet_type)) + struct pkt_parser pkt_parser; + pkt_parser_init(&pkt_parser, LAYER_TYPE_L3 | LAYER_TYPE_L4, 2); + + /* 根据硬件的解析能力,找到最外层的IP */ +#if ENABLE_LDBC_BASED_NIC_PTYPE + bool is_no_l2_label = (mbuf->packet_type & RTE_PTYPE_L2_MASK) == RTE_PTYPE_L2_ETHER; + if (is_no_l2_label && RTE_ETH_IS_IPV4_HDR(mbuf->packet_type)) { - data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); - layer_type = LAYER_TYPE_IPV6; + outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); + __complex_parser_ipv4(&pkt_parser, outer_data, LAYER_TYPE_IPV4); } - - if (layer_type == LAYER_TYPE_IPV4) + else if (is_no_l2_label && RTE_ETH_IS_IPV6_HDR(mbuf->packet_type)) { - layer_len = sizeof(struct ipv4_hdr); - l4_layer_type = ((struct ipv4_hdr *)data)->next_proto_id; + outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, sizeof(struct ether_hdr)); + __complex_parser_ipv6(&pkt_parser, outer_data, LAYER_TYPE_IPV6); } - else if (layer_type == LAYER_TYPE_IPV6) + else { - layer_len = sizeof(struct ipv6_hdr); - l4_layer_type = ((struct ipv4_hdr *)data)->next_proto_id; +#endif + const char * outer_data = rte_pktmbuf_mtod_offset(mbuf, const char *, 0); + __complex_parser_ether(&pkt_parser, outer_data, LAYER_TYPE_ETHER); + +#if ENABLE_LDBC_BASED_NIC_PTYPE } - else return 0; +#endif - uint32_t ip_hash = 0; - if (dist_object->fn_hash_0 != NULL) + if (pkt_parser.nr_results == 0) return 0; + + const struct pkt_parser_result * l3_layer_result = NULL; + const struct pkt_parser_result * l4_layer_result = NULL; + + /* 逆序查找L3层和L4层 */ + for(unsigned int i = pkt_parser.nr_results - 1; i >= 0; i--) { - ip_hash = dist_object->fn_hash_0(dist_object, data, layer_type, 0); - if (ip_hash == 0) return 0; + const struct pkt_parser_result * layer = &pkt_parser.results[i]; + + /* 找到L3层后,就不查找了,因为L3层后不会有L4层,如果有,为上层隧道的L4,不参与计算 */ + if(layer->this_layer_type & LAYER_TYPE_L3) { l3_layer_result = layer; break; } + + /* 找到L4层后,继续查找L3层 */ + if(layer->this_layer_type & LAYER_TYPE_L4) { l4_layer_result = layer; } } - if((mbuf->packet_type & RTE_PTYPE_L4_TCP) || l4_layer_type == IPPROTO_TCP) + uint32_t hash = dist_object->orin_hash; + if(l3_layer_result != NULL) { - return dist_object->fn_hash_1(dist_object, data + layer_len, LAYER_TYPE_TCP, ip_hash); + hash = dist_object->fn_hash_0(dist_object, l3_layer_result->data, l3_layer_result->this_layer_type, hash); } - else if((mbuf->packet_type & RTE_PTYPE_L4_UDP) || l4_layer_type == IPPROTO_UDP) + + if(l4_layer_result != NULL) { - return dist_object->fn_hash_1(dist_object, data + layer_len, LAYER_TYPE_UDP, ip_hash); + hash = dist_object->fn_hash_1(dist_object, l4_layer_result->data, l4_layer_result->this_layer_type, hash); } - - return ip_hash; + + return hash; } static int distributer_outer_tuple2(struct distributer * dist_object, diff --git a/infra/test/TestDistributer.cc b/infra/test/TestDistributer.cc index 2f67ec2..c3d9a37 100644 --- a/infra/test/TestDistributer.cc +++ b/infra/test/TestDistributer.cc @@ -120,6 +120,8 @@ TEST_P(TestFixtureDistributer, TestDistHashResult) hash_result = m->hash.usr; } } + + EXPECT_NE(hash_result, 0); } std::tuple<const char *, enum e_dist_mode, enum e_hash_mode> testTable[] @@ -130,30 +132,60 @@ std::tuple<const char *, enum e_dist_mode, enum e_hash_mode> testTable[] std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", LDBC_DIST_INNER_TUPLE2, LDBC_HASH_SYM_RSS), + std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_CRC), + std::make_tuple("178_89_4_219_to_117_122_217_89_mpls_vxlan_inner.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_RSS), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE2, LDBC_HASH_SYM_CRC), std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", LDBC_DIST_INNER_TUPLE2, LDBC_HASH_SYM_RSS), + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_CRC), + std::make_tuple("100_95_37_122_to_149_3_200_32_gtpv1_u.pcap", + LDBC_DIST_INNER_TUPLE4, + LDBC_HASH_SYM_RSS), std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_CRC), std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_RSS), + std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_CRC), + std::make_tuple("178_89_4_219_to_117_122_217_89_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_RSS), std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_CRC), std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_RSS), + std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_CRC), + std::make_tuple("178.89.4.221_to_31.13.70.49_mpls_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_RSS), std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_CRC), std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", LDBC_DIST_OUTER_TUPLE2, LDBC_HASH_SYM_RSS), + std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_CRC), + std::make_tuple("178.89.4.221_to_31.13.70.49_asym_mpls_ipv4.pcap", + LDBC_DIST_OUTER_TUPLE4, + LDBC_HASH_SYM_RSS), }; INSTANTIATE_TEST_CASE_P(TestOuterTuple2, TestFixtureDistributer, ::testing::ValuesIn(testTable)); |
