Summary of the invention
The algorithm that the present invention proposes can solve the problem, and it calculates the topological diagram of whole network, shows multicast distribution situation on topological diagram simultaneously, helps user's diagnostic network.It shows the multicast path in network intuitively, in real time, check specific Multicast Flows the equipment of process, and the transmitting terminal of this Multicast Flows and receiving terminal.This algorithm supports that complicated topological diagram generates, and multicast path combines, and can show the Multicast Flows of particular topology node on the network topological diagram generated, and the topological node that flows through of the specific Multicast Flows of real-time exhibition, facilitates supervision and the management of keeper simultaneously.
This algorithm adopts client-side/server-side structure, and in selection network, a PC is as service end, and in network, switch and router are as client, adopt udp protocol communication between client and service end.The program of service end is divided into two independently threads, is communication thread and service thread respectively.Communication thread is responsible for user client communication and is received the information upload of client, according to information upload generating network topological diagram, preserves various uploading data, sets up the corresponding relation of each network node and multicast address.Service thread is mainly used to represent topological diagram, represents the multicast table on each node, provides to inquire about to use into confession administrative staff simultaneously.Two threads use public data structure to deposit the data of topological diagram and multicast table.Two threads adopt synchronization mechanism, communication thread receives the data of client, common data structures is safeguarded in foundation, then notification service thread after having operated common data structures, service thread receives notice, read public data structure, the information deposited according to common data structures repaints topological diagram.The synchronized relation of communication thread and service thread as shown in Figure 1.
Common data structures comprises three parts: equipment chained list, multicast address table.Equipment chained list comprises device node.Device node comprises equipment sign, IP address of equipment, device mac address, points to the pointer of port node, points to the pointer of next device node.Port node comprises: the port numbering of local terminal, the port numbering of opposite end, neighbor device pointer, points to the pointer of the next port node of same equipment; Multicast address table comprises: multicast address node, and this node comprises the pointer of multicast device node of the type of multicast address, Multicast MAC Address, Multicast IP Address, sensing, points to the pointer of next multicast address node.Multicast device node comprises the pointer of sensing equipment node, the device port vector of this multicast address use, points to the pointer of next multicast device node.Relation between common data structures as shown in Figure 2.
Service end and client adopt udp protocol, and when client terminal to discover connects change or the change of IP/MAC Multicast Flows, active upload information is to service end.Need the data uploaded little when network stabilization, need when network changes in time change information to be issued service end, service end and client are often short connections, the data volume of transmission is little, higher to time requirement, therefore employing udp protocol, compare TCP server simultaneously and adopt UDP service end can support more UDP client.The message of service end to client upload confirms, communication two party defines two kinds of data formats for this reason: the data format that the data format of client upload and service end confirm.The data format uploaded comprises: the body part of sequence number, sender IP address, sender's MAC Address, command type, order.One of them UDP message uploaded comprises type and the body part of order of one or more order, the type decided of the order content of body part, and the type of order and text thereof have several below:
1. command type 0x01, implication adds new neighbours; The text of this order comprises: the IP address of sender, the MAC Address of sender, the port numbering of local terminal, the port numbering of opposite end, the IP address of neighbours, the MAC Address of neighbours.
2. command type 0x11, implication loses neighbours to connect; The text of this order comprises: the IP address of sender, the MAC Address of sender, the port numbering of local terminal, the port numbering of opposite end, the IP address of neighbours, the MAC Address of neighbours.
3. command type 0x02, implication newly adds multicast address; This order text comprises: the IP address of sender, the MAC Address of sender, the type of multicast address, Multicast IP Address, Multicast MAC Address, corresponding port vector.
4. command type 0x22, implication is that multicast address leaves; This order text comprises: the IP address of sender, the MAC Address of sender, the type of multicast address, Multicast IP Address, Multicast MAC Address, corresponding port vector.
First the public udp port of service end binding both sides agreement, waits for that client data arrives.First service end sends back message after receiving the uploading message of client, and back message content comprises the sequence number of uploading message, then the content of analytic message, operation common data structures.Service end takes out the IP of transmit leg and the MAC Address of transmit leg in message, inquires about corresponding equipment chained list accordingly.If do not inquire corresponding device node, then a newly-built device node, the then type of viewing command.
If command type is 0x01, in equipment chained list, corresponding transmitting apparatus node is found with IP and MAC of sender's equipment in order text, if corresponding equipment can be found, according to the port numbering of the local terminal in order text, search the port node of port chained list with or without the port numbering of the local terminal of correspondence of device node sensing, if there is corresponding port node to exist, then in the device node pointed to by the neighbor device pin of port node and order text, IP and MAC of neighbor device compares.If equal, then prove that this neighborhood exists, end process; If neighbor device can not mate, then in equipment chained list, find corresponding device node with IP and MAC of neighbor device in order text, if find corresponding neighbor device node, then revise the new-found device node of neighbor device pointed of port node, if do not find neighbor device, the device node that then establishment one is new, is inserted into the end of equipment chained list, then this equipment of neighbor device pointed of port node; If do not find the port numbering of the local terminal of corresponding transmitting apparatus, then create a port node, be inserted into the afterbody of device node port chained list, in equipment chained list, corresponding device node is looked for IP and MAC of the neighbor device in order text, if find the device node that the neighbor device pointed of the port node newly created finds by corresponding neighbor device, if do not find neighbor device, create a new device node, be inserted into the end of equipment chained list, this equipment of neighbor device pointed of this port node.
If command type is 0x11, in equipment chained list, find corresponding transmitting apparatus node with IP and MAC of sender's equipment in order text, if do not have corresponding transmitting apparatus to end process.If there is corresponding transmitting apparatus, according to the port numbering of the local terminal in order text, search the port of port table with or without correspondence of device node sensing, if do not have corresponding ports to end process; If there is corresponding port node, IP and MAC of the neighbor device in IP and MAC of the device node of the neighbor device pointed of port node and order text is compared.If more identical, then the device pointer of port is set to null pointer; If more not identical, then do not deal with.
If the type of order is 0x02, then representative has new multicast address to add, first multicast address table is searched, if find multicast address node, then search the multicast device node that multicast address points to, if IP with MAC of the device node pointed by the device pointer of multicast device node is the same with IP with MAC in message, then by the port vector of filling this node with order text middle port vector, end process flow process; If do not find corresponding device node, creates a new device node, be inserted into the end of equipment chained list, by the port vector of this node of order text middle port vector filling, newly-established equipment pointed by the device pointer of multicast device node.If do not find multicast address node, then add a multicast address node; Whether the device node then searching this multicast address associations exists, if there is no a then newly-built device node, this device node is put into the end of equipment chained list, then one or more port node is created according to the port vector in message, the port node that the port node pointed of the new equipment chained list node created newly creates; The equipment chained list device pointer of new multicast address node points to newly-built device node, and fill the port vector of this node with order text middle port vector, device pointer points to the device node created.If find multicast address node, whether the device node then searching this multicast address associations exists, if there is no a then newly-built equipment chained list node, this equipment chained list node is put into the end of equipment chained list, then one or more port node is created according to the port vector in message, the port node that the port node pointed of the new equipment chained list node created newly creates; The equipment chained list device pointer of new multicast address node points to newly-built device node, and fill the port vector of this node with order text middle port vector, device pointer points to the device node created.If there is this device node, check that whether the port vector of multicast device node is identical, if fruit is not identical, replace, identical, end process.If corresponding equipment also exists while multicast address node exists, then check that whether the port vector of multicast device node is identical, if fruit is not identical, replace, identical, end process.
If the type of order is 0x22, then representative has multicast address to leave, first multicast address table is searched, if find multicast address node, search the device node pointer of its sensing, then whether the IP address of the equipment of the multicast device node of compare facilities pointed is equal with MAC Address with the IP address of message transmitting party with MAC Address.If the port vector in equal judgement message and the step-by-step of multicast device node middle port vector compare, if the position of correspondence both 1, then this position 0 of the port vector that this multicast device is corresponding; If the ip address of the multicast device of multicast device pointed and mac are unequal in message, the next multicast device node that more next multicast device node pointer points to.Above-mentioned service end receives the handling process of order as shown in Figure 3.
As mentioned above, the communication thread of service end is responsible for setting up and is safeguarded common data structures, if communication thread finds that common data structures has any change, notification service thread starts to repaint topological diagram.Service end long-play, As time goes on, common data structures has increasing junk data, and communication thread opens timer for this reason, unwanted data in timed collection cleaning common data structures.Concrete method for cleaning is as follows:
First clear up isolated device node, isolated device node is the node without any neighbor device.Scanning device chained list successively, checks whether the port chain list index that equipment chained list points to is null pointer, if null pointer, shows that this equipment does not have neighbours, is an isolated equipment, then deletes this device node; If port chain list index non-NULL, check whether the neighbor device pointer of all port nodes of this equipment is all null pointer, if be all null pointer, then can delete all of the port node of this equipment, then delete this device node.Next empties invalid multicast address, and invalid multicast address refers to this multicast address not on any equipment.The step removed is: scanning multicast address table, checks whether the multicast device node pointer of multicast address node is null pointer, if null pointer, deletes this multicast address node.
One of function of service thread is generating network topological diagram, generates the algorithm that can adopt Depth Priority Algorithm and BFS of topological diagram.This algorithm adopts depth-first search, and its concrete steps are:
A. arranging looped network mark amount is 0 show not occur loop, and each Node configuration of equipment chained list is not for search for complement mark;
B. the equipment not having to have searched for is found, if do not find this equipment to exit whole step.If find this equipment, the current depth of this equipment and depth capacity are set to 0, set up current device current depth path vector, current depth path vector, spends path vector the most deeply, all of the port of all devices is set to not accessed mark simultaneously;
C. set up a stack, the element of stack comprises the type of node, device node, port node; If what type equaled that 0 representative deposits is equipment, port node reset represent nonsensical; If type equals 1, what deposit is port, the device node at what now equipment was deposited is port place, and port deposits port node data, represents current device node stacked; Step B find not search for finishing equipment node stacked, device node stored in current depth path vector, current depth value 1;
D. judge whether stack is empty, if stack is empty, the device node of popping recently is set to search and completes, and goes to step B; If be not empty, get stack top element, if stack top element is port node, turn to step e; If stack top element is device node, search the port node of the not accessed mistake of this equipment and stacked, arrange this port for access flag, the port of the correspondence of the neighbor device simultaneously port node pointed to is set to access flag; If equipment does not find the port node of not accessed mistake, then pop, current depth subtracts 1, and current path degree of depth vector removes this equipment, turns to step D; If find this port, this port is stacked, arranges this port for access flag, and the port of the correspondence of the neighbor device simultaneously port node pointed to is set to access flag; If the neighbor device pointer of this port node exists, check that whether the device node of pointer indication is identical with the node in path vector, identically go to step G, if not identical, then current depth adds 1, and neighbor device, stored in current depth path vector, then jumps to the device node of neighbor device pointed, neighbor device is stacked, moves into current depth path vector simultaneously; Go to step F;
If E. stack top element is port node, the equipment at port place is obtained from this stack top element, search the port node of not accessing of this equipment, find this port stacked, this port is set for access flag, the port of the correspondence of the neighbor device of port node sensing is set to access flag, port node indication neighbor device node is stacked, turns to step D simultaneously; The port node of not accessing does not exist, and pops, and turns to step D;
F. current depth adds 1, when current depth is greater than depth capacity, upgrades depth capacity with current depth, and current depth path vector copies to depth capacity vector simultaneously, turns to step D;
If G. identical, then prove to occur loop, all nodes on record loop are also preserved, arranging looped network mark amount is 1 show to occur loop, preserves the nodes that this ring exists simultaneously, abandons this deep search, the all nodes occurred in loop, be set to search for mark, then start the root node finding next depth-first search, this node did not occur in the loop of record.Turn to step B;
Repeat above-mentioned in steps until all devices is all provided with search complement mark, all depth capacitys being root node with this equipment can be obtained by aforesaid operations.If asking in depth capacity process the node not having to find repeating, then network configuration is being tree topology.Ask the algorithm flow of depth capacity as shown in Figure 4.
After obtaining depth capacity, start the distance between computing equipment, area shared by each equipment, equipment is represented with square, distance between equipment equals the total height of painting canvas divided by depth capacity: suppose that this distance is for D, the foursquare length of side representing equipment equals 1/8th of equipment distance, i.e. length of side a=D/8.Each equipment has 2 hiding painting canvas, and the essential information of a painting canvas recording equipment comprises equipment sign, IP address, MAC Address, the multicast address of each port association of another painting canvas recording equipment.The two ends of the line of every 2 equipment have one to hide picture simultaneously, the port numbers of record institute attached device.
Network topological diagram has two large classes: tree topology, ring topology.According to depth-first search and BFS, two and multiple same device node is there is in searching route, then can judge it is ring topology, otherwise be tree topology, this algorithm is asked in the depth capacity process of device node and is judged that network is annular or tree topology, and adopts diverse ways drawing topological graph.
The plot step of tree topology is: detection ring network mark will amount, if be 0, then representative is tree structure, check the depth capacity of each device node, if the degree of depth is identical, the mac address of compare facilities, little preferential in mac address, they are carried out descending, find arrangement first equipment, it is placed in the middle position of the top of painting canvas, then the path vector of this equipment is traveled through, under Current Scan, target equipment points to the beginning of arrangement, from the 1st equipment of the arrangement of subscript sensing, D distance immediately below equipment, draw next equipment, then setting-out connects this two equipment.According to said method draw all devices on the depth capacity path of this equipment.After all devices line in the darkest path of the darkest equipment of the degree of depth is completed, Current Scan subscript adds 1, start the device node path of the equipment depth capacity of drawing scanning subscript indication: first judge to occur in the figure of the whether former drafting of this equipment, then need not draw separately if there is crossing, find out this node, then draw according to the method for drawing the darkest path of Article 1.Before this node of each drafting, first judge whether this node exists, if existed, need not draw, directly connect with straight line.If this node did not occur, horizontal-shift D distance, vertical shift H(H=(depth capacity-present node degree of depth) × D), draw this node.In addition in order to the overall maintenance balance of figure, in turn at the darkest path the right and left drawing path and equipment, each drafting departs from D distance downwards, departs from D distance to the left side or the right simultaneously.According to this kind of method until all devices in queue is all completed.And then scanning device chained list, specifically according to BFS, check which equipment line is not drawn, if do not drawn, connect this two equipment with sensing.The method for drafting of tree structure as shown in Figure 5.
The drafting of ring topology figure, detection ring network mark will amount, if be 1, check all looped network nodes and looped network interior joint logarithmic data preserved, therefrom finds out that ring that the nodes of preservation is maximum.If the nodes of several ring is the same, then that first detects is preferential, and the nodes of this ring is set to depth H, draw the equipment on this ring and line, determine a bit in the central authorities of painting canvas, be the center of circle with this, 1/4 width of painting canvas for radius, start the equipment drawn on circumference.Each increase 360/H degree central angle, draws out all devices on ring and straight line connection.And then successively with the equipment on this ring for source point, be breadth first search, first check whether its neighbor device occurs in the figure drawn, if there is cross and they between there is no line, then directly draw straight line connect this two equipment; If do not occurred, with the equipment on ring for the center of circle, 1/8 width of painting canvas is radius, and its neighbor device do not occurred all is plotted on painting canvas.The central angle of each drafting increase fixed angle, suppose neighbours' number that it did not occur for T=360/, when after on ring, the neighbours of all devices have drawn, again in the same way, the equipment newly added with these for the center of circle start draw, until all limits and equipment all occurred on painting canvas.
According to the method for drafting of above-mentioned tree structure and loop configuration, while each equipment of drafting, add the port information on the IP address of this equipment, MAC Address, descriptor, equipment line both sides in the same position hidden Layers.After line between all devices and equipment is completed, scanning multicast address table, adds to multicast address on the hiding painting canvas of multicast address associations equipment, also adds the port vector of this multicast address corresponding device simultaneously.
The service thread of service end is responsible for user interface part, it have show and hide Layers, inquiry apparatus information, inquiry multicast address information, various function such as inquiry multicast path etc.The multicast address of user's query device specific, only needs the multicast address painting canvas equipment is hidden again to show.Whether whether user wants to inquire about specific multicast address exists in current network, first need to inquire about this address and be present in multicast address table, if do not existed in multicast address table, return query failure message; If existed, then inquire about the multicast device pointer chained list that multicast address points to, then on painting canvas, these relevant devices pointed by pointer are highlighted display, line also overstriking display.Any one multicast address distribution situation in a network in current network can be checked by this.
Client is responsible for information upload to service end, client needs IP address and the port numbers of knowing service end, general port numbers remains unchanged, but network manager can change the IP setting of service end sometimes, or keeper moves to another computer service end from a computer, now all in normal conditions clients all need to reconfigure.The present invention proposes following scheme and solves this problem: in service end running, the IP address of periodic overseas broadcast oneself, whether the IP preserved before first client adopts in just bringing into operation is normal to detect service end, if time-out does not receive the response message of service end, start the broadcast message receiving service end, the IP address of new service end is obtained from the content of the broadcast message received, then with new IP address and service end communication, and preserve this IP address, when next time is run, use this address.
Client needs to upload neighbor information and multicast address information, client process and LLDP protocol process, and GMRP protocol process, IGMP protocol process carries out synchronous collaboration.The mode of synchronous collaboration has the several types such as pipeline, message queue, shared drive, web socket.In this algorithm, adopt message queue, the type of the order of type of message and service end process is here duplicate, and numbering and the implication of type of message are as follows:
1. type of message 0x01, finds new neighbours.
2. type of message 0x02, former neighbours are out of touch.
3. type of message 0x11, finds new multicast address.
4. type of message 0x12, multicast address leaves a port.
Client process needs and the cooperation of LLDP protocol process obtains neighbor information, adopts message queue to carry out data and transmit with synchronous between two processes.After the neighbours that LLDP protocol discovery one is new, type of message 0x01 is set, by these information such as the port numbers of the IP address of the MAC Address of the IP address of sender, sender, neighbours, MAC Address and correspondence, issues client process by message queue.After client process receives this information in message queue, be assembled into UDP message and issue service end.After LLDP protocol discovery neighbours are out of touch, type of message 0x02 is set, by these information of port numbers of the IP address of the MAC Address of the IP address of sender, sender, neighbours, MAC Address and correspondence, client process is issued by message queue, after client process receives this information in queue, be assembled into UDP message and issue service end.
Client process needs and GMRP agreement or IGMP protocol process cooperate obtains multicast address information, when GMRP agreement or IGMP protocol process receive join message registration multicast address time, type of message 0x11 is set, by the IP address of sender, the MAC Address of sender, multicast address type, multicast address, corresponding port vector, write in message queue, when GMRP agreement or IGMP protocol process receive leave message nullify multicast address time or multicast address time-out known time, type of message 0x12 is set, the IP address of sender, the MAC Address of sender, multicast address type, multicast address, corresponding port vector, write in message queue.After client process receives this information in queue, be assembled into UDP message and issue service end.Cooperation relation between the process of service end and client as shown in Figure 5.