Disclosure of Invention
Embodiments of the present invention provide a content distribution method, a content distribution apparatus, a content request apparatus, and a routing node that overcome the above problems or at least partially solve the above problems.
In a first aspect, an embodiment of the present invention provides a content distribution method, which is applied to a routing node, and the method includes:
when a resource acquisition request is received, matching the name of the resource recorded in the resource acquisition request in a to-be-determined interest table maintained by the resource acquisition request;
if the name is unsuccessfully matched in the pending interest table, matching in a resource cache according to the hash value recorded in the resource acquisition request;
if the hash value is successfully matched in the resource cache, the corresponding resource is transmitted back to the content request device;
if the hash value fails to be matched in the resource cache, adding a new table entry in the interest table to be determined, and continuously forwarding the resource acquisition request;
wherein, the new table entry in the pending interest table is used for recording the name of the resource and the content request device of the resource acquisition request; the resource cache is used for storing the resource, the name of the resource and a hash value, and the hash value is calculated according to the content of the resource.
In a second aspect, an embodiment of the present invention provides a content distribution method, which is applied to a content distribution apparatus, and the method includes:
storing resources and generating names and hash values of the resources, wherein the hash values of the resources are calculated according to the contents of the resources;
publishing the name and the hash value of the resource;
and if the resource acquisition request is received, finding the corresponding resource according to the name and/or the hash value of the resource recorded in the resource acquisition request, and transmitting the resource back to the content request device.
In a third aspect, an embodiment of the present invention provides a content distribution method, which is applied to a content request device, and the method includes:
acquiring the name and the hash value of a resource published by a content publishing device, wherein the hash value is calculated according to the content of the resource;
sending a resource acquisition request, wherein the resource acquisition request records the name and the hash value of a resource;
and if the resource is received, processing the resource according to a preset rule.
In a fourth aspect, an embodiment of the present invention further provides a routing node, including:
the name matching module is used for matching the names of the resources recorded in the resource acquisition request in a self-maintained interest table to be determined when the resource acquisition request is received;
the hash value matching module is used for matching in the resource cache according to the hash value recorded in the resource acquisition request if the name is unsuccessfully matched in the pending interest table;
the back transmission module is used for transmitting the corresponding resource back to the content request device if the hash value is successfully matched in the resource cache; if the hash value fails to be matched in the resource cache, adding a new table entry in the interest table to be determined, and continuously forwarding the resource acquisition request;
wherein, the new table entry in the pending interest table is used for recording the name of the resource and the content request device of the resource acquisition request; the resource cache is used for storing the resource, the name of the resource and a hash value, and the hash value is calculated according to the content of the resource.
In a fifth aspect, an embodiment of the present invention further provides a content distribution apparatus, including:
the resource storage module is used for storing resources and generating names and hash values of the resources, and the hash values of the resources are calculated according to the contents of the resources;
the resource publishing module is used for publishing the name and the hash value of the resource;
and the resource returning module is used for finding the corresponding resource according to the name and/or the hash value of the resource recorded in the resource acquisition request and returning the resource to the content requesting device if the resource acquisition request is received.
In a sixth aspect, an embodiment of the present invention further provides a content requesting apparatus, including:
the demand module is used for acquiring the name and the hash value of the resource published by the content publishing device, and the hash value is calculated according to the content of the resource;
the request sending module is used for sending a resource obtaining request, and the resource obtaining request records the name and the hash value of the resource;
and the resource receiving module is used for processing the resources according to a preset rule if the resources are received.
In a seventh aspect, an embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method provided in the first to third aspects when executing the program.
In an eighth aspect, an embodiment of the present invention provides a non-transitory computer readable storage medium, on which a computer program is stored, which when executed by a processor implements the steps of the method as provided in the first to third aspects.
According to the content distribution method, the content issuing device, the content requesting device and the routing node provided by the embodiment of the invention, the resource is subjected to double matching by the name and the hash value determined by the resource content, so that the routing node directly returns the pre-cached resource to the content requesting device under the condition that the names are different and the hash values are the same, and the resource obtaining request does not need to be continuously forwarded to the content issuing party or the routing node with the completely same stored name is encountered, so that the distribution efficiency can be effectively improved, the network response delay is shortened, and the resource utilization efficiency is increased.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flow diagram of a content distribution method provided in an embodiment of the present invention, where the content distribution method is applied to a routing node, as shown in fig. 1, the method includes S101, S102, and S103, and specifically:
s101, when a resource acquisition request is received, matching the name of the resource recorded in the resource acquisition request in a to-be-determined interest table maintained by the resource acquisition request;
it should be noted that, in the resource obtaining request according to the embodiment of the present invention, a name and a hash value of a resource are recorded, where the hash value of the resource is calculated according to the content of the resource. The resource acquisition request of the embodiment of the invention can be directly sent by the content request device by the routing node or forwarded by other routing nodes. When a resource acquisition request is received, the embodiment of the invention firstly carries out matching in the self-maintained interest table to be determined. The name of the resource which is not returned is recorded in the pending interest table.
Table 1 is a pending interest table according to the embodiment of the present invention, and as shown in table 1, there are three columns of entries in the pending interest table, which are Name, Request Face and From, respectively, where Name is a Name of a resource, Request Face is an interface number of a routing node, and From is an identifier of a content requesting device of a resource acquisition Request. For example, the resource of bupt/Host2/APP3/video. mp4/s1 is initiated by the content requesting device Host1 and transmitted to the routing node through interface 1 of the routing node, and the resource of bupt/Host3/APP3/video. mp4/s2 is transmitted to the routing node through interface 2 of the routing node.
Name
|
Request Face
|
From
|
bupt/host2/APP3/video.mp4/s1
|
1
|
Host1
|
bupt/host3/APP3/video.mp4/s2
|
2
|
Host2 |
TABLE 1 table of interest to be assessed
And S102, if the name is unsuccessfully matched in the pending interest table, matching in a resource cache according to the hash value recorded in the resource acquisition request.
It should be noted that, if the name is unsuccessfully matched in the pending interest table, it is indicated that a resource acquisition request for acquiring the resource of the name is not received before, but in the embodiment of the present invention, it is considered that the same resource content may correspond to multiple names, and therefore, the embodiment of the present invention further calculates a hash value for each resource according to the content of the resource, thereby ensuring that the resource cached before may be acquired by searching for the hash value of the resource even if the same resource content has different names. It can be understood that, when receiving a new resource, the routing node according to the embodiment of the present invention will cache the resource in the resource cache.
Table 2 is an indication table of the resource cache according to the embodiment of the present invention, and as shown in table 2, there are three rows of entries in the resource cache, which are Name, HashCode, and Data, respectively. Name is the Name of the resource, HashCode is the hash value of the resource, Data is the content of the resource, two resources, namely, video. mp4/s1 and video. mp4/s2, and suffixes s1 and s2 are actually two pieces of Data of video. mp4, are recorded in table 1, that is, the embodiment of the present invention splits one mp4 file into multiple pieces of Data, thereby reducing the size of Data transmitted each time. The bupt refers to a domain name, and host2 and host3 refer to two different content distribution devices. The name of the resource in the embodiment of the invention consists of a domain name, a path name and a file name, taking table 2 as an example, host2/APP 3/is the path name, and video. mp4/s1 is the file name.
Name
|
HashCode
|
Data
|
bupt/host2/APP3/video.mp4/s1
|
S13H12D25V9C31
|
video.mp4/s1
|
bupt/host3/APP3/video.mp4/s2
|
F45SS48C15S47A5
|
video.mp4/s2 |
Table 2 schematic table of resource cache
S103, if the hash value is successfully matched in the resource cache, transmitting the corresponding resource back to the content request device; and if the hash value fails to be matched in the resource cache, adding a new table entry in the pending interest table, and continuously forwarding the resource acquisition request.
It should be noted that, if the hash value is successfully matched in the resource cache, it indicates that the routing node caches the resource with the same content in advance, and then the routing node may return the corresponding resource in the resource cache to the content request device, and discard the resource acquisition request, and no longer forward the resource acquisition request. If the hash value fails to be matched in the resource cache, it indicates that the routing node does not cache the resource with the same content in advance, the resource acquisition request is not satisfied, and the new entry in the pending interest table is used for recording the name of the content request device and the resource of the resource acquisition request.
According to the content distribution method, the names of the resources and the hash values determined by the resource content are subjected to double matching, so that the routing nodes directly return the pre-cached resources to the content request device under the condition that the names are different and the hash values are the same, the resource acquisition request does not need to be continuously forwarded to the content publisher or the routing nodes with the completely same names are encountered, the distribution efficiency can be effectively improved, the network response delay is shortened, and the resource utilization efficiency is increased.
On the basis of the foregoing embodiments, as an optional embodiment, the matching, in a pending interest table maintained by the resource acquisition request, the name of the resource recorded in the resource acquisition request, and then further includes:
if the name is unsuccessfully matched in the pending interest table, continuing to match the content request device in the pending interest table maintained by the content request device, and if the name is successfully matched, discarding the resource acquisition request; and if the matching fails, further searching the resource cache.
It should be noted that, if the name is successfully matched in the pending interest table, it indicates that the resource has been requested by the content request device before, so the embodiment of the present invention continues to match the content request device in the pending interest table maintained by the routing node itself, and if the name is successfully matched, it indicates that the resource has been requested by the content request device before, so the routing node discards the resource acquisition request, and if the name is not successfully matched, it indicates that no other content request device has requested the resource, or that other resource acquisition requests have been satisfied, and the routing node further searches the resource cache.
On the basis of the above embodiments, as an optional embodiment, the embodiment of the present invention further includes: and if the hash value fails to be matched in the resource cache, adding a new table entry in the interest table to be determined, and continuously forwarding the resource acquisition request. It should be noted that, the failure of hash value matching indicates that no content requesting device has requested a resource of the same content before, and then the routing node adds a new entry in the pending interest table and continues to forward the resource acquisition request.
On the basis of the above embodiments, as an optional embodiment, if the routing node receives the resource transmitted from the content distribution device, the name of the resource is matched in the pending interest table maintained by the routing node, and if the matching is successful, it indicates that the routing node has received a request for the resource from a certain content distribution device before, the routing node deletes the corresponding entry in the pending interest table, and continues to forward the resource. Therefore, the embodiment of the invention can be seen in that a dynamically maintained pending interest table is set, and when the corresponding resource is received, the corresponding table entry is deleted from the pending interest table, so that the forwarding process of the resource is defined.
On the basis of the foregoing embodiments, as an optional embodiment, the matching the name of the resource in a pending interest table maintained by the apparatus itself further includes:
if the name is unsuccessfully matched in the pending interest table, matching the hash value of the resource in the resource cache, and if the hash value is successfully matched in the resource cache, forwarding the corresponding resource;
if the hash value fails to be matched in the resource cache, storing the resource, the name of the resource and the hash value in the resource cache, and forwarding the resource
It should be noted that, if the name fails to be matched in the pending interest table, it indicates that the resource with the same name is not received before, and the routing node will continue to match the hash value of the resource in the resource cache. The caching of the resource can obviously be achieved by performing a hash operation on the content of the resource. If the matching is successful, the resource which has received the same content before is indicated, and the resource is only forwarded. If the matching fails, which means that the resource of the content has not been received before, the routing node additionally stores the resource, the name of the resource and the hash value in the resource cache while forwarding the resource, so that the resource can be directly returned when a request about the resource is received next time.
Fig. 2 is a schematic flow diagram of another content distribution method provided in an embodiment of the present invention, where the method is applied to a content distribution apparatus, as shown in fig. 2, the method includes S201, S202, and S203, specifically:
s201, storing the resource, and generating the name and the hash value of the resource, wherein the hash value of the resource is calculated according to the content of the resource;
s202, publishing the name and the hash value of the resource;
s203, if the resource acquisition request is received, finding the corresponding resource according to the name and/or the hash value of the resource recorded in the resource acquisition request, and transmitting the resource back to the content request device.
It should be noted that, the content publishing device in the embodiment of the present invention may publish the name and the hash value of the resource in the entire network architecture after generating the name and the hash value of the resource, so as to be acquired by the content requesting device, and when the content publishing device receives the resource acquiring request, find the corresponding resource according to the name and/or the hash value of the resource recorded in the resource acquiring request, and return the resource to the content requesting device.
Fig. 3 is a schematic flow chart of another content distribution method provided in an embodiment of the present invention, where the method is applied to a content requesting device, and as shown in fig. 3, the method includes S301, S302, and S303, specifically:
s301, acquiring the name and the hash value of the resource published by the content publishing device, wherein the hash value is calculated according to the content of the resource;
s302, sending a resource acquisition request, wherein the resource acquisition request records the name and the hash value of the resource;
and S303, if the resource is received, processing the resource according to a preset rule.
In the embodiment of the present invention, the content publishing devices are Host2 and Host3, the content requesting devices are Host1 and Host4, and the routing nodes through which the resource obtaining request and the data packet are forwarded include Router1, Router2, Router3, Router4, and Router 5. The Host2 and the Host3 issue data resources video.mp4 with different names and the same content, and segment the resources to be suitable for the size of the data packet, and the Host1 and the Host4 respectively send resource acquisition requests with different names and the same resource identification to request the data resources video.mp4 issued by the Host2 and the Host 3.
The named data format provided by the embodiment of the invention is as follows: domain name/pathname/file name. For example, the first piece of data of video. mp4 published by APP2 is applied to the terminal Host2, namely named: bupt/…/Host2/APP2/video. mp4/s1, each segment corresponding to a domain name, a path name and a file name.
When the Host4 sends a resource obtaining request to request the resource video.mp4 issued by the Host3, the request will pass through the Router2, and the processing flow here is as follows:
step 100: the resource acquisition request is named as bupt/Host3/APP3/video. mp4/S1, and the HashCode is S13HI2D25V9C 31. After reaching Router2, matching the carried name with the name in the table entry of the pending interest table in a complete matching manner;
step 101: because the resource acquisition request reaches Router2 for the first time, the matching fails, and the content cache is further searched according to the HashCode carried in the resource acquisition request;
step 102: in the process of searching for the content cache by using the HashCode value, since the data of the resource acquisition request has not yet reached Router2, any data is missed, a resource acquisition request entry needs to be newly added in the pending interest entry to indicate that the resource acquisition request is not satisfied temporarily, and the resource acquisition request is continuously forwarded according to the forwarding interface recorded in the forwarding information table.
Similarly, when the Host3 returns the corresponding packet to the Host4, the corresponding resource acquisition request is transmitted along the same transmission path as the packet, but in the opposite direction, and therefore passes through the Router 2. According to the rules of the flow chart, the process flow here is as follows:
step 110: the name of the data packet is bupt/Host3/APP3/video. mp4/s1, and after the data packet reaches Router2, the name carried by the data packet is matched with the name in the table entry of the undetermined interest table in a complete matching mode;
step 111: because the resource acquisition request requesting the resource leaves an entry in the pending interest table, the matching is successful, which indicates that the data packet is requested by the resource acquisition request, and the data packet is forwarded through a corresponding interface in the matching table;
step 112: router2 performs Hash processing on the content of the data packet to obtain a resource identifier HashCode: s13, HI2D25V9C31, and further searching content cache according to HashCode;
step 113: in the process of searching for content cache by using HashCode, since the packet arrives at Router2 for the first time, any data is missed, the newly arrived packet will be cached, and the corresponding resource identifier HashCode is recorded.
Fig. 4 is a flowchart of a content distribution method according to another embodiment of the present invention, which is used to illustrate a process in which a Host4 sends a resource obtaining request to request a resource video. mp4 issued by a Host3, where a solid arrow in fig. 4 represents a sending path of the resource obtaining request (interest packet), and a dashed arrow represents a return path of the resource (date packet), and a specific flow is as follows:
step 200: different applications APP2 on the content publishing devices End Host2 and End Host3, APP3 respectively publish video.mp4 data contents with different names but completely same contents, and meanwhile, End Host4 sends a resource acquisition request with name of bupt/Host3/APP3/video.mp4/S1 and resource identifier HashCode of S13HI2D25V9C31 to request video.mp4 published by Host 3;
step 201: the resource acquisition request successfully reaches the content distribution apparatus End Host3 via the path Router4, Router2, Router 5. The Host3 finds the corresponding resource video.mp4 according to the resource name and the resource identifier in the resource acquisition request, segments the resource video.mp4, and returns the segmented resource video.mp4 in the form of a data packet;
step 202: the data packet successfully arrives at the content requesting device End Host4 through the route 5, the route 2 and the route 4, is delivered to the application handler, and the data content of the resource video. mp4 is cached at the route 5, the route 2 and the route 4 respectively.
Fig. 5 is a flowchart of a content distribution method according to another embodiment of the present invention, which is used to illustrate a process that after a Host4 successfully retrieves a resource video.mp4 issued by a Host3, the Host1 sends a resource acquisition request to request the same content resource video.mp4 issued by the Host2, where a solid arrow in fig. 5 represents a sending path of a resource acquisition request (interest packet), and a dashed arrow represents a return path of a resource (date packet), and a specific flow is as follows:
step 210: different applications APP2 and APP3 on the content publishing devices Host2 and Host3 respectively publish video. mp4 data contents with different names but completely same contents, and meanwhile, the Host1 sends a resource acquisition request with the name of bupt/Host2/APP2/video. mp4/S1 and the resource identifier HashCode of S13HI2D25V9C31 to request the video. mp4 published by the Host 2;
step 211: the resource acquisition request passes through routing node Router1 to routing node Router 2. Router2 matches the pending interest table miss according to the name carried by the resource obtaining request, but successfully hits the data according to the resource identifier HashCode carried by the resource obtaining request, because the previously cached name is bupt/Host3/APP3/video. mp4/s1 and the data of the resource obtaining request have the same data content although the names are different, and the resource identifiers HashCode thereof can be matched. Thus, Router2 passes its cached resource video. mp4 back in the form of a packet;
step 212: the packet successfully reaches the content requesting device Host1 via the routing node Router1 and is delivered to its corresponding application handler.
Fig. 6 is a schematic structural diagram of a routing node according to an embodiment of the present invention, and as shown in fig. 6, the routing node apparatus includes: a name matching module 601, a hash value matching module 602, and a backhaul module 603, wherein:
a name matching module 601, configured to, when a resource acquisition request is received, match names of resources recorded in the resource acquisition request in a pending interest table maintained by the name matching module;
a hash value matching module 602, configured to, if the name fails to be matched in the pending interest table, perform matching in the resource cache according to the hash value recorded in the resource acquisition request;
a returning module 603, configured to return the corresponding resource to the content requesting device if the hash value is successfully matched in the resource cache; and if the hash value fails to be matched in the resource cache, adding a new table entry in the pending interest table, and continuously forwarding the resource acquisition request.
Wherein, the new table entry in the pending interest table is used for recording the name of the resource and the content request device of the resource acquisition request; the resource cache is used for storing the resource, the name of the resource and a hash value, and the hash value is calculated according to the content of the resource.
The routing node provided in the embodiment of the present invention specifically executes the embodiment flows of the content distribution methods on the routing node side, and please refer to the contents of the embodiments of the content distribution methods on the routing node side for details, which are not described herein again. The routing node provided by the embodiment of the invention directly returns the pre-cached resource to the content request device by performing double matching on the name of the resource and the hash value determined by the resource content under the condition that the names of the resource are different and the hash values are the same, and the resource acquisition request does not need to be continuously forwarded to a content publisher or the routing node with the completely same name is encountered, so that the distribution efficiency can be effectively improved, the network response delay is shortened, and the resource utilization efficiency is increased.
An embodiment of the present invention further provides a content publishing apparatus, including:
the resource storage module is used for storing resources and generating names and hash values of the resources, and the hash values of the resources are calculated according to the contents of the resources;
the resource publishing module is used for publishing the name and the hash value of the resource;
and the resource returning module is used for finding the corresponding resource according to the name and/or the hash value of the resource recorded in the resource acquisition request and returning the resource to the content requesting device if the resource acquisition request is received.
An embodiment of the present invention further provides a content requesting apparatus, including:
the demand module is used for acquiring the name and the hash value of the resource published by the content publishing device, and the hash value is calculated according to the content of the resource;
the request sending module is used for sending a resource obtaining request, and the resource obtaining request records the name and the hash value of the resource;
and the resource receiving module is used for processing the resources according to a preset rule if the resources are received.
Fig. 7 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 7, the electronic device may include: a processor (processor)710, a communication Interface (Communications Interface)720, a memory (memory)730, and a communication bus 740, wherein the processor 710, the communication Interface 720, and the memory 730 communicate with each other via the communication bus 740. The processor 710 may invoke a computer program stored on the memory 730 and executable on the processor 710 to perform the content distribution methods provided by the embodiments described above, including, for example: when a resource acquisition request is received, matching the name of the resource recorded in the resource acquisition request in a to-be-determined interest table maintained by the resource acquisition request; if the name is unsuccessfully matched in the pending interest table, matching in a resource cache according to the hash value recorded in the resource acquisition request; if the hash value is successfully matched in the resource cache, the corresponding resource is transmitted back to the content request device; if the hash value fails to be matched in the resource cache, adding a new table entry in the interest table to be determined; wherein, the new table entry in the pending interest table is used for recording the name of the resource and the content request device of the resource acquisition request; the resource cache is used for storing the resource, the name of the resource and a hash value, and the hash value is calculated according to the content of the resource.
In addition, the logic instructions in the memory 730 can be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solutions of the embodiments of the present invention may be essentially implemented or make a contribution to the prior art, or may be implemented in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Embodiments of the present invention further provide a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program is implemented to perform the content distribution method provided in the foregoing embodiments when executed by a processor, for example, the method includes: when a resource acquisition request is received, matching the name of the resource recorded in the resource acquisition request in a to-be-determined interest table maintained by the resource acquisition request; if the name is unsuccessfully matched in the pending interest table, matching in a resource cache according to the hash value recorded in the resource acquisition request; if the hash value is successfully matched in the resource cache, the corresponding resource is transmitted back to the content request device; if the hash value fails to be matched in the resource cache, adding a new table entry in the interest table to be determined; wherein, the new table entry in the pending interest table is used for recording the name of the resource and the content request device of the resource acquisition request; the resource cache is used for storing the resource, the name of the resource and a hash value, and the hash value is calculated according to the content of the resource.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.