Summary of the invention
The object of the present invention is to provide a kind of method and device that helps the maintaining routing list of multi-protocols coexistence simply, efficiently.
For achieving the above object, the method for maintaining routing list provided by the invention comprises:
(1) receiving the RIP packet, is that RIP request package or RIP respond packet ask respectively to handle or response is handled according to the packet that receives;
(2) set up the structure of RIP interface table; Set up RIP request package, triggering renewal RIP bag and cycle renewal RIP bag, as required RIP request package, triggering renewal RIP bag and the cycle renewal RIP bag interface by appointment is sent;
(3) initiate Routing Protocol module is registered, and be provided at the handling function that increases and delete route in the routing table for it; When the described handling function of Routing Protocol module invokes adds route, route and routing protocol priority that protocol module is added record in the own routing information base of safeguarding, then according to the treaty override level of each route of same purpose and tolerance and these three factors decisions of life span any bar route adding kernel routing table; When the described handling function deletion of Routing Protocol module invokes route, delete this route entry in own routing information base and the kernel routing table;
(4) the timed sending cycle is upgraded the RIP bag, when the routing table li is changed by clauses and subclauses, sends to trigger and upgrades the RIP bag;
When (5) interface of described appointment newly starts, send router RIP request package in the mode of broadcasting.
The present invention also comprises:
Set up the structure of RIP bag, be used to set up the RIP bag,
Order: the kind that is used to identify the RIP bag;
This structure comprises following field:
Version number: the version number that is used to identify the RIP agreement;
Route entry: be used to identify routing iinformation.
Set up the structure of route entry table, this structure comprises following field
The purpose prefix; The destination address that is used for identification data packet;
Routing tag; Be used for the inner or outside route of sign;
Prefix length: the number of bits that is used for the recognition purpose prefix;
Route metric: be used to identify this router to the destination router the router number of process.
Set up the routing table structure, described routing table comprises following field:
Next clauses and subclauses: be used to indicate next route entry;
Route entry: be used to store this route entry;
Gateway address: be used to store the gateway address that is connected with router;
Kernel sign: the sign that is used for kernel routing table respective entries;
The RIP sign; The sign that is used for RIP routing table respective entries;
Time: the update time that is used to identify routing table entry;
Interface: be used to identify the interface that obtains routing table.
Described RIP interface table comprises following field:
Title 1: the title that is used to identify interface;
Title 2: be used to identify the adjacent next interface name of describing with these clauses and subclauses of interface;
Index: be used to identify interface search index value;
MTU: the MTU that is used to identify interface;
Tolerance: the metric that is used to identify interface;
Sign: the state that is used to identify interface;
Multicast address: the multicast address that is used to identify interface;
Link address: be used to identify the interface link local address;
Multicast sign: be used to identify interface and whether participate in the multicast group.
The present invention also provides a kind of device of maintaining routing list simultaneously, comprises;
Input processing device: receiving the RIP packet, is that RIP request package or RIP respond packet ask respectively to handle or response is handled according to the packet that receives;
Output processing apparatus: the structure of setting up RIP interface table; Be used for RIP bag, set up RIP request package, triggering renewal RIP bag and cycle renewal RIP bag, as required RIP request package, triggering renewal RIP bag and the cycle renewal RIP bag interface by appointment is sent according to described reception;
Routing operations device: be used to inquire about the RIP routing table, and the handling function that calls described route intensifier and provide adds route and the invalid route of deletion in described RIP routing table;
Route intensifier: be used for initiate Routing Protocol module is registered, and be provided at the handling function that increases and delete route in the routing table for it;
Timer processing device: be used for the renewal of maintaining routing list and triggering cycle.
The invention has the advantages that: owing to have RIP interface table according to the structure storage of the RIP interface table of independent design, make RIP interface table and routing table and kernel separate, when a new route messages arrives, RIP can upgrade its routing table and this change is loaded in the kernel routing table, notify other Routing Protocol modules simultaneously, therefore adopt maintaining routing list of the present invention can improve the efficient of routing table maintenance, reduce complexity, be easy to the interpolation of other Routing Protocol module; Simultaneously, owing to the present invention can register initiate Routing Protocol module, and for it is provided at the handling function that increases and delete route in the routing table, the updating message that RIP is sent can reflect existing routing directory situation exactly.
In addition, the structure and the routing table structure of the independently RIP interface table of the present invention's design can make RIP interface table and routing table adopt the chain sheet form to manage, and are suitable for managing more route entry, therefore can improve the efficient of routing table maintenance.
Embodiment:
For understanding the present invention better, the invention will be further described below in conjunction with accompanying drawing.
Method of the present invention is applied to comprise the router of RIP routing table, kernel IP route table, kernel UDP module and kernel IP module.Method of the present invention is when concrete the application, at first router startup, all neighbor routers are given in the request of output request full routing table then, and the timer of start-up period renewal simultaneously starts RIP request package or the RIP respond packet that receiving process waits for that other neighbor router sends; If the cycle is upgraded timer then, the transmission cycle is upgraded the message of RIP routing table; If receiving process receives the RIP bag that others sends, divide request and response to carry out respective handling, if request checks that then it denys corresponding route entry that routing table has, and sends respond packet then; If routing table is then watched in response, see if there is respective entries, if directly this route entry is not added routing table entry, have then to add, delete processing by the agreement principle, then, whether change to activate to trigger according to routing table and upgrade.
Specifically, the present invention includes four steps, with reference to figure 1.Carry out the RIP input in step 1 and handle operation.Comprise to the processing of request package with to the processing of respond packet.At first the input processing threads of this step enters Infinite Cyclic and monitors socket, receives the RIP bag, and response or the request of carrying out the RIP bag according to the value of command field handled then, handle return after, then wait for receiving next RIP bag.
It is one by one that project is handled that described RIP bag to reception asks to handle, and does not have clauses and subclauses just not respond.Special circumstances are arranged, if just in time have only clauses and subclauses in the request, and its purpose prefix is 0, and prefix length is 0 also, measures to infinite.This is the request that a request sends whole routing tables.At this moment, require output that routing table is delivered to request address/port.It is the RTE table of one by one checking request package that other request is handled, and to every clauses and subclauses, searches this destination address in the routing database of router, if there is a route, the tolerance of that route is added in the tolerance of this RTE.Were it not for the route of the point of destination of appointment, put infinite in the metric field.After the reason clauses and subclauses are all filled in, order is changed into response and datagram is beamed back the requestor.
The response appointment and all during the routing table request, different to the processing of tolerance.If complete routing table is wanted in request, normally exports, comprise visual field separation.If only require the clauses and subclauses of appointment, in routing table, find them and the information former state is beamed back, do not carry out the processing that separate in the visual field.The reason of doing this difference is to think that these requests might be used for various objectives.When a router newly adds fashionable, its multicast on each network that links to each other requires to send the request of whole routing table, the routing table that will be used for update request person to this request responding, therefore must carry out the visual field and separate, and think the request of concrete route is just sent by diagnostic software, and its response is not used in and upgrades the kernel routing table, at this moment, the requestor wonders the accurate content of routing table and does not wish that information is hidden or revises that therefore, separate without the visual field this moment.
When described RIP bag to reception responds processing,, handle all identical no matter why response produces.Because the processing meeting routing table of new router more to response, so validity of necessary scrutiny response, ignore is not from the non-local multi-case data that address or non-peaked RIP bag of time-to-live and router oneself are sent out that encircles in the source of RIPng (next generationRIP, the port of the next RIP of generation) port or datagram.
When whole packet is effective, clauses and subclauses in the processing response one by one.Owing to will support next to jump the processing of clauses and subclauses, whether be that next jumps clauses and subclauses so will watch clauses and subclauses earlier.If next jumps clauses and subclauses, then gateway is set as analog value; If route entry, the beginning validity check.Basic validity check is as follows:
---the purpose prefix is effective (for example: be not the broadcasting prefix, neither locally encircle the address).
---effectively whether prefix (that is: at 0 to 128).
---effectively whether tolerance (that is: at 1 to 16).
As long as each is made mistakes, ignore this clauses and subclauses, then handle next clauses and subclauses.
When this project proves when effective, upgrade its tolerance, add the cost of the network that receives this message.If the result, uses the infinitely great tolerance of upgrading greater than infinite.That is: tolerance=MIN (tolerance+cost, infinite).
Watch whether a clear and definite route to this order ground prefix is arranged, were it not for such route, this route is added in the routing table entry, unless its tolerance is for infinite.Dosing route in the routing table may further comprise the steps:
---purpose prefix and length are set to the data in the corresponding field of RTE.
---tolerance is set to the former router address of datagram or by the next hop address of next clauses and subclauses appointment.
---be this router initialization overtime timer.If the garbage reclamation timer just for this route operation, is then ended.
---the route change flag is set exports the triggering renewal simultaneously.
If a route of depositing is earlier arranged, relatively next hop address and datagram are come the address of source router.If this datagram comes from the router identical with existing route, reinitializes overtime timer.
Comparison measuring then.If new tolerance is taked following measures less than infinite and be not equal to old tolerance: accept route, and router change flag and notice output are set trigger and upgrade from datagram, otherwise, if new tolerance is infinite, begins deletion and handle; If identical direct next clauses and subclauses of processing of new tolerance with old tolerance.
Any failing all is left in the basket by the project of above-mentioned detection, because it is good unlike current path.
In this step, not only the interface additions and deletions route that will provide by the routing operations device also can cause output to be handled to the response of request message with to triggering the processing of upgrading.Jump the processing of clauses and subclauses owing to considered next in response is handled, therefore method of the present invention can receive outside route; After response is handled, trigger renewal at once and handle, can effectively suppress every renewal one route that not have again of route circulation and upgrade the huge network load that is caused with regard to sending out a triggering.
In this step, also need;
Set up the structure of RIP bag, be used to set up the RIP bag, described structure comprises following field:
Order: the kind that is used to identify the RIP bag;
Version number: the version number that is used to identify the RIP agreement;
Route entry: be used to identify routing iinformation.
Set up the structure of route entry table, this structure comprises following field:
Purpose prefix: the destination address that is used for identification data packet;
Routing tag: be used for the inner or outside route of sign;
Prefix length; The number of bits that is used for the recognition purpose prefix;
Route metric: be used to identify this router to the destination router the number of router of process.
Set up the structure of routing table, described structure comprises following field:
Next clauses and subclauses: be used to indicate next route entry;
Route entry: be used to store this route entry;
Gateway address: be used to store the gateway address that is connected with router;
Kernel sign: be used to identify the kernel routing table;
RIP sign: be used to identify the RIP routing table;
Time: the update time that is used to identify routing table entry;
Interface: be used to identify the interface that obtains routing table.
Carrying out RIP output in step 2 handles.Trigger and upgrade, the cycle upgrades, and all need export processing to the response of request package.Wherein trigger to upgrade and processing is imported in the response of request package and cause.This step mainly comprises three subprocess, and one is used for setting up bag, and one is used for output packet, and one is used to generate request package.
Build the steamed stuffed bun process and need two input parameters: output interface and sign, described sign are used to indicate and need transmission trigger still cycle renewal of renewal, and which interface described output interface is used to indicate to is exported the RIP bag.Set up the packet format of protocol compliant, the version that version number is current RIPng should be set, command field is arranged to response, zero territory is arranged to zero.Begin to fill out RTE again.Remember that the maximum length of datagram is subjected to the MTU of network (MTU) restriction.When not having more space in the datagram, send current response, and then begin a new response.When filling in RTE, check every route in the routing table, trigger renewal, need only comprise the route that those are provided with the route change flag if produce one; If after the separating treatment of the visual field, should not comprise this route, just ignore it; If must comprise this route, in RTE, fill in the purpose prefix, prefix length and tolerance.Even the tolerance of route is infinitely also need be included in the datagram.
The generation of request package need not input parameter, and only needing one of generation to have only a prefix is zero, and prefix length is zero, measures the RIP bag into infinite clauses and subclauses.
The output subprocess comprises four input parameters (bag is long, output interface for destination, RIP bag), and the RIP bag of above-mentioned foundation sends the interface of described RIP bag by appointment as required by this subprocess.
Also comprise the structure of setting up RIP interface table in this step, be used for organizing RIP interface table by the form of chained list.Described structure comprises following field:
Title 1: the title that is used to identify interface;
Title 2: be used to identify the next interface name of facing mutually with the interface of these clauses and subclauses description;
Index: be used to identify interface search index value;
MTU: the MTU that is used to identify interface;
Tolerance: the metric that is used to identify interface;
Sign; Be used to identify the state of interface;
Multicast address: the multicast address that is used to identify interface:
Link address: be used to identify the interface link local address;
Multicast sign: be used to identify interface and whether participate in the multicast group.
In step 3, initiate Routing Protocol module is registered, and be provided at the handling function that increases and delete route in the routing table for it.Owing in the operation of router, mainly comprise three kinds: look into routing table, add route, the deletion route, in order to be consistent with kernel better and can better to coexist with other Routing Protocol later on, in this step, when a Routing Protocol changes a route, all notify other Routing Protocol and kernel, thereby make between all Routing Protocol modules all routes are reached common understanding.
When a new Routing Protocol module adds fashionablely, carry out protocol registration earlier, indicate protocol name and the priority of oneself during registration, return a routing operations function to it then, when increasing and delete a route, all calls protocol module this function.When this function of Routing Protocol module invokes adds route, route and routing protocol priority that protocol module is added record in the routing information base of oneself safeguarding, result's decision of considering according to the treaty override level and the combined factors such as tolerance and life span of each route that arrives same purpose adds the kernel routing table to which bar route then, simultaneously it is notified to other Routing Protocol module.During this function deletion route of Routing Protocol module invokes, need this route entry in own routing information base of deletion and the kernel routing table, search the route that whether has in the storehouse to same purpose simultaneously,, then it is added the kernel routing table and notify other routing module simultaneously if having.
In step 4, regularly the routing table cycle of carrying out to be upgraded, every route in the routing table is provided with two timers: an overtime timer, a garbage reclamation timer.Overtime timer reaches when route is set up and starts when receiving this routing update message, and when overtime timer overflowed, it is invalid that this route is denoted as, and starts the garbage reclamation timer simultaneously.When the garbage reclamation timer overflows, be denoted as invalid route and just from routing table, delete.
In step 5, when the interface of described appointment newly starts, send router RIP request package in the mode of broadcasting.
Fig. 3 is the applied environment schematic diagram of device of the present invention.According to Fig. 3, device 1 of the present invention is applied to comprise the router of RIP routing table 2, kernel IP route table 3, kernel UDP module 4 and kernel IP module 5, is used to safeguard described RIP routing table 2.
Fig. 2 is a device embodiment block diagram of the present invention.The device 1 of the described maintaining routing list of Fig. 2 comprises:
Input processing device 15: receive the RIP packet, described packet is asked to handle or the response processing according to the command field of described packet.This device comprises:
Request processing unit 151: each clauses and subclauses that is used for RTE (route entry) tabulation to request package are handled;
Response processing unit 152: be used for next of the respond packet that receives jumped clauses and subclauses and route entry is handled.
Output processing apparatus 14: set up RIP interface list structure; Be used for RIP bag, set up RIP request package, triggering renewal RIP bag and cycle renewal RIP bag, as required RIP request package, triggering renewal RIP bag and the cycle renewal RIP bag interface by appointment is sent according to described reception.This device comprises:
Set up parts 141: be used to set up the RIP bag;
Generate parts 142: be used to set up the RIP request package;
Output block 143: the RIP bag that is used to export above-mentioned foundation.
Routing operations device 12: be used to inquire about the RIP routing table, and the handling function that calls described route intensifier and provide adds route and the invalid route of deletion in described RIP routing table; This device comprises:
The parts 121 of tabling look-up: be used to inquire about the RIP routing table;
Add parts 122: be used for adding route to described RIP routing table;
Deletion parts 123: be used for from the invalid route of described RIP routing table deletion.
Route intensifier 13: be used for initiate Routing Protocol module is registered, and be provided at the handling function that increases and delete route in the routing table for it;
Timer processing device 11: be used for regularly the routing table cycle of carrying out being upgraded.
When the device of using maintaining routing list of the present invention carries out safeguarding of routing table:
When router receives the respond packet that neighbours send, calling the parts 121 of tabling look-up earlier watches routing table and sees if there is respective entries, it's not true calls and adds parts 122 it is added routing table entry, whether the words that have the then gateway according to new and old route are identical, handle in two kinds of situation: a kind of be the gateway of new route and old route not simultaneously, if new tolerance is littler, call the route in the deletion parts 123 deletion routing tables, call interpolation parts 122 newer routes are added routing table entry: otherwise, motionless: another kind is from same gateway, as long as tolerance changes, just changes tolerance setting, otherwise, only upgrade and just can update time.
Timer processing thread Infinite Cyclic is called the life span that the parts 121 of tabling look-up are checked each route entry in the routing table, when the overtime needs of Route Age in the routing table are deleted, calls 123 deletions of deletion parts.