WO2015096058A1 - 一种数据包处理方法和装置 - Google Patents

一种数据包处理方法和装置 Download PDF

Info

Publication number
WO2015096058A1
WO2015096058A1 PCT/CN2013/090413 CN2013090413W WO2015096058A1 WO 2015096058 A1 WO2015096058 A1 WO 2015096058A1 CN 2013090413 W CN2013090413 W CN 2013090413W WO 2015096058 A1 WO2015096058 A1 WO 2015096058A1
Authority
WO
WIPO (PCT)
Prior art keywords
protocol stack
data packet
identifier
target
domain
Prior art date
Application number
PCT/CN2013/090413
Other languages
English (en)
French (fr)
Inventor
唐继元
王伟
陈克平
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to CN201380002979.XA priority Critical patent/CN104969533B/zh
Priority to PCT/CN2013/090413 priority patent/WO2015096058A1/zh
Publication of WO2015096058A1 publication Critical patent/WO2015096058A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols

Definitions

  • the present invention relates to the field of communications, and in particular, to a data packet processing method and apparatus. Background technique
  • the embodiment of the invention provides a data packet processing method and device, which can solve the problem that the performance of the current protocol stack is relatively low, and the performance of the device is relatively low.
  • an embodiment of the present invention provides a data packet processing method, including:
  • DPS destination protocol stack
  • the identifier of the protocol stack or the domain of the specific identifier, the specific identifier is used to indicate that the receiving device and the sending device do not establish a protocol stack correspondence
  • the receiving device is a device identified by the destination address in the packet header
  • the sending The device is a device identified by the source address in the packet header;
  • the first destination Allocating the first data packet to a first target protocol stack according to the first identifier, the first destination
  • the standard protocol stack processes the first data packet; wherein the first target protocol stack is a protocol stack in multiple protocol stacks that are started.
  • the first identifier is an identifier of a protocol stack of the receiving end
  • the first data packet is allocated to the first target protocol stack according to the first identifier, and the first target protocol stack processes the first data packet, including:
  • the first identifier is the specific identifier
  • the first data packet is allocated to the first target protocol stack according to the first identifier, and the first target protocol stack processes the first data packet, including:
  • the protocol stack Identifying, according to the first identifier, that the protocol stack is not established with the sending device, and broadcasting the first data packet to the initiated multiple protocol stacks, when the first target protocol stack identifies the first target protocol.
  • the stack includes a service of the service type of the first data packet, the first target protocol stack processes the first data packet; or
  • the first target protocol stack processes the first data packet; wherein the corresponding relationship includes service information of each protocol stack, and the first target protocol stack includes the The protocol stack of the service type of the first packet.
  • the packet header further includes a source protocol a source protocol stack (SPS) field, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, and the SPS domain includes a second processing of the first data packet in the sending device a second identifier of the target protocol stack;
  • SPS source protocol stack
  • the method further includes: returning, to the sending device, a second data packet, where the second data is a response of the first data packet a data packet, the packet header of the second data packet includes an SPS domain and a DPS domain, where the SPS domain included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the second data packet
  • the DPS field included in the packet header includes the second identifier.
  • the first target protocol stack is selected from the plurality of protocol stacks to provide services for the application, where the service provided by the first target protocol stack for the application is The service of the service type of the first data packet.
  • an embodiment of the present invention provides a data packet processing method, including: generating a first data packet by using a second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS
  • the DPS domain is a domain for carrying an identifier of the protocol stack of the receiving device or a specific identifier, and the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding relationship with the sending device, and the receiving device a device that is identified by a destination address in the packet header, where the sending device is a device identified by a source address in the packet header;
  • the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device;
  • the first identifier is included, and the SPS domain includes a second identifier of the second target protocol stack;
  • the receiving device Transmitting the first data packet to the receiving device, so that the receiving device allocates the first data packet to a first target protocol stack according to the first identifier, where the first target protocol stack processes the The first data packet; wherein the first target protocol stack is a protocol stack in multiple protocol stacks initiated by the receiving device.
  • the method further includes:
  • a second data packet where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where the second The SPS field included in the packet header of the data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier;
  • the second data packet is allocated to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • an embodiment of the present invention provides a data packet processing apparatus, including: an acquiring unit and a distribution unit, where:
  • the obtaining unit is configured to acquire a first data packet, and parse a packet header of the first data packet, to obtain a first identifier included in a DPS domain in the packet header, where the DPS domain is used to carry a receiving device.
  • the allocating unit is configured to allocate the first data packet to the first target protocol stack according to the first identifier, and process the first data packet by using the first target protocol stack;
  • the target protocol stack is the protocol stack in multiple protocol stacks that are started.
  • the allocating unit is configured to: when the first identifier is the identifier of the protocol stack of the receiving end, Selecting a first target protocol stack identified as the first identity; and assigning the first data packet to the first target protocol stack, the first data packet being processed by the first target protocol stack.
  • the allocating unit is configured to: when the first identifier is the specific identifier, identify that the first identifier is not The sending device does not establish a protocol stack correspondence, and broadcasts the first data packet to the initiated multiple protocol stacks, when the first target protocol stack identifies that the first target protocol stack includes the service type of the first data packet. Processing, processing, by the first target protocol stack, the first data packet; or
  • the allocating unit is configured to: when the first identifier is the specific identifier, identify, according to the first identifier, that the protocol stack is not established with the sending device, and the pre-acquired service and protocol stack are Finding a first target protocol stack in the corresponding relationship, and then assigning the first data packet to the first target protocol stack, where the first target protocol stack processes the first data packet; wherein the corresponding relationship includes Service information of each protocol stack, the first target protocol stack is a protocol stack of a service including a service type of the first data packet.
  • the packet header is further included
  • the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, and the SPS domain includes a second of a second target protocol stack of the sending device that processes the first data packet.
  • the device also includes:
  • a sending unit configured to return a second data packet to the sending device, where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where The SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier.
  • the apparatus further includes:
  • a startup unit configured to start multiple protocol stacks, and assign an identifier to each protocol stack
  • a selecting unit configured to: when the application needs to use the network, select the first target protocol stack from the plurality of protocol stacks to serve the application, where the first target protocol stack is the application
  • the service provided by the program is a service of the service type of the first data packet.
  • an embodiment of the present invention provides a data packet processing apparatus, including: a generating unit and a sending unit, where:
  • the generating unit is configured to generate a first data packet by using a second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain, where the DPS domain is used to carry a receiving device.
  • An identifier of the protocol stack or a domain of the specific identifier where the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, the receiving device is a device identified by the destination address in the packet header, and the sending device is a device identified by the source address in the packet header;
  • the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device;
  • the DPS domain includes a first identifier, and the SPS domain includes the second target The second identifier of the protocol stack;
  • the sending unit is configured to send the first data packet to the receiving device, to enable the receiving device to allocate the first data packet to a first target protocol stack according to the first identifier, where A target protocol stack processes the first data packet; wherein the first target protocol stack is a protocol stack of multiple protocol stacks initiated by the receiving device.
  • the device further includes: a receiving unit, configured to receive a second data packet returned by the receiving device, where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where The SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier;
  • an allocating unit configured to allocate the second data packet to the second target protocol stack, where the second target protocol stack processes the second data packet.
  • an embodiment of the present invention provides a data packet processing apparatus, including: a receiver and a memory, and a processor respectively connected to the receiver and the memory, where the memory is used to store a set of program codes,
  • the processor is configured to invoke the code stored by the memory to perform the following operations: acquiring, by the receiver, a first data packet, and parsing a header of the first data packet, to obtain a first identifier included in a DPS domain in the packet header
  • the DPS domain is a domain for carrying an identifier of the protocol stack of the receiving device or a specific identifier, and the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding relationship with the sending device, where the receiving device is a device identified by a destination address in the packet header, where the sending device is a device identified by a source address in the packet header;
  • the first identifier is an identifier of a protocol stack of the receiving end
  • the operation performed by the processor to allocate the first data packet to the first target protocol stack according to the first identifier, and the operation of the first target protocol stack to process the first data packet includes:
  • the first identifier is the specific identifier
  • the operation performed by the processor to allocate the first data packet to the first target protocol stack according to the first identifier, and the operation of the first target protocol stack to process the first data packet includes:
  • the protocol stack Identifying, according to the first identifier, that the protocol stack is not established with the sending device, and Transmitting the first data packet to a plurality of protocol stacks that are started, and when the first target protocol stack identifies that the first target protocol stack includes a service of a service type of the first data packet, the first target protocol stack processing The first data packet; or
  • the first target protocol stack processes the first data packet; wherein the corresponding relationship includes service information of each protocol stack, and the first target protocol stack includes the The protocol stack of the service type of the first packet.
  • the packet header further includes an SPS domain, where An SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain includes a second identifier of a second target protocol stack in the sending device that processes the first data packet;
  • the apparatus further includes a transmitter, the processor, after performing the operation of processing the first data packet by the first target protocol stack, the processor is further configured to perform the following operations:
  • a second data packet to the sending device, where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where The SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier.
  • the method further includes:
  • the first target protocol stack is selected from the plurality of protocol stacks to provide services for the application, where the service provided by the first target protocol stack for the application is The service of the service type of the first data packet.
  • an embodiment of the present invention provides a data packet processing apparatus, including: a transmitter and a memory, and a processor respectively connected to the transmitter and the memory, where the memory is used to store a set of program codes,
  • the code used by the processor to call the memory store performs the following operations: Generating a first data packet by using a second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain, where the DPS domain is an identifier or a specific identifier of a protocol stack for carrying a receiving device
  • the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, the receiving device is a device identified by the destination address in the packet header, and the sending device is a source address in the packet header.
  • the identified device; the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device;
  • the DPS domain includes a first identifier, and the SPS domain includes a second identifier of the second
  • the transmitter Transmitting, by the transmitter, the first data packet to the receiving device, to enable the receiving device to allocate the first data packet to a first target protocol stack according to the first identifier, the first target
  • the protocol stack processes the first data packet, where the first target protocol stack is a protocol stack of multiple protocol stacks initiated by the receiving device.
  • the apparatus further includes a receiver, where: the processor, after performing an operation of sending the first data packet to the receiving device by using the transmitter , also used to do the following:
  • a packet header of the second data packet includes an SPS domain and a DPS domain
  • the SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier
  • the second data packet is allocated to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • the first data packet after acquiring the first data packet, is allocated to the first target protocol stack according to the first identifier included in the DPS field in the packet header of the first data packet, so that the first target protocol stack can be Processing the first data packet; and wherein the first target protocol stack is a protocol stack in multiple protocol stacks that are started.
  • the first target protocol stack is selected from the plurality of protocol stacks to process the first data packet according to the first identifier carried by the first data packet.
  • multiple cores access the same protocol stack at the same time.
  • Embodiments of the invention can improve the performance of the protocol stack, thereby improving the performance of the device.
  • FIG. 1 is a schematic flowchart of a data packet processing method according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of another data packet processing method according to an embodiment of the present invention
  • Optional header diagram is a schematic flowchart of another data packet processing method according to an embodiment of the present invention.
  • FIG. 4 is a schematic flowchart of another method for processing a data packet according to an embodiment of the present invention
  • FIG. 5 is a schematic flowchart of another method for processing a data packet according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of another method for processing a data packet according to an embodiment of the present invention
  • FIG. 8 is a schematic diagram of an optional scenario provided by an embodiment of the present invention.
  • FIG. 9 is a schematic structural diagram of a data packet processing apparatus according to an embodiment of the present invention.
  • FIG. 10 is a schematic structural diagram of another data packet processing apparatus according to an embodiment of the present invention.
  • FIG. 12 is a schematic structural diagram of another data packet processing apparatus according to an embodiment of the present invention.
  • FIG. 13 is a schematic structural diagram of another data packet processing apparatus according to an embodiment of the present invention.
  • 14 is a schematic structural diagram of another data packet processing apparatus according to an embodiment of the present invention;
  • FIG. 15 is a schematic structural diagram of another data packet processing apparatus according to an embodiment of the present invention;
  • a schematic diagram of the structure of a packet processing device A schematic diagram of the structure of a packet processing device. detailed description
  • FIG. 1 is a schematic flowchart of a data packet processing method according to an embodiment of the present invention. As shown in FIG. 1, the method includes the following steps:
  • the first data packet is obtained, and the packet header of the first data packet is parsed, and the first identifier included in the DPS domain in the packet header is obtained.
  • the DPS domain is used to carry the protocol stack of the receiving device.
  • the specific identifier is used to indicate that the receiving device and the sending device do not establish a protocol stack correspondence, the receiving device is a device identified by the destination address in the packet header, and the sending device is the The device identified by the source address in the header.
  • the identifier of the foregoing protocol stack may be used to uniquely identify the protocol stack. That is, a protocol stack uniquely corresponds to an identifier, so that only one protocol stack can be found by the identifier.
  • the identifier of the protocol stack can be a number, for example: Start 5 protocol stacks, then the identifiers of the 5 protocol stacks can be 1, 2, 3, 4, and 5 respectively.
  • the corresponding relationship between the receiving device and the sending device that does not establish a protocol stack may be that the sending device does not know which protocol stack on the receiving device processes the first data packet, that is, the sending device does not acquire the first device.
  • the identity of the protocol stack of the packet For example, when the first data packet is a request packet, the receiving device and the sending device may not establish a protocol stack correspondence relationship; or the first data packet is the first data that is sent by the sending device and the receiving device for the first time. When the packet is used, the receiving device and the transmitting device may not establish a protocol stack correspondence.
  • the source address may be a source IP address
  • the destination address may be a destination IP address.
  • the first data packet is allocated to the first target protocol stack according to the first identifier, where the first target protocol stack processes the first data packet, where the first target protocol stack is started.
  • the multiple protocol stacks initiated above may be at least two protocol stacks.
  • the foregoing first data packet may be an IP data packet.
  • the foregoing method may be applied to a server or a user terminal, where the server may implement the foregoing method, or the user end of the user terminal may implement the foregoing method; or the server or the core of the user terminal may implement the foregoing
  • the method may also implement the foregoing method by using a user-mode centralized network parallel protocol stack of a server or a user terminal; or implementing the above method by using a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a network-enabled smart device such as a tablet, a mobile phone, an electronic reader, a remote controller, a personal computer (PC), a notebook computer, a car device, a network television, a wearable device, or the like.
  • FIG. 2 is a schematic flowchart of another method for processing a data packet according to an embodiment of the present invention. As shown in FIG. 2, the method includes the following steps:
  • step 201 may be to start multiple protocol stacks in a certain order, and then assign an identifier to each activated protocol stack, for example: assigning numbers according to the starting sequence.
  • the multiple protocol stacks are parallel protocol stacks, and the multiple protocol stacks can be independent protocol stacks.
  • the service is a service of the service type of the first data packet.
  • the foregoing first target protocol stack provides services for the application, and the first target protocol stack provides services for processes or threads of the application.
  • the foregoing service may be a network service, for example: the foregoing service is all TCP/IP services for the TCP/IP protocol cluster; the foregoing server may also be a network service other than the TCP/IP protocol cluster, etc. Not limited.
  • step 202 is only an implementation manner in which the first target protocol stack provides services for the foregoing application, and in this embodiment, other protocol stacks that are started may be used to provide services for other applications, and of course, different protocol stacks. The services offered can be different.
  • the selecting the first target protocol stack from the multiple protocol stacks to provide services for the application may include:
  • the application applies for a protocol stack
  • the application sends a setup service request to the first target protocol stack
  • the first target protocol stack establishes a service.
  • the application when the application needs a transport layer protocol for network services, the application can also perform Port application, if the application uses the network layer or data link layer protocol, you can do not need port application.
  • the initiated protocol stack may also be managed by a protocol stack management module dedicated to managing the protocol stack.
  • the protocol stack management module can be a virtual module.
  • the port application and the protocol stack application can be applied to the protocol stack management module, and the protocol stack management module can allocate the port and the first target protocol stack to the application, and then notify the allocation result to the distribution result.
  • the application so that the application can send a setup service request to the first target protocol stack.
  • the foregoing assigning the foregoing first target protocol stack to the application according to a specific principle may include:
  • the protocol stack bound by the application is used as the first target protocol stack; when the application is bound to multiple In the protocol stack, a protocol stack is selected from the protocol stack bound by the application as the first target protocol stack;
  • a protocol stack is selected from the plurality of protocol stacks that are started as the first target protocol stack.
  • selecting the protocol stack from the protocol stack bound by the application as the first target protocol stack may be: selecting the protocol stack with the lightest load from the protocol stack bound by the application as the first The target protocol, or the protocol stack can be allocated according to other allocation methods, such as the polling mode: the first allocation is to allocate the first protocol stack of the multiple protocol stacks bound to the application, and the second allocation is the application allocation.
  • the second protocol stack and the like in the multiple protocol stacks are not limited in this embodiment.
  • selecting one protocol stack from the multiple protocol stacks that are started as the first target protocol stack may be: selecting the least loaded protocol stack from the multiple protocol stacks that are started as the first target protocol stack, or The protocol stack is allocated according to other allocation methods.
  • the above application may refer to a process or a thread of an application.
  • multiple protocol stacks that are started may be managed. For example, when the network load increases, a new protocol stack may be loaded when multiple protocol stacks that are currently started are processed. For example, when the network load is reduced, the protocol stack that needs to be uninstalled may be unloaded in the multiple protocol stacks that are started, the protocol stack is unloaded, or the connection information of the protocol stack is migrated, and then the protocol stack is uninstalled;
  • the protocol stack that needs to be uninstalled refers to a protocol stack that does not currently have any connection or any load.
  • the foregoing connection information may include: TCP connection information, TCP service information, and/or User Datagram Protocol (UDP) service information. This embodiment is not limited.
  • connection information may further include: IP service information, File Transfer Protocol (FTP) service information, Secure Shell (SSH) service information, etc.
  • Connection information can refer to all network service information.
  • TCP connection information may mainly refer to: state machine information, source IP address, source port number, destination IP address, destination port number, and destination protocol stack information of each connection.
  • the TCP service information and the UDP service information may mainly refer to: destination IP, destination port number, destination protocol stack information, and the like.
  • the connection information of the protocol stack 1 is migrated to the protocol stack 2, and then the protocol stack 1 is unloaded, so that the protocol stack 2 can handle the connection on the protocol stack 1, that is, the protocol stack 2 can handle the load on the protocol stack 1.
  • this embodiment can establish a protocol stack management module management protocol stack.
  • 203 Acquire a first data packet, and parse the packet header of the first data packet, to obtain a first identifier included in the DPS domain in the packet header, where the DPS domain is an identifier of a protocol stack used to carry the receiving device, or a specific identifier, the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, the receiving device is a device identified by the destination address in the packet header, and the sending device is in the packet header The device identified by the source address.
  • the DPS domain is an identifier of a protocol stack used to carry the receiving device, or a specific identifier
  • the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device
  • the receiving device is a device identified by the destination address in the packet header
  • the sending device is in the packet header The device identified by the source address.
  • the first data packet may be a data packet processed by the application, for example, the service type of the first data packet is a type that the first target protocol stack provides for the application.
  • the foregoing packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain may include processing the first data in the sending device.
  • the second identifier of the second target protocol stack of the packet In this way, the identifier of the second target protocol stack in the sending device can be known through the SPS domain, so that when the data packet is returned to the sending device, the identifier of the second target protocol stack can be carried in the DPS domain of the data packet.
  • the packet header of the first data packet may be a packet header as shown in FIG. 3, and the packet header may include: a version domain, a header length domain, a service type domain, a total length domain, a recombination identifier domain, a flag domain, and a segment offset domain. , time to live domain, protocol code field, header checksum and domain, source IP address domain, destination IP address domain, SPS domain, DPS domain, optional data domain, and user data domain.
  • the SPS domain and the DPS domain are The position where the length is not limited may not be limited.
  • the first data packet is allocated to the first target protocol stack according to the first identifier, where the first target protocol stack processes the first data packet, where the first target protocol stack is started.
  • the step 204 may include:
  • the first target protocol stack may be searched according to the first identifier in the DPS domain, and the first data packet is allocated to the first target protocol stack, so that the first target protocol stack can process the first data packet independently.
  • the first target protocol stack does not have any protocol connection information with other protocol stacks.
  • the step 204 may include: identifying, according to the first identifier, that the protocol stack is not established with the sending device, and the first data packet is Broadcasting to a plurality of initiated protocol stacks, when the first target protocol stack identifies that the first target protocol stack includes a service of the service type of the first data packet, the first target protocol stack processes the first data packet .
  • the service type of the first data packet is fixed, the service type provided by the first target protocol stack is also fixed. After the first target protocol stack obtains the first data packet, the service type of the first data packet may be detected. When the first target protocol stack includes the service type service of the first data packet, the first target The protocol stack processes the first data packet. Other protocol stacks do not include the service type of the first packet, so that these other protocol stacks can discard the first packet.
  • the step 204 may include: identifying, according to the first identifier, that the protocol stack is not established with the sending device, and the pre-acquired service and protocol Finding a first target protocol stack in a correspondence relationship of the stack, and then allocating the first data packet to the first target protocol stack, where the first target protocol stack processes the first data packet;
  • the relationship includes service information of each protocol stack, and the first target protocol stack includes The protocol stack of the service type of the first data packet.
  • the method may generate a correspondence between the service and the protocol stack, where the correspondence includes service information of each protocol stack, that is, the correspondence indicates a service of each protocol stack.
  • the correspondence may be the above correspondence generated when each protocol establishes a service for an application.
  • Each protocol stack can provide services for different applications through the implementation of step 202, so that the corresponding relationship can be generated.
  • the correspondence may specifically be an information table of a service and a protocol stack.
  • the packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain includes processing, by the sending device, the first data packet.
  • the second identifier of the second target protocol stack as shown in FIG. 4, before the step 204, the method may further include:
  • a second data packet where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where the The SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier.
  • the second data packet may be directly allocated to the second target protocol stack according to the second identifier included in the DPS domain of the second data packet, and the second target protocol stack is configured by the second target protocol stack. Process the second packet.
  • the first data packet may be a fragmented data packet, that is, the first data packet is a part of a certain data packet.
  • the DPS domain, the SPS domain, and the service type in the header of the fragmented data packet are the same, so that multiple packets obtained by fragmenting the same data packet can be allocated to the same protocol stack through the above steps.
  • the DPS domain, the SPS domain, and the service type of the headers of multiple packets obtained by the same packet fragment are the same, the above steps must be assigned to the same protocol stack.
  • fragmented data packets of the same data stream may be aggregated into a buffer area, and all the fragmented data packets arrive at the buffer area and then synthesized into a complete data packet, and then distributed to the first target protocol stack for processing, thereby reducing The overhead of the first target protocol stack.
  • the foregoing method may be applied to a server or a user terminal, where the server may implement the foregoing method, or the user end of the user terminal may implement the foregoing method; or the server or the core of the user terminal may implement the foregoing Method; can also be a server or user
  • the user-mode centralized network parallel protocol stack of the terminal implements the above method; the above method can also be implemented by the lib library protocol stack of the server or the user terminal. among them.
  • the user terminal can be a network-enabled smart device such as a tablet, a mobile phone, an e-reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • FIG. 5 is a schematic flowchart of another method for processing a data packet according to an embodiment of the present invention. As shown in FIG. 5, the method includes the following steps:
  • the first data packet is generated by using the second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain, where the DPS domain is an identifier of a protocol stack used to carry the receiving device, or a specific identifier, the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, the receiving device is a device identified by the destination address in the packet header, and the sending device is in the packet header
  • the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device;
  • the DPS domain includes a first identifier, and the SPS domain includes a second of the second target protocol stack Logo.
  • the first data packet may be a data packet that an application needs to send to the receiving device, for example: when an application needs to establish communication with the receiving device, the second target may be allocated to the application.
  • the protocol stack; wherein the second target protocol stack is allocated to the application, the second target protocol stack may be allocated to the application according to a specific principle.
  • the foregoing assigning the second target protocol stack to the application according to a specific principle may include:
  • the protocol stack bound by the application is used as the second target protocol stack; when the application is bound to multiple When the protocol stack is used, the least loaded protocol stack in the protocol stack bound by the application is used as the second target protocol stack;
  • the least loaded protocol stack of the multiple protocol stacks to be started is used as the second target protocol stack.
  • the above application may refer to a process or a thread of an application.
  • the source address may be a source IP address
  • the destination address may be a destination IP address.
  • the receiving device may parse the packet header of the first data packet to obtain a first identifier included in the DPS domain in the packet header, and then, according to the first identifier, The first data packet is allocated to a first target protocol stack, and the first target protocol stack processes the first data packet stack.
  • the method may further include:
  • a packet header of the second data packet includes an SPS domain and a DPS domain
  • the SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier
  • the second data packet is allocated to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • the step 504 can directly allocate the second data packet to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • the foregoing method may be applied to a server or a user terminal, where the server may implement the foregoing method, or the user end of the user terminal may implement the foregoing method; or the server or the core of the user terminal may implement the foregoing
  • the method may also implement the foregoing method by using a user-mode centralized network parallel protocol stack of a server or a user terminal; or implementing the above method by using a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • the first data packet is generated by using the second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain; and the first data packet is sent to the receiving device;
  • the receiving device allocates the first data packet to the first target protocol according to the first identifier
  • the first target protocol stack processes the first data packet; wherein the first target protocol stack is a protocol stack of multiple protocol stacks initiated by the receiving device.
  • the first target protocol stack is selected from the plurality of protocol stacks to process the first data packet according to the first identifier carried by the first data packet.
  • multiple cores access the same protocol stack at the same time.
  • FIG. 7 is a schematic diagram of another method for processing a data packet according to an embodiment of the present invention
  • FIG. 8 is a schematic diagram of an optional scenario according to an embodiment of the present invention
  • the TCP 80 service is provided (for example, the web service uses TCP port 80), and the user terminal with the IP address of 192.168.1.2 requests the monthly service for an example.
  • the embodiment may include the following steps:
  • the server process or thread of the server applies for port 80, and then applies to the protocol stack management module for the protocol stack (this may be sent in the form of a message, or may be an API interface provided by the system to the application);
  • the protocol stack management module of the server selects the protocol stack #1 according to the rule from the protocol stack #1 and the protocol stack #2 according to the load balancing rule, and feeds the selection result to the server process or the thread;
  • the server process or thread of the server sends a service establishment request to the protocol stack #1, and the TCP 80 service is required to be established.
  • the protocol stack #1 of the server creates a TCP 80 service, and the service is currently in a state to be connected (ie, a listening state, indicating that the server is ready, waiting for a connection request from the client), and returns the creation result to the server process or thread. ;
  • the process requests the protocol stack from the protocol stack management module.
  • the protocol stack management module of the user terminal selects the protocol stack #1 according to the load balancing rule from the current legal protocol stack (the system currently only loads one protocol stack), and feeds the selection result to the client process or Thread
  • the client process or thread of the user terminal transmits a connection request (a TCP 80 service with an IP address of 192.168.1.1) to the protocol stack #1;
  • the protocol stack #1 of the user terminal first obtains an idle TCP port (such as TCP 8888). Port), and then construct the IP packet of the connection request to be sent to the server with the IP address 192.168.1.1 through the network card; wherein the key part of the IP packet header of the connection request is: source IP address 192.168.1.2, destination IP address 192.168.1.1
  • the SP field is 1, the DPS field is 0, and the DPS field is 0, which can be equal to the specific identifier introduced in the above embodiment; the SP field is 1, and the DPS field is 0 because the protocol stack of the user terminal is already known as the protocol stack #1. So, the SPS is 1, but the protocol stack of the destination IP address is not known, so the DPS is 0; the key part of the TCP packet header of the connection request is: source port 8888, destination port 80;
  • the server receives the IP data packet, and the DPS distribution module obtains the IP data packet from the buffer queue.
  • the server DPS distribution module finds that the IP value of the IP packet IP header is 0, and the DPS distribution module broadcasts the IP data to the protocol stack #1 and the protocol stack #2;
  • the protocol stack #1 of the server finds that the IP data packet is a connection request of the TCP 80 service, and therefore sends a connection request reply data packet to the user terminal; wherein, the connection request returns a key part of the data packet.
  • the source IP address is 192.168.1.1
  • the destination IP address is 192.168.1.2, SPSl, DP S1;
  • the association relationship between the two ends of the protocol stack has been established.
  • the IP packet of the connection directly goes to the two associated protocol stacks. Since there is no TCP 80 service in protocol stack #2, protocol stack #2 will discard the IP packet.
  • the DPS distribution module, the protocol stack management module, and the protocol stack may be implemented by hardware or software.
  • the foregoing DPS distribution module may be implemented by hardware in a network card, or may be implemented by software.
  • the following is a device embodiment of the present invention.
  • the device embodiment of the present invention is used to perform the method for implementing the first to fourth embodiments of the present invention. For the convenience of description, only parts related to the embodiment of the present invention are shown, and the specific technical details are not disclosed. Please refer to the first embodiment, the second embodiment, the third embodiment and the fourth embodiment of the present invention. Referring to FIG. 9, FIG. 9, FIG.
  • the method includes: an obtaining unit 91 and an allocating unit 92, where: The obtaining unit 91 is configured to obtain a first data packet, and parse the packet header of the first data packet, to obtain a first identifier included in the DPS domain in the packet header, where the DPS domain is a protocol for carrying the receiving device An identifier of the stack or a domain of the specific identifier, where the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, where the receiving device is a device identified by the destination address in the packet header, and the sending device is The device identified by the source address in the packet header.
  • the identifier of the foregoing protocol stack may be used to uniquely identify the protocol stack. That is, a protocol stack uniquely corresponds to an identifier, so that only one protocol stack can be found by the identifier.
  • the identifier of the protocol stack can be a number, for example: Start 5 protocol stacks, then the identifiers of the 5 protocol stacks can be 1, 2, 3, 4, and 5 respectively.
  • the corresponding relationship between the receiving device and the sending device that does not establish a protocol stack may be that the sending device does not know which protocol stack on the receiving device processes the first data packet, that is, the sending device does not acquire the first device.
  • the identity of the protocol stack of the packet For example, when the first data packet is a request packet, the receiving device and the sending device may not establish a protocol stack correspondence relationship; or the first data packet is the first data that is sent by the sending device and the receiving device for the first time. When the packet is used, the receiving device and the transmitting device may not establish a protocol stack correspondence.
  • the source address may be a source IP address
  • the destination address may be a destination IP address.
  • the allocating unit 92 is configured to allocate the first data packet to the first target protocol stack according to the first identifier, and process the first data packet by using the first target protocol stack; wherein, the first target The protocol stack is the protocol stack in multiple protocol stacks that are started.
  • the multiple protocol stacks initiated above may be at least two protocol stacks.
  • the foregoing first data packet may be an IP data packet.
  • the foregoing device may be specifically applied to a server or a user terminal, where the server of the server may implement the foregoing device, or the user end of the user terminal may implement the foregoing device; or the kernel of the server or the user terminal may implement the foregoing.
  • the apparatus may also implement the foregoing apparatus by a user-mode centralized network parallel protocol stack of a server or a user terminal; and may also implement the foregoing apparatus by a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • FIG. 10 is a schematic structural diagram of another packet processing apparatus according to an embodiment of the present invention. As shown in FIG. 10, the method includes: a starting unit 101, a selecting unit 102, an obtaining unit 103, and an allocating unit 104, where :
  • the starting unit 101 is configured to start multiple protocol stacks, and assign an identifier to each protocol stack.
  • the initiating unit 101 may start multiple protocol stacks in a certain order, and then assign an identifier to each activated protocol stack, for example: assign numbers according to the starting sequence.
  • the multiple protocol stacks are parallel protocol stacks, and the multiple protocol stacks can be independent protocol stacks.
  • the selecting unit 102 is configured to: when the application needs to use the network, select the first target protocol stack from the plurality of protocol stacks to serve the application, where the first target protocol stack is The service provided by the application is a service of the service type of the first data packet.
  • the foregoing first target protocol stack provides services for the application, and the first target protocol stack provides services for processes or threads of the application.
  • the foregoing service may be a network service, for example: the foregoing service is all TCP/IP services for the TCP/IP protocol cluster; the foregoing server may also be a network service other than the TCP/IP protocol cluster, etc.
  • the selecting unit 102 is only an implementation manner in which the first target protocol stack provides services for the foregoing application. In this embodiment, other protocol stacks that are started may be used to provide services for other applications. Of course, different protocols. The services provided by the stack can be different.
  • the selecting unit 102 may be configured to control an application to apply to the protocol stack; and allocate the foregoing first target protocol stack to the application according to a specific principle; and control the application to send the establishment to the first target protocol stack. a service request; and controlling the first target protocol stack to establish a service.
  • the protocol stack management layer dedicated to managing the protocol stack may also be used.
  • the module manages the protocol stack that is started.
  • the protocol stack management module can be a virtual module.
  • the port application and the protocol stack application can be applied to the protocol stack management module, and the protocol stack management module can allocate the port and the first target protocol stack to the application, and then notify the allocation result to the distribution result.
  • the application so that the application can send a setup service request to the first target protocol stack.
  • the selecting unit 102 may be configured to determine whether the application is bound to the protocol stack; if the application is bound to the protocol stack, when the application is only bound to a protocol stack, the protocol stack bound to the application is As the first target protocol stack; when the application is bound to multiple protocol stacks, a protocol stack is selected from the protocol stack bound by the application as the first target protocol stack;
  • the selecting unit 102 may be further configured to select one of the plurality of protocol stacks that are started as the first target protocol stack if the application is not bound to the protocol stack.
  • the above application may refer to a process or a thread of an application.
  • multiple protocol stacks that are started may be managed. For example, when the network load increases, a new protocol stack may be loaded when multiple protocol stacks that are currently started are processed. For example, when the network load is reduced, the protocol stack that needs to be uninstalled may be unloaded in multiple protocol stacks that are started, the protocol stack is unloaded, or the connection information of the protocol stack is migrated, and then the protocol stack is uninstalled;
  • the protocol stack refers to a protocol stack that does not have any connection or any load at present.
  • the foregoing connection information may include: TCP connection information, TCP service information, and/or UDP service information, which is not limited in this embodiment, for example: It may include: IP service information, FTP service information, SSH service information, etc.
  • connection information may refer to all network service information.
  • the TCP connection information may mainly refer to: state machine information, source IP address, source port number, destination IP address, destination port number, and destination protocol stack information of each connection.
  • TCP service information and UDP service information can mainly refer to: destination IP, destination port number, destination protocol stack information, and so on.
  • the stack can be reloaded.
  • this embodiment can establish a protocol stack management module management protocol stack.
  • the obtaining unit 103 is configured to acquire the first data packet, and parse the packet header of the first data packet, to obtain a first identifier included in the DPS domain in the packet header, where the DPS domain is used for carrying and receiving The identifier of the protocol stack or the domain of the specific identifier, where the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, and the receiving device is a device that identifies the destination address in the packet header,
  • the sending device is a device identified by the source address in the packet header.
  • the first data packet may be a data packet processed by the application, for example, the service type of the first data packet is a type that the first target protocol stack provides for the application.
  • the foregoing packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain may include processing the first data in the sending device.
  • the second identifier of the second target protocol stack of the packet In this way, the identifier of the second target protocol stack in the sending device can be known through the SPS domain, so that when the data packet is returned to the sending device, the identifier of the second target protocol stack can be carried in the DPS domain of the data packet.
  • the packet header of the first data packet may be a packet header as shown in FIG. 3, and the packet header may include: a version domain, a header length domain, a service type domain, a total length domain, a recombination identifier domain, a flag domain, and a segment offset domain. , time to live domain, protocol code field, header checksum and domain, source IP address domain, destination IP address domain, SPS domain, DPS domain, optional data domain, and user data domain.
  • the position of the SPS domain and the DPS domain in the present embodiment is not limited.
  • the allocating unit 104 is configured to allocate the first data packet to the first target protocol stack according to the first identifier, where the first target protocol stack processes the first data packet, where the first target protocol
  • the stack is the protocol stack in multiple protocol stacks that are started.
  • the allocating unit 104 may be configured to: when the first identifier is the identifier of the protocol stack of the receiving end, select the identifier that is the first identifier from the multiple protocol stacks that are started. a target protocol stack; and allocating the first data packet to the first target protocol stack, and processing the first data packet by the first target protocol stack.
  • the first target protocol stack may be searched according to the first identifier in the DPS domain, and the first data packet is allocated to the first target protocol stack, so that the first target protocol stack can process the first data packet independently.
  • the first target protocol stack does not have any protocol connection information with other protocol stacks.
  • the allocating unit 104 may be configured to: when the first identifier is the specific identifier, identify that the protocol stack is not established according to the first identifier, and the first Transmitting, by the first target protocol stack, the first target protocol stack, by the first target protocol stack, when the first target protocol stack identifies that the first target protocol stack includes a service of the service type of the first data packet A packet of data.
  • the service type of the first data packet is fixed, the service type provided by the first target protocol stack is also fixed. After the first target protocol stack obtains the first data packet, the service type of the first data packet may be detected. When the first target protocol stack includes the service type service of the first data packet, the first target The protocol stack processes the first data packet. Other protocol stacks do not include the service type of the first packet, so that these other protocol stacks can discard the first packet.
  • the allocating unit 104 may be configured to: when the first identifier is the specific identifier, identify, according to the first identifier, that the protocol stack is not established with the sending device, and the pre-acquired service is obtained. Finding a first target protocol stack in a correspondence relationship with the protocol stack, and then allocating the first data packet to the first target protocol stack, where the first target protocol stack processes the first data packet;
  • the correspondence relationship includes service information of each protocol stack, and the first target protocol stack is a protocol stack of a service including a service type of the first data packet.
  • the device may generate a correspondence between the service and the protocol stack, where the correspondence includes service information of each protocol stack, that is, the correspondence indicates a service of each protocol stack.
  • This can be the above correspondence generated when each protocol establishes a service for an application.
  • Each protocol stack can be serviced by different units through the selection unit 102, so that the above correspondence can be generated.
  • the correspondence may specifically be an information table of a service and a protocol stack.
  • the packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain includes processing, by the sending device, the first data packet.
  • the second identifier of the second target protocol stack as shown in FIG. 11, the device may further include: a sending unit 105, configured to return a second data packet to the sending device, where the second data is the a response packet of the data packet, the packet header of the second data packet includes an SPS domain and a DPS domain, where the SPS domain included in the packet header of the second data packet includes an identifier of the first target protocol stack, The DPS field included in the header of the second data packet includes the second identifier.
  • the second data packet may be directly allocated to the second target protocol stack according to the second identifier included in the DPS domain of the second data packet, by the second destination.
  • the first data packet may be a fragmented data packet, that is, the first data packet is a part of a certain data packet.
  • the DPS domain, the SPS domain, and the service type in the header of the fragmented data packet are the same, so that multiple packets obtained by fragmenting the same data packet can be allocated to the same protocol stack by the above device. . Because the DPS domain, the SPS domain, and the service type of the headers of multiple packets obtained by the same packet fragment are the same, the above steps must be allocated to the same protocol stack.
  • fragmented data packets of the same data stream may be aggregated into a buffer area, and all the fragmented data packets arrive at the buffer area and then synthesized into a complete data packet, and then distributed to the first target protocol stack for processing, thereby reducing The overhead of the first target protocol stack.
  • the foregoing device may be specifically applied to a server or a user terminal, where the server of the server may implement the foregoing device, or the user end of the user terminal may implement the foregoing device; or the kernel of the server or the user terminal may implement the foregoing.
  • the apparatus may also implement the foregoing apparatus by a user-mode centralized network parallel protocol stack of a server or a user terminal; and may also implement the foregoing apparatus by a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • FIG. 12 is a schematic structural diagram of another packet processing apparatus according to an embodiment of the present invention. As shown in FIG. 12, the method includes: a generating unit 121 and a sending unit 122, where:
  • a generating unit 12 configured to generate a first data packet by using a second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain, where the DPS domain is a protocol for carrying a receiving device An identifier of the stack or a domain of the specific identifier, where the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, where the receiving device is a device identified by the destination address in the packet header, and the sending device is a device identified by a source address in the packet header; the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device; the DPS domain includes a first identifier, and the SPS domain includes the second target protocol The second identifier of the stack.
  • the foregoing first data packet may be data that an application needs to send to the receiving device.
  • a packet for example: when an application needs to establish communication with the receiving device, the generating unit 12 can allocate the second target protocol stack to the application; wherein the generating unit 12 allocates the second target protocol stack to the application.
  • the second target protocol stack described above may be assigned to the application on a particular basis.
  • the generating unit 12 can also be used to determine whether the application is bound to the protocol stack; if the application is bound to the protocol stack, when the application is only bound to a protocol stack, the application is bound to the protocol. The stack is used as the second target protocol stack; when the application is bound to multiple protocol stacks, the least loaded protocol stack in the protocol stack bound by the application is used as the second target protocol stack;
  • the generating unit 12 can also be used to use the lightest protocol stack among the plurality of protocol stacks to be started as the second target protocol stack if the application is not bound to the protocol stack.
  • the above application may refer to a process or a thread of an application.
  • the source address may be a source IP address
  • the destination address may be a destination IP address.
  • the sending unit 122 is configured to send the first data packet to the receiving device, to enable the receiving device to allocate the first data packet to a first target protocol stack according to the first identifier, where the first The target protocol stack processes the first data packet; wherein the first target protocol stack is a protocol stack in multiple protocol stacks initiated by the receiving device.
  • the receiving device may parse the packet header of the first data packet to obtain a first identifier included in the DPS domain in the packet header, and then, according to the first identifier, The first data packet is allocated to a first target protocol stack, and the first target protocol stack processes the first data packet stack.
  • the apparatus may further include:
  • the receiving unit 123 is configured to receive a second data packet returned by the receiving device, where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain.
  • the SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier.
  • the allocating unit 124 is configured to allocate the second data packet to the second target protocol stack, where the second target protocol stack processes the second data packet.
  • the allocating unit 124 can directly allocate the second data packet to the second target protocol stack, and the second target protocol stack processes the second number. According to the package.
  • the foregoing device may be specifically applied to a server or a user terminal, where the server of the server may implement the foregoing device, or the user end of the user terminal may implement the foregoing device; or the kernel of the server or the user terminal may implement the foregoing.
  • the apparatus may also implement the foregoing apparatus by a user-mode centralized network parallel protocol stack of a server or a user terminal; and may also implement the foregoing apparatus by a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • the first data packet is generated by using the second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain; and the first data packet is sent to the receiving device;
  • the receiving device allocates the first data packet to the first target protocol stack according to the first identifier, where the first target protocol stack processes the first data packet, where the first target protocol stack is The protocol stack in the plurality of protocol stacks initiated by the receiving device.
  • the first target protocol stack is selected from the plurality of protocol stacks to process the first data packet according to the first identifier carried by the first data packet.
  • multiple cores access the same protocol stack at the same time.
  • FIG. 14 is a schematic structural diagram of another packet processing apparatus according to an embodiment of the present invention. As shown in FIG. 14, the method includes: a receiver 141 and a memory 142, and a receiver 141 and a memory, respectively.
  • the 142 is connected to the processor 143, wherein the memory 142 is configured to store a set of program codes, and the processor 143 is configured to invoke the code stored by the memory 142 to perform the following operations:
  • the identifier of the foregoing protocol stack may be used to uniquely identify the protocol stack. That is, a protocol stack uniquely corresponds to an identifier, so that only one protocol stack can be found by the identifier.
  • the identifier of the protocol stack can be a number, for example: Start 5 protocol stacks, then the identifiers of the 5 protocol stacks can be 1, 2, 3, 4, and 5 respectively.
  • the corresponding relationship between the receiving device and the sending device that does not establish a protocol stack may be that the sending device does not know which protocol stack on the receiving device processes the first data packet, that is, the sending device does not acquire the first device.
  • the identity of the protocol stack of the packet For example, when the first data packet is a request packet, the receiving device and the sending device may not establish a protocol stack correspondence relationship; or the first data packet is the first data that is sent by the sending device and the receiving device for the first time. When the packet is used, the receiving device and the transmitting device may not establish a protocol stack correspondence.
  • the source address may be a source IP address
  • the destination address may be a destination IP address
  • the multiple protocol stacks initiated above may be at least two protocol stacks.
  • the foregoing first data packet may be an IP data packet.
  • the foregoing apparatus may be specifically applied to a server or a user terminal, and specifically, the server of the server may implement the foregoing apparatus, or the user end of the user terminal may implement the foregoing method; or may implement the foregoing by using a kernel of a server or a user terminal.
  • the method may also implement the foregoing method by using a user-mode centralized network parallel protocol stack of a server or a user terminal; or implementing the above method by using a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a network-enabled smart device such as a tablet, a mobile phone, an electronic reader, a remote controller, a personal computer (PC), a notebook computer, a car device, a network television, a wearable device, or the like.
  • a network-enabled smart device such as a tablet, a mobile phone, an electronic reader, a remote controller, a personal computer (PC), a notebook computer, a car device, a network television, a wearable device, or the like.
  • the first data packet after acquiring the first data packet, is allocated to the first target protocol stack according to the first identifier included in the DPS field in the packet header of the first data packet, so that the first target protocol stack can be Processing the first data packet; wherein, the first target protocol stack is a protocol stack in multiple protocol stacks that are started.
  • the first target protocol stack is selected from the plurality of protocol stacks to process the first data packet according to the first identifier carried by the first data packet.
  • multiple cores access the same protocol stack at the same time.
  • Embodiments of the invention can improve the performance of the protocol stack, thereby improving the performance of the device. Referring to FIG. 15, FIG.
  • FIG. 15 is a block diagram of another packet processing apparatus according to an embodiment of the present invention.
  • the schematic diagram, as shown in FIG. 15, includes: a receiver 151 and a memory 152, and a processor 153 connected to the receiver 151 and the memory 152, respectively, wherein the memory 152 is configured to store a set of program codes,
  • the processor 153 is configured to invoke the code stored by the memory 152 to perform the following operations:
  • the first target protocol stack is selected from the plurality of protocol stacks to provide services for the application, where the service provided by the first target protocol stack for the application is a service of the service type of the first data packet;
  • the receiver 151 Obtaining, by the receiver 151, the first data packet, and parsing the packet header of the first data packet, to obtain a first identifier included in the DPS domain in the packet header, where the DPS domain is a protocol for carrying the receiving device An identifier of the stack or a domain of the specific identifier, where the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, where the receiving device is a device identified by the destination address in the packet header, and the sending device is a device identified by a source address in the packet header;
  • the processor 153 may start multiple protocol stacks in a certain order, and then assign an identifier to each activated protocol stack, for example: assign numbers according to the starting sequence.
  • the multiple protocol stacks are parallel protocol stacks, and the multiple protocol stacks can be independently operated protocol stacks.
  • the foregoing first target protocol stack provides services for the application, and the first target protocol stack provides services for processes or threads of the application.
  • the foregoing service may be a network service, for example: the foregoing service is all TCP/IP services for the TCP/IP protocol cluster; the foregoing server may also be a network service other than the TCP/IP protocol cluster, etc. Not limited.
  • the foregoing only describes the implementation manner in which the first target protocol stack provides services for the foregoing application.
  • the processor 153 can also implement other protocol stacks that are started to provide services for other applications. Of course, different The services provided by the protocol stack can be different.
  • selecting, by the processor 153, the first target protocol stack from the multiple protocol stacks may include:
  • the application applies for a protocol stack
  • the application sends a setup service request to the first target protocol stack
  • the first target protocol stack establishes a service.
  • the application can also apply for a port. If the application uses a protocol at the network layer or the data link layer, the port application is not required.
  • the processor 153 may also manage the initiated protocol stack through a protocol stack management module dedicated to managing the protocol stack.
  • the protocol stack management module can be a virtual module.
  • the port application and the protocol stack application can be applied to the protocol stack management module, and the protocol stack management module can allocate the port and the first target protocol stack to the application, and then notify the allocation result to the application.
  • the application so that the application can send a setup service request to the first target protocol stack.
  • the operation performed by the processor 153 to allocate the foregoing first target protocol stack to the application according to a specific principle may include:
  • the protocol stack bound by the application is used as the first target protocol stack; when the application is bound to multiple In the protocol stack, a protocol stack is selected from the protocol stack bound by the application as the first target protocol stack;
  • a protocol stack is selected from the plurality of protocol stacks that are started as the first target protocol stack.
  • the above application may refer to a process or a thread of an application.
  • the processor 153 may also manage multiple protocol stacks that are started, for example: when the network load increases, when multiple protocol stacks that are currently started are processed, a new protocol may be loaded.
  • Stack For example, when the network load is reduced, the protocol stack that needs to be uninstalled may be unloaded in multiple protocol stacks that are started, the protocol stack is unloaded, or the connection information of the protocol stack is migrated, and then the protocol stack is uninstalled;
  • the protocol stack refers to a protocol stack that does not currently have any connection or any load.
  • the above connection information may include: TCP connection information, TCP service information, and/or UDP service. The information is not limited in this embodiment.
  • connection information may also include: IP service information, FTP service information, SSH service information, etc.
  • connection information may refer to all network service information.
  • TCP connection information may mainly refer to: state machine information, source IP address, source port number, destination IP address, destination port number, and destination protocol stack information of each connection.
  • the TCP service information and the UDP service information may mainly refer to: destination IP, destination port number, destination protocol stack information, and the like.
  • the connection information of the protocol stack 1 is migrated to the protocol stack 2, and then the protocol stack 1 is unloaded, so that the protocol stack 2 can handle the connection on the protocol stack 1, that is, the protocol stack 2 can handle the load on the protocol stack 1.
  • this embodiment can establish a protocol stack management module management protocol stack.
  • the first data packet may be a data packet processed by the application, for example, the service type of the first data packet is a type that the first target protocol stack provides for the application.
  • the foregoing packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain may include processing the first data in the sending device.
  • the second identifier of the second target protocol stack of the packet In this way, the identifier of the second target protocol stack in the sending device can be known through the SPS domain, so that when the data packet is returned to the sending device, the identifier of the second target protocol stack can be carried in the DPS domain of the data packet.
  • the packet header of the first data packet may be a packet header as shown in FIG. 3, and the packet header may include: a version domain, a header length domain, a service type domain, a total length domain, a recombination identifier domain, a flag domain, and a segment offset domain. , time to live domain, protocol code field, header checksum and domain, source IP address domain, destination IP address domain, SPS domain, DPS domain, optional data domain, and user data domain.
  • the position of the SPS domain and the DPS domain in the present embodiment is not limited.
  • the first identifier is an identifier of a protocol stack of the receiving end
  • the processor 153 performs, according to the first identifier, allocating the first data packet to a first target protocol stack, where the first target is
  • the operation of the protocol stack to process the first data packet may include:
  • the first target protocol may be found according to the first identifier in the DPS domain.
  • the stack then allocates the first data packet to the first target protocol stack for processing, so that the first target protocol stack can process the first data packet independently, so that the first target protocol stack is completely independent, that is, the first target protocol stack and other protocols.
  • the stack does not have any protocol connection information.
  • the first identifier is the specific identifier
  • the first target protocol stack is allocated by the processor 153 according to the first identifier to the first target protocol stack.
  • the operation of the first data packet may include:
  • the first target protocol stack processes the first data packet when the stack includes a service of the service type of the first data packet.
  • the service type of the first data packet is fixed, the service type provided by the first target protocol stack is also fixed. After the first target protocol stack obtains the first data packet, the service type of the first data packet may be detected. When the first target protocol stack includes the service type service of the first data packet, the first target The protocol stack processes the first data packet. Other protocol stacks do not include the service type of the first packet, so that these other protocol stacks can discard the first packet.
  • the first identifier is the specific identifier
  • the first target protocol stack is allocated by the processor 153 according to the first identifier to the first target protocol stack.
  • the operation of the first data packet may include:
  • the first target protocol stack processes the first data packet; wherein the corresponding relationship includes service information of each protocol stack, and the first target protocol stack includes the The protocol stack of the service type of the first packet.
  • the device may generate a correspondence between the service and the protocol stack, where the correspondence includes service information of each protocol stack, that is, the correspondence indicates a service of each protocol stack.
  • This may be the above correspondence generated when each protocol establishes a service for an application.
  • Each protocol stack can be implemented by the processor 153 to provide services for different applications, so that the above correspondence can be generated.
  • the correspondence may specifically be an information table of a service and a protocol stack.
  • the packet header may further include an SPS domain, where the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device, where the SPS domain includes processing, by the sending device, the first data packet.
  • the second identifier of the second target protocol stack the apparatus may further include: a transmitter 154; the processor 153 is further configured to execute after the first target protocol stack performs the operation of processing the first data packet Do the following:
  • a second data packet to the sending device, where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain, where The SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack, and the DPS domain included in the packet header of the second data packet includes the second identifier.
  • the second data packet may be directly allocated to the second target protocol stack according to the second identifier included in the DPS domain of the second data packet, and the second target protocol stack is configured by the second target protocol stack. Process the second packet.
  • the first data packet may be a fragmented data packet, that is, the first data packet is a part of a certain data packet.
  • the DPS domain, the SPS domain, and the service type in the header of the fragmented data packet are the same, so that multiple packets obtained by fragmenting the same data packet can be allocated to the same protocol stack by the above steps. deal with. Because the DPS domain, SPS domain, and service type of the headers of multiple packets obtained by the same packet fragment are the same, the above steps must be assigned to the same protocol stack.
  • fragmented data packets of the same data stream may be aggregated into a buffer area, and all the fragmented data packets arrive at the buffer area and then synthesized into a complete data packet, and then distributed to the first target protocol stack for processing, thereby reducing The overhead of the first target protocol stack.
  • the foregoing device may be specifically applied to a server or a user terminal, where the server of the server may implement the foregoing device, or the user end of the user terminal may implement the foregoing device; or the kernel of the server or the user terminal may implement the foregoing.
  • the apparatus may also implement the foregoing apparatus by a user-mode centralized network parallel protocol stack of a server or a user terminal; and may also implement the foregoing apparatus by a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • FIG. 16 is a schematic structural diagram of another packet processing apparatus according to an embodiment of the present invention.
  • the method includes: a transmitter 161 and a memory 162, and the transmitter 161 and the memory, respectively. 162 connected processor 163, wherein the memory 162 is used to store a set of program codes, and the processor 163 is configured to invoke the code stored in the memory 162 to perform the following operations:
  • the header of the first data packet includes an SPS domain and a DPS domain
  • the DPS domain is an identifier or a specific identifier of a protocol stack for carrying a receiving device
  • the specific identifier is used to indicate that the receiving device does not establish a protocol stack corresponding to the sending device, the receiving device is a device identified by the destination address in the packet header, and the sending device is a source address in the packet header.
  • the identified device; the SPS domain is a domain for carrying an identifier of a protocol stack of the sending device;
  • the DPS domain includes a first identifier, and the SPS domain includes a second identifier of the second target protocol stack;
  • the transmitter 161 Transmitting, by the transmitter 161, the first data packet to the receiving device, so that the receiving device allocates the first data packet to a first target protocol stack according to the first identifier, the first The target protocol stack processes the first data packet; wherein the first target protocol stack is a protocol stack in multiple protocol stacks initiated by the receiving device.
  • the first data packet may be a data packet that an application needs to send to the receiving device, for example: when an application needs to establish communication with the receiving device, the processor 163 may allocate the foregoing to the application.
  • the second target protocol stack; wherein the processor 163 allocates the second target protocol stack to the application, the second target protocol stack may be allocated to the application according to a specific principle.
  • the operation performed by the processor 163 to allocate the foregoing second target protocol stack to the application according to a specific principle may include:
  • the protocol stack bound by the application is used as the second target protocol stack; when the application is bound to multiple When the protocol stack is used, the least loaded protocol stack in the protocol stack bound by the application is used as the second target protocol stack;
  • the lightest protocol stack among multiple protocol stacks that will be started if the application is not bound to the protocol stack As the above second target protocol stack.
  • the above application may refer to a process or a thread of an application.
  • the source address may be a source IP address
  • the destination address may be a destination IP address
  • the device may further include a receiver 164, where: after the processor 163 sends the first data packet to the receiving device by using the transmitter 161, the processor 163 is further configured to perform the following operations. :
  • a second data packet returned by the receiving device where the second data is a response data packet of the first data packet, and a packet header of the second data packet includes an SPS domain and a DPS domain
  • the SPS field included in the packet header of the second data packet includes an identifier of the first target protocol stack
  • the DPS domain included in the packet header of the second data packet includes the second identifier
  • the second data packet is allocated to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • the step 504 can directly allocate the second data packet to the second target protocol stack, and the second target protocol stack processes the second data packet.
  • the foregoing device may be specifically applied to a server or a user terminal, where the server of the server may implement the foregoing device, or the user end of the user terminal may implement the foregoing device; or the kernel of the server or the user terminal may implement the foregoing.
  • the apparatus may also implement the foregoing apparatus by a user-mode centralized network parallel protocol stack of a server or a user terminal; and may also implement the foregoing apparatus by a lib library protocol stack of a server or a user terminal. among them.
  • the user terminal can be a smart device with a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • a network function such as a tablet, a mobile phone, an electronic reader, a remote controller, a PC, a notebook computer, an in-vehicle device, a network television, a wearable device, or the like.
  • the first data packet is generated by using the second target protocol stack, where the header of the first data packet includes an SPS domain and a DPS domain; and the first data packet is sent to the receiving device;
  • the receiving device allocates the first data packet to the first target protocol stack according to the first identifier, where the first target protocol stack processes the first data packet, where the first target protocol stack is The protocol stack in the plurality of protocol stacks initiated by the receiving device.
  • the first target protocol stack is selected from the plurality of protocol stacks to process the first data packet according to the first identifier carried by the first data packet.
  • Embodiments of the invention can improve the protocol stack Performance, thereby improving the performance of the device.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (Random Access Memory).

Abstract

本发明实施例公开了一种数据包处理方法和装置,该可包括:获取第一数据包,并解析所述第一数据包的包头,得到所述包头中DPS域包括的第一标识;其中,所述DPS域为用于携带接收设备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的设备,所述发送设备为所述包头中源地址标识的设备;根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述第一数据包;其中,所述第一目标协议栈为启动的多个协议栈中的协议栈。本发明实施例可以提高协议栈的性能,从而提高设备的性能。

Description

一种数据包处理方法和装置
技术领域
本发明涉及通信领域, 尤其涉及一种数据包处理方法和装置。 背景技术
网络通信技术的快速发展促使网络带宽和流量不断增大,而网络带宽和流 量的增大, 导致协议栈的负载也增大, 这样协议栈的处理能力逐渐成为设备总 体性能的瓶颈。
虽然目前多核技术和网卡多队列技术的出现,能够将网络负载分摊到多个 内核上,但这些内核仍然共享一个协议栈。这样当多个内核同时获取到数据包 时, 这些内核都就会同时去访问协议栈的套接字 (socket )链表, 或者访问协 议栈的传输控制协议 ( Transmission Control Protocol, TCP )状态机或者通过 协议栈进行 TCP重组或者通过协议栈进行因特网互联协议( Internet Protocol , IP ) 重组时, 都将导致锁竟争开销、 緩存(cache ) 失效开销、 同步开销或者 异步开销等额外的开销。 且内核数越多时, 这些额外的开销就会越多。
可见, 目前协议栈的性能比较低, 从而设备的性能也会比较低。 发明内容
本发明实施例提供了一种数据包处理方法和装置,可以解决目前协议栈的 性能比较低, 从而设备的性能也会比较低的问题。
第一方面, 本发明实施例提供一种数据包处理方法, 包括:
获取第一数据包, 并解析所述第一数据包的包头,得到所述包头中目标协 议栈( Destination Protocol Stack , DPS )域包括的第一标识; 其中, 所述 DPS 为用于携带接收设备的协议栈的标识或者特定标识的域,所述特定标识用于表 示所述接收设备与发送设备未建立协议栈对应关系,所述接收设备为所述包头 中目的地址标识的设备, 所述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈 ,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
在第一方面的第一种可能的实现方式中,所述第一标识为所述接收端的协 议栈的标识;
所述根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第 一目标协议栈处理所述第一数据包, 包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈 ,所述第一目标协议栈处理 所述第一数据包。
结合第一方面,在第一方面的第二种可能的实现方式中, 所述第一标识为 所述特定标识;
所述根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第 一目标协议栈处理所述第一数据包, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包; 或者
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
结合第一方面或者第一方面的第一种可能的实现方式或者第一方面的第 二种可能的实现方式,在第一方面的第三种可能的实现方式中, 所述包头还包 括源协议栈(Source Protocol Stack , SPS )域, 所述 SPS域为用于携带所述 发送设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第 一数据包的第二目标协议栈的第二标识;
所述第一目标协议栈处理所述第一数据包之后, 所述方法还包括: 向所述发送设备返回第二数据包,所述第二数据为所述第一数据包的响应 数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据 包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的 包头包括的 DPS域包括所述第二标识。
结合第一方面或者第一方面的第一种可能的实现方式或者第一方面的第 二种可能的实现方式,在第一方面的第四种可能的实现方式中, 所述获取第一 数据包, 并解析所述第一数据包的包头, 得到所述包头中 DPS域包括的第一 标识之前, 所述方法还包括:
启动多个协议栈, 并为每个协议栈分配标识;
当应用程序需要使用网络时,从所述多个协议栈中选择所述第一目标协议 栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程序提供 的服务为所述第一数据包的服务类型的服务。
第二方面, 本发明实施例提供一种数据包处理方法, 其特征在于, 包括: 通过第二目标协议栈生成第一数据包,所述第一数据包的得到所述包头包 括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈的标识 或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协 议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备,所述发送设 备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送设备的 协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述第二目 标协议栈的第二标识;
向所述接收设备发送所述第一数据包;以使所述接收设备根据所述第一标 识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述第 一数据包; 其中, 所述第一目标协议栈为所述接收设备启动的多个协议栈中的 协议栈。
在第二方面的第一种可能实现方式中,所述向所述接收设备发送所述第一 数据包之后, 所述方法还包括:
接收所述接收设备返回的第二数据包,所述第二数据为所述第一数据包的 响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二 数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述第二数据 包的包头包括的 DPS域包括所述第二标识; 将所述第二数据包分配至所述第二目标协议栈,所述第二目标协议栈处理 所述第二数据包。
第三方面, 本发明实施例提供一种数据包处理装置, 包括: 获取单元和分 配单元, 其中:
所述获取单元, 用于获取第一数据包, 并解析所述第一数据包的包头, 得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备;
所述分配单元,用于根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 通过所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标 协议栈为启动的多个协议栈中的协议栈。
在第三方面的第一种可能的实现方式中,所述分配单元用于当所述第一标 识所述第一标识为所述接收端的协议栈的标识时,从启动的多个协议栈中选择 标识为所述第一标识的第一目标协议栈;以及将所述第一数据包分配至所述第 一目标协议栈, 通过所述第一目标协议栈处理所述第一数据包。
结合第三方面,在第三方面的第二种可能的实现方式中, 所述分配单元用 于当所述第一标识为所述特定标识时,根据所述第一标识识别到未与所述发送 设备未建立协议栈对应关系, 并将所述第一数据包广播给启动的多个协议栈, 当第一目标协议栈识别该第一目标协议栈包括所述第一数据包的服务类型的 服务时, 通过所述第一目标协议栈处理所述第一数据包; 或者
所述分配单元用于当所述第一标识为所述特定标识时,根据所述第一标识 识别到未与所述发送设备未建立协议栈对应关系 ,并从预先获取的服务与协议 栈的对应关系中查找第一目标协议栈,再将所述第一数据包分配至所述第一目 标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包 括每个协议栈的服务信息,所述第一目标协议栈为包括所述第一数据包的服务 类型的服务的协议栈。
结合第三方面或者第三方面的第一种可能的实现方式或者第三方面的第 二种可能的实现方式,在第三方面的第三种可能的实现方式中, 所述包头还包 括 SPS域, 所述 SPS域为用于携带所述发送设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数据包的第二目标协议栈的第二标 识;
所述装置还包括:
发送单元, 用于向所述发送设备返回第二数据包, 所述第二数据为所述第 一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述 第二数据包的包头包括的 DPS域包括所述第二标识。
结合第三方面或者第三方面的第一种可能的实现方式或者第三方面的第 二种可能的实现方式,在第三方面的第四种可能的实现方式中, 所述装置还包 括:
启动单元, 用于启动多个协议栈, 并为每个协议栈分配标识;
选择单元, 用于当应用程序需要使用网络时,从所述多个协议栈中选择所 述第一目标协议栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所 述应用程序提供的服务为所述第一数据包的服务类型的服务。
第四方面, 本发明实施例提供一种数据包处理装置, 包括: 生成单元和发 送单元, 其中:
所述生成单元, 用于通过第二目标协议栈生成第一数据包, 所述第一数据 包的得到所述包头包括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收 设备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备 与发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识 的设备, 所述发送设备为所述包头中源地址标识的设备; 所述 SPS域为用于 携带所述发送设备的协议栈的标识的域;所述 DPS域包括第一标识,所述 SPS 域包括所述第二目标协议栈的第二标识;
所述发送单元, 用于向所述接收设备发送所述第一数据包; 以使所述接收 设备根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启 动的多个协议栈中的协议栈。
在第四方面的第一种可能的实现方式中, 所述装置还包括: 接收单元, 用于接收所述接收设备返回的第二数据包, 所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
分配单元, 用于将所述第二数据包分配至所述第二目标协议栈, 所述第二 目标协议栈处理所述第二数据包。
第五方面, 本发明实施例提供一种数据包处理装置, 包括: 接收器和存储 器, 以及分别与所述接收器和存储器连接的处理器, 其中, 所述存储器用于存 储一组程序代码, 所述处理器用于调用所述存储器存储的代码执行如下操作: 通过所述接收器获取第一数据包, 并解析所述第一数据包的包头,得到所 述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设备的 协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送 设备未建立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设 备, 所述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
在第五方面的第一种可能实现方式中,所述第一标识为所述接收端的协议 栈的标识;
所述处理器执行的根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 所述第一目标协议栈处理所述第一数据包的操作, 包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈 ,所述第一目标协议栈处理 所述第一数据包。
结合第五方面,在第五方面的第二种可能实现方式中, 所述第一标识为所 述特定标识;
所述处理器执行的根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 所述第一目标协议栈处理所述第一数据包的操作, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系 ,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包; 或者
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
结合第五方面或者第五方面的第一种可能实现方式或者第五方面的第二 种可能实现方式, 在第五方面的第三种可能实现方式中, 所述包头还包括 SPS 域, 所述 SPS域为用于携带所述发送设备的协议栈的标识的域, 所述 SPS域 包括所述发送设备中处理所述第一数据包的第二目标协议栈的第二标识;
所述装置还包括发射器,所述处理器在执行第一目标协议栈处理所述第一 数据包的操作之后, 所述处理器还用于执行如下操作:
通过所述发射器向所述发送设备返回第二数据包,所述第二数据为所述第 一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述 第二数据包的包头包括的 DPS域包括所述第二标识。
结合第五方面或者第五方面的第一种可能实现方式或者第五方面的第二 种可能实现方式,在第五方面的第四种可能实现方式中,所述获取第一数据包, 并解析所述第一数据包的包头,得到所述包头中 DPS域包括的第一标识之前, 所述方法还包括:
启动多个协议栈, 并为每个协议栈分配标识;
当应用程序需要使用网络时,从所述多个协议栈中选择所述第一目标协议 栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程序提供 的服务为所述第一数据包的服务类型的服务。
第六方面, 本发明实施例提供数据包处理装置, 包括: 发射器和存储器, 以及分别与所述发射器和存储器连接的处理器, 其中, 所述存储器用于存储一 组程序代码, 所述处理器用于调用所述存储器存储的代码执行如下操作: 通过第二目标协议栈生成第一数据包,所述第一数据包的得到所述包头包 括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈的标识 或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协 议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备,所述发送设 备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送设备的 协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述第二目 标协议栈的第二标识;
通过所述发射器向所述接收设备发送所述第一数据包;以使所述接收设备 根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目标协 议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启动的 多个协议栈中的协议栈。
在第六方面的第一种可能的实现方式中, 所述装置还包括接收器, 其中: 所述处理器在执行通过所述发射器向所述接收设备发送所述第一数据包的操 作之后, 还用于执行如下操作:
通过所述接收器接收所述接收设备返回的第二数据包,所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
将所述第二数据包分配至所述第二目标协议栈,所述第二目标协议栈处理 所述第二数据包。
上述技术方案中, 获取第一数据包后会根据第一数据包的包头中 DPS域 包括的第一标识将所述第一数据包分配至第一目标协议栈,这样第一目标协议 栈就可以处理所述第一数据包; 而其中, 第一目标协议栈为启动的多个协议栈 中的协议栈。这样就可以实现根据第一数据包携带的第一标识从多个协议栈中 选择第一目标协议栈处理第一数据包,相比现有技术中, 多个内核同时访问同 一个协议栈, 本发明实施例可以提高协议栈的性能, 从而提高设备的性能。 附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施 例或现有技术描述中所需要使用的附图作筒单地介绍,显而易见地, 下面描述 中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲, 在不付 出创造性劳动的前提下, 还可以根据这些附图获得其他的附图。
图 1是本发明实施例提供的一种数据包处理方法的流程示意图; 图 2是本发明实施例提供的另一种数据包处理方法的流程示意图; 图 3是本发明实施例提供的一种可选的包头示意图;
图 4是本发明实施例提供的另一种数据包处理方法的流程示意图; 图 5是本发明实施例提供的另一种数据包处理方法的流程示意图; 图 6是本发明实施例提供的另一种数据包处理方法的流程示意图; 图 Ί是本发明实施例提供的另一种数据包处理方法的示意图;
图 8是本发明实施例提供的一种可选的场景示意图;
图 9是本发明实施例提供的一种数据包处理装置的结构示意图; 图 10是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 11是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 12是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 13是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 14是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 15是本发明实施例提供的另一种数据包处理装置的结构示意图; 图 16是本发明实施例提供的另一种数据包处理装置的结构示意图。 具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。基于本发明中的实施例, 本领域普通技术人员在没有作出创造 性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。
请参阅图 1 , 图 1是本发明实施例提供的一种数据包处理方法的流程示意 图, 如图 1所示, 包括以下步骤:
101、 获取第一数据包, 并解析所述第一数据包的包头, 得到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设备的协议栈的 标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建 立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备, 所述发 送设备为所述包头中源地址标识的设备。
可选的, 上述协议栈的标识可以是用于唯一标识协议栈。 即一个协议栈唯 一对应一个标识, 这样通过该标识就可以查找到唯——个协议栈。 例如: 协议 栈的标识可以是编号, 例如: 启动 5个协议栈, 那么这 5个协议栈的标识就可 以分别为 1、 2、 3、 4、 5。
可选的, 上述接收设备与发送设备未建立协议栈对应关系可以是指,发送 设备不知道接收设备上是哪个协议栈处理上述第一数据包,即发送设备未获取 接收设备上处理上述第一数据包的协议栈的标识。 例如, 上述第一数据包为请 求包时, 上述接收设备与发送设备就可能未建立协议栈对应关系; 或者, 上述 第一数据包为上述发送设备与接收设备第一次通信的第一个数据包时,上述接 收设备与发送设备就可能未建立协议栈对应关系。
可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。 102、 根据所述第一标识将所述第一数据包分配至第一目标协议栈, 所述 第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多 个协议栈中的协议栈。
可选的, 上述启动的多个协议栈可以是至少两个协议栈。
可选的, 上述第一数据包可以是 IP数据包。
可选的, 上述方法具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述方法, 或者用户终端的用户端可以实现上述方 法; 还可以服务器或者用户终端的内核实现上述方法; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述方法;还可以服务器或者用户终 端的 lib库协议栈实现上述方法。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 个人计算机( Personal Computer, PC )、 笔记本电脑、 车 载设备、 网络电视、 可穿戴设备等具有网络功能的智能设备。
上述技术方案中, 获取第一数据包后会根据第一数据包的包头中 DPS域 包括的第一标识将所述第一数据包分配至第一目标协议栈,这样第一目标协议 栈就可以处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。这样就可以实现根据第一数据包携带的第一标识从多个协议栈 中选择第一目标协议栈处理第一数据包,相比现有技术中, 多个内核同时访问 同一个协议栈, 本发明实施例可以提高协议栈的性能, 从而提高设备的性能。 请参阅图 2, 图 2是本发明实施例提供的另一种数据包处理方法的流程示 意图, 如图 2所示, 包括以下步骤:
201、 启动多个协议栈, 并为每个协议栈分配标识。
可选的, 步骤 201可以是按照一定顺序启动多个协议栈,再为每个启动的 协议栈分配标识, 例如: 按照启动的先后顺序分配编号。 另外, 由于启动多个 协议栈, 这样这多个协议栈就为并行协议栈,且这多个协议栈可以是独立运行 的协议栈。
202、 当应用程序需要使用网络时, 从所述多个协议栈中选择所述第一目 标协议栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程 序提供的服务为所述第一数据包的服务类型的服务。
可选的,上述应用程序需要使用网络可以是指应用程序的进程或者线程需 要使用网络。上述第一目标协议栈为所述应用程序提供服务可以是, 第一目标 协议栈为应用程序的进程或者线程提供服务。其中,上述服务可以是网络服务, 例如: 上述服务对于 TCP/IP协议簇来说就是所有的 TCP/IP服务; 该上述服务 器还可以非 TCP/IP协议簇的网络服务等, 本实施例对此不作限定。 另外, 步 骤 202仅是介绍了第一目标协议栈为上述应用程序提供服务的实现方式,在本 实施例中还可以实现为启动的其它协议栈为其它应用程序提供服务, 当然, 不 同的协议栈提供的服务可以是不同的。
可选的 ,上述从所述多个协议栈中选择所述第一目标协议栈为所述应用程 序提供服务, 可以包括:
应用程序申请协议栈;
按特定原则为所述应用程序分配上述第一目标协议栈;
应用程序向所述第一目标协议栈发送建立服务请求;
第一目标协议栈建立服务。
可选的, 当应用程序需要传输层协议进行网络服务,应用程序还可以进行 端口申请, 如果应用程序用的是网络层或者数据链路层的协议时, 就可以不需 要端口申请。
可选的, 本实施例中,还可以通过一个专门用于管理协议栈的协议栈管理 模块管理启动的协议栈。 其中, 该协议栈管理模块可以是一个虚拟的模块。 这 样应用程序需要使用网络时,就可以向该协议栈管理模块进行端口申请和协议 栈申请, 该协议栈管理模块就可以为该应用程序分配端口和第一目标协议栈, 再将分配结果通知给应用程序,这样应用程序就可以向第一目标协议栈发送建 立服务请求。另外,上述按特定原则为所述应用程序分配上述第一目标协议栈, 可以包括:
判断上述应用程序是否绑定协议栈;
若上述应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时, 将该应用程序绑定的协议栈为作为上述第一目标协议栈;当上述应用程序绑定 了多个协议栈时 ,从该应用程序绑定的协议栈中选择一个协议栈作为上述第一 目标协议栈;
若上述应用程序未绑定协议栈时,从启动的多个协议栈中选择一个协议栈 作为上述第一目标协议栈。
可选的,上述从该应用程序绑定的协议栈中选择一个协议栈作为上述第一 目标协议栈可以是,从该应用程序绑定的协议栈中选择负载最轻的协议栈作为 上述第一目标协议,或者可以按照其他的分配方式来分配协议栈, 比如轮询方 式: 第一次分配为应用程序分配绑定的多个协议栈中的第一协议栈, 第二次分 配为应用程序分配绑定的多个协议栈中的第二协议栈等,对此本实施例不作限 定。 同理,从启动的多个协议栈中选择一个协议栈作为上述第一目标协议栈可 以是, 从启动的多个协议栈中选择负载最轻的协议栈作为上述第一目标协议 栈, 或者可以按照其他的分配方式来分配协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。
可选的, 本实施例中, 还可以对启动的多个协议栈进行管理, 例如: 当网 络负载增大时, 当前启动的多个协议栈处理不过来时, 可以加载新的协议栈。 例如: 当网络负载减小时, 可以将启动的多个协议栈中存在需要卸载的协议栈 时, 卸载该协议栈, 或者迁移该协议栈的连接信息, 再卸载该协议栈; 其中, 该需要卸载的协议栈是指当前没有任何连接或者没有任何负载的协议栈,上述 连接信息可以包括: TCP连接信息、 TCP服务信息和 /或用户数据报协议(User Datagram Protocol, UDP )服务信息, 对此本实施例不作限定, 例如: 连接信 息还可以包括: IP服务信息、 文件传输协议(File Transfer Protocol, FTP )服 务信息、 安全壳协议(Secure Shell, SSH )服务信息等, 总的来说: 连接信息 就可以指所有的网络服务信息。 另外, TCP连接信息主要可以指: 每个连接的 状态机信息、 源 IP地址、 源端口号、 目的 IP地址、 目的端口号、 目的协议栈 信息。 TCP服务信息和 UDP服务信息主要可以是指: 目的 IP、 目的端口号、 目的协议栈信息等。 例如: 将协议栈 1的连接信息迁移至协议栈 2, 再卸载协 议栈 1 , 这样协议栈 2就可以处理协议栈 1上的连接, 即协议栈 2就可以处理 协议栈 1上的负载。 例如: 当某一个协议栈因错误导致异常时, 还可以重新加 载该协议栈。 另外, 本实施例可以建立一个协议栈管理模块管理协议栈。
203、 获取第一数据包, 并解析所述第一数据包的包头, 得到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设备的协议栈的 标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建 立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备, 所述发 送设备为所述包头中源地址标识的设备。
可选的, 上述第一数据包可以是上述应用程序处理的数据包, 例如: 上述 第一数据包的服务类型为上述第一目标协议栈为所述应用程序提供服务的类 型。
可选的, 上述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域可以是包括所述发送设备中处理所述 第一数据包的第二目标协议栈的第二标识。 这样通过该 SPS域就可以知道发 送设备中第二目标协议栈的标识, 这样在往发送设备返回数据包时,就可以在 数据包的 DPS域中携带该第二目标协议栈的标识。
可选的, 第一数据包的包头可以为如图 3所示包头, 该包头可以包括: 版 本域、 头长域、 服务类型域、 总长域、 重组标识域、 标志域、 段偏移量域、 生 存时间域、 协议代码域、 头检验和域、 源 IP地址域、 目的 IP地址域、 SPS域、 DPS域、 可选数据域和用户数据域。 另外, 本实施例中对 SPS域和 DPS域的 长度不限的位置可以不作限定。
204、 根据所述第一标识将所述第一数据包分配至第一目标协议栈, 所述 第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多 个协议栈中的协议栈。
可选的, 当上述第一标识为所述接收端的协议栈的标识时, 步骤 204, 可 以包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈,所述第一目标协议栈处理 所述第一数据包。
该实施方式, 可以根据实现 DPS域中第一标识查找到上述第一目标协议 栈,再将第一数据包分配至第一目标协议栈处理, 这样可以第一目标协议栈独 立处理第一数据包, 以实现第一目标协议栈完全独立, 即第一目标协议栈与其 它协议栈没有任何协议连接信息。
可选的, 当上述第一标识为所述特定标识时, 步骤 204可以包括: 根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包。
该实施方式中由于第一数据包的服务类型是固定的,而上述第一目标协议 栈提供的服务类型也是固定的。这样当第一目标协议栈获取到上述第一数据包 后, 就可以检测第一数据包的服务类型, 当第一目标协议栈包括所述第一数据 包的服务类型的服务时, 第一目标协议栈处理所述第一数据包。 而其它协议栈 不包括第一数据包的服务类型的服务,这样这些其它协议栈就可以丟弃第一数 据包。
可选的, 当上述第一标识为所述特定标识时, 步骤 204可以包括: 根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
可选的,在步骤 204之前, 所述方法可以生成上述服务与协议栈的对应关 系, 该对应关系包括每个协议栈的服务信息, 即该对应关系表明每个协议栈的 服务。 可以是在每个协议为应用程序建立服务时生成的上述对应关系。 例如: 每个协议栈都可以通过步骤 202的实现方式为不同的应用程序提供服务,这样 就可以生成上述对应关系。 另外, 该对应关系具体可以是服务与协议栈的信息 表。
可选的, 所述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数 据包的第二目标协议栈的第二标识; 如图 4所示, 在步骤 204之前, 所述方法 还可以包括:
205、 向所述发送设备返回第二数据包, 所述第二数据为所述第一数据包 的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第 二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数 据包的包头包括的 DPS域包括所述第二标识。
这样当发送设备接收到上述第二数据包时, 就可以是根据第二数据包的 DPS域包括的第二标识,直接将第二数据包分配至第二目标协议栈, 由第二目 标协议栈处理第二数据包。
可选的, 上述第一数据包可以是分片后的数据包, 即第一数据包为某一数 据包中的一部分。 但是分片后的数据包的包头中的 DPS域、 SPS域和服务类 型是一致的,这样通过上述步骤就可以实现将同一个数据包分片得到的多个数 据包分配至同一个协议栈处理。因为同一个数据包分片得到的多个数据包的包 头中的 DPS域、 SPS域和服务类型都是相同的, 这样通过上述步骤就一定会 分配至同一个协议栈。 另外, 可以采取将同一个数据流的分片数据包聚合到一 个緩存区中,待所有分片数据包都到达緩存区再合成一个完整数据包后再分配 至第一目标协议栈处理, 以减少第一目标协议栈的开销。
可选的, 上述方法具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述方法, 或者用户终端的用户端可以实现上述方 法; 还可以服务器或者用户终端的内核实现上述方法; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述方法;还可以服务器或者用户终 端的 lib库协议栈实现上述方法。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 在第一个实施例的基本上增加了多种可选的实施方式, 且都可以实现提高协议栈的性能, 从而提高设备的性能。 请参阅图 5 , 图 5是本发明实施例提供的另一种数据包处理方法的流程示 意图, 如图 5所示, 包括以下步骤:
501、 通过第二目标协议栈生成第一数据包, 所述第一数据包的得到所述 包头包括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈 的标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未 建立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备, 所述 发送设备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述 第二目标协议栈的第二标识。
可选的,上述第一数据包可以是某个应用程序需要向接收设备发送的数据 包, 例如: 当某一应用程序需要与接收设备建立通信时, 就可以为该应用程序 分配上述第二目标协议栈; 其中, 为该应用程序分配上述第二目标协议栈可以 是按特定原则为该应用程序分配上述第二目标协议栈。上述按特定原则为该应 用程序分配上述第二目标协议栈, 可以包括:
判断该应用程序是否绑定协议栈;
若该应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时, 将 该应用程序绑定的协议栈为作为上述第二目标协议栈;当上述应用程序绑定了 多个协议栈时,将该应用程序绑定的协议栈中负载最轻的协议栈作为上述第二 目标协议栈;
若该应用程序未绑定协议栈时,将启动的多个协议栈中负载最轻的协议栈 作为上述第二目标协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。 可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。
502、 向所述接收设备发送所述第一数据包; 以使所述接收设备根据所述 第一标识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理 所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启动的多个协议 栈中的协议栈。
可选的,接收设备接收到上述第一数据包后, 就可以解析所述第一数据包 的包头, 得到所述包头中 DPS域包括的第一标识; 再根据所述第一标识将所 述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述第一数据 包栈。
可选的, 如图 6所示, 在步骤 502之后, 所述方法还可以包括:
503、 接收所述接收设备返回的第二数据包, 所述第二数据为所述第一数 据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所 述第二数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述第 二数据包的包头包括的 DPS域包括所述第二标识;
504、 将所述第二数据包分配至所述第二目标协议栈, 所述第二目标协议 栈处理所述第二数据包。
由于上述第二数据包的 DPS域包括上述第二标识, 这样步骤 504就可以 直接将第二数据包分配至第二目标协议栈, 由第二目标协议栈处理第二数据 包。
可选的, 上述方法具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述方法, 或者用户终端的用户端可以实现上述方 法; 还可以服务器或者用户终端的内核实现上述方法; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述方法;还可以服务器或者用户终 端的 lib库协议栈实现上述方法。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 通过第二目标协议栈生成第一数据包, 所述第一数据包 的得到所述包头包括 SPS域和 DPS域;向所述接收设备发送所述第一数据包; 以使所述接收设备根据所述第一标识将所述第一数据包分配至第一目标协议 栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为 所述接收设备启动的多个协议栈中的协议栈。这样就可以实现根据第一数据包 携带的第一标识从多个协议栈中选择第一目标协议栈处理第一数据包,相比现 有技术中, 多个内核同时访问同一个协议栈, 本发明实施例可以提高协议栈的 性能, 从而提高设备的性能。 请参阅图 7和图 8, 图 7是本发明实施例提供的另一种数据包处理方法的 示意图, 图 8是本发明实施例提供的一种可选的场景示意图; 其中, 该实施例 以 IP为 192.168.1.1的服务器的提供 TCP 80服务(例如: 网页服务使用 TCP 的 80端口 ) , IP为 192.168.1.2的用户终端请求月良务进行举例说明。 如图 7所 示, 该实施例可以包括如下步骤:
701、服务器的服务端进程或者线程申请 80端口,再向协议栈管理模块申 请协议栈(这可以是以消息的形式发送, 也可以是系统提供给应用程序的 API 接口);
702、服务器的协议栈管理模块按照规则从协议栈 #1和协议栈 #2中按照负 载均衡规则选择协议栈 #1 , 并将选择结果反馈给服务端进程或线程;
703、 服务器的服务端进程或者线程将服务建立请求发送给协议栈 #1 , 要 求建立 TCP 80服务;
704、 服务器的协议栈 #1创建 TCP 80服务, 该服务当前处于待连接状态 (即侦听状态, 表示服务端准备就绪, 等待客户端的连接请求), 并将创建结 果返回给服务端进程或线程;
705、 用户终端的客户端进程需要 tcp 80服务时, 该进程向协议栈管理模 块申请协议栈;
706、 用户终端的协议栈管理模块按照规则从当前合法的协议栈中 (该系 统目前只加载了一个协议栈)中按照负载均衡规则选择协议栈 #1 , 并将选择结 果反馈给客户端进程或线程;
707、用户终端的客户端进程或线程将连接请求(连接 IP地址为 192.168.1.1 的 TCP 80服务 )传给协议栈 #1 ;
708、 用户终端的协议栈 #1首先获得一个空闲 TCP端口 (比如 TCP 8888 端口), 然后构造连接请求的 IP数据包通过网卡发送给 IP地址为 192.168.1.1 的服务器;其中,连接请求的 IP数据包头的关键部分为:源 IP地址 192.168.1.2, 目的 IP地址 192.168.1.1 ; SP域为 1 , DPS域为 0, DPS域为 0可以等于上 面实施例介绍的特定标识; SP域为 1 , DPS域为 0是因为此时用户终端的协 议栈已经知道是协议栈 #1了, 所以 SPS为 1 , 但是目的 IP地址端的协议栈尚 不知道,所以 DPS为 0;连接请求的 TCP数据包头的关键部分为:源端口 8888, 目的端口 80;
709、 服务器接收到该 IP数据包, DPS分发模块从緩冲队列中获取该 IP 数据包;
7010、服务器的 DPS分发模块通过解析发现, 该 IP数据包 IP头的 DP值 为 0, DPS分发模块将该 IP数据广播给协议栈 #1和协议栈 #2;
7011、服务器的协议栈 #1收到该 IP数据包后,发现该 IP数据包为 TCP 80 服务的连接请求, 故发送一个连接请求回复数据包给用户终端; 其中, 连接请 求回复数据包关键部分为: 源 IP地址 192.168.1.1 , 目的 IP地址 192.168.1.2; SPSl , DP S1 ; 至此两端协议栈关联关系已经建立, 此时该连接的 IP数据包就 直接走这两个关联的协议栈。 由于协议栈 #2中没有 TCP 80服务, 故协议栈 #2 将丟弃该 IP数据包。
在图 8所示的示意图中,表示了该实施例中每个步骤的数据走向示意, 另 外, 本实施例中, DPS分发模块、 协议栈管理模块和协议栈都可以是由硬件, 或者软件实现的, 对此本实施例不作限定; 例如: 上述 DPS分发模块可以是 由网卡中硬件实现, 也可以通过软件实现。 下面为本发明装置实施例,本发明装置实施例用于执行本发明方法实施例 一至四实现的方法, 为了便于说明, 仅示出了与本发明实施例相关的部分, 具 体技术细节未揭示的, 请参照本发明实施例一、 实施例二、 实施例三和实施例 四。 请参阅图 9, 图 9是本发明实施例提供的一种数据包处理装置的结构示意 图, 如图 9所示, 包括: 获取单元 91和分配单元 92, 其中: 获取单元 91 , 用于获取第一数据包, 并解析所述第一数据包的包头, 得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备。
可选的, 上述协议栈的标识可以是用于唯一标识协议栈。 即一个协议栈唯 一对应一个标识, 这样通过该标识就可以查找到唯——个协议栈。 例如: 协议 栈的标识可以是编号, 例如: 启动 5个协议栈, 那么这 5个协议栈的标识就可 以分别为 1、 2、 3、 4、 5。
可选的, 上述接收设备与发送设备未建立协议栈对应关系可以是指,发送 设备不知道接收设备上是哪个协议栈处理上述第一数据包,即发送设备未获取 接收设备上处理上述第一数据包的协议栈的标识。 例如, 上述第一数据包为请 求包时, 上述接收设备与发送设备就可能未建立协议栈对应关系; 或者, 上述 第一数据包为上述发送设备与接收设备第一次通信的第一个数据包时,上述接 收设备与发送设备就可能未建立协议栈对应关系。
可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。 分配单元 92, 用于根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 通过所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标 协议栈为启动的多个协议栈中的协议栈。
可选的, 上述启动的多个协议栈可以是至少两个协议栈。
可选的, 上述第一数据包可以是 IP数据包。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述装 置; 还可以服务器或者用户终端的内核实现上述装置; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述装置;还可以服务器或者用户终 端的 lib库协议栈实现上述装置。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 获取第一数据包后会根据第一数据包的包头中 DPS域 包括的第一标识将所述第一数据包分配至第一目标协议栈 ,这样第一目标协议 栈就可以处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。这样就可以实现根据第一数据包携带的第一标识从多个协议栈 中选择第一目标协议栈处理第一数据包,相比现有技术中, 多个内核同时访问 同一个协议栈, 本发明实施例可以提高协议栈的性能, 从而提高设备的性能。 请参阅图 10, 图 10是本发明实施例提供的另一种数据包处理装置的结构 示意图, 如图 10所示, 包括: 启动单元 101、 选择单元 102、 获取单元 103 和分配单元 104, 其中:
启动单元 101 , 用于启动多个协议栈, 并为每个协议栈分配标识。
可选的, 启动单元 101可以是按照一定顺序启动多个协议栈,再为每个启 动的协议栈分配标识, 例如: 按照启动的先后顺序分配编号。 另外, 由于启动 多个协议栈, 这样这多个协议栈就为并行协议栈, 且这多个协议栈可以是独立 运行的协议栈。
选择单元 102, 用于当应用程序需要使用网络时, 从所述多个协议栈中选 择所述第一目标协议栈为所述应用程序提供服务, 其中, 所述第一目标协议栈 为所述应用程序提供的服务为所述第一数据包的服务类型的服务。
可选的,上述应用程序需要使用网络可以是指应用程序的进程或者线程需 要使用网络。上述第一目标协议栈为所述应用程序提供服务可以是, 第一目标 协议栈为应用程序的进程或者线程提供服务。其中,上述服务可以是网络服务, 例如: 上述服务对于 TCP/IP协议簇来说就是所有的 TCP/IP服务; 该上述服务 器还可以非 TCP/IP协议簇的网络服务等, 本实施例对此不作限定。 另外, 选 择单元 102仅是介绍了第一目标协议栈为上述应用程序提供服务的实现方式, 在本实施例中还可以实现为启动的其它协议栈为其它应用程序提供服务, 当 然, 不同的协议栈提供的服务可以是不同的。
可选的,选择单元 102可以用于控制应用程序向进行协议栈申请; 并按特 定原则为所述应用程序分配上述第一目标协议栈;以及控制应用程序向所述第 一目标协议栈发送建立服务请求; 以及控制第一目标协议栈建立服务。
可选的, 本实施例中,还可以通过一个专门用于管理协议栈的协议栈管理 模块管理启动的协议栈。 其中, 该协议栈管理模块可以是一个虚拟的模块。 这 样应用程序需要使用网络时,就可以向该协议栈管理模块进行端口申请和协议 栈申请, 该协议栈管理模块就可以为该应用程序分配端口和第一目标协议栈, 再将分配结果通知给应用程序,这样应用程序就可以向第一目标协议栈发送建 立服务请求。另外,选择单元 102可以用于判断上述应用程序是否绑定协议栈; 若上述应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时,将该 应用程序绑定的协议栈为作为上述第一目标协议栈;当上述应用程序绑定了多 个协议栈时,从该应用程序绑定的协议栈中选择一个协议栈作为上述第一目标 协议栈;
选择单元 102还可以用于若上述应用程序未绑定协议栈时,从启动的多个 协议栈中选择一个协议栈作为上述第一目标协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。
可选的, 本实施例中, 还可以对启动的多个协议栈进行管理, 例如: 当网 络负载增大时, 当前启动的多个协议栈处理不过来时, 可以加载新的协议栈。 例如: 当网络负载减小时, 可以将启动的多个协议栈中存在需要卸载的协议栈 时, 卸载该协议栈, 或者迁移该协议栈的连接信息, 再卸载该协议栈; 其中, 该需要卸载的协议栈是指当前没有任何连接或者没有任何负载的协议栈,上述 连接信息可以包括: TCP连接信息、 TCP服务信息和 /或 UDP服务信息, 对此 本实施例不作限定, 例如: 连接信息还可以包括: IP服务信息、 FTP服务信 息、 SSH服务信息等, 总的来说: 连接信息就可以指所有的网络服务信息。 另 外, TCP连接信息主要可以指: 每个连接的状态机信息、 源 IP地址、 源端口 号、 目的 IP地址、 目的端口号、 目的协议栈信息。 TCP服务信息和 UDP服务 信息主要可以是指: 目的 IP、 目的端口号、 目的协议栈信息等。 例如: 将协 议栈 1的连接信息迁移至协议栈 2, 再卸载协议栈 1 , 这样协议栈 2就可以处 理协议栈 1上的连接, 即协议栈 2就可以处理协议栈 1上的负载。 例如: 当某 一个协议栈因错误导致异常时, 还可以重新加载该协议栈。 另外, 本实施例可 以建立一个协议栈管理模块管理协议栈。
获取单元 103 , 用于获取第一数据包, 并解析所述第一数据包的包头, 得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备。
可选的, 上述第一数据包可以是上述应用程序处理的数据包, 例如: 上述 第一数据包的服务类型为上述第一目标协议栈为所述应用程序提供服务的类 型。
可选的, 上述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域可以是包括所述发送设备中处理所述 第一数据包的第二目标协议栈的第二标识。 这样通过该 SPS域就可以知道发 送设备中第二目标协议栈的标识, 这样在往发送设备返回数据包时,就可以在 数据包的 DPS域中携带该第二目标协议栈的标识。
可选的, 第一数据包的包头可以为如图 3所示包头, 该包头可以包括: 版 本域、 头长域、 服务类型域、 总长域、 重组标识域、 标志域、 段偏移量域、 生 存时间域、 协议代码域、 头检验和域、 源 IP地址域、 目的 IP地址域、 SPS域、 DPS域、 可选数据域和用户数据域。 另外, 本实施例中对 SPS域和 DPS域的 长度不限的位置可以不作限定。
分配单元 104, 用于根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议 栈为启动的多个协议栈中的协议栈。
可选的 ,分配单元 104可以用于当所述第一标识所述第一标识为所述接收 端的协议栈的标识时 ,从启动的多个协议栈中选择标识为所述第一标识的第一 目标协议栈; 以及将所述第一数据包分配至所述第一目标协议栈,通过所述第 一目标协议栈处理所述第一数据包。
该实施方式, 可以根据实现 DPS域中第一标识查找到上述第一目标协议 栈,再将第一数据包分配至第一目标协议栈处理, 这样可以第一目标协议栈独 立处理第一数据包, 以实现第一目标协议栈完全独立, 即第一目标协议栈与其 它协议栈没有任何协议连接信息。
可选的, 分配单元 104可以用于当所述第一标识为所述特定标识时,根据 所述第一标识识别到未与所述发送设备未建立协议栈对应关系 ,并将所述第一 数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标协议栈包 括所述第一数据包的服务类型的服务时 ,通过所述第一目标协议栈处理所述第 一数据包。
该实施方式中由于第一数据包的服务类型是固定的,而上述第一目标协议 栈提供的服务类型也是固定的。这样当第一目标协议栈获取到上述第一数据包 后, 就可以检测第一数据包的服务类型, 当第一目标协议栈包括所述第一数据 包的服务类型的服务时, 第一目标协议栈处理所述第一数据包。 而其它协议栈 不包括第一数据包的服务类型的服务,这样这些其它协议栈就可以丟弃第一数 据包。
可选的, 分配单元 104可以用于当所述第一标识为所述特定标识时,根据 所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从预先获取 的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数据包分配 至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所 述对应关系包括每个协议栈的服务信息,所述第一目标协议栈为包括所述第一 数据包的服务类型的服务的协议栈。
可选的, 所述装置可以生成上述服务与协议栈的对应关系, 该对应关系包 括每个协议栈的服务信息, 即该对应关系表明每个协议栈的服务。可以是在每 个协议为应用程序建立服务时生成的上述对应关系。例如: 每个协议栈都可以 通过选择单元 102实现为不同的应用程序提供服务,这样就可以生成上述对应 关系。 另外, 该对应关系具体可以是服务与协议栈的信息表。
可选的, 所述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数 据包的第二目标协议栈的第二标识; 如图 11所示, 所述装置还可以包括: 发送单元 105 , 用于向所述发送设备返回第二数据包, 所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识。
这样当发送设备接收到上述第二数据包时, 就可以是根据第二数据包的 DPS域包括的第二标识,直接将第二数据包分配至第二目标协议栈, 由第二目 可选的, 上述第一数据包可以是分片后的数据包, 即第一数据包为某一数 据包中的一部分。 但是分片后的数据包的包头中的 DPS域、 SPS域和服务类 型是一致的,这样通过上述装置就可以实现将同一个数据包分片得到的多个数 据包分配至同一个协议栈处理。因为同一个数据包分片得到的多个数据包的包 头中的 DPS域、 SPS域和服务类型都是相同的, 这样通过上述步骤就一定会 分配至同一个协议栈。 另外, 可以采取将同一个数据流的分片数据包聚合到一 个緩存区中,待所有分片数据包都到达緩存区再合成一个完整数据包后再分配 至第一目标协议栈处理, 以减少第一目标协议栈的开销。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述装 置; 还可以服务器或者用户终端的内核实现上述装置; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述装置;还可以服务器或者用户终 端的 lib库协议栈实现上述装置。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中,在第一个装置实施例的基本上增加了多种可选的实施方 式, 且都可以实现提高协议栈的性能, 从而提高设备的性能。 请参阅图 12, 图 12是本发明实施例提供的另一种数据包处理装置的结构 示意图, 如图 12所示, 包括: 生成单元 121和发送单元 122, 其中:
生成单元 12, 用于通过第二目标协议栈生成第一数据包, 所述第一数据 包的得到所述包头包括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收 设备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备 与发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识 的设备, 所述发送设备为所述包头中源地址标识的设备; 所述 SPS域为用于 携带所述发送设备的协议栈的标识的域;所述 DPS域包括第一标识,所述 SPS 域包括所述第二目标协议栈的第二标识。
可选的,上述第一数据包可以是某个应用程序需要向接收设备发送的数据 包, 例如: 当某一应用程序需要与接收设备建立通信时, 生成单元 12就可以 为该应用程序分配上述第二目标协议栈; 其中, 生成单元 12为该应用程序分 配上述第二目标协议栈可以是按特定原则为该应用程序分配上述第二目标协 议栈。 例如: 生成单元 12还可以用于判断该应用程序是否绑定协议栈; 若该 应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时,将该应用程 序绑定的协议栈为作为上述第二目标协议栈;当上述应用程序绑定了多个协议 栈时,将该应用程序绑定的协议栈中负载最轻的协议栈作为上述第二目标协议 栈;
生成单元 12还可以用于若该应用程序未绑定协议栈时, 将启动的多个协 议栈中负载最轻的协议栈作为上述第二目标协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。
可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。 发送单元 122, 用于向所述接收设备发送所述第一数据包; 以使所述接收 设备根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启 动的多个协议栈中的协议栈。
可选的,接收设备接收到上述第一数据包后, 就可以解析所述第一数据包 的包头, 得到所述包头中 DPS域包括的第一标识; 再根据所述第一标识将所 述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述第一数据 包栈。
可选的, 如图 13所示, 所述装置还可以包括:
接收单元 123 , 用于接收所述接收设备返回的第二数据包, 所述第二数据 为所述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS 域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的 标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
分配单元 124, 用于将所述第二数据包分配至所述第二目标协议栈, 所述 第二目标协议栈处理所述第二数据包。
由于上述第二数据包的 DPS域包括上述第二标识, 这样分配单元 124就 可以直接将第二数据包分配至第二目标协议栈,由第二目标协议栈处理第二数 据包。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述装 置; 还可以服务器或者用户终端的内核实现上述装置; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述装置;还可以服务器或者用户终 端的 lib库协议栈实现上述装置。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 通过第二目标协议栈生成第一数据包, 所述第一数据包 的得到所述包头包括 SPS域和 DPS域;向所述接收设备发送所述第一数据包; 以使所述接收设备根据所述第一标识将所述第一数据包分配至第一目标协议 栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为 所述接收设备启动的多个协议栈中的协议栈。这样就可以实现根据第一数据包 携带的第一标识从多个协议栈中选择第一目标协议栈处理第一数据包,相比现 有技术中, 多个内核同时访问同一个协议栈, 本发明实施例可以提高协议栈的 性能, 从而提高设备的性能。 请参阅图 14, 图 14是本发明实施例提供的另一种数据包处理装置的结构 示意图, 如图 14所示, 包括: 接收器 141和存储器 142, 以及分别与所述接 收器 141和存储器 142连接的处理器 143 , 其中, 所述存储器 142用于存储一 组程序代码,所述处理器 143用于调用所述存储器 142存储的代码执行如下操 作:
通过所述接收器 141获取第一数据包, 并解析所述第一数据包的包头,得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
可选的, 上述协议栈的标识可以是用于唯一标识协议栈。 即一个协议栈唯 一对应一个标识, 这样通过该标识就可以查找到唯——个协议栈。 例如: 协议 栈的标识可以是编号, 例如: 启动 5个协议栈, 那么这 5个协议栈的标识就可 以分别为 1、 2、 3、 4、 5。
可选的, 上述接收设备与发送设备未建立协议栈对应关系可以是指,发送 设备不知道接收设备上是哪个协议栈处理上述第一数据包,即发送设备未获取 接收设备上处理上述第一数据包的协议栈的标识。 例如, 上述第一数据包为请 求包时, 上述接收设备与发送设备就可能未建立协议栈对应关系; 或者, 上述 第一数据包为上述发送设备与接收设备第一次通信的第一个数据包时,上述接 收设备与发送设备就可能未建立协议栈对应关系。
可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。 可选的, 上述启动的多个协议栈可以是至少两个协议栈。
可选的, 上述第一数据包可以是 IP数据包。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述方 法; 还可以服务器或者用户终端的内核实现上述方法; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述方法;还可以服务器或者用户终 端的 lib库协议栈实现上述方法。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 个人计算机( Personal Computer, PC )、 笔记本电脑、 车 载设备、 网络电视、 可穿戴设备等具有网络功能的智能设备。
上述技术方案中, 获取第一数据包后会根据第一数据包的包头中 DPS域 包括的第一标识将所述第一数据包分配至第一目标协议栈,这样第一目标协议 栈就可以处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。这样就可以实现根据第一数据包携带的第一标识从多个协议栈 中选择第一目标协议栈处理第一数据包,相比现有技术中, 多个内核同时访问 同一个协议栈, 本发明实施例可以提高协议栈的性能, 从而提高设备的性能。 请参阅图 15 , 图 15是本发明实施例提供的另一种数据包处理装置的结构 示意图, 如图 15所示, 包括: 接收器 151和存储器 152, 以及分别与所述接 收器 151和存储器 152连接的处理器 153 , 其中, 所述存储器 152用于存储一 组程序代码,所述处理器 153用于调用所述存储器 152存储的代码执行如下操 作:
启动多个协议栈, 并为每个协议栈分配标识;
当应用程序需要使用网络时,从所述多个协议栈中选择所述第一目标协议 栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程序提供 的服务为所述第一数据包的服务类型的服务;
通过所述接收器 151获取第一数据包, 并解析所述第一数据包的包头,得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
可选的, 处理器 153可以是按照一定顺序启动多个协议栈,再为每个启动 的协议栈分配标识, 例如: 按照启动的先后顺序分配编号。 另外, 由于启动多 个协议栈, 这样这多个协议栈就为并行协议栈,且这多个协议栈可以是独立运 行的协议栈。
可选的,上述应用程序需要使用网络可以是指应用程序的进程或者线程需 要使用网络。上述第一目标协议栈为所述应用程序提供服务可以是, 第一目标 协议栈为应用程序的进程或者线程提供服务。其中,上述服务可以是网络服务, 例如: 上述服务对于 TCP/IP协议簇来说就是所有的 TCP/IP服务; 该上述服务 器还可以非 TCP/IP协议簇的网络服务等, 本实施例对此不作限定。 另外, 上 述仅是介绍了第一目标协议栈为上述应用程序提供服务的实现方式,在本实施 例中还可以处理器 153实现为启动的其它协议栈为其它应用程序提供服务,当 然, 不同的协议栈提供的服务可以是不同的。
可选的,处理器 153执行的从所述多个协议栈中选择所述第一目标协议栈 为所述应用程序提供服务的操作, 可以包括:
应用程序申请协议栈;
按特定原则为所述应用程序分配上述第一目标协议栈;
应用程序向所述第一目标协议栈发送建立服务请求;
第一目标协议栈建立服务。
可选的, 当应用程序需要传输层协议进行网络服务,应用程序还可以进行 端口申请, 如果应用程序用的是网络层或者数据链路层的协议时, 就可以不需 要端口申请。
可选的, 本实施例中, 处理器 153还可以通过一个专门用于管理协议栈的 协议栈管理模块管理启动的协议栈。其中, 该协议栈管理模块可以是一个虚拟 的模块。这样应用程序需要使用网络时, 就可以向该协议栈管理模块进行端口 申请和协议栈申请,该协议栈管理模块就可以为该应用程序分配端口和第一目 标协议栈,再将分配结果通知给应用程序, 这样应用程序就可以向第一目标协 议栈发送建立服务请求。 另外, 处理器 153执行的按特定原则为所述应用程序 分配上述第一目标协议栈的操作, 可以包括:
判断上述应用程序是否绑定协议栈;
若上述应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时, 将该应用程序绑定的协议栈为作为上述第一目标协议栈;当上述应用程序绑定 了多个协议栈时 ,从该应用程序绑定的协议栈中选择一个协议栈作为上述第一 目标协议栈;
若上述应用程序未绑定协议栈时,从启动的多个协议栈中选择一个协议栈 作为上述第一目标协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。
可选的, 本实施例中, 处理器 153还可以对启动的多个协议栈进行管理 , 例如: 当网络负载增大时, 当前启动的多个协议栈处理不过来时, 可以加载新 的协议栈。 例如: 当网络负载减小时, 可以将启动的多个协议栈中存在需要卸 载的协议栈时, 卸载该协议栈, 或者迁移该协议栈的连接信息, 再卸载该协议 栈; 其中, 该需要卸载的协议栈是指当前没有任何连接或者没有任何负载的协 议栈, 上述连接信息可以包括: TCP连接信息、 TCP服务信息和 /或 UDP服务 信息, 对此本实施例不作限定, 例如: 连接信息还可以包括: IP服务信息、 FTP服务信息、 SSH服务信息等, 总的来说: 连接信息就可以指所有的网络服 务信息。 另外, TCP连接信息主要可以指: 每个连接的状态机信息、 源 IP地 址、 源端口号、 目的 IP地址、 目的端口号、 目的协议栈信息。 TCP服务信息 和 UDP服务信息主要可以是指: 目的 IP、 目的端口号、 目的协议栈信息等。 例如: 将协议栈 1的连接信息迁移至协议栈 2, 再卸载协议栈 1 , 这样协议栈 2就可以处理协议栈 1上的连接, 即协议栈 2就可以处理协议栈 1上的负载。 例如: 当某一个协议栈因错误导致异常时, 还可以重新加载该协议栈。 另外, 本实施例可以建立一个协议栈管理模块管理协议栈。
可选的, 上述第一数据包可以是上述应用程序处理的数据包, 例如: 上述 第一数据包的服务类型为上述第一目标协议栈为所述应用程序提供服务的类 型。
可选的, 上述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域可以是包括所述发送设备中处理所述 第一数据包的第二目标协议栈的第二标识。 这样通过该 SPS域就可以知道发 送设备中第二目标协议栈的标识, 这样在往发送设备返回数据包时,就可以在 数据包的 DPS域中携带该第二目标协议栈的标识。
可选的, 第一数据包的包头可以为如图 3所示包头, 该包头可以包括: 版 本域、 头长域、 服务类型域、 总长域、 重组标识域、 标志域、 段偏移量域、 生 存时间域、 协议代码域、 头检验和域、 源 IP地址域、 目的 IP地址域、 SPS域、 DPS域、 可选数据域和用户数据域。 另外, 本实施例中对 SPS域和 DPS域的 长度不限的位置可以不作限定。
可选的, 所述第一标识为所述接收端的协议栈的标识; 处理器 153执行的 根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目标协 议栈处理所述第一数据包的操作, 可以包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈,所述第一目标协议栈处理 所述第一数据包。
该实施方式, 可以根据实现 DPS域中第一标识查找到上述第一目标协议 栈 ,再将第一数据包分配至第一目标协议栈处理, 这样可以第一目标协议栈独 立处理第一数据包, 以实现第一目标协议栈完全独立, 即第一目标协议栈与其 它协议栈没有任何协议连接信息。
可选的, 所述第一标识为所述特定标识; 处理器 153执行的根据所述第一 标识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述 第一数据包的操作可以, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包。
该实施方式中由于第一数据包的服务类型是固定的,而上述第一目标协议 栈提供的服务类型也是固定的。这样当第一目标协议栈获取到上述第一数据包 后, 就可以检测第一数据包的服务类型, 当第一目标协议栈包括所述第一数据 包的服务类型的服务时, 第一目标协议栈处理所述第一数据包。 而其它协议栈 不包括第一数据包的服务类型的服务,这样这些其它协议栈就可以丟弃第一数 据包。
可选的, 所述第一标识为所述特定标识; 处理器 153执行的根据所述第一 标识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述 第一数据包的操作可以, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
可选的, 所述装置可以生成上述服务与协议栈的对应关系, 该对应关系包 括每个协议栈的服务信息, 即该对应关系表明每个协议栈的服务。可以是在每 个协议为应用程序建立服务时生成的上述对应关系。例如: 每个协议栈都可以 通过处理器 153实现为不同的应用程序提供服务,这样就可以生成上述对应关 系。 另外, 该对应关系具体可以是服务与协议栈的信息表。 可选的, 所述包头还可以包括 SPS域, 所述 SPS域为用于携带所述发送 设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数 据包的第二目标协议栈的第二标识; 所述装置还可以包括: 发射器 154; 处理 器 153 在执行第一目标协议栈处理所述第一数据包的操作之后, 处理器 153 还用于执行如下操作:
通过所述发射器 154向所述发送设备返回第二数据包,所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识。
这样当发送设备接收到上述第二数据包时, 就可以是根据第二数据包的 DPS域包括的第二标识,直接将第二数据包分配至第二目标协议栈, 由第二目 标协议栈处理第二数据包。
可选的, 上述第一数据包可以是分片后的数据包, 即第一数据包为某一数 据包中的一部分。 但是分片后的数据包的包头中的 DPS域、 SPS域和服务类 型都是相同的,这样通过上述步骤就可以实现将同一个数据包分片得到的多个 数据包分配至同一个协议栈处理。因为同一个数据包分片得到的多个数据包的 包头中的 DPS域、 SPS域和服务类型都是相同的, 这样通过上述步骤就一定 会分配至同一个协议栈。 另外, 可以采取将同一个数据流的分片数据包聚合到 一个緩存区中 ,待所有分片数据包都到达緩存区再合成一个完整数据包后再分 配至第一目标协议栈处理, 以减少第一目标协议栈的开销。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述装 置; 还可以服务器或者用户终端的内核实现上述装置; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述装置;还可以服务器或者用户终 端的 lib库协议栈实现上述装置。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 在上面实施例的基本上增加了多种可选的实施方式, 且 都可以实现提高协议栈的性能, 从而提高设备的性能。 请参阅图 16, 图 16是本发明实施例提供的另一种数据包处理装置的结构 示意图, 如图 16所示, 包括: 发射器 161和存储器 162, 以及分别与所述发 射器 161和存储器 162连接的处理器 163 , 其中, 所述存储器 162用于存储一 组程序代码,所述处理器 163用于调用所述存储器 162存储的代码执行如下操 作:
通过第二目标协议栈生成第一数据包,所述第一数据包的得到所述包头包 括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈的标识 或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协 议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备,所述发送设 备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送设备的 协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述第二目 标协议栈的第二标识;
通过所述发射器 161向所述接收设备发送所述第一数据包;以使所述接收 设备根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启 动的多个协议栈中的协议栈。
可选的,上述第一数据包可以是某个应用程序需要向接收设备发送的数据 包, 例如: 当某一应用程序需要与接收设备建立通信时, 处理器 163就可以为 该应用程序分配上述第二目标协议栈; 其中, 处理器 163为该应用程序分配上 述第二目标协议栈可以是按特定原则为该应用程序分配上述第二目标协议栈。 处理器 163执行的按特定原则为该应用程序分配上述第二目标协议栈的操作, 可以包括:
判断该应用程序是否绑定协议栈;
若该应用程序绑定了协议栈时, 当上述应用程序只绑定一个协议栈时, 将 该应用程序绑定的协议栈为作为上述第二目标协议栈;当上述应用程序绑定了 多个协议栈时,将该应用程序绑定的协议栈中负载最轻的协议栈作为上述第二 目标协议栈;
若该应用程序未绑定协议栈时,将启动的多个协议栈中负载最轻的协议栈 作为上述第二目标协议栈。
其中, 上述应用程序可以是指应用程序的进程或者线程。
可选的,上述源地址可以是源 IP地址,上述目的地址可以是目的 IP地址。 可选的, 所述装置还可以包括接收器 164, 其中: 所述处理器 163通过所 述发射器 161向所述接收设备发送所述第一数据包之后,处理器 163还用于执 行如下操作:
通过所述接收器 164接收所述接收设备返回的第二数据包,所述第二数据 为所述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS 域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的 标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
将所述第二数据包分配至所述第二目标协议栈,所述第二目标协议栈处理 所述第二数据包。
由于上述第二数据包的 DPS域包括上述第二标识, 这样步骤 504就可以 直接将第二数据包分配至第二目标协议栈, 由第二目标协议栈处理第二数据 包。
可选的, 上述装置具体可以是应用于服务器或者用户终端上, 具体可以是 服务器的服务端可以实现上述装置, 或者用户终端的用户端可以实现上述装 置; 还可以服务器或者用户终端的内核实现上述装置; 还可以服务器或者用户 终端的用户态集中式网络并行协议栈实现上述装置;还可以服务器或者用户终 端的 lib库协议栈实现上述装置。 其中。 用户终端可以是平板电脑、 手机、 电 子阅读器、 遥控器、 PC、 笔记本电脑、 车载设备、 网络电视、 可穿戴设备等 具有网络功能的智能设备。
上述技术方案中, 通过第二目标协议栈生成第一数据包, 所述第一数据包 的得到所述包头包括 SPS域和 DPS域;向所述接收设备发送所述第一数据包; 以使所述接收设备根据所述第一标识将所述第一数据包分配至第一目标协议 栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为 所述接收设备启动的多个协议栈中的协议栈。这样就可以实现根据第一数据包 携带的第一标识从多个协议栈中选择第一目标协议栈处理第一数据包,相比现 有技术中, 多个内核同时访问同一个协议栈, 本发明实施例可以提高协议栈的 性能, 从而提高设备的性能。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程, 是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算 机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。 其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory, ROM )或随机存取存储器(Random Access Memory, 筒称 RAM )等。
以上所揭露的仅为本发明较佳实施例而已,当然不能以此来限定本发明之 权利范围,因此依本发明权利要求所作的等同变化,仍属本发明所涵盖的范围。

Claims

权 利 要 求
1、 一种数据包处理方法, 其特征在于, 包括:
获取第一数据包, 并解析所述第一数据包的包头,得到所述包头中目的协 议栈 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设备的协议 栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备 未建立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备, 所 述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
2、 如权利要求 1所述的方法, 其特征在于, 所述第一标识为所述接收端 的协议栈的标识;
所述根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第 一目标协议栈处理所述第一数据包, 包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈 ,所述第一目标协议栈处理 所述第一数据包。
3、 如权利要求 1所述的方法, 其特征在于, 所述第一标识为所述特定标 识;
所述根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第 一目标协议栈处理所述第一数据包, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包; 或者
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
4、 如权利要求 1-3 中任一项所述的方法, 其特征在于, 所述包头还包括 源协议栈 SPS域,所述 SPS域为用于携带所述发送设备的协议栈的标识的域, 所述 SPS域包括所述发送设备中处理所述第一数据包的第二目标协议栈的第 二标识;
所述第一目标协议栈处理所述第一数据包之后, 所述方法还包括: 向所述发送设备返回第二数据包,所述第二数据为所述第一数据包的响应 数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据 包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的 包头包括的 DPS域包括所述第二标识。
5、 如权利要求 1-3 中任一项所述的方法, 其特征在于, 所述获取第一数 据包, 并解析所述第一数据包的包头, 得到所述包头中 DPS域包括的第一标 识之前, 所述方法还包括:
启动多个协议栈, 并为每个协议栈分配标识;
当应用程序需要使用网络时,从所述多个协议栈中选择所述第一目标协议 栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程序提供 的服务为所述第一数据包的服务类型的服务。
6、 一种数据包处理方法, 其特征在于, 包括:
通过第二目标协议栈生成第一数据包,所述第一数据包的得到所述包头包 括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈的标识 或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协 议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备, 所述发送设 备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送设备的 协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述第二目 标协议栈的第二标识;
向所述接收设备发送所述第一数据包;以使所述接收设备根据所述第一标 识将所述第一数据包分配至第一目标协议栈,所述第一目标协议栈处理所述第 一数据包; 其中, 所述第一目标协议栈为所述接收设备启动的多个协议栈中的 协议栈。
7、 如权利要求 6所述的方法, 其特征在于, 所述向所述接收设备发送所 述第一数据包之后, 所述方法还包括:
接收所述接收设备返回的第二数据包,所述第二数据为所述第一数据包的 响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二 数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述第二数据 包的包头包括的 DPS域包括所述第二标识;
将所述第二数据包分配至所述第二目标协议栈,所述第二目标协议栈处理 所述第二数据包。
8、 一种数据包处理装置, 其特征在于, 包括: 获取单元和分配单元, 其 中:
所述获取单元, 用于获取第一数据包, 并解析所述第一数据包的包头, 得 到所述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设 备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与 发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识的 设备, 所述发送设备为所述包头中源地址标识的设备;
所述分配单元,用于根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 通过所述第一目标协议栈处理所述第一数据包; 其中, 所述第一目标 协议栈为启动的多个协议栈中的协议栈。
9、 如权利要求 8所述的装置, 其特征在于, 所述分配单元用于当所述第 一标识所述第一标识为所述接收端的协议栈的标识时,从启动的多个协议栈中 选择标识为所述第一标识的第一目标协议栈;以及将所述第一数据包分配至所 述第一目标协议栈, 通过所述第一目标协议栈处理所述第一数据包。
10、 如权利要求 8所述的装置, 其特征在于, 所述分配单元用于当所述第 一标识为所述特定标识时,根据所述第一标识识别到未与所述发送设备未建立 协议栈对应关系, 并将所述第一数据包广播给启动的多个协议栈, 当第一目标 协议栈识别该第一目标协议栈包括所述第一数据包的服务类型的服务时,通过 所述第一目标协议栈处理所述第一数据包; 或者
所述分配单元用于当所述第一标识为所述特定标识时,根据所述第一标识 识别到未与所述发送设备未建立协议栈对应关系 ,并从预先获取的服务与协议 栈的对应关系中查找第一目标协议栈,再将所述第一数据包分配至所述第一目 标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包 括每个协议栈的服务信息,所述第一目标协议栈为包括所述第一数据包的服务 类型的服务的协议栈。
11、 如权利要求 8-10 中任一项所述的装置, 其特征在于, 所述包头还包 括 SPS域, 所述 SPS域为用于携带所述发送设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数据包的第二目标协议栈的第二标 识;
所述装置还包括:
发送单元, 用于向所述发送设备返回第二数据包, 所述第二数据为所述第 一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述 第二数据包的包头包括的 DPS域包括所述第二标识。
12、 如权利要求 8-10中任一项所述的装置, 其特征在于, 所述装置还包 括:
启动单元, 用于启动多个协议栈, 并为每个协议栈分配标识;
选择单元, 用于当应用程序需要使用网络时,从所述多个协议栈中选择所 述第一目标协议栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所 述应用程序提供的服务为所述第一数据包的服务类型的服务。
13、 一种数据包处理装置, 其特征在于, 包括: 生成单元和发送单元, 其 中:
所述生成单元, 用于通过第二目标协议栈生成第一数据包, 所述第一数据 包的得到所述包头包括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收 设备的协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备 与发送设备未建立协议栈对应关系,所述接收设备为所述包头中目的地址标识 的设备, 所述发送设备为所述包头中源地址标识的设备; 所述 SPS域为用于 携带所述发送设备的协议栈的标识的域;所述 DPS域包括第一标识,所述 SPS 域包括所述第二目标协议栈的第二标识;
所述发送单元, 用于向所述接收设备发送所述第一数据包; 以使所述接收 设备根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启 动的多个协议栈中的协议栈。
14、 如权利要求 13所述的装置, 其特征在于, 所述装置还包括: 接收单元, 用于接收所述接收设备返回的第二数据包, 所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
分配单元, 用于将所述第二数据包分配至所述第二目标协议栈, 所述第二 目标协议栈处理所述第二数据包。
15、 一种数据包处理装置, 其特征在于, 包括: 接收器和存储器, 以及分 别与所述接收器和存储器连接的处理器, 其中, 所述存储器用于存储一组程序 代码, 所述处理器用于调用所述存储器存储的代码执行如下操作:
通过所述接收器获取第一数据包, 并解析所述第一数据包的包头,得到所 述包头中 DPS域包括的第一标识; 其中, 所述 DPS域为用于携带接收设备的 协议栈的标识或者特定标识的域,所述特定标识用于表示所述接收设备与发送 设备未建立协议栈对应关系, 所述接收设备为所述包头中目的地址标识的设 备, 所述发送设备为所述包头中源地址标识的设备;
根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目 标协议栈处理所述第一数据包; 其中, 所述第一目标协议栈为启动的多个协议 栈中的协议栈。
16、 如权利要求 15所述的装置, 其特征在于, 所述第一标识为所述接收 端的协议栈的标识;
所述处理器执行的根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 所述第一目标协议栈处理所述第一数据包的操作, 包括:
从启动的多个协议栈中选择标识为所述第一标识的第一目标协议栈; 将所述第一数据包分配至所述第一目标协议栈 ,所述第一目标协议栈处理 所述第一数据包。
17、 如权利要求 15所述的装置, 其特征在于, 所述第一标识为所述特定 标识;
所述处理器执行的根据所述第一标识将所述第一数据包分配至第一目标 协议栈, 所述第一目标协议栈处理所述第一数据包的操作, 包括:
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并将 所述第一数据包广播给启动的多个协议栈,当第一目标协议栈识别该第一目标 协议栈包括所述第一数据包的服务类型的服务时,所述第一目标协议栈处理所 述第一数据包; 或者
根据所述第一标识识别到未与所述发送设备未建立协议栈对应关系,并从 预先获取的服务与协议栈的对应关系中查找第一目标协议栈,再将所述第一数 据包分配至所述第一目标协议栈, 所述第一目标协议栈处理所述第一数据包; 其中, 所述对应关系包括每个协议栈的服务信息, 所述第一目标协议栈为包括 所述第一数据包的服务类型的服务的协议栈。
18、 如权利要求 15-17中任一项所述的装置, 其特征在于, 所述包头还包 括 SPS域, 所述 SPS域为用于携带所述发送设备的协议栈的标识的域, 所述 SPS 域包括所述发送设备中处理所述第一数据包的第二目标协议栈的第二标 识;
所述装置还包括发射器,所述处理器在执行第一目标协议栈处理所述第一 数据包的操作之后, 所述处理器还用于执行如下操作:
通过所述发射器向所述发送设备返回第二数据包,所述第二数据为所述第 一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS 域包括所述第一目标协议栈的标识, 所述 第二数据包的包头包括的 DPS域包括所述第二标识。
19、 如权利要求 15-17中任一项所述的装置, 其特征在于, 所述获取第一 数据包, 并解析所述第一数据包的包头, 得到所述包头中 DPS域包括的第一 标识之前, 所述方法还包括:
启动多个协议栈, 并为每个协议栈分配标识;
当应用程序需要使用网络时,从所述多个协议栈中选择所述第一目标协议 栈为所述应用程序提供服务, 其中, 所述第一目标协议栈为所述应用程序提供 的服务为所述第一数据包的服务类型的服务。
20、 一种数据包处理装置, 其特征在于, 包括: 发射器和存储器, 以及分 别与所述发射器和存储器连接的处理器, 其中, 所述存储器用于存储一组程序 代码, 所述处理器用于调用所述存储器存储的代码执行如下操作:
通过第二目标协议栈生成第一数据包,所述第一数据包的得到所述包头包 括 SPS域和 DPS域; 其中, 所述 DPS域为用于携带接收设备的协议栈的标识 或者特定标识的域,所述特定标识用于表示所述接收设备与发送设备未建立协 议栈对应关系, 所述接收设备为所述包头中目的地址标识的设备,所述发送设 备为所述包头中源地址标识的设备; 所述 SPS域为用于携带所述发送设备的 协议栈的标识的域; 所述 DPS域包括第一标识, 所述 SPS域包括所述第二目 标协议栈的第二标识; 通过所述发射器向所述接收设备发送所述第一数据包;以使所述接收设备 根据所述第一标识将所述第一数据包分配至第一目标协议栈,所述第一目标协 议栈处理所述第一数据包; 其中, 所述第一目标协议栈为所述接收设备启动的 多个协议栈中的协议栈。
21、 如权利要求 20所述的装置, 其特征在于, 所述装置还包括接收器, 其中:所述处理器在执行通过所述发射器向所述接收设备发送所述第一数据包 的操作之后, 还用于执行如下操作:
通过所述接收器接收所述接收设备返回的第二数据包,所述第二数据为所 述第一数据包的响应数据包, 所述第二数据包的包头包括 SPS域和 DPS域, 其中, 所述第二数据包的包头包括的 SPS域包括所述第一目标协议栈的标识, 所述第二数据包的包头包括的 DPS域包括所述第二标识;
将所述第二数据包分配至所述第二目标协议栈,所述第二目标协议栈处理 所述第二数据包。
PCT/CN2013/090413 2013-12-25 2013-12-25 一种数据包处理方法和装置 WO2015096058A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201380002979.XA CN104969533B (zh) 2013-12-25 2013-12-25 一种数据包处理方法和装置
PCT/CN2013/090413 WO2015096058A1 (zh) 2013-12-25 2013-12-25 一种数据包处理方法和装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2013/090413 WO2015096058A1 (zh) 2013-12-25 2013-12-25 一种数据包处理方法和装置

Publications (1)

Publication Number Publication Date
WO2015096058A1 true WO2015096058A1 (zh) 2015-07-02

Family

ID=53477333

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/090413 WO2015096058A1 (zh) 2013-12-25 2013-12-25 一种数据包处理方法和装置

Country Status (2)

Country Link
CN (1) CN104969533B (zh)
WO (1) WO2015096058A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107920073A (zh) * 2017-11-17 2018-04-17 广西小草信息产业有限责任公司 一种协议栈运行装置和方法

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111490963B (zh) * 2019-01-25 2022-07-29 上海哔哩哔哩科技有限公司 基于quic协议栈的数据处理方法、系统、设备及存储介质
CN112637329B (zh) * 2020-12-21 2022-08-23 网络通信与安全紫金山实验室 一种多应用程序的标识方法、装置、设备及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1592303A (zh) * 2003-08-28 2005-03-09 国际商业机器公司 用于应用实例级工作负荷分配亲合性的方法和系统
CN1852296A (zh) * 2005-09-30 2006-10-25 华为技术有限公司 一种多协议支持系统及方法
CN101442547A (zh) * 2008-12-12 2009-05-27 华为技术有限公司 一种报文处理方法、系统及设备
CN102238187A (zh) * 2011-07-26 2011-11-09 东念(杭州)科技有限公司 基于tcp/ip协议的通信协议的系统及其实现方法
US20120166580A1 (en) * 2010-12-28 2012-06-28 Samsung Electronics Co., Ltd. Method and apparatus for communication using heterogeneous protocols

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100929852B1 (ko) * 2007-09-20 2009-12-04 한국전자통신연구원 공유 메모리를 이용한 가상 기계 상의 응용프로그램 간통신 인터페이스 장치 및 그 방법
US7751401B2 (en) * 2008-06-30 2010-07-06 Oracle America, Inc. Method and apparatus to provide virtual toe interface with fail-over
CN102970244B (zh) * 2012-11-23 2018-04-13 上海寰创通信科技股份有限公司 一种多cpu核间负载均衡的网络报文处理方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1592303A (zh) * 2003-08-28 2005-03-09 国际商业机器公司 用于应用实例级工作负荷分配亲合性的方法和系统
CN1852296A (zh) * 2005-09-30 2006-10-25 华为技术有限公司 一种多协议支持系统及方法
CN101442547A (zh) * 2008-12-12 2009-05-27 华为技术有限公司 一种报文处理方法、系统及设备
US20120166580A1 (en) * 2010-12-28 2012-06-28 Samsung Electronics Co., Ltd. Method and apparatus for communication using heterogeneous protocols
CN102238187A (zh) * 2011-07-26 2011-11-09 东念(杭州)科技有限公司 基于tcp/ip协议的通信协议的系统及其实现方法

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107920073A (zh) * 2017-11-17 2018-04-17 广西小草信息产业有限责任公司 一种协议栈运行装置和方法

Also Published As

Publication number Publication date
CN104969533B (zh) 2018-11-06
CN104969533A (zh) 2015-10-07

Similar Documents

Publication Publication Date Title
US10419531B2 (en) Method for setting gateway device identity, and management gateway device
US9210124B2 (en) Method, apparatus, and system for allocating public IP address
US9300733B2 (en) System and/or method for client-driven server load distribution
US8612611B2 (en) Proxy apparatus and operation method thereof
US10313247B2 (en) System, method, and device for network load balance processing
JP5220920B2 (ja) クライアント・アプリケーション・プログラムがインターネット・プロトコル(ip)ネットワーク上でサーバ・アプリケーション・プログラム・インスタンスにアクセスするための方法、装置、及びソフトウェア
US9237591B2 (en) Techniques enabling use of a Wi-Fi direct services (WFDS) application services platform (ASP) for layer 2 services
US20140067914A1 (en) Computer system and packet transfer method
US10952264B2 (en) Persistent distribution of connectionless traffic supporting virtual connection migration
US20080294778A1 (en) Network connection manager
WO2021008591A1 (zh) 数据传输方法、装置及系统
WO2023272874A1 (zh) 实时通信rtc连接方法、服务器及存储介质
CN110417632B (zh) 一种网络通信方法、系统及服务器
WO2014142258A1 (ja) 通信システム、制御装置、アドレス割当方法及びプログラム
WO2015096058A1 (zh) 一种数据包处理方法和装置
US10652626B2 (en) Gateway, and method, computer program and storage means corresponding thereto
US20150074234A1 (en) Content system and method for chunk-based content delivery
US20120300776A1 (en) Method for creating virtual link, communication network element, and ethernet network system
US7564854B2 (en) Network architecture with a light-weight TCP stack
WO2020048177A1 (zh) 机顶盒管理方法、装置、设备及存储介质
EP4216510A1 (en) Method for acquiring address, apparatus and system
EP2523390A1 (en) Method and apparatus for achieving communications between different networks
CN109660495B (zh) 一种文件传输方法和装置
TWI483605B (zh) 用於網路系統之部署方法及電腦系統
CN115065672A (zh) 一种sfu系统数据传输方法及相关设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13900572

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13900572

Country of ref document: EP

Kind code of ref document: A1