A data transmission method, applied to a communications system, wherein the communications system comprises a first device, a second device, a third device and a virtualized network function, VNF, the VNF comprises a plurality of virtual machines, VMs, the first device is located in a first network, the second device is located in a second network, the third device is located in the second network, the plurality of VMs communicate with the first device by using the second device or the third device, and the method comprises: receiving, by the first device, a first data packet, and extracting first address information of the first data packet, wherein the first address information is used to indicate the virtualized network function, VNF;receiving, by the first device, a second data packet, and extracting the first address information of the second data packet, wherein the first address information is used to indicate the VNF; retrieving, by the first device based on the first address information, a segment routing over internet protocol 6, SRv6, tunnel policy that corresponds to the first address information and that is from a SRv6 tunnel list, wherein the SRv6 tunnel policy is used to indicate at least one SRv6 tunnel between the first device and the VNF, and the SRv6 tunnel policy comprises a first SRv6 virtual private network segment identifier, VPN SID and a second SRv6 VPN SID; obtaining, by the first device, a first forwarding path corresponding to the first SRv6 VPN SID, wherein the first forwarding path is used as a data transmission path when the first device communicates with a second device corresponding to the first SRv6 VPN SID; obtaining, by the first device, a second forwarding path corresponding to the second SRv6 VPN SID, wherein the second forwarding path is used as a data transmission path when the first device communicates with the third device corresponding to the second SRv6 VPN SID; encapsulating, by the first device, the first SRv6 VPN SID into the first data packet to form a first encapsulated data packet; encapsulating, by the first device, the second SRv6 VPN SID into the second data packet to form a second encapsulated data packet; forwarding, by the first device, the first encapsulated data packet to the VNF based on the first forwarding path by using the second device; and forwarding, by the first device, the second encapsulated data packet to the VNF based on the second forwarding path by using the third device. receiving, by the first device, a first data packet, and extracting first address information of the first data packet, wherein the first address information is used to indicate the virtualized network function, VNF;receiving, by the first device, a second data packet, and extracting the first address information of the second data packet, wherein the first address information is used to indicate the VNF; retrieving, by the first device based on the first address information, a segment routing over internet protocol 6, SRv6, tunnel policy that corresponds to the first address information and that is from a SRv6 tunnel list, wherein the SRv6 tunnel policy is used to indicate at least one SRv6 tunnel between the first device and the VNF, and the SRv6 tunnel policy comprises a first SRv6 virtual private network segment identifier, VPN SID and a second SRv6 VPN SID; obtaining, by the first device, a first forwarding path corresponding to the first SRv6 VPN SID, wherein the first forwarding path is used as a data transmission path when the first device communicates with a second device corresponding to the first SRv6 VPN SID; obtaining, by the first device, a second forwarding path corresponding to the second SRv6 VPN SID, wherein the second forwarding path is used as a data transmission path when the first device communicates with the third device corresponding to the second SRv6 VPN SID; encapsulating, by the first device, the first SRv6 VPN SID into the first data packet to form a first encapsulated data packet; encapsulating, by the first device, the second SRv6 VPN SID into the second data packet to form a second encapsulated data packet; forwarding, by the first device, the first encapsulated data packet to the VNF based on the first forwarding path by using the second device; and forwarding, by the first device, the second encapsulated data packet to the VNF based on the second forwarding path by using the third device.