CN114443707A - Address query method and device, electronic equipment and storage medium - Google Patents

Address query method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114443707A
CN114443707A CN202111619688.8A CN202111619688A CN114443707A CN 114443707 A CN114443707 A CN 114443707A CN 202111619688 A CN202111619688 A CN 202111619688A CN 114443707 A CN114443707 A CN 114443707A
Authority
CN
China
Prior art keywords
address
block data
cidr
retrieved
binary
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111619688.8A
Other languages
Chinese (zh)
Inventor
范宇超
鄢智勇
吴贤维
张兆东
杜国中
范炜瑞
车群娣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianyi Cloud Technology Co Ltd
Original Assignee
Tianyi Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianyi Cloud Technology Co Ltd filed Critical Tianyi Cloud Technology Co Ltd
Priority to CN202111619688.8A priority Critical patent/CN114443707A/en
Publication of CN114443707A publication Critical patent/CN114443707A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The application provides an address query method, an address query device, electronic equipment and a storage medium, and relates to the technical field of computers.

Description

Address query method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to an address query method and apparatus, an electronic device, and a storage medium.
Background
Classless Inter-Domain Routing (CIDR) is a way to classify IP addresses for assigning Internet Protocol (IP) addresses to users and for Routing IP packets efficiently over the Internet. CIDR facilitates routing by combining address blocks containing multiple addresses, called CIDR address blocks, into a routing table entry based on the longest match principle.
For planning and constructing cloud computing nodes, it is usually necessary to frequently search Internet Protocol version 4 (IPv 4) addresses in CIDR address block data.
In the prior art, a network number and a mask corresponding to a CIDR address block are usually stored, a start IPv4 and an end IPv4 corresponding to the CIDR address block are calculated in advance, and are stored separately in a data table, and when a user searches an IPv4 address in the CIDR address block, a Structured Query Language (SQL) needs to be adjusted to perform range Query between the start IPv4 address and the end IPv4 address in the data table, so as to perform range Query between the two IPv4 addresses. In the query process, the query efficiency is low and the query speed is slow.
Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present application provide an address query method, an address query device, an electronic device, and a storage medium, so that the address query speed is high, and the query efficiency is high.
In a first aspect, an embodiment of the present application provides an address query method, where the method includes:
determining an address to be retrieved based on the obtained query operator;
determining a binary address to be retrieved and prefix digits of the address to be retrieved, which correspond to the address to be retrieved;
determining a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure based on the binary address to be retrieved and the prefix bit number of the address to be retrieved; wherein the binary data structure is a search data structure including only 0 or 1 search branches.
In a possible implementation manner, the configuration process of the CIDR address block data index of the binary data structure includes:
determining a target storage area according to the storage space required by the CIDR address block data index;
setting an initial node in the target storage area, and configuring a plurality of CIDR address block data nodes based on the initial node; each CIDR address block data node is configured based on a corresponding address prefix digit and a binary address corresponding to the address prefix digit;
creating a CIDR address block data index of the binary data structure; and the index level of the CIDR address block data index is equal to the address prefix bit number.
In a possible implementation manner, the determining, based on the binary address to be retrieved and the number of prefix bits of the address to be retrieved, a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure includes:
based on the binary address to be retrieved, sequentially judging the values of the binary numbers in the binary address to be retrieved according to the sequence from the first bit to the prefix bit of the address to be retrieved, and adjusting an address pointer pointing to the initial node;
and if the binary address of the current CIDR address block data node pointed by the address pointer is the same as the binary address to be retrieved, and the address prefix bit number of the current CIDR address block data node is equal to the address prefix bit number to be retrieved, determining that the current CIDR address block data node is a target CIDR address block data node.
In a possible implementation manner, the sequentially determining values of binary numbers in the binary address to be retrieved according to an order from a first bit to a prefix bit of the address to be retrieved based on the binary address to be retrieved, and adjusting an address pointer pointing to the initial node includes:
if the value of the binary number in the binary address to be retrieved is 0, adjusting the address pointer to point to the left CIDR address block data node in the next index level of the current CIDR address block data node;
and if the value of the binary number in the binary address to be retrieved is 1, adjusting the address pointer to point to the right CIDR address block data node in the next index level of the current CIDR address block data node.
In a possible implementation manner, after determining a target CIDR address block data node corresponding to the address to be retrieved, the method further includes:
determining at least one primary key identification code based on the query operator and the target CIDR address block data node.
In one possible implementation, the determining at least one primary key identification code based on the query operator and the target CIDR address block data node includes:
if the query operator is configured to be equal to the address to be retrieved, determining a primary key identification code corresponding to the target CIDR address block data node;
if the query operator is configured to be smaller than the address to be retrieved, determining a main key identification code corresponding to a left CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the left CIDR address block data node in the next index level of the target CIDR address block data node;
and if the configuration in the query operator is larger than the address to be retrieved, determining a main key identification code corresponding to a right CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index level of the target CIDR address block data node.
In a second aspect, an embodiment of the present application provides an address query apparatus, where the apparatus includes:
the first determining unit is used for determining the address to be retrieved based on the acquired query operator;
and the second determining unit is used for determining the binary address to be retrieved and the prefix bit number of the address to be retrieved, which correspond to the address to be retrieved.
And the query unit is used for determining a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure based on the binary address to be retrieved and the prefix bit number of the address to be retrieved.
In a possible embodiment, the address querying device further includes:
the configuration unit is used for determining a target storage area according to the storage space required by the CIDR address block data index;
setting an initial node in the target storage area, and configuring a plurality of CIDR address block data nodes based on the initial node; each CIDR address block data node is configured based on a corresponding address prefix digit and a binary address corresponding to the address prefix digit;
creating a CIDR address block data index of the binary data structure; and the index level of the CIDR address block data index is equal to the address prefix bit number.
In a possible embodiment, the querying unit is further configured to:
based on the binary address to be retrieved, sequentially judging the values of the binary numbers in the binary address to be retrieved according to the sequence from the first bit to the prefix bit of the address to be retrieved, and adjusting an address pointer pointing to the initial node;
and if the binary address of the current CIDR address block data node pointed by the address pointer is the same as the binary address to be retrieved, and the address prefix bit number of the current CIDR address block data node is equal to the address prefix bit number to be retrieved, determining that the current CIDR address block data node is a target CIDR address block data node.
In a possible embodiment, the querying unit is further configured to:
if the value of the binary number in the binary address to be retrieved is 0, adjusting the address pointer to point to the left CIDR address block data node in the next index level of the current CIDR address block data node;
and if the value of the binary number in the binary address to be retrieved is 1, adjusting the address pointer to point to the right CIDR address block data node in the next index level of the current CIDR address block data node.
In a possible embodiment, the querying unit is further configured to:
determining at least one primary key identification code based on the query operator and the target CIDR address block data node.
In a possible embodiment, the querying unit is further configured to:
if the query operator is configured to be equal to the address to be retrieved, determining a main key identification code corresponding to the target CIDR address block data node;
if the query operator is configured to be smaller than the address to be retrieved, determining a main key identification code corresponding to a left CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the left CIDR address block data node in the next index level of the target CIDR address block data node;
and if the configuration in the query operator is larger than the address to be retrieved, determining a main key identification code corresponding to a right CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index level of the target CIDR address block data node.
In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, where the memory stores a computer program that is executable on the processor, and when the computer program is executed by the processor, the steps of the address query method in any one of the above first aspects are implemented.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the address query method in any one of the above first aspects are implemented.
In a fifth aspect, the present application provides a computer program product, which includes computer-executable instructions for causing a computer to execute the steps of the address query method according to any one of the first aspect.
The embodiment of the application provides an address query method, which is based on an obtained query operator, determines an address to be retrieved, determines a binary address to be retrieved and a prefix digit of the address to be retrieved through the address to be retrieved, and in a CIDR address block data index of a binary data structure, by comparing the binary address in the binary address to be retrieved and the CIDR address block data index, the prefix digit of the address to be retrieved and the prefix digit of the address, and indexing in a binary mode, the efficiency of address query can be improved, and the speed of address query can be improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings may be obtained according to these drawings without inventive labor.
Fig. 1 is a schematic flowchart illustrating an address query method according to an embodiment of the present application;
FIG. 2 is a schematic structural diagram illustrating a partial CIDR address block data index provided by an embodiment of the present application;
fig. 3 is a schematic flowchart illustrating another address query method provided in an embodiment of the present application;
fig. 4 is a schematic structural diagram illustrating an address query apparatus according to an embodiment of the present application;
fig. 5 is a schematic structural diagram illustrating another address query apparatus provided in an embodiment of the present application;
fig. 6 shows a schematic structural diagram of an electronic device provided in an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. 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 application.
It should be noted that references in the specification of the present application to the terms "comprises" and "comprising," and variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Some terms in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
IP address: an IP address typically contains two parts, a prefix part of the address and the host address immediately following in this address. Specifically, like 10.128.0.1/24, the binary address is (00001010100000000000000000000001), and since the prefix portion of the address is 24 bits, the first 24 bits of the binary address are both the prefix portion, and the last 8 bits are the host address.
CIDR address block: CIDR is a standard for interpreting IP addresses based on address prefix portions according to binary address bits corresponding to the IP addresses. CIDR combines multiple address blocks, called CIDR address blocks, into a routing table entry based on the longest match principle to facilitate routing. When these addresses are represented in binary, the number of bits at their beginning is the same. Such as: 10.128.0.1/24 and 10.128.0.0/24, are belonging to the same CIDR address block.
In order to facilitate understanding of the address query method in the embodiment of the present application, in the planning and construction of cloud computing nodes, because IPv4 addresses are in short supply, CIDR address block planning is often performed on a large segment of an applied IPv4 address, so as to improve the utilization rate of IPv4 addresses. One core function of the IPv4 resource planning management system is to frequently search IPv4 in CIDR address block data, and a current general solution is to store a network number and a mask corresponding to a CIDR address block, and also calculate a start IPv4 and an end IPv4 corresponding to the address block in advance, store redundant fields in a data table separately, and when a user searches IPv4 in the CIDR address block, the user needs to adjust a Structured Query Language (SQL) to perform range Query between a start IPv4 and an end IPv4 field in the data table. The query mode is complicated, the address query speed is low, and the query efficiency is low.
In order to solve the problems of low query speed and low query efficiency in the address query process in the prior art, the embodiment of the application provides an address query method, which is characterized in that an address to be retrieved is determined based on an acquired query operator, a binary address to be retrieved and a prefix bit number of the address to be retrieved are determined through the address to be retrieved, and in a CIDR address block data index of a binary data structure, the binary address in the binary address to be retrieved and the CIDR address block data index, the prefix bit number of the address to be retrieved and the prefix bit number of the address to be retrieved are compared, and the indexing is performed in a binary search mode, so that the address query efficiency can be improved, and the address query speed can be improved.
Fig. 1 illustrates an address query method provided in an embodiment of the present application, which is applied to an electronic device, where the electronic device may be a terminal device such as a computer.
Before the address query method as provided in fig. 1 is performed, a CIDR address block data index of a binary data structure for querying an address needs to be configured.
In one possible embodiment, a target storage area is determined according to storage space required by a CIDR address block data index, an initial node is set in the target storage area, a plurality of CIDR address block data nodes are configured based on the initial node, and the CIDR address block data index of a binary data structure is created.
The index level of the CIDR address block data index is equal to the number of address prefix bits, and each CIDR address block data node is configured based on the corresponding address prefix bits and the binary address corresponding to the address prefix bits. The CIDR address block data index includes a plurality of CIDR address block data nodes.
Illustratively, according to the storage space required by the CIDR address block data index, a continuous block of address space is determined for storing the data corresponding to the CIDR address block data index. An initial node, which may also be referred to as a root node, is set at the beginning of the CIDR address block data index. The address of the initial node can be set to 0.0.0.0/0, and the number of prefix bits of the address of the initial node is 0 and the binary address is (00000000000000000000000000000000) as can be seen from the address of the initial node. The level of the initial node may be set to the same number of address prefix bits as the initial node, and therefore, the level of the initial node is a level 0.
Other CIDR address block data nodes in the CIDR address block data index may be configured based on the address of the initial node. Each CIDR address block data node is configured according to the address prefix bit number corresponding to the node and the binary address corresponding to the address prefix position.
It should be noted that each CIDR address block data node is substantially a CIDR address block, but in the process of configuring the CIDR address block data index, each CIDR address block is a node in the CIDR address block data index, so each CIDR address block in the CIDR address block data index is called a CIDR address block data node.
Specifically, a new CIDR address block data node is configured based on an initial node, and two CIDR address block data nodes of a first hierarchy are configured from the initial node. In the first hierarchy, for the initial node, the CIDR address block data node on the left side is configured such that if the value of the first-bit binary address in the binary addresses is 0, the address pointer is streamed from the initial node to the CIDR address block data node on the left side of the initial node in the first hierarchy.
In the first hierarchy, for the initial node, the CIDR address block data node on the right side is configured such that if the value of the first-bit binary address in the binary addresses is 1, the address pointer is streamed from the initial node to the CIDR address block data node on the right side of the initial node in the first hierarchy.
According to the above manner, the CIDR address block data nodes in the second hierarchy corresponding to the CIDR address block data nodes on the left side in the first hierarchy are arranged based on the CIDR address block data nodes on the right side in the first hierarchy, and the CIDR address block data nodes in the second hierarchy corresponding to the CIDR address block data nodes on the right side in the first hierarchy are arranged based on the CIDR address block data nodes on the right side in the first hierarchy. The address prefix bit number of the binary address corresponding to the CIDR address block data node in the first hierarchy is 1 bit. The address prefix bit number of the binary address corresponding to the CIDR address block data node in the second hierarchy is 2 bits.
Since the address to be retrieved is a 32-bit address, the index hierarchy of the CIDR address block data can be configured as a 32-index hierarchy.
The above lookup data structure including only 0 and 1 is a Binary data structure, which may also be referred to as Binary Search Tree (BST).
Through the above steps, namely configuring the CIDR address block data index of the binary data structure, the address query method as in fig. 1 can be performed.
As shown in fig. 1, an address query method provided in the embodiment of the present application includes the following steps:
step S101: and determining the address to be retrieved based on the obtained query operator.
In one possible embodiment, when address query is performed, after query operators are obtained, addresses to be retrieved can be determined from the query operators.
For example: the query operators are: SELECT FROM t1 where 'cidr ═ 10.128.0.135/25'; the address to be retrieved is 10.128.0.135/25.
If the query operator is: and the SELECT FROM t1 where 'cidr' < '10.128.0.68/26', the address to be retrieved is 10.128.0.68/26.
If the query operator is: and if the SELECT is FROM t1 where 'cidr' > '10.128.0.68/26', the address to be retrieved is 10.128.0.68/26.
Step S102: and determining the binary address to be retrieved and the prefix digit of the address to be retrieved corresponding to the address to be retrieved.
In one possible embodiment, if the address to be retrieved is 10.128.0.135/25, the binary address to be retrieved is (00001010100000000000000010000111), and the prefix bit number of the address to be retrieved is 25 bits.
If the address to be retrieved is 10.128.0.68/26, the binary address to be retrieved is 00001010100000000000000001000100, and the prefix digit of the address to be retrieved is 26 bits.
Step S103: and determining a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure based on the binary address to be retrieved and the prefix bit number of the address to be retrieved.
After the target CIDR address block data node is found, at least one primary key identification code may be determined based on the query operator.
In a possible embodiment, if the address to be retrieved is 10.128.0.135/25, based on the preconfigured CIDR address block data index of the binary data structure, the query may be started from the initial node, and since the target CIDR address block data node is finally determined, at least one primary key identification code may be determined, so that the primary key identification codes are shown together in fig. 2, and specifically, reference may be made to the partial CIDR address block data index of the binary data structure shown in fig. 2.
As shown in fig. 2, each CIDR address block data node is divided into an upper part and a lower part in fig. 2, the upper part is a binary address and an address prefix digit corresponding to the CIDR address block data node, and the lower part is a main key identification code corresponding to the CIDR address block data node.
Illustratively, based on the binary address to be retrieved, the values of binary numbers in the binary address to be retrieved are sequentially judged according to the sequence from the first bit to the prefix bit of the address to be retrieved, and an address pointer pointing to the initial node is adjusted, if the binary address of the current CIDR address block data node pointed by the address pointer is the same as the binary address to be retrieved, and the number of the address prefix bits of the current CIDR address block data node is equal to the number of the prefix bits of the address to be retrieved, the current CIDR address block data node is determined to be the target CIDR address block data node.
Like the partial CIDR address block data index shown in FIG. 2, the start query address is at the initial node, assuming that the current CIDR address block data node is 10.128.0.0/24, indicating that the CIDR address block data node pointed to by the current address pointer is 10.128.0.0/24. Firstly, whether the address prefix bit number of the current CIDR address block data node is the same as the address prefix bit number to be retrieved of the address to be retrieved is required to be compared, if the address prefix bit number is different, the retrieval can be continued, and if the address prefix bit number is the same, the current CIDR address block data node is the target CIDR address block data node. After comparison, the prefix bit number of the address to be retrieved is 25, and the prefix bit number of the address of the current CIDR address block data node is 24, so that the retrieval needs to be continued.
Since the address prefix bit number corresponding to the current CIDR address block data node is 24, and the binary address corresponding to the address prefix bit number is (000010101000000000000000 xxxxxx), it can be seen that the binary address corresponding to the address prefix bit number of the current CIDR address block data node is completely the same as the binary address to be retrieved corresponding to the first 24 bits of the address to be retrieved, and the next address query can be performed, and then the 25 th bit of the address prefix bit number to be retrieved in the address to be retrieved is 0 or 1.
Specifically, if the value of the binary number in the binary address to be retrieved is 0, the address pointer is adjusted to point to the left CIDR address block data node in the next index hierarchy of the current CIDR address block data node, and if the value of the binary number in the binary address to be retrieved is 1, the address pointer is adjusted to point to the right CIDR address block data node in the next index hierarchy of the current CIDR address block data node.
According to the partial CIDR address block data index shown in fig. 2, it can be seen that if the 25 th bit of the prefix bit number of the address to be retrieved in the address to be retrieved is 0, the address pointer is adjusted from the current 10.128.0.0/24 to 10.128.0.0/25; if the 25 th bit of the prefix bit number of the address to be retrieved in the address to be retrieved is 1, the address pointer is adjusted from the current 10.128.0.0/24 to 10.128.0.128/25.
Since the binary address to be retrieved is (00001010100000000000000010000111), bit 25 is obviously a 1, so the address pointer points to 10.128.0.128/25. Comparing 10.128.0.128/25, the address prefix bit number of the CIDR address block data node is the same as the address prefix bit number to be retrieved, and both are 25, so that 10.128.0.128/25 of the CIDR address block data node can be determined to be the target CIDR address block data node.
After the target CIDR address block data node is found, at least one primary key identification code may be determined based on the query operator.
If the query operator is configured to: and if the SELECT FROM t1 where 'CIDR ═ 10.128.0.135/25', the main key identification code corresponding to the target CIDR address block data node is determined to be 50.
If the query operator is configured to: and selecting FROM room t1 where 'CIDR' < '10.128.0.135/25', determining a main key identification code corresponding to the left CIDR address block data node in the next index hierarchy of the target CIDR address block data node, and determining main key identification codes corresponding to all the CIDR address block data nodes below the left CIDR address block data node in the next index hierarchy of the target CIDR address block data node.
That is, the CIDR address block data node 10.128.0.128/26 shown in fig. 2 can be determined according to the query operator, and since the index level corresponding to the CIDR address block data node 10.128.0.128/26 is the 26 th level, the finally determined primary key identifier is the primary key identifier corresponding to the CIDR address block data node 10.128.0.128/26, and the primary key identifiers corresponding to all the CIDR address block data nodes below the CIDR address block data node 10.128.0.128/26.
If the query operator is configured as SELECT FROM t1 where 'CIDR' > '10.128.0.135/25', a primary key identifier corresponding to a right CIDR address block data node in the next index hierarchy of the target CIDR address block data node and primary key identifiers corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index hierarchy of the target CIDR address block data node are determined.
It should be noted that, in the process of querying an address in the CIDR address block data index, if it is found that the CIDR address block data node corresponding to the current CIDR address block data node is a null node in the retrieval process, and the CIDR address block data node is not configured at the back of the CIDR address block data node, it is described that the configuration of the CIDR address block data index in the configuration process is incomplete, the process of querying an address may be exited.
The embodiment of the application provides an address query method, which is based on an obtained query operator, determines an address to be retrieved, determines a binary address to be retrieved and a prefix digit of the address to be retrieved through the address to be retrieved, and in a CIDR address block data index of a binary data structure, by comparing the binary address in the binary address to be retrieved and the CIDR address block data index, the prefix digit of the address to be retrieved and the prefix digit of the address, and indexing in a binary mode, the efficiency of address query can be improved, and the speed of address query can be improved.
Optionally, the CIDR address block data index may be updated, the updating of the CIDR address block data index is equivalent to newly creating a CIDR address block data node, and the original CIDR address block data node is deleted first by default, and then the creation of a new CIDR address block data node is performed, and collision detection is required to avoid data duplication. In essence, the main key identification code corresponding to the CIDR address block data node needs to be cleared first, then the CIDR address block data node is deleted, and then the CIDR address block data index is reconfigured.
Fig. 3 shows a detailed address query method provided in an embodiment of the present application, which is applied to an electronic device, where the electronic device may be a terminal device such as a computer. As shown in fig. 3, the address query method provided in the embodiment of the present application includes the following steps:
step S301: and determining the address to be retrieved based on the obtained query operator.
Step S302: and determining the binary address to be retrieved and the prefix digit of the address to be retrieved corresponding to the address to be retrieved.
Step S303: and starting to index from the initial node of the configured CIDR address block data index.
Since the index is started from the initial node, when the address query is started, the address query is performed from the CIDR address block data node with the address prefix bit number as the first bit.
Step S304: judging the binary number value of the prefix digit of the current address in the binary address to be retrieved, and if the binary number value in the binary address to be retrieved is 0, executing the step S305; if the binary number in the binary address to be retrieved is 1, step S306 is executed.
And judging the binary value in the first binary address to be retrieved, if so, adjusting the address pointer to the left CIDR address block data node of the initial node, and if so, adjusting the address pointer to the right CIDR address block data node of the initial node.
Step S305: the address pointer is adjusted to point to the left CIDR address block data node in the next index level of the current CIDR address block data node.
Step S306: the address pointer is adjusted to point to a right CIDR address block data node in a next index level of the current CIDR address block data node.
Step S307 is continuously executed regardless of whether step S305 or step S306 is executed. After the binary value identical to the first bit of the binary address to be retrieved is found in the index of CIDR address block data, step S307 is performed.
Step S307: judging whether the address prefix bit number of the current CIDR address block data node is the same as the address prefix bit number to be retrieved; if yes, go to step S308; if not, go to step S309.
Judging whether the prefix number of the address to be retrieved of the binary address to be retrieved is the same as the address prefix number of the current CIDR address block data node, if so, indicating that the binary address to be retrieved is the same as the binary address of the current CIDR address block data node, and the address prefix number of the current CIDR address block data node is the same as the prefix number of the address to be retrieved, so that the current CIDR address block data node is the target CIDR address block data node corresponding to the address to be retrieved.
If not, the address prefix bit number of the current CIDR address block data node is different from the address prefix bit number to be retrieved, the address prefix bit number of the current CIDR address block data node is added with 1, and the step S304 is returned to continue the retrieval.
Step S308: and determining the current CIDR address block data node as a target CIDR address block data node.
Step S309: and adding 1 to the prefix bit number of the current address. And returns to step S304.
Step S310: judging a query operator, and if the query operator is configured to be smaller than the address to be retrieved, executing step S311; if the query operator is configured to be equal to the address to be retrieved, executing step S312; if the query operator is configured to be larger than the address to be retrieved, executing step S313;
step S311: determining a main key identification code corresponding to a left CIDR address block data node in a next index level of the target CIDR address block data node, and determining main key identification codes corresponding to all CIDR address block data nodes below the left CIDR address block data node in the next index level of the target CIDR address block data node.
Step S312: and determining a main key identification code corresponding to the target CIDR address block data node.
Step S313: and determining a main key identification code corresponding to a right CIDR address block data node in the next index level of the target CIDR address block data node, and main key identification codes corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index level of the target CIDR address block data node.
Based on the same inventive concept, an address query device is further provided in the embodiments of the present application, and fig. 4 is a schematic structural diagram of the address query device provided in the embodiments of the present application; as shown in fig. 4, the apparatus includes:
a first determining unit 401, configured to determine, based on the obtained query operator, an address to be retrieved;
a second determining unit 402, configured to determine a binary address to be retrieved and a prefix bit number of the address to be retrieved corresponding to the address to be retrieved
The query unit 403 is configured to determine, based on the binary address to be retrieved and the prefix bit number of the address to be retrieved, a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure.
In a possible embodiment, the querying unit 403 is further configured to:
based on the binary address to be retrieved, sequentially judging the values of the binary numbers in the binary address to be retrieved according to the sequence from the first bit to the prefix bit of the address to be retrieved, and adjusting an address pointer pointing to the initial node;
and if the binary address of the current CIDR address block data node pointed by the address pointer is the same as the binary address to be retrieved, and the address prefix bit number of the current CIDR address block data node is equal to the address prefix bit number to be retrieved, determining that the current CIDR address block data node is the target CIDR address block data node.
In a possible embodiment, the querying unit 403 is further configured to:
if the value of the binary number in the binary address to be retrieved is 0, adjusting the address pointer to point to the left CIDR address block data node in the next index level of the current CIDR address block data node;
and if the value of the binary number in the binary address to be retrieved is 1, adjusting the address pointer to point to the right CIDR address block data node in the next index level of the current CIDR address block data node.
In a possible embodiment, the querying unit 403 is further configured to:
at least one primary key identification code is determined based on the query operator and the target CIDR address block data node.
In a possible embodiment, the querying unit 403 is further configured to:
if the query operator is configured to be equal to the address to be retrieved, determining a main key identification code corresponding to the target CIDR address block data node;
if the query operator is configured to be smaller than the address to be retrieved, determining a main key identification code corresponding to a left CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the left CIDR address block data node in the next index level of the target CIDR address block data node;
and if the query operator is configured to be larger than the address to be retrieved, determining a primary key identification code corresponding to a right CIDR address block data node in the next index level of the target CIDR address block data node and primary key identification codes corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index level of the target CIDR address block data node.
In a possible implementation manner, fig. 5 shows a schematic structural diagram of another address query apparatus provided in an embodiment of the present application, where the address query apparatus further includes:
a configuration unit 501, configured to determine a target storage area according to a storage space required by the index of CIDR address block data;
setting an initial node in a target storage area, and configuring a plurality of CIDR address block data nodes based on the initial node; each CIDR address block data node is configured based on the corresponding address prefix bit number and the binary address corresponding to the address prefix bit number;
creating a CIDR address block data index of a binary data structure; and the index level of the CIDR address block data index is equal to the address prefix bit number.
The embodiment of the present application further provides an electronic device, where the electronic device at least includes a memory and a processor for storing data, and for the processor for data Processing, when performing Processing, the processor may be implemented by using a microprocessor, a CPU, a GPU (Graphics Processing Unit), a DSP, or an FPGA. For the memory, the memory stores therein an operation instruction, which may be a computer executable code, and the operation instruction implements the steps in the address query method according to the embodiment of the present application.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 6, the electronic device 600 includes a memory 601, a processor 602, a data acquisition module 603, and a bus 604. The memory 601, the processor 602 and the data obtaining module 603 are all connected by a bus 604, and the bus 604 is used for data transmission among the memory 601, the processor 602 and the data obtaining module 603.
The memory 601 may be used to store software programs and modules, and the processor 602 executes various functional applications and data processing of the electronic device 600 by running the software programs and modules stored in the memory 601, such as the address query method provided in the embodiments of the present application. The memory 601 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program of at least one application, and the like; the storage data area may store data created according to the use of the electronic device 600, and the like. Further, the memory 601 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
The processor 602 is a control center of the electronic apparatus 600, connects various parts of the entire electronic apparatus 600 using the bus 604 and various interfaces and lines, and performs various functions of the electronic apparatus 600 and processes data by running or executing software programs and/or modules stored in the memory 601 and calling data stored in the memory 601. Alternatively, the processor 602 may include one or more Processing units, such as a CPU, a GPU (Graphics Processing Unit), a digital Processing Unit, and the like.
The data obtaining module 603 is configured to obtain data, such as the obtained query operator, and obtain an instruction to update the index of the CIDR address block data, and an instruction to delete a node of the CIDR address block data in the index of the CIDR address block data.
An embodiment of the present application further provides a computer-readable non-volatile storage medium, which includes program code, when the program code runs on a computing terminal, the program code is configured to enable the computing terminal to execute any one of the steps of the address query method.
In some possible embodiments, the various aspects of the address query method provided in the present application may also be implemented in the form of a program product, which includes program code for causing a computer device to perform the steps of the address query method according to various exemplary embodiments of the present application described above in this specification when the program product runs on the computer device, for example, the computer device may perform the flow of the address query method of steps S101 to S103 shown in fig. 1.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. An address query method, the method comprising:
determining an address to be retrieved based on the obtained query operator;
determining a binary address to be retrieved and prefix digits of the address to be retrieved, which correspond to the address to be retrieved;
determining a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure based on the binary address to be retrieved and the prefix bit number of the address to be retrieved; wherein the binary data structure is a search data structure including only 0 or 1 search branches.
2. The method of claim 1, wherein the configuration process of the CIDR address block data index of the binary data structure comprises:
determining a target storage area according to the storage space required by the CIDR address block data index;
setting an initial node in the target storage area, and configuring a plurality of CIDR address block data nodes based on the initial node; each CIDR address block data node is configured based on a corresponding address prefix digit and a binary address corresponding to the address prefix digit;
creating a CIDR address block data index of the binary data structure; and the index level of the CIDR address block data index is equal to the address prefix bit number.
3. The method according to claim 2, wherein the determining, based on the binary address to be retrieved and the number of prefix bits of the address to be retrieved, a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure comprises:
based on the binary address to be retrieved, sequentially judging the values of the binary numbers in the binary address to be retrieved according to the sequence from the first bit to the prefix bit of the address to be retrieved, and adjusting an address pointer pointing to the initial node;
and if the binary address of the current CIDR address block data node pointed by the address pointer is the same as the binary address to be retrieved, and the address prefix bit number of the current CIDR address block data node is equal to the address prefix bit number to be retrieved, determining that the current CIDR address block data node is a target CIDR address block data node.
4. The method according to claim 3, wherein the sequentially determining values of binary numbers in the binary address to be retrieved according to an order from a first bit to a prefix bit of the address to be retrieved based on the binary address to be retrieved, and adjusting an address pointer pointing to the initial node comprises:
if the value of the binary number in the binary address to be retrieved is 0, adjusting the address pointer to point to the left CIDR address block data node in the next index level of the current CIDR address block data node;
and if the value of the binary number in the binary address to be retrieved is 1, adjusting the address pointer to point to the right CIDR address block data node in the next index level of the current CIDR address block data node.
5. The method according to claim 1 or 2, wherein after determining the target CIDR address block data node corresponding to the address to be retrieved, the method further comprises:
determining at least one primary key identification code based on the query operator and the target CIDR address block data node.
6. The method of claim 5, wherein determining at least one primary key identification code based on the query operator and the target CIDR address block data node comprises:
if the query operator is configured to be equal to the address to be retrieved, determining a main key identification code corresponding to the target CIDR address block data node;
if the query operator is configured to be smaller than the address to be retrieved, determining a main key identification code corresponding to a left CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the left CIDR address block data node in the next index level of the target CIDR address block data node;
and if the configuration in the query operator is larger than the address to be retrieved, determining a main key identification code corresponding to a right CIDR address block data node in the next index level of the target CIDR address block data node and main key identification codes corresponding to all CIDR address block data nodes below the right CIDR address block data node in the next index level of the target CIDR address block data node.
7. An address lookup apparatus, comprising:
the first determining unit is used for determining the address to be retrieved based on the acquired query operator;
a second determining unit, configured to determine a binary address to be retrieved and a prefix bit number of the address to be retrieved corresponding to the address to be retrieved
And the query unit is used for determining a target CIDR address block data node corresponding to the address to be retrieved in a CIDR address block data index of a pre-configured binary data structure based on the binary address to be retrieved and the prefix bit number of the address to be retrieved.
8. An electronic device comprising a memory and a processor, a computer program executable on the memory on the processor, the computer program, when executed by the processor, implementing the method of any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored therein, the computer program characterized by: the computer program, when executed by a processor, implements the method of any of claims 1-6.
10. A computer program product comprising computer executable instructions for causing a computer to perform the method of any one of claims 1 to 6.
CN202111619688.8A 2021-12-27 2021-12-27 Address query method and device, electronic equipment and storage medium Pending CN114443707A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111619688.8A CN114443707A (en) 2021-12-27 2021-12-27 Address query method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111619688.8A CN114443707A (en) 2021-12-27 2021-12-27 Address query method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114443707A true CN114443707A (en) 2022-05-06

Family

ID=81365939

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111619688.8A Pending CN114443707A (en) 2021-12-27 2021-12-27 Address query method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114443707A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103051543A (en) * 2012-11-01 2013-04-17 广州微仕科信息技术有限公司 Route prefix processing, lookup, adding and deleting method
CN103561133A (en) * 2013-11-19 2014-02-05 中国科学院计算机网络信息中心 IP address ownership information indexing and fast querying method
CN105830039A (en) * 2013-12-17 2016-08-03 日本电气株式会社 Write information storage device, method, and recording medium
CN107169054A (en) * 2017-04-26 2017-09-15 四川长虹电器股份有限公司 Ip indexing means based on prefix forest
CN112800067A (en) * 2021-02-20 2021-05-14 成都佰维存储科技有限公司 Range query method and device, computer readable storage medium and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103051543A (en) * 2012-11-01 2013-04-17 广州微仕科信息技术有限公司 Route prefix processing, lookup, adding and deleting method
CN103561133A (en) * 2013-11-19 2014-02-05 中国科学院计算机网络信息中心 IP address ownership information indexing and fast querying method
CN105830039A (en) * 2013-12-17 2016-08-03 日本电气株式会社 Write information storage device, method, and recording medium
CN107169054A (en) * 2017-04-26 2017-09-15 四川长虹电器股份有限公司 Ip indexing means based on prefix forest
CN112800067A (en) * 2021-02-20 2021-05-14 成都佰维存储科技有限公司 Range query method and device, computer readable storage medium and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
杜慧军;杨宁;: "高端路由器CIDR表非关键字索引的B-Tree机制", 北京邮电大学学报, no. 05, 15 October 2009 (2009-10-15) *

Similar Documents

Publication Publication Date Title
CN110489059B (en) Data cluster storage method and device and computer equipment
CN111553670B (en) Transaction processing method and device and computer readable storage medium
CN109981493B (en) Method and device for configuring virtual machine network
CN106817236B (en) Configuration method and device of virtual network function
CN110737663B (en) Data storage method, device, equipment and storage medium
KR101754618B1 (en) A method and apparatus for generating dinamic virtual network based on software defined networks
CN116566832A (en) Method and device for generating network topology information, storage medium and processor
CN110020272B (en) Caching method and device and computer storage medium
CN112217655B (en) Network equipment configuration method and device in SD-WAN system and computer equipment
CN109144690B (en) Task processing method and device
CN116760762B (en) Decentralised ad hoc network method and device
CN114443707A (en) Address query method and device, electronic equipment and storage medium
CN104717280A (en) Data synchronism marking method and device
CN105227468A (en) One searches device, lookup method and collocation method
CN104536784B (en) Real-time system update method and device
CN116303343A (en) Data slicing method, device, electronic equipment and storage medium
CN114666311A (en) Engineering machine, and engineering machine software upgrading method and device
CN114791985A (en) Domain name matching method and device and prefix tree updating method and device
CN112822112B (en) Routing address storage method and device
CN113010151A (en) Method, system, equipment and medium for traversing dynamic options in HII database
CN113076330A (en) Query processing method and device, database system, electronic equipment and storage medium
CN111382200A (en) Information loading method and device, server and storage medium
CN111147618B (en) Communication method, communication device, electronic equipment and storage medium
US11445036B1 (en) Cluster management method and apparatus, electronic device and storage medium
CN113064720B (en) Object allocation method, device, server and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination