技术领域Technical field
本发明涉及通信技术领域,更具体地,涉及一种测试系统、测试方法及计算机程序产品。The present invention relates to the field of communication technology, and more specifically, to a testing system, a testing method and a computer program product.
背景技术Background technique
在当前主机与目标主机的通信过程中,经常需要获取当前主机与目标主机之间的网络延时。在现有技术中,通常调用ping命令来获取网络延时。由于每次调用ping命令时都需要启动进程,在需要多次调用ping命令时会出现频繁的进程调度,消耗CPU(CentralProcessing Unit,中央处理器)资源较多。During the communication process between the current host and the target host, it is often necessary to obtain the network delay between the current host and the target host. In the existing technology, the ping command is usually called to obtain the network delay. Since the process needs to be started every time the ping command is called, frequent process scheduling will occur when the ping command needs to be called multiple times, consuming a lot of CPU (Central Processing Unit, central processing unit) resources.
发明内容Contents of the invention
本发明的一个目的是提供一种用于测试网络延时的新技术方案。An object of the present invention is to provide a new technical solution for testing network delay.
根据本发明的第一方面,提供了一种测试系统,包括:According to a first aspect of the present invention, a test system is provided, including:
主线程,用于接收测试请求,所述测试请求中至少包括第一IP地址和第一本机网卡信息,检测是否存在与所述测试请求对应的收发线程和套接字;The main thread is used to receive a test request, which includes at least the first IP address and the first local network card information, and detect whether there is a transceiver thread and socket corresponding to the test request;
所述主线程还用于在检测到不存在与所述测试请求对应的收发线程和套接字的情况下,创建与所述测试请求对应的第一套接字和收发线程,将所述第一套接字中的网卡字段设置为所述第一本机网卡信息,将所述第一套接字中的目标IP地址字段设置为所述第一IP地址,将所述第一套接字配置给所述收发线程;The main thread is also used to create a first socket and a transceiver thread corresponding to the test request when it is detected that there are no transceiver threads and sockets corresponding to the test request, and add the first transceiver thread to the test request. The network card field in the socket is set to the first local network card information, the target IP address field in the first socket is set to the first IP address, and the first socket Configured to the transceiver thread;
所述收发线程用于通过所述第一套接字向第一目标主机发送查询报文,通过所述第一套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文,所述第一目标主机的IP地址为所述第一IP地址;The transceiver thread is used to send a query message to the first target host through the first socket, and receive feedback corresponding to the query message returned by the first target host through the first socket. message, the IP address of the first target host is the first IP address;
所述主线程还用于在检测到存在与所述测试请求对应的收发线程和套接字的情况下,通过所述测试请求对应的收发线程和套接字向所述第一目标主机发送查询报文,以及通过所述测试请求对应的收发线程和套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文。The main thread is also used to send a query to the first target host through the transceiver thread and socket corresponding to the test request when it is detected that there is a transceiver thread and socket corresponding to the test request. message, and receive a feedback message corresponding to the query message returned by the first target host through the transceiver thread and socket corresponding to the test request.
可选地,所述主线程用于在接收到更改地址指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文;Optionally, the main thread is configured to send a pause message to the transceiver thread after receiving the address change instruction, and the pause message is used to instruct the transceiver thread to stop sending query messages and stop receiving feedback messages;
所述主线程用于销毁所述第一套接字,创建第二套接字,将所述第二套接字中的网卡字段设置为所述第一本机网卡信息,将所述第二套接字中的目标IP地址字段设置为所述更改地址指令中包含的第二IP地址;The main thread is used to destroy the first socket, create a second socket, set the network card field in the second socket to the first local network card information, and set the second The target IP address field in the socket is set to the second IP address contained in the change address instruction;
所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程通过所述第二套接字向第二目标主机发送查询报文,通过所述第二套接字接收所述第二目标主机返回的与所述查询报文对应的反馈报文,所述第二目标主机的IP地址为所述第二IP地址。The main thread is used to send a recovery message to the transceiver thread. The recovery message is used to instruct the transceiver thread to send a query message to the second target host through the second socket. The interface receives a feedback message corresponding to the query message returned by the second target host, where the IP address of the second target host is the second IP address.
可选地,所述主线程用于在接收到更改网卡指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止报文的接收和发送;Optionally, the main thread is configured to send a pause message to the transceiver thread after receiving the instruction to change the network card, and the pause message is used to instruct the transceiver thread to stop receiving and sending messages;
所述主线程用于将所述第一套接字中的网卡字段设置为所述更改网卡指令中包含的第二本机网卡信息;The main thread is used to set the network card field in the first socket to the second local network card information included in the change network card instruction;
所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。The main thread is used to send a recovery message to the transceiver thread, and the recovery message is used to instruct the transceiver thread to resume sending query messages and to resume receiving feedback messages.
可选地,所述测试请求中还包括第一周期和第一循环次数;Optionally, the test request also includes a first period and a first number of cycles;
所述主线程用于将所述第一周期和所述第一循环次数发送至所述收发线程;The main thread is used to send the first period and the first number of cycles to the transceiver thread;
所述收发线程用于每隔所述第一周期通过所述第一套接字向所述第一目标主机发送所述查询报文;The transceiver thread is configured to send the query message to the first target host through the first socket every first cycle;
所述收发线程用于在发送所述查询报文的次数达到所述第一循环次数的情况下,停止发送所述查询报文。The sending and receiving thread is configured to stop sending the query message when the number of times the query message is sent reaches the first number of cycles.
可选地,所述主线程用于在接收到更改周期指令之后,将所述更改周期指令中包含的第二周期发送至所述收发线程;Optionally, the main thread is configured to send the second cycle included in the change cycle instruction to the transceiver thread after receiving the change cycle instruction;
所述收发线程用于每隔所述第二周期通过所述第一套接字向所述第一目标主机发送所述查询报文。The transceiver thread is configured to send the query message to the first target host through the first socket every second period.
可选地,所述主线程用于在接收到更改循环次数指令之后,将所述更改循环次数指令中包含的第二循环次数发送至所述收发线程;Optionally, the main thread is configured to, after receiving the instruction to change the number of cycles, send the second number of cycles contained in the instruction to change the number of cycles to the transceiver thread;
所述收发线程用于在发送所述查询报文的次数达到所述第二循环次数的情况下,停止发送所述查询报文。The sending and receiving thread is configured to stop sending the query message when the number of times the query message is sent reaches the second cycle number.
可选地,所述主线程用于在接收到多个测试请求的情况下,创建与每个所述测试请求对应的收发线程以及与每个所述收发线程对应的套接字,将每个所述套接字中的目标IP地址字段设置为所述套接字对应的测试请求中包含的IP地址,将每个所述套接字中的网卡字段设置为所述套接字对应的测试请求中包含的本机网卡信息;Optionally, the main thread is used to create a transceiver thread corresponding to each test request and a socket corresponding to each transceiver thread when multiple test requests are received, and each The target IP address field in the socket is set to the IP address included in the test request corresponding to the socket, and the network card field in each socket is set to the test corresponding to the socket. The local network card information included in the request;
每个所述收发线程用于通过对应的套接字向目标主机发送查询报文,通过所述对应的套接字接收所述目标主机返回的与所述查询报文对应的反馈报文。Each of the transceiver threads is used to send a query message to the target host through a corresponding socket, and receive a feedback message corresponding to the query message returned by the target host through the corresponding socket.
可选地,所述主线程用于在接收到暂停指令时,检测所述收发线程是否处于运行状态,在所述收发线程处于运行状态时,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文。Optionally, the main thread is used to detect whether the transceiver thread is in a running state when receiving a pause instruction, and when the transceiver thread is in a running state, send a pause message to the transceiver thread. The pause message Used to instruct the transceiver thread to stop sending query messages and stop receiving feedback messages.
可选地,所述主线程用于在接收到恢复指令时,检测所述收发线程是否处于暂停状态,在所述收发线程处于暂停状态时,向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。Optionally, the main thread is used to detect whether the transceiver thread is in a suspended state when receiving a resume instruction, and when the transceiver thread is in a suspended state, send a resume message to the transceiver thread. The resume message Used to instruct the transceiver thread to resume sending query messages and resume receiving feedback messages.
根据本发明的第二方面,提供了一种测试方法,所述方法包括:According to a second aspect of the present invention, a testing method is provided, which method includes:
主线程接收测试请求,所述测试请求中至少包括第一IP地址和第一本机网卡信息;The main thread receives a test request, where the test request at least includes the first IP address and the first local network card information;
所述主线程创建与所述测试请求对应的第一套接字和收发线程,将所述第一套接字中的网卡字段设置为所述第一本机网卡信息,将所述第一套接字中的目标IP地址字段设置为所述第一IP地址,将所述第一套接字配置给所述收发线程;The main thread creates a first socket and a transceiver thread corresponding to the test request, sets the network card field in the first socket to the first local network card information, and sets the first set of The target IP address field in the socket is set to the first IP address, and the first socket is configured to the transceiver thread;
所述收发线程通过所述第一套接字向第一目标主机发送查询报文,通过所述第一套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文,所述第一目标主机的IP地址为所述第一IP地址。The transceiver thread sends a query message to the first target host through the first socket, and receives a feedback message corresponding to the query message returned by the first target host through the first socket. , the IP address of the first target host is the first IP address.
根据本发明的第三方面,提供了一种计算机程序产品,包括计算机程序/指令,当所述计算机程序/指令处理器被执行时实现如本发明第二方面所述的方法。According to a third aspect of the present invention, there is provided a computer program product, comprising a computer program/instructions which, when executed by a processor, implements the method according to the second aspect of the present invention.
根据本发明的一个实施例,本发明通过在接收到测试请求后检测是否存在对应的收发线程和套接字,在没有对应的收发线程和套接字的情况下创建收发线程和第一套接字,收发线程通过第一套接字向第一目标主机发送查询报文,并通过第一目标主机返回的反馈报文,如果存在对应的收发线程和套接字,那么不需要重复创建,直接使用已有的收发线程和套接字进行报文的发送和接收,在需要多次获取网络延时的情况下,可以通过收发线程反复发送查询报文来得出网络延时,不用多次创建线程,降低系统资源的消耗。According to an embodiment of the present invention, the present invention detects whether the corresponding transceiver thread and socket exist after receiving the test request, and creates the transceiver thread and the first socket when there is no corresponding transceiver thread and socket. word, the transceiver thread sends a query message to the first target host through the first socket, and passes the feedback message returned by the first target host. If the corresponding transceiver thread and socket exist, there is no need to repeatedly create them, directly Use existing transceiver threads and sockets to send and receive messages. If you need to obtain the network delay multiple times, you can obtain the network delay by repeatedly sending query messages through the transceiver thread without creating threads multiple times. , reduce the consumption of system resources.
通过以下参照附图对本发明的示例性实施例的详细描述,本发明的其它特征及其优点将会变得清楚。Other features of the invention and its advantages will become apparent from the following detailed description of exemplary embodiments of the invention with reference to the accompanying drawings.
附图说明Description of the drawings
被结合在说明书中并构成说明书的一部分的附图示出了本发明的实施例,并且连同其说明一起用于解释本发明的原理。The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description, serve to explain the principles of the invention.
图1是本发明实施例中测试系统的示意图。Figure 1 is a schematic diagram of a test system in an embodiment of the present invention.
图2是本发明另一实施例中测试系统的示意图。Figure 2 is a schematic diagram of a test system in another embodiment of the present invention.
图3是本发明实施例中测试方法的流程图。Figure 3 is a flow chart of the testing method in the embodiment of the present invention.
具体实施方式Detailed ways
现在将参照附图来详细描述本发明的各种示例性实施例。应注意到:除非另外具体说明,否则在这些实施例中阐述的部件和步骤的相对布置、数字表达式和数值不限制本发明的范围。Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these examples do not limit the scope of the invention unless otherwise specifically stated.
以下对至少一个示例性实施例的描述实际上仅仅是说明性的,决不作为对本发明及其应用或使用的任何限制。The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application or uses.
对于相关领域普通技术人员已知的技术、方法和设备可能不作详细讨论,但在适当情况下,所述技术、方法和设备应当被视为说明书的一部分。Techniques, methods and devices known to those of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, such techniques, methods and devices should be considered a part of the specification.
在这里示出和讨论的所有例子中,任何具体值应被解释为仅仅是示例性的,而不是作为限制。因此,示例性实施例的其它例子可以具有不同的值。In all examples shown and discussed herein, any specific values are to be construed as illustrative only and not as limiting. Accordingly, other examples of the exemplary embodiments may have different values.
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步讨论。It should be noted that similar reference numerals and letters refer to similar items in the following figures, so that once an item is defined in one figure, it does not need further discussion in subsequent figures.
ping命令是工作在TCP/IP网络体系结构中应用层的一个服务命令,主要是向特定的目标主机发送ICMP(Internet Control Message Protocol,因特网报文控制协议)请求报文,测试目标主机是否可达以及了解相关网络状态。The ping command is a service command that works at the application layer in the TCP/IP network architecture. It mainly sends ICMP (Internet Control Message Protocol, Internet Message Control Protocol) request messages to a specific target host to test whether the target host is reachable. and understand related network status.
目前很多网络服务和应用程序都需要检测网络延时。在需要获取当前主机与目标主机之间的网络延时的情况下,通常会调用ping命令并获取其执行结果。由于每次调用ping命令都需要启动进程,当需要多次调用ping命令时,会增大消耗的CPU资源。对于嵌入式设备,特别是算力较低的设备,这种方式会极大影响设备的性能。Currently, many network services and applications need to detect network latency. When it is necessary to obtain the network delay between the current host and the target host, the ping command is usually called and its execution results are obtained. Since the process needs to be started every time the ping command is called, when the ping command needs to be called multiple times, the CPU resources consumed will increase. For embedded devices, especially devices with low computing power, this method will greatly affect the performance of the device.
如图1所示,本实施例介绍了一种测试系统,用于测试当前主机与目标主机之间的网络延时。当前主机和目标主机是具有通信需求的设备,比如可以为手机、电脑、车辆、服务器等设备。比如测试系统可以用于测试车辆与服务器之间的网络延时,测试系统也可以用于测试服务器与服务器之间的网络延时。As shown in Figure 1, this embodiment introduces a test system for testing the network delay between the current host and the target host. The current host and the target host are devices with communication requirements, such as mobile phones, computers, vehicles, servers and other devices. For example, the test system can be used to test the network delay between the vehicle and the server, and the test system can also be used to test the network delay between the server and the server.
所述测试系统包括主线程,用于接收测试请求,检测是否存在与所述测试请求对应的收发线程和套接字,所述测试请求中至少包括第一IP地址和第一本机网卡信息。The test system includes a main thread for receiving a test request and detecting whether there is a transceiver thread and socket corresponding to the test request. The test request includes at least a first IP address and first local network card information.
所述主线程还用于在检测到不存在与所述测试请求对应的收发线程和套接字的情况下,创建与所述测试请求对应的第一套接字和收发线程,将所述第一套接字中的网卡字段设置为所述第一本机网卡信息,将所述第一套接字中的目标IP地址字段设置为所述第一IP地址,将所述第一套接字配置给所述收发线程。The main thread is also used to create a first socket and a transceiver thread corresponding to the test request when it is detected that there are no transceiver threads and sockets corresponding to the test request, and transfer the third The network card field in the socket is set to the first local network card information, the target IP address field in the first socket is set to the first IP address, and the first socket Configured to the transceiver thread.
所述收发线程用于通过所述第一套接字向第一目标主机发送查询报文,通过所述第一套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文,所述第一目标主机的IP地址为所述第一IP地址。The transceiver thread is used to send a query message to the first target host through the first socket, and receive feedback corresponding to the query message returned by the first target host through the first socket. message, the IP address of the first target host is the first IP address.
所述主线程还用于在检测到存在与所述测试请求对应的收发线程和套接字的情况下,通过所述测试请求对应的收发线程和套接字向所述第一目标主机发送查询报文,以及通过所述测试请求对应的收发线程和套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文。The main thread is also used to send a query to the first target host through the transceiver thread and socket corresponding to the test request when it is detected that there is a transceiver thread and socket corresponding to the test request. message, and receive a feedback message corresponding to the query message returned by the first target host through the transceiver thread and socket corresponding to the test request.
主线程部署在当前主机,在当前主机还运行有其它应用程序。当某个应用程序需要获取当前主机与第一目标主机之间的网络延时的情况下,由该应用程序向主线程发送测试请求。主线程向应用程序提供接口,应用程序通过调用主线程提供的接口来发送测试请求。The main thread is deployed on the current host, and other applications are also running on the current host. When an application needs to obtain the network delay between the current host and the first target host, the application sends a test request to the main thread. The main thread provides an interface to the application program, and the application program sends test requests by calling the interface provided by the main thread.
在测试请求中包含第一目标主机的IP(Internet Protocol,网际互连协议)地址。比如应用程序需要获取当前主机与服务器之间的网络延时,那么应用程序将该服务器的IP地址添加至发送给主线程的测试请求中。The test request contains the IP (Internet Protocol) address of the first target host. For example, if the application needs to obtain the network delay between the current host and the server, the application will add the IP address of the server to the test request sent to the main thread.
同时测试请求中还包含第一本机网卡信息。第一本机网卡信息表示当前主机的网卡信息,具体地,网卡信息可以是网卡的MAC地址(Media Access Control Address,物理地址)。在当前主机中可以包括多个网卡,应用程序可以选择某一个网卡的信息作为第一本机网卡信息。比如,当前主机包括网卡1、网卡2和网卡3,在应用程序中配置通过网卡1与第一目标主机通信,当该应用程序需要获取与第一目标主机之间的网络延时的情况下,该应用程序将网卡1的信息发送给主线程。At the same time, the test request also contains the first local network card information. The first local network card information represents the network card information of the current host. Specifically, the network card information may be the MAC address (Media Access Control Address, physical address) of the network card. The current host can include multiple network cards, and the application can select the information of a certain network card as the first local network card information. For example, the current host includes network card 1, network card 2 and network card 3. The application is configured to communicate with the first target host through network card 1. When the application needs to obtain the network delay with the first target host, The application sends the information for network card 1 to the main thread.
主线程在接收到测试请求后,会检测是否存在与该测试请求对应的收发线程和套接字。如果存在与该测试请求对应的收发线程和套接字,那么可以直接使用该收发线程和套接字进行报文发送和接收,测试与第一目标主机之间的网络延时,不需要重复创建。After receiving the test request, the main thread will detect whether there is a sending and receiving thread and socket corresponding to the test request. If there is a transceiver thread and socket corresponding to the test request, you can directly use the transceiver thread and socket to send and receive messages to test the network delay with the first target host without the need to create it again. .
在没有与该测试请求对应的收发线程和套接字的情况下,主线程才会创建与该测试请求对应的第一套接字和收发线程。第一套接字包括多个属性字段,比如网卡字段和目标IP地址字段。其中目标IP地址字段表示通信对象的IP地址,比如需要让当前主机与第一目标主机进行通信,那么将第一套接字中的目标IP地址字段设置为第一目标主机的IP地址。网卡字段表示在当前主机与第一目标主机通信时所使用的网卡。主线程将测试请求中包含的第一本机网卡信息写入第一套接字,作为第一套接字的网卡字段。If there are no transceiver threads and sockets corresponding to the test request, the main thread will create the first socket and transceiver thread corresponding to the test request. The first socket includes multiple attribute fields, such as the network card field and the target IP address field. The target IP address field represents the IP address of the communication object. For example, if the current host needs to communicate with the first target host, then the target IP address field in the first socket is set to the IP address of the first target host. The network card field indicates the network card used when the current host communicates with the first target host. The main thread writes the first local network card information contained in the test request to the first socket as the network card field of the first socket.
主线程通过将第一套接字配置给收发线程,建立该收发线程与第一套接字之间的绑定关系。收发线程可以通过该第一套接字发送查询报文或者接收反馈报文。收发线程在通过第一套接字向第一目标主机发送查询报文时,记录发送查询报文的时间。收发线程在通过第一套接字接收第一目标主机返回的反馈报文时,记录接收反馈报文的时间。根据发送查询报文的时间和接收反馈报文的时间即可得出当前主机与第一目标主机之间的网络延时。The main thread configures the first socket to the transceiver thread to establish a binding relationship between the transceiver thread and the first socket. The transceiver thread can send query messages or receive feedback messages through the first socket. When the transceiver thread sends the query message to the first target host through the first socket, it records the time when the query message is sent. When the transceiver thread receives the feedback message returned by the first target host through the first socket, it records the time of receiving the feedback message. The network delay between the current host and the first target host can be obtained based on the time of sending the query message and the time of receiving the feedback message.
本实施例通过在接收到测试请求后检测是否存在对应的收发线程和套接字,在没有对应的收发线程和套接字的情况下创建收发线程和第一套接字,收发线程通过第一套接字向第一目标主机发送查询报文,并通过第一目标主机返回的反馈报文,如果存在对应的收发线程和套接字,那么不需要重复创建,直接使用已有的收发线程和套接字进行报文的发送和接收,在需要多次获取网络延时的情况下,可以通过收发线程反复发送查询报文来得出网络延时,不用多次创建线程,降低系统资源的消耗。This embodiment detects whether the corresponding transceiver thread and socket exist after receiving the test request, and creates the transceiver thread and the first socket when there is no corresponding transceiver thread and socket. The transceiver thread passes the first The socket sends a query message to the first target host, and uses the feedback message returned by the first target host. If there is a corresponding transceiver thread and socket, there is no need to create it again, and the existing transceiver thread and socket are directly used. Sockets are used to send and receive messages. When the network delay needs to be obtained multiple times, the network delay can be obtained by repeatedly sending query messages through the sending and receiving threads. This eliminates the need to create threads multiple times and reduces the consumption of system resources.
本实施例中,所述主线程用于在接收到暂停指令时,检测所述收发线程是否处于运行状态,在所述收发线程处于运行状态时,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文。In this embodiment, the main thread is used to detect whether the transceiver thread is in a running state when receiving a pause instruction, and when the transceiver thread is in a running state, send a pause message to the transceiver thread. The pause The message is used to instruct the transceiver thread to stop sending query messages and stop receiving feedback messages.
通常一个应用程序具有多个功能,对于该应用程序的部分功能,需要用到当前主机与第一目标主机之间的网络延时,那么在该应用程序运行这部分功能时,通过向主线程发送测试请求来获取网络延时。而当该应用程序运行其它功能时,则不需要获取网络延时,那么通过向主线程发送暂停指令,让收发线程停止发送查询报文以及接收反馈报文,以降低资源消耗。Usually an application has multiple functions. For some functions of the application, the network delay between the current host and the first target host needs to be used. Then when the application runs this part of the function, it is sent to the main thread. Test requests to obtain network latency. When the application runs other functions, it does not need to obtain network delay. Then, by sending a pause instruction to the main thread, the transceiver thread stops sending query messages and receiving feedback messages to reduce resource consumption.
主线程在接收到暂停指令后,会检测收发线程是否处于运行状态。如果收发线程不处于运行状态,说明收发线程已经处于暂停状态,收发线程已经停止发送查询报文和停止接收反馈报文,在此情况下主线程不需要针对该暂停指令作出相应的处理,主线程不用向收发线程发送消息。After receiving the pause instruction, the main thread will detect whether the transceiver thread is running. If the transceiver thread is not running, it means that the transceiver thread is already in a suspended state. The transceiver thread has stopped sending query messages and stopped receiving feedback messages. In this case, the main thread does not need to handle the pause instruction accordingly. The main thread There is no need to send messages to the sending and receiving threads.
如果主线程接收到暂停指令后,检测出收发线程处于运行状态,那么向收发线程发送暂停消息。收发线程接收到暂停消息后,收发线程会停止发送查询报文,并停止接收反馈报文,收发线程进入暂停状态,等待主线程的下次唤醒。If the main thread detects that the transceiver thread is running after receiving the pause instruction, it sends a pause message to the transceiver thread. After the transceiver thread receives the pause message, the transceiver thread will stop sending query messages and stop receiving feedback messages. The transceiver thread will enter the paused state and wait for the next wake-up of the main thread.
本实施例中,所述主线程用于在接收到恢复指令时,检测所述收发线程是否处于暂停状态,在所述收发线程处于暂停状态时,向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。In this embodiment, the main thread is used to detect whether the transceiver thread is in a suspended state when receiving a resume instruction, and when the transceiver thread is in a suspended state, send a resume message to the transceiver thread. The message is used to instruct the transceiver thread to resume sending query messages and to resume receiving feedback messages.
当应用程序运行不需要网络延时的功能时,应用程序会向主线程发送暂停指令,让收发线程进入暂停状态。而当应用程序又运行需要网络延时的功能时,应用程序会向主线程发送恢复指令。When the application runs a function that does not require network delay, the application will send a pause instruction to the main thread to put the sending and receiving threads into a paused state. When the application runs a function that requires network delay, the application will send a recovery instruction to the main thread.
主线程接收到恢复指令后,检测收发线程是否处于暂停状态。如果收发线程不处于暂停状态,说明收发线程处于运行状态,那么主线程不需要针对该恢复指令作出相应处理。After receiving the resume instruction, the main thread detects whether the transceiver thread is in a suspended state. If the transceiver thread is not in a suspended state, it means that the transceiver thread is in a running state, and the main thread does not need to handle the recovery instruction accordingly.
如果主线程接收到恢复指令后,检测出收发线程处于暂停状态,那么向收发线程发送恢复消息。收发线程接收到恢复消息后,收发线程恢复发送查询报文以及恢复接收反馈报文,收发线程进入运行状态。If the main thread detects that the transceiver thread is in a suspended state after receiving the resume instruction, it sends a resume message to the transceiver thread. After the transceiver thread receives the recovery message, the transceiver thread resumes sending query messages and resumes receiving feedback messages, and the transceiver thread enters the running state.
本实施例中,所述主线程用于在接收到更改地址指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文。In this embodiment, the main thread is used to send a pause message to the transceiver thread after receiving the address change instruction. The pause message is used to instruct the transceiver thread to stop sending query messages and stop receiving feedback messages. .
所述主线程用于销毁所述第一套接字,创建第二套接字,将所述第二套接字中的网卡字段设置为所述第一本机网卡信息,将所述第二套接字中的目标IP地址字段设置为所述更改地址指令中包含的第二IP地址。The main thread is used to destroy the first socket, create a second socket, set the network card field in the second socket to the first local network card information, and set the second The target IP address field in the socket is set to the second IP address contained in the change address instruction.
所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程通过所述第二套接字向第二目标主机发送查询报文,通过所述第二套接字接收所述第二目标主机返回的与所述查询报文对应的反馈报文,所述第二目标主机的IP地址为所述第二IP地址。The main thread is used to send a recovery message to the transceiver thread. The recovery message is used to instruct the transceiver thread to send a query message to the second target host through the second socket. The interface receives a feedback message corresponding to the query message returned by the second target host, where the IP address of the second target host is the second IP address.
应用程序根据自身的业务需求,可能会需要与不同的目标主机进行通信。比如应用程序先与目标主机1进行通信,然后与目标主机2进行通信。在应用程序与目标主机1进行通信时,应用程序向主线程发送测试请求,来获取当前主机与目标主机1之间的网络延时。而当应用程序切换至与目标主机2进行通信后,应用程序需要获取当前主机与目标主机2之间的网络延时,此时应用程序向主线程发送更改地址指令,在更改地址指令中包含目标主机2的IP地址。Applications may need to communicate with different target hosts based on their own business needs. For example, the application first communicates with target host 1, and then communicates with target host 2. When the application communicates with target host 1, the application sends a test request to the main thread to obtain the network delay between the current host and target host 1. When the application switches to communicate with target host 2, the application needs to obtain the network delay between the current host and target host 2. At this time, the application sends a change address instruction to the main thread, and includes the target in the change address instruction. The IP address of host 2.
主线程接收到更改地址指令之后,向收发线程发送暂停消息。收发线程接收到暂停消息后,停止发送查询报文以及停止接收查询报文。具体地,收发线程停止通过第一套接字发送查询报文,收发线程停止通过第一套接字接收反馈报文。After receiving the change address instruction, the main thread sends a pause message to the transceiver thread. After receiving the pause message, the transceiver thread stops sending query messages and stops receiving query messages. Specifically, the transceiver thread stops sending query messages through the first socket, and the transceiver thread stops receiving feedback messages through the first socket.
然后主线程将第一套接字销毁,并创建新的第二套接字。由于更改地址指令中只包含第二目标IP地址,在通信时仍然使用原有网卡,那么主线程将第一本机网卡信息写入第二套接字,主线程还将更改地址指令中包含的第二目标IP地址写入第二套接字。Then the main thread destroys the first socket and creates a new second socket. Since the change address instruction only contains the second target IP address, and the original network card is still used during communication, the main thread writes the first local network card information to the second socket, and the main thread will also change the address included in the instruction. The second destination IP address is written to the second socket.
在将第二套接字的属性设置完毕后,主线程向收发线程发送恢复消息,唤醒收发线程。收发线程接收到恢复消息后,通过第二套接字向第二目标IP地址对应的第二目标主机发送查询报文,并接收第二目标主机返回的反馈报文,以得出当前主机与第二目标主机之间的网络延时。After setting the properties of the second socket, the main thread sends a recovery message to the transceiver thread to wake up the transceiver thread. After receiving the recovery message, the transceiver thread sends a query message to the second target host corresponding to the second target IP address through the second socket, and receives a feedback message returned by the second target host to determine the relationship between the current host and the second target host. The network delay between the two target hosts.
本实施例通过在主线程接收到更改地址指令之后,将原有的第一套接字销毁,创建新的第二套接字,让收发线程通过新创建的第二套接字进行报文的发送和接收,不需要创建新的收发线程,节约系统资源。In this embodiment, after the main thread receives the address change instruction, it destroys the original first socket and creates a new second socket, allowing the sending and receiving threads to process messages through the newly created second socket. For sending and receiving, there is no need to create new sending and receiving threads, saving system resources.
本实施例中,所述主线程用于在接收到更改网卡指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止报文的接收和发送。所述主线程用于将所述第一套接字中的网卡字段设置为所述更改网卡指令中包含的第二本机网卡信息。所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。In this embodiment, the main thread is used to send a pause message to the transceiver thread after receiving the instruction to change the network card. The pause message is used to instruct the transceiver thread to stop receiving and sending messages. The main thread is used to set the network card field in the first socket to the second local network card information included in the change network card instruction. The main thread is used to send a recovery message to the transceiver thread, and the recovery message is used to instruct the transceiver thread to resume sending query messages and to resume receiving feedback messages.
在当前主机中可以包括多个网卡,如果应用程序使用另外的网卡进行通信,那么应用程序向主线程发送更改网卡指令。比如当前主机为车辆,在车辆中设有多个网卡,每个网卡分别对应不同的网络服务商,而在不同的地区不同网络服务商提供的信号强度不同。比如在地区1网络服务商A的信号强度最高,在地区2网络服务商B的信号强度最高。那么车辆在地区1时应用程序使用网络服务商A对应的网卡,车辆在地区2时应用程序使用网络服务商B对应的网卡。当车辆从地区1驶入地区2后,应用程序使用的网卡发生切换,在此情况下应用程序向主线程发送更改网卡指令。The current host may include multiple network cards. If the application uses another network card for communication, the application sends a change network card instruction to the main thread. For example, the current host is a vehicle, and there are multiple network cards in the vehicle. Each network card corresponds to a different network service provider, and different network service providers in different regions provide different signal strengths. For example, in area 1, network service provider A has the highest signal strength, and in area 2, network service provider B has the highest signal strength. Then when the vehicle is in region 1, the application uses the network card corresponding to network service provider A, and when the vehicle is in region 2, the application uses the network card corresponding to network service provider B. When the vehicle drives from area 1 to area 2, the network card used by the application is switched. In this case, the application sends a change network card instruction to the main thread.
在更改网卡指令中包含新的第二本机网卡信息。主线程接收到更改网卡指令之后,需要修改第一套接字中的网卡字段。在修改第一套接字的网卡字段之前,主线程向收发线程发送暂停消息,收发线程停止发送查询报文以及停止接收反馈报文。在主线程将第二本机网卡信息写入第一套接字之后,主线程向收发线程发送恢复消息。让收发线程恢复发送查询报文以及恢复接收反馈报文。Include the new second local network card information in the change network card command. After the main thread receives the instruction to change the network card, it needs to modify the network card field in the first socket. Before modifying the network card field of the first socket, the main thread sends a pause message to the transceiver thread, and the transceiver thread stops sending query messages and stops receiving feedback messages. After the main thread writes the second local network card information to the first socket, the main thread sends a recovery message to the transceiver thread. Let the transceiver thread resume sending query messages and resume receiving feedback messages.
本实施例通过在主线程接收到更改网卡指令之后,直接修改第一套接字的网卡字段,不需要创建新的套接字和收发线程,节约系统资源。In this embodiment, after the main thread receives the instruction to change the network card, it directly modifies the network card field of the first socket without creating a new socket and transceiver thread, thus saving system resources.
本实施例中,所述测试请求中还包括第一周期和第一循环次数。所述主线程用于将所述第一周期和所述第一循环次数发送至所述收发线程。所述收发线程用于每隔所述第一周期通过所述第一套接字向所述第一目标主机发送所述查询报文。所述收发线程用于在发送所述查询报文的次数达到所述第一循环次数的情况下,停止发送所述查询报文。In this embodiment, the test request also includes a first period and a first number of cycles. The main thread is used to send the first period and the first number of cycles to the transceiver thread. The transceiver thread is configured to send the query message to the first target host through the first socket every first cycle. The sending and receiving thread is configured to stop sending the query message when the number of times the query message is sent reaches the first number of cycles.
应用程序在向主线程发送测试请求时,还可以在测试请求中加入第一周期和第一循环次数。第一周期表示收发线程发送查询报文的时间间隔。第一循环次数表示收发线程发送查询报文的次数。When the application sends a test request to the main thread, it can also add the first cycle and the first number of loops to the test request. The first cycle represents the time interval between the sending and receiving threads sending query messages. The number of first cycles indicates the number of times the transceiver thread sends query messages.
主线程接收到测试请求后,创建对应的收发线程和第一套接字,将测试请求中的第一周期和第一循环次数发送给收发线程。收发线程根据第一周期和第一循环次数来发送查询报文。After receiving the test request, the main thread creates the corresponding transceiver thread and the first socket, and sends the first cycle and the first number of cycles in the test request to the transceiver thread. The transceiver thread sends the query message according to the first cycle and the first cycle number.
比如第一周期为50ms,第一循环次数为5次。那么收发线程每隔50ms发送一次查询报文,并且在收发线程发送5次查询报文后停止继续发送查询报文。For example, the first period is 50ms, and the number of first cycles is 5 times. Then the transceiver thread sends a query message every 50ms, and stops sending query messages after the transceiver thread sends query messages 5 times.
本实施例通过在测试请求中加入第一周期和第一循环次数,让收发线程根据第一周期和第一循环次数来发送查询报文,满足应用程序的个性化需求,加强测试系统的功能性。In this embodiment, the first cycle and the first cycle number are added to the test request, so that the transceiver thread sends the query message according to the first cycle and the first cycle number, so as to meet the personalized needs of the application and enhance the functionality of the test system. .
本实施例中,所述主线程用于在接收到更改周期指令之后,将所述更改周期指令中包含的第二周期发送至所述收发线程。所述收发线程用于每隔所述第二周期通过所述第一套接字向所述第一目标主机发送所述查询报文。In this embodiment, the main thread is configured to send the second cycle included in the change cycle instruction to the transceiver thread after receiving the change cycle instruction. The transceiver thread is configured to send the query message to the first target host through the first socket every second period.
应用程序可以根据自身的业务需求来确定收发线程发送查询报文的周期。当应用程序需要更改收发线程发送查询报文的周期时,应用程序向主线程发送更改周期指令。更改周期指令中包括新的第二周期。The application can determine the cycle of sending query messages by the transceiver thread according to its own business needs. When the application program needs to change the period at which the transceiver thread sends query messages, the application program sends a change period instruction to the main thread. A new second cycle is included in the change cycle command.
主线程接收到更改周期指令之后,将更改周期指令中包含的第二周期发送至收发线程。收发线程根据第二周期来发送查询报文。比如第一周期为50ms,第二周期为70ms。在主线程接收到更改周期指令之前,收发线程每隔50ms发送一次查询报文。在主线程接收到更改周期指令之后,收发线程每隔70ms发送一次查询报文。After receiving the change cycle instruction, the main thread sends the second cycle included in the change cycle instruction to the transceiver thread. The transceiver thread sends the query message according to the second cycle. For example, the first period is 50ms and the second period is 70ms. Before the main thread receives the change cycle instruction, the transceiver thread sends a query message every 50ms. After the main thread receives the change cycle instruction, the transceiver thread sends a query message every 70ms.
本实施例中,所述主线程用于在接收到更改循环次数指令之后,将所述更改循环次数指令中包含的第二循环次数发送至所述收发线程。所述收发线程用于在发送所述查询报文的次数达到所述第二循环次数的情况下,停止发送所述查询报文。In this embodiment, the main thread is configured to send the second cycle number contained in the change cycle number instruction to the transceiver thread after receiving the instruction to change the number of cycles. The sending and receiving thread is configured to stop sending the query message when the number of times the query message is sent reaches the second cycle number.
应用程序也可以根据自身业务需求来确定收发线程发送查询报文的循环次数。当应用程序需要更改收发线程发送查询报文的循环次数时,应用程序向主线程发送更改循环次数指令。更改循环次数指令中包括新的第二循环次数。The application can also determine the number of cycles for the sending and receiving thread to send query messages based on its own business needs. When the application needs to change the number of cycles for sending query messages by the transceiver thread, the application sends a change cycle number instruction to the main thread. The change cycle count instruction includes a new second cycle count.
主线程接收到更改循环次数指令之后,将更改循环次数指令中包含的第二循环次数发送至收发线程。收发线程根据第二循环次数来发送查询报文。比如第一循环次数为5次,第二循环次数为10次。在主线程接收到更改循环次数指令之前,收发线程发送5次查询报文后停止发送。在主线程接收到更改循环次数指令之后,收发线程发送10次查询报文后停止发送。After receiving the instruction to change the number of cycles, the main thread sends the second number of cycles included in the instruction to change the number of cycles to the transceiver thread. The sending and receiving thread sends the query message according to the second cycle number. For example, the first cycle number is 5 times, and the second cycle number is 10 times. Before the main thread receives the instruction to change the number of cycles, the transceiver thread sends query messages 5 times and then stops sending. After the main thread receives the instruction to change the number of cycles, the transceiver thread sends query messages 10 times and then stops sending.
本实施例中,所述主线程用于在接收到多个测试请求的情况下,创建与每个所述测试请求对应的收发线程以及与每个所述收发线程对应的套接字,将每个所述套接字中的目标IP地址字段设置为所述套接字对应的测试请求中包含的IP地址,将每个所述套接字中的网卡字段设置为所述套接字对应的测试请求中包含的本机网卡信息;In this embodiment, the main thread is used to create a transceiver thread corresponding to each test request and a socket corresponding to each transceiver thread when multiple test requests are received. The target IP address field in each of the sockets is set to the IP address included in the test request corresponding to the socket, and the network card field in each of the sockets is set to the IP address corresponding to the socket. The local network card information included in the test request;
每个所述收发线程用于通过对应的套接字向目标主机发送查询报文,通过所述对应的套接字接收所述目标主机返回的与所述查询报文对应的反馈报文。Each of the transceiver threads is used to send a query message to the target host through a corresponding socket, and receive a feedback message corresponding to the query message returned by the target host through the corresponding socket.
在当前主机中可以运行多个应用程序,这多个应用程序通信的目标主机可能不同。如果多个应用程序都需要获取当前主机与各自对应的目标主机之间的网络延时,那么每个应用程序都可以向主线程发送测试请求。在测试请求中加入本机网卡信息和目标IP地址。Multiple applications can be running on the current host, and the target hosts for communication between these multiple applications may be different. If multiple applications need to obtain the network delay between the current host and their corresponding target host, then each application can send a test request to the main thread. Add the local network card information and target IP address to the test request.
比如应用程序1需要与服务器1通信,应用程序2需要与服务器2通信。那么应用程序1向主线程发送的测试请求中加入服务器1的IP地址,应用程序2向主线程发送的测试请求中加入服务器2的IP地址。For example, application 1 needs to communicate with server 1, and application 2 needs to communicate with server 2. Then application 1 adds the IP address of server 1 to the test request sent to the main thread, and application 2 adds the IP address of server 2 to the test request sent to the main thread.
主线程在接收到多个测试请求后,针对每个测试请求创建对应的套接字和收发线程。将测试请求中包含的目标IP地址和本机网卡信息写入对应的套接字。如果测试请求中还包括周期和循环次数,那么主线程将测试请求中的周期和循环次数发送给对应的收发线程。收发线程通过对应的套接字来接收和发送报文。After receiving multiple test requests, the main thread creates corresponding sockets and transceiver threads for each test request. Write the target IP address and local network card information contained in the test request to the corresponding socket. If the test request also includes the period and number of cycles, then the main thread sends the period and number of cycles in the test request to the corresponding transceiver thread. The transceiver thread receives and sends messages through the corresponding socket.
如图3所示,主线程接收到三个应用程序的测试请求,这三个应用程序对应的目标主机都不同。主线程在当前主机中创建三个收发线程和套接字,每个收发线程通过各自的套接字向对应的目标主机发送查询报文,并接收对应的目标主机返回的反馈报文。As shown in Figure 3, the main thread receives test requests from three applications, and the target hosts corresponding to these three applications are different. The main thread creates three transceiver threads and sockets in the current host. Each transceiver thread sends query messages to the corresponding target host through its own socket, and receives feedback messages returned by the corresponding target host.
在一种实施方式中,主线程先接收到第一应用程序发送的第一测试请求,并创建第一测试请求对应的第一套接字和第一收发线程。第一收发线程通过第一套接字向第一应用程序对应的第一目标主机发送查询报文,并接收第一目标主机返回的反馈报文。第一收发线程根据发送查询报文的时间和接收查询报文的时间得出网络延时。In one implementation, the main thread first receives the first test request sent by the first application program, and creates the first socket and the first transceiver thread corresponding to the first test request. The first transceiver thread sends a query message to the first target host corresponding to the first application program through the first socket, and receives a feedback message returned by the first target host. The first transceiver thread obtains the network delay based on the time of sending the query message and the time of receiving the query message.
然后在主线程已经创建第一测试请求对应的第一套接字和第一收发线程的情况下,主线程接收到第二应用程序发送的第二测试请求。在此情况下,主线程判断第二测试请求中的本机网卡信息与第一测试请求中的本机网卡信息是否相同,同时还判断第二测试请求中的目标IP地址与第一测试请求中的目标IP地址是否相同。Then, when the main thread has created the first socket and the first transceiver thread corresponding to the first test request, the main thread receives the second test request sent by the second application. In this case, the main thread determines whether the local network card information in the second test request is the same as the local network card information in the first test request, and also determines whether the target IP address in the second test request is the same as the local network card information in the first test request. The destination IP addresses are the same.
如果都相同,那么说明第一应用程序和第二应用程序的通信对象是同一目标主机,并且第一应用程序和第二应用程序通过同一本机网卡进行通信,在此情况下主线程不用创建新的套接字和收发线程,主线程可以直接将第一收发线程得到的网络延时反馈至第二应用程序,降低系统资源的消耗。If they are the same, it means that the communication object of the first application and the second application is the same target host, and the first application and the second application communicate through the same local network card. In this case, the main thread does not need to create a new With the socket and transceiver thread, the main thread can directly feed back the network delay obtained by the first transceiver thread to the second application, reducing the consumption of system resources.
如果有至少一种参数不同,那么主线程创建第二测试请求对应的第二套接字和第二收发线程,第二收发线程通过第二套接字向第二应用程序对应的第二目标主机发送查询报文,并接收第二目标主机返回的反馈报文,得出当前主机与第二目标主机之间的网络延时。If at least one parameter is different, then the main thread creates a second socket corresponding to the second test request and a second transceiver thread, and the second transceiver thread sends a message to the second target host corresponding to the second application through the second socket. Send a query message and receive a feedback message returned by the second target host to obtain the network delay between the current host and the second target host.
本实施例通过在主线程接收到多个测试请求的情况下,创建每个测试请求对应的套接字和收发线程,每个收发线程独立进行报文的发送和接收,满足多个应用程序的测试需求。同时主线程只需要向应用程序提供一个接口,通过主线程对多个收发线程和多个套接字进行统一管理,提高系统的便利性。In this embodiment, when the main thread receives multiple test requests, it creates a socket and a transceiver thread corresponding to each test request. Each transceiver thread independently sends and receives messages to meet the needs of multiple applications. Testing requirements. At the same time, the main thread only needs to provide an interface to the application program, and unified management of multiple transceiver threads and multiple sockets through the main thread improves the convenience of the system.
如图3所示,本实施例介绍了一种测试方法,该测试方法应用于本发明任一实施例所述的测试系统。所述方法包括步骤3100-3300。As shown in Figure 3, this embodiment introduces a test method, which is applied to the test system described in any embodiment of the present invention. The method includes steps 3100-3300.
步骤3100:主线程接收测试请求,所述测试请求中至少包括第一IP地址和本机网卡信息。Step 3100: The main thread receives a test request, which at least includes the first IP address and local network card information.
步骤3200:所述主线程创建与所述测试请求对应的第一套接字和收发线程,将所述第一套接字中的网卡字段设置为所述第一本机网卡信息,将所述第一套接字中的目标IP地址字段设置为所述第一IP地址,将所述第一套接字配置给所述收发线程。Step 3200: The main thread creates the first socket and transceiver thread corresponding to the test request, sets the network card field in the first socket to the first local network card information, and sets the The target IP address field in the first socket is set to the first IP address, and the first socket is configured to the transceiver thread.
步骤3300:所述收发线程通过所述第一套接字向第一目标主机发送查询报文,通过所述第一套接字接收所述第一目标主机返回的与所述查询报文对应的反馈报文,所述第一目标主机的IP地址为所述第一IP地址。Step 3300: The transceiver thread sends a query message to the first target host through the first socket, and receives the query message returned by the first target host through the first socket and corresponding to the query message. In the feedback message, the IP address of the first target host is the first IP address.
本发明通过创建收发线程和第一套接字,收发线程通过第一套接字向第一目标主机发送查询报文,并通过第一目标主机返回的反馈报文,在需要多次获取网络延时的情况下,可以通过收发线程反复发送查询报文来得出网络延时,不用多次创建线程,降低系统资源的消耗。The present invention creates a transceiver thread and a first socket. The transceiver thread sends a query message to the first target host through the first socket, and uses the feedback message returned by the first target host to obtain the network delay multiple times. In the case of time, the network delay can be obtained by repeatedly sending query messages by the sending and receiving threads. There is no need to create threads multiple times, which reduces the consumption of system resources.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程在接收到更改地址指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文;After receiving the address change instruction, the main thread sends a pause message to the transceiver thread, and the pause message is used to instruct the transceiver thread to stop sending query messages and stop receiving feedback messages;
所述主线程用于销毁所述第一套接字,创建第二套接字,将所述第二套接字中的网卡字段设置为所述第一本机网卡信息,将所述第二套接字中的目标IP地址字段设置为所述更改地址指令中包含的第二IP地址;The main thread is used to destroy the first socket, create a second socket, set the network card field in the second socket to the first local network card information, and set the second The target IP address field in the socket is set to the second IP address contained in the change address instruction;
所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程通过所述第二套接字向第二目标主机发送查询报文,通过所述第二套接字接收所述第二目标主机返回的与所述查询报文对应的反馈报文,所述第二目标主机的IP地址为所述第二IP地址。The main thread is used to send a recovery message to the transceiver thread. The recovery message is used to instruct the transceiver thread to send a query message to the second target host through the second socket. The interface receives a feedback message corresponding to the query message returned by the second target host, where the IP address of the second target host is the second IP address.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到更改网卡指令之后,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止报文的接收和发送;The main thread is used to send a pause message to the transceiver thread after receiving the instruction to change the network card, and the pause message is used to instruct the transceiver thread to stop receiving and sending messages;
所述主线程用于将所述第一套接字中的网卡字段设置为所述更改网卡指令中包含的第二本机网卡信息;The main thread is used to set the network card field in the first socket to the second local network card information included in the change network card instruction;
所述主线程用于向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。The main thread is used to send a recovery message to the transceiver thread, and the recovery message is used to instruct the transceiver thread to resume sending query messages and to resume receiving feedback messages.
可选地,所述测试请求中还包括第一周期和第一循环次数,所述方法还包括:Optionally, the test request also includes a first period and a first number of cycles, and the method further includes:
所述主线程将所述第一周期和所述第一循环次数发送至所述收发线程;The main thread sends the first period and the first number of cycles to the transceiver thread;
所述收发线程每隔所述第一周期通过所述第一套接字向所述第一目标主机发送所述查询报文;The transceiver thread sends the query message to the first target host through the first socket every said first cycle;
所述收发线程在发送所述查询报文的次数达到所述第一循环次数的情况下,停止发送所述查询报文。When the number of times the sending and receiving thread sends the query message reaches the first number of cycles, it stops sending the query message.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到更改周期指令之后,将所述更改周期指令中包含的第二周期发送至所述收发线程;The main thread is configured to send the second cycle included in the change cycle instruction to the transceiver thread after receiving the change cycle instruction;
所述收发线程用于每隔所述第二周期通过所述第一套接字向所述第一目标主机发送所述查询报文。The transceiver thread is configured to send the query message to the first target host through the first socket every second period.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到更改循环次数指令之后,将所述更改循环次数指令中包含的第二循环次数发送至所述收发线程;The main thread is configured to send the second cycle number contained in the change cycle number instruction to the transceiver thread after receiving the change cycle number instruction;
所述收发线程用于在发送所述查询报文的次数达到所述第二循环次数的情况下,停止发送所述查询报文。The sending and receiving thread is configured to stop sending the query message when the number of times the query message is sent reaches the second cycle number.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到多个测试请求的情况下,创建与每个所述测试请求对应的收发线程以及与每个所述收发线程对应的套接字,将每个所述套接字中的目标IP地址字段设置为所述套接字对应的测试请求中包含的IP地址,将每个所述套接字中的网卡字段设置为所述套接字对应的测试请求中包含的本机网卡信息;The main thread is used to create a transceiver thread corresponding to each test request and a socket corresponding to each transceiver thread when multiple test requests are received, and connect each socket The target IP address field in the word is set to the IP address included in the test request corresponding to the socket, and the network card field in each of the sockets is set to the IP address included in the test request corresponding to the socket. Local network card information;
每个所述收发线程用于通过对应的套接字向目标主机发送查询报文,通过所述对应的套接字接收所述目标主机返回的与所述查询报文对应的反馈报文。Each of the transceiver threads is used to send a query message to the target host through a corresponding socket, and receive a feedback message corresponding to the query message returned by the target host through the corresponding socket.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到暂停指令时,检测所述收发线程是否处于运行状态,在所述收发线程处于运行状态时,向所述收发线程发送暂停消息,所述暂停消息用于指示所述收发线程停止发送查询报文以及停止接收反馈报文。The main thread is used to detect whether the transceiver thread is in a running state when receiving a pause instruction. When the transceiver thread is in a running state, send a pause message to the transceiver thread. The pause message is used to indicate that the transceiver thread is in a running state. The above-mentioned transceiver thread stops sending query messages and stops receiving feedback messages.
可选地,所述方法还包括:Optionally, the method also includes:
所述主线程用于在接收到恢复指令时,检测所述收发线程是否处于暂停状态,在所述收发线程处于暂停状态时,向所述收发线程发送恢复消息,所述恢复消息用于指示所述收发线程恢复发送查询报文以及恢复接收反馈报文。The main thread is used to detect whether the transceiver thread is in a suspended state when receiving a resume instruction. When the transceiver thread is in a suspended state, send a resume message to the transceiver thread. The resume message is used to indicate that the transceiver thread is in a suspended state. The above-mentioned transceiver thread resumes sending query messages and resumes receiving feedback messages.
本实施例介绍了一种计算机程序产品,包括计算机程序/指令,当所述计算机程序/指令处理器被执行时实现如本发明任一实施例所述的测试方法。This embodiment introduces a computer program product, which includes a computer program/instruction. When the computer program/instruction is executed by a processor, the testing method according to any embodiment of the present invention is implemented.
本实施例介绍了一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如本发明任一实施例所述的测试方法的步骤。This embodiment introduces a readable storage medium. The readable storage medium stores programs or instructions. When the program or instructions are executed by a processor, the steps of the testing method described in any embodiment of the present invention are implemented.
本申请中的方法可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机程序或指令。在计算机上加载和执行所述计算机程序或指令时,全部或部分地执行本申请所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、网络设备、用户设备、核心网设备、OAM或者其它可编程装置。The methods in this application can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed on a computer, the processes or functions described in this application are performed in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, a core network device, an OAM or other programmable device.
所述计算机程序或指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机程序或指令可以从一个网站站点、计算机、服务器或数据中心通过有线或无线方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是集成一个或多个可用介质的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,例如,软盘、硬盘、磁带;也可以是光介质,例如,数字视频光盘;还可以是半导体介质,例如,固态硬盘。该计算机可读存储介质可以是易失性或非易失性存储介质,或可包括易失性和非易失性两种类型的存储介质。The computer program or instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer program or instructions may be transmitted from a website, computer, A server or data center transmits via wired or wireless means to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media, such as floppy disks, hard disks, and tapes; optical media, such as digital video optical disks; or semiconductor media, such as solid-state hard drives. The computer-readable storage medium may be volatile or nonvolatile storage media, or may include both volatile and nonvolatile types of storage media.
这里所描述的计算机程序/指令可以从计算机可读存储介质下载到各个计算/处理设备,或者通过网络、例如因特网、局域网、广域网和/或无线网下载到外部计算机或外部存储设备。网络可以包括铜传输电缆、光纤传输、无线传输、路由器、防火墙、交换机、网关计算机和/或边缘服务器。每个计算/处理设备中的网络适配卡或者网络接口从网络接收计算机可读程序指令,并转发该计算机可读程序指令,以供存储在各个计算/处理设备中的计算机可读存储介质中。The computer programs/instructions described herein may be downloaded from a computer-readable storage medium to various computing/processing devices, or to an external computer or external storage device over a network, such as the Internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage on a computer-readable storage medium in the respective computing/processing device .
用于执行本发明操作的计算机程序指令可以是汇编指令、指令集架构(ISA)指令、机器指令、机器相关指令、微代码、固件指令、状态设置数据、或者以一种或多种编程语言的任意组合编写的源代码或目标代码,所述编程语言包括面向对象的编程语言—诸如Smalltalk、C++等,以及常规的过程式编程语言—诸如“C”语言或类似的编程语言。计算机可读程序指令可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络—包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。在一些实施例中,通过利用计算机可读程序指令的状态信息来个性化定制电子电路,例如可编程逻辑电路、现场可编程门阵列(FPGA)或可编程逻辑阵列(PLA),该电子电路可以执行计算机可读程序指令,从而实现本发明的各个方面。Computer program instructions for performing operations of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or instructions in one or more programming languages. Source code or object code written in any combination of object-oriented programming languages - such as Smalltalk, C++, etc., and conventional procedural programming languages - such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server implement. In situations involving remote computers, the remote computer can be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (such as an Internet service provider through the Internet). connect). In some embodiments, by utilizing state information of computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit can Computer readable program instructions are executed to implement various aspects of the invention.
这里参照根据本发明实施例的方法、装置(系统)和计算机程序产品的流程图和/或框图描述了本发明的各个方面。应当理解,流程图和/或框图的每个方框以及流程图和/或框图中各方框的组合,都可以由计算机可读程序指令实现。Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
这些计算机可读程序指令可以提供给通用计算机、专用计算机或其它可编程数据处理装置的处理器,从而生产出一种机器,使得这些指令在通过计算机或其它可编程数据处理装置的处理器执行时,产生了实现流程图和/或框图中的一个或多个方框中规定的功能/动作的装置。也可以把这些计算机可读程序指令存储在计算机可读存储介质中,这些指令使得计算机、可编程数据处理装置和/或其他设备以特定方式工作,从而,存储有指令的计算机可读介质则包括一个制造品,其包括实现流程图和/或框图中的一个或多个方框中规定的功能/动作的各个方面的指令。These computer-readable program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus, thereby producing a machine that, when executed by the processor of the computer or other programmable data processing apparatus, , resulting in an apparatus that implements the functions/actions specified in one or more blocks in the flowchart and/or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium. These instructions cause the computer, programmable data processing device and/or other equipment to work in a specific manner. Therefore, the computer-readable medium storing the instructions includes An article of manufacture that includes instructions that implement aspects of the functions/acts specified in one or more blocks of the flowcharts and/or block diagrams.
也可以把计算机可读程序指令加载到计算机、其它可编程数据处理装置、或其它设备上,使得在计算机、其它可编程数据处理装置或其它设备上执行一系列操作步骤,以产生计算机实现的过程,从而使得在计算机、其它可编程数据处理装置、或其它设备上执行的指令实现流程图和/或框图中的一个或多个方框中规定的功能/动作。Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other equipment, causing a series of operating steps to be performed on the computer, other programmable data processing apparatus, or other equipment to produce a computer-implemented process , thereby causing instructions executed on a computer, other programmable data processing apparatus, or other equipment to implement the functions/actions specified in one or more blocks in the flowcharts and/or block diagrams.
附图中的流程图和框图显示了根据本发明的多个实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或指令的一部分,所述模块、程序段或指令的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。对于本领域技术人员来说公知的是,通过硬件方式实现、通过软件方式实现以及通过软件和硬件结合的方式实现都是等价的。The flowcharts and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions that contains one or more components for implementing the specified logical function(s). Executable instructions. In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two consecutive blocks may actually execute substantially in parallel, or they may sometimes execute in the reverse order, depending on the functionality involved. It will also be noted that each block of the block diagram and/or flowchart illustration, and combinations of blocks in the block diagram and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts. , or can be implemented using a combination of specialized hardware and computer instructions. It is well known to those skilled in the art that implementation through hardware, implementation through software, and implementation through a combination of software and hardware are all equivalent.
以上已经描述了本发明的各实施例,上述说明是示例性的,并非穷尽性的,并且也不限于所披露的各实施例。在不偏离所说明的各实施例的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。本文中所用术语的选择,旨在最好地解释各实施例的原理、实际应用或对市场中的技术的技术改进,或者使本技术领域的其它普通技术人员能理解本文披露的各实施例。本发明的范围由所附权利要求来限定。The embodiments of the present invention have been described above. The above description is illustrative, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the invention is defined by the appended claims.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311307911.4ACN117061393B (en) | 2023-10-10 | 2023-10-10 | Test system, test method and computer program product |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311307911.4ACN117061393B (en) | 2023-10-10 | 2023-10-10 | Test system, test method and computer program product |
| Publication Number | Publication Date |
|---|---|
| CN117061393A CN117061393A (en) | 2023-11-14 |
| CN117061393Btrue CN117061393B (en) | 2024-01-09 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311307911.4AActiveCN117061393B (en) | 2023-10-10 | 2023-10-10 | Test system, test method and computer program product |
| Country | Link |
|---|---|
| CN (1) | CN117061393B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103001835A (en)* | 2012-12-29 | 2013-03-27 | 电信科学技术第一研究所 | Network bandwidth test method and system based on data transmission |
| CN104539698A (en)* | 2014-12-29 | 2015-04-22 | 哈尔滨工业大学 | Multithreading socket synchronous communication access method based on delayed modification |
| CN109446242A (en)* | 2018-11-12 | 2019-03-08 | 郑州云海信息技术有限公司 | A kind of Delay querying method and device |
| CN110868747A (en)* | 2019-11-28 | 2020-03-06 | 上海商米科技集团股份有限公司 | Method for detecting delay and automatically switching multiple network modes |
| CN114237937A (en)* | 2021-12-17 | 2022-03-25 | 威创集团股份有限公司 | Multithreading data transmission method and device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20100070552A1 (en)* | 2008-09-12 | 2010-03-18 | Charles Austin Parker | Providing a Socket Connection between a Java Server and a Host Environment |
| US8341643B2 (en)* | 2010-03-29 | 2012-12-25 | International Business Machines Corporation | Protecting shared resources using shared memory and sockets |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103001835A (en)* | 2012-12-29 | 2013-03-27 | 电信科学技术第一研究所 | Network bandwidth test method and system based on data transmission |
| CN104539698A (en)* | 2014-12-29 | 2015-04-22 | 哈尔滨工业大学 | Multithreading socket synchronous communication access method based on delayed modification |
| CN109446242A (en)* | 2018-11-12 | 2019-03-08 | 郑州云海信息技术有限公司 | A kind of Delay querying method and device |
| CN110868747A (en)* | 2019-11-28 | 2020-03-06 | 上海商米科技集团股份有限公司 | Method for detecting delay and automatically switching multiple network modes |
| CN114237937A (en)* | 2021-12-17 | 2022-03-25 | 威创集团股份有限公司 | Multithreading data transmission method and device |
| Publication number | Publication date |
|---|---|
| CN117061393A (en) | 2023-11-14 |
| Publication | Publication Date | Title |
|---|---|---|
| US11249788B2 (en) | Cloud management platform, and virtual machine management method and system | |
| CN108924274B (en) | Domain name system DNS processing method and device, storage medium and electronic equipment | |
| CN113268308B (en) | Information processing method, device and storage medium | |
| CN111984395B (en) | Data migration method, system and computer readable storage medium | |
| CN109614147B (en) | A PHY register reading and writing method and device | |
| CN102316043B (en) | Port virtualization method, switch and communication system | |
| CN102752215B (en) | Processing method for VDP (vertical data processing) request messages and edge switch | |
| JP7510429B2 (en) | Cloud-enable legacy trusted network devices for zero-touch provisioning and enterprise-as-a-service | |
| CN111416723A (en) | Equipment management method and related equipment | |
| US9479438B2 (en) | Link aggregation based on virtual interfaces of VLANs | |
| WO2019109923A1 (en) | Message processing method and system, storage medium and electronic device | |
| CN114448805A (en) | Virtual network equipment, virtual overlay network and configuration and message transmission method | |
| CN114710549A (en) | A method, system and service node for dynamic management of network card in container platform | |
| CN113791792B (en) | Methods, devices and storage media for obtaining application call information | |
| CN114500467A (en) | A kind of address conflict detection method, address conflict detection device and electronic equipment | |
| CN104077187B (en) | For the method and system of the execution of scheduling application | |
| CN118921397B (en) | Communication connection method, device, storage device and program product | |
| CN110062396A (en) | A kind of method and device configuring base station | |
| CN108306757B (en) | Programmable data plane virtual layer construction method and storage medium | |
| CN117061393B (en) | Test system, test method and computer program product | |
| WO2021175105A1 (en) | Connection method and apparatus, device, and storage medium | |
| US20240056391A1 (en) | Communication method, apparatus, device, and system, and computer-readable storage medium | |
| WO2020221033A1 (en) | Method for managing remote storage device by means of management device | |
| WO2023092504A1 (en) | Subscription control method and apparatus, and computer device and storage medium | |
| CN116781780A (en) | Request processing method, device, server and storage medium |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |