CN100484084C - Method for searching IP address - Google Patents

Method for searching IP address Download PDF

Info

Publication number
CN100484084C
CN100484084C CNB031541348A CN03154134A CN100484084C CN 100484084 C CN100484084 C CN 100484084C CN B031541348 A CNB031541348 A CN B031541348A CN 03154134 A CN03154134 A CN 03154134A CN 100484084 C CN100484084 C CN 100484084C
Authority
CN
China
Prior art keywords
address
node
current
mask
length
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.)
Expired - Fee Related
Application number
CNB031541348A
Other languages
Chinese (zh)
Other versions
CN1581846A (en
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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies 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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CNB031541348A priority Critical patent/CN100484084C/en
Publication of CN1581846A publication Critical patent/CN1581846A/en
Application granted granted Critical
Publication of CN100484084C publication Critical patent/CN100484084C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Abstract

The method is in use for searching and matching addresses in IP address set relevant to current IP address; global address linked list formed from IP addresses includes relation sorting, and tree indexed structure is formed according to ascending sequence by using mask length of address as node; head pointer and tail pointer of node point to IP address in global address linked list. A set of addresses intercepted on global address linked list by two pointers is contained by IP sub network represented by the node. Thus, based on mask length of configured current IP address, corresponding node is searched out from tree index structure at testing time; conflicting determination etc. operation is carried out in IP addresses in global linked list included by head pointer and tail pointer of the node.

Description

A kind of method of retrieving the IP address
Technical field
The present invention relates to the method for a kind of IP of retrieval address.
Background technology
When giving the routing device configuration of IP address, generally all to detect the IP address of configuration for the consideration of fail safe and whether conflict with existing IP address.If conflict then configuration is unsuccessful and the prompting user is then admitted the IP address of configuration and is generated corresponding route if do not conflict.For collision detection, can be divided into two class problems and solve respectively: the 1) strategy of collision detection; 2) location of IP address.
The strategy of so-called collision detection, different products has different requirements to this, and for example, the product that has does not allow to comprise mutually between the IP subnet, and the product that has then allows it to comprise arbitrarily.This strategy is only relevant with the demand of product, and it doesn't matter with the institutional framework of IP address.For collision detection is exactly to check that whether and between IP address that once disposed in the past and the subnet IP address of new configuration and subnet exist the relation that may cause ambiguity.The IP address of for example new configuration and former IP address are just the same, and it has run counter to the uniqueness of IP address; Perhaps on distinct interface, disposed IP address, made same subnet cross over a plurality of distinct interfaces, thereby can't obtain unique result when causing carrying out the longest matched and searched of IP route with same subnet, or the like.Not only need to indicate IP address itself during actual disposition IP address, but also need stipulate the subnet mask at its place, 255.255.0.0 for example, the numerical value isometric that it is made up of continuous " 1 " and " 0 " with the IP address, by IP address and mask mutually " with " can obtain so-called IP subnet.In theory, the main frame with address representative of identical IP subnet should be in the L 2 broadcast territory of a connection physically, is continuous by the Ethernet of a shared medium as them promptly.Because the only in this way now general IP algorithm of tabling look-up of long coupling could correctly E-Packet according to destination address.This shows that above-mentioned all restrictions have been arranged just, if make and when configuration of IP address, do not add collision detection, just may be because the mistake of configuration cause the unusual of system forwards, particularly all the more so when configuration is complicated.In fact exactly by the built-in checking mechanism of system several frequently seen configuration error is checked and increase collision detection mechanism, when the user does not recognize mistake, given the user with prompting, the generation of guard against false.
The location of so-called IP address is meant and finds out the address set relevant with current configuration address from a large amount of IP address, only need detect conflict and get final product in this address set.It doesn't matter to determine the strategy of this address set and collision detection, then closely related with the institutional framework of address.In fact, the operation of this location IP address address is not only used in collision detection, and in system's running, resembling the startup of Routing Protocol, such operations such as the generation of static routing also all need frequent use, so the height of its efficient will be directly connected to the performance of system.Especially for the switch product, because its supported vlans interface, and VLAN interface number a lot (2-4094) can dispose 10 IP addresses at most on each VLAN interface, the number of IP address may be very big like this.If the address that can not be from a large amount of addresses those and the address of new configuration is had no to concern weeds out, the process of then locating the IP address will be a poor efficiency.Have only the how irrelevant address of rejecting could dwindle the scope of search to greatest extent, thereby raise the efficiency, reduce useless operation.
The technical scheme of prior art one:
Manage conflict and detect and a method the most direct of search address travels through the global address chain exactly, follow on the chained list one all IP addresses that are about to this equipment disposition all string.As shown in Figure 1: during configuration of IP address, at first travel through wherein each node, use specific collision detection strategy to judge to each node along this chained list.Find conflict, then return at once and point out the user to make mistakes, otherwise just increase a node, wherein preserve IP address and the subnet mask that disposes at the end of this chained list.This chained list has a gauge outfit node.All point to oneself to pointer before and after it at the beginning, along with the continuous adding of address, this chained list constantly increases, but double-linked circular list always, and the heir pointer Compass head node of last node is so insert and delete all very convenient.
In this scheme, the IP address is to add chained list according to the sequencing that disposes, do not consider correlation inherent between the IP address, can't reject those incoherent addresses when therefore locating the IP address, have only current all IP addresses that have been configured are all traveled through one time, will judge all that to each IP address wherein it is very low therefore to carry out efficient according to predefined collision detection strategy, will be very consuming time when this IP address, method location of frequent use.
The technical scheme of prior art two:
Want to realize quick location, the way in can the comparable data storehouse---set up index structure according to certain contact of data.By the index that search is set up by relation between the address, can find relevant address set fast, and judge on this basis whether to exist between this IP address and the IP address that newly disposes and conflict.This shows, set up the demand that index structure has following two aspects: the function of search of (1) index structure is powerful, and locating speed is fast; (2) maintenance of index structure is simple as far as possible, and time and space expense is little.Balance two difference tree (AVL) a kind of index structure that comes to this.
Balance two difference tree (AVL) outstanding features are that the absolute value of the difference in height of the left and right sides subtree of any one subtree (comprising itself) among the AVL is no more than 1.Under the situation of identical leaf node, the degree of depth of tree is minimum like this, that is to say, the number of times of inquiry is minimum, and its time complexity is O (log2N).Scheme after improving on the basis of the balance two difference trees of existing program and standard now.The AVL algorithm of standard only requires that the difference in height of left and right sides subtree is no more than 1, but when leaf node was even number, the height of left and right sides subtree will differ from 1, and correspondingly also can there be small difference in the searching route along different subtrees.Can accomplish left and right sides subtree symmetry fully and improve back AVL algorithm, the degree of depth of no matter along what path passing by is the same.In fact, the AVL strictness after the improvement should be can be regarded as three difference trees in fact, and promptly it also has a pointer in the centre of left and right sides subtree, an IP address that has more when being used for specially depositing IP address number for even number.When the IP address is odd number, then be that a left and right sides subtree difference in height is 0 standard two difference trees like this; And when number is even number, a unnecessary IP address is hung on the middle pointer with balance left and right sides subtree.
No matter consult Fig. 3, be the AVL or the improved AVL of standard, and their characteristics are exactly to carry out the accurate comparison of numerical value, can only carry out the accurate coupling of 32 bits for the IP address, can not resemble to look into to carry out the longest coupling the routing table.Therefore, whether be configured, use finding very much of aspect of Adelson-Velskii-Landis tree if only want the IP address itself of determining new configuration.But since in the strategy of the collision detection of IP address except IP above-mentioned address itself can not equate, the IP subnet can not be identical.So outside the Adelson-Velskii-Landis tree that has compared the IP address, also need the Adelson-Velskii-Landis tree of Searching I P subnet.Because IP subnet mask ground value from 1 to 31 (in fact maximum can only get 30) correspondingly, also needs to preserve the Adelson-Velskii-Landis tree of 31 stalk nets except preserving ground, IP address Adelson-Velskii-Landis tree in inside.During actual retrieval, do not consider earlier the Adelson-Velskii-Landis tree of subnet mask with IP address check address, if do not find conflict, then with IP address and mask to " with " take out network portion, length according to mask searches for whether there is same subnet in corresponding subnet Adelson-Velskii-Landis tree, if also can not find identical node, then think and do not conflict.That is to say judge whether an IP address conflicts, need twice Adelson-Velskii-Landis tree of inquiry at most, consult flow chart shown in Figure 3.Because the difference in height of any left and right sides subtree of this scheme is 0, therefore when increasing or deleting an IP address, may relate to the change of whole Adelson-Velskii-Landis tree, and the change algorithm of every grade of subtree is identical, therefore, adopt the method for recurrence during realization.Detailed process is as follows:
When (1) inserting, if the IP address that increases newly equate than the numerical value of present node, show then that this node has existed needn't insert in Adelson-Velskii-Landis tree, return at once, otherwise change (2)
(2), change (5) if there is intermediate node in this node; Otherwise change (3)
(3) if newly-increased IP address is littler than present node numerical value, change (4), otherwise be this function of root node recursive call with the right subtree node.After recurrence is returned, from right subtree, extract the IP address of minimum value again, put it on the current root node, and the IP address in the root node is suspended on the intermediate node.Finish
(4) be this function of root node recursive call with the left subtree node.After recurrence is returned, from left subtree, extract the IP address of greatest measure again, it is suspended on the intermediate node.Finish
(5) if newly-increased IP address is littler than present node numerical value, change (6), otherwise be this function of root node recursive call with the right subtree node.After recurrence is returned, with the left subtree node be root node once more this function of recursive call intermediate node is inserted in the left subtree, finish
(6) be this function of root node recursive call with the left subtree node.After recurrence is returned, intermediate node is put on the current root node, and the IP address on the present node is inserted in the right subtree, finish.
With regard to single numerical value comparatively speaking, Adelson-Velskii-Landis tree beyond doubt the most fast.But because the essence of Adelson-Velskii-Landis tree can only be carried out the accurate coupling of numerical value, and can not carry out the comparison of inclusion relation, and the IP address itself being a kind of addressing scheme of stratification, is born with and has the relation that comprises mutually in its sky.Therefore, will inevitably there be some problems in the collision detection of carrying out the IP address with Adelson-Velskii-Landis tree.For example, it also needs (1) to search Adelson-Velskii-Landis tree once more to determine whether to exist consistent subnet with the IP subnet except comparing IP address itself; (2) Adelson-Velskii-Landis tree can only detect that the IP address equates and subnet equates, and can not detect the subnet inclusion relation, and for some product, possible it be exactly not allow subnet to comprise.In addition, Adelson-Velskii-Landis tree does not utilize the inclusion relation between the IP address, makes it support some new demand sides to seem unable to do what one wishes, if for example want to retrieve all IP addresses that this equipment disposes etc. in certain scope.The position fixing process of safeguarding Adelson-Velskii-Landis tree from above as can be seen, that is the recursive procedure of a complexity, every increase or delete the change that whole Adelson-Velskii-Landis tree may be brought in an IP address.And it need safeguard the Adelson-Velskii-Landis tree of an IP address and the Adelson-Velskii-Landis tree of 31 stalk nets simultaneously, from the time still be the expense of aspect, space all be bigger.When the IP address number is little, can also bear, but for the product that resembles supported vlans interfaces such as switch, expense is very huge.Its basic reason also is IP address and subnet to be isolated come, and causes safeguarding IP address and subnet thereof simultaneously.
Summary of the invention
At the deficiencies in the prior art, the object of the present invention is to provide the method for a kind of IP of retrieval address.
Technical scheme of the present invention: a kind of method of retrieving the IP address, according to the current IP address that provides at least secondary IP address concentrate the relevant IP address of search, the IP address in the described IP address set forms the global address chained list, this method comprises following step:
A, obtain the mask-length of pending IP address;
B, press ascending sequence according to the mask-length of the IP address of the configuration of node correspondence and form the tree index structure, root node from described tree index structure, the mask-length of node representative and the mask-length of current IP address are compared, if find first present node, then continue step c more than or equal to the mask-length of current IP address; Otherwise change step e;
Whether the subnet of the IP address that the subnet of c, comparison current IP address and present node are corresponding is identical, if identical then carry out steps d, if inequality then carry out step e;
All IP addresses that from the global address chained list, intercepted between d, the head pointer of obtaining present node and the tail pointer, the described IP address that intercepts is comprised by the subnet of the IP address of present node correspondence, and adopts the strategy of the conflict of judgement that each IP address is judged; If find conflict then point out and finish retrieval, otherwise carry out step e;
E, affirmation current IP address are not conflicted with existing IP address and current IP address are joined in the described global address chained list.
A kind of method of retrieving the IP address, secondary IP address are deleted after concentrating and searching current IP address, and the IP address in the described IP address set forms the global address chained list, and this method comprises following step:
The mask-length of a, acquisition current IP address;
B, press ascending sequence according to the mask-length of the IP address of the configuration of node correspondence and form the tree index structure, root node from described tree index structure, the mask-length of node representative is compared with the mask-length of current IP address, find the mask of current IP address to be less than or equal to the present node of the mask-length that node represents;
Whether the subnet of the IP address that c, comparison current IP address and present node are corresponding is identical, if identical then carry out steps d, if inequality then prompting would not have current IP address and finishes;
All IP addresses that d, the head pointer of obtaining present node and tail pointer are intercepted from the global address chained list, the described IP address that intercepts is comprised by the subnet of the IP address of present node correspondence, from these IP addresses, search current IP address, if find then delete this current IP address, and carry out step e; Do not have IP address to be deleted and finish if find then point out;
E, find node corresponding, and this node is handled according to the pointer of preserving in the current IP address in the global address chained list that return to refer to the index tree internal node.
Wherein: described tree index structure is a kind ofly can realize the data structure of the binary tree of long coupling.
Described global address chained list is pressed the inclusion relation ordering of IP address, and the head pointer of node and all IP addresses that tail pointer is intercepted from this global address chained list are comprised by the IP subnet of this node representative in the tree index structure.
The present invention can locate the IP address set that needs easily by organizing radix tree and IP address link list.Because during search, inquiry radix sets earlier, and its time complexity is O (log2N).No matter dispose what IP addresses, at most only need the IP address structure that inquiry can be found for 32 times to be needed.Provide any one IP subnet and just can find out in the current system all fast, and needn't search for whole address chain by its IP address set that comprises.This point is that Adelson-Velskii-Landis tree is not available.
Adelson-Velskii-Landis tree can not provide the function of inclusion relation between the inquiry IP subnet.If certain product does not allow the IP address to comprise mutually, then Adelson-Velskii-Landis tree is just powerless.And radix tree itself is with the inclusion relation tissue, and big more the closer to the subnet scoping of the node representative of root, the father node subnet must comprise the subnet of child node correspondence.Therefore, the present invention just supports to detect the inclusion relation of IP address naturally.Like this, just can finish the multiple function that IP address detected and IP subnet detect and subnet comprises simultaneously, will not inquire about many trees and do not resemble the AVL algorithm by the inquiry one tree.
Safeguarding aspect the index structure, increasing and safeguarding that the expense of a radix tree is lower than two trees of maintenance of AVL algorithm during deletion IP address.And, only just safeguard the expense of one tree, the radix tree is also low than Adelson-Velskii-Landis tree.This is because radix tree and do not require the complete symmetry of tree structure, the scope that its is revised only be confined to the two-layer up and down of a node and with tree in other nodes it doesn't matter, so the algorithm of radix tree is a constantly one-way process of search downwards; The structure of Adelson-Velskii-Landis tree is then wanted the many of strictness, revise the change that a node may cause whole tree structure, so Adelson-Velskii-Landis tree need be finished the modification of each node layer by a recursive procedure.When increasing the IP address, the radix tree needs traversal 32 node layers just can find the place of inserting node at most, upgrading up and down then, the pointer of two-stage node gets final product, and not as the recursive algorithm of AVL, increase a node and need consider the variation that brings to node on each aspect up and down, though not necessarily all nodes all change, need at least whole tree all traveled through one time.During deletion IP address, because the pointer that refers to the radix tree node is arranged back in address structure, therefore not need to search for the internal node that the radix tree just can be determined needs deletion, deleting an internal node equally only needs also that the pointer of two-stage node gets final product about the modification.
Description of drawings
Fig. 1 is the list structure schematic diagram of the technical scheme of prior art one;
Fig. 2 is the index structure schematic diagram of the technical scheme of prior art two;
Fig. 3 is the flow chart that prior art two detects the IP address;
Fig. 4 is the switch-type router structured flowchart;
Fig. 5 is the related schematic diagram with index structure of overall chained list of IP address among the present invention;
Fig. 6 is a flow chart of the present invention.
Embodiment
Consult shown in Figure 4ly, in order to improve the forwarding rate of router, switch-type router has adopted to be transmitted and structure that control is separated.Flow enters from the incoming interface card and exchanges to the outgoing interface card through switching network after the back is transmitted by the inquiry of network processing unit or ASIC hardware circuit and forward, everything work is most of to be finished by hardware, do not need the participation of route processing unit, can reach very high forwarding rate.Moving the main control software of router in the route processing unit, mainly be responsible for receiving user's configuration order, generating forwarding-table item by Routing Protocol and be issued in network processing unit or the ASCIC hardware circuit for transmitting use.And the primary prerequisite that will generate forwarding-table item is exactly interface configuration IP address and mask to router, and the IP address of other configuration of routers is acquired by Routing Protocol by this equipment and just formed the forwarding-table item that arrives destination network segment.Can the correctness of IP address configuration is directly connected to flow correctly arrive the destination, therefore need do some testings during configuration of IP address, in case IP address and original IP address of new configuration clash, problem is controlled on the source as far as possible, in order to avoid the diffusion of information of mistake is caused confusion in whole network.
IP address and mask have confidential relation, when judging collision detection, need not only to judge whether the IP address is identical, but also need to judge whether subnet is identical, even some product does not also allow comprising of subnet and more complicated strategy.And these strategies have nothing to do with adopting any index structure, just need all carry out above-mentioned strategy to all possible IP address and judge, omit to get final product.
Consult Fig. 5, the part in the dotted line is exactly a tree index structure of the present invention, and this tree can be realized the data structure of the binary tree of long coupling (being called for short the radix tree) for a kind of, is used for locating fast IP address and set thereof.And the IP address in the global address chained list is according to its inclusion relation ordering.
The radix tree is to organize like this: according to the mask-length of the IP address that disposes, insert an internal node in the radix tree, KEY value wherein is exactly the length of IP address mask.Simultaneously the data structure of this IP address correspondence is inserted in the global address chained list according to the size of IP subnet, and pointed to IP address structure in the global address chained list simultaneously with head pointer begin_ptr on this internal node and tail pointer end_ptr.These two pointers are comprised by the IP subnet of this internal node representative all from the sector address set that the global address chained list intercepts, be the mask of this section IP address all the KEY value than this internal node appointment is long, and the mask phase of their IP addresses by the representative of KEY value " with " after network portion all identical.The IP subnet that an internal node representative is for example arranged is 10.1.0.0/255.255.0.0, then its KEY value is 16, its head pointer begin and the tail pointer end pointer IP address of drawing together all is following form so, 10.1.X.X/255.255.X.X, wherein X can be 0, can not be 0 also, just so-calledly be comprised by subnet 10.1.0.0/255.255.0.0.
Internal node can be navigated to fast by search radix tree during retrieval, the IP address structure that needs can be directly obtained by head pointer begin_ptr in the internal node and tail pointer end_ptr pointer again.In addition, search for the radix tree during for fear of deletion IP address once more, in the IP address structure, increase a pointer that oppositely points to radix tree internal node, when deletion can directly be found the internal node that needs deletion by this pointer like this, if just can directly delete internal node (detailed process of deleting internal node is introduced below) when not having the IP address of other same subnet on this node.If having disposed a plurality of mask-lengths equates, and during the identical IP address of subnet, because all returning, they point to same internal node in the radix tree, so they are inserted on the position that is close in the overall chained list, the position is specified by the head pointer begin_ptr and the tail pointer end_ptr of radix tree internal node respectively end to end.For example on ethernetl, disposed the primary ip address of 10.1.1.1/255.255.255.0, on same interface, disposed the secondary IP address of 10.1.1.2/255.255.255.0 then again, then the backward pointer in these two IP addresses points to same internal node, they come on the continuous position of overall chained list by the sequencing that inserts, head pointer begin_ptr points to 10.1.1.1/255.255.255.0, and tail pointer end_ptr points to 10.1.1.2/255.255.255.0.
At the IP address set of being drawn together by head pointer begin_ptr and tail pointer end_ptr such characteristics are arranged on the whole not only, and portion also is according to certain rule compositor within it.IP overall situation chained list after the rearrangement has such characteristics: the IP address set that any one node left and right sides pointer is drawn together is made up of three following subclass: [all IP addresses that dispose on the root node] [the IP address of node configuration in the left subtree] [IP address of right subtree node configuration].Wherein so-called [all IP addresses that dispose on the root node] are exactly the address link list that mask equates, subnet is identical that is configured on the root node above-mentioned; And so-called [the IP address set of left and right sides subtree configuration] intercepted the IP address field with left and right sides child by the subtree that root forms respectively, they also are to organize in this order, that is to say that this relation is a kind of order of recurrence, till leaf node.For example, comprise following three IP address: 10.1.1.1/255.255.0.0,10.1.127.1/255.255.255.0 and 10.1.129.1/255.255.255.0 in the current system.Just have three nodes in the radix tree so, root node KEY value is 16, represents 10.1.1.1/255.255.0.0; The KEY value of left sibling is 24, represents 10.1.127.1/255.255.255.0; And right son's KEY value also is 24, represents 10.1.129.1/255.255.255.0.Like this, i.e. tissue: [10.1.1.1/255.255.0.0] [10.1.127.1/255.255.255.0...] [10.1.129.1/255.255.255.0...] in the following order of the IP address chain that intercepted of the head pointer begin_ptr of root node and tail pointer end_ptr.
Certainly, this set not necessarily comprises this three parts fully, for example, if present node does not have left subtree, does not then have second portion; Do not have right subtree, then do not have third part; And do not have configuration of IP address on the root node, then there is not first; When left and right sides subtree did not all have, then begin_ptr and end_ptr equaled on the IP address of internal node KEY value with regard to the mask that points to configuration, if such IP address has only disposed one, then begin_ptr and end_ptr pointer all point to this IP address.Correspondingly, if certain part of radix tree is deleted, the left and right sides pointer of node also needs to adjust accordingly.For example with after all IP address deletions of disposing on the node, the head pointer begin_ptr of this node just need readjust the head pointer begin_ptr into its left son or right son.
Detect conflict process just locate the process of this IP address particular location in the radix tree, detect and just found the accurate position of inserting radix after finishing in fact.It is that to detect conflict IP address with desire be operand, along continuing to advance from the direction of radix root node to leaf node.Whenever, can obtain the KEY value of this node appointment, the mask of the IP address of this KEY value and current operation is compared through a radix node.If the KEY value is more than or equal to having disposed the IP address on the IP mask of current operation and this radix node, the IP address of then indicating current operation should be inserted in the top (because the radix tree from top to down of this radix node certainly, the KEY value constantly increases progressively), no longer need down to have advanced again; Otherwise with this KEY value is the numerical value of corresponding bit on sequence number (this sequence number is since 0) the detecting operation object.If this bit is 0, then continue to set out to the left subtree of current radix; Otherwise set out to right subtree.Like this, in constantly advancing and detecting till going to leaf node.For example, the following IP address 10.1.1.1/255.255.255.0 of configuration.In current radix tree four nodes are arranged, their KEY value is respectively 8,16,24 and 32.At first run into KEY value like this and be 8 node on the path that advances, relatively the back finds that KEY value (8) is littler than the mask (255.255.255.0) of current address, then shows needs continuation propelling.Be that sequence number detects the 9th bit (because the KEY value begins with 0, therefore actual is the 9th bit) then with KEY, found that it is 0, then set out along left subtree.Second node and the like, up to the 3rd node.This moment, its KEY value also was 24, equated with the IP mask and had disposed IP address, then no longer down searching.Next the IP address that the is exactly more current operation IP address bit-by-bit corresponding with the 3rd node compares, find out the sequence number diff_bit at first different bits place, this sequence number diff_bit<=MIN (current IP address mask, the KEY value of present node).According to the different numerical value of sequence number diff_bit, need carry out different processing.It is as follows to consult idiographic flow shown in 6:
Step 10: the mask-length that obtains the current IP address of configuration;
Step 20: the root node of getting the radix tree is a present node;
Step 30:, then change step 40 if the subnet mask of configuration is littler or equal than present node KEY value; Otherwise the IP address of judging current configuration is in the specified bit place value of present node KEY value.If be 1, then getting right child node is present node; Otherwise get left child node is present node, compares again in commentaries on classics step 30 then, until changeing step 40;
Step 40: relatively the IP address of the IP address of present node correspondence and new configuration with mask mutually " with " after the subnet portion that obtains whether equate, if equal commentaries on classics step 50; Otherwise find out the bit diff_bit that first does not wait, change step 60, show that the formed subnet in IP address of new configuration does not comprise any existing subnet this moment, but still may be comprised by bigger subnet, diff_bit is exactly current IP address is inserted needs the internal node of bifurcated when radix sets a KEY value.
Step 50: the IP address of configuration same subnet before showing, search in the address set that only need draw together at the head pointer begin_ptr and the tail pointer end_ptr of this node this moment, each IP call by location is wherein judged that the strategic function of conflict gets final product.If find conflict, prompting IP address configuration mistake is also returned; Do not find conflict behind the IP address in relatively intacter set, can think that then this address is legal.
Step 60: do not wait bit and the mask of new configuration and the relation of present node bit according to first, can be divided into three kinds of situations:
If the bit diff_bit that a does not wait equals present node KEY value, the IP address that then will newly dispose is as the subtree of present node;
If the bit diff_bit that b does not wait equals the mask-length of new configuration of IP address, then with the subtree of present node as the IP address of new configuration;
If c does not wait bit diff_bit littler than the mask-length of present node KEY value and new configuration of IP address, a then newly-built node is as node of divergence, and the IP address of present node and new configuration is the brother each other, all as the left and right sides subtree of node of divergence.
Any situation no matter, all need according to difference detect conflict strategy detection father nodes at different levels from bottom to top the IP address whether with the address conflict of new configuration.For example,, then only need to detect whether identical getting final product of IP address itself, otherwise whether identical also need to detect the IP subnet except IP address itself or comprise if allow subnet to comprise.
From top structure as can be seen, the starting point of radix tree is the inclusion relation of safeguarding between the IP address, and it provides the inner link between the IP address in the most detailed system.No matter the collision detection of each product has any specific demand, only needs to change a strategic function and get final product, and needn't change the structure that radix sets.This mainly is that itself is just implying this inclusion relation because the IP address is a kind of address of stratification, this with some address system in the addressing method of non-stratification be different.Pay close attention to IP subnet rather than IP address more in IP address family, because can regard single IP address as IP subnet with 32 complete 1 masks, therefore the base unit of also the IP subnet being formed as its logic among the Internet just needs the new network segment that distributes an IP subnet during network of every increase.Only be the whole implications that are difficult to accurate description its representative itself with regard to the IP address, have only the huge use that forms different subnet structure competence exertion IP addresses by mask, for example to add mask by the IP address exactly just well-determined for the route in the routing table.The radix tree has met this point just and could adapt to each different demand, and AVL does not consider getting in touch between IP address and the mask just, and only merely relatively the size of two numerical value is just feasible supports the demand of different product to become very difficult.
Check when not having conflict, the IP address that just needs newly to dispose is inserted in the radix tree according to mask-length, the method of its method and collision detection above-mentioned is basic identical, here repeat no more, be inserted in the global address chained list according to pointer begin_ptr in its corresponding radix internal node and pointer end_ptr position simultaneously.
Need do opposite action when deleting an IP address, the IP address is extractd from global address chained list and radix tree.From overall chained list is a doubly linked list, and it is very simple to extract one of them node; And excision at first needs to find corresponding internal node from the radix tree, just need use returning of preserving in the IP address this moment and refer to that radix sets the pointer of internal node.Node according to this pointer can find needs to delete at once is divided into three kinds of situations then and handles respectively:
1) if there is left and right sides subtree simultaneously in node, then this node need keep as node of divergence, can return at once
2) if node left and right sides subtree does not all have, then delete this node.This node of sensing middle finger pin of father node is emptied.If this moment, father node also had the IP address to be attached thereto, then father node need keep at once and returns, and is present node otherwise get father node, changes 3);
3) if having only left subtree or have only right subtree, then delete this node, simultaneously left subtree or right subtree are suspended to this node on the respective pointer of its father node.
No matter be above-mentioned any situation, after handling internal node, need to check whether need the head pointer begin_ptr of mobile father node and the pointer of tail pointer end_ptr.Whether need to move actually and can carry out with reference to following principle:
(1) if IP address to be deleted had not both been pointed to by the head pointer begin_ptr of internal node not to be pointed to by tail pointer end_ptr, then need not adjust this two pointers yet, can return.
(2) iff being pointed to by head pointer begin_ptr, then show first IP address that this IP address is its place subnet, only need shift to tail pointer begin_ptr pointer a back IP address this moment.If present node is positioned on the left subtree of its father node, then father node is repeated this principle as present node, otherwise directly return.
(3) iff being pointed to by tail pointer end_ptr, then show last IP address that this IP address is its place subnet, only need shift to tail pointer end_ptr previous IP address this moment.If present node is positioned on the right subtree of its father node, then father node is repeated this principle as present node, otherwise directly return.
(4) if pointed to by head pointer begin_ptr and tail pointer end_ptr simultaneously, show that then it is a unique IP address that disposes in this subnet, need delete internal node in the lump this moment, and adjust the head and the tail pointer of its father node.Be made as present node with father node this moment, reuses this principle and get final product.
This shows, insertion is still deleted all very simple, at most only need to revise the pointer in father and son's two-stage node, and do not relate to other nodes, thereby modification is limited within the very little scope, this and very big again different of the recursive algorithm of Adelson-Velskii-Landis tree, this also is one of advantage of radix algorithm.
The radix tree itself is exactly a kind of hierarchical setting, is particularly suitable for organizing resembling the IP address and needing so the address structure of long coupling.But the algorithm of radix tree has only defined the internal node of tree, and the external node of tree is not stipulated.This just organizes external data to the user of radix tree with great flexibility.This programme is included all IP addresses that comprise in the subnet interior by head pointer begin_ptr and two pointers that point to overall chained list of tail pointer end_ptr, thereby realize the purpose of location relative address set fast, only need one section chained list of probe pointer begin_ptr and tail pointer end_ptr definition to get final product when correspondingly traveling through the IP address in the relative address set.Except that this method, can also exist method for distinguishing to organize the external node of radix tree.For example, can be outside the global ip address chained list, distribution structure is preserved IP address and mask in addition, and these data structures that will have same subnet number simultaneously conspire to create a chained list and are suspended on the internal node of radix.Such method can be finished the address conflict measuring ability equally, but need take extra memory, and need adopt the method for traversal radix tree during the IP address in the traversal relative address set, than the method complexity of the traversal doubly linked list in this programme.

Claims (12)

1, a kind of method of retrieving the IP address, according to the current IP address that provides at least secondary IP address concentrate the relevant IP address of search, the IP address in the described IP address set forms the global address chained list, it is characterized in that this method comprises following step:
The mask-length of a, acquisition current IP address;
B, press ascending sequence according to the mask-length of the IP address of the configuration of node correspondence and form the tree index structure, root node from described tree index structure, the mask-length of node representative and the mask-length of current IP address are compared, if find first present node, continue step c more than or equal to the mask-length of current IP address; Otherwise carry out step e;
Whether the subnet of the IP address that the subnet of c, comparison current IP address and present node are corresponding is identical, if identical then carry out steps d, if inequality then carry out step e;
All IP addresses that from the global address chained list, intercepted between d, the head pointer of obtaining present node and the tail pointer, the described IP address that intercepts is comprised by the subnet of the IP address of present node correspondence, and adopts the strategy of the conflict of judgement that each IP address is judged; If find conflict then point out and finish retrieval, otherwise carry out step e;
E, affirmation current IP address are not conflicted with existing IP address and current IP address are joined in the described global address chained list.
2, the method for claim 1 is characterized in that, described tree index structure is a kind ofly can realize the data structure of the binary tree of long coupling.
3, method as claimed in claim 1 or 2 is characterized in that, described global address chained list is pressed the inclusion relation ordering of IP address.
4, method as claimed in claim 3 is characterized in that, if there are a plurality of mask-lengths to equate and the identical IP address of subnet in the global address chained list, then arrange in overall chained list continuously this a plurality of IP address.
5, the method for claim 1, it is characterized in that, among the step b, when the mask-length of current IP address is bigger than the mask-length of present node representative, judge that current IP address is used to represent the bit value of the specified position of KEY value of IP address mask length at present node, if be 1 then to get right child node be that present node continues relatively, be that present node continues relatively otherwise get left child node.
6, the method for claim 1, it is characterized in that, among the step c, when the subnet of the IP address that the subnet of current IP address is corresponding with present node is inequality, the IP address bit-by-bit corresponding with present node by current IP address compares, determine the sequence number that first does not wait bit, and handle respectively according to the mask of this sequence number and current IP address and the relation of present node bit:
(1) if described sequence number equals the mask-length of present node representative, then with the subtree of current IP address as present node;
(2) if described sequence number equals the mask-length of current IP address, then with the subtree of present node as current IP address;
(3) if described sequence number is all littler than the mask-length of the mask-length of present node representative and current IP address, a then newly-built node is as node of divergence, and present node and current IP address are fraternal each other, all as the left and right sides subtree of node of divergence.
7, a kind of method of retrieving the IP address, secondary IP address are deleted after concentrating and searching current IP address, and the IP address in the described IP address set forms the global address chained list, it is characterized in that this method comprises following step:
The mask-length of a, acquisition current IP address;
B, press ascending sequence according to the mask-length of the IP address of the configuration of node correspondence and form the tree index structure, root node from described tree index structure, the mask-length of node representative is compared with the mask-length of current IP address, find the mask of current IP address to be less than or equal to the present node of the mask-length that node represents;
Whether the subnet of the IP address that c, comparison current IP address and present node are corresponding is identical, if identical then carry out steps d, if inequality then prompting would not have current IP address and finishes;
All IP addresses that d, the head pointer of obtaining present node and tail pointer are intercepted from the global address chained list, the described IP address that intercepts is comprised by the subnet of the IP address of present node correspondence, from these IP addresses, search current IP address, if find then delete this current IP address, and carry out step e; Do not have IP address to be deleted and finish if find then point out;
E, find node corresponding, respectively node handled by following situation according to the pointer of preserving in the current IP address in the global address chained list that return to refer to the index tree internal node:
(1) if there is left and right sides subtree simultaneously in node, then this node keeps as node of divergence, end process;
(2) if node does not have subtree, then delete this node, the pointer that father node is pointed to this node empties; If this moment, father node also had the IP address to be attached thereto, then end process is a present node otherwise get father node, carries out step (3);
(3) if node has only left subtree or has only right subtree, then delete this node, simultaneously left subtree or right subtree are suspended to this node on the respective pointer of its father node.
8, method as claimed in claim 7 is characterized in that, described tree index structure is a kind ofly can realize the data structure of the binary tree of long coupling.
9, method as claimed in claim 7 is characterized in that, described global address chained list is pressed the inclusion relation ordering of IP address.
10, method as claimed in claim 7 is characterized in that, if there are a plurality of mask-lengths to equate and the identical IP address of subnet in the global address chained list, then arrange in overall chained list continuously this a plurality of IP address.
11, method as claimed in claim 7, it is characterized in that, among the step b, when the mask-length of current IP address is bigger than the mask-length of present node representative, judge that current IP address is used to represent the bit value of the specified position of KEY value of IP address mask length at present node, if be 1 then to get right child node be that present node continues relatively, be that present node continues relatively otherwise get left child node.
13, method as claimed in claim 7 is characterized in that, also comprises behind the processing node head pointer and the tail pointer of node are handled by following situation:
(1) if the IP address of deletion is only pointed to by the head pointer of node, then head pointer is shifted to a back IP address;
(2) if the IP address of deletion is only pointed to by tail pointer, then tail pointer is shifted to previous IP address;
(3) if the IP address of deletion is pointed to by head pointer and tail pointer simultaneously, then delete head pointer and tail pointer.
CNB031541348A 2003-08-12 2003-08-12 Method for searching IP address Expired - Fee Related CN100484084C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB031541348A CN100484084C (en) 2003-08-12 2003-08-12 Method for searching IP address

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB031541348A CN100484084C (en) 2003-08-12 2003-08-12 Method for searching IP address

Publications (2)

Publication Number Publication Date
CN1581846A CN1581846A (en) 2005-02-16
CN100484084C true CN100484084C (en) 2009-04-29

Family

ID=34580144

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB031541348A Expired - Fee Related CN100484084C (en) 2003-08-12 2003-08-12 Method for searching IP address

Country Status (1)

Country Link
CN (1) CN100484084C (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100444171C (en) * 2006-08-15 2008-12-17 北京金山软件有限公司 Method for searching IP dictionary and engine device for searching words
CN101437016B (en) * 2007-11-16 2012-06-06 北京乾坤化物数字技术有限公司 Method for building IP address structure tree
CN102214182A (en) * 2010-04-12 2011-10-12 北京银万特科技有限公司 Accurate query searching method according to internet protocol (IP) address
CN103020054B (en) * 2011-09-20 2016-04-13 深圳市金蝶中间件有限公司 Fuzzy query method and system
CN105897943A (en) * 2015-11-19 2016-08-24 乐视致新电子科技(天津)有限公司 Intelligent device searching method and device
CN107682266B (en) * 2017-09-12 2021-02-26 杭州迪普科技股份有限公司 Method and device for matching flow table items and computer-readable storage medium
CN112737830B (en) * 2020-12-25 2022-07-29 杭州迪普科技股份有限公司 Method and device for calibrating detection target information reported by mechanism
CN114268608A (en) * 2021-12-20 2022-04-01 卓米私人有限公司 Address segment retrieval method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN1581846A (en) 2005-02-16

Similar Documents

Publication Publication Date Title
Liu et al. NET–a system for extracting web data from flat and nested data records
US11599535B2 (en) Query translation for searching complex structures of objects
EP2040184B1 (en) Database and database processing methods
US8176034B2 (en) Method for integrating road names and points of interest in source data
US20090119257A1 (en) Method and apparatus for searching a hierarchical database and an unstructured database with a single search query
CN107154899B (en) System for searching IP route by suffix index
US20070192564A1 (en) Methods and arrangements for inserting values in hash tables
CN101436192A (en) Method and apparatus for optimizing inquiry aiming at vertical storage type database
JP4747094B2 (en) DML statement for densifying data in a relational database system
CN1377543A (en) Method and apparatus for four-way hash table
CN108681603B (en) Method for rapidly searching tree structure data in database and storage medium
CN100385880C (en) Packet classification apparatus and method using field level tries
CN101110812A (en) Text command analyzing and processing method
CN100484084C (en) Method for searching IP address
CN104536958A (en) Composite index method and device
CN103020054A (en) Fuzzy query method and system
WO2015010509A1 (en) One-dimensional liner space-based method for implementing trie tree dictionary search
Yuan et al. Keyword search over distributed graphs with compressed signature
CA2461871A1 (en) An efficient index structure to access hierarchical data in a relational database system
Mpinda et al. Evaluation of graph databases performance through indexing techniques
CA3140362C (en) Methods, systems, and media for resolving graph database queries
CN110990423B (en) SQL statement execution method, device, equipment and storage medium
US8166043B2 (en) Bit strings search apparatus, search method, and program
CN106302178B (en) Route query method and device
RU2433467C1 (en) Method of forming aggregated data structure and method of searching for data through aggregated data structure in data base management system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20090429

Termination date: 20150812

EXPY Termination of patent right or utility model