Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flowchart of a method for discovering topology information according to an embodiment of the present invention, and as shown in fig. 1, the method for discovering topology information according to this embodiment may include the following steps:
step 101, sending a topology information request message to an adjacent device to be queried, where the topology information request message carries a spanning tree type, an identifier of a query request device and identifier information of all devices to be queried, so that the adjacent device to be queried forwards the topology information request message to a next-stage adjacent device to be queried;
and 102, respectively receiving topology information response messages returned by all the devices to be queried if the spanning tree protocol of the spanning tree type identifier is consistent with the running spanning tree protocol, wherein the topology information response messages carry the identifier of the query request device, the port information of the device port to be queried of all the devices to be queried participating in the spanning tree protocol calculation and the identifier of the device to be queried of the opposite port of the device port to be queried.
The query request device identifier may be a Media Access Control (MAC) address of the query request device; correspondingly, the device identifier to be queried of the peer port may be an MAC address of the device to be queried of the peer port.
In this embodiment, the identification information of all the devices to be queried may include two forms: when the devices to be queried are all devices in the network, the identification information of all the devices to be queried is a specific field value, for example: fffffffffff; when the device to be queried is a certain device in the network, the identification information of all the devices to be queried is the MAC address of the device.
The embodiment can be applied to a network without a VLAN, for example: the device to be queried in the network runs Spanning Tree protocols such as Spanning Tree Protocol (STP), Rapid Spanning Tree Protocol (RSTP), and the like, and can also be applied to a network in which a VLAN exists, for example: the device to be queried in the network runs Spanning Tree protocols such as Multiple Spanning Tree Protocol (MSTP for short).
In this embodiment, after the query request device sends the topology information request message to the device to be queried, the device to be queried returns a topology information response message to the query request device according to the identification information of all devices to be queried in the topology information request message, so that the query request device can obtain the port information of the port of the device to be queried, where all devices to be queried participate in the spanning tree protocol calculation, and thus can confirm the physical topology relationship among devices in the network where no VLAN exists and the logical topology relationship among devices in the network where the VLAN exists.
Fig. 2A is a schematic flowchart of a method for discovering topology information according to a second embodiment of the present invention, and as shown in fig. 2A, the method for discovering topology information according to this embodiment may include the following steps:
step 201, an inquiry request device sends a topology information request message to an adjacent device to be inquired, wherein the topology information request message carries a spanning tree type, an inquiry request device identifier and identifier information of all devices to be inquired, so that the adjacent device to be inquired forwards the topology information request message to the next-stage adjacent device to be inquired;
the content of the topology information request message may be carried in a data (data) field of an 802.3 data frame, and the format of the data frame may be as follows:
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| destination Address-
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Address of | source | non woven
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| Length | DSAP | SSAP | control | protocol | non-visual space
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
I identification | spanning tree type | message type | root |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Marking |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
I operate | live
+ -
| |
+ -
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| | FCS |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Wherein,
destination Address (Destination Address) field: 6 bytes. This field is used to identify the device that needs to receive the data frame. Here, we are compatible with the spanning tree protocol (STP, RSTP, MSTP, etc.), using the multicast address of the spanning tree protocol: 0180c 2000000;
source Address (Source Address) field: 6 bytes. This field is used to identify the device that sent the data frame;
length (Length) field: 2 bytes. The field is used for indicating the length of data contained in the data field of the data frame;
target service access point (DSAP) field: 1 byte, value 0x 42. This field indicates that the spanning tree protocol (STP, RSTP, MSTP, etc.);
source Service Access Point (SSAP) field: 1 byte, value 0x 42. This field indicates that the spanning tree protocol (STP, RSTP, MSTP, etc.);
control (Control) field: 1 byte, value 0x 03. This field indicates the 802.2 unnumbered data format with connectionless services;
protocol Identifier (Protocol Identifier) field: 2 bytes, value 0x 0000. This field indicates Spanning-tree Query Protocol (Spanning-tree Protocol);
spanning-tree type (Spanning-tree Mode) field: 2 bytes, the field indicates the type of the running spanning tree protocol, and may include spanning tree protocols such as STP, RSTP, MSTP, etc., and the corresponding values are as follows:
STP=0x1000;
RSTP=0x2000;
MSTP is 0x30, represents the number of spanning tree instances (Instance), excluding spanning tree Instance 0(Instance 0);
a message Type (Type) field: 1 byte. The field indicates the type of the packet carried in the data frame, and the value and meaning thereof are as follows:
the Type is 2, and the request message represents that the query request equipment requests the logical topological relation (including port information) of each equipment to be queried;
root identification (Root identity) field: 8 bytes. This field represents the root bridge information, including the priority and MAC address of the root bridge;
operation (Operation) field: this field indicates specific processing for spanning tree protocols (STP, RSTP, MSTP, etc.). Since the operation fields can correspond to different spanning tree protocols and have different lengths, the number of bytes of the operation field only defines an upper limit, namely not more than 1000 bytes.
Frame Check Sequence (FCS) field: 4 bytes. This field includes a 32-bit Cyclic Redundancy Check (CRC) value, generated by the sender device (the inquiry requesting device), calculated by the receiver device (the device to be inquired) to check for corrupted frames.
Further, the Operation field may further include the following field information:
when a Spanning-tree Mode (Spanning-tree Mode) field in the topology information request packet (i.e., type 2) takes a value of 0x1000 or 0x2000, the operation field may include the following information:
request mac (request mac) address field: 6 bytes. This field indicates the MAC address of the inquiry requesting device;
other mac (other mac) address field: 6 bytes. When the field takes the value of fffffffffff, the field indicates that all the devices to be inquired need to respond to the request message; when the field dereferencing is the MAC address of a certain device, the field indicates that only the device to be inquired corresponding to the address needs to respond to the request message;
when a Spanning-tree Mode (Spanning-tree Mode) field in the topology information request message (i.e., type 2) takes a value of 0x30, the operation field may include the following information:
request mac (request mac) address field: 6 bytes. This field indicates the MAC address of the inquiry requesting device;
other mac (other mac) address field: 6 bytes. When the field takes the value of fffffffffff, the field indicates that all the devices to be inquired need to respond to the request message; when the field dereferencing is the MAC address of a certain device, the field indicates that only the device to be inquired corresponding to the address needs to respond to the request message;
multiple Spanning Tree (MST) configuration summary (MST Configdigest) field: 16 bytes. The field is used for storing a configuration abstract of the equipment domain, and the content of the field is the MST configuration abstract (MST config digest) field in a Bridge Protocol Data Unit (BPDU for short);
202, receiving the topology information request message by the adjacent device to be queried, if the device to be queried identified by the identification information of all the devices to be queried includes the adjacent device to be queried (which may be a scenario including all devices to be queried in a network, or a scenario including only the adjacent device to be queried), and if a spanning tree protocol of the spanning tree type identification is consistent with a spanning tree protocol of the adjacent device to be queried, returning a topology information response message to the query request device through a port receiving the topology information request message, where the topology information response message carries the query request device identification, port information of a port of the device to be queried, which is calculated by the device to be queried participating in the spanning tree protocol, and a device to be queried identification of an opposite port of the device to be queried;
step 203, the adjacent device to be queried receives the topology information request message, and if the device to be queried identified by the identification information of all the devices to be queried does not include the adjacent device to be queried or the devices to be queried identified by the identification information of all the devices to be queried are all devices to be queried in the network, the topology information request message is forwarded to the next-stage adjacent device to be queried through other ports except the port for receiving the topology information request message;
similarly, the content of the topology information response message may also be carried in a data (data) field of an 802.3 data frame, and the format of the data frame may be as follows:
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| destination Address-
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Address of | source | non woven
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| Length | DSAP | SSAP | control | protocol | non-visual space
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
I identification | spanning tree type | message type | root |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Marking |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
I operate | live
+ -
| |
+ -
| |
+ -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| | FCS |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Wherein,
destination Address (Destination Address) field: 6 bytes. This field is used to identify the device that needs to receive the data frame. Here, we are compatible with the spanning tree protocol (STP, RSTP, MSTP, etc.), using the multicast address of the spanning tree protocol: 0180c 2000000;
source Address (Source Address) field: 6 bytes. This field is used to identify the device that sent the data frame;
length (Length) field: 2 bytes. The field is used for indicating the length of data contained in the data field of the data frame;
target service access point (DSAP) field: 1 byte, value 0x 42. This field indicates that the spanning tree protocol (STP, RSTP, MSTP, etc.);
source Service Access Point (SSAP) field: 1 byte, value 0x 42. This field indicates that the spanning tree protocol (STP, RSTP, MSTP, etc.);
control (Control) field: 1 byte, value 0x 03. This field indicates the 802.2 unnumbered data format with connectionless services;
protocol Identifier (Protocol Identifier) field: 2 bytes, value 0x 0000. This field indicates Spanning-tree Query Protocol (Spanning-tree Protocol);
spanning-tree type (Spanning-tree Mode) field: 2 bytes, the field indicates the type of the running spanning tree protocol, and may include spanning tree protocols such as STP, RSTP, MSTP, etc., and the corresponding values are as follows:
STP=0x1000;
RSTP=0x2000;
MSTP is 0x30, represents the number of spanning tree instances (Instance), excluding spanning tree Instance 0(Instance 0);
a message Type (Type) field: 1 byte. The field indicates the type of the packet carried in the data frame, and the value and meaning thereof are as follows:
the Type is 3, which represents the response message of the device to be queried responding to the query request device Type is 2;
root identification (Root identity) field: 8 bytes. This field represents the root bridge information, including the priority and MAC address of the root bridge;
operation (Operation) field: this field indicates specific processing for spanning tree protocols (STP, RSTP, MSTP, etc.). Since the operation fields can correspond to different spanning tree protocols and have different lengths, the number of bytes of the operation field only defines an upper limit, namely not more than 1000 bytes.
Frame Check Sequence (FCS) field: 4 bytes. This field includes a 32-bit Cyclic Redundancy Check (CRC) value, generated by the sender device (the inquiry requesting device), calculated by the receiver device (the device to be inquired) to check for corrupted frames.
Further, the Operation field may further include the following field information:
when a Spanning-tree Mode (Spanning-tree Mode) field in the topology information response packet (i.e., type — 3) takes a value of 0x1000 or 0x2000, the operation field may include the following information:
request mac (request mac) address field: 6 bytes. This field indicates the MAC address of the inquiry requesting device;
acknowledgement mac (reply mac) address field: 6 bytes. The field indicates the MAC address of the equipment to be inquired which replies the message;
packet count/Packet number field: 1 byte. The field is used for the number of messages transmitted in segments after the information quantity exceeds 1518 bytes, the first 4 bits represent the number of messages which need to be transmitted by the equipment to be inquired, and the last 4 bits represent that the message is the second message;
port information (Ports Status) field: one port occupies 4 bytes. The field is used for storing port information of a port of the equipment to be queried, which is calculated by the equipment to be queried participating in a spanning tree protocol, and the port information comprises information such as a port number, a spanning tree instance number, a port role, a port state and the like;
opposite-end MAC address (Neighbor MAC-address) field: 6 bytes. The field indicates the MAC address of the device to be queried of the opposite port of the device port to be queried, one device port to be queried corresponding to one opposite port.
Further, the port Status field may further include the following field information (taking a port as an example, the following field included in the port information is described):
port number (index) field: 2 bytes. The field is used for recording the value of the port number;
spanning tree Instance number (Instance ID) field: 1 byte. For STP and RSTP, the value of this field is 0;
port role (Port-role) field and Port status (Port-status) field: for a total of 1 byte. Wherein, 4 bits represent the port role, and the values corresponding to each are as follows:
root (Root) port 1000;
port 0100 is designated (Desg);
substitute (Altn) port 0010;
backup (Backup) port 0001;
the other 4 bits represent port states, and the corresponding values are as follows:
forwarding state (Forwarding) 0100;
learning state (Learning) 0010;
blocking state (Blocking) 0001;
when the Spanning-tree Mode field in the topology information response packet (i.e., type 3) takes the value of 0x30, the operation field may include the following information:
request mac (request mac) address field: 6 bytes. This field indicates the MAC address of the inquiry requesting device;
acknowledgement mac (reply mac) address field: 6 bytes. The field indicates the MAC address of the equipment to be inquired which replies the message;
packet count/Packet number field: 1 byte. The field is used for the number of messages transmitted in segments after the information quantity exceeds 1518 bytes, the first 4 bits represent the number of messages which need to be transmitted by the equipment to be inquired, and the last 4 bits represent that the message is the second message;
MST configuration digest (MST config digest) field: 16 bytes. The field is used for storing a configuration abstract of the equipment domain, and the content of the field is the MST configuration abstract (MST config digest) field in a Bridge Protocol Data Unit (BPDU for short);
port information (Ports Status) field: the field is used for storing port information of a port of the equipment to be queried, wherein the port information of the equipment to be queried participates in spanning tree protocol calculation, the port information comprises information such as a port number, a spanning tree instance number, a port role and a port state, the port number is used as an index, and the port role and the port state of the port in each spanning tree instance are recorded under each port. The number of spanning tree instances is recorded in the last 1 byte of the spanning tree type field. If there are n spanning tree instances, one port occupies 2+2 x (n +1) bytes;
opposite-end MAC address (Neighbor MAC-address) field: 6 bytes. The field indicates the MAC address of the device to be queried of the opposite port of the device port to be queried, one device port to be queried corresponding to one opposite port.
Further, the port Status field may further include the following field information (taking a port as an example, the following field included in the port information is described):
port number (index) field: 2 bytes. The field is used for recording the value of the port number;
spanning tree Instance number (Instance ID) field: 1 byte. This field is used to record the value of the spanning tree instance number.
Port role (Port-role) field and Port status (Port-status) field: for a total of 1 byte. Wherein, 4 bits represent the port role, and the values corresponding to each are as follows:
root (Root) port 1000;
port 0100 is designated (Desg);
substitute (Altn) port 0010;
backup (Backup) port 0001;
the other 4 bits represent port states, and the corresponding values are as follows:
forwarding state (Forwarding) 0100;
learning state (Learning) 0010;
blocking state (Blocking) 0001.
It should be noted that: the processing mode after the next-stage neighboring device to be queried adjacent to the query request device receives the topology information request message may refer to the processing performed by the neighboring device to be queried in this step, and details are not repeated here;
step 204, the query request device receives a topology information response message, and if the Spanning tree protocol identified by the Spanning tree type is consistent with the Spanning tree protocol operated by the query request device, stores the port information of the port of the device to be queried, in which all the devices to be queried participate in the Spanning tree protocol calculation, and the MAC address of the device to be queried of the opposite port of the device to be queried, into a preset Spanning tree port state (Spanning-tree Ports Status) table, and stores the MAC address of the device to be queried of the opposite port of the device to be queried into a preset MAC address (SwitchMAC) table;
before this step, the query requesting device may set a spanning tree port state table and a MAC address table in advance. The spanning tree port state table is used for storing port information of a port of query request equipment, which participates in spanning tree protocol calculation, of the query request equipment and an MAC address of equipment to be queried of an opposite port of the query request equipment; the MAC address table is used to store the MAC address of the query request device and the MAC address of the device to be queried of the opposite port of the query request device port.
In this step, after the query request device receives the topology information response message, when it is determined that a value of a request MAC (request MAC) address field in the topology information response message is an MAC address of the device, a port information (Ports Status) field and an opposite-end MAC address (Neighbor MAC-address) field in the topology information response message are stored in a Spanning-tree Ports Status table, and an opposite-end MAC address (Neighbor MAC-address) field is stored in a MAC address (Switch MAC) table.
Further, in order to avoid repeatedly storing the peer MAC address (Neighbor MAC-address) field, in this embodiment, before the step of storing the peer MAC address (Neighbor MAC-address) field in the MAC address table, a following determination may be performed according to the peer MAC address (Neighbor MAC-address) field: if the opposite-end MAC address (Neighbor MAC-address) field already exists in the MAC address table, the opposite-end MAC address (Neighbor MAC-address) field does not need to be stored in the MAC address table: and if the MAC address table does not have the opposite terminal MAC address field, storing the opposite terminal MAC address field into the MAC address table.
The Spanning-tree Ports Status table may include the following fields:
a reply mac (reply mac) address field;
a port number (index) field;
a spanning tree Instance number (Instance ID) field;
a Port role (Port-role) field and a Port status (Port-status) field;
a peer MAC address field;
the Spanning-tree Ports Status table is indexed by a reply mac (reply mac) address field, a port number (index) field, and a Spanning tree Instance number (Instance ID) field.
The MAC address (Switch MAC) table may contain the following fields:
a peer MAC address field.
For example: for example, the following table entry is in the Spanning-tree Ports Status table:
“Reply MAC-address=MAC1”;
“Port index=10”;
“Instance ID=1”;
“Port-status=Forwarding”;
“Port-role=Root”;
“Neighbor MAC-address=MAC2”。
the above entry describes the following information: in the spanning tree instance with spanning tree instance number 1, the device with address MAC1 is connected to the device with address MAC2 via the port with port number 10, the port state of the port is the forwarding state, and the port role is the root port.
In this embodiment, when the query request device receives the topology information response messages responded by the device to be queried corresponding to all MAC fields in the MAC address table, that is, when all MAC address fields in the MAC address table can query the table entry using the MAC address as the response MAC address field in the spanning tree port state table, it can be said that the two tables completely record the topology information of the network, so that the network topology structure can be clearly determined.
It should be noted that: after the device to be queried adjacent to the query request device and the next-stage adjacent device to be queried receive the topology information response message, checking that a request MAC (request MAC) address field in the topology information response message is not an MAC address of the device, not processing the received topology information request message, forwarding the topology information response message through a port corresponding to a request MAC (request MAC) address found in an MAC address table, and finally reaching the query request device.
In this embodiment, if the device to be queried does not run the spanning tree protocol (STP, RSTP, MSTP, etc.) and does not open the BPDU transparent transmission function, the received topology information request/response message is not processed and is not forwarded; if the equipment to be queried does not run spanning tree protocols (STP, RSTP, MSTP and the like) but the BPDU transparent transmission function is started, directly transmitting the received topology information request/response message to the next/previous-stage adjacent equipment to be queried without processing; if the device to be queried runs STP and RSTP and the value of a Spanning tree type (Spanning-tree mode) field in the received topology information request/response message is 0x1000 or 0x2000, the topology information request/response message may be correspondingly processed according to the relevant content of step 202/step 204; if the equipment to be inquired runs the MSTP and the value of a Spanning tree type (Spanning-tree mode) field in the received topology information request/response message is 0x30, checking whether an MST configuration digest (MST configuration digest) field in the topology information request/response message is the same as an MST configuration digest (MST configuration digest) field in a BPDU (BPDU) generated by the equipment to be inquired, if so, correspondingly processing the topology information request/response message according to the relevant content of the step 202/step 204, otherwise, directly discarding the received topology information request/response message without processing; if the device to be queried runs STP and RSTP, the value of the Spanning tree type (Spanning-tree Mode) field in the received topology information request/response message is 0x30 ANG, or the device to be queried runs MSTP, and the value of the Spanning tree type (Spanning-tree Mode) field in the received topology information request/response message is 0x1000 or 0x2000, which indicates that the Spanning tree protocol run by the device to be queried does not negotiate with other devices successfully, the received topology information request/response message is directly discarded without processing.
Fig. 2B is a schematic diagram of a topology structure of an application scenario network of the topology information discovery method provided in the second embodiment of the present invention, where each device in the topology runs MSTP, and the configuration in the domain is as follows:
Instance VLANs Mapped
-----------------------------------------
0 :1-39,104-1999,2101-4094
1 :41,43
2 :40,42
-----------------------------------------
in Instance 0, the root bridge is S1, and after the spanning tree protocol is calculated, the port roles and port states of the ports of the device may be as follows:
idx of S1 is 1, the port role is "desg", and the port status is "forwarding"
idx is 2, the role of the port is desg, and the state of the port is forwarding;
idx of S2 is 1, the port role is "root", and the port status is "forwarding"
idx is 2, the role of the port is desg, and the state of the port is forwarding "
idx is 3, the role of the port is desg, and the state of the port is forwarding;
idx of S3 is 1, the port role is "root", and the port status is "forwarding"
idx is 2, the port role is "altn", and the port state is "blocking"
idx is 3, the role of the port is desg, and the state of the port is forwarding;
idx of S4 is 1, the port role is "root", and the port status is "forwarding"
idx is 2, the port role is "altn" and the port state is "blocking".
In Instance1, the root bridge is S2, and after the spanning tree protocol is calculated, the port roles and port states of the ports of the device may be as follows:
idx of S1 is 1, the port role is "root", and the port status is "forwarding"
idx is 2, the role of the port is desg, and the state of the port is forwarding;
idx of S2 is 1, the port role is "desg", and the port status is "forwarding"
idx is 2, the role of the port is desg, and the state of the port is forwarding "
idx is 3, the role of the port is desg, and the state of the port is forwarding;
idx of S3 is 1, port role is "altn", and port status is "blocking"
idx is 2, the role of the port is root, and the state of the port is forwarding "
idx is 3, the port role is "altn", and the port state is "blocking";
idx of S4 is 1, the port role is "root", and the port status is "forwarding"
idx is 2, the port role is "desg", and the port status is "forwarding".
In Instance3, the root bridge is S3, and after the spanning tree protocol is calculated, the port color and port status of each port of the device can be as follows:
idx of S1 is 1, the port role is "desg", and the port status is "forwarding"
idx is 2, the port role is root, and the port state is forwarding;
idx of S2 is 1, port role is "altn", and port status is "blocking"
idx is 2, the role of the port is root, and the state of the port is forwarding "
idx is 3, the port role is "altn", and the port state is "blocking";
idx of S3 is 1, the port role is "desg", and the port status is "forwarding"
idx is 2, the role of the port is desg, and the state of the port is forwarding "
idx is 3, the role of the port is desg, and the state of the port is forwarding;
idx of S4 is 1, the port role is "desg", and the port status is "forwarding"
idx is 2, the port role is root, and the port state is forwarding.
After the "mapping-tree location-topology query" is run, returning the success of the query, and sequentially traversing the "mapping-tree portals" table by using the "show mapping-tree location-topology" to obtain the logical topology. Taking the topology as an example, in S4, a command "Switch # mapping-tree location-topology query" is first executed to obtain an execution result "mapping-tree location-topology query"; the command "Switch # show mapping-tree logic-topology" is then executed, resulting in the following execution results:
Spanning tree enabled protoCol mstp
-------------------------------------------------------------
MST 0 logic-topology
mac:00 d0 f8 10 04 01
inf fa 0/1(root/fwd)/ \inf fa 0/2(alte/blk)
/ \
inf fa 0/3(desg/fwd)/ \inf fa 0/3(desg/fwd)
/inf fa 0/2(desg/fwd) \
mac:00 d0 f8 10 02 01----------------------mac:00 d0 f8 10 03 01
\ inf fa 0/2(alte/blk)/
inf fa 0/1(root/fwd)\ /inf fa 0/1(root/fwd)
\ /
inf fa 0/1(desg/fwd)\ /inf fa 0/2(desg/fwd)
mac:00 d0 f8 10 01 01
-------------------------------------------------------------
MST 1 logiC-topology
mac:00 d0 f8 10 04 01
inf fa 0/1(root/fwd)/ \inf fa0/2(desg/fwd)
/ \
inf fa 0/3(desg/fwd)/ \inf fa 0/3(alte/blk)
/ inf fa 0/2(desg/fwd) \
mac:00 d0 f8 10 02 01 -----------------------------mac:00d0f8100301
\ in ffa 0/2(root/fwd)/
inf fa 0/1(desg/fwd)\ /inf fa 0/1(alte/blk)
\ /
inf fa 0/1(root/fwd)\ /inf fa 0/2(desg/fwd)
mac:00 d0 f8 10 01 01
-------------------------------------------------------------
MST 3 logic-topology
mac:00 d0 f8 10 04 01
inf fa 0/1(desg/fwd)/ \inf fa 0/2(root/fwd)
/ \
inf fa 0/3(alte/blk)/ \inf fa 0/3(desg/fwd)
/inf fa 0/2(desg/fwd) \
mac:00d0f8100201 ----------------------------mac:00d0f8100301
\ inf fa 0/2(desg/fwd)/
inf fa 0/1(alte/blk)\ /inf fa 0/1(desg/fwd)
\ /
inf fa 0/1(desg/fwd) \ /inf fa 0/2(root/fwd)
mac:00 d0 f8 10 01 01
-------------------------------------------------------------
by the operation result, the topology of the application scenario network can be clearly reproduced, and the logical topological relationship among the devices (S1, S2, S3, and S4) in the VLAN-existing network can be confirmed.
In this embodiment, after the query request device sends the topology information request message to the device to be queried, the device to be queried returns a topology information response message to the query request device according to the identification information of all devices to be queried in the topology information request message, so that the query request device can obtain the port information of the port of the device to be queried, where all devices to be queried participate in the spanning tree protocol calculation, and thus can confirm the physical topology relationship among devices in the network where no VLAN exists and the logical topology relationship among devices in the network where the VLAN exists.
Fig. 3 is a schematic flow chart of a method for discovering topology information according to a third embodiment of the present invention, and as shown in fig. 3, compared with the previous embodiment, the method for discovering topology information according to the present embodiment may further include the following steps:
step 301, when an inquiry request device sends a topology information request message to an adjacent device to be inquired, a timer is started;
step 302, the query request device determines whether the topology information response messages returned by all the devices to be queried identified by the MAC addresses in the MAC address table are received within a preset time of a timer, if the query request device receives the topology information response messages returned by all the devices to be queried identified by the MAC addresses in the MAC address table, step 303 is executed, otherwise step 304 is executed;
step 303, the query request device confirms that the query is successful, and generates a result of successful query;
step 304, the query request device confirms the failure of the query, and generates a result of the failure of the query.
Wherein the preset time of the timer may be set to 3 BPDU handshake times (hello-time).
Alternatively, in this embodiment, in step 303, if the query requesting device does not receive the topology information response messages returned by all the devices to be queried identified by the MAC address in the MAC address table within the preset time of the timer, the query requesting device may further execute step 201 again to send the topology information request message to the adjacent devices to be queried, and the identification information of all the devices to be queried may be a certain MAC address field in the MAC address table that has not been queried in the spanning tree port state table, that is, the value of the other MAC (othermac) address field in the topology information request message is the device to be queried whose MAC address is in the MAC address table and has not received the topology information response message, and further, the preset time of the timer may be halved, and the above-mentioned cycle is repeated. When the preset time of the timer is less than half of the BPDU handshake time, the query fails, and a query failure result is generated.
In this embodiment, the timer is started while the query request device sends the topology information request packet to the adjacent device to be queried, so as to determine whether the topology information acquired by the query request device is complete, thereby ensuring the integrity of the topology information, and enabling the network manager to confirm the logic result of the network. In addition, the embodiment of the invention is completely compatible with the related standards of the current spanning tree protocols (STP, RSTP and MSTP), and has the advantages of less change, convenient deployment and simplicity.
It should be noted that: while, for purposes of simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present invention is not limited by the illustrated ordering of acts, as some steps may occur in other orders or concurrently with other steps in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
Fig. 4 is a schematic structural diagram of an inquiry requesting device according to a fourth embodiment of the present invention, and as shown in fig. 4, the inquiry requesting device according to this embodiment may include a requesting module 41 and an obtaining module 42. The request module 41 sends a topology information request message to an adjacent device to be queried, where the topology information request message carries a spanning tree type, a query request device identifier, and identifier information of all devices to be queried, so that the adjacent device to be queried forwards the topology information request message to a next-stage adjacent device to be queried; the obtaining module 42 receives, if the spanning tree protocol of the spanning tree type identifier is consistent with the running spanning tree protocol, topology information response messages returned by all the devices to be queried, where the topology information response messages carry the identifier of the query request device, the port information of the device port to be queried of all the devices to be queried, which participate in the spanning tree protocol calculation, and the identifier of the device to be queried of the opposite port of the device port to be queried, respectively.
The functions of the query request device in the second embodiment of the present invention and the query request device in the third embodiment of the present invention may be implemented by the query request device provided in this embodiment, and the query request device may be a switch.
The query request device identifier may be a MAC address of the query request device; correspondingly, the device identifier to be queried of the peer port may be an MAC address of the device to be queried of the peer port.
The embodiment can be applied to a network without a VLAN, for example: the device to be queried in the network runs spanning tree protocols such as STP, RSTP, etc., and can also be applied to networks with VLANs, for example: the equipment to be inquired in the network runs a spanning tree protocol such as MSTP.
In this embodiment, after the request module sends the topology information request message to the device to be queried, the device to be queried returns a topology information response message to the acquisition module according to the identification information of all devices to be queried in the topology information request message, so that the acquisition module can acquire the port information of the port of the device to be queried, where all devices to be queried participate in the spanning tree protocol calculation, and thus can confirm the physical topology relationship among devices in the network where the VLAN does not exist and the logical topology relationship among devices in the network where the VLAN exists.
Fig. 5 is a schematic structural diagram of a query requesting device according to a fifth embodiment of the present invention, and as shown in fig. 5, as compared with the previous embodiment, the query requesting device of this embodiment may further include a setting module 51, configured to preset a spanning tree port state table for storing port information of a port of the query requesting device, where the query requesting device participates in spanning tree protocol calculation, and a MAC address of a device to be queried of an opposite port of the query requesting device, and a MAC address table for storing a MAC address of the query requesting device and a MAC address of a device to be queried of an opposite port of the query requesting device.
Further, the query requesting device of the present embodiment may further include a first processing module 52 and a second processing module 53. The first processing module 52 stores the port information of the port of the device to be queried, which is obtained by the obtaining module 42 and is calculated by the spanning tree protocol, of all the devices to be queried and the MAC address of the device to be queried of the opposite port of the device to be queried, into the spanning tree port state table set by the setting module 51; the second processing module 53 stores the MAC address of the device to be queried of the opposite port of the device to be queried, which is obtained by the obtaining module 42, into the MAC address table set by the setting module 51.
Fig. 6 is a schematic structural diagram of a device to be queried according to a sixth embodiment of the present invention, as shown in fig. 6, the device to be queried according to this embodiment may include a receiving module 61 for receiving a topology information request packet, where the topology information request packet carries a spanning tree type, an identifier of a query request device, and identifier information of all devices to be queried, a forwarding module 62 for forwarding the topology information request packet to a next-level adjacent device to be queried according to the identifier information of all devices to be queried, and a providing module 63 for returning a topology information response packet according to the identifier information of all devices to be queried if a spanning tree protocol of the spanning tree type identifier is consistent with an operating spanning tree protocol, where the topology information response packet carries the identifier of the query request device, port information of a port of the device to be queried, which is calculated by the spanning tree protocol of all devices to be queried, and an identifier of the device to be queried of an opposite port of the device to be queried And (4) identifying.
The functions of the device to be queried in the second embodiment of the present invention and the third embodiment of the present invention may be implemented by the device to be queried provided in this embodiment, and the device to be queried may be a switch.
The query request device identifier may be a MAC address of the query request device; correspondingly, the device identifier to be queried of the peer port may be an MAC address of the device to be queried of the peer port.
In this embodiment, the identification information of all the devices to be queried may include two forms: when the devices to be queried are all devices in the network, the identification information of all the devices to be queried is a specific field value, for example: ffffffffff, correspondingly, the providing module 63 may return a topology information response message according to the identification information of all the devices to be queried, and the forwarding module 62 may forward the topology information request message to a next-stage adjacent device to be queried according to the identification information of all the devices to be queried; when the device to be queried is a certain device in the network, the identification information of all the devices to be queried is the MAC address of the device, and accordingly, the providing module 63 may return a topology information response packet according to the identification information of all the devices to be queried.
In this embodiment, after the receiving module 61 receives the topology information request message, if the to-be-queried devices identified by the identification information of all the to-be-queried devices include the to-be-queried device (which may be a scenario including all the to-be-queried devices in a network, or a scenario including only the adjacent to-be-queried device), and the spanning tree protocol identified by the spanning tree type is consistent with the spanning tree protocol operated by the to-be-queried device, the providing module 63 provides a topology information response message returned through a port that receives the topology information request message; if the devices to be queried identified by the identification information of all the devices to be queried do not include the devices to be queried or the devices to be queried identified by the identification information of all the devices to be queried are all devices to be queried in the network, the forwarding module 62 forwards the topology information request message to the next-stage adjacent device to be queried through other ports except the port for receiving the topology information request message.
The embodiment can be applied to a network without a VLAN, for example: the device to be queried in the network runs spanning tree protocols such as STP, RSTP, etc., and can also be applied to networks with VLANs, for example: the equipment to be inquired in the network runs a spanning tree protocol such as MSTP.
In this embodiment, after receiving the topology information request message, the providing module returns a topology information response message according to the identification information of all the devices to be queried in the topology information request message, so that the devices to be queried can obtain the port information of the port of the device to be queried, where all the devices to be queried participate in the spanning tree protocol calculation, and thus can confirm the physical topology relationship among the devices in the network where the VLAN does not exist and the logical topology relationship among the devices in the network where the VLAN exists.
Fig. 7 is a schematic structural diagram of a topology information discovery system according to a seventh embodiment of the present invention, and as shown in fig. 7, the topology information discovery system according to this embodiment may include a query requesting device 71 and a device to be queried 72. Wherein,
the query request device 71 is configured to send a topology information request message to an adjacent device to be queried 72, where the topology information request message carries a spanning tree type, a query request device identifier, and identifier information of all devices to be queried 72, and respectively receive topology information response messages returned by all devices to be queried 72, where the topology information response messages carry the query request device identifier, port information of a device to be queried of the device to be queried 72 participating in spanning tree protocol calculation, and a device to be queried identifier of an opposite port of the device to be queried port;
the device to be queried 72 is configured to receive the topology information request message, forward the topology information request message to a next-stage adjacent device to be queried 72 according to the identification information of all the devices to be queried 72, and return the topology information response message if the spanning tree protocol identified by the spanning tree type is consistent with the running spanning tree protocol according to the identification information of all the devices to be queried 72.
The functions of the query request device in the second embodiment of the present invention and the query request device in the third embodiment of the present invention may be implemented by the query request device 71 in the topology information discovery system provided in this embodiment, and the query request device 71 may be an exchange; the functions of the device to be queried in the second embodiment of the present invention and the third embodiment of the present invention may be implemented by the device to be queried 72 in the topology information discovery system provided in this embodiment, and the device to be queried 72 may be a switch.
The query request device identifier may be a MAC address of the query request device; correspondingly, the device identifier to be queried of the peer port may be an MAC address of the device to be queried of the peer port.
In this embodiment, the identification information of all the devices to be queried may include two forms: when the devices to be queried are all devices in the network, the identification information of all the devices to be queried is a specific field value, for example: ffffffffff, correspondingly, the device to be queried 72 may return a topology information response message according to the identification information of all the devices to be queried, and forward the topology information request message to the next-stage adjacent device to be queried; when the device to be queried is a certain device in the network, the identification information of all the devices to be queried is the MAC address of the device, and correspondingly, the device to be queried 72 may return a topology information response packet according to the identification information of all the devices to be queried.
In this embodiment, after receiving a topology information request message, if the to-be-queried device identified by the identification information of all the to-be-queried devices includes the to-be-queried device (which may be a scenario including all the to-be-queried devices in a network, or a scenario including only the adjacent to-be-queried device), and the spanning tree protocol identified by the spanning tree type is consistent with the spanning tree protocol operated by the to-be-queried device, the to-be-queried device returns a topology information response message through a port receiving the topology information request message; if the devices to be queried identified by the identification information of all the devices to be queried do not include the devices to be queried or the devices to be queried identified by the identification information of all the devices to be queried are all the devices to be queried in the network, the devices to be queried forward the topology information request message to the next-stage adjacent devices to be queried through other ports except the port for receiving the topology information request message.
The embodiment can be applied to a network without a VLAN, for example: the device to be queried in the network runs spanning tree protocols such as STP, RSTP, etc., and can also be applied to networks with VLANs, for example: the equipment to be inquired in the network runs a spanning tree protocol such as MSTP.
In this embodiment, after the query request device sends the topology information request message to the device to be queried, the device to be queried returns a topology information response message to the query request device according to the identification information of all devices to be queried in the topology information request message, so that the query request device can obtain the port information of the port of the device to be queried, where all devices to be queried participate in the spanning tree protocol calculation, and thus can confirm the physical topology relationship among devices in the network where no VLAN exists and the logical topology relationship among devices in the network where the VLAN exists.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.