summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2024-04-14 13:24:41 +0800
committersongyanchao <[email protected]>2024-04-17 02:23:06 +0000
commit5a83f0d644a8564791c531d82a79e1aa4899f882 (patch)
tree5093a72b84233bd58baad5480edcdc61feab2f83
parent0077eda5753ba103b891a3e91b3816e6d772c966 (diff)
🐞 fix: Constructed the source port for VXLAN encapsulation.
Constructed the source port for VXLAN encapsulation.
-rw-r--r--service/src/node_etherfabric.c11
-rw-r--r--test/ptf_test/etherfabric_test.py8
2 files changed, 17 insertions, 2 deletions
diff --git a/service/src/node_etherfabric.c b/service/src/node_etherfabric.c
index 0a959f4..60c2276 100644
--- a/service/src/node_etherfabric.c
+++ b/service/src/node_etherfabric.c
@@ -657,6 +657,15 @@ static struct rte_node_register ef_ingress_node_base = {
RTE_NODE_REGISTER(ef_ingress_node_base);
+/* Generate the source port for VXLAN encapsulation, rfc7348 */
+static inline uint16_t generate_vxlan_src_port(struct rte_mbuf * mbuf)
+{
+ uint16_t min = 49152;
+ uint16_t range = 65535 - 49152 + 1;
+
+ return min + (uint16_t)(mbuf->hash.usr % range);
+}
+
/* Fill Ether IPv4 Udp Vxlan hdr for the constructed packet */
static inline int vxlan_encap_constructed_pkt(struct rte_mbuf * mbuf, struct mrb_metadata * mrb_meta,
struct ef_peer * ef_peer_item, struct mr_dev_desc * dev_desc)
@@ -682,7 +691,7 @@ static inline int vxlan_encap_constructed_pkt(struct rte_mbuf * mbuf, struct mrb
/* TODO: the source port need to be fill with the hash of inner 2-tuple or 4-tuple,
* ignore the udp checksum */
- p_udp_hdr->src_port = htons(4789);
+ p_udp_hdr->src_port = htons(generate_vxlan_src_port(mbuf));
p_udp_hdr->dst_port = htons(4789);
p_udp_hdr->dgram_len = htons(rte_pktmbuf_pkt_len(mbuf));
p_udp_hdr->dgram_cksum = 0;
diff --git a/test/ptf_test/etherfabric_test.py b/test/ptf_test/etherfabric_test.py
index b76ec0d..b5a8f75 100644
--- a/test/ptf_test/etherfabric_test.py
+++ b/test/ptf_test/etherfabric_test.py
@@ -5,6 +5,8 @@ from scapy.all import *
from mrzcpd import Mrzcpd
from common_pkt import *
+import ptf.mask as mask
+
conf_for_virtual_wire_mode = """
[device]
device=veth0
@@ -362,9 +364,13 @@ class IPv4TestForRouteCtx(BaseTest):
send_pkt = simple_vxlan_packet(
eth_src='0a:0a:0a:0a:01:28', eth_dst='10:70:fd:03:c0:bd',
ip_src='10.254.50.1', ip_dst='10.254.60.1',udp_sport=4789,udp_dport=4789, vxlan_vni=32)
- verify_pkt = simple_vxlan_packet(
+ vxlan_pkt = simple_vxlan_packet(
eth_src='10:70:fd:03:c0:bd', eth_dst='0a:0a:0a:0a:01:28',
ip_src='10.254.60.1', ip_dst='10.254.50.1',udp_sport=4789,udp_dport=4789,with_udp_chksum=False,vxlan_flags=0,vxlan_vni=32)
+
+ verify_pkt = mask.Mask(vxlan_pkt)
+ verify_pkt.set_do_not_care_scapy(UDP, "sport")
+
send_packet(self, 0, send_pkt)
verify_packets(self, verify_pkt, [0])
finally: