A kind of TCP connects the implementation method of Hot Spare
Technical field
The present invention relates to network communication technology field, be specifically related to the implementation method that a kind of TCP connects Hot Spare.
Background technology
TCP (Transmission Control Protocol, transmission control protocol) is that current network world uses transport layer protocol the most general, and agreement popular at present such as FTP, HTTP etc. realize based on TCP.Along with router use scenes becomes increasingly complex, more and more diversified, the service based on TCP technology is proposed to the requirement of higher standard, therefore TCP high reliability is arisen at the historic moment.
TCP NSR (Non-Stop Routing) is one of implementation realizing TCP high reliability, refers to as distributed apparatus provides the mechanism of Hot Spare, also known as many Host Technology.For distributed apparatus is equipped with two pieces or polylith main control unit, one piece is primary dish (hereinafter referred to as master), other is dish for subsequent use (hereinafter referred to as standby dish), when master breaks down, system carries out masterslave switchover automatically, seamless by standby dish, to take over master smoothly work.
As shown in Figure 1, set up a TCP between Node A and Node B to connect.Node B is a distributed equipment, has master and standby dish.Complete this TCP by master during normal work to connect, master goes wrong and to be taken over by standby dish.This simply backs up, encounter a difficulty when using Transmission Control Protocol: because standby dish cannot know that on master, TCP connects running status, data cached and used sequence number, must re-establish a new TCP and connect, and this will cause serious problem when switching.Such as Node B and Node A are two routers, between run BGP Routing Protocol, once rebuild TCP, will exchanging routing information again, therefore produce route oscillation.
For solving this problem, current industry adopts two schemes:
In the first scheme as shown in Figure 2, realized the backup of TCP by amendment tcp state machine.ESTAB in figure is stable state intrinsic in tcp state machine, and this programme was increasing SYN RCVD* and SYN SENT* two tcp states newly before ESTAB.Rec ACK in each status change, Rec SYNC, Send SYN, Rec SYN, ACK, Send ACK, Need Synchronization are message format, this scheme can solve the difficult point of TCP backup, but fatal problem is, the program is only applicable to the router of same manufacturer, these two states of ICP/IP protocol stack not perception SYN RCVD* and SYNSENT* on other manufacturer's routers, thus cause dropping packets.
In first scheme as shown in Figure 3, be that packet message master being received or sends all copies a coiling to standby, if master and standby dish adopt identical algorithms, then the tcp state that can be consistent.And in this programme, master and standby dish are independently, although algorithm is consistent, the dispatching sequence of in fact each process may there are differences, and accomplish completely the same very difficult.In actual use, also dropping packets can be caused.
Summary of the invention
For the defect existed in prior art, the object of the present invention is to provide a kind of TCP to connect the implementation method of Hot Spare, ensure that TCP connects masterslave switchover not disconnection, prevent message dropping.
For reaching above object, the technical scheme that the present invention takes is: a kind of TCP connects the implementation method of Hot Spare, based on transmitting terminal and receiving terminal, transmitting terminal and receiving terminal include master and standby dish, master and standby dish include ICP/IP protocol stack and packet buffer queue, ICP/IP protocol stack comprises tcp module again, described implementation method comprises: send message for transmitting terminal, after this end tcp module process, before passing to network layer handles, message is backuped to standby dish, after receiving the confirmation message of standby dish reply, continue process message and send to receiving terminal; Receive message for receiving terminal, after link layer and network layer handles, before passing to transport layer process, message is backuped to standby dish, after receiving the confirmation message of replying for dish, master just continues to process message, and by message up sending to destination applications.
On the basis of technique scheme, the application program of transmitting terminal creates socket controll block, and relevant socket controll block is backuped to standby dish by master ICP/IP protocol stack, and standby dish creates corresponding socket controll block.
On the basis of technique scheme, at transmitting terminal, being blocked in after the application program transmission message of master sends in function, master ICP/IP protocol stack receives message, after calling tcp module process, before sending to network layer, the beginning sequence number of message, message and end sequence number are backuped to the standby dish of transmitting terminal, after standby dish receives the message of master backup, be cached in packet buffer queue, and sending confirmation message to master, after master receives the confirmation message of standby dish, notice is blocked in the application program sent in function and returns; Master continues to call network layer and link layer relevant treatment function, sends message to receiving terminal by normal flow.
On the basis of technique scheme, for transmitting terminal, when master has message not send, then masterslave switchover occurs, standby dish upgrades to master, is reorganized by the message in packet buffer queue and sends.
On the basis of technique scheme, when the user of receiving terminal creates socket controll block, relevant socket controll block is backuped to standby dish by master ICP/IP protocol stack, and standby dish creates corresponding socket controll block.
On the basis of technique scheme, receiving terminal receives message by the physical interface of its master ICP/IP protocol stack, message is after link layer and network layer handles, when being passed to master transport layer entrance, this message of master tcp module buffer memory is in buffer queue, and being pass-through to the tcp module of standby dish, standby dish replys confirmation message to master after receiving message; After master tcp module receives confirmation message, from the packet buffer queue of master, find out corresponding message, reply ACK message to transmitting terminal after treatment, and the message sent by transmitting terminal received is uploaded to master application program.
On the basis of technique scheme, described transmitting terminal or receiving terminal, its standby dish inserts moment, master detects that standby dish is reached the standard grade, if have buffer memory message in the TCP buffering area of master, message up sending to master application program, and is notified that master application program starts debit to demarcation by master tcp module, and master application program carries out related data backup.
On the basis of technique scheme, described master application program is carried out related data backup and is specially, and master application notification master tcp module carries out the demarcation of sending direction, and related data is backuped to the tcp module of standby dish by tcp module.
Beneficial effect of the present invention is: tcp state information is backuped to standby dish from master, the message simultaneously connected by this TCP and sequence number backup to standby dish together, when master breaks down, system carries out masterslave switchover automatically, after switching, message based on backup does smoothing processing, seamless by standby dish, to take over master smoothly work, thus ensures that TCP connects not disconnection.
Accompanying drawing explanation
Fig. 1 is binode Communication Graph in background technology;
Fig. 2 is the first scheme schematic diagram in background technology;
Fig. 3 is first scheme schematic diagram in background technology;
Fig. 4 is the schematic diagram that TCP of the present invention connects the implementation method of Hot Spare;
Fig. 5 is that the embodiment of the present invention sends Message processing flow chart;
Fig. 6 is that the embodiment of the present invention receives Message processing flow chart.
Embodiment
Below in conjunction with drawings and Examples, the present invention is described in further detail.
TCP of the present invention connects the implementation method of Hot Spare, and based on transmitting terminal and receiving terminal, transmitting terminal and receiving terminal include master and standby dish, as shown in Figure 4, is master and the standby dish of transmitting terminal or receiving terminal.Master and standby dish include BGP (Border Gateway Protocol, Border Gateway Protocol) module, ICP/IP protocol stack and packet buffer queue, BGP module is the APP (application program) that an interface by sokcet controll block uses TCP service, ICP/IP protocol stack comprises socket controll block, tcp module (transport layer) and IP module (network layer), jointly externally provides service.Described implementation method comprises: send message for transmitting terminal, after this end tcp module process, before passing to IP module (network layer) process, message is backuped to standby dish, after receiving the confirmation message of standby dish reply, continue process message and also send to receiving terminal; Receive message for receiving terminal, after link layer and network layer handles, before passing to transport layer process, message is backuped to standby dish, after receiving the confirmation message of replying for dish, master just continues to process message, and by message up sending to destination applications.
As shown in Figure 5, the concrete handling process of described transmitting terminal transmission message is as follows:
S101. the APP of transmitting terminal creates socket controll block, and relevant socket controll block is backuped to standby dish by the ICP/IP protocol stack of master, and standby dish creates corresponding socket controll block.
S102.APP is blocked in after sending message and sends in function, and (as lock mechanism between process), does not return.
S103. master ICP/IP protocol stack receives the message that APP sends, calling tcp module is correlated with after api function process, before sending to network layer, the beginning sequence number of message, message and end sequence number are backuped to the standby dish of transmitting terminal, and subsequent packet backups to standby dish together with the sequence number of message, wait for standby dish confirmation message.
S104. after standby dish receives the message of master backup, be cached in its packet buffer queue, and send confirmation message to master, simultaneously by the APP of the message up sending of these buffer memorys to standby dish.
S105., after master receives the confirmation message of standby dish, notice is blocked in the APP sent in function, and APP returns.
S106., after master continues to call network layer and link layer relevant treatment function, message is sent to receiving terminal by normal flow.When master has message not send, then masterslave switchover occurs, standby dish upgrades to master, according to the message in packet buffer queue, reorganizes message and sends, ensure that receiving terminal receives continuous print message.
As shown in Figure 6, receiving terminal reception Message processing flow process is as follows:
S201. when the user of receiving terminal creates socket controll block, relevant socket controll block is backuped to standby dish by master ICP/IP protocol stack, and standby dish creates corresponding socket controll block.
S202. when receiving terminal receives message, from the physical interface packet receiving of master ICP/IP protocol stack, standby dish interface does not participate in transmitting-receiving bag.
S203. the message received is after link layer and network layer handles, and when being passed to transport layer TCP packet receiving process, this message of master tcp module buffer memory in buffer queue, and is pass-through to the tcp module of standby dish, waits for standby dish tcp module confirmation message.
S204., after standby dish tcp module receives the message that master sends, reply confirmation message to master, the message that tcp module process simultaneously receives, and on deliver to standby dish APP, standby dish tcp module deletes the message of buffer memory.
S205. after master tcp module receives the confirmation message of standby dish, from the packet buffer queue of master, find out corresponding message, after relevant treatment, reply ACK message to transmitting terminal, and being sent by transmitting terminal of receiving be uploaded to master APP.
Before the message of transmitting terminal or receiving terminal is switched, need to carry out message demarcation, be specially: at transmitting terminal or receiving terminal, its standby dish inserts moment, and master detects that standby dish is reached the standard grade, and starts to enter batch standby.If have buffer memory message in the TCP buffering area of master, message up sending to master APP, and is notified that master APP starts debit to demarcation by master tcp module.Master APP carries out related data backup, and master APP notifies that master tcp module carries out the demarcation of sending direction, and related data is backuped to the tcp module of standby dish by tcp module.
The present invention is not limited to above-mentioned execution mode, and for those skilled in the art, under the premise without departing from the principles of the invention, can also make some improvements and modifications, these improvements and modifications are also considered as within protection scope of the present invention.The content be not described in detail in this specification belongs to the known prior art of professional and technical personnel in the field.