201251377 六、發明說明: 【發明所屬之技術領域】 [0001]本發明涉及一種網卡資料傳輸方法及系統。 [先前技術] 目前的測試中’網卡傳輪封包的大致機制如下:在源 端主機Linux作業系統的應用層創建通訊端傳輸封包,該 封包通過0SI 7層模型自上而下層層轉發,到達Linux作 業系統的kernei層中的資料連結層;在資料連結層網卡 的驅動程式將該封包寫入網卡共用的訂ite buffer中, 並對訂ite-buffer中的封包進行分割,在物理層將分割 〇 後封包以序列的形式傳送到網路中去,網路中的目的主 機將根據封包中的目的位址來接受屬於自己的封包。 闕朗試方法雖然能達到傳輸資料,及驗證物理鏈路的連 通性的目的,但是在工廢測試專案中,測試的目的往往 只是驗證物_路的連通性和資财網卡之間傳輸的峰 值’所以不需要資料通過完整的OSI七層。而在0SI七層 模型中,封包從應用居3 丁 & 層往下傳輸資料的過程中,根據相 〇 關協定與_ ’封包每經過—層’都要在頭部做相關封 ◎ 裝的動作才往下傳輸’耗時相當長,成為封包傳輸的一 大瓶頸,且無法得到物理層的資料在網卡之間傳輸的峰 值,再者,封包從Llnux作業系統的應用層傳到以顧作 業系統的1^1161層以及從Li_作業系統的kernel層返 回報告給Li_作業系統的應用層的過程令,也需要耗費 掉回應的傳輸時間,這也就成了封包傳送的另一瓶頸。 假設Linux作業系統的應用層要發送1〇〇〇個封包,如果 100121788 表單編號A0101 第4頁/共27頁 1002036878-0 201251377 用常規的方法做這件事情,Linux作業系統的應用層需要 與Linux作業系統的kernel層進行1 000次的溝通,這是 非常耗時的事情;另外,傳送給目的網卡的資料由於從 上至下的傳輸,資料包有丟失的可能性,存在穩定性的 隱患,有時無法正確回應給源端主機Linux作業系統的應 用層,從而無法有效判斷資料是否準確傳送到目的地。 【發明内容】 [0004] ❹ [0005]201251377 VI. Description of the Invention: [Technical Field of the Invention] [0001] The present invention relates to a network card data transmission method and system. [Prior Art] In the current test, the general mechanism of the NIC transmission packet is as follows: The application layer of the source host Linux operating system creates a communication terminal transmission packet, and the packet is forwarded from the top to the bottom layer through the 0SI 7 layer model to reach Linux. The data link layer in the kernei layer of the operating system; the driver in the data link layer network card writes the packet into the subscription ite buffer shared by the network card, and divides the packet in the subscribed ite-buffer, and divides the packet in the physical layer. The post-packet is transmitted to the network in the form of a sequence, and the destination host in the network will accept its own packet according to the destination address in the packet. Although the test method can achieve the purpose of transmitting data and verifying the connectivity of the physical link, in the work waste test project, the purpose of the test is often only to verify the connectivity between the object and the network card. 'So no need to pass the complete OSI seven layers. In the 0SI seven-layer model, the packet is transmitted from the application to the third layer and the layer is down. In accordance with the relevant agreement, the _ 'package per pass-layer' must be related in the head. The action is only transmitted down. It takes a long time to become a bottleneck for packet transmission, and it cannot obtain the peak value of the physical layer data transmission between the network cards. Furthermore, the packet is transmitted from the application layer of the Llnux operating system to the homework. The process of the system's 1^1161 layer and the return from the kernel layer of the Li_ operating system to the application layer of the Li_ operating system also requires the transmission time of the response, which becomes another bottleneck for packet transmission. Assume that the application layer of the Linux operating system is to send 1 packet. If 100121788 Form No. A0101 Page 4 / Total 27 Page 1002036878-0 201251377 This is done in the usual way, the application layer of the Linux operating system needs to be Linux. The kernel layer of the operating system performs 1000 times of communication, which is very time consuming. In addition, the data transmitted to the destination network card has the possibility of loss due to the transmission from top to bottom, and there is a hidden danger of stability. Sometimes the application layer of the Linux operating system of the source host cannot be correctly responded, so that it is impossible to effectively determine whether the data is accurately transmitted to the destination. SUMMARY OF THE INVENTION [0004] ❹ [0005]
鑒於以上内容,有必要提供一種網卡資料傳輸方法及系 統,能夠將封包直接由Linux作業系統的應用層發送至資 料連結層,可準確、穩定、高效的進行網卡資料的傳輸 〇 所述網卡資料傳輸方法,應用於網卡的資料傳輸,該方 法包括以下步驟:設置步驟:在源端主機的Linux作業系 統的應用層設置用於發送的控制參數,並在源端主機的 Linux作業系統的kerne 1層定義與控制參數格式相同的 資料結構;封裝步驟:在所述應用層創建底層套接字, 並將控制參數、源端位址、目的位址及發送内容封裝至 封包中,所述源端位址為源端主機中第一網卡的MAC位址 ,所述目的位址為目的主機中第二網卡的MAC位址,所述 源端主機與目的主機通過網路連接;發送步驟:在源端 主機中將封包由所述應用層發送至所述kernel層中的資 料連結層;解析步驟:在資料連結層中解析封包,將要 發送的封包及控制參數進行分離,所述控制參數包括發 送參數、隨機設置參數、延時參數、回饋參數和調試參 數;管控步驟:在源端主機中根據分離出的控制參數管 100121788 表單編號A0101 第5頁/共27頁 1002036878-0 201251377 技封包的發送過程。 [0006] [0007] [0008] 所述網卡資料傳輸系統,運行於電腦中該系統包括: 汉置权、’’用於在源端主機的Unux作業系統的應用膚設 置用於發送的控制參數,並在源端主_unux作業系統 的kernel層定義與控制參數格式相同的資料結構;封裝 模組,用於在料細層_底層套龄,並將控制參 數、源端位址、目的位址及發送内容封裝至封包中,所 述源端位址為源端主機中第—網卡的MAC位址,所述目的 位址為目的主機中第二網卡的_位址,所述源端主機與 目的主機通過網路連接;發送模組,用於在源端主機中 將封包由所述應用層發送至所述kernel層中的資料連結 層,解析模組’用於在資料連結層中解析封包,將要發 送的封包及控制參數進行分離,所述控制參數包括發送 參數、隨機設置參數、延時參數、回饋參數和調試參數 ;管控模組,用於在源端主機中根據分離出的控制參數 管控封包的發送過程。 相較於習知技術’本發明所述之網卡資料傳輪方法及系 統,能夠將封包直接由LMuX作業系統的應用層發送至資 料連結層,益可減少Linux作業系統的應用層與Linux作 業系統的kernel層溝通的农數,可準確、穩定、高效的 進行網卡資料的傳輸。 【實施方式】 如圖1所示,係為本發明網肀資料傳輸系統較佳實施例之 100121788 架構圖。 網卡資料傳輸系統10運行於滹端主機1中,該源端主機1 --· ----- 第6頁/并27育 表單編號A0101 1002 [0009] 201251377 [0010] ο [0011] [0012] [0013] Ο 還包括第一網卡11,所述源端主機1通過網路2與目的主 機3連接,目的主機3中包含第二網卡30。所述網路2可以 是企業内部網(Intranet)或乙太網(Ethernet), 也可以是網際網路(Internet)或其他類型的通訊網路 所述第一網卡11和第二網卡30可内置於同一主機中,也 可分別位於不同主機中,通過網路2進行連接。本較佳實 施例以第一網卡11和第二網卡30位於不同主機中,通過 網路2進行連接為例進行介紹。 如圖2所示,係為本發明網卡資料傳輸系統較佳實施例之 功能模組圖》 所述網卡資料傳輸系統10包括設置模組1〇〇、封裝模組 101、發送模組102、解析模組103、管控模組1〇4。 所述設置模組_用於在源端主機_inu_f系统的 應用層設置用於發送的控制參數,並在源端主似的 Unux作㈣㈣kefnel層械與控制參數格式相同的 資料結構。所述資料結構用來錢和解析應用層所設置 的控制參數。 [0014] 所述控制參數包括:發送參數、隨機設置參數、延時參 數、回饋參數和賴參數等。料發送參數用於設定投 遞封包的次數;所料機設置參_於在㈣封包的過 程中’進行封包的資料内容及長度的控制;所述延時參 數用於控祕送«間^㈣%她祕封包發送 失敗時,控㈣新料封包的錢;料戰 100121788 表單編號A0101 第7頁/共27頁 1002036878-0 201251377 封匕的發送過程中顯示的相關資訊的輸出,但此時需用 戶進行相關命令的輪入。 [0015] [0016] [0017] 如圖6所不’所述資料結構包含:Control、Dest Adless ' Source Address 、 Type/Length 、 Data , 所 述Control 中包含:Burst、Rand〇m、j)eiay、Retry、In view of the above, it is necessary to provide a network card data transmission method and system, which can directly send the packet from the application layer of the Linux operating system to the data link layer, and can accurately, stably and efficiently transmit the network card data, and the network card data transmission The method is applied to data transmission of a network card, and the method comprises the following steps: setting step: setting a control parameter for sending at an application layer of a Linux operating system of the source host, and kerne layer 1 of the Linux operating system of the source host Defining a data structure having the same format as the control parameter; encapsulating step: creating an underlying socket in the application layer, and encapsulating the control parameter, the source address, the destination address, and the sending content into the packet, where the source terminal The address is the MAC address of the first network card in the source host, the destination address is the MAC address of the second network card in the destination host, and the source host and the destination host are connected through the network; sending step: at the source end Sending, by the application layer, the packet to the data link layer in the kernel layer in the host; parsing step: parsing in the data link layer The packet separates the packet to be sent and the control parameter, and the control parameter includes a sending parameter, a random setting parameter, a delay parameter, a feedback parameter, and a debugging parameter. The control step is: according to the separated control parameter tube 100121788 form in the source host No. A0101 Page 5 of 27 1002036878-0 201251377 The sending process of the technology package. [0007] [0008] The network card data transmission system runs on a computer, and the system includes: a Han power, a 'control parameter for the application environment of the Unux operating system of the source host for sending And in the source layer of the main _unux operating system, the kernel structure defines the same data structure as the control parameter format; the encapsulation module is used for the seed layer _ bottom set age, and the control parameters, the source end address, the destination bit The address and the sending content are encapsulated into a packet, where the source address is the MAC address of the first network card in the source host, and the destination address is the _ address of the second network card in the destination host, and the source host And the destination host is connected through the network; the sending module is configured to send the packet from the application layer to the data link layer in the kernel layer in the source host, and the parsing module is configured to parse in the data link layer The packet separates the packet to be sent and the control parameter, and the control parameter includes a sending parameter, a random setting parameter, a delay parameter, a feedback parameter, and a debugging parameter. The control module is configured to be separated according to the control in the source host. The parameter is the process of sending the control packet. Compared with the prior art technology card transmission method and system of the present invention, the packet can be directly sent from the application layer of the LLuX operating system to the data link layer, thereby reducing the application layer of the Linux operating system and the Linux operating system. The number of farms communicated by the kernel layer can accurately, stably and efficiently transfer network card data. [Embodiment] As shown in FIG. 1, it is a 100121788 architecture diagram of a preferred embodiment of the network data transmission system of the present invention. The network card data transmission system 10 runs in the terminal host 1 , and the source host 1 --· ----- page 6 / 27 form number A0101 1002 [0009] 201251377 [0010] ο [0011] [0012 [0013] The first network card 11 is also included. The source host 1 is connected to the destination host 3 through the network 2, and the destination host 3 includes the second network card 30. The network 2 may be an intranet or an Ethernet, or may be an Internet or other type of communication network. The first network card 11 and the second network card 30 may be built in In the same host, they can also be located in different hosts and connected through network 2. In the preferred embodiment, the first network card 11 and the second network card 30 are located in different hosts, and the connection is performed through the network 2 as an example. As shown in FIG. 2, it is a functional module diagram of a preferred embodiment of the network card data transmission system of the present invention. The network card data transmission system 10 includes a setup module 1 , a package module 101 , a transmission module 102 , and an analysis The module 103 and the control module 1〇4. The setting module _ is configured to set a control parameter for sending at the application layer of the source host _inu_f system, and at the source end is similar to the Unux (4) (4) kefnel layer and the same data structure of the control parameter format. The data structure is used to money and parse the control parameters set by the application layer. [0014] The control parameters include: a sending parameter, a random setting parameter, a delay parameter, a feedback parameter, and a Lai parameter. The material sending parameter is used to set the number of times the delivery packet is sent; the material setting parameter is used to control the content and length of the data packet in the process of (4) packet; the delay parameter is used for secret control to send «间^(四)% of her When the secret packet fails to be sent, the money of the new material package is controlled (four); the material battle 100121788 Form No. A0101 Page 7 / Total 27 pages 1002036878-0 201251377 The output of the related information displayed during the transmission of the seal, but at this time the user needs to perform The rounding of related commands. [0017] [0017] The data structure as shown in FIG. 6 includes: Control, Dest Adless 'Source Address, Type/Length, Data, and the Control includes: Burst, Rand〇m, j) eiay , Retry,
Debug。資料結構中Control用於接收和解析應用層所設 置的控制參數’ Control中對應各項分別對應接收控制參 數中各參數,Burst對應發送參數,Random對應隨機設 置參數’ Delay對應延時參數,Retry對應回饋參數, Debug對應調試參數。所述pest Address用於接收封包 中目的位址,所述s〇urce Address用於接收封包中源端 位址,所述Type/Length用於接收封包的類型及長度, 所述Data用於接收封包内容。 在Linux作業系統中,所述kernel層也可稱為核心 内核層,實際對應的是作業系統中的.内核.,ker>n、 3 el層負 責與各種底層硬體溝通,各種適配器的驅動就是在 、 kernel層實現的。 所述封裝模組101用於在源端主機1的Linux作業系 應用層創建底層套接字’並將控制參數、源端饭址 的位址及發送内容封裝至封包中。所述源端位址為目Debug. In the data structure, Control is used to receive and parse the control parameters set by the application layer. The corresponding items in the Control respectively correspond to the parameters in the receiving control parameters, Burst corresponds to the sending parameters, Random corresponds to the random setting parameter 'Delay corresponding delay parameter, Retry corresponding feedback Parameters, Debug corresponds to the debugging parameters. The destination address is used to receive the destination address in the packet, the s〇urce address is used to receive the source address in the packet, the Type/Length is used to receive the type and length of the packet, and the Data is used to receive the packet. content. In the Linux operating system, the kernel layer can also be called the core kernel layer, and the actual counterpart is the kernel in the operating system. The ker>n, 3el layer is responsible for communicating with various underlying hardware, and the drivers of various adapters are Implemented in the kernel layer. The encapsulation module 101 is configured to create an underlying socket ’ at the Linux operating system application layer of the source host 1 and encapsulate the control parameters, the address of the source address, and the transmission content into the packet. The source address is
主機1中第一網卡11的MAC位址,所述目的位址A 畤目的主 機3中第二網卡30的MAC位址。 [0018] 底層套接字的格式為:int fd S0CK_RAW, IPPROTO.TCP);The MAC address of the first network card 11 in the host 1, and the destination address A is the MAC address of the second network card 30 in the host 3. [0018] The format of the underlying socket is: int fd S0CK_RAW, IPPROTO.TCP);
socket(PF packet 通過底層套接字 100121788 表單編號A0101 第8頁/共27頁 201251377 [0019] Ο [0020] [0021] Ο [0022] [0023] 第一網卡11 ’即通過操作底層套接字可以實現對第一網 卡11的控制。上述底層套接字格式中的S〇CK_RAW可以換 成SOCK一PACKET,換成s〇CK_PACKET之後的底層套接字 與原來為SOCK一RAW的底層套接字功能相同,但是綁定第 一網卡11的方式不同。 底層套接字可以實現封包直接由Linux作業系統的應用層 發送至資料連結層的目的,從而繞開〇Si七層模型中的前 五層,此五層為:應用層、表示層、會話層、傳輸層、 網路層。 所述發送模組102用於在源端主機1中將封包由l i nux作 業系統的應用層發送至Linux作業系統的kernel層中的 資料連結層。在内核即kernel層中,包括資料連結層、 物理層及第一網卡11的驅動程式。 如圖5所示,在Linux作業系統的應用層中進行封包的封 裝’通過底層套接字可以實現由Linux作業系統的應用層 直接發送至資料連結層,繞開0SI七層模型中的應用層、 表示層、會括層、傳輸層和網路層這五層。在kernei層 中包括資料連結層及物理層。 所述解析模組1〇3用於在源端主機1的資料連結層中解析 封包’將要發送的封包及控制參數進行分離。 在kerne 1層中的資料連結層接收到來自[i nux作業系統 的應用層的封包後,根據所定義的資料結構對封包的内 容進行解析,分離出要發送的封包和控制參數。在資料 連結層第—網卡11的驅動程式將分離出的要發送的封包 100121788 表單編號A0101 第9頁/共27頁 1002036878-0 201251377 寫入第一網卡11的write_buffer*。 [0024] 所述管控模組104用於在源端主機1中根據分離出的控制 參數管控封包的發送過程。 [0025] 所述管控模組104包括以下子模組:發送單元一 105、判 斷單元106、計數單元一 107、溝通單元108、計數單元 二 109。 [0026] 所述發送單元一 1 05用於將源端主機1中所分割的封包發 送至目的主機3,封包的發送時間間隔由延時參數決定。 [0027] 在資料連結層第一網卡11的驅動程式將wri te_buf f er中 的封包進行分割,在物理層將分割後的封包傳送至網路2 中,經網路2發送至目的主機3,目的主機3將根據封包中 的目的位址來接受屬於自己的封包。在將write_buffer 中的封包進行分割的過程中,可由隨機設置參數對要分 割的封包的資料内容及長度進行控制。 [0028] 所述判斷單元106用於在源端主機1的Linux作業系統的 kernel層中,對目的主機3的返回值進行判斷,從而判斷 封包是否發送成功。 [0029] 當封包發送成功時,目的主機3將返回一個正值至源端主 機1的kernel層,而當封包發送失敗時,目的主機3將返 回一個負值至源端主機1的kernel層。 [0030] 所述計數單元一 107用於當封包發送成功時,統計發送的 封包成功投遞的次數,判斷封包成功投遞的次數是否達 到Μ次。所述Μ值,為發送參數設定的封包投遞的次數。 100121788 表單編號Α0101 第10頁/共27頁 1002 201251377 [0031] 所述計數單元二109用於當封包發送失敗時,統計封包重 [0032] 新發送的次數,判斷重新發送的次數是否已達到N次。所 述N值為回饋參數所設置的,封包發送失敗時,重新發送 封包的次數。 所述溝通單元108用於當封包成功投遞的次數達到Μ次時 ,或封包重新發送Ν次依然失敗後,源端主機1的Linux作 業系統的kerne 1層與Linux作業系統的應用層進行溝通 〇 [0033] Linux作業系統的kernel層與Linux作業系統的應用層 的溝通時,返回封包發送完成時相關資訊至Linux作業系 統的應用層,以供用戶查看。當失敗時,顯示的資訊為 ,如成功發送多少個封包、在發送哪個封包時失敗等。 當成功時,顯示的資訊為,如成功發送多少個封包、總 共耗時多少等。各個封包的發送過程中對應的返回值及 各個封包發送過程中的相關資訊顯示,由調試參數控制 輸出,但此時需用戶進行相關命令的輸入。 Ο [0034] 如圖3所示,係為本發明網卡資料傳輸方法較佳實施例之 流程圖。 [0035] 步驟S100,所述設置模組100在源端主機1的Linux作業 系統的應用層設置用於發送的控制參數,並在源端主機1 的Linux作業系統的kernel層定義與控制參數格式相同 的資料結構。所述資料結構用來接收和解析應用層所設 置的控制參數。 [0036] 步驟S101,所述封裝模組101在源端主機1的Linux作業 100121788 表單編號A0101 第11頁/共27頁 1002036878-0 201251377 系統的應用層創建底層套接字,並將控制參數、源端位 址、目的位址及發送内容封裝至封包中。所述源端位址 為源端主機1中第一網卡11的MAC位址,所述目的位址為 目的主機3中第二網卡30的MAC位址。 [0037] 底層套接字的格式為:int fd = socket(PF_PACKET, S0CK_RAW,IPPR0T0_TCP);通過底層套接字可以綁定 第一網卡11,即通過操作底層套接字可以實現對第一網 卡11的控制。上述底層套接字格式中的S0CK_RAW可以換 成SOCK_PACKET,換成SOCK_PACKET之後的底層套接字 與原來為S0CK_RAW的底層套接字功能相同,但是綁定第 一網卡11的方式不同。 [0038] 底層套接字可以實現封包直接由Linux作業系統的應用層 發送至資料連結層的目的,從而繞開0SI七層模型中的前 五層,此五層為:應用層、表示層、會話層、傳輸層、 網路層。 [0039] 步驟S102,所述發送模組1〇2在源端主機1中將封包由 Linux作業系統的應用層發送至Linux作業系統的 kernel層中的資料連結層。在kernel層中,包括資料連 結層、物理層及第一網卡11的驅動程式。 [0040] 如圖5所示,在Linux作業系統的應用層中進行封包的封 裝,通過底層套接字可以實現由Linux作業系統的應用層 直接發送至資料連結層’繞開〇SI七層模型中的應用層、 表示層、會話廣、傳輸層和網路層這五層。在kernel層 中包括資料連結層及物理層。 100121788 表單編號A0101 第12頁/共27頁 1002036878-0 201251377 [0041] 步驟S103,所述解析模組103在源端主機1的資料連結層 中解析封包,將要發送的封包及控制參數進行分離。 [0042] 在kernel層中的資料連結層接收到來自Linux作業系統 的應用層的封包後,根據所定義的資料結構對封包的内 容進行解析,分離出要發送的封包和控制參數。在資料 連結層第一網卡11的驅動程式將分離出的要發送的封包 寫入第一網卡11的write_buffer中。 [0043] 步驟S104,所述管控模組104在源端主機1中根據分離出 0 的控制參數管控封包的發送過程。具體管控過程將在圖4 中詳細介紹。 [0044] 如圖4所示,係為本發明網卡資料傳輸方法較佳實施例之 管控子流程圖。 [0045] 步驟S1 040,所述發送單元一 105將源端主機1中所分割 的封包發送至目的主機3,封包的發送時間間隔由延時參 數決定。 ^ [0046] 在資料連結層第一網卡11的驅動程式將wr i te_buf f er中 的封包進行分割,在物理層將分割後的封包傳送至網路2 中,經網路2發送至目的主機3,目的主機3將根據封包中 的目的位址來接受屬於自己的封包。在將write_buffer 中的封包進行分割的過程中,可由隨機設置參數對要分 割的封包的資料内容及長度進行控制。 [0047] 步驟S1041,所述判斷單元106在源端主機1的Linux作業 系統的kernel層中,對目的主機3的返回值進行判斷,從 而判斷封包是否發送成功。當封包發送成功時,執行步 100121788 表單編號 A0101 第 13 頁/共 27 頁 1002036878-0 201251377 驟S1 042,當封包發送失敗時,執行步驟S1 044。 [0048] 當封包發送成功時,目的主機3將返回一個正值至源端主 機1的kernel層,而當封包發送失敗時,目的主機3將返 回一個負值至源端主機1的kernel層。 [0049] 步驟S1042,所述計數單元一 107統計發送的封包成功投 遞的次數,判斷封包成功投遞的次數是否達到Μ次。當封 包成功投遞的次數達到Μ次時,執行步驟S1 043,當封包 成功投遞的次數沒有達到Μ次時,返回步驟S1040。所述Μ 值,為發送參數設定的封包投遞的次數。 [0050] 步驟S1044,所述計數單元二109統計封包重新發送的次 數,判斷是否已達到Ν次。所述Ν值為回饋參數所設置的 當封包發送失敗時,重新發送封包的次數。當達到Ν次時 ,執行步驟S1043,當沒有達到Ν次時,返回步驟S1040 〇 [0051] 步驟S1 043,所述溝通單元108控制源端主機1的Linux作 業系統的kernel層與Linux作業系統的應用層進行溝通 〇 [0052] Linux作業系統的kernel層與Linux作業系統的應用層 進行溝通時,返回封包發送完成時相關資訊至Linux作業 系統的應用層,以供用戶查看。當失敗時,顯示的資訊 為,如成功發送多少個封包、在發送哪個封包時失敗等 。當成功時,顯示的資訊為,如成功發送多少個封包、 總共耗時多少等。各個封包的發送過程中對應的返回值 及各個封包發送過程中的相關資訊顯示,由調試參數控 100121788 表單編號A0101 第14頁/共27頁 1002036878-0 201251377 制輸出,但此時需用戶進行相關命令的輸入。 [0053] 综上所述,本發明符合發明專利要件,爰依法提出專利 申請。惟,以上所述者僅爲本發明之較佳實施例,本發 明之範圍並不以上述實施例爲限,舉凡熟悉本案技藝之 人士援依本發明之精神所作之等效修飾或變化,皆應涵 蓋於以下申請專利範圍内。 【圖式簡單說明】 [0054] 圖1係為本發明網卡資料傳輸系統較佳實施例之架構圖。 [0055] 圖2係為本發明網卡資料傳輸系統較佳實施例之功能模組 圖。 [0056] 圖3係為本發明網卡資料傳輸方法較佳實施例之流程圖。 [0057] 圖4係為本發明網卡資料傳輸方法較佳實施例之管控子流 程圖。 [0058] 圖5係為本發明網卡資料傳輸系統較佳實施例之網卡資料 傳輸示例圖。 [0059] 圖6係為本發明網卡資料傳輸系統較佳實施例所定義之資 料結構。 【主要元件符號說明】 [0060] 源端主機1 [0061] 網卡資料傳輸系統10 [0062] 第一網卡11 [0063] 網路 2 100121788 表單編號A0101 第15頁/共27頁 1002036878-0 201251377 [0064] 目的主機 3 [0065] 第二網卡 30 [0066] 設置模組 100 [0067] 封裝模組 101 [0068] 發送模組 102 [0069] 解析模組 103 [0070] 管控模組 104 [0071] 發送單元 一 105 [0072] 判斷單元 106 [0073] 計數單元 一 107 [0074] 溝通單元 108 [0075] 計數單元二109 [0076] 在應用層設置用於發送的控制參數 與控制參數格式相同的資料結構S100 [0077] 創建底層套接字,並將控制參數、源端位址、目的位址 及發送的内容封裝至封包中S101 [0078] 將封包由應用層發送至kernel層中的資料連結層 [0079] S102 [0080] 在資料連結層中解析封包,將要發送的封包及控制參數 分離S103 100121788 表單編號A0101 第16頁/共27頁 1002036878-0 201251377 [0081] 根據控制參數管控封包的發送過程S104Socket (PF packet through the underlying socket 100121788 Form No. A0101 Page 8 / Total 27 pages 201251377 [0019] [0022] [0022] [0023] The first network card 11 'is operated by the underlying socket The control of the first network card 11 can be implemented. The S〇CK_RAW in the above-mentioned underlying socket format can be replaced with SOCK-PACKET, and the lower layer socket after s〇CK_PACKET is replaced with the lower layer socket originally SOCK-RAW. The functions are the same, but the way to bind the first network card 11 is different. The underlying socket can realize the purpose of sending the packet directly from the application layer of the Linux operating system to the data link layer, thereby bypassing the first five layers of the 七Si seven-layer model. The five layers are: an application layer, a presentation layer, a session layer, a transport layer, and a network layer. The sending module 102 is configured to send the packet from the application layer of the liux operating system to the Linux operation in the source host 1 The data link layer in the kernel layer of the system. In the kernel layer, including the data link layer, the physical layer, and the driver of the first network card 11. As shown in FIG. 5, the packet is encapsulated in the application layer of the Linux operating system. Package The underlying socket can be directly sent to the data link layer by the application layer of the Linux operating system, bypassing the application layer, presentation layer, presentation layer, transport layer and network layer in the 0SI seven-layer model. The kernei layer includes a data link layer and a physical layer. The parsing module 1-3 is configured to parse the packet in the data link layer of the source host 1 to separate the packet and control parameters to be sent. In the kerne layer 1 After receiving the packet from the application layer of the [i nux operating system, the data link layer parses the content of the packet according to the defined data structure, and separates the packet and the control parameter to be sent. In the data link layer - the network card 11 The driver writes the separated packet 100121788 to be sent, the form number A0101, page 9 / page 27, 1002036878-0 201251377, to the write_buffer* of the first network card 11. [0024] The control module 104 is used at the source host The sending process of the control packet is controlled according to the separated control parameters. [0025] The control module 104 includes the following sub-modules: a transmitting unit 105, a determining unit 106, and a counting unit. 107. The communication unit 108 and the counting unit 2 109. [0026] The sending unit 010 is configured to send the divided packet in the source host 1 to the destination host 3, and the sending time interval of the packet is determined by the delay parameter. 0027] The driver of the first network card 11 in the data link layer divides the packet in the wri te_buf er, and transmits the divided packet to the network 2 at the physical layer, and transmits it to the destination host 3 via the network 2, for the purpose of Host 3 will accept its own packet based on the destination address in the packet. In the process of dividing the packet in the write_buffer, the data content and length of the packet to be divided can be controlled by randomly setting parameters. [0028] The determining unit 106 is configured to determine the return value of the destination host 3 in the kernel layer of the Linux operating system of the source host 1 to determine whether the packet is successfully sent. [0029] When the packet transmission succeeds, the destination host 3 will return a positive value to the kernel layer of the source host 1, and when the packet transmission fails, the destination host 3 will return a negative value to the kernel layer of the source host 1. [0030] The counting unit 107 is configured to count the number of successfully delivered packets when the packet is successfully sent, and determine whether the number of successful delivery of the packet reaches the number of times. The threshold is the number of times the packet is delivered for the transmission parameter. 100121788 Form No. 1010101 Page 10/Total 27 Page 1002 201251377 [0031] The counting unit 2 is used to count the number of new transmissions when the packet transmission fails [0032], and determine whether the number of retransmissions has reached N. Times. The N value is set by the feedback parameter, and the number of times the packet is resent when the packet transmission fails. The communication unit 108 is configured to communicate with the application layer of the Linux operating system when the number of successful delivery of the packet reaches the number of times, or after the packet is resent, the kerne layer 1 of the Linux host system of the source host 1 communicates with the application layer of the Linux operating system. [0033] When the kernel layer of the Linux operating system communicates with the application layer of the Linux operating system, the information related to the completion of the packet transmission is returned to the application layer of the Linux operating system for the user to view. When it fails, the information displayed is , such as how many packets were successfully sent, which packet was sent, and so on. When successful, the information displayed is, for example, how many packets were successfully sent, how much total time spent, and so on. The corresponding return value in the sending process of each packet and the related information in the process of sending each packet are controlled by the debugging parameters, but the user needs to input the relevant commands at this time. [0034] As shown in FIG. 3, it is a flowchart of a preferred embodiment of the network card data transmission method of the present invention. [0035] Step S100, the setting module 100 sets a control parameter for sending at the application layer of the Linux operating system of the source host 1 and a kernel layer definition and control parameter format of the Linux operating system of the source host 1 The same data structure. The data structure is used to receive and parse control parameters set by the application layer. [0036] Step S101, the package module 101 creates an underlying socket in the application layer of the Linux host job 100121788 Form No. A0101 page 11/27 page 1002036878-0 201251377 of the source host 1 and controls parameters, The source address, destination address, and transmission content are encapsulated into a packet. The source address is the MAC address of the first network card 11 in the source host 1, and the destination address is the MAC address of the second network card 30 in the destination host 3. [0037] The format of the underlying socket is: int fd = socket (PF_PACKET, S0CK_RAW, IPPR0T0_TCP); the first network card 11 can be bound by the underlying socket, that is, the first network card 11 can be implemented by operating the underlying socket. control. The above-mentioned underlying socket format S0CK_RAW can be replaced with SOCK_PACKET, and the underlying socket after SOCK_PACKET is replaced with the same function as the underlying socket originally S0CK_RAW, but the manner of binding the first NIC 11 is different. [0038] The underlying socket can realize the purpose that the packet is directly sent from the application layer of the Linux operating system to the data link layer, thereby bypassing the first five layers in the 0SI seven-layer model: the application layer, the presentation layer, Session layer, transport layer, network layer. [0039] Step S102, the sending module 1〇2 sends the packet in the source host 1 to the data link layer in the kernel layer of the Linux operating system by the application layer of the Linux operating system. In the kernel layer, the data link layer, the physical layer, and the driver of the first network card 11 are included. [0040] As shown in FIG. 5, the encapsulation of the packet is performed in the application layer of the Linux operating system, and the application layer of the Linux operating system can be directly sent to the data link layer through the underlying socket to bypass the SI seven-layer model. The five layers of the application layer, the presentation layer, the session wide, the transport layer, and the network layer. The data link layer and the physical layer are included in the kernel layer. 100121788 Form No. A0101 Page 12 of 27 1002036878-0 201251377 [0041] Step S103, the parsing module 103 parses the packet in the data link layer of the source host 1, and separates the packet to be sent and the control parameters. [0042] After receiving the packet from the application layer of the Linux operating system, the data link layer in the kernel layer parses the content of the packet according to the defined data structure, and separates the packet and control parameters to be sent. The driver of the first network card 11 at the data link layer writes the separated packet to be transmitted into the write_buffer of the first network card 11. [0043] Step S104, the control module 104 controls the sending process of the packet in the source host 1 according to the control parameter of the separated 0. The specific control process will be described in detail in Figure 4. [0044] As shown in FIG. 4, it is a flowchart of a control sub-control of a preferred embodiment of the network card data transmission method of the present invention. [0045] Step S1 040, the sending unit 105 sends the packet divided by the source host 1 to the destination host 3, and the sending time interval of the packet is determined by the delay parameter. [0046] The driver of the first network card 11 in the data link layer divides the packet in the wr i te_buf er, and transmits the divided packet to the network 2 at the physical layer, and sends it to the destination host via the network 2 3. The destination host 3 will accept its own packet according to the destination address in the packet. In the process of dividing the packet in the write_buffer, the data content and length of the packet to be divided can be controlled by randomly setting parameters. [0047] Step S1041, the determining unit 106 determines the return value of the destination host 3 in the kernel layer of the Linux operating system of the source host 1 to determine whether the packet is successfully transmitted. When the packet is successfully sent, go to step 100121788 Form No. A0101 Page 13 of 27 1002036878-0 201251377 Step S1 042, when the packet transmission fails, step S1 044 is performed. [0048] When the packet transmission succeeds, the destination host 3 will return a positive value to the kernel layer of the source host 1, and when the packet transmission fails, the destination host 3 will return a negative value to the kernel layer of the source host 1. [0049] Step S1042, the counting unit 107 counts the number of times the successfully transmitted packet is successfully delivered, and determines whether the number of successful delivery of the packet reaches the number of times. When the number of successful delivery of the packet reaches the number of times, step S1 043 is performed, and when the number of successful delivery of the packet has not reached the number of times, the process returns to step S1040. The Μ value is the number of times the packet is delivered for the transmission parameter. [0050] Step S1044, the counting unit 2 109 counts the number of times the packet is resent, and determines whether the number has been reached. The Ν value is set by the feedback parameter, and the number of times the packet is resent when the packet transmission fails. When the number of times is reached, step S1043 is performed. When the number of times is not reached, the process returns to step S1040. [0051] Step S1 043, the communication unit 108 controls the kernel layer of the Linux operating system of the source host 1 and the Linux operating system. Communication at the application layer [0052] When the kernel layer of the Linux operating system communicates with the application layer of the Linux operating system, the information about the completion of the packet transmission is returned to the application layer of the Linux operating system for the user to view. When it fails, the information displayed is, for example, how many packets were successfully sent, which packet was sent, and so on. When successful, the information displayed is, for example, how many packets were successfully sent, how much time was spent, and so on. The corresponding return value during the sending process of each packet and the related information display during the sending process of each packet are output by the debugging parameter control 100121788 Form No. A0101 Page 14/27 pages 1002036878-0 201251377, but the user needs to be related at this time. The input of the command. [0053] In summary, the present invention complies with the requirements of the invention patent, and submits a patent application according to law. The above is only the preferred embodiment of the present invention, and the scope of the present invention is not limited to the above-described embodiments, and equivalent modifications or variations made by those skilled in the art in light of the spirit of the present invention are It should be covered by the following patent application. BRIEF DESCRIPTION OF THE DRAWINGS [0054] FIG. 1 is a block diagram of a preferred embodiment of a network card data transmission system of the present invention. 2 is a functional block diagram of a preferred embodiment of the network card data transmission system of the present invention. 3 is a flow chart of a preferred embodiment of a network card data transmission method according to the present invention. 4 is a flow chart of a control sub-control of a preferred embodiment of the network card data transmission method of the present invention. 5 is a diagram showing an example of transmission of a network card data according to a preferred embodiment of the network card data transmission system of the present invention. 6 is a data structure defined by a preferred embodiment of the network card data transmission system of the present invention. [Main component symbol description] [0060] Source host 1 [0061] NIC data transmission system 10 [0062] First network card 11 [0063] Network 2 100121788 Form number A0101 Page 15 / Total 27 pages 1002036878-0 201251377 [ 0064] destination host 3 [0065] second network card 30 [0066] setting module 100 [0067] transmitting module 102 [0069] parsing module 103 [0070] control module 104 [0071] Transmitting unit one 105 [0072] Judging unit 106 [0073] Counting unit one 107 [0074] Communication unit 108 [0075] Counting unit two 109 [0076] Setting the same control data format for transmitting control parameters and control parameters at the application layer Structure S100 [0077] Creating an underlying socket and encapsulating the control parameters, the source address, the destination address, and the sent content into the packet S101 [0078] Sending the packet from the application layer to the data link layer in the kernel layer [0079] S102 parsing the packet in the data link layer, separating the packet to be sent and the control parameter S103 100121788 Form number A0101 Page 16 of 27 page 1002036878-0 201251377 [0081] Controlling the packet according to the control parameter Send process S104
100121788 表單編號A0101 第17頁/共27頁 1002036878-0100121788 Form No. A0101 Page 17 of 27 1002036878-0