A kind of method of testing transmission control protocol client
Technical field
The present invention relates to the ethernet test technology, refer to the method for a kind of testing transmission control protocol (TCP) client especially.
Background technology
As everyone knows, TCP provides a kind of connection-oriented byte stream service, and this just means two TCP application entities, between TCP server and TCP client, before interaction data each other, must set up a TCP earlier and connect, set up TCP and connect and comprise three processes:
1) request end is commonly referred to client, and send one and comprise the TCP message of (SYN) sign synchronously, i.e. SYN message, the SYN message indicates the port of server and the initial TCP sequence number that TCP connects;
2) server will return a confirmation of synchronization (SYN+ACK) message after receiving the SYN message of client, and the request of expression client is accepted, and simultaneously the TCP sequence number is added one;
3) client is also returned an affirmation (ACK) message and is given server end, equally TCP sequence number is added one.
So just having finished a TCP connects.
In order to come the test tcp application entity by the upper layer application protocol of test tcp, TCP between the testing tool that must at first set up measurand and be used for measurand is tested connects, such as, want the test tcp client, measurand is exactly the TCP client so, testing tool then is the TCP server that comes the emulation of emulation TCP server with emulation tool, sets up TCP and be connected between TCP client and testing tool; Want the test tcp server, measurand is exactly the TCP server so, and testing tool then is the TCP client of coming the emulation of emulation TCP client with emulation tool, sets up TCP and be connected between TCP server and testing tool; Utilize the TCP that sets up to connect then,, reach test measurand by the data interaction between the upper layer application protocol of testing tool and measurand is handled.
Generally, a TCP server is connected with a plurality of TCP clients simultaneously, handles the request from different TCP clients respectively.For each TCP client, clear and definite linking objective is arranged, i.e. TCP server, so, when the test tcp server, the emulation of TCP client is realized easily, can adopt the explosion command in the Tool Command Language (TCL) at present, as indicating the IP address of TCP client and the IP address and the port numbers of port numbers and TCP server, can on connecting, this initiate the TCP connection requests to the TCP server with the opench order.
And when the test tcp client, concerning the TCP server, because which TCP client the TCP server need constantly inquire about the TCP request from, and need connect the TCP that sets up and safeguard, therefore, in order to finish test, then cumbersome to the emulation of TCP server to the TCP client.
Fig. 1 is the flow chart of prior art test tcp client, as can be seen from the figure, mainly comprises two steps:
Step 10: in measurand, i.e. TCP client and testing tool are set up TCP and are connected and this connection is safeguarded between the TCP server of i.e. emulation.
Step 11: be connected mutual and deal with data between measurand and the testing tool by TCP, to reach test to the TCP client.
In the above-mentioned steps, when the test tcp client, interface is set up in TCP customer end adopted TCL Programming with Pascal Language, utilize the opench order as mentioned above, indicate the IP address of TCP client and the IP address and the port numbers of port numbers and TCP server, can on connecting, this initiate the TCP connection requests to the TCP server, if connecting, sets up successfully TCP, then the TCP server returns interface channel number and gives the TCP client, so just can pass through this interface channel transfer data packets number between TCP client and TCP server.
And by the emulation of testing tool to the TCP server, method commonly used at present is to utilize socket (socket) establishment function and TCL time to drive the order cooperation to realize:
At first, create a server end socket port, indicate tcp server port.For example: socket-server accept $port , $port represents the port numbers of the socket port that creates;
Then, utilize TCL language passage access time to drive order and monitor the good server end socket port of foundation, inquire about which TCP client with this and set up the TCP connection requests or need interaction data.For example: fileevent $sock readable[list readmsg $sock];
At last, in the processing of reading to realize in the message readmsg function application layer of TCP client of TCL, to reach test to the TCP client.Here, with test short message point-to-point (SMPP) agreement is that example illustrates this processing procedure, after TCP connection foundation is finished, test SMPP agreement establishment of connection process is: the reception for test SMPP agreement connects, the TCP client sends to connect and receives message bind-receiver, and the TCP server correctly returns to connect and receives response message bind-receiver-resp; Transmission for test SMPP agreement connects, and the TCP client sends to connect and sends message bind-transmitter, and the TCP server correctly returns to connect and sends response message bind-transmitter-resp.Above-mentioned reciprocal process promptly is to reach process to the test of measurand by interaction data between testing tool and the measurand; In receiving connection and transmission is connected, the TCP client all can constantly send heartbeat detection message enquire-link, and the TCP server correctly returns heartbeat detection response message enquire-link-resp, reaches the maintenance that TCP is connected with this.At above-mentioned access phase, keep operating condition in order to guarantee the TCP server, the time loop command vwait that can utilize the TCL language to wait for that variable changes constantly calls the heartbeat detection program and realizes.
Above-mentioned prior art is to the method for testing of TCP client, directly sets up TCP is connected between TCP client and emulation tool owing to adopt, and test upper layer application protocol on this TCP connects, and brought certain difficulty to the emulation of TCP server.The emulation of TCP server is to utilize the TCL high-level language to realize fully, therefore set up with upper layer application protocol between be connected after, the heartbeat detection Message Processing is generally comparatively frequent, and is to too much calling of bottom programs such as heartbeat detection program, bigger to the executing efficiency influence; In addition, to the emulation of TCP server, because TCL itself lacks the function that message is edited, sends, handled, actual test job is very loaded down with trivial details, and workload is very big.
Summary of the invention
In view of this, main purpose of the present invention is to provide a kind of method of testing transmission control protocol client, and this method can reduce the emulation difficulty to the TCP server, improves executing efficiency, thereby make the test upper layer application protocol more efficient, simplify test job.
For achieving the above object, technical scheme of the present invention specifically is achieved in that
A kind of method of testing transmission control protocol TCP client is created the testing tool and the TCP transponder that are used for emulation TCP server, and this method may further comprise the steps:
A. set up respectively that TCP client to be tested is connected with TCP between the TCP transponder and testing tool is connected with TCP between the TCP transponder;
The TCP that the utilization of B.TCP transponder is set up connects, and receives the packet from TCP client and testing tool respectively, and leaves the packet that receives in different buffer area;
C. connect by the TCP that sets up, the packet that the TCP transponder will leave different buffer areas in is transmitted to described TCP client and testing tool, realizes the test process that data interaction is handled between TCP client and the testing tool.
The method of described establishment TCP transponder is: utilize the language of supporting the socket programming,
Set up two socket socket ports respectively, one of them socket port be used for and described TCP client between connect, another socket port be used for and described testing tool between connect;
Set up two different buffer areas respectively, one of them buffer area is used to store the packet from described TCP client, and another buffer area is used to store the packet from described testing tool;
Set up two forwarding functions that are used for transmitting described two different buffer area packets respectively.
Among the step C, the method for the packet of different buffer areas is left in described forwarding in: described TCP transponder utilizes described forwarding function, and the packet from testing tool that leaves in first buffer area is transmitted to described TCP client; And/or the packet from described TCP client that will leave in second buffer area is transmitted to described testing tool.
The language of described support socket programming is the C language.
The method of described establishment testing tool is: utilize have to message edit, the professional test instrument of transmission and processing capacity, the test connectivity port of creating described testing tool, this test connectivity port be used for and described TCP transponder between connect;
The testing tool of described establishment utilizes the editting function of described professional test instrument, editor and load application layer message;
The testing tool of described establishment utilizes the transmission and the processing capacity of described professional test instrument, and reception and response are from the packet of described TCP transponder.
Described professional test instrument is that integrated test tools ITT or tree are shown in conjunction with notation TTCN instrument.
In steps A, the method that TCP is connected between the described TCP of foundation client and the TCP transponder is: adopt the TCL Programming with Pascal Language to connect.
Described testing tool is the TCP server of emulation.
As seen from the above technical solution, the present invention is a kind of in measurand, and promptly TCP client and testing tool between the TCP server of i.e. emulation, are set up the TCP connection and transmitted packet by the TCP transponder, realize the method to the test of TCP client.Wherein, utilize TCL language tool in the prior art to be fit to the characteristics of client, set up being connected of TCP client and TCP transponder with the TCL Programming with Pascal Language; With the TCP server of emulation as a TCP client, utilize have to message edit, the professional test instrument of transmission and processing capacity, as integrated test tools (ITT) or tree table in conjunction with notation (TTCN) set up with the TCP transponder between be connected; And the TCP transponder adopt to be supported the socket programming, can efficiently be called the programming language of bottom program, realizes the forwarding of packet between the TCP server of TCP client and emulation as the C language.The inventive method has reduced the emulation difficulty to the TCP server, has improved executing efficiency, thereby makes test tcp client upper layer application protocol more efficiently, has simplified test job.
Description of drawings
Fig. 1 is the flow chart of prior art test tcp client;
Fig. 2 is the flow chart of test tcp client of the present invention.
Embodiment
Core concept of the present invention is: set up measurand by the TCP transponder, be TCP client and testing tool, be that TCP between the TCP server of emulation connects, and forwarding packet, to be reduced to the emulation that is equivalent to the TCP client to the emulation of TCP server, simply and efficiently realize test the TCP client.
For making purpose of the present invention, technical scheme and advantage clearer, below with reference to the accompanying drawing preferred embodiment that develops simultaneously, the present invention is described in more detail.
Fig. 2 is the flow chart of test tcp client of the present invention, and measurand is the TCP client, and testing tool is the TCP server of emulation, may further comprise the steps:
Step 20a: set up between measurand and TCP transponder that TCP is connected and this connection is safeguarded.
In this step, the TCP client can adopt the TCL Programming with Pascal Language to set up interface, as utilize opench to order, indicate the IP address of TCP client and the IP address and the port numbers of port numbers and TCP transponder, can on connecting, this initiate the TCP connection requests to the TCP transponder, if TCP connects and to set up successfully, then the TCP transponder returns interface channel number to the TCP client, so just can pass through this interface channel number pairing passage transfer data packets between TCP client and TCP transponder.The maintenance here is the maintenance of single port to single port, need not to monitor, and is more simple, efficient.
Step 20b: set up between testing tool and TCP transponder that TCP is connected and this connection is safeguarded.
In this step, because the existence of TCP transponder, for the TCP transponder, the TCP server just is equivalent to a client, and this moment, the Correspondent Node of TCP server was determined, was exactly the TCP transponder.Like this, when the TCP server is carried out emulation, do not need to be provided with the time loop command port is constantly monitored, can improve simulation efficiency, make simultaneously the maintenance that TCP is connected become simply, efficiently yet the TCP server.
Among the present invention, can adopt have to message edit, the professional test instrument of transmission and processing capacity comes emulation TCP server, as ITT instrument or TTCN instrument.Here to test the short message service center (SMC) of SMPP agreement, adopting ITT emulation TCP server is example, be achieved in that specifically (1) create a test connectivity port with the TCP transponder, can indicate the IP address of TCP transponder with the opench order, can on this connects, initiate the TCP connection requests to the TCP server; (2) utilize the message editor procedure of ITT to finish the application layer messages editing and load, as loadmsg-msgfile bind_recv $msgpath, Qi Zhong $msgpath is the path of the edit messages preset; (3) utilize the transmission of ITT and processing capacity to receive and response from each bar message of TCP transponder.
Illustrate a bit do not have absolute sequencing between above-mentioned steps 20a and step 20b.
Step 21a: be connected interactive application layer data between measurand and the TCP transponder by TCP.
Step 21b: be connected interactive application layer data between TCP transponder and the testing tool by TCP.
Illustrate a bit do not have absolute sequencing between above-mentioned steps 21a and step 21b.
Step 22:TCP transponder is transmitted the data of interaction process between measurand and the testing tool, to reach the test of testing tool to measurand.
In above-mentioned steps, the TCP transponder is a language that adopt to support the socket programming, as the C Programming with Pascal Language finish respectively and TCP client and TCP server between data interaction, specifically be achieved in that
(1) in the TCP transponder, set up two socket ports respectively, one of them is used to connect TCP transponder and TCP client, and another is used to connect TCP transponder and TCP server, such as:
The socket that sets up TCP server and TCP transponder is connected, as:
ittsock=socket(AF_INET,SOCK_STREAM,0);
Set up the SMC of measurand TCP client and the socket of TCP transponder and be connected, as: smcsock=socket (AF_INET, SOCK_STREAM, 0);
(2) content record in will being connected from the socket of TCP client and TCP server respectively is at buffering area,
Define 2 buffering areas, as char ittbuffer[4096], smcbuffer[4096], and buffer size is set is 4096.Ittbuffer[4096 wherein] buffer area 1 of expression is used for depositing the packet that receives from the TCP server, smcbuffer[4096] buffer area 2 of expression is used for depositing the packet that receives from the SMC of TCP client;
The packet that will receive will connecting from the socket of TCP server is placed among the buffer area ittbuffer, as: recv (itttalk, ittbuffer, 4096,0); Wherein, itttalk is the socket port numbers of buffer area 1, ittbuffer is the address of buffer area 1, the 4096th, the size of buffer area 1, itttalk is ittsock=socket (AF_INET, SOCK_STREAM, 0) return value, this return value are the length of the actual data that read from socket.
The packet that will receive will connecting from the socket of the SMC of TCP client leaves among the buffer area smcbuffer, as: recv (smctalk, smcbuffer, 4096,0); Wherein, smctalk is the socket port numbers of buffer area 2, smcbuffer is the address of buffer area 2, the 4096th, the size of buffer area 2, smctalk is smcsock=socket (AF_INET, SOCK_STREAM, 0) return value, this return value are the length of the actual data that read from socket connects.
(3) packet between realization TCP server and the TCP client is transmitted.
What be used for leaving in buffer area 1 is transmitted to the forwarding function of the SMC of TCP client from TCP data in server bag, as: send (smctalk, ittbuffer, ittreadlength, 0);
The packet from the SMC of TCP client that is used for leaving in buffer area 2 is transmitted to the forwarding function of TCP server, as: send (itttalk, smcbuffer, smcreadlength, 0), wherein, smcreadlength is recv (smctalk, smcbuffer, 4096,0) return value.
From top description, as can be seen, the present invention is the method for testing of TCP client and the difference of prior art maximum, and the TCP client that needs test directly with between the testing tool does not set up that TCP is connected and interaction data, but by the forwarding of TCP transponder; Equally, testing tool does not directly set up with the TCP client that TCP is connected and interaction data yet, is to transmit by the TCP transponder yet; Handle like this, testing tool no longer needs to adopt the time loop command to come continuous listening port, because the link of testing tool is the TCP transponder of determining, reduced the workload of testing tool, thereby improved the simulation efficiency of TCP server, and then improved the operating efficiency of test tcp client.
In addition, among the present invention, the TCP transponder adopts the language of supporting the Socket programming, as C Programming with Pascal Language finish and TCP client and TCP server between mutual, given full play to the high efficiency of C language to the bottom routine call, also make the protocol test program write and execution become simple easily.
The above is preferred embodiment of the present invention only, is not to be used to limit protection scope of the present invention.